1 /* 2 * Copyright (c) 2021-2023 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 /** 17 * @addtogroup OhosAccount 18 * @{ 19 * 20 * @brief Provides ohos account management. 21 * 22 * Provides the capability to manage ohos accounts. 23 * 24 * @since 7.0 25 * @version 7.0 26 */ 27 28 /** 29 * @file ohos_account_kits.h 30 * 31 * @brief Declares ohos account interfaces. 32 * 33 * @since 7.0 34 * @version 7.0 35 */ 36 #ifndef BASE_ACCOUNT_OHOS_ACCOUNT_KITS_H 37 #define BASE_ACCOUNT_OHOS_ACCOUNT_KITS_H 38 39 #include "account_info.h" 40 #include "nocopyable.h" 41 42 namespace OHOS { 43 namespace AccountSA { 44 /** 45 * Interfaces for ohos account subsystem. 46 */ 47 class OhosAccountKits { 48 public: 49 virtual ~OhosAccountKits() = default; 50 DISALLOW_COPY_AND_MOVE(OhosAccountKits); 51 52 /** 53 * Get instance of ohos account manager. 54 * 55 * @return Instance of ohos account manager. 56 */ 57 static OhosAccountKits& GetInstance(); 58 59 /** 60 * Query OHOS Account Info. 61 * 62 * @param VOID. 63 * @return Return a pair of operation result and ohos account info. 64 */ 65 virtual std::pair<bool, OhosAccountInfo> QueryOhosAccountInfo() = 0; 66 67 /** 68 * Query OHOS Account Info. 69 * 70 * @param OhosAccountInfo. ohos account info 71 * @return Return error code. 72 */ 73 virtual ErrCode GetOhosAccountInfo(OhosAccountInfo &accountInfo) = 0; 74 75 /** 76 * Get OHOS account info by user id. 77 * 78 * @param OhosAccountInfo. ohos account info 79 * @return Return error code. 80 */ 81 virtual ErrCode GetOhosAccountInfoByUserId(int32_t userId, OhosAccountInfo &accountInfo) = 0; 82 83 /** 84 * Query OHOS Account Info By user ID. 85 * 86 * @param userId. target local user id 87 * @return Return a pair of operation result and ohos account info. 88 */ 89 virtual std::pair<bool, OhosAccountInfo> QueryOhosAccountInfoByUserId(std::int32_t userId) = 0; 90 91 /** 92 * Update OHOS Account Info. 93 * 94 * @param accountName Indicates the name of the OS account used for a distributed system. 95 * @param uid Uniquely identifies the OS account used for a distributed system. 96 * @param eventStr Indicates the event of the OS account used for a distributed system. 97 * @return Returns {@code true} if the distributed information of the account is updated; 98 * returns {@code false} otherwise. 99 */ 100 virtual bool UpdateOhosAccountInfo(const std::string& accountName, const std::string& uid, 101 const std::string& eventStr) = 0; 102 103 /** 104 * Update OHOS Account Info. 105 * 106 * @param ohosAccountInfo Indicates the information of the distributed account. 107 * Update OHOS Account Info. 108 * @param eventStr Indicates the event of the OS account used for a distributed system. 109 * @return Returns {@code true} if the distributed information of the account is updated; 110 * returns {@code false} otherwise. 111 */ 112 virtual std::int32_t SetOhosAccountInfo(const OhosAccountInfo &ohosAccountInfo, 113 const std::string &eventStr) = 0; 114 115 /** 116 * Sets OHOS Account Info. 117 * 118 * @param userId target local account id. 119 * @param ohosAccountInfo Indicates the information of the distributed account. 120 * Update OHOS Account Info. 121 * @param eventStr Indicates the event of the OS account used for a distributed system. 122 * @return Returns {@code true} if the distributed information of the account is updated; 123 * returns {@code false} otherwise. 124 */ 125 virtual ErrCode SetOhosAccountInfoByUserId( 126 const int32_t userId, const OhosAccountInfo& ohosAccountInfo, const std::string& eventStr) = 0; 127 128 /** 129 * Query Device Account Id. 130 * 131 * @param device account id. 132 * @return if succeed, return ERR_OK and device account Id. 133 */ 134 virtual ErrCode QueryDeviceAccountId(std::int32_t& accountId) = 0; 135 136 /** 137 * Transform uid to device account id. 138 * 139 * @param process calling uid. 140 * @return transformed device account Id 141 */ 142 virtual std::int32_t GetDeviceAccountIdByUID(std::int32_t& uid) = 0; 143 protected: 144 OhosAccountKits() = default; 145 }; 146 } // namespace AccountSA 147 } // namespace OHOS 148 149 #endif // BASE_ACCOUNT_OHOS_ACCOUNT_KITS_H 150