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 #ifndef OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_IINNER_OS_ACCOUNT_MANAGER_H 16 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_IINNER_OS_ACCOUNT_MANAGER_H 17 #include <memory> 18 #include "iinner_os_account.h" 19 #include "ios_account_control.h" 20 #include "ios_account_subscribe.h" 21 #include "os_account_standard_interface.h" 22 #include "singleton.h" 23 namespace OHOS { 24 namespace AccountSA { 25 class IInnerOsAccountManager : public IInnerOsAccount, public DelayedSingleton<IInnerOsAccountManager> { 26 public: 27 IInnerOsAccountManager(); 28 virtual ~IInnerOsAccountManager() = default; 29 void Init() override; 30 ErrCode CreateOsAccount( 31 const std::string &name, const OsAccountType &type, OsAccountInfo &osAccountInfo) override; 32 ErrCode CreateOsAccountForDomain( 33 const OsAccountType &type, const DomainAccountInfo &domainInfo, OsAccountInfo &osAccountInfo) override; 34 ErrCode RemoveOsAccount(const int id) override; 35 ErrCode IsOsAccountExists(const int id, bool &isOsAccountExits) override; 36 ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived) override; 37 ErrCode IsOsAccountConstraintEnable( 38 const int id, const std::string &constraint, bool &isOsAccountConstraintEnable) override; 39 ErrCode IsOsAccountVerified(const int id, bool &isVerified) override; 40 ErrCode GetCreatedOsAccountsCount(unsigned int &createdOsAccountCount) override; 41 ErrCode QueryMaxOsAccountNumber(int &maxOsAccountNumber) override; 42 ErrCode GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints) override; 43 ErrCode QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos) override; 44 ErrCode QueryOsAccountById(const int id, OsAccountInfo &osAccountInfo) override; 45 ErrCode GetOsAccountType(const int id, OsAccountType &type) override; 46 ErrCode GetOsAccountProfilePhoto(const int id, std::string &photo) override; 47 ErrCode IsMultiOsAccountEnable(bool &isMultiOsAccountEnable) override; 48 ErrCode SetOsAccountName(const int id, const std::string &name) override; 49 ErrCode SetOsAccountConstraints( 50 const int id, const std::vector<std::string> &constraints, const bool enable) override; 51 ErrCode SetOsAccountProfilePhoto(const int id, const std::string &photo) override; 52 ErrCode ActivateOsAccount(const int id) override; 53 ErrCode StartOsAccount(const int id) override; 54 ErrCode StopOsAccount(const int id) override; 55 ErrCode GetOsAccountLocalIdBySerialNumber(const int64_t serialNumber, int &id) override; 56 ErrCode GetSerialNumberByOsAccountLocalId(const int &id, int64_t &serialNumber) override; 57 ErrCode SubscribeOsAccount( 58 const OsAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) override; 59 ErrCode UnsubscribeOsAccount(const sptr<IRemoteObject> &eventListener) override; 60 OS_ACCOUNT_SWITCH_MOD GetOsAccountSwitchMod() override; 61 ErrCode IsOsAccountCompleted(const int id, bool &isOsAccountCompleted) override; 62 ErrCode SetOsAccountIsVerified(const int id, const bool isVerified) override; 63 ErrCode IsAllowedCreateAdmin(bool &isAllowedCreateAdmin) override; 64 ErrCode GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id) override; 65 ErrCode GetCreatedOsAccountNumFromDatabase(const std::string& storeID, 66 int &createdOsAccountNum) override; 67 ErrCode GetSerialNumberFromDatabase(const std::string& storeID, int64_t &serialNumber) override; 68 ErrCode GetMaxAllowCreateIdFromDatabase(const std::string& storeID, int &id) override; 69 ErrCode GetOsAccountFromDatabase(const std::string& storeID, const int id, 70 OsAccountInfo &osAccountInfo) override; 71 ErrCode GetOsAccountListFromDatabase(const std::string& storeID, 72 std::vector<OsAccountInfo> &osAccountList) override; 73 ErrCode QueryActiveOsAccountIds(std::vector<int32_t>& ids) override; 74 75 private: 76 void StartAccount(); 77 void CreateBaseAdminAccount(); 78 void CreateBaseStandardAccount(); 79 void CreateBaseStandardAccountSendToOther(); 80 void StartBaseStandardAccount(void); 81 void DeActivateOsAccount(const int id); 82 void ResetActiveStatus(void); 83 ErrCode GetEventHandler(void); 84 ErrCode PrepareOsAccountInfo(const std::string &name, const OsAccountType &type, 85 const DomainAccountInfo &domainAccount, OsAccountInfo &osAccountInfo); 86 ErrCode SendMsgForAccountCreate(OsAccountInfo &osAccountInfo); 87 ErrCode SendMsgForAccountActivate(OsAccountInfo &osAccountInfo); 88 ErrCode SendMsgForAccountStop(OsAccountInfo &osAccountInfo); 89 ErrCode SendMsgForAccountRemove(OsAccountInfo &osAccountInfo); 90 void AddLocalIdToOperating(int32_t localId); 91 void RemoveLocalIdToOperating(int32_t localId); 92 bool IsLocalIdInOperating(int32_t localId); 93 void CleanGarbageAccounts(); 94 95 // operations for active list 96 void PushIDIntoActiveList(int32_t id); 97 bool IsOsAccountIDInActiveList(int32_t id); 98 void CopyFromActiveList(std::vector<int32_t>& idList); 99 void RefreshActiveList(int32_t newId); 100 101 private: 102 std::shared_ptr<IOsAccountControl> osAccountControl_; 103 std::vector<int32_t> activeAccountId_; 104 std::vector<int32_t> operatingId_; 105 std::shared_ptr<IOsAccountSubscribe> subscribeManagerPtr_; 106 std::int32_t counterForStandard_; 107 std::int32_t counterForStandardCreate_; 108 bool isSendToStorageCreate_; 109 bool isSendToStorageStart_; 110 std::shared_ptr<OHOS::AppExecFwk::EventHandler> handler_; 111 static constexpr std::int32_t DELAY_FOR_FOUNDATION_SERVICE = 2 * 1000; // 2s 112 static constexpr std::int32_t DELAY_FOR_TIME_INTERVAL = 1 * 1000; // 1s 113 static constexpr std::int32_t MAX_TRY_TIMES = 100; 114 mutable std::mutex ativeMutex_; 115 mutable std::mutex operatingMutex_; 116 }; 117 } // namespace AccountSA 118 } // namespace OHOS 119 #endif /* OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_IINNER_OS_ACCOUNT_MANAGER_H */