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 OsAccount 18 * @{ 19 * 20 * @brief Provides os account management. 21 * 22 * Provides abilities for you to manage and perform operations on your OS accounts. 23 * 24 * @since 7.0 25 * @version 7.0 26 */ 27 28 /** 29 * @file os_account_manager.h 30 * 31 * @brief Declares os account manager interfaces. 32 * 33 * @since 7.0 34 * @version 7.0 35 */ 36 37 #ifndef OS_ACCOUNT_INTERFACES_INNERKITS_OS_ACCOUNT_MANAGER_H 38 #define OS_ACCOUNT_INTERFACES_INNERKITS_OS_ACCOUNT_MANAGER_H 39 40 #include <string> 41 #include <vector> 42 #include "domain_account_callback.h" 43 #include "os_account_info.h" 44 #include "os_account_subscriber.h" 45 #include "account_error_no.h" 46 namespace OHOS { 47 namespace AccountSA { 48 class OsAccountManager { 49 public: 50 /** 51 * @brief Creates an OS account using the local name and account type. 52 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 53 * @param localName - Indicates the local name of the OS account to create. 54 * @param type - Indicates the type of the OS account to create. 55 * @param osAccountInfo - Indicates the information about the created OS account. 56 * @return error code, see account_error_no.h 57 */ 58 static ErrCode CreateOsAccount(const std::string &name, const OsAccountType &type, OsAccountInfo &osAccountInfo); 59 60 /** 61 * @brief Creates an OS account using the account type and domain account info. 62 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 63 * @param type - Indicates the type of the OS account to create. 64 * @param domainInfo - Indicates the domain account info. 65 * @param callback - Indicates the callback for getting the information of the created OS account. 66 * @return error code, see account_error_no.h 67 */ 68 static ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo, 69 const std::shared_ptr<DomainAccountCallback> &callback); 70 71 /** 72 * @brief Removes an OS account based on its local ID. 73 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 74 * @param id - Indicates the local ID of the OS account. 75 * @return error code, see account_error_no.h 76 */ 77 static ErrCode RemoveOsAccount(const int id); 78 79 /** 80 * @brief Checks whether the specified OS account exists. 81 * @param id - Indicates the local ID of the OS account. 82 * @param isOsAccountExists - Indicates whether the specified OS account exists. 83 * @return error code, see account_error_no.h 84 */ 85 static ErrCode IsOsAccountExists(const int id, bool &isOsAccountExists); 86 87 /** 88 * @brief Checks whether an OS account is activated based on its local ID. 89 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 90 * @param id - Indicates the local ID of the OS account. 91 * @param isOsAccountActived - Indicates whether the OS account is activated. 92 * @return error code, see account_error_no.h 93 */ 94 static ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived); 95 96 /** 97 * @brief Checks whether the specified constraint is enabled for the specified OS account. 98 * @param id - Indicates the local ID of the OS account. 99 * @param constriaint - Indicates the constraint. 100 * @param isConstraintEnable - Indicates whether the specified constraint is enabled. 101 * @return error code, see account_error_no.h 102 */ 103 static ErrCode IsOsAccountConstraintEnable(const int id, const std::string &constraint, bool &isConstraintEnable); 104 105 /** 106 * @brief Checks whether the specified constraint is enabled for the specified OS account. 107 * @param id - Indicates the local ID of the OS account. 108 * @param constriaint - Indicates the constraint. 109 * @param isEnabled - Indicates whether the specified constraint is enabled. 110 * @return error code, see account_error_no.h 111 */ 112 static ErrCode CheckOsAccountConstraintEnabled( 113 const int id, const std::string &constraint, bool &isEnabled); 114 115 /** 116 * @brief Checks whether the specified OS account is verified. 117 * @param id - Indicates the local ID of the OS account. 118 * @param isVerified - Indicates whether the current OS account is verified. 119 * @return error code, see account_error_no.h 120 */ 121 static ErrCode IsOsAccountVerified(const int id, bool &isVerified); 122 123 /** 124 * @brief Gets the number of all OS accounts created on a device. 125 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 126 * @param osAccountsCount - Returns the number of created OS accounts. 127 * @return error code, see account_error_no.h 128 */ 129 static ErrCode GetCreatedOsAccountsCount(unsigned int &osAccountsCount); 130 131 /** 132 * @brief Gets the local ID of the current OS account. 133 * @param id - Indicates the local ID of the current OS account. 134 * @return error code, see account_error_no.h 135 */ 136 static ErrCode GetOsAccountLocalIdFromProcess(int &id); 137 138 /** 139 * @brief Checks whether current process belongs to the main account. 140 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 141 * @param isMainOsAccount - Indicates whether the current process belongs to the main OS account. 142 * @return error code, see account_error_no.h 143 */ 144 static ErrCode IsMainOsAccount(bool &isMainOsAccount); 145 146 /** 147 * @brief Gets the local ID of an OS account from the process UID 148 * @param uid - Indicates the process UID. 149 * @param id - Indicates the local ID of the OS account associated with the specified UID. 150 * @return error code, see account_error_no.h 151 */ 152 static ErrCode GetOsAccountLocalIdFromUid(const int uid, int &id); 153 154 /** 155 * @brief Gets the bundle ID associated with the specified UID. 156 * @param uid - Indicates the target uid. 157 * @param bundleId - Indicates the bundle ID associated with the specified UID. 158 * @return error code, see account_error_no.h 159 */ 160 static ErrCode GetBundleIdFromUid(const int uid, int &bundleId); 161 162 /** 163 * @brief Gets the local ID of the OS account associated with the specified domain account. 164 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 165 * @param domainInfo - Indicates the domain account info. 166 * @param id - Indicates the local ID of the OS account associated with the specified domain account. 167 * @return error code, see account_error_no.h 168 */ 169 static ErrCode GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id); 170 171 /** 172 * @brief Queries the maximum number of OS accounts that can be created on a device. 173 * @param maxOsAccountNumber - Returns the maximum number of OS accounts that can be created. 174 * @return error code, see account_error_no.h 175 */ 176 static ErrCode QueryMaxOsAccountNumber(int &maxOsAccountNumber); 177 178 /** 179 * @brief Gets all constraints of an account based on its ID. 180 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 181 * @param localId - Indicates the local ID of the OS account. 182 * @param constraints - Indicates a list of constraints. 183 * @return error code, see account_error_no.h 184 */ 185 static ErrCode GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints); 186 187 /** 188 * @brief Queries the list of all the OS accounts that have been created in the system. 189 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 190 * @param osAccountInfos - Indicates a list of OS accounts. 191 * @return error code, see account_error_no.h 192 */ 193 static ErrCode QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos); 194 195 /** 196 * @brief Gets information about the current OS account. 197 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 198 * @param osAccountInfo - Indicates the information about the current OS account. 199 * @return error code, see account_error_no.h 200 */ 201 static ErrCode QueryCurrentOsAccount(OsAccountInfo &osAccountInfo); 202 203 /** 204 * @brief Queries OS account information based on the local ID. 205 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 206 * @param localId - Indicates the local ID of the OS account. 207 * @param osAccountInfo - Indicates the OS account information. 208 * @return error code, see account_error_no.h 209 */ 210 static ErrCode QueryOsAccountById(const int id, OsAccountInfo &osAccountInfo); 211 212 /** 213 * @brief Gets the type of this OS account from the current process. 214 * @param type - Indicates the OS account type. 215 * @return error code, see account_error_no.h 216 */ 217 static ErrCode GetOsAccountTypeFromProcess(OsAccountType &type); 218 219 /** 220 * @brief Gets the profile photo of an OS account based on its local ID. 221 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 222 * @param id - Indicates the local ID of the OS account. 223 * @param photo - Indicates the profile photo. 224 * @return error code, see account_error_no.h 225 */ 226 static ErrCode GetOsAccountProfilePhoto(const int id, std::string &photo); 227 228 /** 229 * @brief Checks whether the function of supporting multiple OS accounts is enabled. 230 * @param isMultiOsAccountEnable - Indicates whether multiple OS account feature is enabled. 231 * @return error code, see account_error_no.h 232 */ 233 static ErrCode IsMultiOsAccountEnable(bool &isMultiOsAccountEnable); 234 235 /** 236 * @brief Sets the local name for an OS account based on its local ID. 237 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 238 * @param localId - Indicates the local ID of the OS account. 239 * @param localName - Indicates the local name to set for the OS account. 240 * @return error code, see account_error_no.h 241 */ 242 static ErrCode SetOsAccountName(const int id, const std::string &localName); 243 244 /** 245 * @brief Sets constraints for an OS account based on its local ID. 246 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 247 * @param localId - Indicates the local ID of the OS account. 248 * @param constraints - Indicates the constraints to set for the OS account. The value can be: 249 * <ul> 250 * <li>{@code constraint.wifi.set} - Indicates the constraint on configuring the Wi-Fi access point. 251 * </li> 252 * <li>{@code constraint.sms.use} - Indicates the constraint on sending and receiving short messages. 253 * </li> 254 * <li>{@code constraint.calls.outgoing} - Indicates the constraint on making calls.</li> 255 * <li>{@code constraint.unknown.sources.install} - Indicates the constraint on installing applications 256 * from unknown sources.</li> 257 * </ul> 258 * @param enable - Specifies whether to enable the constraint. 259 * @return error code, see account_error_no.h 260 */ 261 static ErrCode SetOsAccountConstraints( 262 const int id, const std::vector<std::string> &constraints, const bool enable); 263 264 /** 265 * @brief Sets the profile photo for an OS account based on its local ID. 266 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 267 * @param localId - Indicates the local ID of the OS account. 268 * @param photo - Indicates the profile photo to set for the OS account. 269 * @return error code, see account_error_no.h 270 */ 271 static ErrCode SetOsAccountProfilePhoto(const int id, const std::string &photo); 272 273 /** 274 * @brief Gets the distributed virtual device ID (DVID). 275 * <p> 276 * If the same OHOS account has logged in to multiple devices, these devices constitute a super device 277 * through the distributed networking. On the connected devices, you can call this method to obtain the DVIDs. 278 * The same application running on different devices obtains the same DVID, whereas different applications 279 * obtain different DVIDs. 280 * <p> 281 * 282 * @permission ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS 283 * @param deviceId - Indicates the DVID if obtained; returns an empty string if no OHOS account has logged in. 284 * @return error code, see account_error_no.h 285 */ 286 static ErrCode GetDistributedVirtualDeviceId(std::string &deviceId); 287 288 /** 289 * @brief Activates a specified OS account. 290 * <p> 291 * If multiple OS accounts are available, you can call this method to enable a specific OS account 292 * to run in the foreground. Then, the OS account originally running in the foreground will be 293 * switched to the background. 294 * </p> 295 * 296 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 297 * @param id - Indicates the local ID of the OS account. 298 * @param callback - Asynchronous callback interface. 299 * @return error code, see account_error_no.h 300 */ 301 static ErrCode ActivateOsAccount(const int id); 302 303 /** 304 * @brief Starts the specified OS account. 305 * @param id - Indicates the local ID of the OS account. 306 * @return error code, see account_error_no.h 307 */ 308 static ErrCode StartOsAccount(const int id); 309 310 /** 311 * @brief Stops the specified OS account. 312 * @param id - Indicates the local ID of the OS account. 313 * @return error code, see account_error_no.h 314 */ 315 static ErrCode StopOsAccount(const int id); 316 317 /** 318 * @brief Gets localId according to serial number. 319 * @param serialNumber - Indicates serial number. 320 * @param id - Indicates the local ID of the OS account. 321 * @return error code, see account_error_no.h 322 */ 323 static ErrCode GetOsAccountLocalIdBySerialNumber(const int64_t serialNumber, int &id); 324 325 /** 326 * @brief Gets serial number according to localId. 327 * @param localId - Indicates the local ID of the OS account. 328 * @param serialNumber - Indicates the serial number. 329 * @return error code, see account_error_no.h 330 */ 331 static ErrCode GetSerialNumberByOsAccountLocalId(const int &id, int64_t &serialNumber); 332 333 /** 334 * @brief Subscribes the event of an OS account by the subscriber. 335 * @param subscriber subscriber information 336 * @return error code, see account_error_no.h 337 */ 338 static ErrCode SubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> &subscriber); 339 340 /** 341 * @brief Unsubscribes the event of an OS account by the subscriber. 342 * @param subscriber subscriber information 343 * @return error code, see account_error_no.h 344 */ 345 static ErrCode UnsubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> &subscriber); 346 347 /** 348 * @brief Gets the OS account switch mode. 349 * @return switch mode 350 */ 351 static OS_ACCOUNT_SWITCH_MOD GetOsAccountSwitchMod(); 352 353 /** 354 * @brief Checks whether the current OS account is verified. 355 * @param isVerified - Indicates whether the current OS account is verified. 356 * @return error code, see account_error_no.h 357 */ 358 static ErrCode IsCurrentOsAccountVerified(bool &isVerified); 359 360 /** 361 * @brief Checks whether the specified OS account is created completely. 362 * @param id - Indicates the local ID of the specified OS account. 363 * @param isOsAccountCompleted - Indicates whether the current OS account is created completely. 364 * @return error code, see account_error_no.h 365 */ 366 static ErrCode IsOsAccountCompleted(const int id, bool &isOsAccountCompleted); 367 368 /** 369 * @brief Sets the current OS account to be verified. 370 * @param isVerified - Indicates whether the current OS account is verified. 371 * @return error code, see account_error_no.h 372 */ 373 static ErrCode SetCurrentOsAccountIsVerified(const bool isVerified); 374 375 /** 376 * @brief Sets the specified OS account to be verified. 377 * @param id - Indicates the local ID of the specified OS account. 378 * @param isVerified - Indicates whether the current OS account is verified. 379 * @return error code, see account_error_no.h 380 */ 381 static ErrCode SetOsAccountIsVerified(const int id, const bool isVerified); 382 383 /** 384 * @brief Gets the number of the created OS account from database. 385 * @param storeID - Indicates the store ID. 386 * @param id - Indicates the number of the created OS account. 387 * @return error code, see account_error_no.h 388 */ 389 static ErrCode GetCreatedOsAccountNumFromDatabase(const std::string& storeID, int &createdOsAccountNum); 390 391 /** 392 * @brief Get serial number from database. 393 * @param storeID - Indicates the store ID. 394 * @param serialNumber - Indicates the serial number. 395 * @return error code, see account_error_no.h 396 */ 397 static ErrCode GetSerialNumberFromDatabase(const std::string& storeID, int64_t &serialNumber); 398 399 /** 400 * @brief Gets the max ID of the OS account to be created. 401 * @param storeID - Indicates the store ID. 402 * @param id - Indicates the max ID of the OS account to be created. 403 * @return error code, see account_error_no.h 404 */ 405 static ErrCode GetMaxAllowCreateIdFromDatabase(const std::string& storeID, int &id); 406 407 /** 408 * @brief Sets the specified OS account from database. 409 * @param storeID - Indicates the store ID. 410 * @param id - Indicates the local ID of the specified OS account. 411 * @param osAccountInfo - Indicates the OS account information. 412 * @return error code, see account_error_no.h 413 */ 414 static ErrCode GetOsAccountFromDatabase(const std::string& storeID, const int id, OsAccountInfo &osAccountInfo); 415 416 /** 417 * @brief Get a list of OS accounts from database. 418 * @param storeID - Indicates the store ID. 419 * @param osAccountList - Indicates a list of OS accounts. 420 * @return error code, see account_error_no.h 421 */ 422 static ErrCode GetOsAccountListFromDatabase(const std::string& storeID, std::vector<OsAccountInfo> &osAccountList); 423 424 /** 425 * @brief Gets the local IDs of all activated OS accounts. 426 * @param ids - Indicates the local IDs of all activated OS accounts. 427 * @return error code, see account_error_no.h 428 */ 429 static ErrCode QueryActiveOsAccountIds(std::vector<int32_t>& ids); 430 431 /** 432 * @brief Gets a list of constraint source types for the specified os account. 433 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 434 * @param localId - Indicates the local ID of the OS account. 435 * @param constraint - Indicates the constraint to query the source type. 436 * @param constraintSourceTypeInfos - Indicates the list of constraint source types for the specified os account. 437 * @return error code, see account_error_no.h 438 */ 439 static ErrCode QueryOsAccountConstraintSourceTypes(const int32_t id, const std::string constraint, 440 std::vector<ConstraintSourceTypeInfo> &constraintSourceTypeInfos); 441 442 /** 443 * @brief Sets the global constraints for all OS accounts. 444 * @param constraints - Indicates the local IDs of all activated OS accounts. 445 * @param isEnabled - Indicates whether the constraints are enabled. 446 * @param enforcerId - Indicates the local ID of the OS account who enforce the operation. 447 * @param isDeviceOwner - Indicates whether the enforcer is device owner. 448 * @return error code, see account_error_no.h 449 */ 450 static ErrCode SetGlobalOsAccountConstraints(const std::vector<std::string> &constraints, 451 const bool isEnabled, const int32_t enforcerId = 0, const bool isDeviceOwner = false); 452 453 /** 454 * @brief Sets the constraints for the specified OS accounts. 455 * @param constraints - Indicates the local IDs of all activated OS accounts. 456 * @param enable - Indicates whether the constraints are enabled. 457 * @param targetId - Indicates the local ID of the target OS account. 458 * @param enforcerId - Indicates the local ID of the OS account who enforce the operation. 459 * @param isDeviceOwner - Indicates whether the enforcer is device owner. 460 * @return error code, see account_error_no.h 461 */ 462 static ErrCode SetSpecificOsAccountConstraints(const std::vector<std::string> &constraints, 463 const bool enable, const int32_t targetId, const int32_t enforcerId, const bool isDeviceOwner); 464 465 /** 466 * @brief Sets the default activated OS account. 467 * @param id - Indicates the local IDs of the default activated OS accounts. 468 * @return error code, see account_error_no.h 469 */ 470 static ErrCode SetDefaultActivatedOsAccount(const int32_t id); 471 472 /** 473 * @brief Gets the default activated OS account. 474 * @param id - Indicates the local IDs of the default activated OS accounts. 475 * @return error code, see account_error_no.h 476 */ 477 static ErrCode GetDefaultActivatedOsAccount(int32_t &id); 478 }; 479 } // namespace AccountSA 480 } // namespace OHOS 481 #endif // OS_ACCOUNT_INTERFACES_INNERKITS_OS_ACCOUNT_MANAGER_H 482