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