1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "app_domain_verify_rdb_open_callback.h"
16 #include "app_domain_verify_hilog.h"
17 #include "rdb_errno.h"
18 #include "rdb_migrate_mgr.h"
19
20 namespace OHOS {
21 namespace AppDomainVerify {
AppDomainVerifyRdbOpenCallback(const AppDomainVerifyRdbConfig & rdbConfig)22 AppDomainVerifyRdbOpenCallback::AppDomainVerifyRdbOpenCallback(const AppDomainVerifyRdbConfig& rdbConfig)
23 : appDomainVerifyRdbConfig_(rdbConfig)
24 {
25 }
OnCreate(NativeRdb::RdbStore & rdbStore)26 int32_t AppDomainVerifyRdbOpenCallback::OnCreate(NativeRdb::RdbStore& rdbStore)
27 {
28 APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "RdbStore OnCreate");
29 return NativeRdb::E_OK;
30 }
OnUpgrade(NativeRdb::RdbStore & rdbStore,int currentVersion,int targetVersion)31 int32_t AppDomainVerifyRdbOpenCallback::OnUpgrade(NativeRdb::RdbStore& rdbStore, int currentVersion, int targetVersion)
32 {
33 APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE,
34 "OnUpgrade currentVersion: %{public}d, targetVersion: %{public}d", currentVersion, targetVersion);
35 RdbMigrateMgr rdbMigrateMgr(appDomainVerifyRdbConfig_);
36 int32_t ret = rdbMigrateMgr.Upgrade(rdbStore, currentVersion, targetVersion);
37 if (ret != NativeRdb::E_OK) {
38 APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "OnUpgrade fail., ret:%{public}d", ret);
39 return ret;
40 }
41 APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "OnUpgrade End");
42 return NativeRdb::E_OK;
43 }
OnDowngrade(NativeRdb::RdbStore & rdbStore,int currentVersion,int targetVersion)44 int32_t AppDomainVerifyRdbOpenCallback::OnDowngrade(
45 NativeRdb::RdbStore& rdbStore, int currentVersion, int targetVersion)
46 {
47 APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE,
48 "OnDowngrade currentVersion: %{plubic}d, targetVersion: %{plubic}d", currentVersion, targetVersion);
49 return NativeRdb::E_OK;
50 }
OnOpen(NativeRdb::RdbStore & rdbStore)51 int32_t AppDomainVerifyRdbOpenCallback::OnOpen(NativeRdb::RdbStore& rdbStore)
52 {
53 APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "RdbStore OnOpen");
54 return NativeRdb::E_OK;
55 }
onCorruption(std::string databaseFile)56 int32_t AppDomainVerifyRdbOpenCallback::onCorruption(std::string databaseFile)
57 {
58 return NativeRdb::E_OK;
59 }
60 } // namespace AppDomainVerify
61 } // namespace OHOS
62