1 /* 2 * Copyright (c) 2021-2022 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 OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_DATABSE_OPERATOR_H 17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_DATABSE_OPERATOR_H 18 19 #include <memory> 20 #include "account_data_storage.h" 21 #include "ios_account_control.h" 22 #include "json_utils.h" 23 #include "os_account_info.h" 24 25 namespace OHOS { 26 namespace AccountSA { 27 class OsAccountDatabaseOperator { 28 public: 29 OsAccountDatabaseOperator(); 30 virtual ~OsAccountDatabaseOperator(); 31 32 // update infos to database 33 void UpdateOsAccountIDListInDatabase(const CJsonUnique &accountListJson); 34 void UpdateOsAccountInDatabase(const OsAccountInfo &osAccountInfo); 35 void InsertOsAccountIntoDataBase(const OsAccountInfo &osAccountInfo); 36 void DelOsAccountFromDatabase(const int id); 37 38 ErrCode GetCreatedOsAccountNumFromDatabase(const std::string &storeID, int &createdOsAccountNum); 39 ErrCode GetSerialNumberFromDatabase(const std::string &storeID, int64_t &serialNumber); 40 ErrCode GetMaxAllowCreateIdFromDatabase(const std::string &storeID, int &id); 41 ErrCode GetOsAccountFromDatabase(const std::string &storeID, const int id, OsAccountInfo &osAccountInfo); 42 ErrCode GetOsAccountListFromDatabase(const std::string &storeID, std::vector<OsAccountInfo> &osAccountList); 43 ErrCode GetAccountListFromStoreID(const std::string &storeID, CJsonUnique &accountListJson); 44 45 private: 46 bool InnerInit(); 47 48 private: 49 std::shared_ptr<AccountDataStorage> accountDataStorage_ = nullptr; 50 std::mutex initMutex_; 51 }; 52 } // namespace AccountSA 53 } // namespace OHOS 54 55 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_CONTROL_DATABSE_MANAGER_H