1 /* 2 * Copyright (c) 2024 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 16 #ifndef SECURITY_ACCESS_TOKEN_OPEN_CALLBACK_H 17 #define SECURITY_ACCESS_TOKEN_OPEN_CALLBACK_H 18 19 #include "access_token_db_util.h" 20 #include "rdb_open_callback.h" 21 #include "rdb_store.h" 22 23 namespace OHOS { 24 namespace Security { 25 namespace AccessToken { 26 27 static constexpr const char* DATABASE_PATH = "/data/service/el1/public/access_token/"; 28 29 static constexpr const int32_t DATABASE_VERSION_1 = 1; 30 static constexpr const int32_t DATABASE_VERSION_2 = 2; 31 static constexpr const int32_t DATABASE_VERSION_3 = 3; 32 static constexpr const int32_t DATABASE_VERSION_4 = 4; 33 static constexpr const int32_t DATABASE_VERSION_5 = 5; 34 static constexpr const int32_t DATABASE_VERSION_6 = 6; 35 36 class AccessTokenOpenCallback : public NativeRdb::RdbOpenCallback { 37 public: 38 /** 39 * Called when the database associate with this RdbStore is created with the first time. 40 * This is where the creation of tables and insert the initial data of tables should happen. 41 * 42 * param store The RdbStore object. 43 */ 44 int32_t OnCreate(NativeRdb::RdbStore& rdbStore) override; 45 /** 46 * Called when the database associate whit this RdbStore needs to be upgrade. 47 * 48 * param store The RdbStore object. 49 * param oldVersion The old database version. 50 * param newVersion The new database version. 51 */ 52 int32_t OnUpgrade(NativeRdb::RdbStore& rdbStore, int32_t currentVersion, int32_t targetVersion) override; 53 54 private: 55 // OnCreate 56 int32_t CreateHapTokenInfoTable(NativeRdb::RdbStore& rdbStore); 57 int32_t CreateNativeTokenInfoTable(NativeRdb::RdbStore& rdbStore); 58 int32_t CreatePermissionDefinitionTable(NativeRdb::RdbStore& rdbStore); 59 int32_t CreatePermissionStateTable(NativeRdb::RdbStore& rdbStore); 60 int32_t CreateVersionOneTable(NativeRdb::RdbStore& rdbStore); 61 int32_t CreatePermissionRequestToggleStatusTable(NativeRdb::RdbStore& rdbStore); 62 int32_t CreateVersionThreeTable(NativeRdb::RdbStore& rdbStore); 63 int32_t CreatePermissionExtendValueTable(NativeRdb::RdbStore& rdbStore); 64 int32_t CreateVersionFiveTable(NativeRdb::RdbStore& rdbStore); 65 int32_t CreateHapUndefineInfoTable(NativeRdb::RdbStore& rdbStore); 66 int32_t CreateSystemConfigTable(NativeRdb::RdbStore& rdbStore); 67 int32_t CreateVersionSixTable(NativeRdb::RdbStore& rdbStore); 68 69 // OnUpgrade 70 int32_t AddAvailableTypeColumn(NativeRdb::RdbStore& rdbStore); 71 int32_t AddRequestToggleStatusColumn(NativeRdb::RdbStore& rdbStore); 72 int32_t AddPermDialogCapColumn(NativeRdb::RdbStore& rdbStore); 73 int32_t AddKernelEffectAndHasValueColumn(NativeRdb::RdbStore& rdbStore); 74 }; 75 } // namespace AccessToken 76 } // namespace Security 77 } // namespace OHOS 78 79 #endif // SECURITY_ACCESS_TOKEN_OPEN_CALLBACK_H 80