• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Account Subsystem Changelog
2
3## cl.account_os_account.1 Error Code Change
4
5To ensure consistent error codes and normalized return of error codes in the account subsystem APIs, the following changes are made in API version 9:
6
7- Added the following error codes:
8  - [Account Management Error Codes](../../../application-dev/reference/errorcodes/errorcode-account.md)
9
10- Changed the error code return modes as follows:
11  - Asynchronous APIs: Return error information in the **error** object of **AsyncCallback** or **Promise**. Wherein, parameter type or quantity error information is returned by throwing an exception.
12  - Synchronous APIs: Throw an exception to return an error message.
13
14**Change Impact**
15
16The application developed based on earlier versions needs to adapt the method for returning API error information. Otherwise, the original service logic will be affected.
17
18**Key API/Component Changes**
19
20Involved APIs:
21  - class AccountManager
22    - activateOsAccount(localId: number, callback: AsyncCallback<void>): void;
23    - removeOsAccount(localId: number, callback: AsyncCallback<void>): void;
24    - setOsAccountConstraints(localId: number, constraints: Array<string>, enable: boolean, callback: AsyncCallback<void>): void;
25    - setOsAccountName(localId: number, localName: string, callback: AsyncCallback<void>): void;
26    - queryMaxOsAccountNumber(callback: AsyncCallback<number>): void;
27    - queryAllCreatedOsAccounts(callback: AsyncCallback<Array<OsAccountInfo>>): void;
28    - createOsAccount(localName: string, type: OsAccountType, callback: AsyncCallback<OsAccountInfo>): void;
29    - createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo, callback: AsyncCallback<OsAccountInfo>): void;
30    - queryOsAccountById(localId: number, callback: AsyncCallback<OsAccountInfo>): void;
31    - getOsAccountProfilePhoto(localId: number, callback: AsyncCallback<string>): void;
32    - setOsAccountProfilePhoto(localId: number, photo: string, callback: AsyncCallback<void>): void;
33    - on(type: 'activate' | 'activating', name: string, callback: Callback<number>): void;
34    - off(type: 'activate' | 'activating', name: string, callback?: Callback<number>): void;
35    - isMainOsAccount(callback: AsyncCallback<boolean>): void;
36    - queryOsAccountConstraintSourceTypes(localId: number, constraint: string, callback: AsyncCallback<Array<ConstraintSourceTypeInfo>>): void;
37  - class UserAuth
38    - constructor();
39    - getVersion(): number;
40    - getAvailableStatus(authType: AuthType, authTrustLevel: AuthTrustLevel): number;
41    - getProperty(request: GetPropertyRequest, callback: AsyncCallback<ExecutorProperty>): void;
42    - setProperty(request: SetPropertyRequest, callback: AsyncCallback<number>): void;
43    - auth(challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array;
44    - authUser(userId: number, challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array;
45    - cancelAuth(contextID: Uint8Array): number;
46  - class PINAuth
47    - constructor();
48    - registerInputer(inputer: IInputer): boolean;
49    - unregisterInputer(authType: AuthType): void;
50  - class UserIdentityManager
51    - constructor();
52    - openSession(callback: AsyncCallback<Uint8Array>): void;
53    - addCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void;
54    - updateCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void;
55    - closeSession(): void;
56    - cancel(challenge: Uint8Array): number;
57    - delUser(token: Uint8Array, callback: IIdmCallback): void;
58    - delCred(credentialId: Uint8Array, token: Uint8Array, callback: IIdmCallback): void;
59    - getAuthInfo(callback: AsyncCallback<Array<EnrolledCredInfo>>): void;
60  - interface IInputData
61    - onSetData: (authSubType: AuthSubType, data: Uint8Array) => void;
62
63**Adaptation Guide**
64
65The following uses **activateOsAccount** as an example to describe the error information processing logic of an asynchronous API:
66
67```ts
68import account_osAccount from "@ohos.account.osAccount"
69let accountMgr = account_osAccount.getAccountManager()
70let callbackFunc = (err) => {
71  if (err != null) {  // Handle the service error.
72    console.log("account_osAccount failed, error: " + JSON.stringify(err));
73  } else {
74    console.log("account_osAccount successfully");
75  }
76}
77try {
78  accountMgr.activateOsAccount("100", callbackFunc);
79} catch (err) {  // Handle the parameter type error.
80  console.log("account_osAccount failed for incorrect parameter type, error: " + JSON.stringify(err));
81}
82try {
83  accountMgr.activateOsAccount();
84} catch (err) {  // Handle the parameter number error.
85  console.log("account_osAccount failed for incorrect parameter number, error: " + JSON.stringify(err));
86}
87```
88
89The following uses **registerInputer** as an example to describe the error information processing logic of a synchronous API:
90
91```ts
92import account_osAccount from "@ohos.account.osAccount"
93let pinAuth = new account_osAccount.PINAuth()
94try {
95    pinAuth.registerInputer({})
96} catch (err) {  // Handle the parameter type error.
97  console.log("account_osAccount failed for incorrect parameter type, error: " + JSON.stringify(err));
98}
99try {
100    pinAuth.registerInputer()
101} catch (err) {  // Handle the parameter number error.
102  console.log("account_osAccount failed for incorrect parameter number, error: " + JSON.stringify(err));
103}
104```
105
106## cl.account_os_account.2 Change in Error Information Return of Account System APIs
107
108Some system APIs of the account subsystem use service logic return values to indicate error information, which does not comply with the API error code specifications of OpenHarmony. The following changes are made in API version 9:
109
110Asynchronous API: An error message is returned via **AsyncCallback** or the **error** object of **Promise**.
111
112Synchronous API: An error message is returned via an exception.
113
114**Change Impact**
115
116The application developed based on earlier versions needs to be adapted. Otherwise, the service logic will be affected.
117
118**Key API/Component Changes**
119
120Before change:
121
122  - class UserAuth
123    - setProperty(request: SetPropertyRequest, callback: AsyncCallback<number>): void;
124    - setProperty(request: SetPropertyRequest): Promise<number>;
125    - cancelAuth(contextID: Uint8Array): number;
126  - class PINAuth
127    - registerInputer(inputer: Inputer): boolean;
128  - UserIdentityManager
129    - cancel(challenge: Uint8Array): number;
130
131After change:
132
133  - class UserAuth
134    - setProperty(request: SetPropertyRequest, callback: AsyncCallback<void>): void;
135    - setProperty(request: SetPropertyRequest): Promise<void>;
136    - cancelAuth(contextID: Uint8Array): void;
137  - class PINAuth
138    - registerInputer(inputer: Inputer): void;
139  - UserIdentityManager
140    - cancel(challenge: Uint8Array): void;
141
142**Adaptation Guide**
143
144The following uses **setProperty** as an example for asynchronous APIs:
145
146```
147import account_osAccount from "@ohos.account.osAccount"
148userAuth.setProperty({
149    authType: account_osAccount.AuthType.PIN,
150    key: account_osAccount.SetPropertyType.INIT_ALGORITHM,
151    setInfo: new Uint8Array([0])
152}, (err) => {
153    if (err) {
154        console.log("setProperty failed, error: " + JSON.stringify(err));
155    } else {
156        console.log("setProperty successfully");
157    }
158});
159
160userAuth.setProperty({
161    authType: account_osAccount.AuthType.PIN,
162    key: account_osAccount.SetPropertyType.INIT_ALGORITHM,
163    setInfo: new Uint8Array([0])
164}).catch((err) => {
165    if (err) {
166        console.log("setProperty failed, error: " + JSON.stringify(err));
167    } else {
168        console.log("setProperty successfully");
169    }
170});
171```
172
173The following uses **registerInputer** as an example for synchronous APIs:
174
175```
176import account_osAccount from "@ohos.account.osAccount"
177let pinAuth = new account_osAccount.PINAuth()
178let inputer = {
179    onGetData: (authType, passwordRecipient) => {
180        let password = new Uint8Array([0]);
181        passwordRecipient.onSetData(authType, password);
182    }
183}
184try {
185    pinAuth.registerInputer(inputer);
186} catch (err) {
187    console.log("registerInputer failed, error: " + JSON.stringify(err));
188}
189```
190
191## cl.account_os_account.3 Change of ACTION for the App Account Authentication Service
192
193**Change Impact**
194
195For the application developed based on an earlier version, you need to modify **ACTION** in the application configuration file (**config.json** for the FA model and **module.json5** for the stage model). Otherwise, the application authentication service will be affected.
196
197**Key API/Component Changes**
198
199Involved constant:
200
201@ohos.ability.wantConstant.ACTION_APP_ACCOUNT_AUTH
202
203Before change:
204
205ACTION_APP_ACCOUNT_AUTH = "account.appAccount.action.auth"
206
207After change:
208
209ACTION_APP_ACCOUNT_AUTH = "ohos.appAccount.action.auth"
210
211**Adaptation Guide**
212
213For a third-party application providing the account authentication service, change **ACTION** in the **ServiceAbility** configuration file (**config.json** for the FA module or **module.json5** for the stage module).
214
215```
216"abilities": [
217    {
218        "name": "ServiceAbility",
219        "srcEnty": "./ets/ServiceAbility/ServiceAbility.ts",
220        ...
221        "visible": true,
222        "skills": {
223            {
224                "actions": [
225                    "ohos.appAccount.action.auth"
226                ]
227            }
228        }
229    }]
230}
231
232```
233