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_INTERFACES_INNERKITS_OS_ACCOUNT_MANAGER_H 16 #define OS_ACCOUNT_INTERFACES_INNERKITS_OS_ACCOUNT_MANAGER_H 17 18 #include <string> 19 #include <vector> 20 #include "os_account_info.h" 21 #include "os_account_subscriber.h" 22 #include "account_error_no.h" 23 namespace OHOS { 24 namespace AccountSA { 25 class OsAccountManager { 26 public: 27 static ErrCode CreateOsAccount(const std::string &name, const OsAccountType &type, OsAccountInfo &osAccountInfo); 28 static ErrCode CreateOsAccountForDomain( 29 const OsAccountType &type, const DomainAccountInfo &domainInfo, OsAccountInfo &osAccountInfo); 30 static ErrCode RemoveOsAccount(const int id); 31 static ErrCode IsOsAccountExists(const int id, bool &isOsAccountExists); 32 static ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived); 33 static ErrCode IsOsAccountConstraintEnable(const int id, const std::string &constraint, bool &isConstraintEnable); 34 static ErrCode CheckOsAccountConstraintEnabled( 35 const int id, const std::string &constraint, bool &isEnabled); 36 static ErrCode IsOsAccountVerified(const int id, bool &isVerified); 37 static ErrCode GetCreatedOsAccountsCount(unsigned int &osAccountsCount); 38 static ErrCode GetOsAccountLocalIdFromProcess(int &id); 39 static ErrCode IsMainOsAccount(bool &isMainOsAccount); 40 static ErrCode GetOsAccountLocalIdFromUid(const int uid, int &id); 41 static ErrCode GetBundleIdFromUid(const int uid, int &bundleId); 42 static ErrCode GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id); 43 static ErrCode QueryMaxOsAccountNumber(int &maxOsAccountNumber); 44 static ErrCode GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints); 45 static ErrCode QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos); 46 static ErrCode QueryCurrentOsAccount(OsAccountInfo &osAccountInfo); 47 static ErrCode QueryOsAccountById(const int id, OsAccountInfo &osAccountInfo); 48 static ErrCode GetOsAccountTypeFromProcess(OsAccountType &type); 49 static ErrCode GetOsAccountProfilePhoto(const int id, std::string &photo); 50 static ErrCode IsMultiOsAccountEnable(bool &isMultiOsAccountEnable); 51 static ErrCode SetOsAccountName(const int id, const std::string &localName); 52 static ErrCode SetOsAccountConstraints( 53 const int id, const std::vector<std::string> &constraints, const bool enable); 54 static ErrCode SetOsAccountProfilePhoto(const int id, const std::string &photo); 55 static ErrCode GetDistributedVirtualDeviceId(std::string &deviceId); 56 static ErrCode ActivateOsAccount(const int id); 57 static ErrCode StartOsAccount(const int id); 58 static ErrCode StopOsAccount(const int id); 59 static ErrCode GetOsAccountLocalIdBySerialNumber(const int64_t serialNumber, int &id); 60 static ErrCode GetSerialNumberByOsAccountLocalId(const int &id, int64_t &serialNumber); 61 static ErrCode SubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> &subscriber); 62 static ErrCode UnsubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> &subscriber); 63 static OS_ACCOUNT_SWITCH_MOD GetOsAccountSwitchMod(); 64 static ErrCode IsCurrentOsAccountVerified(bool &isVerified); 65 static ErrCode IsOsAccountCompleted(const int id, bool &isOsAccountCompleted); 66 static ErrCode SetCurrentOsAccountIsVerified(const bool isVerified); 67 static ErrCode SetOsAccountIsVerified(const int id, const bool isVerified); 68 69 static ErrCode GetCreatedOsAccountNumFromDatabase(const std::string& storeID, int &createdOsAccountNum); 70 static ErrCode GetSerialNumberFromDatabase(const std::string& storeID, int64_t &serialNumber); 71 static ErrCode GetMaxAllowCreateIdFromDatabase(const std::string& storeID, int &id); 72 static ErrCode GetOsAccountFromDatabase(const std::string& storeID, 73 const int id, 74 OsAccountInfo &osAccountInfo); 75 static ErrCode GetOsAccountListFromDatabase(const std::string& storeID, 76 std::vector<OsAccountInfo> &osAccountList); 77 static ErrCode QueryActiveOsAccountIds(std::vector<int32_t>& ids); 78 static ErrCode QueryOsAccountConstraintSourceTypes(const int32_t id, const std::string constraint, 79 std::vector<ConstraintSourceTypeInfo> &constraintSourceTypeInfos); 80 static ErrCode SetGlobalOsAccountConstraints(const std::vector<std::string> &constraints, 81 const bool isEnabled, const int32_t enforcerId = 0, const bool isDeviceOwner = false); 82 static ErrCode SetSpecificOsAccountConstraints(const std::vector<std::string> &constraints, 83 const bool enable, const int32_t targetId, const int32_t enforcerId, const bool isDeviceOwner); 84 }; 85 } // namespace AccountSA 86 } // namespace OHOS 87 #endif // OS_ACCOUNT_INTERFACES_INNERKITS_OS_ACCOUNT_MANAGER_H 88