1 /* 2 * Copyright (c) 2021-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 OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_MANAGER_SERVICE_H 17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_MANAGER_SERVICE_H 18 19 #include <stdint.h> 20 #include <sys/types.h> 21 #include <memory> 22 #include "account_permission_manager.h" 23 #include "os_account_stub.h" 24 #include "idomain_account_callback.h" 25 #include "iinner_os_account_manager.h" 26 27 namespace OHOS { 28 namespace AccountSA { 29 class OsAccountManagerService : public OsAccountStub { 30 public: 31 OsAccountManagerService(); 32 ~OsAccountManagerService() override; 33 34 ErrCode CreateOsAccount( 35 const std::string &name, const OsAccountType &type, OsAccountInfo &osAccountInfo) override; 36 ErrCode CreateOsAccount(const std::string &localName, const std::string &shortName, 37 const OsAccountType &type, OsAccountInfo &osAccountInfo, const CreateOsAccountOptions &options = {}) override; 38 ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo, 39 const sptr<IDomainAccountCallback> &callback, const CreateOsAccountForDomainOptions &options = {}) override; 40 ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo, 41 const CreateOsAccountOptions &options = {}) override; 42 ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override; 43 44 ErrCode RemoveOsAccount(const int id) override; 45 46 ErrCode IsOsAccountExists(const int id, bool &isOsAccountExists) override; 47 ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived) override; 48 49 ErrCode IsOsAccountConstraintEnable( 50 const int id, const std::string &constraint, bool &isConstraintEnable) override; 51 ErrCode CheckOsAccountConstraintEnabled( 52 const int id, const std::string &constraint, bool &isEnabled) override; 53 ErrCode IsOsAccountVerified(const int id, bool &isVerified) override; 54 ErrCode IsOsAccountDeactivating(const int id, bool &isDeactivating) override; 55 56 ErrCode GetCreatedOsAccountsCount(unsigned int &osAccountsCount) override; 57 ErrCode GetOsAccountLocalIdFromProcess(int &id) override; 58 ErrCode IsMainOsAccount(bool &isMainOsAccount) override; 59 ErrCode GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id) override; 60 ErrCode QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber) override; 61 ErrCode QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum) override; 62 63 ErrCode GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints) override; 64 ErrCode QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos) override; 65 66 ErrCode QueryCurrentOsAccount(OsAccountInfo &osAccountInfo) override; 67 ErrCode QueryOsAccountById(const int id, OsAccountInfo &osAccountInfo) override; 68 69 ErrCode GetOsAccountTypeFromProcess(OsAccountType& type) override; 70 ErrCode GetOsAccountType(const int id, OsAccountType& type) override; 71 ErrCode GetOsAccountProfilePhoto(const int id, std::string &photo) override; 72 73 ErrCode IsMultiOsAccountEnable(bool &isMultiOsAccountEnable) override; 74 ErrCode SetOsAccountName(const int id, const std::string &name) override; 75 76 ErrCode SetOsAccountConstraints( 77 const int id, const std::vector<std::string> &constraints, const bool enable) override; 78 ErrCode SetOsAccountProfilePhoto(const int id, const std::string &photo) override; 79 80 ErrCode ActivateOsAccount(const int id) override; 81 ErrCode DeactivateOsAccount(const int id) override; 82 ErrCode DeactivateAllOsAccounts() override; 83 84 ErrCode StartOsAccount(const int id) override; 85 86 ErrCode GetOsAccountLocalIdBySerialNumber(const int64_t serialNumber, int &id) override; 87 ErrCode GetSerialNumberByOsAccountLocalId(const int &id, int64_t &serialNumber) override; 88 89 ErrCode SubscribeOsAccount( 90 const OsAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) override; 91 ErrCode UnsubscribeOsAccount(const sptr<IRemoteObject> &eventListener) override; 92 93 OS_ACCOUNT_SWITCH_MOD GetOsAccountSwitchMod() override; 94 ErrCode IsCurrentOsAccountVerified(bool &isVerified) override; 95 96 ErrCode IsOsAccountCompleted(const int id, bool &isOsAccountCompleted) override; 97 ErrCode SetCurrentOsAccountIsVerified(const bool isVerified) override; 98 ErrCode SetOsAccountIsVerified(const int id, const bool isVerified) override; 99 ErrCode DumpState(const int &id, std::vector<std::string> &state) override; 100 ErrCode DumpOsAccountInfo(std::vector<std::string> &state); 101 102 ErrCode GetCreatedOsAccountNumFromDatabase(const std::string& storeID, 103 int &createdOsAccountNum) override; 104 ErrCode GetSerialNumberFromDatabase(const std::string& storeID, 105 int64_t &serialNumber) override; 106 ErrCode GetMaxAllowCreateIdFromDatabase(const std::string& storeID, int &id) override; 107 ErrCode GetOsAccountFromDatabase(const std::string& storeID, 108 const int id, OsAccountInfo &osAccountInfo) override; 109 ErrCode GetOsAccountListFromDatabase(const std::string& storeID, 110 std::vector<OsAccountInfo> &osAccountList) override; 111 ErrCode QueryActiveOsAccountIds(std::vector<int32_t>& ids) override; 112 113 ErrCode QueryOsAccountConstraintSourceTypes(const int32_t id, 114 const std::string &constraint, std::vector<ConstraintSourceTypeInfo> &constraintSourceTypeInfos) override; 115 ErrCode SetGlobalOsAccountConstraints(const std::vector<std::string> &constraints, 116 const bool enable, const int32_t enforcerId, const bool isDeviceOwner) override; 117 ErrCode SetSpecificOsAccountConstraints(const std::vector<std::string> &constraints, 118 const bool enable, const int32_t targetId, const int32_t enforcerId, const bool isDeviceOwner) override; 119 120 ErrCode SetDefaultActivatedOsAccount(const int32_t id) override; 121 ErrCode GetDefaultActivatedOsAccount(int32_t &id) override; 122 ErrCode GetOsAccountShortName(std::string &shortName) override; 123 ErrCode GetOsAccountName(std::string &name) override; 124 ErrCode GetOsAccountShortNameById(const int32_t id, std::string &shortName) override; 125 126 ErrCode IsOsAccountForeground(const int32_t localId, const uint64_t displayId, bool &isForeground) override; 127 ErrCode GetForegroundOsAccountLocalId(const uint64_t displayId, int32_t &localId) override; 128 ErrCode GetForegroundOsAccounts(std::vector<ForegroundOsAccount> &accounts) override; 129 ErrCode GetBackgroundOsAccountLocalIds(std::vector<int32_t> &localIds) override; 130 ErrCode SetOsAccountToBeRemoved(int32_t localId, bool toBeRemoved) override; 131 ErrCode GetOsAccountDomainInfo(const int32_t localId, DomainAccountInfo &domainInfo) override; 132 133 private: 134 virtual ErrCode DumpStateByAccounts( 135 const std::vector<OsAccountInfo> &osAccountInfos, std::vector<std::string> &state); 136 bool PermissionCheck(const std::string& permissionName, const std::string& constraintName); 137 bool CheckCreateOsAccountWhiteList(); 138 ErrCode ValidateShortName(const std::string &shortName); 139 void GetCurrentLocalId(int32_t &localId); 140 ErrCode GetOsAccountShortNameCommon(const int32_t id, std::string &shortName); 141 ErrCode ValidateAccountCreateParamAndPermission(const std::string &localName, const OsAccountType &type); 142 143 private: 144 IInnerOsAccountManager &innerManager_; 145 DISALLOW_COPY_AND_MOVE(OsAccountManagerService); 146 }; 147 } // namespace AccountSA 148 } // namespace OHOS 149 150 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_MANAGER_SERVICE_H 151