Go to file
xuqian 6af86ccaee add dfx
Signed-off-by: xuqian <xuqian65@huawei.com>
2024-11-21 16:23:34 +08:00
.gitee fix pr template 2024-03-08 09:48:22 +08:00
dfx fix sysevent 2024-10-21 11:10:50 +08:00
figures 修改内源问题 2022-03-28 17:29:19 +08:00
frameworks !2287 [Bug]: ACTIVED->ACTIVATED 2024-11-20 10:42:23 +00:00
interfaces !2287 [Bug]: ACTIVED->ACTIVATED 2024-11-20 10:42:23 +00:00
sa_profile modify code 2023-05-23 07:15:39 +00:00
services add dfx 2024-11-21 16:23:34 +08:00
test 修复fuzz用例 2024-11-08 02:52:58 +00:00
tools 独立编译整改-去掉编译开关 2024-10-16 04:08:08 +00:00
.gitattributes update OpenHarmony 2.0 Canary 2021-06-02 02:18:42 +08:00
BUILD.gn CAPI 2024-04-18 23:28:58 +08:00
bundle.json [cj]: distributed_account cangjie ffi层 2024-10-19 11:06:36 +08:00
cfi_blocklist.txt add moduletest cfi 2024-03-22 14:56:53 +08:00
CODEOWNERS chage codeowners 2023-07-03 17:02:34 +08:00
hisysevent.yaml 【帐号】文件异常监控以及补充异常操作DFX打点 2023-12-10 18:04:15 +08:00
LICENSE update OpenHarmony 2.0 Canary 2021-06-02 02:18:42 +08:00
OAT.xml 针对JSON格式文件,添加OAT检测规则 2021-07-31 18:31:23 +08:00
os_account.gni [cj] support cj api for osaccount 2024-10-18 21:19:22 +08:00
README_zh.md 分布式帐号readme修改 2023-05-16 19:32:37 +08:00
README.md 修改内源问题 2022-03-28 17:29:19 +08:00

OS Account

Introduction

In the standard system, the account subsystem implements lifecycle management of OS accounts, manages the distributed account login status, and adds or deletes app accounts.

Architecture

Figure 1 Architecture of the OS account module

Directory Structure

/base/account/os_account
├── figures                  Figures
├── frameworks               Code of the account subsystem
│   ├── appaccount           Internal API code of the app account module
│   │   └── native           Code used to implement the app account internal APIs
│   ├── common               Code of the common module
│   │   ├── account_error    Error codes
│   │   ├── database         Database code
│   │   ├── log              Code for printing logs
│   │   ├── perf_stat        Code for performance statistics
│   │   └── test             Test code for the common module
│   ├── ohosaccount         Internal API code of the distributed account module
│   │   ├── native            Code used to implement the distributed account internal APIs
│   │   └── test             Test code for the distributed account internal APIs
│   └── osaccount            Internal API code of the OS account module
│       ├── core             OS account IPC
│       └── native           Code used to implement the OS account internal APIs
├── interfaces               External APIs of the account subsystem
│   ├── innerkits            Internal API header file
│   │   ├── appaccount       Header file of the app account internal APIs
│   │   ├── ohosaccount      Header file of the distributed account internal APIs
│   │   └── osaccount        Header file of the OS account internal APIs
│   └── kits                 External API encapsulation
│       └── napi             External API encapsulation code of the account subsystem
├── sa_profile               SA profile directory of the account subsystem
├── services                accountmgr service code
│   └── accountmgr           Account subsystem service code
│       ├── include          Service code header file
│       ├── src              Source code of the account subsystem service code
│       └── test             Test of the account subsystem service code
├── test                     Test code
│   ├── resource             Test resource files
│   └── systemtest           System test code
└── tools                    Tool code
    ├── acm                  acm tool
    │   ├── include          acm header file
    │   └── src              acm source file
    └── test                 acm test code

Usage

Available APIs

1. Distributed account module

The distributed account module provides APIs to query and update the account login status. These APIs can be used only by system apps.

Table 1 Description of the distributed account module

Module Name

Description

distributedAccount

Provides methods for managing distributed accounts.

Table 2 Classes of distributedAccount

Class

Description

DistributedAccountAbility

Provides methods for querying and updating the distributed account login status.

DistributedInfo

Defines distributed account information, including the account name, account user ID (UID), and login status.

Table 3 Description of DistributedAccountAbility

Method

Description

function getDistributedAccountAbility(): DistributedAccountAbility

Obtains the **DistributedAccountAbility** singleton instance.

Table 4 Methods of DistributedAccountAbility

Method

Description

queryOsAccountDistributedInfo(callback: AsyncCallback<DistributedInfo>): void

Queries information about a distributed account. This method uses an asynchronous callback to return the result.

queryOsAccountDistributedInfo(): Promise<DistributedInfo>

Queries information about a distributed account. This method uses a promise to return the result.

updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback<boolean>): void

Updates information about a distributed account. This method uses an asynchronous callback to return the result.

updateOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<boolean>

Updates information about a distributed account. This method uses a promise to return the result.

2. App account module

The app account module provides APIs to add, delete, query, and modify an app account, enable or disable access to an app account, and flush and synchronize account data.

Table 5 Description of the app account module

Module Name

Description

appAccount

Provides methods for managing app accounts.

Table 6 Classes of appAccount

Class

Description

AppAccountManager

Provides methods for adding, deleting, querying, and modifying app accounts, and enabling or disabling access to app accounts.

AppAccountInfo

Defines app account information, including the account name and bundle name.

OAuthTokenInfo

Defines OAuth access token information, including the authentication type and token value, for an app account.

AuthenticatorInfo

Defines OAuth authenticator information, including the bundle name, icon ID, and label ID, for an app account.

AuthenticatorCallback

Provides callbacks for returning the OAUth authentication result notification or redirecting an authentication request for an app account.

Authenticator

Provides methods for managing the OAuth authenticator information for an app account.

Constants

Defines constants, such as the key name and operation name.

ResultCode

Provides the result codes for the app account APIs.

Table 7 Description of AppAccountManager

Method

Description

function createAppAccountManager(): AppAccountManager

Obtains the **AppAccountManager** singleton instance.

Table 8Methods of AppAccountManager

Method

Description

addAccount(name: string, callback: AsyncCallback<void>): void;

Adds an app account.

addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void;

Adds an app account implicitly.

deleteAccount(name: string, callback: AsyncCallback<void>): void;

Deletes an app account.

enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void;

Enables access to an app account.

disableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void;

Disables access to an app account.

checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): void;

Checks whether application data synchronization is enabled for an app account.

setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void;

Sets credential information for an app account.

setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback<void>): void;

Sets additional information for an app account.

setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback<void>): void;

Sets the synchronization status for an app account.

setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback<void>): void;

Sets the data associated with an app account.

getAllAccessibleAccounts(callback: AsyncCallback <Array< AppAccountInfo>>): void;

Obtains information about all accessible app accounts.

getAllAccounts(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void;

Obtains all app accounts of the specified bundle.

getAccountCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void;

Obtains the credential information about an app account.

getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void;

Obtains additional information about an app account.

getAssociatedData(name: string, key: string, callback: AsyncCallback<string>): void;

Obtains the associated data of an app account.

on(type: 'change', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void;

Subscribes to the changes in the app account information.

off(type: 'change', callback?: Callback<void>): void;

Unsubscribes from the changes in the app account information.

authenticate(name: string, owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void;

Authenticates an app account to obtain an OAuth access token.

getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void;

Obtains the OAuth access token of an app account.

setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void;

Sets the OAuth access token for an app account.

deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void;

Deletes the OAuth access token for an app account.

setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void;

Sets the OAuth access token visibility for an app account.

checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void;

Checks the OAuth access token visibility for an app account.

getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<OAuthTokenInfo>>): void;

Obtains all visible OAuth access tokens of an app account.

getOAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void;

Obtains the OAuth access token list of an app account.

getAuthenticatorCallback(sessionId: string, callback: AsyncCallback<AuthenticatorCallback>): void;

Obtains the OAuth authenticator callback of an app account.

getAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void;

Obtains the OAuth authenticator information of an app account.

3. OS account module

The OS account module provides APIs to add, delete, query, set, subscribe to, and activate OS accounts, and flush OS account data to disks.

Table 9 Description of the OS account module

Module Name

Description

osAccount

Provides methods for managing OS accounts.

Table 10 Classes of osAccount

Class

Description

AccountManager

Provides methods for adding, deleting, querying, setting, subscribing to, and activating OS accounts.

OsAccountInfo

Provides OS account information, including the account name and ID.

DomainAccountInfo

Provides domain account information, such as the domain name and domain account name.

OsAccountType

Defines OS account types, including administrator, common user, and guest.

Table 11 Description of AccountManager

Method

Description

function getAccountManager(): AccountManager

Obtains the **AccountManager** singleton instance.

Table 12 Methods of AccountManager

Method

Description

activateOsAccount(localId: number, callback: AsyncCallback<void>): void;

Activates an OS account. This method uses an asynchronous callback to return the result.

activateOsAccount(localId: number): Promise<void>;

Activates an OS account. This method uses a promise to return the result.

isMultiOsAccountEnable(callback: AsyncCallback<boolean>): void;

Checks whether multiple OS accounts are supported. This method uses an asynchronous callback to return the result.

isMultiOsAccountEnable(): Promise<boolean>;

Checks whether multiple OS accounts are supported. This method uses a promise to return the result.

isOsAccountActived(localId: number, callback: AsyncCallback<boolean>): void;

Checks whether an OS account is activated. This method uses an asynchronous callback to return the result.

isOsAccountActived(localId: number): Promise<boolean>;

Checks whether an OS account is activated. This method uses a promise to return the result.

isOsAccountConstraintEnable(localId: number, constraint: string, callback: AsyncCallback<boolean>): void;

Checks whether an OS account has the given constraints. This method uses an asynchronous callback to return the result.

isOsAccountConstraintEnable(localId: number, constraint: string): Promise<boolean>;

Checks whether an OS account has the given constraints. This method uses a promise to return the result.

isTestOsAccount(callback: AsyncCallback<boolean>): void;

Checks whether this OS account is a test account. This method uses an asynchronous callback to return the result.

isTestOsAccount(): Promise<boolean>;

Checks whether this OS account is a test account. This method uses a promise to return the result.

isOsAccountVerified(callback: AsyncCallback<boolean>): void;

Checks whether this OS account has been verified. This method uses an asynchronous callback to return the result.

isOsAccountVerified(localId: number, callback: AsyncCallback<boolean>): void;

Checks whether an OS account has been verified. This method uses an asynchronous callback to return the result.

isOsAccountVerified(localId?: number): Promise<boolean>;

Checks whether an OS account has been verified. This method uses a promise to return the result.

removeOsAccount(localId: number, callback: AsyncCallback<void>): void;

Deletes an OS account. This method uses an asynchronous callback to return the result.

removeOsAccount(localId: number): Promise<void>;

Deletes an OS account. This method uses a promise to return the result.

setOsAccountConstraints(localId: number, constraints: Array<string>, enable: boolean, callback: AsyncCallback<void>): void;

Sets constraints for an OS account. This method uses an asynchronous callback to return the result.

setOsAccountConstraints(localId: number, constraints: Array<string>, enable: boolean): Promise<void>;

Sets constraints for an OS account. This method uses a promise to return the result.

setOsAccountName(localId: number, localName: string, callback: AsyncCallback<void>): void;

Sets a name for an OS account. This method uses an asynchronous callback to return the result.

setOsAccountName(localId: number, localName: string): Promise<void>;

Sets a name for an OS account. This method uses a promise to return the result.

getCreatedOsAccountsCount(callback: AsyncCallback<number>): void;

Obtains the number of OS accounts created. This method uses an asynchronous callback to return the result.

getCreatedOsAccountsCount(): Promise<number>;

Obtains the number of OS accounts created. This method uses a promise to return the result.

getOsAccountLocalIdFromProcess(callback: AsyncCallback<number>): void;

Obtain the ID of the OS account to which the current process belongs. This method uses an asynchronous callback to return the result.

getOsAccountLocalIdFromProcess(): Promise<number>;

Obtain the ID of the OS account to which the current process belongs. This method uses a promise to return the result.

getOsAccountLocalIdFromUid(uid: number, callback: AsyncCallback<number>): void;

Obtains the OS account ID based on the process UID. This method uses an asynchronous callback to return the result.

getOsAccountLocalIdFromUid(uid: number): Promise<number>;

Obtains the OS account ID based on the process UID. This method uses a promise to return the result.

getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback<number>): void;

Obtains the OS account ID based on the domain information. This method uses an asynchronous callback to return the result.

getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo): Promise<number>;

Obtains the OS account ID based on the domain information. This method uses a promise to return the result.

queryMaxOsAccountNumber(callback: AsyncCallback<number>): void;

Obtains the maximum number of OS accounts that can be created. This method uses an asynchronous callback to return the result.

queryMaxOsAccountNumber(): Promise<number>;

Obtains the maximum number of OS accounts that can be created. This method uses a promise to return the result.

getOsAccountAllConstraints(localId: number, callback: AsyncCallback<Array<string>>): void;

Obtains all constraints of an OS account. This method uses an asynchronous callback to return the result.

getOsAccountAllConstraints(localId: number): Promise<Array<string>>;

Obtains all constraints of an OS account. This method uses a promise to return the result.

queryAllCreatedOsAccounts(callback: AsyncCallback<Array<OsAccountInfo>>): void;

Obtains information about all the OS accounts created. This method uses an asynchronous callback to return the result.

queryAllCreatedOsAccounts(): Promise<Array<OsAccountInfo>>;

Obtains information about all the OS accounts created. This method uses a promise to return the result.

createOsAccount(localName: string, type: OsAccountType, callback: AsyncCallback<OsAccountInfo>): void;

Creates an OS account. This method uses an asynchronous callback to return the result.

createOsAccount(localName: string, type: OsAccountType): Promise<OsAccountInfo>;

Creates an OS account. This method uses a promise to return the result.

createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo, callback: AsyncCallback<OsAccountInfo>): void;

Creates an OS account based on the domain information and binds this OS account to the domain. This method uses an asynchronous callback to return the result.

createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo): Promise<OsAccountInfo>;

Creates an OS account based on the domain information and binds this OS account to the domain. This method uses a promise to return the result.

queryCurrentOsAccount(callback: AsyncCallback<OsAccountInfo>): void;

Obtains information about the OS account to which this process belongs. This method uses an asynchronous callback to return the result.

queryCurrentOsAccount(): Promise<OsAccountInfo>;

Obtains information about the OS account to which this process belongs. This method uses a promise to return the result.

queryOsAccountById(localId: number, callback: AsyncCallback<OsAccountInfo>): void;

Obtains information about an OS account based on the account ID. This method uses an asynchronous callback to return the result.

queryOsAccountById(localId: number): Promise<OsAccountInfo>;

Obtains information about an OS account based on the account ID. This method uses a promise to return the result.

getOsAccountTypeFromProcess(callback: AsyncCallback<OsAccountType>): void;

Obtains the type of the OS account to which the current process belongs. This method uses an asynchronous callback to return the result.

getOsAccountTypeFromProcess(): Promise<OsAccountType>;

Obtains the type of the OS account to which the current process belongs. This method uses a promise to return the result.

getDistributedVirtualDeviceId(callback: AsyncCallback<string>): void;

Obtains the distributed virtual device ID. This method uses an asynchronous callback to return the result.

getDistributedVirtualDeviceId(): Promise<string>;

Obtains the distributed virtual device ID. This method uses a promise to return the result.

getOsAccountProfilePhoto(localId: number, callback: AsyncCallback<string>): void;

Obtains the profile picture of an OS account. This method uses an asynchronous callback to return the result.

getOsAccountProfilePhoto(localId: number): Promise<string>;

Obtains the profile picture of an OS account. This method uses a promise to return the result.

setOsAccountProfilePhoto(localId: number, photo: string, callback: AsyncCallback<void>): void;

Sets a profile picture for an OS account. This method uses an asynchronous callback to return the result.

setOsAccountProfilePhoto(localId: number, photo: string): Promise<void>;

Sets a profile picture for an OS account. This method uses a promise to return the result.

getOsAccountLocalIdBySerialNumber(serialNumber: number, callback: AsyncCallback<number>): void;

Obtains the ID of the OS account associated with the specified SN. This method uses an asynchronous callback to return the result.

getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise<number>;

Obtains the ID of the OS account associated with the specified SN. This method uses a promise to return the result.

getSerialNumberByOsAccountLocalId(localId: number, callback: AsyncCallback<number>): void;

Obtains the SN based on the specified OS account ID. This method uses an asynchronous callback to return the result.

getSerialNumberByOsAccountLocalId(localId: number): Promise<number>;

Obtains the SN based on the specified OS account ID. This method uses a promise to return the result.

on(type: 'activate' | 'activating', name: string, callback: Callback<number>): void;

Subscribes to the changes in OS accounts.

off(type: 'activate' | 'activating', name: string, callback?: Callback<number>): void;

Unsubscribes from the changes in OS accounts.

Repositories Involved

Account subsystem

account_os_account