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 35 class AccessTokenOpenCallback : public NativeRdb::RdbOpenCallback { 36 public: 37 /** 38 * Called when the database associate with this RdbStore is created with the first time. 39 * This is where the creation of tables and insert the initial data of tables should happen. 40 * 41 * param store The RdbStore object. 42 */ 43 int32_t OnCreate(NativeRdb::RdbStore& rdbStore) override; 44 /** 45 * Called when the database associate whit this RdbStore needs to be upgrade. 46 * 47 * param store The RdbStore object. 48 * param oldVersion The old database version. 49 * param newVersion The new database version. 50 */ 51 int32_t OnUpgrade(NativeRdb::RdbStore& rdbStore, int32_t currentVersion, int32_t targetVersion) override; 52 53 private: 54 // OnCreate 55 int32_t CreateHapTokenInfoTable(NativeRdb::RdbStore& rdbStore); 56 int32_t CreateNativeTokenInfoTable(NativeRdb::RdbStore& rdbStore); 57 int32_t CreatePermissionDefinitionTable(NativeRdb::RdbStore& rdbStore); 58 int32_t CreatePermissionStateTable(NativeRdb::RdbStore& rdbStore); 59 int32_t CreatePermissionRequestToggleStatusTable(NativeRdb::RdbStore& rdbStore); 60 int32_t CreatePermissionExtendValueTable(NativeRdb::RdbStore& rdbStore); 61 62 // OnUpgrade 63 int32_t AddAvailableTypeColumn(NativeRdb::RdbStore& rdbStore); 64 int32_t AddRequestToggleStatusColumn(NativeRdb::RdbStore& rdbStore); 65 int32_t AddPermDialogCapColumn(NativeRdb::RdbStore& rdbStore); 66 int32_t AddKernelEffectAndHasValueColumn(NativeRdb::RdbStore& rdbStore); 67 void GetUpgradeFlag(int32_t currentVersion, int32_t targetVersion, uint32_t& flag); 68 int32_t HandleUpgradeWithFlag(NativeRdb::RdbStore& rdbStore, uint32_t flag); 69 }; 70 } // namespace AccessToken 71 } // namespace Security 72 } // namespace OHOS 73 74 #endif // SECURITY_ACCESS_TOKEN_OPEN_CALLBACK_H 75