提交 ee25bb22 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 5a8c3d76
...@@ -64,8 +64,10 @@ Creates an app account. This API uses an asynchronous callback to return the res ...@@ -64,8 +64,10 @@ Creates an app account. This API uses an asynchronous callback to return the res
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.createAccount('WangWu', (err) => { appAccountManager.createAccount('WangWu', (err: BusinessError) => {
console.log('createAccount err: ' + JSON.stringify(err)); console.log('createAccount err: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -101,13 +103,15 @@ Creates an app account with custom data. This API uses an asynchronous callback ...@@ -101,13 +103,15 @@ Creates an app account with custom data. This API uses an asynchronous callback
**Example** **Example**
```js ```js
let options = { import { BusinessError } from '@ohos.base';
let options:account_appAccount.CreateAccountOptions = {
customData: { customData: {
'age': '10' age: '10'
} }
} }
try { try {
appAccountManager.createAccount('LiSi', options, (err) => { appAccountManager.createAccount('LiSi', options, (err: BusinessError) => {
if (err) { if (err) {
console.log('createAccount failed, error: ' + JSON.stringify(err)); console.log('createAccount failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -152,15 +156,17 @@ Creates an app account with custom data. This API uses a promise to return the r ...@@ -152,15 +156,17 @@ Creates an app account with custom data. This API uses a promise to return the r
**Example** **Example**
```js ```js
let options = { import { BusinessError } from '@ohos.base';
let options: account_appAccount.CreateAccountOptions = {
customData: { customData: {
'age': '10' age: '10'
} }
} }
try { try {
appAccountManager.createAccount('LiSi', options).then(() => { appAccountManager.createAccount('LiSi', options).then(() => {
console.log('createAccount successfully'); console.log('createAccount successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('createAccount failed, error: ' + JSON.stringify(err)); console.log('createAccount failed, error: ' + JSON.stringify(err));
}); });
} catch(err) { } catch(err) {
...@@ -197,21 +203,27 @@ Creates an app account implicitly based on the specified account owner. This API ...@@ -197,21 +203,27 @@ Creates an app account implicitly based on the specified account owner. This API
**Example** **Example**
```js ```js
function onResultCallback(code, result) { import { BusinessError } from '@ohos.base';
import Want from '@ohos.app.ability.Want';
import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
function onResultCallback(code: number, result?: account_appAccount.AuthResult): void {
console.log('resultCode: ' + code); console.log('resultCode: ' + code);
console.log('result: ' + JSON.stringify(result)); console.log('result: ' + JSON.stringify(result));
} }
function onRequestRedirectedCallback(request) { function onRequestRedirectedCallback(request: Want): void {
let wantInfo = { let wantInfo: Want = {
deviceId: '', deviceId: '',
bundleName: 'com.example.accountjsdemo', bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData', action: 'ohos.want.action.viewData',
entities: ['entity.system.default'], entities: ['entity.system.default'],
} }
this.context.startAbility(wantInfo).then(() => { context.startAbility(wantInfo).then(() => {
console.log('startAbility successfully'); console.log('startAbility successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('startAbility err: ' + JSON.stringify(err)); console.log('startAbility err: ' + JSON.stringify(err));
}) })
} }
...@@ -256,26 +268,32 @@ Creates an app account implicitly based on the specified account owner and optio ...@@ -256,26 +268,32 @@ Creates an app account implicitly based on the specified account owner and optio
**Example** **Example**
```js ```js
function onResultCallback(code, result) { import { BusinessError } from '@ohos.base';
import Want from '@ohos.app.ability.Want';
import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
function onResultCallback(code: number, result?: account_appAccount.AuthResult): void {
console.log('resultCode: ' + code); console.log('resultCode: ' + code);
console.log('result: ' + JSON.stringify(result)); console.log('result: ' + JSON.stringify(result));
} }
function onRequestRedirectedCallback(request) { function onRequestRedirectedCallback(request: Want): void {
let wantInfo = { let wantInfo: Want = {
deviceId: '', deviceId: '',
bundleName: 'com.example.accountjsdemo', bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData', action: 'ohos.want.action.viewData',
entities: ['entity.system.default'], entities: ['entity.system.default'],
} }
this.context.startAbility(wantInfo).then(() => { context.startAbility(wantInfo).then(() => {
console.log('startAbility successfully'); console.log('startAbility successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('startAbility err: ' + JSON.stringify(err)); console.log('startAbility err: ' + JSON.stringify(err));
}) })
} }
let options = { let options: account_appAccount.CreateAccountImplicitlyOptions = {
authType: 'getSocialData', authType: 'getSocialData',
requiredLabels: [ 'student' ] requiredLabels: [ 'student' ]
}; };
...@@ -315,8 +333,10 @@ Removes an app account. This API uses an asynchronous callback to return the res ...@@ -315,8 +333,10 @@ Removes an app account. This API uses an asynchronous callback to return the res
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.removeAccount('ZhaoLiu', (err) => { appAccountManager.removeAccount('ZhaoLiu', (err: BusinessError) => {
if (err) { if (err) {
console.log('removeAccount failed, error: ' + JSON.stringify(err)); console.log('removeAccount failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -359,10 +379,12 @@ Removes an app account. This API uses a promise to return the result. ...@@ -359,10 +379,12 @@ Removes an app account. This API uses a promise to return the result.
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.removeAccount('Lisi').then(() => { appAccountManager.removeAccount('Lisi').then(() => {
console.log('removeAccount successfully'); console.log('removeAccount successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('removeAccount failed, error: ' + JSON.stringify(err)); console.log('removeAccount failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -399,8 +421,10 @@ Sets the access to the data of an account for an app. This API uses an asynchron ...@@ -399,8 +421,10 @@ Sets the access to the data of an account for an app. This API uses an asynchron
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.setAppAccess('ZhangSan', 'com.example.accountjsdemo', true, (err) => { appAccountManager.setAppAccess('ZhangSan', 'com.example.accountjsdemo', true, (err: BusinessError) => {
if (err) { if (err) {
console.log('setAppAccess failed: ' + JSON.stringify(err)); console.log('setAppAccess failed: ' + JSON.stringify(err));
} else { } else {
...@@ -446,10 +470,12 @@ Sets the access to the data of an account for an app. This API uses a promise to ...@@ -446,10 +470,12 @@ Sets the access to the data of an account for an app. This API uses a promise to
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.setAppAccess('ZhangSan', 'com.example.accountjsdemo', true).then(() => { appAccountManager.setAppAccess('ZhangSan', 'com.example.accountjsdemo', true).then(() => {
console.log('setAppAccess successfully'); console.log('setAppAccess successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setAppAccess failed: ' + JSON.stringify(err)); console.log('setAppAccess failed: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -484,14 +510,17 @@ Checks whether an app can access the data of an account. This API uses an asynch ...@@ -484,14 +510,17 @@ Checks whether an app can access the data of an account. This API uses an asynch
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.checkAppAccess('ZhangSan', 'com.example.accountjsdemo', (err, isAccessible) => { appAccountManager.checkAppAccess('ZhangSan', 'com.example.accountjsdemo',
if (err) { (err: BusinessError, isAccessible: boolean) => {
console.log('checkAppAccess failed, error: ' + JSON.stringify(err)); if (err) {
} else { console.log('checkAppAccess failed, error: ' + JSON.stringify(err));
console.log('checkAppAccess successfully'); } else {
} console.log('checkAppAccess successfully');
}); }
});
} catch (err) { } catch (err) {
console.log('checkAppAccess exception: ' + JSON.stringify(err)); console.log('checkAppAccess exception: ' + JSON.stringify(err));
} }
...@@ -529,10 +558,12 @@ Checks whether an app can access the data of an account. This API uses a promise ...@@ -529,10 +558,12 @@ Checks whether an app can access the data of an account. This API uses a promise
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.checkAppAccess('ZhangSan', 'com.example.accountjsdemo').then((isAccessible) => { appAccountManager.checkAppAccess('ZhangSan', 'com.example.accountjsdemo').then((isAccessible: boolean) => {
console.log('checkAppAccess successfully, isAccessible: ' + isAccessible); console.log('checkAppAccess successfully, isAccessible: ' + isAccessible);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('checkAppAccess failed, error: ' + JSON.stringify(err)); console.log('checkAppAccess failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -569,8 +600,10 @@ Sets data synchronization for an app account. This API uses an asynchronous call ...@@ -569,8 +600,10 @@ Sets data synchronization for an app account. This API uses an asynchronous call
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.setDataSyncEnabled('ZhangSan', true, (err) => { appAccountManager.setDataSyncEnabled('ZhangSan', true, (err: BusinessError) => {
console.log('setDataSyncEnabled err: ' + JSON.stringify(err)); console.log('setDataSyncEnabled err: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -612,10 +645,12 @@ Sets data synchronization for an app account. This API uses a promise to return ...@@ -612,10 +645,12 @@ Sets data synchronization for an app account. This API uses a promise to return
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager .setDataSyncEnabled('ZhangSan', true).then(() => { appAccountManager .setDataSyncEnabled('ZhangSan', true).then(() => {
console.log('setDataSyncEnabled Success'); console.log('setDataSyncEnabled Success');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setDataSyncEnabled err: ' + JSON.stringify(err)); console.log('setDataSyncEnabled err: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -651,8 +686,10 @@ Checks whether data synchronization is enabled for an app account. This API uses ...@@ -651,8 +686,10 @@ Checks whether data synchronization is enabled for an app account. This API uses
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.checkDataSyncEnabled('ZhangSan', (err, isEnabled) => { appAccountManager.checkDataSyncEnabled('ZhangSan', (err: BusinessError, isEnabled: boolean) => {
if (err) { if (err) {
console.log('checkDataSyncEnabled failed, err: ' + JSON.stringify(err)); console.log('checkDataSyncEnabled failed, err: ' + JSON.stringify(err));
} else { } else {
...@@ -697,10 +734,12 @@ Checks whether data synchronization is enabled for an app account. This API uses ...@@ -697,10 +734,12 @@ Checks whether data synchronization is enabled for an app account. This API uses
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.checkDataSyncEnabled('ZhangSan').then((isEnabled) => { appAccountManager.checkDataSyncEnabled('ZhangSan').then((isEnabled: boolean) => {
console.log('checkDataSyncEnabled successfully, isEnabled: ' + isEnabled); console.log('checkDataSyncEnabled successfully, isEnabled: ' + isEnabled);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('checkDataSyncEnabled failed, err: ' + JSON.stringify(err)); console.log('checkDataSyncEnabled failed, err: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -736,8 +775,10 @@ Sets a credential for an app account. This API uses an asynchronous callback to ...@@ -736,8 +775,10 @@ Sets a credential for an app account. This API uses an asynchronous callback to
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.setCredential('ZhangSan', 'PIN_SIX', 'xxxxxx', (err) => { appAccountManager.setCredential('ZhangSan', 'PIN_SIX', 'xxxxxx', (err: BusinessError) => {
if (err) { if (err) {
console.log('setCredential failed, error: ' + JSON.stringify(err)); console.log('setCredential failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -782,10 +823,12 @@ Sets a credential for an app account. This API uses a promise to return the resu ...@@ -782,10 +823,12 @@ Sets a credential for an app account. This API uses a promise to return the resu
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.setCredential('ZhangSan', 'PIN_SIX', 'xxxxxx').then(() => { appAccountManager.setCredential('ZhangSan', 'PIN_SIX', 'xxxxxx').then(() => {
console.log('setCredential successfully'); console.log('setCredential successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setCredential failed, error: ' + JSON.stringify(err)); console.log('setCredential failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -821,8 +864,10 @@ Obtains the credential of an app account. This API uses an asynchronous callback ...@@ -821,8 +864,10 @@ Obtains the credential of an app account. This API uses an asynchronous callback
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.getCredential('ZhangSan', 'PIN_SIX', (err, result) => { appAccountManager.getCredential('ZhangSan', 'PIN_SIX', (err: BusinessError, result: string) => {
if (err) { if (err) {
console.log('getCredential failed, error: ' + JSON.stringify(err)); console.log('getCredential failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -867,10 +912,12 @@ Obtains the credential of an app account. This API uses a promise to return the ...@@ -867,10 +912,12 @@ Obtains the credential of an app account. This API uses a promise to return the
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.getCredential('ZhangSan', 'PIN_SIX').then((credential) => { appAccountManager.getCredential('ZhangSan', 'PIN_SIX').then((credential: string) => {
console.log('getCredential successfully, credential: ' + credential); console.log('getCredential successfully, credential: ' + credential);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getCredential failed, error: ' + JSON.stringify(err)); console.log('getCredential failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -907,8 +954,10 @@ Sets custom data for an app account. This API uses an asynchronous callback to r ...@@ -907,8 +954,10 @@ Sets custom data for an app account. This API uses an asynchronous callback to r
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.setCustomData('ZhangSan', 'age', '12', (err) => { appAccountManager.setCustomData('ZhangSan', 'age', '12', (err: BusinessError) => {
if (err) { if (err) {
console.log('setCustomData failed, error: ' + JSON.stringify(err)); console.log('setCustomData failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -954,10 +1003,12 @@ Sets custom data for an app account. This API uses a promise to return the resul ...@@ -954,10 +1003,12 @@ Sets custom data for an app account. This API uses a promise to return the resul
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.setCustomData('ZhangSan', 'age', '12').then(() => { appAccountManager.setCustomData('ZhangSan', 'age', '12').then(() => {
console.log('setCustomData successfully'); console.log('setCustomData successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setCustomData failed, error: ' + JSON.stringify(err)); console.log('setCustomData failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -993,8 +1044,10 @@ Obtains the custom data of an app account based on the specified key. This API u ...@@ -993,8 +1044,10 @@ Obtains the custom data of an app account based on the specified key. This API u
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.getCustomData('ZhangSan', 'age', (err, data) => { appAccountManager.getCustomData('ZhangSan', 'age', (err: BusinessError, data: string) => {
if (err) { if (err) {
console.log('getCustomData failed, error: ' + err); console.log('getCustomData failed, error: ' + err);
} else { } else {
...@@ -1039,10 +1092,12 @@ Obtains the custom data of an app account based on the specified key. This API u ...@@ -1039,10 +1092,12 @@ Obtains the custom data of an app account based on the specified key. This API u
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.getCustomData('ZhangSan', 'age').then((data) => { appAccountManager.getCustomData('ZhangSan', 'age').then((data: string) => {
console.log('getCustomData successfully, data: ' + data); console.log('getCustomData successfully, data: ' + data);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getCustomData failed, error: ' + JSON.stringify(err)); console.log('getCustomData failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -1114,8 +1169,10 @@ Obtains information about all accessible app accounts. This API uses an asynchro ...@@ -1114,8 +1169,10 @@ Obtains information about all accessible app accounts. This API uses an asynchro
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.getAllAccounts((err, data) => { appAccountManager.getAllAccounts((err: BusinessError, data: account_appAccount.AppAccountInfo[]) => {
if (err) { if (err) {
console.debug('getAllAccounts failed, error: ' + JSON.stringify(err)); console.debug('getAllAccounts failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -1150,10 +1207,12 @@ Obtains information about all accessible app accounts. This API uses a promise t ...@@ -1150,10 +1207,12 @@ Obtains information about all accessible app accounts. This API uses a promise t
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.getAllAccounts().then((data) => { appAccountManager.getAllAccounts().then((data: account_appAccount.AppAccountInfo[]) => {
console.debug('getAllAccounts successfully'); console.debug('getAllAccounts successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.debug('getAllAccounts failed, error: ' + JSON.stringify(err)); console.debug('getAllAccounts failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -1187,14 +1246,17 @@ Obtains the app accounts that can be accessed by the invoker based on the app ac ...@@ -1187,14 +1246,17 @@ Obtains the app accounts that can be accessed by the invoker based on the app ac
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.getAccountsByOwner('com.example.accountjsdemo2', (err, data) => { appAccountManager.getAccountsByOwner('com.example.accountjsdemo2',
if (err) { (err: BusinessError, data: account_appAccount.AppAccountInfo[]) => {
console.debug('getAccountsByOwner failed, error:' + JSON.stringify(err)); if (err) {
} else { console.debug('getAccountsByOwner failed, error:' + JSON.stringify(err));
console.debug('getAccountsByOwner successfully, data:' + JSON.stringify(data)); } else {
} console.debug('getAccountsByOwner successfully, data:' + JSON.stringify(data));
}); }
});
} catch (err) { } catch (err) {
console.debug('getAccountsByOwner exception:' + JSON.stringify(err)); console.debug('getAccountsByOwner exception:' + JSON.stringify(err));
} }
...@@ -1231,10 +1293,13 @@ Obtains the app accounts that can be accessed by the invoker based on the app ac ...@@ -1231,10 +1293,13 @@ Obtains the app accounts that can be accessed by the invoker based on the app ac
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.getAccountsByOwner('com.example.accountjsdemo2').then((data) => { appAccountManager.getAccountsByOwner('com.example.accountjsdemo2').then((
data: account_appAccount.AppAccountInfo[]) => {
console.debug('getAccountsByOwner successfully, data: ' + JSON.stringify(data)); console.debug('getAccountsByOwner successfully, data: ' + JSON.stringify(data));
}).catch((err) => { }).catch((err: BusinessError) => {
console.debug('getAccountsByOwner failed, error: ' + JSON.stringify(err)); console.debug('getAccountsByOwner failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -1269,7 +1334,7 @@ Subscribes to account information changes of apps. ...@@ -1269,7 +1334,7 @@ Subscribes to account information changes of apps.
**Example** **Example**
```js ```js
function changeOnCallback(data){ function changeOnCallback(data: account_appAccount.AppAccountInfo[]): void {
console.log('receive change data:' + JSON.stringify(data)); console.log('receive change data:' + JSON.stringify(data));
} }
try{ try{
...@@ -1304,7 +1369,7 @@ Unsubscribes from account information changes. ...@@ -1304,7 +1369,7 @@ Unsubscribes from account information changes.
**Example** **Example**
```js ```js
function changeOnCallback(data) { function changeOnCallback(data: account_appAccount.AppAccountInfo[]): void {
console.log('receive change data:' + JSON.stringify(data)); console.log('receive change data:' + JSON.stringify(data));
} }
try{ try{
...@@ -1351,23 +1416,27 @@ Authenticates an app account. This API uses an asynchronous callback to return t ...@@ -1351,23 +1416,27 @@ Authenticates an app account. This API uses an asynchronous callback to return t
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
import Want from '@ohos.app.ability.Want';
import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
function onResultCallback(code, authResult) { function onResultCallback(code: number, authResult?: account_appAccount.AuthResult): void {
console.log('resultCode: ' + code); console.log('resultCode: ' + code);
console.log('authResult: ' + JSON.stringify(authResult)); console.log('authResult: ' + JSON.stringify(authResult));
} }
function onRequestRedirectedCallback(request) { function onRequestRedirectedCallback(request: Want): void {
let wantInfo = { let wantInfo: Want = {
deviceId: '', deviceId: '',
bundleName: 'com.example.accountjsdemo', bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData', action: 'ohos.want.action.viewData',
entities: ['entity.system.default'], entities: ['entity.system.default'],
} }
this.context.startAbility(wantInfo).then(() => { context.startAbility(wantInfo).then(() => {
console.log('startAbility successfully'); console.log('startAbility successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('startAbility err: ' + JSON.stringify(err)); console.log('startAbility err: ' + JSON.stringify(err));
}) })
} }
...@@ -1414,29 +1483,33 @@ Authenticates an app account with customized options. This API uses an asynchron ...@@ -1414,29 +1483,33 @@ Authenticates an app account with customized options. This API uses an asynchron
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
import Want from '@ohos.app.ability.Want';
import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
function onResultCallback(code, authResult) { function onResultCallback(code: number, authResult?: account_appAccount.AuthResult): void {
console.log('resultCode: ' + code); console.log('resultCode: ' + code);
console.log('authResult: ' + JSON.stringify(authResult)); console.log('authResult: ' + JSON.stringify(authResult));
} }
function onRequestRedirectedCallback(request) { function onRequestRedirectedCallback(request: Want): void {
let wantInfo = { let wantInfo: Want = {
deviceId: '', deviceId: '',
bundleName: 'com.example.accountjsdemo', bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData', action: 'ohos.want.action.viewData',
entities: ['entity.system.default'], entities: ['entity.system.default'],
} }
this.context.startAbility(wantInfo).then(() => { context.startAbility(wantInfo).then(() => {
console.log('startAbility successfully'); console.log('startAbility successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('startAbility err: ' + JSON.stringify(err)); console.log('startAbility err: ' + JSON.stringify(err));
}) })
} }
let options = { let options: Record<string, Object> = {
'password': 'xxxx', password: 'xxxx',
}; };
try { try {
appAccountManager.auth('LiSi', 'com.example.accountjsdemo', 'getSocialData', options, { appAccountManager.auth('LiSi', 'com.example.accountjsdemo', 'getSocialData', options, {
...@@ -1477,14 +1550,17 @@ Obtains the authorization token of the specified authentication type for an app ...@@ -1477,14 +1550,17 @@ Obtains the authorization token of the specified authentication type for an app
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.getAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', (err, token) => { appAccountManager.getAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData',
if (err) { (err: BusinessError, token: string) => {
console.log('getAuthToken failed, error: ' + JSON.stringify(err)); if (err) {
} else { console.log('getAuthToken failed, error: ' + JSON.stringify(err));
console.log('getAuthToken successfully, token: ' + token); } else {
} console.log('getAuthToken successfully, token: ' + token);
}); }
});
} catch (err) { } catch (err) {
console.log('getAuthToken exception: ' + JSON.stringify(err)); console.log('getAuthToken exception: ' + JSON.stringify(err));
} }
...@@ -1524,10 +1600,12 @@ Obtains the authorization token of the specified authentication type for an app ...@@ -1524,10 +1600,12 @@ Obtains the authorization token of the specified authentication type for an app
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.getAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData').then((token) => { appAccountManager.getAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData').then((token: string) => {
console.log('getAuthToken successfully, token: ' + token); console.log('getAuthToken successfully, token: ' + token);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getAuthToken failed, error: ' + JSON.stringify(err)); console.log('getAuthToken failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -1564,8 +1642,10 @@ Sets an authorization token of the specific authentication type for an app accou ...@@ -1564,8 +1642,10 @@ Sets an authorization token of the specific authentication type for an app accou
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.setAuthToken('LiSi', 'getSocialData', 'xxxx', (err) => { appAccountManager.setAuthToken('LiSi', 'getSocialData', 'xxxx', (err: BusinessError) => {
if (err) { if (err) {
console.log('setAuthToken failed, error: ' + JSON.stringify(err)); console.log('setAuthToken failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -1573,7 +1653,7 @@ Sets an authorization token of the specific authentication type for an app accou ...@@ -1573,7 +1653,7 @@ Sets an authorization token of the specific authentication type for an app accou
} }
}); });
} catch (err) { } catch (err) {
console.log('setAuthToken exception: ' + JSON.stringify(err)); console.log('setAuthToken exception: ' + JSON.stringify(err));
} }
``` ```
...@@ -1611,10 +1691,12 @@ Sets an authorization token of the specific authentication type for an app accou ...@@ -1611,10 +1691,12 @@ Sets an authorization token of the specific authentication type for an app accou
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.setAuthToken('LiSi', 'getSocialData', 'xxxx').then(() => { appAccountManager.setAuthToken('LiSi', 'getSocialData', 'xxxx').then(() => {
console.log('setAuthToken successfully'); console.log('setAuthToken successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setAuthToken failed, error: ' + JSON.stringify(err)); console.log('setAuthToken failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -1652,8 +1734,11 @@ Deletes the authorization token of the specified authentication type for an app ...@@ -1652,8 +1734,11 @@ Deletes the authorization token of the specified authentication type for an app
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.deleteAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx', (err) => { appAccountManager.deleteAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx',
(err: BusinessError) => {
if (err) { if (err) {
console.log('deleteAuthToken failed, error: ' + JSON.stringify(err)); console.log('deleteAuthToken failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -1661,7 +1746,7 @@ Deletes the authorization token of the specified authentication type for an app ...@@ -1661,7 +1746,7 @@ Deletes the authorization token of the specified authentication type for an app
} }
}); });
} catch (err) { } catch (err) {
console.log('deleteAuthToken exception: ' + JSON.stringify(err)); console.log('deleteAuthToken exception: ' + JSON.stringify(err));
} }
``` ```
...@@ -1700,10 +1785,12 @@ Deletes the authorization token of the specified authentication type for an app ...@@ -1700,10 +1785,12 @@ Deletes the authorization token of the specified authentication type for an app
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.deleteAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx').then(() => { appAccountManager.deleteAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx').then(() => {
console.log('deleteAuthToken successfully'); console.log('deleteAuthToken successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('deleteAuthToken failed, error: ' + JSON.stringify(err)); console.log('deleteAuthToken failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -1743,8 +1830,11 @@ Sets the visibility of an authorization token to an app. This API uses an asynch ...@@ -1743,8 +1830,11 @@ Sets the visibility of an authorization token to an app. This API uses an asynch
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.setAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true, (err) => { appAccountManager.setAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true,
(err: BusinessError) => {
if (err) { if (err) {
console.log('setAuthTokenVisibility failed, error: ' + JSON.stringify(err)); console.log('setAuthTokenVisibility failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -1793,10 +1883,12 @@ Sets the visibility of an authorization token to an app. This API uses a promise ...@@ -1793,10 +1883,12 @@ Sets the visibility of an authorization token to an app. This API uses a promise
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.setAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true).then(() => { appAccountManager.setAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true).then(() => {
console.log('setAuthTokenVisibility successfully'); console.log('setAuthTokenVisibility successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setAuthTokenVisibility failed, error: ' + JSON.stringify(err)); console.log('setAuthTokenVisibility failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -1833,14 +1925,17 @@ Checks the visibility of an authorization token of the specified authentication ...@@ -1833,14 +1925,17 @@ Checks the visibility of an authorization token of the specified authentication
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.checkAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', (err, isVisible) => { appAccountManager.checkAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo',
if (err) { (err: BusinessError, isVisible: boolean) => {
console.log('checkAuthTokenVisibility failed, error: ' + JSON.stringify(err)); if (err) {
} else { console.log('checkAuthTokenVisibility failed, error: ' + JSON.stringify(err));
console.log('checkAuthTokenVisibility successfully, isVisible: ' + isVisible); } else {
} console.log('checkAuthTokenVisibility successfully, isVisible: ' + isVisible);
}); }
});
} catch (err) { } catch (err) {
console.log('checkAuthTokenVisibility exception: ' + JSON.stringify(err)); console.log('checkAuthTokenVisibility exception: ' + JSON.stringify(err));
} }
...@@ -1880,10 +1975,13 @@ Checks the visibility of an authorization token of the specified authentication ...@@ -1880,10 +1975,13 @@ Checks the visibility of an authorization token of the specified authentication
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.checkAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo').then((isVisible) => { appAccountManager.checkAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo').then((
isVisible: boolean) => {
console.log('checkAuthTokenVisibility successfully, isVisible: ' + isVisible); console.log('checkAuthTokenVisibility successfully, isVisible: ' + isVisible);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('checkAuthTokenVisibility failed, error: ' + JSON.stringify(err)); console.log('checkAuthTokenVisibility failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -1918,14 +2016,17 @@ Obtains all tokens visible to the invoker for an app account. This API uses an a ...@@ -1918,14 +2016,17 @@ Obtains all tokens visible to the invoker for an app account. This API uses an a
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.getAllAuthTokens('LiSi', 'com.example.accountjsdemo', (err, tokenArr) => { appAccountManager.getAllAuthTokens('LiSi', 'com.example.accountjsdemo',
if (err) { (err: BusinessError, tokenArr: account_appAccount.AuthTokenInfo[]) => {
console.log('getAllAuthTokens failed, error: ' + JSON.stringify(err)); if (err) {
} else { console.log('getAllAuthTokens failed, error: ' + JSON.stringify(err));
console.log('getAllAuthTokens successfully, tokenArr: ' + tokenArr); } else {
} console.log('getAllAuthTokens successfully, tokenArr: ' + tokenArr);
}); }
});
} catch (err) { } catch (err) {
console.log('getAllAuthTokens exception: ' + JSON.stringify(err)); console.log('getAllAuthTokens exception: ' + JSON.stringify(err));
} }
...@@ -1963,11 +2064,14 @@ Obtains all tokens visible to the invoker for an app account. This API uses a pr ...@@ -1963,11 +2064,14 @@ Obtains all tokens visible to the invoker for an app account. This API uses a pr
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.getAllAuthTokens('LiSi', 'com.example.accountjsdemo').then((tokenArr) => { appAccountManager.getAllAuthTokens('LiSi', 'com.example.accountjsdemo').then((
console.log('getAllAuthTokens successfully, tokenArr: ' + JSON.stringify(tokenArr)); tokenArr: account_appAccount.AuthTokenInfo[]) => {
}).catch((err) => { console.log('getAllAuthTokens successfully, tokenArr: ' + JSON.stringify(tokenArr));
console.log('getAllAuthTokens failed, error: ' + JSON.stringify(err)); }).catch((err: BusinessError) => {
console.log('getAllAuthTokens failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
console.log('getAllAuthTokens exception: ' + JSON.stringify(err)); console.log('getAllAuthTokens exception: ' + JSON.stringify(err));
...@@ -2002,8 +2106,10 @@ Obtains the authorization list of the specified authentication type for an app a ...@@ -2002,8 +2106,10 @@ Obtains the authorization list of the specified authentication type for an app a
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.getAuthList('LiSi', 'getSocialData', (err, authList) => { appAccountManager.getAuthList('LiSi', 'getSocialData', (err: BusinessError, authList: string[]) => {
if (err) { if (err) {
console.log('getAuthList failed, error: ' + JSON.stringify(err)); console.log('getAuthList failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -2048,10 +2154,12 @@ Obtains the authorization list of the specified authentication type for an app a ...@@ -2048,10 +2154,12 @@ Obtains the authorization list of the specified authentication type for an app a
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.getAuthList('LiSi', 'getSocialData').then((authList) => { appAccountManager.getAuthList('LiSi', 'getSocialData').then((authList: string[]) => {
console.log('getAuthList successfully, authList: ' + authList); console.log('getAuthList successfully, authList: ' + authList);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getAuthList failed, error: ' + JSON.stringify(err)); console.log('getAuthList failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -2085,19 +2193,22 @@ Obtains the authenticator callback for an authentication session. This API uses ...@@ -2085,19 +2193,22 @@ Obtains the authenticator callback for an authentication session. This API uses
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
import Want from '@ohos.app.ability.Want';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
export default class EntryAbility extends UIAbility { export default class EntryAbility extends UIAbility {
onCreate(want, param) { onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function.
var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID]; let sessionId: string = want.parameters![account_appAccount.Constants.KEY_SESSION_ID] as string;
try { try {
appAccountManager.getAuthCallback(sessionId, (err, callback) => { appAccountManager.getAuthCallback(sessionId, (err: BusinessError, callback: account_appAccount.AuthCallback) => {
if (err != null) { if (err != null) {
console.log('getAuthCallback err: ' + JSON.stringify(err)); console.log('getAuthCallback err: ' + JSON.stringify(err));
return; return;
} }
var result = { let result: account_appAccount.AuthResult = {
accountInfo: { account: {
name: 'Lisi', name: 'Lisi',
owner: 'com.example.accountjsdemo', owner: 'com.example.accountjsdemo',
}, },
...@@ -2146,15 +2257,18 @@ Obtains the authenticator callback for an authentication session. This API uses ...@@ -2146,15 +2257,18 @@ Obtains the authenticator callback for an authentication session. This API uses
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
import Want from '@ohos.app.ability.Want';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
export default class EntryAbility extends UIAbility { export default class EntryAbility extends UIAbility {
onCreate(want, param) { onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function.
var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID]; let sessionId: string = want.parameters![account_appAccount.Constants.KEY_SESSION_ID] as string;
try { try {
appAccountManager.getAuthCallback(sessionId).then((callback) => { appAccountManager.getAuthCallback(sessionId).then((callback: account_appAccount.AuthCallback) => {
var result = { let result: account_appAccount.AuthResult = {
accountInfo: { account: {
name: 'Lisi', name: 'Lisi',
owner: 'com.example.accountjsdemo', owner: 'com.example.accountjsdemo',
}, },
...@@ -2164,7 +2278,7 @@ Obtains the authenticator callback for an authentication session. This API uses ...@@ -2164,7 +2278,7 @@ Obtains the authenticator callback for an authentication session. This API uses
} }
}; };
callback.onResult(0, result); callback.onResult(0, result);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getAuthCallback err: ' + JSON.stringify(err)); console.log('getAuthCallback err: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -2200,14 +2314,17 @@ Obtains the authenticator information of an app. This API uses an asynchronous c ...@@ -2200,14 +2314,17 @@ Obtains the authenticator information of an app. This API uses an asynchronous c
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.queryAuthenticatorInfo('com.example.accountjsdemo', (err, info) => { appAccountManager.queryAuthenticatorInfo('com.example.accountjsdemo',
if (err) { (err: BusinessError, info: account_appAccount.AuthenticatorInfo) => {
console.log('queryAuthenticatorInfo failed, error: ' + JSON.stringify(err)); if (err) {
} else { console.log('queryAuthenticatorInfo failed, error: ' + JSON.stringify(err));
console.log('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info)); } else {
} console.log('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info));
}); }
});
} catch (err) { } catch (err) {
console.log('queryAuthenticatorInfo exception: ' + JSON.stringify(err)); console.log('queryAuthenticatorInfo exception: ' + JSON.stringify(err));
} }
...@@ -2244,11 +2361,14 @@ Obtains the authenticator information of an app. This API uses a promise to retu ...@@ -2244,11 +2361,14 @@ Obtains the authenticator information of an app. This API uses a promise to retu
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.queryAuthenticatorInfo('com.example.accountjsdemo').then((info) => { appAccountManager.queryAuthenticatorInfo('com.example.accountjsdemo').then((
console.log('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info)); info: account_appAccount.AuthenticatorInfo) => {
}).catch((err) => { console.log('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info));
console.log('queryAuthenticatorInfo failed, error: ' + JSON.stringify(err)); }).catch((err: BusinessError) => {
console.log('queryAuthenticatorInfo failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
console.log('queryAuthenticatorInfo exception: ' + JSON.stringify(err)); console.log('queryAuthenticatorInfo exception: ' + JSON.stringify(err));
...@@ -2286,15 +2406,18 @@ Checks whether an app account has specific labels. This API uses an asynchronous ...@@ -2286,15 +2406,18 @@ Checks whether an app account has specific labels. This API uses an asynchronous
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let labels = ['student']; let labels = ['student'];
try { try {
appAccountManager.checkAccountLabels('zhangsan', 'com.example.accountjsdemo', labels, (err, hasAllLabels) => { appAccountManager.checkAccountLabels('zhangsan', 'com.example.accountjsdemo', labels,
if (err) { (err: BusinessError, hasAllLabels: boolean) => {
console.log('checkAccountLabels failed, error: ' + JSON.stringify(err)); if (err) {
} else { console.log('checkAccountLabels failed, error: ' + JSON.stringify(err));
console.log('checkAccountLabels successfully, hasAllLabels: ' + hasAllLabels); } else {
} console.log('checkAccountLabels successfully, hasAllLabels: ' + hasAllLabels);
}); }
});
} catch (err) { } catch (err) {
console.log('checkAccountLabels exception: ' + JSON.stringify(err)); console.log('checkAccountLabels exception: ' + JSON.stringify(err));
} }
...@@ -2336,11 +2459,14 @@ Checks whether an app account has specific labels. This API uses a promise to re ...@@ -2336,11 +2459,14 @@ Checks whether an app account has specific labels. This API uses a promise to re
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let labels = ['student']; let labels = ['student'];
try { try {
appAccountManager.checkAccountLabels('zhangsan', 'com.example.accountjsdemo', labels).then((hasAllLabels) => { appAccountManager.checkAccountLabels('zhangsan', 'com.example.accountjsdemo', labels).then((
hasAllLabels: boolean) => {
console.log('checkAccountLabels successfully: ' + hasAllLabels); console.log('checkAccountLabels successfully: ' + hasAllLabels);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('checkAccountLabels failed, error: ' + JSON.stringify(err)); console.log('checkAccountLabels failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -2376,8 +2502,10 @@ Deletes the credential of the specified type from an app account. This API uses ...@@ -2376,8 +2502,10 @@ Deletes the credential of the specified type from an app account. This API uses
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.deleteCredential('zhangsan', 'PIN_SIX', (err) => { appAccountManager.deleteCredential('zhangsan', 'PIN_SIX', (err: BusinessError) => {
if (err) { if (err) {
console.log('deleteCredential failed, error: ' + JSON.stringify(err)); console.log('deleteCredential failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -2422,10 +2550,12 @@ Deletes the credential of the specified type from an app account. This API uses ...@@ -2422,10 +2550,12 @@ Deletes the credential of the specified type from an app account. This API uses
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
appAccountManager.deleteCredential('zhangsan', 'PIN_SIX').then(() => { appAccountManager.deleteCredential('zhangsan', 'PIN_SIX').then(() => {
console.log('deleteCredential successfully'); console.log('deleteCredential successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('deleteCredential failed, error: ' + JSON.stringify(err)); console.log('deleteCredential failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -2460,18 +2590,21 @@ Selects the accounts that can be accessed by the invoker based on the options. T ...@@ -2460,18 +2590,21 @@ Selects the accounts that can be accessed by the invoker based on the options. T
**Example** **Example**
```js ```js
let options = { import { BusinessError } from '@ohos.base';
let options: account_appAccount.SelectAccountsOptions = {
allowedOwners: [ 'com.example.accountjsdemo' ], allowedOwners: [ 'com.example.accountjsdemo' ],
requiredLabels: [ 'student' ] requiredLabels: [ 'student' ]
}; };
try { try {
appAccountManager.selectAccountsByOptions(options, (err, accountArr) => { appAccountManager.selectAccountsByOptions(options,
if (err) { (err: BusinessError, accountArr: account_appAccount.AppAccountInfo[]) => {
console.log('selectAccountsByOptions failed, error: ' + JSON.stringify(err)); if (err) {
} else { console.log('selectAccountsByOptions failed, error: ' + JSON.stringify(err));
console.log('selectAccountsByOptions successfully, accountArr: ' + JSON.stringify(accountArr)); } else {
} console.log('selectAccountsByOptions successfully, accountArr: ' + JSON.stringify(accountArr));
}); }
});
} catch (err) { } catch (err) {
console.log('selectAccountsByOptions exception: ' + JSON.stringify(err)); console.log('selectAccountsByOptions exception: ' + JSON.stringify(err));
} }
...@@ -2509,13 +2642,15 @@ Selects the accounts that can be accessed by the invoker based on the options. T ...@@ -2509,13 +2642,15 @@ Selects the accounts that can be accessed by the invoker based on the options. T
**Example** **Example**
```js ```js
let options = { import { BusinessError } from '@ohos.base';
let options: account_appAccount.SelectAccountsOptions = {
allowedOwners: ['com.example.accountjsdemo'] allowedOwners: ['com.example.accountjsdemo']
}; };
try { try {
appAccountManager.selectAccountsByOptions(options).then((accountArr) => { appAccountManager.selectAccountsByOptions(options).then((accountArr: account_appAccount.AppAccountInfo[]) => {
console.log('selectAccountsByOptions successfully, accountArr: ' + JSON.stringify(accountArr)); console.log('selectAccountsByOptions successfully, accountArr: ' + JSON.stringify(accountArr));
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('selectAccountsByOptions failed, error: ' + JSON.stringify(err)); console.log('selectAccountsByOptions failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -2553,13 +2688,15 @@ Verifies the credential of an app account. This API uses an asynchronous callbac ...@@ -2553,13 +2688,15 @@ Verifies the credential of an app account. This API uses an asynchronous callbac
**Example** **Example**
```js ```js
import Want from '@ohos.app.ability.Want';
try { try {
appAccountManager.verifyCredential('zhangsan', 'com.example.accountjsdemo', { appAccountManager.verifyCredential('zhangsan', 'com.example.accountjsdemo', {
onResult: (resultCode, result) => { onResult: (resultCode: number, result?: account_appAccount.AuthResult) => {
console.log('verifyCredential onResult, resultCode: ' + JSON.stringify(resultCode)); console.log('verifyCredential onResult, resultCode: ' + JSON.stringify(resultCode));
console.log('verifyCredential onResult, result: ' + JSON.stringify(result)); console.log('verifyCredential onResult, result: ' + JSON.stringify(result));
}, },
onRequestRedirected: (request) => { onRequestRedirected: (request: Want) => {
console.log('verifyCredential onRequestRedirected, request: ' + JSON.stringify(request)); console.log('verifyCredential onRequestRedirected, request: ' + JSON.stringify(request));
} }
}); });
...@@ -2599,17 +2736,19 @@ Verifies the user credential. This API uses an asynchronous callback to return t ...@@ -2599,17 +2736,19 @@ Verifies the user credential. This API uses an asynchronous callback to return t
**Example** **Example**
```js ```js
let options = { import Want from '@ohos.app.ability.Want';
let options: account_appAccount.VerifyCredentialOptions = {
credentialType: 'pin', credentialType: 'pin',
credential: '123456' credential: '123456'
}; };
try { try {
appAccountManager.verifyCredential('zhangsan', 'com.example.accountjsdemo', options, { appAccountManager.verifyCredential('zhangsan', 'com.example.accountjsdemo', options, {
onResult: (resultCode, result) => { onResult: (resultCode: number, result?: account_appAccount.AuthResult) => {
console.log('verifyCredential onResult, resultCode: ' + JSON.stringify(resultCode)); console.log('verifyCredential onResult, resultCode: ' + JSON.stringify(resultCode));
console.log('verifyCredential onResult, result: ' + JSON.stringify(result)); console.log('verifyCredential onResult, result: ' + JSON.stringify(result));
}, },
onRequestRedirected: (request) => { onRequestRedirected: (request: Want) => {
console.log('verifyCredential onRequestRedirected, request: ' + JSON.stringify(request)); console.log('verifyCredential onRequestRedirected, request: ' + JSON.stringify(request));
} }
}); });
...@@ -2646,13 +2785,15 @@ Sets the authenticator attributes of an app. This API uses an asynchronous callb ...@@ -2646,13 +2785,15 @@ Sets the authenticator attributes of an app. This API uses an asynchronous callb
**Example** **Example**
```js ```js
import Want from '@ohos.app.ability.Want';
try { try {
appAccountManager.setAuthenticatorProperties('com.example.accountjsdemo', { appAccountManager.setAuthenticatorProperties('com.example.accountjsdemo', {
onResult: (resultCode, result) => { onResult: (resultCode: number, result?: account_appAccount.AuthResult) => {
console.log('setAuthenticatorProperties onResult, resultCode: ' + JSON.stringify(resultCode)); console.log('setAuthenticatorProperties onResult, resultCode: ' + JSON.stringify(resultCode));
console.log('setAuthenticatorProperties onResult, result: ' + JSON.stringify(result)); console.log('setAuthenticatorProperties onResult, result: ' + JSON.stringify(result));
}, },
onRequestRedirected: (request) => { onRequestRedirected: (request: Want) => {
console.log('setAuthenticatorProperties onRequestRedirected, request: ' + JSON.stringify(request)); console.log('setAuthenticatorProperties onRequestRedirected, request: ' + JSON.stringify(request));
} }
}); });
...@@ -2690,16 +2831,18 @@ Set authenticator properties. This API uses an asynchronous callback to return t ...@@ -2690,16 +2831,18 @@ Set authenticator properties. This API uses an asynchronous callback to return t
**Example** **Example**
```js ```js
let options = { import Want from '@ohos.app.ability.Want';
properties: {'prop1': 'value1'}
let options: account_appAccount.SetPropertiesOptions = {
properties: {prop1: 'value1'}
}; };
try { try {
appAccountManager.setAuthenticatorProperties('com.example.accountjsdemo', options, { appAccountManager.setAuthenticatorProperties('com.example.accountjsdemo', options, {
onResult: (resultCode, result) => { onResult: (resultCode: number, result?: account_appAccount.AuthResult) => {
console.log('setAuthenticatorProperties onResult, resultCode: ' + JSON.stringify(resultCode)); console.log('setAuthenticatorProperties onResult, resultCode: ' + JSON.stringify(resultCode));
console.log('setAuthenticatorProperties onResult, result: ' + JSON.stringify(result)); console.log('setAuthenticatorProperties onResult, result: ' + JSON.stringify(result));
}, },
onRequestRedirected: (request) => { onRequestRedirected: (request: Want) => {
console.log('setAuthenticatorProperties onRequestRedirected, request: ' + JSON.stringify(request)); console.log('setAuthenticatorProperties onRequestRedirected, request: ' + JSON.stringify(request));
} }
}); });
...@@ -2732,7 +2875,9 @@ Adds an app account. This API uses an asynchronous callback to return the result ...@@ -2732,7 +2875,9 @@ Adds an app account. This API uses an asynchronous callback to return the result
**Example** **Example**
```js ```js
appAccountManager.addAccount('WangWu', (err) => { import { BusinessError } from '@ohos.base';
appAccountManager.addAccount('WangWu', (err: BusinessError) => {
console.log('addAccount err: ' + JSON.stringify(err)); console.log('addAccount err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -2759,7 +2904,9 @@ Adds an app account name and additional information. This API uses an asynchrono ...@@ -2759,7 +2904,9 @@ Adds an app account name and additional information. This API uses an asynchrono
**Example** **Example**
```js ```js
appAccountManager.addAccount('LiSi', 'token101', (err) => { import { BusinessError } from '@ohos.base';
appAccountManager.addAccount('LiSi', 'token101', (err: BusinessError) => {
console.log('addAccount err: ' + JSON.stringify(err)); console.log('addAccount err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -2791,9 +2938,11 @@ Adds an app account name and additional information. This API uses an asynchrono ...@@ -2791,9 +2938,11 @@ Adds an app account name and additional information. This API uses an asynchrono
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
appAccountManager.addAccount('LiSi', 'token101').then(()=> { appAccountManager.addAccount('LiSi', 'token101').then(()=> {
console.log('addAccount Success'); console.log('addAccount Success');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('addAccount err: ' + JSON.stringify(err)); console.log('addAccount err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -2822,23 +2971,27 @@ Adds an app account implicitly based on the specified owner. This API uses an as ...@@ -2822,23 +2971,27 @@ Adds an app account implicitly based on the specified owner. This API uses an as
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
import Want from '@ohos.app.ability.Want';
import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
function onResultCallback(code, result) { function onResultCallback(code: number, result: Record<string, Object>): void {
console.log('resultCode: ' + code); console.log('resultCode: ' + code);
console.log('result: ' + JSON.stringify(result)); console.log('result: ' + JSON.stringify(result));
} }
function onRequestRedirectedCallback(request) { function onRequestRedirectedCallback(request: Want): void {
let wantInfo = { let wantInfo: Want = {
deviceId: '', deviceId: '',
bundleName: 'com.example.accountjsdemo', bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData', action: 'ohos.want.action.viewData',
entities: ['entity.system.default'], entities: ['entity.system.default'],
} }
this.context.startAbility(wantInfo).then(() => { context.startAbility(wantInfo).then(() => {
console.log('startAbility successfully'); console.log('startAbility successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('startAbility err: ' + JSON.stringify(err)); console.log('startAbility err: ' + JSON.stringify(err));
}) })
} }
...@@ -2871,7 +3024,9 @@ Deletes an app account. This API uses an asynchronous callback to return the res ...@@ -2871,7 +3024,9 @@ Deletes an app account. This API uses an asynchronous callback to return the res
**Example** **Example**
```js ```js
appAccountManager.deleteAccount('ZhaoLiu', (err) => { import { BusinessError } from '@ohos.base';
appAccountManager.deleteAccount('ZhaoLiu', (err: BusinessError) => {
console.log('deleteAccount err: ' + JSON.stringify(err)); console.log('deleteAccount err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -2903,9 +3058,11 @@ Deletes an app account. This API uses a promise to return the result. ...@@ -2903,9 +3058,11 @@ Deletes an app account. This API uses a promise to return the result.
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
appAccountManager.deleteAccount('ZhaoLiu').then(() => { appAccountManager.deleteAccount('ZhaoLiu').then(() => {
console.log('deleteAccount Success'); console.log('deleteAccount Success');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('deleteAccount err: ' + JSON.stringify(err)); console.log('deleteAccount err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -2932,7 +3089,9 @@ Disables an app account from accessing an app. This API uses an asynchronous cal ...@@ -2932,7 +3089,9 @@ Disables an app account from accessing an app. This API uses an asynchronous cal
**Example** **Example**
```js ```js
appAccountManager.disableAppAccess('ZhangSan', 'com.example.accountjsdemo', (err) => { import { BusinessError } from '@ohos.base';
appAccountManager.disableAppAccess('ZhangSan', 'com.example.accountjsdemo', (err: BusinessError) => {
console.log('disableAppAccess err: ' + JSON.stringify(err)); console.log('disableAppAccess err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -2965,9 +3124,11 @@ Disables an app account from accessing an app. This API uses a promise to return ...@@ -2965,9 +3124,11 @@ Disables an app account from accessing an app. This API uses a promise to return
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
appAccountManager.disableAppAccess('ZhangSan', 'com.example.accountjsdemo').then(() => { appAccountManager.disableAppAccess('ZhangSan', 'com.example.accountjsdemo').then(() => {
console.log('disableAppAccess Success'); console.log('disableAppAccess Success');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('disableAppAccess err: ' + JSON.stringify(err)); console.log('disableAppAccess err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -2995,7 +3156,9 @@ Enables an app account to access an app. This API uses an asynchronous callback ...@@ -2995,7 +3156,9 @@ Enables an app account to access an app. This API uses an asynchronous callback
**Example** **Example**
```js ```js
appAccountManager.enableAppAccess('ZhangSan', 'com.example.accountjsdemo', (err) => { import { BusinessError } from '@ohos.base';
appAccountManager.enableAppAccess('ZhangSan', 'com.example.accountjsdemo', (err: BusinessError) => {
console.log('enableAppAccess: ' + JSON.stringify(err)); console.log('enableAppAccess: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3028,9 +3191,11 @@ Enables an app account to access an app. This API uses a promise to return the r ...@@ -3028,9 +3191,11 @@ Enables an app account to access an app. This API uses a promise to return the r
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
appAccountManager.enableAppAccess('ZhangSan', 'com.example.accountjsdemo').then(() => { appAccountManager.enableAppAccess('ZhangSan', 'com.example.accountjsdemo').then(() => {
console.log('enableAppAccess Success'); console.log('enableAppAccess Success');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('enableAppAccess err: ' + JSON.stringify(err)); console.log('enableAppAccess err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3059,7 +3224,9 @@ Checks whether data synchronization is enabled for an app account. This API uses ...@@ -3059,7 +3224,9 @@ Checks whether data synchronization is enabled for an app account. This API uses
**Example** **Example**
```js ```js
appAccountManager.checkAppAccountSyncEnable('ZhangSan', (err, result) => { import { BusinessError } from '@ohos.base';
appAccountManager.checkAppAccountSyncEnable('ZhangSan', (err: BusinessError, result: boolean) => {
console.log('checkAppAccountSyncEnable err: ' + JSON.stringify(err)); console.log('checkAppAccountSyncEnable err: ' + JSON.stringify(err));
console.log('checkAppAccountSyncEnable result: ' + result); console.log('checkAppAccountSyncEnable result: ' + result);
}); });
...@@ -3094,9 +3261,11 @@ Checks whether data synchronization is enabled for an app account. This API uses ...@@ -3094,9 +3261,11 @@ Checks whether data synchronization is enabled for an app account. This API uses
**Example** **Example**
```js ```js
appAccountManager.checkAppAccountSyncEnable('ZhangSan').then((data) => { import { BusinessError } from '@ohos.base';
appAccountManager.checkAppAccountSyncEnable('ZhangSan').then((data: boolean) => {
console.log('checkAppAccountSyncEnable, result: ' + data); console.log('checkAppAccountSyncEnable, result: ' + data);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('checkAppAccountSyncEnable err: ' + JSON.stringify(err)); console.log('checkAppAccountSyncEnable err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3125,7 +3294,9 @@ Set credentials for an app account. This API uses an asynchronous callback to re ...@@ -3125,7 +3294,9 @@ Set credentials for an app account. This API uses an asynchronous callback to re
**Example** **Example**
```js ```js
appAccountManager.setAccountCredential('ZhangSan', 'credentialType001', 'credential001', (err) => { import { BusinessError } from '@ohos.base';
appAccountManager.setAccountCredential('ZhangSan', 'credentialType001', 'credential001', (err: BusinessError) => {
console.log('setAccountCredential err: ' + JSON.stringify(err)); console.log('setAccountCredential err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3159,9 +3330,11 @@ Set credentials for an app account. This API uses a promise to return the result ...@@ -3159,9 +3330,11 @@ Set credentials for an app account. This API uses a promise to return the result
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
appAccountManager.setAccountCredential('ZhangSan', 'credentialType001', 'credential001').then(() => { appAccountManager.setAccountCredential('ZhangSan', 'credentialType001', 'credential001').then(() => {
console.log('setAccountCredential Success'); console.log('setAccountCredential Success');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setAccountCredential err: ' + JSON.stringify(err)); console.log('setAccountCredential err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3190,7 +3363,9 @@ Sets additional information for an app account. This API uses an asynchronous ca ...@@ -3190,7 +3363,9 @@ Sets additional information for an app account. This API uses an asynchronous ca
**Example** **Example**
```js ```js
appAccountManager.setAccountExtraInfo('ZhangSan', 'Tk002', (err) => { import { BusinessError } from '@ohos.base';
appAccountManager.setAccountExtraInfo('ZhangSan', 'Tk002', (err: BusinessError) => {
console.log('setAccountExtraInfo err: ' + JSON.stringify(err)); console.log('setAccountExtraInfo err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3224,9 +3399,11 @@ Sets additional information for an app account. This API uses a promise to retur ...@@ -3224,9 +3399,11 @@ Sets additional information for an app account. This API uses a promise to retur
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
appAccountManager.setAccountExtraInfo('ZhangSan', 'Tk002').then(() => { appAccountManager.setAccountExtraInfo('ZhangSan', 'Tk002').then(() => {
console.log('setAccountExtraInfo Success'); console.log('setAccountExtraInfo Success');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setAccountExtraInfo err: ' + JSON.stringify(err)); console.log('setAccountExtraInfo err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3256,7 +3433,9 @@ Sets data synchronization for an app account. This API uses an asynchronous call ...@@ -3256,7 +3433,9 @@ Sets data synchronization for an app account. This API uses an asynchronous call
**Example** **Example**
```js ```js
appAccountManager.setAppAccountSyncEnable('ZhangSan', true, (err) => { import { BusinessError } from '@ohos.base';
appAccountManager.setAppAccountSyncEnable('ZhangSan', true, (err: BusinessError) => {
console.log('setAppAccountSyncEnable err: ' + JSON.stringify(err)); console.log('setAppAccountSyncEnable err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3291,9 +3470,11 @@ Sets data synchronization for an app account. This API uses a promise to return ...@@ -3291,9 +3470,11 @@ Sets data synchronization for an app account. This API uses a promise to return
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
appAccountManager .setAppAccountSyncEnable('ZhangSan', true).then(() => { appAccountManager .setAppAccountSyncEnable('ZhangSan', true).then(() => {
console.log('setAppAccountSyncEnable Success'); console.log('setAppAccountSyncEnable Success');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setAppAccountSyncEnable err: ' + JSON.stringify(err)); console.log('setAppAccountSyncEnable err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3323,7 +3504,9 @@ Sets data to be associated with an app account. This API uses an asynchronous ca ...@@ -3323,7 +3504,9 @@ Sets data to be associated with an app account. This API uses an asynchronous ca
**Example** **Example**
```js ```js
appAccountManager.setAssociatedData('ZhangSan', 'k001', 'v001', (err) => { import { BusinessError } from '@ohos.base';
appAccountManager.setAssociatedData('ZhangSan', 'k001', 'v001', (err: BusinessError) => {
console.log('setAssociatedData err: ' + JSON.stringify(err)); console.log('setAssociatedData err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3358,9 +3541,11 @@ Sets data to be associated with an app account. This API uses a promise to retur ...@@ -3358,9 +3541,11 @@ Sets data to be associated with an app account. This API uses a promise to retur
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
appAccountManager.setAssociatedData('ZhangSan', 'k001', 'v001').then(() => { appAccountManager.setAssociatedData('ZhangSan', 'k001', 'v001').then(() => {
console.log('setAssociatedData Success'); console.log('setAssociatedData Success');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setAssociatedData err: ' + JSON.stringify(err)); console.log('setAssociatedData err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3388,7 +3573,9 @@ Obtains information about all accessible app accounts. This API uses an asynchro ...@@ -3388,7 +3573,9 @@ Obtains information about all accessible app accounts. This API uses an asynchro
**Example** **Example**
```js ```js
appAccountManager.getAllAccessibleAccounts((err, data)=>{ import { BusinessError } from '@ohos.base';
appAccountManager.getAllAccessibleAccounts((err: BusinessError, data: account_appAccount.AppAccountInfo[])=>{
console.debug('getAllAccessibleAccounts err: ' + JSON.stringify(err)); console.debug('getAllAccessibleAccounts err: ' + JSON.stringify(err));
console.debug('getAllAccessibleAccounts data: ' + JSON.stringify(data)); console.debug('getAllAccessibleAccounts data: ' + JSON.stringify(data));
}); });
...@@ -3417,9 +3604,11 @@ Obtains information about all accessible app accounts. This API uses a promise t ...@@ -3417,9 +3604,11 @@ Obtains information about all accessible app accounts. This API uses a promise t
**Example** **Example**
```js ```js
appAccountManager.getAllAccessibleAccounts().then((data) => { import { BusinessError } from '@ohos.base';
appAccountManager.getAllAccessibleAccounts().then((data: account_appAccount.AppAccountInfo[]) => {
console.log('getAllAccessibleAccounts: ' + data); console.log('getAllAccessibleAccounts: ' + data);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getAllAccessibleAccounts err: ' + JSON.stringify(err)); console.log('getAllAccessibleAccounts err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3448,8 +3637,10 @@ Obtains the app accounts that can be accessed by the invoker based on the app ac ...@@ -3448,8 +3637,10 @@ Obtains the app accounts that can be accessed by the invoker based on the app ac
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
const selfBundle = 'com.example.actsgetallaaccounts'; const selfBundle = 'com.example.actsgetallaaccounts';
appAccountManager.getAllAccounts(selfBundle, (err, data)=>{ appAccountManager.getAllAccounts(selfBundle, (err: BusinessError, data: account_appAccount.AppAccountInfo[])=>{
console.debug('getAllAccounts err: ' + JSON.stringify(err)); console.debug('getAllAccounts err: ' + JSON.stringify(err));
console.debug('getAllAccounts data:' + JSON.stringify(data)); console.debug('getAllAccounts data:' + JSON.stringify(data));
}); });
...@@ -3484,10 +3675,12 @@ Obtains the app accounts that can be accessed by the invoker based on the app ac ...@@ -3484,10 +3675,12 @@ Obtains the app accounts that can be accessed by the invoker based on the app ac
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
const selfBundle = 'com.example.actsgetallaaccounts'; const selfBundle = 'com.example.actsgetallaaccounts';
appAccountManager.getAllAccounts(selfBundle).then((data) => { appAccountManager.getAllAccounts(selfBundle).then((data: account_appAccount.AppAccountInfo[]) => {
console.log('getAllAccounts: ' + data); console.log('getAllAccounts: ' + data);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getAllAccounts err: ' + JSON.stringify(err)); console.log('getAllAccounts err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3515,7 +3708,9 @@ Obtains the credential of an app account. This API uses an asynchronous callback ...@@ -3515,7 +3708,9 @@ Obtains the credential of an app account. This API uses an asynchronous callback
**Example** **Example**
```js ```js
appAccountManager.getAccountCredential('ZhangSan', 'credentialType001', (err, result) => { import { BusinessError } from '@ohos.base';
appAccountManager.getAccountCredential('ZhangSan', 'credentialType001', (err: BusinessError, result: string) => {
console.log('getAccountCredential err: ' + JSON.stringify(err)); console.log('getAccountCredential err: ' + JSON.stringify(err));
console.log('getAccountCredential result: ' + result); console.log('getAccountCredential result: ' + result);
}); });
...@@ -3549,9 +3744,11 @@ Obtains the credential of an app account. This API uses a promise to return the ...@@ -3549,9 +3744,11 @@ Obtains the credential of an app account. This API uses a promise to return the
**Example** **Example**
```js ```js
appAccountManager.getAccountCredential('ZhangSan', 'credentialType001').then((data) => { import { BusinessError } from '@ohos.base';
appAccountManager.getAccountCredential('ZhangSan', 'credentialType001').then((data: string) => {
console.log('getAccountCredential, result: ' + data); console.log('getAccountCredential, result: ' + data);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getAccountCredential err: ' + JSON.stringify(err)); console.log('getAccountCredential err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3578,7 +3775,9 @@ Obtains additional information of an app account. Additional information refers ...@@ -3578,7 +3775,9 @@ Obtains additional information of an app account. Additional information refers
**Example** **Example**
```js ```js
appAccountManager.getAccountExtraInfo('ZhangSan', (err, result) => { import { BusinessError } from '@ohos.base';
appAccountManager.getAccountExtraInfo('ZhangSan', (err: BusinessError, result: string) => {
console.log('getAccountExtraInfo err: ' + JSON.stringify(err)); console.log('getAccountExtraInfo err: ' + JSON.stringify(err));
console.log('getAccountExtraInfo result: ' + result); console.log('getAccountExtraInfo result: ' + result);
}); });
...@@ -3611,9 +3810,11 @@ Obtains additional information of an app account. Additional information refers ...@@ -3611,9 +3810,11 @@ Obtains additional information of an app account. Additional information refers
**Example** **Example**
```js ```js
appAccountManager.getAccountExtraInfo('ZhangSan').then((data) => { import { BusinessError } from '@ohos.base';
appAccountManager.getAccountExtraInfo('ZhangSan').then((data: string) => {
console.log('getAccountExtraInfo, result: ' + data); console.log('getAccountExtraInfo, result: ' + data);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getAccountExtraInfo err: ' + JSON.stringify(err)); console.log('getAccountExtraInfo err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3641,7 +3842,9 @@ Obtains data associated with an app account. This API uses an asynchronous callb ...@@ -3641,7 +3842,9 @@ Obtains data associated with an app account. This API uses an asynchronous callb
**Example** **Example**
```js ```js
appAccountManager.getAssociatedData('ZhangSan', 'k001', (err, result) => { import { BusinessError } from '@ohos.base';
appAccountManager.getAssociatedData('ZhangSan', 'k001', (err: BusinessError, result: string) => {
console.log('getAssociatedData err: ' + JSON.stringify(err)); console.log('getAssociatedData err: ' + JSON.stringify(err));
console.log('getAssociatedData result: ' + result); console.log('getAssociatedData result: ' + result);
}); });
...@@ -3675,9 +3878,11 @@ Obtains data associated with an app account. This API uses a promise to return t ...@@ -3675,9 +3878,11 @@ Obtains data associated with an app account. This API uses a promise to return t
**Example** **Example**
```js ```js
appAccountManager.getAssociatedData('ZhangSan', 'k001').then((data) => { import { BusinessError } from '@ohos.base';
appAccountManager.getAssociatedData('ZhangSan', 'k001').then((data: string) => {
console.log('getAssociatedData: ' + data); console.log('getAssociatedData: ' + data);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getAssociatedData err: ' + JSON.stringify(err)); console.log('getAssociatedData err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3705,7 +3910,7 @@ Subscribes to account information changes of apps. ...@@ -3705,7 +3910,7 @@ Subscribes to account information changes of apps.
**Example** **Example**
```js ```js
function changeOnCallback(data){ function changeOnCallback(data: account_appAccount.AppAccountInfo[]): void {
console.debug('receive change data:' + JSON.stringify(data)); console.debug('receive change data:' + JSON.stringify(data));
} }
try{ try{
...@@ -3738,9 +3943,9 @@ Unsubscribes from account information changes. ...@@ -3738,9 +3943,9 @@ Unsubscribes from account information changes.
**Example** **Example**
```js ```js
function changeOnCallback(data){ function changeOnCallback(data: account_appAccount.AppAccountInfo[]): void {
console.debug('receive change data: ' + JSON.stringify(data)); console.debug('receive change data: ' + JSON.stringify(data));
appAccountManager.off('change', function(){ appAccountManager.off('change', () => {
console.debug('off finish'); console.debug('off finish');
}) })
} }
...@@ -3777,21 +3982,27 @@ Authenticates an app account with customized options. This API uses an asynchron ...@@ -3777,21 +3982,27 @@ Authenticates an app account with customized options. This API uses an asynchron
**Example** **Example**
```js ```js
function onResultCallback(code, result) { import { BusinessError } from '@ohos.base';
import Want from '@ohos.app.ability.Want';
import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
function onResultCallback(code: number, result: Record<string, Object>): void {
console.log('resultCode: ' + code); console.log('resultCode: ' + code);
console.log('result: ' + JSON.stringify(result)); console.log('result: ' + JSON.stringify(result));
} }
function onRequestRedirectedCallback(request) { function onRequestRedirectedCallback(request: Want): void {
let wantInfo = { let wantInfo: Want = {
deviceId: '', deviceId: '',
bundleName: 'com.example.accountjsdemo', bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData', action: 'ohos.want.action.viewData',
entities: ['entity.system.default'], entities: ['entity.system.default'],
} }
this.context.startAbility(wantInfo).then(() => { context.startAbility(wantInfo).then(() => {
console.log('startAbility successfully'); console.log('startAbility successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('startAbility err: ' + JSON.stringify(err)); console.log('startAbility err: ' + JSON.stringify(err));
}) })
} }
...@@ -3826,10 +4037,13 @@ Obtains the authorization token of the specified authentication type for an app ...@@ -3826,10 +4037,13 @@ Obtains the authorization token of the specified authentication type for an app
**Example** **Example**
```js ```js
appAccountManager.getOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', (err, data) => { import { BusinessError } from '@ohos.base';
console.log('getOAuthToken err: ' + JSON.stringify(err));
console.log('getOAuthToken token: ' + data); appAccountManager.getOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData',
}); (err: BusinessError, data: string) => {
console.log('getOAuthToken err: ' + JSON.stringify(err));
console.log('getOAuthToken token: ' + data);
});
``` ```
### getOAuthToken<sup>(deprecated)</sup> ### getOAuthToken<sup>(deprecated)</sup>
...@@ -3861,9 +4075,11 @@ Obtains the authorization token of the specified authentication type for an app ...@@ -3861,9 +4075,11 @@ Obtains the authorization token of the specified authentication type for an app
**Example** **Example**
```js ```js
appAccountManager.getOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData').then((data) => { import { BusinessError } from '@ohos.base';
appAccountManager.getOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData').then((data: string) => {
console.log('getOAuthToken token: ' + data); console.log('getOAuthToken token: ' + data);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOAuthToken err: ' + JSON.stringify(err)); console.log('getOAuthToken err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3892,7 +4108,9 @@ Sets an authorization token of the specific authentication type for an app accou ...@@ -3892,7 +4108,9 @@ Sets an authorization token of the specific authentication type for an app accou
**Example** **Example**
```js ```js
appAccountManager.setOAuthToken('LiSi', 'getSocialData', 'xxxx', (err) => { import { BusinessError } from '@ohos.base';
appAccountManager.setOAuthToken('LiSi', 'getSocialData', 'xxxx', (err: BusinessError) => {
console.log('setOAuthToken err: ' + JSON.stringify(err)); console.log('setOAuthToken err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3926,9 +4144,11 @@ Sets an authorization token of the specific authentication type for an app accou ...@@ -3926,9 +4144,11 @@ Sets an authorization token of the specific authentication type for an app accou
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
appAccountManager.setOAuthToken('LiSi', 'getSocialData', 'xxxx').then(() => { appAccountManager.setOAuthToken('LiSi', 'getSocialData', 'xxxx').then(() => {
console.log('setOAuthToken successfully'); console.log('setOAuthToken successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setOAuthToken err: ' + JSON.stringify(err)); console.log('setOAuthToken err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3958,9 +4178,12 @@ Deletes the authorization token of the specified authentication type for an app ...@@ -3958,9 +4178,12 @@ Deletes the authorization token of the specified authentication type for an app
**Example** **Example**
```js ```js
appAccountManager.deleteOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx', (err) => { import { BusinessError } from '@ohos.base';
console.log('deleteOAuthToken err: ' + JSON.stringify(err));
}); appAccountManager.deleteOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx',
(err: BusinessError) => {
console.log('deleteOAuthToken err: ' + JSON.stringify(err));
});
``` ```
### deleteOAuthToken<sup>(deprecated)</sup> ### deleteOAuthToken<sup>(deprecated)</sup>
...@@ -3993,9 +4216,11 @@ Deletes the authorization token of the specified authentication type for an app ...@@ -3993,9 +4216,11 @@ Deletes the authorization token of the specified authentication type for an app
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
appAccountManager.deleteOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx').then(() => { appAccountManager.deleteOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx').then(() => {
console.log('deleteOAuthToken successfully'); console.log('deleteOAuthToken successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('deleteOAuthToken err: ' + JSON.stringify(err)); console.log('deleteOAuthToken err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -4025,9 +4250,12 @@ Sets the visibility of an authorization token to an app. This API uses an asynch ...@@ -4025,9 +4250,12 @@ Sets the visibility of an authorization token to an app. This API uses an asynch
**Example** **Example**
```js ```js
appAccountManager.setOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true, (err) => { import { BusinessError } from '@ohos.base';
console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
}); appAccountManager.setOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true,
(err: BusinessError) => {
console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
});
``` ```
### setOAuthTokenVisibility<sup>(deprecated)</sup> ### setOAuthTokenVisibility<sup>(deprecated)</sup>
...@@ -4060,9 +4288,11 @@ Sets the visibility of an authorization token to an app. This API uses a promise ...@@ -4060,9 +4288,11 @@ Sets the visibility of an authorization token to an app. This API uses a promise
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
appAccountManager.setOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true).then(() => { appAccountManager.setOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true).then(() => {
console.log('setOAuthTokenVisibility successfully'); console.log('setOAuthTokenVisibility successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err)); console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -4091,10 +4321,13 @@ Checks the visibility of an authorization token of the specified authentication ...@@ -4091,10 +4321,13 @@ Checks the visibility of an authorization token of the specified authentication
**Example** **Example**
```js ```js
appAccountManager.checkOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', (err, data) => { import { BusinessError } from '@ohos.base';
appAccountManager.checkOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo',
(err: BusinessError, data: boolean) => {
console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
console.log('checkOAuthTokenVisibility isVisible: ' + data); console.log('checkOAuthTokenVisibility isVisible: ' + data);
}); });
``` ```
### checkOAuthTokenVisibility<sup>(deprecated)</sup> ### checkOAuthTokenVisibility<sup>(deprecated)</sup>
...@@ -4126,10 +4359,13 @@ Checks the visibility of an authorization token of the specified authentication ...@@ -4126,10 +4359,13 @@ Checks the visibility of an authorization token of the specified authentication
**Example** **Example**
```js ```js
appAccountManager.checkOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo').then((data) => { import { BusinessError } from '@ohos.base';
console.log('checkOAuthTokenVisibility isVisible: ' + data);
}).catch((err) => { appAccountManager.checkOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo').then((
console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); data: boolean) => {
console.log('checkOAuthTokenVisibility isVisible: ' + data);
}).catch((err: BusinessError) => {
console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -4156,10 +4392,13 @@ Obtains all tokens visible to the invoker for an app account. This API uses an a ...@@ -4156,10 +4392,13 @@ Obtains all tokens visible to the invoker for an app account. This API uses an a
**Example** **Example**
```js ```js
appAccountManager.getAllOAuthTokens('LiSi', 'com.example.accountjsdemo', (err, data) => { import { BusinessError } from '@ohos.base';
appAccountManager.getAllOAuthTokens('LiSi', 'com.example.accountjsdemo',
(err: BusinessError, data: account_appAccount.OAuthTokenInfo[]) => {
console.log('getAllOAuthTokens err: ' + JSON.stringify(err)); console.log('getAllOAuthTokens err: ' + JSON.stringify(err));
console.log('getAllOAuthTokens data: ' + JSON.stringify(data)); console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
}); });
``` ```
### getAllOAuthTokens<sup>(deprecated)</sup> ### getAllOAuthTokens<sup>(deprecated)</sup>
...@@ -4190,10 +4429,13 @@ Obtains all tokens visible to the invoker for an app account. This API uses a pr ...@@ -4190,10 +4429,13 @@ Obtains all tokens visible to the invoker for an app account. This API uses a pr
**Example** **Example**
```js ```js
appAccountManager.getAllOAuthTokens('LiSi', 'com.example.accountjsdemo').then((data) => { import { BusinessError } from '@ohos.base';
console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
}).catch((err) => { appAccountManager.getAllOAuthTokens('LiSi', 'com.example.accountjsdemo').then((
console.log('getAllOAuthTokens err: ' + JSON.stringify(err)); data: account_appAccount.OAuthTokenInfo[]) => {
console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
console.log('getAllOAuthTokens err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -4220,7 +4462,9 @@ Obtains the authorization list of the specified authentication type for an app a ...@@ -4220,7 +4462,9 @@ Obtains the authorization list of the specified authentication type for an app a
**Example** **Example**
```js ```js
appAccountManager.getOAuthList('LiSi', 'getSocialData', (err, data) => { import { BusinessError } from '@ohos.base';
appAccountManager.getOAuthList('LiSi', 'getSocialData', (err: BusinessError, data: string[]) => {
console.log('getOAuthList err: ' + JSON.stringify(err)); console.log('getOAuthList err: ' + JSON.stringify(err));
console.log('getOAuthList data: ' + JSON.stringify(data)); console.log('getOAuthList data: ' + JSON.stringify(data));
}); });
...@@ -4254,9 +4498,11 @@ Obtains the authorization list of the specified authentication type for an app a ...@@ -4254,9 +4498,11 @@ Obtains the authorization list of the specified authentication type for an app a
**Example** **Example**
```js ```js
appAccountManager.getOAuthList('LiSi', 'getSocialData').then((data) => { import { BusinessError } from '@ohos.base';
appAccountManager.getOAuthList('LiSi', 'getSocialData').then((data: string[]) => {
console.log('getOAuthList data: ' + JSON.stringify(data)); console.log('getOAuthList data: ' + JSON.stringify(data));
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOAuthList err: ' + JSON.stringify(err)); console.log('getOAuthList err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -4283,22 +4529,27 @@ Obtains the authenticator callback for an authentication session. This API uses ...@@ -4283,22 +4529,27 @@ Obtains the authenticator callback for an authentication session. This API uses
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
import Want from '@ohos.app.ability.Want';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
export default class EntryAbility extends UIAbility { export default class EntryAbility extends UIAbility {
onCreate(want, param) { onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function.
var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID]; let sessionId: string = want.parameters![account_appAccount.Constants.KEY_SESSION_ID] as string;
appAccountManager.getAuthenticatorCallback(sessionId, (err, callback) => { appAccountManager.getAuthenticatorCallback(sessionId,
if (err.code != account_appAccount.ResultCode.SUCCESS) { (err: BusinessError, callback: account_appAccount.AuthenticatorCallback) => {
console.log('getAuthenticatorCallback err: ' + JSON.stringify(err)); if (err.code != account_appAccount.ResultCode.SUCCESS) {
return; console.log('getAuthenticatorCallback err: ' + JSON.stringify(err));
} return;
var result = {[account_appAccount.Constants.KEY_NAME]: 'LiSi', }
[account_appAccount.Constants.KEY_OWNER]: 'com.example.accountjsdemo', callback.onResult(account_appAccount.ResultCode.SUCCESS, {
[account_appAccount.Constants.KEY_AUTH_TYPE]: 'getSocialData', name: 'LiSi',
[account_appAccount.Constants.KEY_TOKEN]: 'xxxxxx'}; owner: 'com.example.accountjsdemo',
callback.onResult(account_appAccount.ResultCode.SUCCESS, result); authType: 'getSocialData',
}); token: 'xxxxxx'}
);
});
} }
} }
``` ```
...@@ -4330,18 +4581,23 @@ Obtains the authenticator callback for an authentication session. This API uses ...@@ -4330,18 +4581,23 @@ Obtains the authenticator callback for an authentication session. This API uses
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
import Want from '@ohos.app.ability.Want';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
export default class EntryAbility extends UIAbility { export default class EntryAbility extends UIAbility {
onCreate(want, param) { onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function.
var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID]; let sessionId: string = want.parameters![account_appAccount.Constants.KEY_SESSION_ID] as string;
appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => { appAccountManager.getAuthenticatorCallback(sessionId).then((
var result = {[account_appAccount.Constants.KEY_NAME]: 'LiSi', callback: account_appAccount.AuthenticatorCallback) => {
[account_appAccount.Constants.KEY_OWNER]: 'com.example.accountjsdemo', callback.onResult(account_appAccount.ResultCode.SUCCESS, {
[account_appAccount.Constants.KEY_AUTH_TYPE]: 'getSocialData', name: 'LiSi',
[account_appAccount.Constants.KEY_TOKEN]: 'xxxxxx'}; owner: 'com.example.accountjsdemo',
callback.onResult(account_appAccount.ResultCode.SUCCESS, result); authType: 'getSocialData',
}).catch((err) => { token: 'xxxxxx'}
);
}).catch((err: BusinessError) => {
console.log('getAuthenticatorCallback err: ' + JSON.stringify(err)); console.log('getAuthenticatorCallback err: ' + JSON.stringify(err));
}); });
} }
...@@ -4370,10 +4626,13 @@ Obtains the authenticator information of an app. This API uses an asynchronous c ...@@ -4370,10 +4626,13 @@ Obtains the authenticator information of an app. This API uses an asynchronous c
**Example** **Example**
```js ```js
appAccountManager.getAuthenticatorInfo('com.example.accountjsdemo', (err, data) => { import { BusinessError } from '@ohos.base';
appAccountManager.getAuthenticatorInfo('com.example.accountjsdemo',
(err: BusinessError, data: account_appAccount.AuthenticatorInfo) => {
console.log('getAuthenticatorInfo err: ' + JSON.stringify(err)); console.log('getAuthenticatorInfo err: ' + JSON.stringify(err));
console.log('getAuthenticatorInfo data: ' + JSON.stringify(data)); console.log('getAuthenticatorInfo data: ' + JSON.stringify(data));
}); });
``` ```
### getAuthenticatorInfo<sup>(deprecated)</sup> ### getAuthenticatorInfo<sup>(deprecated)</sup>
...@@ -4403,10 +4662,13 @@ Obtains the authenticator information of an app. This API uses a promise to retu ...@@ -4403,10 +4662,13 @@ Obtains the authenticator information of an app. This API uses a promise to retu
**Example** **Example**
```js ```js
appAccountManager.getAuthenticatorInfo('com.example.accountjsdemo').then((data) => { import { BusinessError } from '@ohos.base';
console.log('getAuthenticatorInfo: ' + JSON.stringify(data));
}).catch((err) => { appAccountManager.getAuthenticatorInfo('com.example.accountjsdemo').then((
console.log('getAuthenticatorInfo err: ' + JSON.stringify(err)); data: account_appAccount.AuthenticatorInfo) => {
console.log('getAuthenticatorInfo: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
console.log('getAuthenticatorInfo err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -4609,11 +4871,13 @@ Called to return the result of an authentication request. ...@@ -4609,11 +4871,13 @@ Called to return the result of an authentication request.
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let appAccountManager = account_appAccount.createAppAccountManager(); let appAccountManager = account_appAccount.createAppAccountManager();
var sessionId = '1234'; let sessionId = '1234';
appAccountManager.getAuthCallback(sessionId).then((callback) => { appAccountManager.getAuthCallback(sessionId).then((callback: account_appAccount.AuthCallback) => {
var result = { let result: account_appAccount.AuthResult = {
accountInfo: { account: {
name: 'Lisi', name: 'Lisi',
owner: 'com.example.accountjsdemo', owner: 'com.example.accountjsdemo',
}, },
...@@ -4623,7 +4887,7 @@ Called to return the result of an authentication request. ...@@ -4623,7 +4887,7 @@ Called to return the result of an authentication request.
} }
}; };
callback.onResult(account_appAccount.ResultCode.SUCCESS, result); callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getAuthCallback err: ' + JSON.stringify(err)); console.log('getAuthCallback err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -4646,16 +4910,19 @@ Called to redirect a request. ...@@ -4646,16 +4910,19 @@ Called to redirect a request.
```js ```js
class MyAuthenticator extends account_appAccount.Authenticator { class MyAuthenticator extends account_appAccount.Authenticator {
createAccountImplicitly(options, callback) { createAccountImplicitly(
callback.onRequestRedirected({ options: account_appAccount.CreateAccountImplicitlyOptions, callback: account_appAccount.AuthCallback) {
bundleName: 'com.example.accountjsdemo', let want: Want = {
abilityName: 'com.example.accountjsdemo.LoginAbility', bundleName: 'com.example.accountjsdemo',
}); abilityName: 'com.example.accountjsdemo.LoginAbility',
};
callback.onRequestRedirected(want);
} }
auth(name, authType, options, callback) { auth(name: string, authType: string,
var result = { options: { [key: string]: Object }, callback: account_appAccount.AuthCallback) {
accountInfo: { let result: account_appAccount.AuthResult = {
account: {
name: 'Lisi', name: 'Lisi',
owner: 'com.example.accountjsdemo', owner: 'com.example.accountjsdemo',
}, },
...@@ -4680,12 +4947,16 @@ Called to continue to process the request. ...@@ -4680,12 +4947,16 @@ Called to continue to process the request.
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let appAccountManager = account_appAccount.createAppAccountManager(); let appAccountManager = account_appAccount.createAppAccountManager();
var sessionId = '1234'; let sessionId = '1234';
appAccountManager.getAuthCallback(sessionId).then((callback) => { appAccountManager.getAuthCallback(sessionId).then((callback: account_appAccount.AuthCallback) => {
if (callback.onRequestContinued != undefined) {
callback.onRequestContinued(); callback.onRequestContinued();
}).catch((err) => { }
console.log('getAuthCallback err: ' + JSON.stringify(err)); }).catch((err: BusinessError) => {
console.log('getAuthCallback err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -4715,15 +4986,18 @@ Called to return the result of an authentication request. ...@@ -4715,15 +4986,18 @@ Called to return the result of an authentication request.
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let appAccountManager = account_appAccount.createAppAccountManager(); let appAccountManager = account_appAccount.createAppAccountManager();
var sessionId = '1234'; let sessionId = '1234';
appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => { appAccountManager.getAuthenticatorCallback(sessionId).then((callback: account_appAccount.AuthenticatorCallback) => {
var result = {[account_appAccount.Constants.KEY_NAME]: 'LiSi', callback.onResult(account_appAccount.ResultCode.SUCCESS, {
[account_appAccount.Constants.KEY_OWNER]: 'com.example.accountjsdemo', name: 'LiSi',
[account_appAccount.Constants.KEY_AUTH_TYPE]: 'getSocialData', owner: 'com.example.accountjsdemo',
[account_appAccount.Constants.KEY_TOKEN]: 'xxxxxx'}; authType: 'getSocialData',
callback.onResult(account_appAccount.ResultCode.SUCCESS, result); token: 'xxxxxx'}
}).catch((err) => { );
}).catch((err: BusinessError) => {
console.log('getAuthenticatorCallback err: ' + JSON.stringify(err)); console.log('getAuthenticatorCallback err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -4746,42 +5020,26 @@ Called to redirect a request. ...@@ -4746,42 +5020,26 @@ Called to redirect a request.
```js ```js
class MyAuthenticator extends account_appAccount.Authenticator { class MyAuthenticator extends account_appAccount.Authenticator {
addAccountImplicitly(authType, callerBundleName, options, callback) { addAccountImplicitly(authType: string, callerBundleName: string,
callback.onRequestRedirected({ options: { [key: string]: Object }, callback: account_appAccount.AuthenticatorCallback) {
bundleName: 'com.example.accountjsdemo', let want: Want = {
abilityName: 'com.example.accountjsdemo.LoginAbility', bundleName: 'com.example.accountjsdemo',
}); abilityName: 'com.example.accountjsdemo.LoginAbility',
};
callback.onRequestRedirected(want);
} }
authenticate(name, authType, callerBundleName, options, callback) { authenticate(name: string, authType: string, callerBundleName: string,
var result = {[account_appAccount.Constants.KEY_NAME]: name, options: { [key: string]: Object }, callback: account_appAccount.AuthenticatorCallback) {
[account_appAccount.Constants.KEY_AUTH_TYPE]: authType, callback.onResult(account_appAccount.ResultCode.SUCCESS, {
[account_appAccount.Constants.KEY_TOKEN]: 'xxxxxx'}; name: name,
callback.onResult(account_appAccount.ResultCode.SUCCESS, result); authType: authType,
token: 'xxxxxx'}
);
} }
} }
``` ```
### onRequestContinued<sup>9+</sup>
onRequestContinued?: () =&gt; void
Called to continue to process the request.
**System capability**: SystemCapability.Account.AppAccount
**Example**
```js
let appAccountManager = account_appAccount.createAppAccountManager();
var sessionId = '1234';
appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
callback.onRequestContinued();
}).catch((err) => {
console.log('getAuthenticatorCallback err: ' + JSON.stringify(err));
});
```
## Authenticator<sup>8+</sup> ## Authenticator<sup>8+</sup>
Provides APIs to operate the authenticator. Provides APIs to operate the authenticator.
...@@ -4935,49 +5193,62 @@ Obtains the remote object of an authenticator. This API cannot be overloaded. ...@@ -4935,49 +5193,62 @@ Obtains the remote object of an authenticator. This API cannot be overloaded.
**Example** **Example**
```js ```js
import rpc from '@ohos.rpc';
class MyAuthenticator extends account_appAccount.Authenticator { class MyAuthenticator extends account_appAccount.Authenticator {
addAccountImplicitly(authType, callerBundleName, options, callback) { addAccountImplicitly(authType: string, callerBundleName: string,
callback.onRequestRedirected({ options: { [key: string]: Object }, callback: account_appAccount.AuthenticatorCallback) {
bundleName: 'com.example.accountjsdemo', let want: Want = {
abilityName: 'com.example.accountjsdemo.LoginAbility', bundleName: 'com.example.accountjsdemo',
}); abilityName: 'com.example.accountjsdemo.LoginAbility',
};
callback.onRequestRedirected(want);
} }
authenticate(name, authType, callerBundleName, options, callback) { authenticate(name: string, authType: string, callerBundleName: string,
var result = {[account_appAccount.Constants.KEY_NAME]: name, options: { [key: string]: Object }, callback: account_appAccount.AuthenticatorCallback) {
[account_appAccount.Constants.KEY_AUTH_TYPE]: authType, callback.onResult(account_appAccount.ResultCode.SUCCESS, {
[account_appAccount.Constants.KEY_TOKEN]: 'xxxxxx'}; name: name,
callback.onResult(account_appAccount.ResultCode.SUCCESS, result); authType: authType,
token: 'xxxxxx'}
);
} }
verifyCredential(name, options, callback) { verifyCredential(name: string,
callback.onRequestRedirected({ options: account_appAccount.VerifyCredentialOptions, callback: account_appAccount.AuthCallback) {
bundleName: 'com.example.accountjsdemo', let want: Want = {
abilityName: 'com.example.accountjsdemo.VerifyAbility', bundleName: 'com.example.accountjsdemo',
parameters: { abilityName: 'com.example.accountjsdemo.VerifyAbility',
name: name parameters: {
} name: name
}); }
};
callback.onRequestRedirected(want);
} }
setProperties(options, callback) { setProperties(options: account_appAccount.SetPropertiesOptions, callback: account_appAccount.AuthCallback) {
callback.onResult(account_appAccount.ResultCode.SUCCESS, {}); let want: Want = {
bundleName: 'com.example.accountjsdemo',
abilityName: 'com.example.accountjsdemo.SetPropertiesAbility',
parameters: {
options: options
}
};
callback.onRequestRedirected(want);
} }
checkAccountLabels(name, labels, callback) { checkAccountLabels(name: string, labels: string[], callback: account_appAccount.AuthCallback) {
var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: false}; callback.onResult(account_appAccount.ResultCode.SUCCESS);
callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
} }
checkAccountRemovable(name, callback) { checkAccountRemovable(name: string, callback: account_appAccount.AuthCallback) {
var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: true}; callback.onResult(account_appAccount.ResultCode.SUCCESS);
callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
} }
} }
var authenticator = null;
export default { export default {
onConnect(want) { onConnect(want): rpc.RemoteObject { // serviceAbility lifecycle function.
authenticator = new MyAuthenticator(); let authenticator = new MyAuthenticator();
return authenticator.getRemoteObject(); return authenticator.getRemoteObject();
} }
} }
......
...@@ -59,15 +59,18 @@ Obtains distributed account information. This API uses an asynchronous callback ...@@ -59,15 +59,18 @@ Obtains distributed account information. This API uses an asynchronous callback
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
const accountAbility = account_distributedAccount.getDistributedAccountAbility(); const accountAbility = account_distributedAccount.getDistributedAccountAbility();
try { try {
accountAbility.getOsAccountDistributedInfo((err, data) => { accountAbility.getOsAccountDistributedInfo(
if (err) { (err: BusinessError, data: account_distributedAccount.DistributedInfo) => {
console.log('getOsAccountDistributedInfo exception: ' + JSON.stringify(err)); if (err) {
} else { console.log('getOsAccountDistributedInfo exception: ' + JSON.stringify(err));
console.log('distributed information: ' + JSON.stringify(data)); } else {
} console.log('distributed information: ' + JSON.stringify(data));
}); }
});
} catch (err) { } catch (err) {
console.log('getOsAccountDistributedInfo exception: ' + JSON.stringify(err)); console.log('getOsAccountDistributedInfo exception: ' + JSON.stringify(err));
} }
...@@ -97,11 +100,13 @@ Obtains distributed account information. This API uses a promise to return the r ...@@ -97,11 +100,13 @@ Obtains distributed account information. This API uses a promise to return the r
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
const accountAbility = account_distributedAccount.getDistributedAccountAbility(); const accountAbility = account_distributedAccount.getDistributedAccountAbility();
try { try {
accountAbility.getOsAccountDistributedInfo().then((data) => { accountAbility.getOsAccountDistributedInfo().then((data: account_distributedAccount.DistributedInfo) => {
console.log('distributed information: ' + JSON.stringify(data)); console.log('distributed information: ' + JSON.stringify(data));
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOsAccountDistributedInfo exception: ' + JSON.stringify(err)); console.log('getOsAccountDistributedInfo exception: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -137,15 +142,18 @@ Obtains distributed information about an OS account. This API uses an asynchrono ...@@ -137,15 +142,18 @@ Obtains distributed information about an OS account. This API uses an asynchrono
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
const accountAbility = account_distributedAccount.getDistributedAccountAbility(); const accountAbility = account_distributedAccount.getDistributedAccountAbility();
try { try {
accountAbility.getOsAccountDistributedInfoByLocalId(100, (err, data) => { accountAbility.getOsAccountDistributedInfoByLocalId(100,
if (err) { (err: BusinessError, data: account_distributedAccount.DistributedInfo) => {
console.log('getOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err)); if (err) {
} else { console.log('getOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err));
console.log('distributed information: ' + JSON.stringify(data)); } else {
} console.log('distributed information: ' + JSON.stringify(data));
}); }
});
} catch (err) { } catch (err) {
console.log('getOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err)); console.log('getOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err));
} }
...@@ -178,15 +186,18 @@ Obtains distributed information about an OS account. This API uses a promise to ...@@ -178,15 +186,18 @@ Obtains distributed information about an OS account. This API uses a promise to
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
const accountAbility = account_distributedAccount.getDistributedAccountAbility(); const accountAbility = account_distributedAccount.getDistributedAccountAbility();
try { try {
accountAbility.getOsAccountDistributedInfoByLocalId(100).then((data) => { accountAbility.getOsAccountDistributedInfoByLocalId(100).then((
console.log('distributed information: ' + JSON.stringify(data)); data: account_distributedAccount.DistributedInfo) => {
}).catch((err) => { console.log('distributed information: ' + JSON.stringify(data));
console.log('getOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err)); }).catch((err: BusinessError) => {
console.log('getOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
console.log('getOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err)); console.log('getOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err));
} }
``` ```
...@@ -211,14 +222,17 @@ Obtains distributed account information. This API uses an asynchronous callback ...@@ -211,14 +222,17 @@ Obtains distributed account information. This API uses an asynchronous callback
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
const accountAbility = account_distributedAccount.getDistributedAccountAbility(); const accountAbility = account_distributedAccount.getDistributedAccountAbility();
accountAbility.queryOsAccountDistributedInfo((err, data) => { accountAbility.queryOsAccountDistributedInfo(
if (err) { (err: BusinessError, data: account_distributedAccount.DistributedInfo) => {
console.log('queryOsAccountDistributedInfo exception: ' + JSON.stringify(err)); if (err) {
} else { console.log('queryOsAccountDistributedInfo exception: ' + JSON.stringify(err));
console.log('distributed information: ' + JSON.stringify(data)); } else {
} console.log('distributed information: ' + JSON.stringify(data));
}); }
});
``` ```
### queryOsAccountDistributedInfo<sup>(deprecated)</sup> ### queryOsAccountDistributedInfo<sup>(deprecated)</sup>
...@@ -243,10 +257,12 @@ Obtains distributed account information. This API uses a promise to return the r ...@@ -243,10 +257,12 @@ Obtains distributed account information. This API uses a promise to return the r
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
const accountAbility = account_distributedAccount.getDistributedAccountAbility(); const accountAbility = account_distributedAccount.getDistributedAccountAbility();
accountAbility.queryOsAccountDistributedInfo().then((data) => { accountAbility.queryOsAccountDistributedInfo().then((data: account_distributedAccount.DistributedInfo) => {
console.log('distributed information: ' + JSON.stringify(data)); console.log('distributed information: ' + JSON.stringify(data));
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('queryOsAccountDistributedInfo exception: ' + JSON.stringify(err)); console.log('queryOsAccountDistributedInfo exception: ' + JSON.stringify(err));
}); });
``` ```
...@@ -278,10 +294,13 @@ Sets the distributed account information. This API uses an asynchronous callback ...@@ -278,10 +294,13 @@ Sets the distributed account information. This API uses an asynchronous callback
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
const accountAbility = account_distributedAccount.getDistributedAccountAbility(); const accountAbility = account_distributedAccount.getDistributedAccountAbility();
let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'}; let accountInfo: account_distributedAccount.DistributedInfo =
{id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'};
try { try {
accountAbility.setOsAccountDistributedInfo(accountInfo, (err) => { accountAbility.setOsAccountDistributedInfo(accountInfo, (err: BusinessError) => {
if (err) { if (err) {
console.log('setOsAccountDistributedInfo exception: ' + JSON.stringify(err)); console.log('setOsAccountDistributedInfo exception: ' + JSON.stringify(err));
} else { } else {
...@@ -325,12 +344,15 @@ Sets the distributed account information. This API uses a promise to return the ...@@ -325,12 +344,15 @@ Sets the distributed account information. This API uses a promise to return the
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
const accountAbility = account_distributedAccount.getDistributedAccountAbility(); const accountAbility = account_distributedAccount.getDistributedAccountAbility();
let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'}; let accountInfo: account_distributedAccount.DistributedInfo =
{id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'};
try { try {
accountAbility.setOsAccountDistributedInfo(accountInfo).then(() => { accountAbility.setOsAccountDistributedInfo(accountInfo).then(() => {
console.log('setOsAccountDistributedInfo successfully'); console.log('setOsAccountDistributedInfo successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setOsAccountDistributedInfo exception: ' + JSON.stringify(err)); console.log('setOsAccountDistributedInfo exception: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -368,10 +390,13 @@ Sets the distributed information for an OS account. This API uses an asynchronou ...@@ -368,10 +390,13 @@ Sets the distributed information for an OS account. This API uses an asynchronou
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
const accountAbility = account_distributedAccount.getDistributedAccountAbility(); const accountAbility = account_distributedAccount.getDistributedAccountAbility();
let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'}; let accountInfo: account_distributedAccount.DistributedInfo =
{id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'};
try { try {
accountAbility.setOsAccountDistributedInfoByLocalId(100, accountInfo, (err) => { accountAbility.setOsAccountDistributedInfoByLocalId(100, accountInfo, (err: BusinessError) => {
if (err) { if (err) {
console.log('setOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err)); console.log('setOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err));
} else { } else {
...@@ -419,12 +444,15 @@ Sets the distributed information for an OS account. This API uses a promise to r ...@@ -419,12 +444,15 @@ Sets the distributed information for an OS account. This API uses a promise to r
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
const accountAbility = account_distributedAccount.getDistributedAccountAbility(); const accountAbility = account_distributedAccount.getDistributedAccountAbility();
let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'}; let accountInfo: account_distributedAccount.DistributedInfo =
{id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'};
try { try {
accountAbility.setOsAccountDistributedInfoByLocalId(100, accountInfo).then(() => { accountAbility.setOsAccountDistributedInfoByLocalId(100, accountInfo).then(() => {
console.log('setOsAccountDistributedInfoByLocalId successfully'); console.log('setOsAccountDistributedInfoByLocalId successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err)); console.log('setOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -455,9 +483,12 @@ Updates the distributed account information. This API uses an asynchronous callb ...@@ -455,9 +483,12 @@ Updates the distributed account information. This API uses an asynchronous callb
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
const accountAbility = account_distributedAccount.getDistributedAccountAbility(); const accountAbility = account_distributedAccount.getDistributedAccountAbility();
let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'}; let accountInfo: account_distributedAccount.DistributedInfo =
accountAbility.updateOsAccountDistributedInfo(accountInfo, (err) => { {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'};
accountAbility.updateOsAccountDistributedInfo(accountInfo, (err: BusinessError) => {
if (err) { if (err) {
console.log('queryOsAccountDistributedInfo exception: ' + JSON.stringify(err)); console.log('queryOsAccountDistributedInfo exception: ' + JSON.stringify(err));
} else { } else {
...@@ -492,11 +523,14 @@ Updates the distributed account information. This API uses a promise to return t ...@@ -492,11 +523,14 @@ Updates the distributed account information. This API uses a promise to return t
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
const accountAbility = account_distributedAccount.getDistributedAccountAbility(); const accountAbility = account_distributedAccount.getDistributedAccountAbility();
let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'}; let accountInfo: account_distributedAccount.DistributedInfo =
{id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'};
accountAbility.updateOsAccountDistributedInfo(accountInfo).then(() => { accountAbility.updateOsAccountDistributedInfo(accountInfo).then(() => {
console.log('updateOsAccountDistributedInfo successfully'); console.log('updateOsAccountDistributedInfo successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('updateOsAccountDistributedInfo exception: ' + JSON.stringify(err)); console.log('updateOsAccountDistributedInfo exception: ' + JSON.stringify(err));
}); });
``` ```
......
...@@ -79,10 +79,10 @@ Activates an OS account. This API uses an asynchronous callback to return the re ...@@ -79,10 +79,10 @@ Activates an OS account. This API uses an asynchronous callback to return the re
**Example**: Activate OS account 100. **Example**: Activate OS account 100.
```js ```js
let accountManager = account_osAccount.getAccountManager(); import { BusinessError } from '@ohos.base';
let localId = 100; let localId: number = 100;
try { try {
accountManager.activateOsAccount(localId, (err)=>{ accountManager.activateOsAccount(localId, (err: BusinessError)=>{
if (err) { if (err) {
console.error(`activateOsAccount failed, code is ${err.code}, message is ${err.message}`); console.error(`activateOsAccount failed, code is ${err.code}, message is ${err.message}`);
} else { } else {
...@@ -130,12 +130,13 @@ Activates an OS account. This API uses a promise to return the result. ...@@ -130,12 +130,13 @@ Activates an OS account. This API uses a promise to return the result.
**Example**: Activate OS account 100. **Example**: Activate OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
try { try {
accountManager.activateOsAccount(localId).then(() => { accountManager.activateOsAccount(localId).then(() => {
console.log('activateOsAccount successfully'); console.log('activateOsAccount successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('activateOsAccount failed, err:' + JSON.stringify(err)); console.log('activateOsAccount failed, err:' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -166,9 +167,10 @@ Checks whether multiple OS accounts are supported. This API uses an asynchronous ...@@ -166,9 +167,10 @@ Checks whether multiple OS accounts are supported. This API uses an asynchronous
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.checkMultiOsAccountEnabled((err, isEnabled) => { accountManager.checkMultiOsAccountEnabled((err: BusinessError, isEnabled: boolean) => {
if (err) { if (err) {
console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`); console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
} else { } else {
...@@ -203,11 +205,12 @@ Checks whether multiple OS accounts are supported. This API uses a promise to re ...@@ -203,11 +205,12 @@ Checks whether multiple OS accounts are supported. This API uses a promise to re
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
try { try {
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.checkMultiOsAccountEnabled().then((isEnabled) => { accountManager.checkMultiOsAccountEnabled().then((isEnabled: boolean) => {
console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled); console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`); console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
}); });
} catch (err) { } catch (err) {
...@@ -243,10 +246,11 @@ Checks whether an OS account is activated. This API uses an asynchronous callbac ...@@ -243,10 +246,11 @@ Checks whether an OS account is activated. This API uses an asynchronous callbac
**Example**: Check whether OS account 100 is activated. **Example**: Check whether OS account 100 is activated.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
try { try {
accountManager.checkOsAccountActivated(localId, (err, isActivated) => { accountManager.checkOsAccountActivated(localId, (err: BusinessError, isActivated: boolean) => {
if (err) { if (err) {
console.log('checkOsAccountActivated failed, error:' + JSON.stringify(err)); console.log('checkOsAccountActivated failed, error:' + JSON.stringify(err));
} else { } else {
...@@ -291,12 +295,13 @@ Checks whether an OS account is activated. This API uses a promise to return the ...@@ -291,12 +295,13 @@ Checks whether an OS account is activated. This API uses a promise to return the
**Example**: Check whether OS account 100 is activated. **Example**: Check whether OS account 100 is activated.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
try { try {
accountManager.checkOsAccountActivated(localId).then((isActivated) => { accountManager.checkOsAccountActivated(localId).then((isActivated: boolean) => {
console.log('checkOsAccountActivated successfully, isActivated: ' + isActivated); console.log('checkOsAccountActivated successfully, isActivated: ' + isActivated);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('checkOsAccountActivated failed, error: ' + JSON.stringify(err)); console.log('checkOsAccountActivated failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -333,11 +338,12 @@ Checks whether the specified constraint is enabled for an OS account. This API u ...@@ -333,11 +338,12 @@ Checks whether the specified constraint is enabled for an OS account. This API u
**Example**: Check whether OS account 100 is forbidden to use Wi-Fi. **Example**: Check whether OS account 100 is forbidden to use Wi-Fi.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
let constraint = 'constraint.wifi'; let constraint: string = 'constraint.wifi';
try { try {
accountManager.checkOsAccountConstraintEnabled(localId, constraint, (err, isEnabled)=>{ accountManager.checkOsAccountConstraintEnabled(localId, constraint, (err: BusinessError, isEnabled: boolean)=>{
if (err) { if (err) {
console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err)); console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -383,13 +389,14 @@ Checks whether the specified constraint is enabled for an OS account. This API u ...@@ -383,13 +389,14 @@ Checks whether the specified constraint is enabled for an OS account. This API u
**Example**: Check whether OS account 100 is forbidden to use Wi-Fi. **Example**: Check whether OS account 100 is forbidden to use Wi-Fi.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
let constraint = 'constraint.wifi'; let constraint: string = 'constraint.wifi';
try { try {
accountManager.checkOsAccountConstraintEnabled(localId, constraint).then((isEnabled) => { accountManager.checkOsAccountConstraintEnabled(localId, constraint).then((isEnabled: boolean) => {
console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled); console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err)); console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -420,9 +427,10 @@ Checks whether this OS account is a test account. This API uses an asynchronous ...@@ -420,9 +427,10 @@ Checks whether this OS account is a test account. This API uses an asynchronous
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.checkOsAccountTestable((err, isTestable) => { accountManager.checkOsAccountTestable((err: BusinessError, isTestable: boolean) => {
if (err) { if (err) {
console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err)); console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -457,11 +465,12 @@ Checks whether this OS account is a test account. This API uses a promise to ret ...@@ -457,11 +465,12 @@ Checks whether this OS account is a test account. This API uses a promise to ret
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.checkOsAccountTestable().then((isTestable) => { accountManager.checkOsAccountTestable().then((isTestable: boolean) => {
console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable); console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err)); console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -492,9 +501,10 @@ Checks whether this OS account has been verified. This API uses an asynchronous ...@@ -492,9 +501,10 @@ Checks whether this OS account has been verified. This API uses an asynchronous
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.checkOsAccountVerified((err, isVerified) => { accountManager.checkOsAccountVerified((err: BusinessError, isVerified: boolean) => {
if (err) { if (err) {
console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err)); console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -529,11 +539,12 @@ Checks whether this OS account has been verified. This API uses a promise to ret ...@@ -529,11 +539,12 @@ Checks whether this OS account has been verified. This API uses a promise to ret
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.checkOsAccountVerified().then((isVerified) => { accountManager.checkOsAccountVerified().then((isVerified: boolean) => {
console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified); console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err)); console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -569,10 +580,11 @@ Checks whether an OS account has been verified. This API uses an asynchronous ca ...@@ -569,10 +580,11 @@ Checks whether an OS account has been verified. This API uses an asynchronous ca
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
try { try {
accountManager.checkOsAccountVerified(localId, (err, isVerified) => { accountManager.checkOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => {
if (err) { if (err) {
console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err)); console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -617,12 +629,13 @@ Checks whether an OS account has been verified. This API uses a promise to retur ...@@ -617,12 +629,13 @@ Checks whether an OS account has been verified. This API uses a promise to retur
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
try { try {
accountManager.checkOsAccountVerified(localId).then((isVerified) => { accountManager.checkOsAccountVerified(localId).then((isVerified: boolean) => {
console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified); console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err)); console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -653,11 +666,12 @@ Checks whether this OS account has been verified. This API uses a promise to ret ...@@ -653,11 +666,12 @@ Checks whether this OS account has been verified. This API uses a promise to ret
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.checkOsAccountVerified().then((isVerified) => { accountManager.checkOsAccountVerified().then((isVerified: boolean) => {
console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified); console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err)); console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -696,16 +710,18 @@ Deletes an OS account. This API uses an asynchronous callback to return the resu ...@@ -696,16 +710,18 @@ Deletes an OS account. This API uses an asynchronous callback to return the resu
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let accountName = 'testAccountName'; let accountName: string = 'testAccountName';
try { try {
accountManager.createOsAccount(accountName, account_osAccount.OsAccountType.NORMAL, (err, osAccountInfo) => { accountManager.createOsAccount(accountName, account_osAccount.OsAccountType.NORMAL,
accountManager.removeOsAccount(osAccountInfo.localId, (err)=>{ (err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo) => {
if (err) { accountManager.removeOsAccount(osAccountInfo.localId, (err: BusinessError)=>{
console.log('removeOsAccount failed, error: ' + JSON.stringify(err)); if (err) {
} else { console.log('removeOsAccount failed, error: ' + JSON.stringify(err));
console.log('removeOsAccount successfully'); } else {
} console.log('removeOsAccount successfully');
}
}); });
}); });
} catch (err) { } catch (err) {
...@@ -749,15 +765,17 @@ Deletes an OS account. This API uses a promise to return the result. ...@@ -749,15 +765,17 @@ Deletes an OS account. This API uses a promise to return the result.
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let accountName = 'testAccountName'; let accountName: string = 'testAccountName';
try { try {
accountManager.createOsAccount(accountName, account_osAccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{ accountManager.createOsAccount(accountName, account_osAccount.OsAccountType.NORMAL,
accountManager.removeOsAccount(osAccountInfo.localId).then(() => { (err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo)=>{
console.log('removeOsAccount successfully'); accountManager.removeOsAccount(osAccountInfo.localId).then(() => {
}).catch((err) => { console.log('removeOsAccount successfully');
console.log('removeOsAccount failed, error: ' + JSON.stringify(err)); }).catch((err: BusinessError) => {
}); console.log('removeOsAccount failed, error: ' + JSON.stringify(err));
});
}); });
} catch (err) { } catch (err) {
console.log('removeOsAccount exception: ' + JSON.stringify(err)); console.log('removeOsAccount exception: ' + JSON.stringify(err));
...@@ -797,11 +815,12 @@ Sets or removes constraints for an OS account. This API uses an asynchronous cal ...@@ -797,11 +815,12 @@ Sets or removes constraints for an OS account. This API uses an asynchronous cal
**Example**: Disable Wi-Fi for OS account 100. **Example**: Disable Wi-Fi for OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
let constraint = 'constraint.wifi'; let constraint: string = 'constraint.wifi';
try { try {
accountManager.setOsAccountConstraints(localId, [constraint], true, (err) => { accountManager.setOsAccountConstraints(localId, [constraint], true, (err: BusinessError) => {
if (err) { if (err) {
console.log('setOsAccountConstraints failed, error: ' + JSON.stringify(err)); console.log('setOsAccountConstraints failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -851,12 +870,13 @@ Sets or removes constraints for an OS account. This API uses a promise to return ...@@ -851,12 +870,13 @@ Sets or removes constraints for an OS account. This API uses a promise to return
**Example**: Remove the constraint on the use of Wi-Fi for OS account 100. **Example**: Remove the constraint on the use of Wi-Fi for OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
try { try {
accountManager.setOsAccountConstraints(localId, ['constraint.location.set'], false).then(() => { accountManager.setOsAccountConstraints(localId, ['constraint.location.set'], false).then(() => {
console.log('setOsAccountConstraints succsuccessfully'); console.log('setOsAccountConstraints succsuccessfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setOsAccountConstraints failed, error: ' + JSON.stringify(err)); console.log('setOsAccountConstraints failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -896,11 +916,12 @@ Sets a name for an OS account. This API uses an asynchronous callback to return ...@@ -896,11 +916,12 @@ Sets a name for an OS account. This API uses an asynchronous callback to return
**Example**: Set the name of OS account 100 to **demoName**. **Example**: Set the name of OS account 100 to **demoName**.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
let name = 'demoName'; let name: string = 'demoName';
try { try {
accountManager.setOsAccountName(localId, name, (err) => { accountManager.setOsAccountName(localId, name, (err: BusinessError) => {
if (err) { if (err) {
console.log('setOsAccountName failed, error: ' + JSON.stringify(err)); console.log('setOsAccountName failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -949,13 +970,14 @@ Sets a name for an OS account. This API uses a promise to return the result. ...@@ -949,13 +970,14 @@ Sets a name for an OS account. This API uses a promise to return the result.
**Example**: Set the name of OS account 100 to **demoName**. **Example**: Set the name of OS account 100 to **demoName**.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
let name = 'testName'; let name: string = 'testName';
try { try {
accountManager.setOsAccountName(localId, name).then(() => { accountManager.setOsAccountName(localId, name).then(() => {
console.log('setOsAccountName successfully'); console.log('setOsAccountName successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setOsAccountName failed, error: ' + JSON.stringify(err)); console.log('setOsAccountName failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -988,9 +1010,10 @@ Obtains the number of OS accounts created. This API uses an asynchronous callbac ...@@ -988,9 +1010,10 @@ Obtains the number of OS accounts created. This API uses an asynchronous callbac
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.getOsAccountCount((err, count) => { accountManager.getOsAccountCount((err: BusinessError, count: number) => {
if (err) { if (err) {
console.log('getOsAccountCount failed, error: ' + JSON.stringify(err)); console.log('getOsAccountCount failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -1027,11 +1050,12 @@ Obtains the number of OS accounts created. This API uses a promise to return the ...@@ -1027,11 +1050,12 @@ Obtains the number of OS accounts created. This API uses a promise to return the
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.getOsAccountCount().then((count) => { accountManager.getOsAccountCount().then((count: number) => {
console.log('getOsAccountCount successfully, count: ' + count); console.log('getOsAccountCount successfully, count: ' + count);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOsAccountCount failed, error: ' + JSON.stringify(err)); console.log('getOsAccountCount failed, error: ' + JSON.stringify(err));
}); });
} catch(err) { } catch(err) {
...@@ -1062,9 +1086,10 @@ Obtains the ID of the OS account to which the current process belongs. This API ...@@ -1062,9 +1086,10 @@ Obtains the ID of the OS account to which the current process belongs. This API
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.getOsAccountLocalId((err, localId) => { accountManager.getOsAccountLocalId((err: BusinessError, localId: number) => {
if (err) { if (err) {
console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err)); console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -1099,11 +1124,12 @@ Obtains the ID of the OS account to which the current process belongs. This API ...@@ -1099,11 +1124,12 @@ Obtains the ID of the OS account to which the current process belongs. This API
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.getOsAccountLocalId().then((localId) => { accountManager.getOsAccountLocalId().then((localId: number) => {
console.log('getOsAccountLocalId successfully, localId: ' + localId); console.log('getOsAccountLocalId successfully, localId: ' + localId);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err)); console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -1136,10 +1162,11 @@ Obtains the OS account ID based on the process UID. This API uses an asynchronou ...@@ -1136,10 +1162,11 @@ Obtains the OS account ID based on the process UID. This API uses an asynchronou
**Example**: Obtain the ID of the OS account whose process UID is **12345678**. **Example**: Obtain the ID of the OS account whose process UID is **12345678**.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let uid = 12345678; let uid: number = 12345678;
try { try {
accountManager.getOsAccountLocalIdForUid(uid, (err, localId) => { accountManager.getOsAccountLocalIdForUid(uid, (err: BusinessError, localId: number) => {
if (err) { if (err) {
console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err)); console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err));
} }
...@@ -1180,12 +1207,13 @@ Obtains the OS account ID based on the process UID. This API uses a promise to r ...@@ -1180,12 +1207,13 @@ Obtains the OS account ID based on the process UID. This API uses a promise to r
**Example**: Obtain the ID of the OS account whose process UID is **12345678**. **Example**: Obtain the ID of the OS account whose process UID is **12345678**.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let uid = 12345678; let uid: number = 12345678;
try { try {
accountManager.getOsAccountLocalIdForUid(uid).then((localId) => { accountManager.getOsAccountLocalIdForUid(uid).then((localId: number) => {
console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId); console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err)); console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -1220,10 +1248,11 @@ Obtains the OS account ID based on the domain account information. This API uses ...@@ -1220,10 +1248,11 @@ Obtains the OS account ID based on the domain account information. This API uses
**Example** **Example**
```js ```js
let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'}; import { BusinessError } from '@ohos.base';
let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.getOsAccountLocalIdForDomain(domainInfo, (err, localId) => { accountManager.getOsAccountLocalIdForDomain(domainInfo, (err: BusinessError, localId: number) => {
if (err) { if (err) {
console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err)); console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -1267,12 +1296,13 @@ Obtains the OS account ID based on the domain account information. This API uses ...@@ -1267,12 +1296,13 @@ Obtains the OS account ID based on the domain account information. This API uses
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'}; let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
try { try {
accountManager.getOsAccountLocalIdForDomain(domainInfo).then((localId) => { accountManager.getOsAccountLocalIdForDomain(domainInfo).then((localId: number) => {
console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId); console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err)); console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -1305,9 +1335,10 @@ Obtains the maximum number of OS accounts that can be created. This API uses an ...@@ -1305,9 +1335,10 @@ Obtains the maximum number of OS accounts that can be created. This API uses an
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.queryMaxOsAccountNumber((err, maxCnt) => { accountManager.queryMaxOsAccountNumber((err: BusinessError, maxCnt: number) => {
if (err) { if (err) {
console.log('queryMaxOsAccountNumber failed, error:' + JSON.stringify(err)); console.log('queryMaxOsAccountNumber failed, error:' + JSON.stringify(err));
} else { } else {
...@@ -1344,11 +1375,12 @@ Obtains the maximum number of OS accounts that can be created. This API uses a p ...@@ -1344,11 +1375,12 @@ Obtains the maximum number of OS accounts that can be created. This API uses a p
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.queryMaxOsAccountNumber().then((maxCnt) => { accountManager.queryMaxOsAccountNumber().then((maxCnt: number) => {
console.log('queryMaxOsAccountNumber successfully, maxCnt: ' + maxCnt); console.log('queryMaxOsAccountNumber successfully, maxCnt: ' + maxCnt);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('queryMaxOsAccountNumber failed, error: ' + JSON.stringify(err)); console.log('queryMaxOsAccountNumber failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -1384,10 +1416,11 @@ Obtains all constraints enabled for an OS account. This API uses an asynchronous ...@@ -1384,10 +1416,11 @@ Obtains all constraints enabled for an OS account. This API uses an asynchronous
**Example**: Obtain all constraints of OS account 100. **Example**: Obtain all constraints of OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
try { try {
accountManager.getOsAccountConstraints(localId, (err, constraints) => { accountManager.getOsAccountConstraints(localId, (err: BusinessError, constraints: string[]) => {
if (err) { if (err) {
console.log('getOsAccountConstraints failed, err: ' + JSON.stringify(err)); console.log('getOsAccountConstraints failed, err: ' + JSON.stringify(err));
} else { } else {
...@@ -1432,12 +1465,13 @@ Obtains all constraints enabled for an OS account. This API uses a promise to re ...@@ -1432,12 +1465,13 @@ Obtains all constraints enabled for an OS account. This API uses a promise to re
**Example**: Obtain all constraints of OS account 100. **Example**: Obtain all constraints of OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
try { try {
accountManager.getOsAccountConstraints(localId).then((constraints) => { accountManager.getOsAccountConstraints(localId).then((constraints: string[]) => {
console.log('getOsAccountConstraints, constraints: ' + constraints); console.log('getOsAccountConstraints, constraints: ' + constraints);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOsAccountConstraints err: ' + JSON.stringify(err)); console.log('getOsAccountConstraints err: ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -1472,9 +1506,10 @@ Obtains information about all the OS accounts created. This API uses an asynchro ...@@ -1472,9 +1506,10 @@ Obtains information about all the OS accounts created. This API uses an asynchro
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.queryAllCreatedOsAccounts((err, accountArr)=>{ accountManager.queryAllCreatedOsAccounts((err: BusinessError, accountArr: account_osAccount.OsAccountInfo[])=>{
console.log('queryAllCreatedOsAccounts err:' + JSON.stringify(err)); console.log('queryAllCreatedOsAccounts err:' + JSON.stringify(err));
console.log('queryAllCreatedOsAccounts accountArr:' + JSON.stringify(accountArr)); console.log('queryAllCreatedOsAccounts accountArr:' + JSON.stringify(accountArr));
}); });
...@@ -1510,11 +1545,12 @@ Obtains information about all the OS accounts created. This API uses a promise t ...@@ -1510,11 +1545,12 @@ Obtains information about all the OS accounts created. This API uses a promise t
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.queryAllCreatedOsAccounts().then((accountArr) => { accountManager.queryAllCreatedOsAccounts().then((accountArr: account_osAccount.OsAccountInfo[]) => {
console.log('queryAllCreatedOsAccounts, accountArr: ' + JSON.stringify(accountArr)); console.log('queryAllCreatedOsAccounts, accountArr: ' + JSON.stringify(accountArr));
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('queryAllCreatedOsAccounts err: ' + JSON.stringify(err)); console.log('queryAllCreatedOsAccounts err: ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -1545,9 +1581,10 @@ Obtains information about all activated OS accounts. This API uses an asynchrono ...@@ -1545,9 +1581,10 @@ Obtains information about all activated OS accounts. This API uses an asynchrono
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.getActivatedOsAccountLocalIds((err, idArray)=>{ accountManager.getActivatedOsAccountLocalIds((err: BusinessError, idArray: number[])=>{
console.log('getActivatedOsAccountLocalIds err:' + JSON.stringify(err)); console.log('getActivatedOsAccountLocalIds err:' + JSON.stringify(err));
console.log('getActivatedOsAccountLocalIds idArray length:' + idArray.length); console.log('getActivatedOsAccountLocalIds idArray length:' + idArray.length);
for(let i=0;i<idArray.length;i++) { for(let i=0;i<idArray.length;i++) {
...@@ -1582,11 +1619,12 @@ Obtains information about all activated OS accounts. This API uses a promise to ...@@ -1582,11 +1619,12 @@ Obtains information about all activated OS accounts. This API uses a promise to
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.getActivatedOsAccountLocalIds().then((idArray) => { accountManager.getActivatedOsAccountLocalIds().then((idArray: number[]) => {
console.log('getActivatedOsAccountLocalIds, idArray: ' + idArray); console.log('getActivatedOsAccountLocalIds, idArray: ' + idArray);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getActivatedOsAccountLocalIds err: ' + JSON.stringify(err)); console.log('getActivatedOsAccountLocalIds err: ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -1627,9 +1665,11 @@ Creates an OS account. This API uses an asynchronous callback to return the resu ...@@ -1627,9 +1665,11 @@ Creates an OS account. This API uses an asynchronous callback to return the resu
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.createOsAccount('testName', account_osAccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{ accountManager.createOsAccount('testName', account_osAccount.OsAccountType.NORMAL,
(err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo)=>{
console.log('createOsAccount err:' + JSON.stringify(err)); console.log('createOsAccount err:' + JSON.stringify(err));
console.log('createOsAccount osAccountInfo:' + JSON.stringify(osAccountInfo)); console.log('createOsAccount osAccountInfo:' + JSON.stringify(osAccountInfo));
}); });
...@@ -1676,11 +1716,13 @@ Creates an OS account. This API uses a promise to return the result. ...@@ -1676,11 +1716,13 @@ Creates an OS account. This API uses a promise to return the result.
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.createOsAccount('testAccountName', account_osAccount.OsAccountType.NORMAL).then((accountInfo) => { accountManager.createOsAccount('testAccountName', account_osAccount.OsAccountType.NORMAL).then(
(accountInfo: account_osAccount.OsAccountInfo) => {
console.log('createOsAccount, accountInfo: ' + JSON.stringify(accountInfo)); console.log('createOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('createOsAccount err: ' + JSON.stringify(err)); console.log('createOsAccount err: ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -1721,10 +1763,13 @@ Creates an OS account and associates it with the specified domain account. This ...@@ -1721,10 +1763,13 @@ Creates an OS account and associates it with the specified domain account. This
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'}; let domainInfo: account_osAccount.DomainAccountInfo =
{domain: 'testDomain', accountName: 'testAccountName'};
try { try {
accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo, (err, osAccountInfo)=>{ accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo,
(err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo)=>{
console.log('createOsAccountForDomain err:' + JSON.stringify(err)); console.log('createOsAccountForDomain err:' + JSON.stringify(err));
console.log('createOsAccountForDomain osAccountInfo:' + JSON.stringify(osAccountInfo)); console.log('createOsAccountForDomain osAccountInfo:' + JSON.stringify(osAccountInfo));
}); });
...@@ -1771,12 +1816,15 @@ Creates an OS account and associates it with the specified domain account. This ...@@ -1771,12 +1816,15 @@ Creates an OS account and associates it with the specified domain account. This
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'}; let domainInfo: account_osAccount.DomainAccountInfo =
{domain: 'testDomain', accountName: 'testAccountName'};
try { try {
accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo).then((accountInfo) => { accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo).then(
(accountInfo: account_osAccount.OsAccountInfo) => {
console.log('createOsAccountForDomain, account info: ' + JSON.stringify(accountInfo)); console.log('createOsAccountForDomain, account info: ' + JSON.stringify(accountInfo));
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('createOsAccountForDomain err: ' + JSON.stringify(err)); console.log('createOsAccountForDomain err: ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -1809,9 +1857,10 @@ Obtains information about the OS account to which the current process belongs. T ...@@ -1809,9 +1857,10 @@ Obtains information about the OS account to which the current process belongs. T
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.getCurrentOsAccount((err, curAccountInfo)=>{ accountManager.getCurrentOsAccount((err: BusinessError, curAccountInfo: account_osAccount.OsAccountInfo)=>{
console.log('getCurrentOsAccount err:' + JSON.stringify(err)); console.log('getCurrentOsAccount err:' + JSON.stringify(err));
console.log('getCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo)); console.log('getCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo));
}); });
...@@ -1845,11 +1894,12 @@ Obtains information about the OS account to which the current process belongs. T ...@@ -1845,11 +1894,12 @@ Obtains information about the OS account to which the current process belongs. T
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.getCurrentOsAccount().then((accountInfo) => { accountManager.getCurrentOsAccount().then((accountInfo: account_osAccount.OsAccountInfo) => {
console.log('getCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo)); console.log('getCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getCurrentOsAccount err: ' + JSON.stringify(err)); console.log('getCurrentOsAccount err: ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -1887,10 +1937,11 @@ Obtains information about the OS account of the given ID. This API uses an async ...@@ -1887,10 +1937,11 @@ Obtains information about the OS account of the given ID. This API uses an async
**Example**: Query information about OS account 100. **Example**: Query information about OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
try { try {
accountManager.queryOsAccountById(localId, (err, accountInfo)=>{ accountManager.queryOsAccountById(localId, (err: BusinessError, accountInfo: account_osAccount.OsAccountInfo)=>{
console.log('queryOsAccountById err:' + JSON.stringify(err)); console.log('queryOsAccountById err:' + JSON.stringify(err));
console.log('queryOsAccountById accountInfo:' + JSON.stringify(accountInfo)); console.log('queryOsAccountById accountInfo:' + JSON.stringify(accountInfo));
}); });
...@@ -1934,12 +1985,13 @@ Obtains information about the OS account of the given ID. This API uses a promis ...@@ -1934,12 +1985,13 @@ Obtains information about the OS account of the given ID. This API uses a promis
**Example**: Query information about OS account 100. **Example**: Query information about OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
try { try {
accountManager.queryOsAccountById(localId).then((accountInfo) => { accountManager.queryOsAccountById(localId).then((accountInfo: account_osAccount.OsAccountInfo) => {
console.log('queryOsAccountById, accountInfo: ' + JSON.stringify(accountInfo)); console.log('queryOsAccountById, accountInfo: ' + JSON.stringify(accountInfo));
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('queryOsAccountById err: ' + JSON.stringify(err)); console.log('queryOsAccountById err: ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -1970,9 +2022,10 @@ Obtains the type of the account to which the current process belongs. This API u ...@@ -1970,9 +2022,10 @@ Obtains the type of the account to which the current process belongs. This API u
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.getOsAccountType((err, accountType) => { accountManager.getOsAccountType((err: BusinessError, accountType: account_osAccount.OsAccountType) => {
console.log('getOsAccountType err: ' + JSON.stringify(err)); console.log('getOsAccountType err: ' + JSON.stringify(err));
console.log('getOsAccountType accountType: ' + accountType); console.log('getOsAccountType accountType: ' + accountType);
}); });
...@@ -2004,11 +2057,12 @@ Obtains the type of the account to which the current process belongs. This API u ...@@ -2004,11 +2057,12 @@ Obtains the type of the account to which the current process belongs. This API u
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.getOsAccountType().then((accountType) => { accountManager.getOsAccountType().then((accountType: account_osAccount.OsAccountType) => {
console.log('getOsAccountType, accountType: ' + accountType); console.log('getOsAccountType, accountType: ' + accountType);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOsAccountType err: ' + JSON.stringify(err)); console.log('getOsAccountType err: ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -2041,9 +2095,10 @@ Obtains the ID of this distributed virtual device. This API uses an asynchronous ...@@ -2041,9 +2095,10 @@ Obtains the ID of this distributed virtual device. This API uses an asynchronous
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.queryDistributedVirtualDeviceId((err, virtualID) => { accountManager.queryDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => {
console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err)); console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err));
console.log('queryDistributedVirtualDeviceId virtualID: ' + virtualID); console.log('queryDistributedVirtualDeviceId virtualID: ' + virtualID);
}); });
...@@ -2077,11 +2132,12 @@ Obtains the ID of this distributed virtual device. This API uses a promise to re ...@@ -2077,11 +2132,12 @@ Obtains the ID of this distributed virtual device. This API uses a promise to re
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.queryDistributedVirtualDeviceId().then((virtualID) => { accountManager.queryDistributedVirtualDeviceId().then((virtualID: string) => {
console.log('queryDistributedVirtualDeviceId, virtualID: ' + virtualID); console.log('queryDistributedVirtualDeviceId, virtualID: ' + virtualID);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err)); console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -2119,10 +2175,11 @@ Obtains the profile photo of an OS account. This API uses an asynchronous callba ...@@ -2119,10 +2175,11 @@ Obtains the profile photo of an OS account. This API uses an asynchronous callba
**Example**: Obtain the profile photo of OS account 100. **Example**: Obtain the profile photo of OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
try { try {
accountManager.getOsAccountProfilePhoto(localId, (err, photo)=>{ accountManager.getOsAccountProfilePhoto(localId, (err: BusinessError, photo: string)=>{
console.log('getOsAccountProfilePhoto err:' + JSON.stringify(err)); console.log('getOsAccountProfilePhoto err:' + JSON.stringify(err));
console.log('get photo:' + photo + ' by localId: ' + localId); console.log('get photo:' + photo + ' by localId: ' + localId);
}); });
...@@ -2166,12 +2223,13 @@ Obtains the profile photo of an OS account. This API uses a promise to return th ...@@ -2166,12 +2223,13 @@ Obtains the profile photo of an OS account. This API uses a promise to return th
**Example**: Obtain the profile photo of OS account 100. **Example**: Obtain the profile photo of OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
try { try {
accountManager.getOsAccountProfilePhoto(localId).then((photo) => { accountManager.getOsAccountProfilePhoto(localId).then((photo: string) => {
console.log('getOsAccountProfilePhoto: ' + photo); console.log('getOsAccountProfilePhoto: ' + photo);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOsAccountProfilePhoto err: ' + JSON.stringify(err)); console.log('getOsAccountProfilePhoto err: ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -2211,14 +2269,15 @@ Sets a profile photo for an OS account. This API uses an asynchronous callback t ...@@ -2211,14 +2269,15 @@ Sets a profile photo for an OS account. This API uses an asynchronous callback t
**Example**: Set a profile photo for OS account 100. **Example**: Set a profile photo for OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
let photo = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+ let photo: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+
'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+ 'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+
'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+ 'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+
'+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==' '+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg=='
try { try {
accountManager.setOsAccountProfilePhoto(localId, photo, (err)=>{ accountManager.setOsAccountProfilePhoto(localId, photo, (err: BusinessError)=>{
console.log('setOsAccountProfilePhoto err:' + JSON.stringify(err)); console.log('setOsAccountProfilePhoto err:' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -2263,16 +2322,17 @@ Sets a profile photo for an OS account. This API uses a promise to return the re ...@@ -2263,16 +2322,17 @@ Sets a profile photo for an OS account. This API uses a promise to return the re
**Example**: Set a profile photo for OS account 100. **Example**: Set a profile photo for OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
let photo = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+ let photo: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+
'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+ 'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+
'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+ 'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+
'+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==' '+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg=='
try { try {
accountManager.setOsAccountProfilePhoto(localId, photo).then(() => { accountManager.setOsAccountProfilePhoto(localId, photo).then(() => {
console.log('setOsAccountProfilePhoto success'); console.log('setOsAccountProfilePhoto success');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setOsAccountProfilePhoto err: ' + JSON.stringify(err)); console.log('setOsAccountProfilePhoto err: ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -2306,10 +2366,11 @@ Obtains the OS account ID based on the serial number (SN). This API uses an asyn ...@@ -2306,10 +2366,11 @@ Obtains the OS account ID based on the serial number (SN). This API uses an asyn
**Example**: Obtain the ID of the OS account whose SN is 12345. **Example**: Obtain the ID of the OS account whose SN is 12345.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let serialNumber = 12345; let serialNumber: number = 12345;
try { try {
accountManager.getOsAccountLocalIdForSerialNumber(serialNumber, (err, localId)=>{ accountManager.getOsAccountLocalIdForSerialNumber(serialNumber, (err: BusinessError, localId: number)=>{
console.log('ger localId err:' + JSON.stringify(err)); console.log('ger localId err:' + JSON.stringify(err));
console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber); console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber);
}); });
...@@ -2349,12 +2410,13 @@ Obtains the OS account ID based on the SN. This API uses a promise to return the ...@@ -2349,12 +2410,13 @@ Obtains the OS account ID based on the SN. This API uses a promise to return the
**Example**: Obtain the ID of the OS account whose SN is 12345. **Example**: Obtain the ID of the OS account whose SN is 12345.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let serialNumber = 12345; let serialNumber: number = 12345;
try { try {
accountManager.getOsAccountLocalIdForSerialNumber(serialNumber).then((localId) => { accountManager.getOsAccountLocalIdForSerialNumber(serialNumber).then((localId: number) => {
console.log('getOsAccountLocalIdForSerialNumber localId: ' + localId); console.log('getOsAccountLocalIdForSerialNumber localId: ' + localId);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOsAccountLocalIdForSerialNumber err: ' + JSON.stringify(err)); console.log('getOsAccountLocalIdForSerialNumber err: ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -2388,10 +2450,11 @@ Obtains the SN of an OS account based on the account ID. This API uses an asynch ...@@ -2388,10 +2450,11 @@ Obtains the SN of an OS account based on the account ID. This API uses an asynch
**Example**: Obtain the SN of the OS account 100. **Example**: Obtain the SN of the OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
try { try {
accountManager.getSerialNumberForOsAccountLocalId(localId, (err, serialNumber)=>{ accountManager.getSerialNumberForOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{
console.log('ger serialNumber err:' + JSON.stringify(err)); console.log('ger serialNumber err:' + JSON.stringify(err));
console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId); console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId);
}); });
...@@ -2431,12 +2494,13 @@ Obtains the SN of an OS account based on the account ID. This API uses a promise ...@@ -2431,12 +2494,13 @@ Obtains the SN of an OS account based on the account ID. This API uses a promise
**Example**: Obtain the SN of the OS account 100. **Example**: Obtain the SN of the OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
try { try {
accountManager.getSerialNumberForOsAccountLocalId(localId).then((serialNumber) => { accountManager.getSerialNumberForOsAccountLocalId(localId).then((serialNumber: number) => {
console.log('getSerialNumberForOsAccountLocalId serialNumber: ' + serialNumber); console.log('getSerialNumberForOsAccountLocalId serialNumber: ' + serialNumber);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getSerialNumberForOsAccountLocalId err: ' + JSON.stringify(err)); console.log('getSerialNumberForOsAccountLocalId err: ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -2475,7 +2539,7 @@ Subscribes to the OS account activation states, including the states of the acco ...@@ -2475,7 +2539,7 @@ Subscribes to the OS account activation states, including the states of the acco
```js ```js
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
function onCallback(receiveLocalId){ function onCallback(receiveLocalId: number){
console.log('receive localId:' + receiveLocalId); console.log('receive localId:' + receiveLocalId);
} }
try { try {
...@@ -2553,10 +2617,11 @@ Obtains the bundle ID based on the UID. This API uses an asynchronous callback t ...@@ -2553,10 +2617,11 @@ Obtains the bundle ID based on the UID. This API uses an asynchronous callback t
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let testUid = 1000000; let testUid: number = 1000000;
try { try {
accountManager.getBundleIdForUid(testUid, (err, bundleId) => { accountManager.getBundleIdForUid(testUid, (err: BusinessError, bundleId: number) => {
console.info('getBundleIdForUid errInfo:' + JSON.stringify(err)); console.info('getBundleIdForUid errInfo:' + JSON.stringify(err));
console.info('getBundleIdForUid bundleId:' + JSON.stringify(bundleId)); console.info('getBundleIdForUid bundleId:' + JSON.stringify(bundleId));
}); });
...@@ -2596,12 +2661,13 @@ Obtains the bundle ID based on the UID. This API uses a promise to return the re ...@@ -2596,12 +2661,13 @@ Obtains the bundle ID based on the UID. This API uses a promise to return the re
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let testUid = 1000000; let testUid: number = 1000000;
try { try {
accountManager.getBundleIdForUid(testUid).then((result) => { accountManager.getBundleIdForUid(testUid).then((result: number) => {
console.info('getBundleIdForUid bundleId:' + JSON.stringify(result)); console.info('getBundleIdForUid bundleId:' + JSON.stringify(result));
}).catch((err)=>{ }).catch((err: BusinessError) => {
console.info('getBundleIdForUid errInfo:' + JSON.stringify(err)); console.info('getBundleIdForUid errInfo:' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -2636,9 +2702,10 @@ Checks whether the current process belongs to the main OS account. This API uses ...@@ -2636,9 +2702,10 @@ Checks whether the current process belongs to the main OS account. This API uses
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.isMainOsAccount((err,result)=>{ accountManager.isMainOsAccount((err: BusinessError,result: boolean)=>{
console.info('isMainOsAccount errInfo:' + JSON.stringify(err)); console.info('isMainOsAccount errInfo:' + JSON.stringify(err));
console.info('isMainOsAccount result:' + JSON.stringify(result)); console.info('isMainOsAccount result:' + JSON.stringify(result));
}); });
...@@ -2673,11 +2740,12 @@ Checks whether the current process belongs to the main OS account. This API uses ...@@ -2673,11 +2740,12 @@ Checks whether the current process belongs to the main OS account. This API uses
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.isMainOsAccount().then((result) => { accountManager.isMainOsAccount().then((result: boolean) => {
console.info('isMainOsAccount result:' + JSON.stringify(result)); console.info('isMainOsAccount result:' + JSON.stringify(result));
}).catch((err)=>{ }).catch((err: BusinessError) => {
console.info('isMainOsAccount errInfo:' + JSON.stringify(err)); console.info('isMainOsAccount errInfo:' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -2715,9 +2783,11 @@ Obtains the constraint source information of an OS account. This API uses an asy ...@@ -2715,9 +2783,11 @@ Obtains the constraint source information of an OS account. This API uses an asy
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.getOsAccountConstraintSourceTypes(100, 'constraint.wifi',(err,sourceTypeInfos)=>{ accountManager.getOsAccountConstraintSourceTypes(100, 'constraint.wifi',
(err: BusinessError,sourceTypeInfos: account_osAccount.ConstraintSourceTypeInfo[])=>{
console.info('getOsAccountConstraintSourceTypes errInfo:' + JSON.stringify(err)); console.info('getOsAccountConstraintSourceTypes errInfo:' + JSON.stringify(err));
console.info('getOsAccountConstraintSourceTypes sourceTypeInfos:' + JSON.stringify(sourceTypeInfos)); console.info('getOsAccountConstraintSourceTypes sourceTypeInfos:' + JSON.stringify(sourceTypeInfos));
}); });
...@@ -2762,11 +2832,13 @@ Obtains the constraint source information of an OS account. This API uses a prom ...@@ -2762,11 +2832,13 @@ Obtains the constraint source information of an OS account. This API uses a prom
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
try { try {
accountManager.getOsAccountConstraintSourceTypes(100, 'constraint.wifi').then((result) => { accountManager.getOsAccountConstraintSourceTypes(100, 'constraint.wifi').then(
(result: account_osAccount.ConstraintSourceTypeInfo[]) => {
console.info('getOsAccountConstraintSourceTypes sourceTypeInfos:' + JSON.stringify(result)); console.info('getOsAccountConstraintSourceTypes sourceTypeInfos:' + JSON.stringify(result));
}).catch((err)=>{ }).catch((err: BusinessError) => {
console.info('getOsAccountConstraintSourceTypes errInfo:' + JSON.stringify(err)); console.info('getOsAccountConstraintSourceTypes errInfo:' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -2795,8 +2867,9 @@ Checks whether multiple OS accounts are supported. This API uses an asynchronous ...@@ -2795,8 +2867,9 @@ Checks whether multiple OS accounts are supported. This API uses an asynchronous
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.isMultiOsAccountEnable((err, isEnabled) => { accountManager.isMultiOsAccountEnable((err: BusinessError, isEnabled: boolean) => {
if (err) { if (err) {
console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err)); console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -2826,10 +2899,11 @@ Checks whether multiple OS accounts are supported. This API uses a promise to re ...@@ -2826,10 +2899,11 @@ Checks whether multiple OS accounts are supported. This API uses a promise to re
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.isMultiOsAccountEnable().then((isEnabled) => { accountManager.isMultiOsAccountEnable().then((isEnabled: boolean) => {
console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled); console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err)); console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err));
}); });
``` ```
...@@ -2859,9 +2933,10 @@ Checks whether an OS account is activated. This API uses an asynchronous callbac ...@@ -2859,9 +2933,10 @@ Checks whether an OS account is activated. This API uses an asynchronous callbac
**Example**: Check whether OS account 100 is activated. **Example**: Check whether OS account 100 is activated.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
accountManager.isOsAccountActived(localId, (err, isActived) => { accountManager.isOsAccountActived(localId, (err: BusinessError, isActived: boolean) => {
if (err) { if (err) {
console.log('isOsAccountActived failed, err:' + JSON.stringify(err)); console.log('isOsAccountActived failed, err:' + JSON.stringify(err));
} else { } else {
...@@ -2899,11 +2974,12 @@ Checks whether an OS account is activated. This API uses a promise to return the ...@@ -2899,11 +2974,12 @@ Checks whether an OS account is activated. This API uses a promise to return the
**Example**: Check whether OS account 100 is activated. **Example**: Check whether OS account 100 is activated.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
accountManager.isOsAccountActived(localId).then((isActived) => { accountManager.isOsAccountActived(localId).then((isActived: boolean) => {
console.log('isOsAccountActived successfully, isActived: ' + isActived); console.log('isOsAccountActived successfully, isActived: ' + isActived);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('isOsAccountActived failed, error: ' + JSON.stringify(err)); console.log('isOsAccountActived failed, error: ' + JSON.stringify(err));
}); });
``` ```
...@@ -2933,10 +3009,11 @@ Checks whether the specified constraint is enabled for an OS account. This API u ...@@ -2933,10 +3009,11 @@ Checks whether the specified constraint is enabled for an OS account. This API u
**Example**: Check whether OS account 100 is forbidden to use Wi-Fi. **Example**: Check whether OS account 100 is forbidden to use Wi-Fi.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
let constraint = 'constraint.wifi'; let constraint: string = 'constraint.wifi';
accountManager.isOsAccountConstraintEnable(localId, constraint, (err, isEnabled) => { accountManager.isOsAccountConstraintEnable(localId, constraint, (err: BusinessError, isEnabled: boolean) => {
if (err) { if (err) {
console.log('isOsAccountConstraintEnable failed, error: ' + JSON.stringify(err)); console.log('isOsAccountConstraintEnable failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -2975,12 +3052,13 @@ Checks whether the specified constraint is enabled for an OS account. This API u ...@@ -2975,12 +3052,13 @@ Checks whether the specified constraint is enabled for an OS account. This API u
**Example**: Check whether OS account 100 is forbidden to use Wi-Fi. **Example**: Check whether OS account 100 is forbidden to use Wi-Fi.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
let constraint = 'constraint.wifi'; let constraint: string = 'constraint.wifi';
accountManager.isOsAccountConstraintEnable(localId, constraint).then((isEnabled) => { accountManager.isOsAccountConstraintEnable(localId, constraint).then((isEnabled: boolean) => {
console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled); console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('isOsAccountConstraintEnable err: ' + JSON.stringify(err)); console.log('isOsAccountConstraintEnable err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3006,8 +3084,9 @@ Checks whether this OS account is a test account. This API uses an asynchronous ...@@ -3006,8 +3084,9 @@ Checks whether this OS account is a test account. This API uses an asynchronous
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.isTestOsAccount((err, isTestable) => { accountManager.isTestOsAccount((err: BusinessError, isTestable: boolean) => {
if (err) { if (err) {
console.log('isTestOsAccount failed, error: ' + JSON.stringify(err)); console.log('isTestOsAccount failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -3037,10 +3116,11 @@ Checks whether this OS account is a test account. This API uses a promise to ret ...@@ -3037,10 +3116,11 @@ Checks whether this OS account is a test account. This API uses a promise to ret
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.isTestOsAccount().then((isTestable) => { accountManager.isTestOsAccount().then((isTestable: boolean) => {
console.log('isTestOsAccount successfully, isTestable: ' + isTestable); console.log('isTestOsAccount successfully, isTestable: ' + isTestable);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('isTestOsAccount failed, error: ' + JSON.stringify(err)); console.log('isTestOsAccount failed, error: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3068,8 +3148,9 @@ Checks whether this OS account has been verified. This API uses an asynchronous ...@@ -3068,8 +3148,9 @@ Checks whether this OS account has been verified. This API uses an asynchronous
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.isOsAccountVerified((err, isVerified) => { accountManager.isOsAccountVerified((err: BusinessError, isVerified: boolean) => {
if (err) { if (err) {
console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err)); console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -3102,9 +3183,10 @@ Checks whether an OS account has been verified. This API uses an asynchronous ca ...@@ -3102,9 +3183,10 @@ Checks whether an OS account has been verified. This API uses an asynchronous ca
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
accountManager.isOsAccountVerified(localId, (err, isVerified) => { accountManager.isOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => {
if (err) { if (err) {
console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err)); console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -3142,10 +3224,11 @@ Checks whether an OS account has been verified. This API uses a promise to retur ...@@ -3142,10 +3224,11 @@ Checks whether an OS account has been verified. This API uses a promise to retur
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.isOsAccountVerified(localId).then((isVerified) => { accountManager.isOsAccountVerified(localId).then((isVerified: boolean) => {
console.log('isOsAccountVerified successfully, isVerified: ' + isVerified); console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err)); console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3173,8 +3256,9 @@ Obtains the number of OS accounts created. This API uses an asynchronous callbac ...@@ -3173,8 +3256,9 @@ Obtains the number of OS accounts created. This API uses an asynchronous callbac
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.getCreatedOsAccountsCount((err, count)=>{ accountManager.getCreatedOsAccountsCount((err: BusinessError, count: number)=>{
if (err) { if (err) {
console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err)); console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -3206,10 +3290,11 @@ Obtains the number of OS accounts created. This API uses a promise to return the ...@@ -3206,10 +3290,11 @@ Obtains the number of OS accounts created. This API uses a promise to return the
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.getCreatedOsAccountsCount().then((count) => { accountManager.getCreatedOsAccountsCount().then((count: number) => {
console.log('getCreatedOsAccountsCount successfully, count: ' + count); console.log('getCreatedOsAccountsCount successfully, count: ' + count);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err)); console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3235,8 +3320,9 @@ Obtains the ID of the OS account to which the current process belongs. This API ...@@ -3235,8 +3320,9 @@ Obtains the ID of the OS account to which the current process belongs. This API
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.getOsAccountLocalIdFromProcess((err, localId) => { accountManager.getOsAccountLocalIdFromProcess((err: BusinessError, localId: number) => {
if (err) { if (err) {
console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err)); console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -3266,10 +3352,11 @@ Obtains the ID of the OS account to which the current process belongs. This API ...@@ -3266,10 +3352,11 @@ Obtains the ID of the OS account to which the current process belongs. This API
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.getOsAccountLocalIdFromProcess().then((localId) => { accountManager.getOsAccountLocalIdFromProcess().then((localId: number) => {
console.log('getOsAccountLocalIdFromProcess successfully, localId: ' + localId); console.log('getOsAccountLocalIdFromProcess successfully, localId: ' + localId);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err)); console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3296,9 +3383,10 @@ Obtains the OS account ID based on the process UID. This API uses an asynchronou ...@@ -3296,9 +3383,10 @@ Obtains the OS account ID based on the process UID. This API uses an asynchronou
**Example**: Obtain the ID of the OS account whose process UID is **12345678**. **Example**: Obtain the ID of the OS account whose process UID is **12345678**.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let uid = 12345678; let uid: number = 12345678;
accountManager.getOsAccountLocalIdFromUid(uid, (err, localId) => { accountManager.getOsAccountLocalIdFromUid(uid, (err: BusinessError, localId: number) => {
if (err) { if (err) {
console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err)); console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -3334,11 +3422,12 @@ Obtains the OS account ID based on the process UID. This API uses a promise to r ...@@ -3334,11 +3422,12 @@ Obtains the OS account ID based on the process UID. This API uses a promise to r
**Example**: Obtain the ID of the OS account whose process UID is **12345678**. **Example**: Obtain the ID of the OS account whose process UID is **12345678**.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let uid = 12345678; let uid: number = 12345678;
accountManager.getOsAccountLocalIdFromUid(uid).then((localId) => { accountManager.getOsAccountLocalIdFromUid(uid).then((localId: number) => {
console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId); console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err)); console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3367,9 +3456,10 @@ Obtains the OS account ID based on the domain account information. This API uses ...@@ -3367,9 +3456,10 @@ Obtains the OS account ID based on the domain account information. This API uses
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'}; let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'};
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.getOsAccountLocalIdFromDomain(domainInfo, (err, localId) => { accountManager.getOsAccountLocalIdFromDomain(domainInfo, (err: BusinessError, localId: number) => {
if (err) { if (err) {
console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err)); console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -3407,11 +3497,12 @@ Obtains the OS account ID based on the domain account information. This API uses ...@@ -3407,11 +3497,12 @@ Obtains the OS account ID based on the domain account information. This API uses
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'}; let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'};
accountManager.getOsAccountLocalIdFromDomain(domainInfo).then((localId) => { accountManager.getOsAccountLocalIdFromDomain(domainInfo).then((localId: number) => {
console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId); console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err)); console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3440,9 +3531,10 @@ Obtains all constraints enabled for an OS account. This API uses an asynchronous ...@@ -3440,9 +3531,10 @@ Obtains all constraints enabled for an OS account. This API uses an asynchronous
**Example**: Obtain all constraints of OS account 100. **Example**: Obtain all constraints of OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
accountManager.getOsAccountAllConstraints(localId, (err, constraints)=>{ accountManager.getOsAccountAllConstraints(localId, (err: BusinessError, constraints: string[])=>{
console.log('getOsAccountAllConstraints err:' + JSON.stringify(err)); console.log('getOsAccountAllConstraints err:' + JSON.stringify(err));
console.log('getOsAccountAllConstraints:' + JSON.stringify(constraints)); console.log('getOsAccountAllConstraints:' + JSON.stringify(constraints));
}); });
...@@ -3477,11 +3569,12 @@ Obtains all constraints enabled for an OS account. This API uses a promise to re ...@@ -3477,11 +3569,12 @@ Obtains all constraints enabled for an OS account. This API uses a promise to re
**Example**: Obtain all constraints of OS account 100. **Example**: Obtain all constraints of OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
accountManager.getOsAccountAllConstraints(localId).then((constraints) => { accountManager.getOsAccountAllConstraints(localId).then((constraints: string[]) => {
console.log('getOsAccountAllConstraints, constraints: ' + constraints); console.log('getOsAccountAllConstraints, constraints: ' + constraints);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOsAccountAllConstraints err: ' + JSON.stringify(err)); console.log('getOsAccountAllConstraints err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3507,8 +3600,9 @@ Obtains information about all activated OS accounts. This API uses an asynchrono ...@@ -3507,8 +3600,9 @@ Obtains information about all activated OS accounts. This API uses an asynchrono
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.queryActivatedOsAccountIds((err, idArray)=>{ accountManager.queryActivatedOsAccountIds((err: BusinessError, idArray: number[])=>{
console.log('queryActivatedOsAccountIds err:' + JSON.stringify(err)); console.log('queryActivatedOsAccountIds err:' + JSON.stringify(err));
console.log('queryActivatedOsAccountIds idArray length:' + idArray.length); console.log('queryActivatedOsAccountIds idArray length:' + idArray.length);
for(let i=0;i<idArray.length;i++) { for(let i=0;i<idArray.length;i++) {
...@@ -3538,10 +3632,11 @@ Obtains information about all activated OS accounts. This API uses a promise to ...@@ -3538,10 +3632,11 @@ Obtains information about all activated OS accounts. This API uses a promise to
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.queryActivatedOsAccountIds().then((idArray) => { accountManager.queryActivatedOsAccountIds().then((idArray: number[]) => {
console.log('queryActivatedOsAccountIds, idArray: ' + idArray); console.log('queryActivatedOsAccountIds, idArray: ' + idArray);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('queryActivatedOsAccountIds err: ' + JSON.stringify(err)); console.log('queryActivatedOsAccountIds err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3569,8 +3664,9 @@ Obtains information about the OS account to which the current process belongs. T ...@@ -3569,8 +3664,9 @@ Obtains information about the OS account to which the current process belongs. T
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.queryCurrentOsAccount((err, curAccountInfo)=>{ accountManager.queryCurrentOsAccount((err: BusinessError, curAccountInfo: account_osAccount.OsAccountInfo)=>{
console.log('queryCurrentOsAccount err:' + JSON.stringify(err)); console.log('queryCurrentOsAccount err:' + JSON.stringify(err));
console.log('queryCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo)); console.log('queryCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo));
}); });
...@@ -3599,10 +3695,11 @@ Obtains information about the OS account to which the current process belongs. T ...@@ -3599,10 +3695,11 @@ Obtains information about the OS account to which the current process belongs. T
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.queryCurrentOsAccount().then((accountInfo) => { accountManager.queryCurrentOsAccount().then((accountInfo: account_osAccount.OsAccountInfo) => {
console.log('queryCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo)); console.log('queryCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('queryCurrentOsAccount err: ' + JSON.stringify(err)); console.log('queryCurrentOsAccount err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3628,8 +3725,9 @@ Obtains the type of the account to which the current process belongs. This API u ...@@ -3628,8 +3725,9 @@ Obtains the type of the account to which the current process belongs. This API u
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.getOsAccountTypeFromProcess((err, accountType) => { accountManager.getOsAccountTypeFromProcess((err: BusinessError, accountType: account_osAccount.OsAccountType) => {
console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err)); console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err));
console.log('getOsAccountTypeFromProcess accountType: ' + accountType); console.log('getOsAccountTypeFromProcess accountType: ' + accountType);
}); });
...@@ -3656,10 +3754,11 @@ Obtains the type of the account to which the current process belongs. This API u ...@@ -3656,10 +3754,11 @@ Obtains the type of the account to which the current process belongs. This API u
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.getOsAccountTypeFromProcess().then((accountType) => { accountManager.getOsAccountTypeFromProcess().then((accountType: account_osAccount.OsAccountType) => {
console.log('getOsAccountTypeFromProcess, accountType: ' + accountType); console.log('getOsAccountTypeFromProcess, accountType: ' + accountType);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err)); console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3687,8 +3786,9 @@ Obtains the ID of this distributed virtual device. This API uses an asynchronous ...@@ -3687,8 +3786,9 @@ Obtains the ID of this distributed virtual device. This API uses an asynchronous
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.getDistributedVirtualDeviceId((err, virtualID) => { accountManager.getDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => {
console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err)); console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err));
console.log('getDistributedVirtualDeviceId virtualID: ' + virtualID); console.log('getDistributedVirtualDeviceId virtualID: ' + virtualID);
}); });
...@@ -3717,10 +3817,11 @@ Obtains the ID of this distributed virtual device. This API uses a promise to re ...@@ -3717,10 +3817,11 @@ Obtains the ID of this distributed virtual device. This API uses a promise to re
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
accountManager.getDistributedVirtualDeviceId().then((virtualID) => { accountManager.getDistributedVirtualDeviceId().then((virtualID: string) => {
console.log('getDistributedVirtualDeviceId, virtualID: ' + virtualID); console.log('getDistributedVirtualDeviceId, virtualID: ' + virtualID);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err)); console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3747,9 +3848,10 @@ Obtains the OS account ID based on the SN. This API uses an asynchronous callbac ...@@ -3747,9 +3848,10 @@ Obtains the OS account ID based on the SN. This API uses an asynchronous callbac
**Example**: Obtain the ID of the OS account whose SN is 12345. **Example**: Obtain the ID of the OS account whose SN is 12345.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let serialNumber = 12345; let serialNumber: number = 12345;
accountManager.getOsAccountLocalIdBySerialNumber(serialNumber, (err, localId)=>{ accountManager.getOsAccountLocalIdBySerialNumber(serialNumber, (err: BusinessError, localId: number)=>{
console.log('ger localId err:' + JSON.stringify(err)); console.log('ger localId err:' + JSON.stringify(err));
console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber); console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber);
}); });
...@@ -3782,11 +3884,12 @@ Obtains the OS account ID based on the SN. This API uses a promise to return the ...@@ -3782,11 +3884,12 @@ Obtains the OS account ID based on the SN. This API uses a promise to return the
**Example**: Obtain the ID of the OS account whose SN is 12345. **Example**: Obtain the ID of the OS account whose SN is 12345.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let serialNumber = 12345; let serialNumber: number = 12345;
accountManager.getOsAccountLocalIdBySerialNumber(serialNumber).then((localId) => { accountManager.getOsAccountLocalIdBySerialNumber(serialNumber).then((localId: number) => {
console.log('getOsAccountLocalIdBySerialNumber localId: ' + localId); console.log('getOsAccountLocalIdBySerialNumber localId: ' + localId);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getOsAccountLocalIdBySerialNumber err: ' + JSON.stringify(err)); console.log('getOsAccountLocalIdBySerialNumber err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3813,9 +3916,10 @@ Obtains the SN of an OS account based on the account ID. This API uses an asynch ...@@ -3813,9 +3916,10 @@ Obtains the SN of an OS account based on the account ID. This API uses an asynch
**Example**: Obtain the SN of the OS account 100. **Example**: Obtain the SN of the OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
accountManager.getSerialNumberByOsAccountLocalId(localId, (err, serialNumber)=>{ accountManager.getSerialNumberByOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{
console.log('ger serialNumber err:' + JSON.stringify(err)); console.log('ger serialNumber err:' + JSON.stringify(err));
console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId); console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId);
}); });
...@@ -3848,11 +3952,12 @@ Obtains the SN of an OS account based on the account ID. This API uses a promise ...@@ -3848,11 +3952,12 @@ Obtains the SN of an OS account based on the account ID. This API uses a promise
**Example**: Obtain the SN of the OS account 100. **Example**: Obtain the SN of the OS account 100.
```js ```js
import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager(); let accountManager = account_osAccount.getAccountManager();
let localId = 100; let localId: number = 100;
accountManager.getSerialNumberByOsAccountLocalId(localId).then((serialNumber) => { accountManager.getSerialNumberByOsAccountLocalId(localId).then((serialNumber: number) => {
console.log('getSerialNumberByOsAccountLocalId serialNumber: ' + serialNumber); console.log('getSerialNumberByOsAccountLocalId serialNumber: ' + serialNumber);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getSerialNumberByOsAccountLocalId err: ' + JSON.stringify(err)); console.log('getSerialNumberByOsAccountLocalId err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -3897,7 +4002,7 @@ Obtains version information. ...@@ -3897,7 +4002,7 @@ Obtains version information.
**Example** **Example**
```js ```js
let userAuth = new account_osAccount.UserAuth(); let userAuth = new account_osAccount.UserAuth();
let version = userAuth.getVersion(); let version: number = userAuth.getVersion();
console.log('getVersion version = ' + version); console.log('getVersion version = ' + version);
``` ```
...@@ -3974,18 +4079,19 @@ Obtains the executor property based on the request. This API uses an asynchronou ...@@ -3974,18 +4079,19 @@ Obtains the executor property based on the request. This API uses an asynchronou
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let userAuth = new account_osAccount.UserAuth(); let userAuth = new account_osAccount.UserAuth();
let keys = [ let keys = [
account_osAccount.GetPropertyType.AUTH_SUB_TYPE, account_osAccount.GetPropertyType.AUTH_SUB_TYPE,
account_osAccount.GetPropertyType.REMAIN_TIMES, account_osAccount.GetPropertyType.REMAIN_TIMES,
account_osAccount.GetPropertyType.FREEZING_TIME account_osAccount.GetPropertyType.FREEZING_TIME
]; ];
let request = { let request: account_osAccount.GetPropertyRequest = {
authType: account_osAccount.AuthType.PIN, authType: account_osAccount.AuthType.PIN,
keys: keys keys: keys
}; };
try { try {
userAuth.getProperty(request, (err, result) => { userAuth.getProperty(request, (err: BusinessError, result: account_osAccount.ExecutorProperty) => {
console.log('getProperty err = ' + JSON.stringify(err)); console.log('getProperty err = ' + JSON.stringify(err));
console.log('getProperty result = ' + JSON.stringify(result)); console.log('getProperty result = ' + JSON.stringify(result));
}); });
...@@ -4027,20 +4133,21 @@ Obtains the executor property based on the request. This API uses a promise to r ...@@ -4027,20 +4133,21 @@ Obtains the executor property based on the request. This API uses a promise to r
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let userAuth = new account_osAccount.UserAuth(); let userAuth = new account_osAccount.UserAuth();
let keys = [ let keys = [
account_osAccount.GetPropertyType.AUTH_SUB_TYPE, account_osAccount.GetPropertyType.AUTH_SUB_TYPE,
account_osAccount.GetPropertyType.REMAIN_TIMES, account_osAccount.GetPropertyType.REMAIN_TIMES,
account_osAccount.GetPropertyType.FREEZING_TIME account_osAccount.GetPropertyType.FREEZING_TIME
]; ];
let request = { let request: account_osAccount.GetPropertyRequest = {
authType: account_osAccount.AuthType.PIN, authType: account_osAccount.AuthType.PIN,
keys: keys keys: keys
}; };
try { try {
userAuth.getProperty(request).then((result) => { userAuth.getProperty(request).then((result: account_osAccount.ExecutorProperty) => {
console.log('getProperty result = ' + JSON.stringify(result)); console.log('getProperty result = ' + JSON.stringify(result));
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getProperty error = ' + JSON.stringify(err)); console.log('getProperty error = ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -4076,14 +4183,15 @@ Sets the property for the initialization algorithm. This API uses an asynchronou ...@@ -4076,14 +4183,15 @@ Sets the property for the initialization algorithm. This API uses an asynchronou
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let userAuth = new account_osAccount.UserAuth(); let userAuth = new account_osAccount.UserAuth();
let request = { let request: account_osAccount.SetPropertyRequest = {
authType: account_osAccount.AuthType.PIN, authType: account_osAccount.AuthType.PIN,
key: account_osAccount.SetPropertyType.INIT_ALGORITHM, key: account_osAccount.SetPropertyType.INIT_ALGORITHM,
setInfo: new Uint8Array([0]) setInfo: new Uint8Array([0])
}; };
try { try {
userAuth.setProperty(request, (err) => { userAuth.setProperty(request, (err: BusinessError) => {
if (err) { if (err) {
console.log('setProperty failed, error = ' + JSON.stringify(err)); console.log('setProperty failed, error = ' + JSON.stringify(err));
} else { } else {
...@@ -4128,16 +4236,17 @@ Sets the property for the initialization algorithm. This API uses a promise to r ...@@ -4128,16 +4236,17 @@ Sets the property for the initialization algorithm. This API uses a promise to r
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let userAuth = new account_osAccount.UserAuth(); let userAuth = new account_osAccount.UserAuth();
let request = { let request2: account_osAccount.SetPropertyRequest = {
authType: account_osAccount.AuthType.PIN, authType: account_osAccount.AuthType.PIN,
key: account_osAccount.SetPropertyType.INIT_ALGORITHM, key: account_osAccount.SetPropertyType.INIT_ALGORITHM,
setInfo: new Uint8Array([0]) setInfo: new Uint8Array([0])
}; };
try { try {
userAuth.setProperty(request).then(() => { userAuth.setProperty(request2).then(() => {
console.log('setProperty successfully'); console.log('setProperty successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('setProperty failed, error = ' + JSON.stringify(err)); console.log('setProperty failed, error = ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -4195,7 +4304,7 @@ Performs authentication of the current user. This API uses an asynchronous callb ...@@ -4195,7 +4304,7 @@ Performs authentication of the current user. This API uses an asynchronous callb
let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1; let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
try { try {
userAuth.auth(challenge, authType, authTrustLevel, { userAuth.auth(challenge, authType, authTrustLevel, {
onResult: function(result,extraInfo){ onResult: (result,extraInfo) => {
console.log('auth result = ' + result); console.log('auth result = ' + result);
console.log('auth extraInfo = ' + JSON.stringify(extraInfo)); console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
} }
...@@ -4251,13 +4360,13 @@ Performs authentication of the specified user. This API uses an asynchronous cal ...@@ -4251,13 +4360,13 @@ Performs authentication of the specified user. This API uses an asynchronous cal
**Example** **Example**
```js ```js
let userAuth = new account_osAccount.UserAuth(); let userAuth = new account_osAccount.UserAuth();
let userID = 100; let userID: number = 100;
let challenge = new Uint8Array([0]); let challenge = new Uint8Array([0]);
let authType = account_osAccount.AuthType.PIN; let authType = account_osAccount.AuthType.PIN;
let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1; let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
try { try {
userAuth.authUser(userID, challenge, authType, authTrustLevel, { userAuth.authUser(userID, challenge, authType, authTrustLevel, {
onResult: function(result,extraInfo){ onResult: (result,extraInfo) => {
console.log('authUser result = ' + result); console.log('authUser result = ' + result);
console.log('authUser extraInfo = ' + JSON.stringify(extraInfo)); console.log('authUser extraInfo = ' + JSON.stringify(extraInfo));
} }
...@@ -4295,10 +4404,10 @@ Cancels an authentication. ...@@ -4295,10 +4404,10 @@ Cancels an authentication.
**Example** **Example**
```js ```js
let userAuth = new account_osAccount.UserAuth(); let userAuth = new account_osAccount.UserAuth();
let pinAuth = new account_osAccount.PINAuth(); let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
let challenge = new Uint8Array([0]); let challenge = new Uint8Array([0]);
let contextId = userAuth.auth(challenge, account_osAccount.AuthType.PIN, account_osAccount.AuthTrustLevel.ATL1, { let contextId = userAuth.auth(challenge, account_osAccount.AuthType.PIN, account_osAccount.AuthTrustLevel.ATL1, {
onResult: (result, extraInfo) => { onResult: (result: number, extraInfo: account_osAccount.AuthResult) => {
console.log('auth result = ' + result); console.log('auth result = ' + result);
console.log('auth extraInfo = ' + JSON.stringify(extraInfo)); console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
} }
...@@ -4328,7 +4437,7 @@ A constructor used to create an instance for PIN authentication. ...@@ -4328,7 +4437,7 @@ A constructor used to create an instance for PIN authentication.
**Example** **Example**
```js ```js
let pinAuth = new account_osAccount.PINAuth(); let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
``` ```
### registerInputer<sup>8+</sup> ### registerInputer<sup>8+</sup>
...@@ -4359,11 +4468,11 @@ Register a PIN inputer. ...@@ -4359,11 +4468,11 @@ Register a PIN inputer.
**Example** **Example**
```js ```js
let pinAuth = new account_osAccount.PINAuth(); let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
let password = new Uint8Array([0, 0, 0, 0, 0]); let password = new Uint8Array([0, 0, 0, 0, 0]);
try { try {
let result = pinAuth.registerInputer({ let result = pinAuth.registerInputer({
onGetData: (authSubType, callback) => { onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
callback.onSetData(authSubType, password); callback.onSetData(authSubType, password);
} }
}); });
...@@ -4387,7 +4496,7 @@ Unregisters this PIN inputer. ...@@ -4387,7 +4496,7 @@ Unregisters this PIN inputer.
**Example** **Example**
```js ```js
let pinAuth = new account_osAccount.PINAuth(); let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
pinAuth.unregisterInputer(); pinAuth.unregisterInputer();
``` ```
...@@ -4426,10 +4535,10 @@ Register a credential inputer. ...@@ -4426,10 +4535,10 @@ Register a credential inputer.
**Example** **Example**
```js ```js
let authType = account_osAccount.AuthType.DOMAIN; let authType = account_osAccount.AuthType.DOMAIN;
let password = new Uint8Array([0, 0, 0, 0, 0]); let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0]);
try { try {
account_osAccount.InputerManager.registerInputer(authType, { account_osAccount.InputerManager.registerInputer(authType, {
onGetData: (authSubType, callback) => { onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
callback.onSetData(authSubType, password); callback.onSetData(authSubType, password);
} }
}); });
...@@ -4500,24 +4609,33 @@ Authenticates a domain account. ...@@ -4500,24 +4609,33 @@ Authenticates a domain account.
**Example** **Example**
```js ```js
let plugin = { import { AsyncCallback } from './@ohos.base';
auth: (domainAccountInfo, credential, callback) => { let plugin: account_osAccount.DomainPlugin = {
auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
callback: account_osAccount.IUserAuthCallback) => {
// mock authentication // mock authentication
// notify authentication result // notify authentication result
callback.onResult(0, { let result: account_osAccount.AuthResult = {
token: new Uint8Array([0]), token: new Uint8Array([0]),
remainTimes: 5, remainTimes: 5,
freezingTime: 0 freezingTime: 0
}); };
callback.onResult(0, result);
}, },
authWithPopup: (domainAccountInfo, callback) => {}, authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
authWithToken: (domainAccountInfo, token, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
getAccountInfo: (domain, accountName, callback) => {}, authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
getAuthStatusInfo: (domainAccountInfo, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {}, getAccountInfo: (domain: string, accountName: string,
unbindAccount: (domainAccountInfo, callback) => {}, callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
isAccountTokenValid: (domainAccountInfo, token, callback) => {}, getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
getAccessToken: (options, callback) => {} callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
callback: AsyncCallback<void>) => {},
unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
callback: AsyncCallback<boolean>) => {},
getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
} }
account_osAccount.DomainAccountManager.registerPlugin(plugin); account_osAccount.DomainAccountManager.registerPlugin(plugin);
let userAuth = new account_osAccount.UserAuth(); let userAuth = new account_osAccount.UserAuth();
...@@ -4526,7 +4644,7 @@ Authenticates a domain account. ...@@ -4526,7 +4644,7 @@ Authenticates a domain account.
let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1; let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
try { try {
userAuth.auth(challenge, authType, authTrustLevel, { userAuth.auth(challenge, authType, authTrustLevel, {
onResult: (resultCode, authResult) => { onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => {
console.log('auth resultCode = ' + resultCode); console.log('auth resultCode = ' + resultCode);
console.log('auth authResult = ' + JSON.stringify(authResult)); console.log('auth authResult = ' + JSON.stringify(authResult));
} }
...@@ -4555,24 +4673,33 @@ Authenticates a domain account in a pop-up window. ...@@ -4555,24 +4673,33 @@ Authenticates a domain account in a pop-up window.
**Example** **Example**
```js ```js
let plugin = { import { AsyncCallback } from './@ohos.base';
auth: (domainAccountInfo, credential, callback) => {}, let plugin: account_osAccount.DomainPlugin = {
authWithPopup: (domainAccountInfo, callback) => { auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
callback: account_osAccount.IUserAuthCallback) => {},
authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
callback: account_osAccount.IUserAuthCallback) => {
// mock authentication // mock authentication
// notify authentication result // notify authentication result
callback.onResult(0, { let result: account_osAccount.AuthResult = {
token: new Uint8Array([0]), token: new Uint8Array([0]),
remainTimes: 5, remainTimes: 5,
freezingTime: 0 freezingTime: 0
}); };
callback.onResult(0, result);
}, },
authWithToken: (domainAccountInfo, token, callback) => {}, authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
getAccountInfo: (domain, accountName, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
getAuthStatusInfo: (domainAccountInfo, callback) => {}, getAccountInfo: (domain: string, accountName: string,
bindAccount: (domainAccountInfo, localId, callback) => {}, callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
unbindAccount: (domainAccountInfo, callback) => {}, getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
isAccountTokenValid: (domainAccountInfo, token, callback) => {}, callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
getAccessToken: (options, callback) => {} bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
callback: AsyncCallback<void>) => {},
unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
callback: AsyncCallback<boolean>) => {},
getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
} }
account_osAccount.DomainAccountManager.registerPlugin(plugin) account_osAccount.DomainAccountManager.registerPlugin(plugin)
``` ```
...@@ -4597,24 +4724,33 @@ Authenticates a domain account by the authorization token. ...@@ -4597,24 +4724,33 @@ Authenticates a domain account by the authorization token.
**Example** **Example**
```js ```js
let plugin = { import { AsyncCallback } from './@ohos.base';
auth: (domainAccountInfo, credential, callback) => {}, let plugin: account_osAccount.DomainPlugin = {
authWithPopup: (domainAccountInfo, callback) => {}, auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
authWithToken: (domainAccountInfo, token, callback) => { callback: account_osAccount.IUserAuthCallback) => {},
authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
callback: account_osAccount.IUserAuthCallback) => {},
authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
callback: account_osAccount.IUserAuthCallback) => {
// mock authentication // mock authentication
// notify authentication result // notify authentication result
callback.onResult(0, { let result: account_osAccount.AuthResult = {
token: new Uint8Array([0]), token: new Uint8Array([0]),
remainTimes: 5, remainTimes: 5,
freezingTime: 0 freezingTime: 0
}); };
callback.onResult(0, result);
}, },
getAccountInfo: (domain, accountName, callback) => {}, getAccountInfo: (domain: string, accountName: string,
getAuthStatusInfo: (domainAccountInfo, callback) => {}, callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
bindAccount: (domainAccountInfo, localId, callback) => {}, getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
unbindAccount: (domainAccountInfo, callback) => {}, callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
isAccountTokenValid: (domainAccountInfo, token, callback) => {}, bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
getAccessToken: (options, callback) => {} callback: AsyncCallback<void>) => {},
unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
callback: AsyncCallback<boolean>) => {},
getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
} }
account_osAccount.DomainAccountManager.registerPlugin(plugin) account_osAccount.DomainAccountManager.registerPlugin(plugin)
``` ```
...@@ -4639,26 +4775,38 @@ Obtains information about a domain account. ...@@ -4639,26 +4775,38 @@ Obtains information about a domain account.
**Example** **Example**
```js ```js
let plugin = { import { AsyncCallback, BusinessError } from '@ohos.base';
auth: (domainAccountInfo, credential, callback) => {}, let plugin: account_osAccount.DomainPlugin = {
authWithPopup: (domainAccountInfo, callback) => {}, auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
authWithToken: (domainAccountInfo, token, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
getAccountInfo: (domain, accountName, callback) => { authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
callback: account_osAccount.IUserAuthCallback) => {},
authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
callback: account_osAccount.IUserAuthCallback) => {},
getAccountInfo: (domain: string, accountName: string,
callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {
// mock getting account information // mock getting account information
// notify result // notify result
callback({ let code: BusinessError = {
code: 0 code: 0,
}, { name: "",
message: ""
};
let accountInfo: account_osAccount.DomainAccountInfo = {
domain: domain, domain: domain,
accountName: accountName, accountName: accountName,
accountId: 'xxxx' accountId: 'xxxx'
}) };
callback(code, accountInfo);
}, },
getAuthStatusInfo: (domainAccountInfo, callback) => {}, getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
bindAccount: (domainAccountInfo, localId, callback) => {}, callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
unbindAccount: (domainAccountInfo, callback) => {}, bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
isAccountTokenValid: (domainAccountInfo, token, callback) => {}, callback: AsyncCallback<void>) => {},
getAccessToken: (options, callback) => {} unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
callback: AsyncCallback<boolean>) => {},
getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
} }
account_osAccount.DomainAccountManager.registerPlugin(plugin) account_osAccount.DomainAccountManager.registerPlugin(plugin)
``` ```
...@@ -4682,23 +4830,35 @@ Obtains the authentication status of a domain account. ...@@ -4682,23 +4830,35 @@ Obtains the authentication status of a domain account.
**Example** **Example**
```js ```js
let plugin = { import { AsyncCallback, BusinessError } from '@ohos.base';
auth: (domainAccountInfo, credential, callback) => {}, let plugin: account_osAccount.DomainPlugin = {
authWithPopup: (domainAccountInfo, callback) => {}, auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
authWithToken: (domainAccountInfo, token, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
getAccountInfo: (domain, accountName, callback) => {}, authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
getAuthStatusInfo: (domainAccountInfo, callback) => { callback: account_osAccount.IUserAuthCallback) => {},
callback({ authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
code: 0 callback: account_osAccount.IUserAuthCallback) => {},
}, { getAccountInfo: (domain: string, accountName: string,
callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {
let code: BusinessError = {
code: 0,
name: "",
message: ""
};
let statusInfo: account_osAccount.AuthStatusInfo = {
remainTimes: 5, remainTimes: 5,
freezingTime: 0 freezingTime: 0
}) };
callback(code, statusInfo);
}, },
bindAccount: (domainAccountInfo, localId, callback) => {}, bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
unbindAccount: (domainAccountInfo, callback) => {}, callback: AsyncCallback<void>) => {},
isAccountTokenValid: (domainAccountInfo, token, callback) => {}, unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
getAccessToken: (options, callback) => {} isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
callback: AsyncCallback<boolean>) => {},
getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
} }
account_osAccount.DomainAccountManager.registerPlugin(plugin) account_osAccount.DomainAccountManager.registerPlugin(plugin)
``` ```
...@@ -4722,20 +4882,33 @@ Binds a domain account. ...@@ -4722,20 +4882,33 @@ Binds a domain account.
**Example** **Example**
```js ```js
let plugin = { import { AsyncCallback, BusinessError } from './@ohos.base';
auth: (domainAccountInfo, credential, callback) => {}, let plugin: account_osAccount.DomainPlugin = {
authWithPopup: (domainAccountInfo, callback) => {}, auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
authWithToken: (domainAccountInfo, token, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
getAccountInfo: (domain, accountName, callback) => {}, authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
getAuthStatusInfo: (domainAccountInfo, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
bindAccount: (domainAccountInfo, localId, callback) => { authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
callback: account_osAccount.IUserAuthCallback) => {},
getAccountInfo: (domain: string, accountName: string,
callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
callback: AsyncCallback<void>) => {
// mock unbinding operation // mock unbinding operation
// notify binding result // notify binding result
callback({code: 0}) let code: BusinessError = {
code: 0,
name: "",
message: ""
};
callback(code);
}, },
unbindAccount: (domainAccountInfo, callback) => {}, unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
isAccountTokenValid: (domainAccountInfo, token, callback) => {}, isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
getAccessToken: (options, callback) => {} callback: AsyncCallback<boolean>) => {},
getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
} }
account_osAccount.DomainAccountManager.registerPlugin(plugin) account_osAccount.DomainAccountManager.registerPlugin(plugin)
``` ```
...@@ -4759,20 +4932,33 @@ Unbinds a domain account. ...@@ -4759,20 +4932,33 @@ Unbinds a domain account.
**Example** **Example**
```js ```js
let plugin = { import { AsyncCallback, BusinessError } from './@ohos.base';
auth: (domainAccountInfo, credential, callback) => {}, let plugin: account_osAccount.DomainPlugin = {
authWithPopup: (domainAccountInfo, callback) => {}, auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
authWithToken: (domainAccountInfo, token, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
getAccountInfo: (domain, accountName, callback) => {}, authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
getAuthStatusInfo: (domainAccountInfo, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {}, authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
unbindAccount: (domainAccountInfo, callback) => { callback: account_osAccount.IUserAuthCallback) => {},
getAccountInfo: (domain: string, accountName: string,
callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
callback: AsyncCallback<void>) => {},
unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {
// mock unbinding operation // mock unbinding operation
// notify unbinding result // notify unbinding result
callback({code: 0}) let code: BusinessError = {
code: 0,
name: "",
message: ""
};
callback(code);
}, },
isAccountTokenValid: (domainAccountInfo, token, callback) => {}, isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
getAccessToken: (options, callback) => {} callback: AsyncCallback<boolean>) => {},
getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
} }
account_osAccount.DomainAccountManager.registerPlugin(plugin) account_osAccount.DomainAccountManager.registerPlugin(plugin)
``` ```
...@@ -4797,20 +4983,33 @@ Checks whether a domain account token is valid. ...@@ -4797,20 +4983,33 @@ Checks whether a domain account token is valid.
**Example** **Example**
```js ```js
let plugin = { import { AsyncCallback, BusinessError } from './@ohos.base';
auth: (domainAccountInfo, credential, callback) => {}, let plugin: account_osAccount.DomainPlugin = {
authWithPopup: (domainAccountInfo, callback) => {}, auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
authWithToken: (domainAccountInfo, token, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
getAccountInfo: (domain, accountName, callback) => {}, authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
getAuthStatusInfo: (domainAccountInfo, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {}, authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
unbindAccount: (domainAccountInfo, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
isAccountTokenValid: (domainAccountInfo, token, callback) => { getAccountInfo: (domain: string, accountName: string,
callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
callback: AsyncCallback<void>) => {},
unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
callback: AsyncCallback<boolean>) => {
// mock checking operation // mock checking operation
// notify checking result // notify checking result
callback({code: 0}, true); let code: BusinessError = {
code: 0,
name: "",
message: ""
};
callback(code, true);
}, },
getAccessToken: (options, callback) => {} getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
} }
account_osAccount.DomainAccountManager.registerPlugin(plugin) account_osAccount.DomainAccountManager.registerPlugin(plugin)
``` ```
...@@ -4834,20 +5033,33 @@ Obtains the domain access token based on the specified conditions. ...@@ -4834,20 +5033,33 @@ Obtains the domain access token based on the specified conditions.
**Example** **Example**
```js ```js
let plugin = { import { AsyncCallback, BusinessError } from './@ohos.base';
auth: (domainAccountInfo, credential, callback) => {}, let plugin: account_osAccount.DomainPlugin = {
authWithPopup: (domainAccountInfo, callback) => {}, auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
authWithToken: (domainAccountInfo, token, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
getAccountInfo: (domain, accountName, callback) => {}, authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
getAuthStatusInfo: (domainAccountInfo, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {}, authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
unbindAccount: (domainAccountInfo, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
isAccountTokenValid: (domainAccountInfo, token, callback) => {}, getAccountInfo: (domain: string, accountName: string,
getAccessToken: (options, callback) => { callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
callback: AsyncCallback<void>) => {},
unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
callback: AsyncCallback<boolean>) => {},
getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {
// mock getting operation // mock getting operation
let token = new Uint8Array([0]);
// notify result // notify result
callback({code: 0}, token); let code: BusinessError = {
code: 0,
name: "",
message: ""
};
let token: Uint8Array = new Uint8Array([0]);
callback(code, token);
} }
} }
account_osAccount.DomainAccountManager.registerPlugin(plugin) account_osAccount.DomainAccountManager.registerPlugin(plugin)
...@@ -4882,16 +5094,24 @@ Registers a domain plug-in. ...@@ -4882,16 +5094,24 @@ Registers a domain plug-in.
**Example** **Example**
```js ```js
let plugin = { import { AsyncCallback } from './@ohos.base';
auth: (domainAccountInfo, credential, callback) => {}, let plugin: account_osAccount.DomainPlugin = {
authWithPopup: (domainAccountInfo, callback) => {}, auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
authWithToken: (domainAccountInfo, token, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
getAccountInfo: (domain, accountName, callback) => {}, authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
getAuthStatusInfo: (domainAccountInfo, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {}, authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
unbindAccount: (domainAccountInfo, callback) => {}, callback: account_osAccount.IUserAuthCallback) => {},
isAccountTokenValid: (domainAccountInfo, token, callback) => {}, getAccountInfo: (domain: string, accountName: string,
getAccessToken: (options, callback) => {} callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
callback: AsyncCallback<void>) => {},
unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
callback: AsyncCallback<boolean>) => {},
getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
} }
try { try {
account_osAccount.DomainAccountManager.registerPlugin(plugin); account_osAccount.DomainAccountManager.registerPlugin(plugin);
...@@ -4961,14 +5181,14 @@ Authenticates a domain account. ...@@ -4961,14 +5181,14 @@ Authenticates a domain account.
**Example** **Example**
```js ```js
let domainAccountInfo = { let domainAccountInfo: account_osAccount.DomainAccountInfo = {
domain: 'CHINA', domain: 'CHINA',
accountName: 'zhangsan' accountName: 'zhangsan'
} }
let credential = new Uint8Array([0]) let credential = new Uint8Array([0])
try { try {
account_osAccount.DomainAccountManager.auth(domainAccountInfo, credential, { account_osAccount.DomainAccountManager.auth(domainAccountInfo, credential, {
onResult: (resultCode, authResult) => { onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => {
console.log('auth resultCode = ' + resultCode); console.log('auth resultCode = ' + resultCode);
console.log('auth authResult = ' + JSON.stringify(authResult)); console.log('auth authResult = ' + JSON.stringify(authResult));
} }
...@@ -5015,7 +5235,7 @@ Authenticates this domain account in a pop-up window. ...@@ -5015,7 +5235,7 @@ Authenticates this domain account in a pop-up window.
```js ```js
try { try {
account_osAccount.DomainAccountManager.authWithPopup({ account_osAccount.DomainAccountManager.authWithPopup({
onResult: (resultCode, authResult) => { onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => {
console.log('auth resultCode = ' + resultCode); console.log('auth resultCode = ' + resultCode);
console.log('auth authResult = ' + JSON.stringify(authResult)); console.log('auth authResult = ' + JSON.stringify(authResult));
} }
...@@ -5064,7 +5284,7 @@ Authenticates a domain account in a pop-up window. ...@@ -5064,7 +5284,7 @@ Authenticates a domain account in a pop-up window.
```js ```js
try { try {
account_osAccount.DomainAccountManager.authWithPopup(100, { account_osAccount.DomainAccountManager.authWithPopup(100, {
onResult: (resultCode, authResult) => { onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => {
console.log('authWithPopup resultCode = ' + resultCode); console.log('authWithPopup resultCode = ' + resultCode);
console.log('authWithPopup authResult = ' + JSON.stringify(authResult)); console.log('authWithPopup authResult = ' + JSON.stringify(authResult));
} }
...@@ -5100,15 +5320,17 @@ Checks whether a domain account exists. ...@@ -5100,15 +5320,17 @@ Checks whether a domain account exists.
| 12300001 | System service exception. | | 12300001 | System service exception. |
| 12300002 | Invalid domainAccountInfo. | | 12300002 | Invalid domainAccountInfo. |
| 12300013 | Network exception. | | 12300013 | Network exception. |
| 12300111 | Operation timeout. |
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let domainAccountInfo = { let domainAccountInfo = {
domain: 'CHINA', domain: 'CHINA',
accountName: 'zhangsan' accountName: 'zhangsan'
} }
try { try {
account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo, (err, result) => { account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo, (err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.log('call hasAccount failed, error: ' + JSON.stringify(err)); console.log('call hasAccount failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -5151,17 +5373,19 @@ Checks whether a domain account exists. ...@@ -5151,17 +5373,19 @@ Checks whether a domain account exists.
| 12300001 | System service exception. | | 12300001 | System service exception. |
| 12300002 | Invalid domainAccountInfo. | | 12300002 | Invalid domainAccountInfo. |
| 12300013 | Network exception. | | 12300013 | Network exception. |
| 12300111 | Operation timeout. |
**Example** **Example**
```js ```js
let domainAccountInfo = { import { BusinessError } from '@ohos.base';
let domainAccountInfo: account_osAccount.DomainAccountInfo = {
domain: 'CHINA', domain: 'CHINA',
accountName: 'zhangsan' accountName: 'zhangsan'
} }
try { try {
account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo).then((result) => { account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo).then((result: boolean) => {
console.log('hasAccount result: ' + result); console.log('hasAccount result: ' + result);
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('call hasAccount failed, error: ' + JSON.stringify(err)); console.log('call hasAccount failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -5199,14 +5423,15 @@ Updates the token of a domain account. An empty token means an invalid token. Th ...@@ -5199,14 +5423,15 @@ Updates the token of a domain account. An empty token means an invalid token. Th
**Example** **Example**
```js ```js
let domainAccountInfo = { import { BusinessError } from '@ohos.base';
let domainAccountInfo: account_osAccount.DomainAccountInfo = {
domain: 'CHINA', domain: 'CHINA',
accountName: 'zhangsan', accountName: 'zhangsan',
accountId: '123456' accountId: '123456'
} }
let token = new Uint8Array([0]) let token = new Uint8Array([0])
try { try {
account_osAccount.DomainAccountManager.updateAccountToken(domainAccountInfo, token, (err) => { account_osAccount.DomainAccountManager.updateAccountToken(domainAccountInfo, token, (err: BusinessError) => {
if (err != null) { if (err != null) {
console.log('updateAccountToken failed, error: ' + JSON.stringify(err)); console.log('updateAccountToken failed, error: ' + JSON.stringify(err));
} else { } else {
...@@ -5253,7 +5478,8 @@ Updates the token of a domain account. An empty token means an invalid token. Th ...@@ -5253,7 +5478,8 @@ Updates the token of a domain account. An empty token means an invalid token. Th
**Example** **Example**
```js ```js
let domainAccountInfo = { import { BusinessError } from '@ohos.base';
let domainAccountInfo: account_osAccount.DomainAccountInfo = {
domain: 'CHINA', domain: 'CHINA',
accountName: 'zhangsan', accountName: 'zhangsan',
accountId: '123456' accountId: '123456'
...@@ -5262,7 +5488,7 @@ Updates the token of a domain account. An empty token means an invalid token. Th ...@@ -5262,7 +5488,7 @@ Updates the token of a domain account. An empty token means an invalid token. Th
try { try {
account_osAccount.DomainAccountManager.updateAccountToken(domainAccountInfo, token).then(() => { account_osAccount.DomainAccountManager.updateAccountToken(domainAccountInfo, token).then(() => {
console.log('updateAccountToken successfully'); console.log('updateAccountToken successfully');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('updateAccountToken failed, error: ' + JSON.stringify(err)); console.log('updateAccountToken failed, error: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (err) {
...@@ -5317,9 +5543,10 @@ Opens a session to obtain the challenge value. This API uses an asynchronous cal ...@@ -5317,9 +5543,10 @@ Opens a session to obtain the challenge value. This API uses an asynchronous cal
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let userIDM = new account_osAccount.UserIdentityManager(); let userIDM = new account_osAccount.UserIdentityManager();
try { try {
userIDM.openSession((err, challenge) => { userIDM.openSession((err: BusinessError, challenge: Uint8Array) => {
console.log('openSession error = ' + JSON.stringify(err)); console.log('openSession error = ' + JSON.stringify(err));
console.log('openSession challenge = ' + JSON.stringify(challenge)); console.log('openSession challenge = ' + JSON.stringify(challenge));
}); });
...@@ -5354,11 +5581,12 @@ Opens a session to obtain the challenge value. This API uses a promise to return ...@@ -5354,11 +5581,12 @@ Opens a session to obtain the challenge value. This API uses a promise to return
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let userIDM = new account_osAccount.UserIdentityManager(); let userIDM = new account_osAccount.UserIdentityManager();
try { try {
userIDM.openSession().then((challenge) => { userIDM.openSession().then((challengechallenge: Uint8Array) => {
console.info('openSession challenge = ' + JSON.stringify(challenge)); console.info('openSession challenge = ' + JSON.stringify(challenge));
}).catch((err) => { }).catch((err: BusinessError) => {
console.info('openSession error = ' + JSON.stringify(err)); console.info('openSession error = ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -5399,23 +5627,24 @@ Adds credential information, including the credential type, subtype, and token ( ...@@ -5399,23 +5627,24 @@ Adds credential information, including the credential type, subtype, and token (
**Example** **Example**
```js ```js
let password = new Uint8Array([0, 0, 0, 0, 0, 0]); import { BusinessError } from '@ohos.base';
let pinAuth = new account_osAccount.PINAuth(); let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]);
let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
pinAuth.registerInputer({ pinAuth.registerInputer({
onGetData: (authSubType, callback) => { onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
callback.onSetData(authSubType, password); callback.onSetData(authSubType, password);
} }
}); });
let credentialInfo = { let credentialInfo: account_osAccount.CredentialInfo = {
credType: account_osAccount.AuthType.PIN, credType: account_osAccount.AuthType.PIN,
credSubType: account_osAccount.AuthSubType.PIN_SIX, credSubType: account_osAccount.AuthSubType.PIN_SIX,
token: null token: null
}; };
let userIDM = new account_osAccount.UserIdentityManager(); let userIDM = new account_osAccount.UserIdentityManager();
userIDM.openSession((err, challenge) => { userIDM.openSession((err: BusinessError, challenge: Uint8Array) => {
try { try {
userIDM.addCredential(credentialInfo, { userIDM.addCredential(credentialInfo, {
onResult: (result, extraInfo) => { onResult: (result: number, extraInfo: account_osAccount.RequestResult) => {
console.log('addCredential result = ' + result); console.log('addCredential result = ' + result);
console.log('addCredential extraInfo = ' + extraInfo); console.log('addCredential extraInfo = ' + extraInfo);
} }
...@@ -5459,30 +5688,33 @@ Updates credential information. This API uses a callback to return the result. ...@@ -5459,30 +5688,33 @@ Updates credential information. This API uses a callback to return the result.
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let userIDM = new account_osAccount.UserIdentityManager(); let userIDM = new account_osAccount.UserIdentityManager();
let userAuth = new account_osAccount.UserAuth(); let userAuth: account_osAccount.UserAuth = new account_osAccount.UserAuth();
let pinAuth = new account_osAccount.PINAuth(); let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
let password = new Uint8Array([0, 0, 0, 0, 0, 0]); let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]);
let credentialInfo = { let credentialInfo: account_osAccount.CredentialInfo = {
credType: account_osAccount.AuthType.PIN, credType: account_osAccount.AuthType.PIN,
credSubType: account_osAccount.AuthSubType.PIN_SIX, credSubType: account_osAccount.AuthSubType.PIN_SIX,
token: null token: new Uint8Array([]),
}; };
pinAuth.registerInputer({ pinAuth.registerInputer({
onGetData: (authSubType, callback) => { onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
callback.onSetData(authSubType, password); callback.onSetData(authSubType, password);
} }
}); });
userIDM.openSession((err, challenge) => { userIDM.openSession((err: BusinessError, challenge: Uint8Array) => {
userAuth.auth(challenge, credentialInfo.credType, account_osAccount.AuthTrustLevel.ATL1, { userAuth.auth(challenge, credentialInfo.credType, account_osAccount.AuthTrustLevel.ATL1, {
onResult: (result, extraInfo) => { onResult: (result: number, extraInfo: account_osAccount.AuthResult) => {
if (result != account_osAccount.ResultCode.SUCCESS) { if (result != account_osAccount.ResultCode.SUCCESS) {
return; return;
} }
credentialInfo.token = extraInfo.token; if (extraInfo.token != null) {
credentialInfo.token = extraInfo.token;
}
try { try {
userIDM.updateCredential(credentialInfo, { userIDM.updateCredential(credentialInfo, {
onResult: (result, extraInfo) => { onResult: (result: number, extraInfo: account_osAccount.RequestResult) => {
console.log('updateCredential result = ' + result); console.log('updateCredential result = ' + result);
console.log('updateCredential extraInfo = ' + extraInfo); console.log('updateCredential extraInfo = ' + extraInfo);
} }
...@@ -5541,7 +5773,7 @@ Cancels an entry based on the challenge value. ...@@ -5541,7 +5773,7 @@ Cancels an entry based on the challenge value.
**Example** **Example**
```js ```js
let userIDM = new account_osAccount.UserIdentityManager(); let userIDM = new account_osAccount.UserIdentityManager();
let challenge = new Uint8Array([0]); let challenge: Uint8Array = new Uint8Array([0]);
try { try {
userIDM.cancel(challenge); userIDM.cancel(challenge);
} catch(err) { } catch(err) {
...@@ -5578,10 +5810,10 @@ Deletes a user based on the authentication token. This API uses a callback to re ...@@ -5578,10 +5810,10 @@ Deletes a user based on the authentication token. This API uses a callback to re
**Example** **Example**
```js ```js
let userIDM = new account_osAccount.UserIdentityManager(); let userIDM = new account_osAccount.UserIdentityManager();
let token = new Uint8Array([0]); let token: Uint8Array = new Uint8Array([0]);
try { try {
userIDM.delUser(token, { userIDM.delUser(token, {
onResult: (result, extraInfo) => { onResult: (result: number, extraInfo: account_osAccount.RequestResult) => {
console.log('delUser result = ' + result); console.log('delUser result = ' + result);
console.log('delUser extraInfo = ' + JSON.stringify(extraInfo)); console.log('delUser extraInfo = ' + JSON.stringify(extraInfo));
} }
...@@ -5623,11 +5855,11 @@ Deletes user credential information. ...@@ -5623,11 +5855,11 @@ Deletes user credential information.
**Example** **Example**
```js ```js
let userIDM = new account_osAccount.UserIdentityManager(); let userIDM = new account_osAccount.UserIdentityManager();
let credentialId = new Uint8Array([0]); let credentialId: Uint8Array = new Uint8Array([0]);
let token = new Uint8Array([0]); let token: Uint8Array = new Uint8Array([0]);
try { try {
userIDM.delCred(credentialId, token, { userIDM.delCred(credentialId, token, {
onResult: (result, extraInfo) => { onResult: (result: number, extraInfo: account_osAccount.RequestResult) => {
console.log('delCred result = ' + result); console.log('delCred result = ' + result);
console.log('delCred extraInfo = ' + JSON.stringify(extraInfo)); console.log('delCred extraInfo = ' + JSON.stringify(extraInfo));
} }
...@@ -5664,9 +5896,10 @@ Obtains authentication information. This API uses an asynchronous callback to re ...@@ -5664,9 +5896,10 @@ Obtains authentication information. This API uses an asynchronous callback to re
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let userIDM = new account_osAccount.UserIdentityManager(); let userIDM = new account_osAccount.UserIdentityManager();
try { try {
userIDM.getAuthInfo((err, result) => { userIDM.getAuthInfo((err: BusinessError, result: account_osAccount.EnrolledCredInfo[]) => {
console.log('getAuthInfo err = ' + JSON.stringify(err)); console.log('getAuthInfo err = ' + JSON.stringify(err));
console.log('getAuthInfo result = ' + JSON.stringify(result)); console.log('getAuthInfo result = ' + JSON.stringify(result));
}); });
...@@ -5704,9 +5937,11 @@ Obtains authentication information of the specified type. This API uses an async ...@@ -5704,9 +5937,11 @@ Obtains authentication information of the specified type. This API uses an async
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let userIDM = new account_osAccount.UserIdentityManager(); let userIDM = new account_osAccount.UserIdentityManager();
try { try {
userIDM.getAuthInfo(account_osAccount.AuthType.PIN, (err, result) => { userIDM.getAuthInfo(account_osAccount.AuthType.PIN,
(err: BusinessError, result: account_osAccount.EnrolledCredInfo[]) => {
console.log('getAuthInfo err = ' + JSON.stringify(err)); console.log('getAuthInfo err = ' + JSON.stringify(err));
console.log('getAuthInfo result = ' + JSON.stringify(result)); console.log('getAuthInfo result = ' + JSON.stringify(result));
}); });
...@@ -5749,11 +5984,12 @@ Obtains authentication information of the specified type. This API uses a promis ...@@ -5749,11 +5984,12 @@ Obtains authentication information of the specified type. This API uses a promis
**Example** **Example**
```js ```js
import { BusinessError } from '@ohos.base';
let userIDM = new account_osAccount.UserIdentityManager(); let userIDM = new account_osAccount.UserIdentityManager();
try { try {
userIDM.getAuthInfo(account_osAccount.AuthType.PIN).then((result) => { userIDM.getAuthInfo(account_osAccount.AuthType.PIN).then((result: account_osAccount.EnrolledCredInfo[]) => {
console.log('getAuthInfo result = ' + JSON.stringify(result)) console.log('getAuthInfo result = ' + JSON.stringify(result))
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('getAuthInfo error = ' + JSON.stringify(err)); console.log('getAuthInfo error = ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
...@@ -5792,10 +6028,10 @@ Called to set data in a PIN operation. ...@@ -5792,10 +6028,10 @@ Called to set data in a PIN operation.
**Example** **Example**
```js ```js
let password = new Uint8Array([0, 0, 0, 0, 0, 0]); let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]);
let passwordNumber = new Uint8Array([1, 2, 3, 4]); let passwordNumber: Uint8Array = new Uint8Array([1, 2, 3, 4]);
let inputer = { let inputer: account_osAccount.IInputer = {
onGetData: (authSubType, callback) => { onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
if (authSubType == account_osAccount.AuthSubType.PIN_NUMBER) { if (authSubType == account_osAccount.AuthSubType.PIN_NUMBER) {
callback.onSetData(authSubType, passwordNumber); callback.onSetData(authSubType, passwordNumber);
} else { } else {
...@@ -5829,10 +6065,10 @@ Called to obtain data. ...@@ -5829,10 +6065,10 @@ Called to obtain data.
**Example** **Example**
```js ```js
let password = new Uint8Array([0, 0, 0, 0, 0, 0]); let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]);
let passwordNumber = new Uint8Array([1, 2, 3, 4]); let passwordNumber: Uint8Array = new Uint8Array([1, 2, 3, 4]);
let inputer = { let inputer: account_osAccount.IInputer = {
onGetData: (authSubType, callback) => { onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
if (authSubType == account_osAccount.AuthSubType.PIN_NUMBER) { if (authSubType == account_osAccount.AuthSubType.PIN_NUMBER) {
callback.onSetData(authSubType, passwordNumber); callback.onSetData(authSubType, passwordNumber);
} else { } else {
...@@ -5840,7 +6076,7 @@ Called to obtain data. ...@@ -5840,7 +6076,7 @@ Called to obtain data.
} }
} }
}; };
let pinAuth = new account_osAccount.PINAuth(); let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
let result = pinAuth.registerInputer(inputer); let result = pinAuth.registerInputer(inputer);
console.log('registerInputer result: ' + result); console.log('registerInputer result: ' + result);
``` ```
...@@ -5870,8 +6106,8 @@ Called to return the result code and authentication result. ...@@ -5870,8 +6106,8 @@ Called to return the result code and authentication result.
**Example** **Example**
```js ```js
let authCallback = { let authCallback: account_osAccount.IUserAuthCallback = {
onResult: (result, extraInfo) => { onResult: (result: number, extraInfo: account_osAccount.AuthResult) => {
console.log('auth result = ' + result); console.log('auth result = ' + result);
console.log('auth extraInfo = ' + JSON.stringify(extraInfo)); console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
} }
...@@ -5898,12 +6134,12 @@ Called to acquire identity authentication information. ...@@ -5898,12 +6134,12 @@ Called to acquire identity authentication information.
**Example** **Example**
```js ```js
let authCallback = { let authCallback: account_osAccount.IUserAuthCallback = {
onResult: (result, extraInfo) => { onResult: (result: number, extraInfo: account_osAccount.AuthResult) => {
console.log('auth result = ' + result) console.log('auth result = ' + result)
console.log('auth extraInfo = ' + JSON.stringify(extraInfo)); console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
}, },
onAcquireInfo: (module, acquire, extraInfo) => { onAcquireInfo: (module: number, acquire: number, extraInfo: account_osAccount.RequestResult) => {
console.log('auth module = ' + module); console.log('auth module = ' + module);
console.log('auth acquire = ' + acquire); console.log('auth acquire = ' + acquire);
console.info('auth extraInfo = ' + JSON.stringify(extraInfo)); console.info('auth extraInfo = ' + JSON.stringify(extraInfo));
...@@ -5936,8 +6172,8 @@ Called to return the result code and request result information. ...@@ -5936,8 +6172,8 @@ Called to return the result code and request result information.
**Example** **Example**
```js ```js
let idmCallback = { let idmCallback: account_osAccount.IIdmCallback = {
onResult: (result, extraInfo) => { onResult: (result: number, extraInfo: account_osAccount.RequestResult) => {
console.log('callback result = ' + result) console.log('callback result = ' + result)
console.info('callback extraInfo = ' + JSON.stringify(extraInfo)); console.info('callback extraInfo = ' + JSON.stringify(extraInfo));
} }
...@@ -5964,12 +6200,12 @@ Called to acquire IDM information. ...@@ -5964,12 +6200,12 @@ Called to acquire IDM information.
**Example** **Example**
```js ```js
let idmCallback = { let idmCallback: account_osAccount.IIdmCallback = {
onResult: (result, extraInfo) => { onResult: (result: number, extraInfo: Object) => {
console.log('callback result = ' + result) console.log('callback result = ' + result)
console.log('callback onResult = ' + JSON.stringify(extraInfo)); console.log('callback onResult = ' + JSON.stringify(extraInfo));
}, },
onAcquireInfo: (module, acquire, extraInfo) => { onAcquireInfo: (module: number, acquire: number, extraInfo: Object) => {
console.log('callback module = ' + module); console.log('callback module = ' + module);
console.log('callback acquire = ' + acquire); console.log('callback acquire = ' + acquire);
console.log('callback onacquireinfo = ' + JSON.stringify(extraInfo)); console.log('callback onacquireinfo = ' + JSON.stringify(extraInfo));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册