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