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 BASE_ACCOUNT_OHOS_ACCOUNT_KITS_H 17 #define BASE_ACCOUNT_OHOS_ACCOUNT_KITS_H 18 19 #include "account_info.h" 20 #include "nocopyable.h" 21 #include "iaccount.h" 22 23 namespace OHOS { 24 namespace AccountSA { 25 /** 26 * Interfaces for ohos account subsystem. 27 */ 28 class OhosAccountKits { 29 public: 30 virtual ~OhosAccountKits() = default; 31 DISALLOW_COPY_AND_MOVE(OhosAccountKits); 32 33 /** 34 * Get instance of ohos account manager. 35 * 36 * @return Instance of ohos account manager. 37 */ 38 static OhosAccountKits& GetInstance(); 39 40 /** 41 * Query OHOS Account Info. 42 * 43 * @param VOID. 44 * @return Return a pair of operation result and ohos account info. 45 */ 46 virtual std::pair<bool, OhosAccountInfo> QueryOhosAccountInfo() = 0; 47 48 /** 49 * Query OHOS Account Info. 50 * 51 * @param OhosAccountInfo. ohos account info 52 * @return Return error code. 53 */ 54 virtual ErrCode GetOhosAccountInfo(OhosAccountInfo &accountInfo) = 0; 55 56 /** 57 * Get OHOS account info by user id. 58 * 59 * @param OhosAccountInfo. ohos account info 60 * @return Return error code. 61 */ 62 virtual ErrCode GetOhosAccountInfoByUserId(int32_t userId, OhosAccountInfo &accountInfo) = 0; 63 64 /** 65 * Query OHOS Account Info By user ID. 66 * 67 * @param userId. target local user id 68 * @return Return a pair of operation result and ohos account info. 69 */ 70 virtual std::pair<bool, OhosAccountInfo> QueryOhosAccountInfoByUserId(std::int32_t userId) = 0; 71 72 /** 73 * Update OHOS Account Info. 74 * 75 * @param accountName Indicates the name of the OS account used for a distributed system. 76 * @param uid Uniquely identifies the OS account used for a distributed system. 77 * @param eventStr Indicates the event of the OS account used for a distributed system. 78 * @return Returns {@code true} if the distributed information of the account is updated; 79 * returns {@code false} otherwise. 80 */ 81 virtual bool UpdateOhosAccountInfo(const std::string& accountName, const std::string& uid, 82 const std::string& eventStr) = 0; 83 84 /** 85 * Update OHOS Account Info. 86 * 87 * @param ohosAccountInfo Indicates the information of the disctributed account. 88 * Update OHOS Account Info. 89 * @param eventStr Indicates the event of the OS account used for a distributed system. 90 * @return Returns {@code true} if the distributed information of the account is updated; 91 * returns {@code false} otherwise. 92 */ 93 virtual std::int32_t SetOhosAccountInfo(const OhosAccountInfo &ohosAccountInfo, 94 const std::string &eventStr) = 0; 95 96 /** 97 * Query Device Account Id. 98 * 99 * @param device account id. 100 * @return if succeed, return ERR_OK and device account Id. 101 */ 102 virtual ErrCode QueryDeviceAccountId(std::int32_t& accountId) = 0; 103 104 /** 105 * Transform uid to device account id. 106 * 107 * @param process calling uid. 108 * @return transformed device account Id 109 */ 110 virtual std::int32_t GetDeviceAccountIdByUID(std::int32_t& uid) = 0; 111 protected: 112 OhosAccountKits() = default; 113 }; 114 } // namespace AccountSA 115 } // namespace OHOS 116 117 #endif // BASE_ACCOUNT_OHOS_ACCOUNT_KITS_H 118