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