1 /* 2 * Copyright (c) 2021-2025 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_constraint_subscriber.h" 44 #include "os_account_info.h" 45 #include "os_account_subscriber.h" 46 #include "account_error_no.h" 47 namespace OHOS { 48 namespace AccountSA { 49 class OsAccountManager { 50 public: 51 /** 52 * @brief Creates an OS account using the local name and account type. 53 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 54 * @param localName - Indicates the local name of the OS account to create. 55 * @param type - Indicates the type of the OS account to create. 56 * @param osAccountInfo - Indicates the information about the created OS account. 57 * @return error code, see account_error_no.h 58 */ 59 static ErrCode CreateOsAccount(const std::string &name, const OsAccountType &type, OsAccountInfo &osAccountInfo); 60 61 /** 62 * @brief Creates an OS account using the local name, short name and account type. 63 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 64 * @param localName - Indicates the local name of the OS account to create. 65 * @param shortName - Indicates the short name of the OS account to create. 66 * @param type - Indicates the type of the OS account to create. 67 * @param osAccountInfo - Indicates the information about the created OS account. 68 * @return error code, see account_error_no.h 69 */ 70 static ErrCode CreateOsAccount(const std::string& localName, const std::string& shortName, 71 const OsAccountType& type, OsAccountInfo& osAccountInfo); 72 73 /** 74 * @brief Creates an OS account using the local name, short name, account type and other options. 75 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 76 * @param localName - Indicates the local name of the OS account to create. 77 * @param shortName - Indicates the short name of the OS account to create. 78 * @param type - Indicates the type of the OS account to create. 79 * @param options - Indicates the options of the OS account to create. 80 * - Include disallowedHapList - Indicates the disallowed install hap list. 81 * @param osAccountInfo - Indicates the information about the created OS account. 82 * @return error code, see account_error_no.h 83 */ 84 static ErrCode CreateOsAccount(const std::string& localName, const std::string& shortName, 85 const OsAccountType& type, const CreateOsAccountOptions& options, OsAccountInfo& osAccountInfo); 86 87 /** 88 * @brief Creates an OS account using full user info 89 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 90 * @param osAccountInfo - Indicates the information about the created OS account. 91 * @return error code, see account_error_no.h 92 */ 93 static ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo, 94 const CreateOsAccountOptions& options = {}); 95 96 /** 97 * @brief Updates an OS account using full user info 98 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 99 * @param osAccountInfo - Indicates the information about the created OS account. 100 * @return error code, see account_error_no.h 101 */ 102 static ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo); 103 104 /** 105 * @brief Creates an OS account using the account type and domain account info. 106 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 107 * @param type - Indicates the type of the OS account to create. 108 * @param domainInfo - Indicates the domain account info. 109 * @param callback - Indicates the callback for getting the information of the created OS account. 110 * @return error code, see account_error_no.h 111 */ 112 static ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo, 113 const std::shared_ptr<DomainAccountCallback> &callback, const CreateOsAccountForDomainOptions& options = {}); 114 115 /** 116 * @brief Removes an OS account based on its local ID. 117 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 118 * @param id - Indicates the local ID of the OS account. 119 * @return error code, see account_error_no.h 120 */ 121 static ErrCode RemoveOsAccount(const int id); 122 123 /** 124 * @brief Checks whether the specified OS account exists. 125 * @param id - Indicates the local ID of the OS account. 126 * @param isOsAccountExists - Indicates whether the specified OS account exists. 127 * @return error code, see account_error_no.h 128 */ 129 static ErrCode IsOsAccountExists(const int id, bool &isOsAccountExists); 130 131 /** 132 * @brief Checks whether an OS account is activated based on its local ID. 133 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 134 * @param id - Indicates the local ID of the OS account. 135 * @param isOsAccountActived - Indicates whether the OS account is activated. 136 * @return error code, see account_error_no.h 137 */ 138 static ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived); 139 140 /** 141 * @brief Checks whether the specified constraint is enabled for the specified OS account. 142 * @param id - Indicates the local ID of the OS account. 143 * @param constriaint - Indicates the constraint. 144 * @param isConstraintEnable - Indicates whether the specified constraint is enabled. 145 * @return error code, see account_error_no.h 146 */ 147 static ErrCode IsOsAccountConstraintEnable(const int id, const std::string &constraint, bool &isConstraintEnable); 148 149 /** 150 * @brief Checks whether the specified constraint is enabled for the specified OS account. 151 * @param id - Indicates the local ID of the OS account. 152 * @param constriaint - Indicates the constraint. 153 * @param isEnabled - Indicates whether the specified constraint is enabled. 154 * @return error code, see account_error_no.h 155 */ 156 static ErrCode CheckOsAccountConstraintEnabled( 157 const int id, const std::string &constraint, bool &isEnabled); 158 159 /** 160 * @brief Checks whether the specified OS account is verified. 161 * @param id - Indicates the local ID of the OS account. 162 * @param isVerified - Indicates whether the current OS account is verified. 163 * @return error code, see account_error_no.h 164 */ 165 static ErrCode IsOsAccountVerified(const int id, bool &isVerified); 166 167 /** 168 * @brief Checks whether the specified OS account is deactivating. 169 * @param id - Indicates the local ID of the OS account. 170 * @param isDeactivating - Indicates whether the current OS account is deactivating. 171 * @return error code, see account_error_no.h 172 */ 173 static ErrCode IsOsAccountDeactivating(const int id, bool &isDeactivating); 174 175 /** 176 * @brief Gets the number of all OS accounts created on a device. 177 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 178 * @param osAccountsCount - Returns the number of created OS accounts. 179 * @return error code, see account_error_no.h 180 */ 181 static ErrCode GetCreatedOsAccountsCount(unsigned int &osAccountsCount); 182 183 /** 184 * @brief Gets the local ID of the current OS account. 185 * @param id - Indicates the local ID of the current OS account. 186 * @return error code, see account_error_no.h 187 */ 188 static ErrCode GetOsAccountLocalIdFromProcess(int &id); 189 190 /** 191 * @brief Checks whether current process belongs to the main account. 192 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 193 * @param isMainOsAccount - Indicates whether the current process belongs to the main OS account. 194 * @return error code, see account_error_no.h 195 */ 196 static ErrCode IsMainOsAccount(bool &isMainOsAccount); 197 198 /** 199 * @brief Gets the local ID of an OS account from the process UID 200 * @param uid - Indicates the process UID. 201 * @param id - Indicates the local ID of the OS account associated with the specified UID. 202 * @return error code, see account_error_no.h 203 */ 204 static ErrCode GetOsAccountLocalIdFromUid(const int uid, int &id); 205 206 /** 207 * @brief Gets the bundle ID associated with the specified UID. 208 * @param uid - Indicates the target uid. 209 * @param bundleId - Indicates the bundle ID associated with the specified UID. 210 * @return error code, see account_error_no.h 211 */ 212 static ErrCode GetBundleIdFromUid(const int uid, int &bundleId); 213 214 /** 215 * @brief Gets the local ID of the OS account associated with the specified domain account. 216 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 217 * @param domainInfo - Indicates the domain account info. 218 * @param id - Indicates the local ID of the OS account associated with the specified domain account. 219 * @return error code, see account_error_no.h 220 */ 221 static ErrCode GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id); 222 223 /** 224 * @brief Queries the maximum number of OS accounts that can be created on a device. 225 * @param maxOsAccountNumber - Returns the maximum number of OS accounts that can be created. 226 * @return error code, see account_error_no.h 227 */ 228 static ErrCode QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber); 229 230 /** 231 * @brief Queries the maximum number of OS accounts that can be logged in. 232 * @param maxNum - Returns the maximum number of OS accounts that can be created. 233 * @return error code, see account_error_no.h 234 */ 235 static ErrCode QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum); 236 237 /** 238 * @brief Gets all constraints of an account based on its ID. 239 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 240 * @param localId - Indicates the local ID of the OS account. 241 * @param constraints - Indicates a list of constraints. 242 * @return error code, see account_error_no.h 243 */ 244 static ErrCode GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints); 245 246 /** 247 * @brief Queries the list of all the OS accounts that have been created in the system. 248 * @selinux The caller needs to configure selinux permissions: allow Caller_SA_Name accountmgr:fd {use}. 249 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 250 * @param osAccountInfos - Indicates a list of OS accounts. 251 * @return error code, see account_error_no.h 252 */ 253 static ErrCode QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos); 254 255 /** 256 * @brief Gets information about the current OS account. 257 * @selinux The caller needs to configure selinux permissions: allow Caller_SA_Name accountmgr:fd {use}. 258 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 259 * @param osAccountInfo - Indicates the information about the current OS account. 260 * @return error code, see account_error_no.h 261 */ 262 static ErrCode QueryCurrentOsAccount(OsAccountInfo &osAccountInfo); 263 264 /** 265 * @brief Queries OS account information based on the local ID. 266 * @selinux The caller needs to configure selinux permissions: allow Caller_SA_Name accountmgr:fd {use}. 267 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 268 * @param localId - Indicates the local ID of the OS account. 269 * @param osAccountInfo - Indicates the OS account information. 270 * @return error code, see account_error_no.h 271 */ 272 static ErrCode QueryOsAccountById(const int id, OsAccountInfo &osAccountInfo); 273 274 /** 275 * @brief Gets the type of this OS account from the current process. 276 * @param type - Indicates the OS account type. 277 * @return error code, see account_error_no.h 278 */ 279 static ErrCode GetOsAccountTypeFromProcess(OsAccountType &type); 280 281 /** 282 * @brief Gets the type of this OS account from the current process. 283 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 284 * @param id - Indicates the local ID of the OS account. 285 * @param type - Indicates the OS account type. 286 * @return error code, see account_error_no.h 287 */ 288 static ErrCode GetOsAccountType(const int id, OsAccountType& type); 289 290 /** 291 * @brief Gets the profile photo of an OS account based on its local ID. 292 * @selinux The caller needs to configure selinux permissions: allow Caller_SA_Name accountmgr:fd {use}. 293 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 294 * @param id - Indicates the local ID of the OS account. 295 * @param photo - Indicates the profile photo. 296 * @return error code, see account_error_no.h 297 */ 298 static ErrCode GetOsAccountProfilePhoto(const int id, std::string &photo); 299 300 /** 301 * @brief Checks whether the function of supporting multiple OS accounts is enabled. 302 * @param isMultiOsAccountEnable - Indicates whether multiple OS account feature is enabled. 303 * @return error code, see account_error_no.h 304 */ 305 static ErrCode IsMultiOsAccountEnable(bool &isMultiOsAccountEnable); 306 307 /** 308 * @brief Sets the local name for an OS account based on its local ID. 309 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 310 * @param localId - Indicates the local ID of the OS account. 311 * @param localName - Indicates the local name to set for the OS account. 312 * @return error code, see account_error_no.h 313 */ 314 static ErrCode SetOsAccountName(const int id, const std::string &localName); 315 316 /** 317 * @brief Sets constraints for an OS account based on its local ID. 318 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 319 * @param localId - Indicates the local ID of the OS account. 320 * @param constraints - Indicates the constraints to set for the OS account. The value can be: 321 * <ul> 322 * <li>{@code constraint.wifi.set} - Indicates the constraint on configuring the Wi-Fi access point. 323 * </li> 324 * <li>{@code constraint.sms.use} - Indicates the constraint on sending and receiving short messages. 325 * </li> 326 * <li>{@code constraint.calls.outgoing} - Indicates the constraint on making calls.</li> 327 * <li>{@code constraint.unknown.sources.install} - Indicates the constraint on installing applications 328 * from unknown sources.</li> 329 * </ul> 330 * @param enable - Specifies whether to enable the constraint. 331 * @return error code, see account_error_no.h 332 */ 333 static ErrCode SetOsAccountConstraints( 334 const int id, const std::vector<std::string> &constraints, const bool enable); 335 336 /** 337 * @brief Sets the profile photo for an OS account based on its local ID. 338 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 339 * @param localId - Indicates the local ID of the OS account. 340 * @param photo - Indicates the profile photo to set for the OS account. 341 * @return error code, see account_error_no.h 342 */ 343 static ErrCode SetOsAccountProfilePhoto(const int id, const std::string &photo); 344 345 /** 346 * @brief Gets the distributed virtual device ID (DVID). 347 * <p> 348 * If the same OHOS account has logged in to multiple devices, these devices constitute a super device 349 * through the distributed networking. On the connected devices, you can call this method to obtain the DVIDs. 350 * The same application running on different devices obtains the same DVID, whereas different applications 351 * obtain different DVIDs. 352 * <p> 353 * 354 * @permission ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS 355 * @param dvid - Indicates the DVID if obtained; returns an empty string if no OHOS account has logged in. 356 * @return error code, see account_error_no.h 357 */ 358 static ErrCode GetDistributedVirtualDeviceId(std::string &dvid); 359 360 /** 361 * @brief Gets the distributed virtual device ID (DVID). 362 * <p> 363 * If the same OHOS account has logged in to multiple devices, these devices constitute a super device 364 * through the distributed networking. On the connected devices, you can call this method to obtain the DVIDs. 365 * The same application running on different devices obtains the same DVID, whereas different applications 366 * obtain different DVIDs. 367 * <p> 368 * 369 * @permission ohos.permission.GET_DISTRIBUTED_ACCOUNTS or ohos.permission.MANAGE_LOCAL_ACCOUNTS or 370 * ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS 371 * @param bundleName - Indicates the target bundle name. 372 * @param localId - Indicates the local ID of the OS account. 373 * @param dvid - Indicates the DVID if obtained; returns an empty string if no OHOS account has logged in. 374 * @return error code, see account_error_no.h 375 * @SystemAPI 376 */ 377 static ErrCode QueryDistributedVirtualDeviceId(const std::string &bundleName, int32_t localId, std::string &dvid); 378 379 /** 380 * @brief Activates a specified OS account. 381 * <p> 382 * If multiple OS accounts are available, you can call this method to enable a specific OS account 383 * to run in the foreground. Then, the OS account originally running in the foreground will be 384 * switched to the background. 385 * </p> 386 * 387 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 388 * @param id - Indicates the local ID of the OS account. 389 * @return error code, see account_error_no.h 390 */ 391 static ErrCode ActivateOsAccount(const int id); 392 393 /** 394 * @brief Deactivates a specified OS account. 395 * <p> 396 * You can call this method to disable a specific OS account. 397 * </p> 398 * 399 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 400 * @param id - Indicates the local ID of the OS account. 401 * @return error code, see account_error_no.h 402 */ 403 static ErrCode DeactivateOsAccount(const int id); 404 405 /** 406 * @brief Deactivates all OS account. 407 * <p> 408 * You can call this method to disable all OS account. 409 * </p> 410 * 411 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 412 * @return error code, see account_error_no.h 413 */ 414 static ErrCode DeactivateAllOsAccounts(); 415 416 /** 417 * @brief Starts the specified OS account. 418 * @param id - Indicates the local ID of the OS account. 419 * @return error code, see account_error_no.h 420 */ 421 static ErrCode StartOsAccount(const int id); 422 423 /** 424 * @brief Gets localId according to serial number. 425 * @param serialNumber - Indicates serial number. 426 * @param id - Indicates the local ID of the OS account. 427 * @return error code, see account_error_no.h 428 */ 429 static ErrCode GetOsAccountLocalIdBySerialNumber(const int64_t serialNumber, int &id); 430 431 /** 432 * @brief Gets serial number according to localId. 433 * @param localId - Indicates the local ID of the OS account. 434 * @param serialNumber - Indicates the serial number. 435 * @return error code, see account_error_no.h 436 */ 437 static ErrCode GetSerialNumberByOsAccountLocalId(const int &id, int64_t &serialNumber); 438 439 /** 440 * @brief Subscribes the event of an OS account by the subscriber. 441 * @param subscriber subscriber information 442 * @return error code, see account_error_no.h 443 */ 444 static ErrCode SubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> &subscriber); 445 446 /** 447 * @brief Unsubscribes the event of an OS account by the subscriber. 448 * @param subscriber subscriber information 449 * @return error code, see account_error_no.h 450 */ 451 static ErrCode UnsubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> &subscriber); 452 453 /** 454 * @brief Gets the OS account switch mode. 455 * @return switch mode 456 */ 457 static OS_ACCOUNT_SWITCH_MOD GetOsAccountSwitchMod(); 458 459 /** 460 * @brief Checks whether the current OS account is verified. 461 * @param isVerified - Indicates whether the current OS account is verified. 462 * @return error code, see account_error_no.h 463 */ 464 static ErrCode IsCurrentOsAccountVerified(bool &isVerified); 465 466 /** 467 * @brief Checks whether the specified OS account is created completely. 468 * @param id - Indicates the local ID of the specified OS account. 469 * @param isOsAccountCompleted - Indicates whether the current OS account is created completely. 470 * @return error code, see account_error_no.h 471 */ 472 static ErrCode IsOsAccountCompleted(const int id, bool &isOsAccountCompleted); 473 474 /** 475 * @brief Sets the current OS account to be verified. 476 * @param isVerified - Indicates whether the current OS account is verified. 477 * @return error code, see account_error_no.h 478 */ 479 static ErrCode SetCurrentOsAccountIsVerified(const bool isVerified); 480 481 /** 482 * @brief Sets the specified OS account to be verified. 483 * @param id - Indicates the local ID of the specified OS account. 484 * @param isVerified - Indicates whether the current OS account is verified. 485 * @return error code, see account_error_no.h 486 */ 487 static ErrCode SetOsAccountIsVerified(const int id, const bool isVerified); 488 489 /** 490 * @brief Gets the number of the created OS account from database. 491 * @param storeID - Indicates the store ID. 492 * @param id - Indicates the number of the created OS account. 493 * @return error code, see account_error_no.h 494 */ 495 static ErrCode GetCreatedOsAccountNumFromDatabase(const std::string& storeID, int &createdOsAccountNum); 496 497 /** 498 * @brief Get serial number from database. 499 * @param storeID - Indicates the store ID. 500 * @param serialNumber - Indicates the serial number. 501 * @return error code, see account_error_no.h 502 */ 503 static ErrCode GetSerialNumberFromDatabase(const std::string& storeID, int64_t &serialNumber); 504 505 /** 506 * @brief Gets the max ID of the OS account to be created. 507 * @param storeID - Indicates the store ID. 508 * @param id - Indicates the max ID of the OS account to be created. 509 * @return error code, see account_error_no.h 510 */ 511 static ErrCode GetMaxAllowCreateIdFromDatabase(const std::string& storeID, int &id); 512 513 /** 514 * @brief Sets the specified OS account from database. 515 * @selinux The caller needs to configure selinux permissions: allow Caller_SA_Name accountmgr:fd {use}. 516 * @param storeID - Indicates the store ID. 517 * @param id - Indicates the local ID of the specified OS account. 518 * @param osAccountInfo - Indicates the OS account information. 519 * @return error code, see account_error_no.h 520 */ 521 static ErrCode GetOsAccountFromDatabase(const std::string& storeID, const int id, OsAccountInfo &osAccountInfo); 522 523 /** 524 * @brief Get a list of OS accounts from database. 525 * @selinux The caller needs to configure selinux permissions: allow Caller_SA_Name accountmgr:fd {use}. 526 * @param storeID - Indicates the store ID. 527 * @param osAccountList - Indicates a list of OS accounts. 528 * @return error code, see account_error_no.h 529 */ 530 static ErrCode GetOsAccountListFromDatabase(const std::string& storeID, std::vector<OsAccountInfo> &osAccountList); 531 532 /** 533 * @brief Gets the local IDs of all activated OS accounts. 534 * @param ids - Indicates the local IDs of all activated OS accounts. 535 * @return error code, see account_error_no.h 536 */ 537 static ErrCode QueryActiveOsAccountIds(std::vector<int32_t>& ids); 538 539 /** 540 * @brief Gets a list of constraint source types for the specified os account. 541 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 542 * @param localId - Indicates the local ID of the OS account. 543 * @param constraint - Indicates the constraint to query the source type. 544 * @param constraintSourceTypeInfos - Indicates the list of constraint source types for the specified os account. 545 * @return error code, see account_error_no.h 546 */ 547 static ErrCode QueryOsAccountConstraintSourceTypes(const int32_t id, const std::string constraint, 548 std::vector<ConstraintSourceTypeInfo> &constraintSourceTypeInfos); 549 550 /** 551 * @brief Sets the global constraints for all OS accounts. 552 * @param constraints - Indicates the local IDs of all activated OS accounts. 553 * @param isEnabled - Indicates whether the constraints are enabled. 554 * @param enforcerId - Indicates the local ID of the OS account who enforce the operation. 555 * @param isDeviceOwner - Indicates whether the enforcer is device owner. 556 * @return error code, see account_error_no.h 557 */ 558 static ErrCode SetGlobalOsAccountConstraints(const std::vector<std::string> &constraints, 559 const bool isEnabled, const int32_t enforcerId = 0, const bool isDeviceOwner = false); 560 561 /** 562 * @brief Sets the constraints for the specified OS accounts. 563 * @param constraints - Indicates the local IDs of all activated OS accounts. 564 * @param enable - Indicates whether the constraints are enabled. 565 * @param targetId - Indicates the local ID of the target OS account. 566 * @param enforcerId - Indicates the local ID of the OS account who enforce the operation. 567 * @param isDeviceOwner - Indicates whether the enforcer is device owner. 568 * @return error code, see account_error_no.h 569 */ 570 static ErrCode SetSpecificOsAccountConstraints(const std::vector<std::string> &constraints, 571 const bool enable, const int32_t targetId, const int32_t enforcerId, const bool isDeviceOwner); 572 573 /** 574 * @brief Subscribes the event of constraints changed by the subscriber. 575 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 576 * @param subscriber subscriber information 577 * @return error code, see account_error_no.h 578 */ 579 static ErrCode SubscribeOsAccountConstraints(const std::shared_ptr<OsAccountConstraintSubscriber> &subscriber); 580 581 /** 582 * @brief unsubscribes the event of constraints changed by the subscriber. 583 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 584 * @param subscriber unsubscriber information which must be subscribed before 585 * @return error code, see account_error_no.h 586 */ 587 static ErrCode UnsubscribeOsAccountConstraints(const std::shared_ptr<OsAccountConstraintSubscriber> &subscriber); 588 589 /** 590 * @brief Sets the default activated OS account. 591 * @param id - Indicates the local IDs of the default activated OS accounts. 592 * @return error code, see account_error_no.h 593 */ 594 static ErrCode SetDefaultActivatedOsAccount(const int32_t id); 595 596 /** 597 * @brief Gets the default activated OS account. 598 * @param id - Indicates the local IDs of the default activated OS accounts. 599 * @return error code, see account_error_no.h 600 */ 601 static ErrCode GetDefaultActivatedOsAccount(int32_t &id); 602 603 /** 604 * @brief Gets the currend user short name. 605 * @param shortName - Indicates the current user short name of the OS account. 606 * @return error code, see account_error_no.h 607 */ 608 static ErrCode GetOsAccountShortName(std::string &shortName); 609 610 /** 611 * @brief Gets the currend user local name. 612 * @param name - Indicates the current user local name of the OS account. 613 * @return error code, see account_error_no.h 614 */ 615 static ErrCode GetOsAccountName(std::string &name); 616 617 /** 618 * @brief Gets the user name by specified id. 619 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS or ohos.permission.MANAGE_LOCAL_ACCOUNTS 620 * @param name - Indicates the user name of the specified OS account. 621 * @return error code, see account_error_no.h 622 */ 623 static ErrCode GetOsAccountNameById(int32_t id, std::string &name); 624 625 /** 626 * @brief Gets the user short name, based on account id. 627 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 628 * @param id - Indicates the local ID of the OS account. 629 * @param shortName - Indicates the current user short name of the OS account. 630 * @return error code, see account_error_no.h 631 */ 632 static ErrCode GetOsAccountShortName(const int32_t id, std::string &shortName); 633 634 /** 635 * @brief Checks whether the current accoount is foreground. 636 * @param isForeground - Indicates whether the specified localId is Foreground. 637 * @return error code, see account_error_no.h 638 */ 639 static ErrCode IsOsAccountForeground(bool &isForeground); 640 641 /** 642 * @brief Checks whether the specified accoount is foreground. 643 * @param localId - Indicates the local Id of the OS account. 644 * @param isForeground - Indicates whether the specified localId is foreground. 645 * @return error code, see account_error_no.h 646 */ 647 static ErrCode IsOsAccountForeground(const int32_t localId, bool &isForeground); 648 649 /** 650 * @brief Checks whether the specified accoount is foreground in specified display. 651 * @param localId - Indicates the local id of the OS account. 652 * @param displayId - Indicates the id of the display. 653 * @param isForeground - Indicates whether the specified localId is foreground. 654 * @return error code, see account_error_no.h 655 */ 656 657 static ErrCode IsOsAccountForeground(const int32_t localId, const uint64_t displayId, bool &isForeground); 658 659 /** 660 * @brief Gets the id from default display. 661 * @param localId - Indicates the corresponding localId of default display. 662 * @return error code, see account_error_no.h 663 */ 664 static ErrCode GetForegroundOsAccountLocalId(int32_t &localId); 665 666 /** 667 * @brief Gets the id from specified display. 668 * @param displayId - Indicates the id of the specified display. 669 * @param localId - Indicates the corresponding localId of specified display. 670 * @return error code, see account_error_no.h 671 */ 672 static ErrCode GetForegroundOsAccountLocalId(const uint64_t displayId, int32_t &localId); 673 674 /** 675 * @brief Gets the foreground accounts. 676 * @param accounts - Indicates the foreground accounts. 677 * @return error code, see account_error_no.h 678 */ 679 static ErrCode GetForegroundOsAccounts(std::vector<ForegroundOsAccount> &accounts); 680 681 /** 682 * @brief Gets the foreground localId list. 683 * @param localIds - Indicates the foreground localId list. 684 * @return error code, see account_error_no.h 685 */ 686 static ErrCode GetBackgroundOsAccountLocalIds(std::vector<int32_t> &localIds); 687 688 /** 689 * @brief Sets the target OS account to be removed or not. 690 * 691 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 692 * @param localId - Indicates the target OS account. 693 * @param toBeRemoved - Indicates whether the target OS account to be removed. 694 * @return error code, see account_error_no.h 695 */ 696 static ErrCode SetOsAccountToBeRemoved(int32_t localId, bool toBeRemoved); 697 698 /** 699 * @brief Get domain account info by a given os account id 700 * 701 * @permission ohos.permission.GET_DOMAIN_ACCOUNTS and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 702 * @param localId - Indicates the target OS account. 703 * @param domainInfo - Returns the domain account information. 704 * @return error code, see account_error_no.h 705 */ 706 static ErrCode GetOsAccountDomainInfo(const int32_t localId, DomainAccountInfo &domainInfo); 707 708 /** 709 * @brief Publish the locking state of OS account. 710 * 711 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 712 * @param localId - Indicates the target OS account. 713 * @param isLocking - true means locking, false means locked. 714 * @return error code, see account_error_no.h 715 */ 716 static ErrCode PublishOsAccountLockEvent(const int32_t localId, bool isLocking); 717 718 /** 719 * @brief Lock a specified OS account. 720 * 721 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 722 * @param localId - Indicates the target OS account. 723 * @return error code, see account_error_no.h 724 */ 725 static ErrCode LockOsAccount(const int32_t localId); 726 727 /** 728 * @brief Bind domain account to a given os account id 729 * 730 * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS 731 * @param localId - Indicates the target OS account. 732 * @param domainInfo - Indicates the domain account information. 733 * @param callback - Indicates the callback for getting the result of binding domain account process. 734 * @return error code, see account_error_no.h 735 */ 736 static ErrCode BindDomainAccount(const int32_t localId, const DomainAccountInfo &domainInfo, 737 const std::shared_ptr<DomainAccountCallback> &callback); 738 }; 739 } // namespace AccountSA 740 } // namespace OHOS 741 #endif // OS_ACCOUNT_INTERFACES_INNERKITS_OS_ACCOUNT_MANAGER_H 742