1 /* 2 * Copyright (c) 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 OHOS_ABILITY_RUNTIME_OS_ACCOUNT_MANAGER_WRAPPER_H 17 #define OHOS_ABILITY_RUNTIME_OS_ACCOUNT_MANAGER_WRAPPER_H 18 19 #include <vector> 20 21 #include "errors.h" 22 #include "singleton.h" 23 24 namespace OHOS { 25 namespace AppExecFwk { 26 class OsAccountManagerWrapper : public DelayedSingleton<OsAccountManagerWrapper> { 27 public: 28 OsAccountManagerWrapper() = default; 29 virtual ~OsAccountManagerWrapper() = default; 30 31 /** 32 * @brief Gets the local IDs of all activated OS accounts. 33 * 34 * @param ids The local IDs of all activated OS accounts. 35 * @return error code, ERR_OK on success, others on failure. 36 */ 37 ErrCode QueryActiveOsAccountIds(std::vector<int32_t>& ids); 38 39 /** 40 * @brief Gets the local ID of an OS account from the process UID 41 * 42 * @param uid The process UID. 43 * @param id The local ID of the OS account associated with the specified UID. 44 * @return error code, ERR_OK on success, others on failure. 45 */ 46 ErrCode GetOsAccountLocalIdFromUid(const int32_t uid, int32_t &id); 47 48 /** 49 * @brief Gets the local ID of the current OS account. 50 * 51 * @param id The local ID of the current OS account. 52 * @return error code, ERR_OK on success, others on failure. 53 */ 54 ErrCode GetOsAccountLocalIdFromProcess(int &id); 55 56 /** 57 * @brief Checks whether the specified OS account exists. 58 * 59 * @param id The local ID of the OS account. 60 * @param isOsAccountExists Indicates whether the specified OS account exists. 61 * @return error code, ERR_OK on success, others on failure. 62 */ 63 ErrCode IsOsAccountExists(const int id, bool &isOsAccountExists); 64 65 /** 66 * @brief Creates an OS account using the local name and account type. 67 * 68 * @param name The name of the OS account to create. 69 * @param osAccountUserId The local id of the created OS account. 70 * @return error code, ERR_OK on success, others on failure. 71 */ 72 ErrCode CreateOsAccount(const std::string &name, int32_t &osAccountUserId); 73 74 /** 75 * @brief Removes an OS account based on its local ID. 76 * 77 * @param id The local ID of the OS account. 78 * @return error code, ERR_OK on success, others on failure. 79 */ 80 ErrCode RemoveOsAccount(const int id); 81 82 /** 83 * @brief Get the current active user ID. 84 * 85 * @return int32_t user ID 86 */ 87 static int32_t GetCurrentActiveAccountId(); 88 }; 89 } // namespace AppExecFwk 90 } // namespace OHOS 91 #endif // OHOS_ABILITY_RUNTIME_OS_ACCOUNT_MANAGER_WRAPPER_H