From e975b1d664f4cb2b4e51a812883c825182b5445f Mon Sep 17 00:00:00 2001 From: Gloria Date: Mon, 13 Feb 2023 17:40:57 +0800 Subject: [PATCH] Update docs Signed-off-by: wusongqing --- .../apis/js-apis-application-context.md | 41 -- .../js-apis-application-extensionAbility.md | 62 --- .../apis/js-apis-backgroundTaskManager.md | 24 +- .../apis/js-apis-distributedBundle.md | 479 ------------------ .../reference/apis/js-apis-environment.md | 106 ---- ...-resourceschedule-backgroundTaskManager.md | 68 +-- .../js-apis-resourceschedule-workScheduler.md | 10 +- .../reference/apis/js-apis-securityLabel.md | 179 ------- .../reference/apis/js-apis-workScheduler.md | 361 ------------- .../workscheduler-extensionability.md | 68 +-- 10 files changed, 85 insertions(+), 1313 deletions(-) delete mode 100644 en/application-dev/reference/apis/js-apis-application-context.md delete mode 100644 en/application-dev/reference/apis/js-apis-application-extensionAbility.md delete mode 100644 en/application-dev/reference/apis/js-apis-distributedBundle.md delete mode 100644 en/application-dev/reference/apis/js-apis-environment.md delete mode 100644 en/application-dev/reference/apis/js-apis-securityLabel.md delete mode 100644 en/application-dev/reference/apis/js-apis-workScheduler.md diff --git a/en/application-dev/reference/apis/js-apis-application-context.md b/en/application-dev/reference/apis/js-apis-application-context.md deleted file mode 100644 index d42e522c14..0000000000 --- a/en/application-dev/reference/apis/js-apis-application-context.md +++ /dev/null @@ -1,41 +0,0 @@ -# @ohos.application.context (Context) - -The **Context** module provides all level-2 module APIs for developers to export. - -> **NOTE** -> -> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. -> The APIs of this module can be used only in the stage model. - -## Modules to Import - -```ts -import context from '@ohos.application.context' -``` - -**System capability**: SystemCapability.Ability.AbilityBase - -| Name | Readable/Writable| Type | Mandatory| Description | -| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ | -| AbilityContext | Read Only | [AbilityContext](js-apis-ability-context.md) | No | Level-2 module **AbilityContext**. | -| AbilityStageContext | Read Only | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | No | Level-2 module **AbilityStageContext**.| -| ApplicationContext | Read Only | [ApplicationContext](js-apis-inner-application-applicationContext.md) | No | Level-2 module **ApplicationContext**.| -| BaseContext | Read Only | [BaseContext](js-apis-inner-application-baseContext.md) | No | Level-2 module **BaseContext**.| -| Context | Read Only | [Context](js-apis-inner-application-context.md) | No | Level-2 module **Context**.| -| ExtensionContext | Read Only | [ExtensionContext](js-apis-inner-application-extensionContext.md) | No | Level-2 module **ExtensionContext**.| -| FormExtensionContext | Read Only | [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) | No | Level-2 module **FormExtensionContext**.| -| EventHub | Read Only | [EventHub](js-apis-inner-application-eventHub.md) | No | Level-2 module **EventHub**.| -| PermissionRequestResult | Read Only | [PermissionRequestResult](js-apis-inner-application-permissionRequestResult.md) | No | Level-2 module **PermissionRequestResult**.| - -**Example** -```ts -let abilityContext: context.AbilityContext; -let abilityStageContext: context.AbilityStageContext; -let applicationContext: context.ApplicationContext; -let baseContext: context.BaseContext; -let context: context.Context; -let extensionContext: context.ExtensionContext; -let formExtensionContext: context.FormExtensionContext; -let eventHub: context.EventHub; -let permissionRequestResult: context.PermissionRequestResult; -``` diff --git a/en/application-dev/reference/apis/js-apis-application-extensionAbility.md b/en/application-dev/reference/apis/js-apis-application-extensionAbility.md deleted file mode 100644 index f18b293edd..0000000000 --- a/en/application-dev/reference/apis/js-apis-application-extensionAbility.md +++ /dev/null @@ -1,62 +0,0 @@ -# @ohos.application.ExtensionAbility (ExtensionAbility) - -The **ExtensionAbility** module manages the ExtensionAbility lifecycle and context, such as creating and destroying an ExtensionAbility, and dumping client information. - -> **NOTE** -> -> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. -> The APIs of this module can be used only in the stage model. - -## Modules to Import - -```ts -import ExtensionAbility from '@ohos.application.ExtensionAbility'; -``` - -## ExtensionAbility.onConfigurationUpdated - -onConfigurationUpdated(newConfig: Configuration): void; - -Called when the configuration of the environment where the ability is running is updated. - -**System capability**: SystemCapability.Ability.AbilityRuntime.Core - -**Parameters** - - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | newConfig | [Configuration](js-apis-application-configuration.md) | Yes| New configuration.| - -**Example** - - ```ts - class MyExtensionAbility extends ExtensionAbility { - onConfigurationUpdated(config) { - console.log('onConfigurationUpdated, config:' + JSON.stringify(config)); - } - } - ``` - -## ExtensionAbility.onMemoryLevel - -onMemoryLevel(level: AbilityConstant.MemoryLevel): void; - -Called when the system has decided to adjust the memory level. For example, this API can be used when there is not enough memory to run as many background processes as possible. - -**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore - -**Parameters** - - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | level | [AbilityConstant.MemoryLevel](js-apis-application-abilityConstant.md#abilityconstantmemorylevel) | Yes| Memory level that indicates the memory usage status. When the specified memory level is reached, a callback will be invoked and the system will start adjustment.| - -**Example** - - ```ts - class MyExtensionAbility extends ExtensionAbility { - onMemoryLevel(level) { - console.log('onMemoryLevel, level:' + JSON.stringify(level)); - } - } - ``` diff --git a/en/application-dev/reference/apis/js-apis-backgroundTaskManager.md b/en/application-dev/reference/apis/js-apis-backgroundTaskManager.md index 6080d2c9bc..66a87735c1 100644 --- a/en/application-dev/reference/apis/js-apis-backgroundTaskManager.md +++ b/en/application-dev/reference/apis/js-apis-backgroundTaskManager.md @@ -187,7 +187,7 @@ let wantAgentInfo = { wants: [ { bundleName: "com.example.myapplication", - abilityName: "EntryAbility" + abilityName: "com.example.myapplication.MainAbility" } ], operationType: wantAgent.OperationType.START_ABILITY, @@ -205,7 +205,7 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { Stage model: ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; +import Ability from '@ohos.application.Ability'; import backgroundTaskManager from '@ohos.backgroundTaskManager'; import wantAgent from '@ohos.wantAgent'; @@ -217,13 +217,13 @@ function callback(err, data) { } } -export default class EntryAbility extends UIAbility { +export default class MainAbility extends Ability { onCreate(want, launchParam) { let wantAgentInfo = { wants: [ { bundleName: "com.example.myapplication", - abilityName: "EntryAbility" + abilityName: "com.example.myapplication.MainAbility" } ], operationType: wantAgent.OperationType.START_ABILITY, @@ -276,7 +276,7 @@ let wantAgentInfo = { wants: [ { bundleName: "com.example.myapplication", - abilityName: "EntryAbility" + abilityName: "com.example.myapplication.MainAbility" } ], operationType: wantAgent.OperationType.START_ABILITY, @@ -297,17 +297,17 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { Stage model: ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; +import Ability from '@ohos.application.Ability'; import backgroundTaskManager from '@ohos.backgroundTaskManager'; import wantAgent from '@ohos.wantAgent'; -export default class EntryAbility extends UIAbility { +export default class MainAbility extends Ability { onCreate(want, launchParam) { let wantAgentInfo = { wants: [ { bundleName: "com.example.myapplication", - abilityName: "EntryAbility" + abilityName: "com.example.myapplication.MainAbility" } ], operationType: wantAgent.OperationType.START_ABILITY, @@ -365,7 +365,7 @@ backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext(), callbac Stage model: ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; +import Ability from '@ohos.application.Ability'; import backgroundTaskManager from '@ohos.backgroundTaskManager'; function callback(err, data) { @@ -376,7 +376,7 @@ function callback(err, data) { } } -export default class EntryAbility extends UIAbility { +export default class MainAbility extends Ability { onCreate(want, launchParam) { backgroundTaskManager.stopBackgroundRunning(this.context, callback); } @@ -422,10 +422,10 @@ backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() Stage model: ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; +import Ability from '@ohos.application.Ability'; import backgroundTaskManager from '@ohos.backgroundTaskManager'; -export default class EntryAbility extends UIAbility { +export default class MainAbility extends Ability { onCreate(want, launchParam) { backgroundTaskManager.stopBackgroundRunning(this.context).then(() => { console.info("Operation stopBackgroundRunning succeeded"); diff --git a/en/application-dev/reference/apis/js-apis-distributedBundle.md b/en/application-dev/reference/apis/js-apis-distributedBundle.md deleted file mode 100644 index 98a15d8184..0000000000 --- a/en/application-dev/reference/apis/js-apis-distributedBundle.md +++ /dev/null @@ -1,479 +0,0 @@ -# distributedBundle - -The **distributedBundle** module provides APIs for managing distributed bundles. - -> **NOTE** -> -> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. -> -> The APIs provided by this module are system APIs. - -## Modules to Import - -``` -import distributedBundle from '@ohos.bundle.distributedBundle'; -``` - -## System Capability - -SystemCapability.BundleManager.DistributedBundleFramework - -## Required Permissions - -| Permission | Permission Level | Description | -| ------------------------------------------ | ------------ | ------------------ | -| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all bundles.| - -For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels). - -## distributedBundle.getRemoteAbilityInfo - -getRemoteAbilityInfo(elementName: ElementName, callback: AsyncCallback\): void; - -Obtains information about the remote ability that matches the given element name. This API uses an asynchronous callback to return the result. - -**System API**: This is a system API. - -**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED - -**System capability**: SystemCapability.BundleManager.DistributedBundleFramework - -**Parameters** - -| Name | Type | Mandatory| Description | -| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| elementName | [ElementName](js-apis-bundleManager-elementName.md) | Yes | Target element name. | -| callback | AsyncCallback<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the **RemoteAbilityInfo** object obtained. Otherwise, **err** is an error object.| - -**Error codes** - -For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). - -| ID| Error Message | -|----------|--------------------------------------| -| 17700001 | The specified bundle name is not found. | -| 17700003 | The specified ability name is not found. | -| 17700007 | The specified device ID is not found. | -| 17700027 | The distributed service is not running. | - -**Example** - -```ts -try { - distributedBundle.getRemoteAbilityInfo( - { - deviceId: '1', - bundleName: 'com.example.application', - abilityName: 'MainAbility' - }, (err, data) => { - if (err) { - console.error('Operation failed:' + JSON.stringify(err)); - } else { - console.info('Operation succeed:' + JSON.stringify(data)); - } - }); -} catch (err) { - console.error('Operation failed:' + JSON.stringify(err)); -} -``` - -## distributedBundle.getRemoteAbilityInfo - -getRemoteAbilityInfo(elementName: ElementName): Promise\; - -Obtains information about the remote ability that matches the given element name. This API uses a promise to return the result. - -**System API**: This is a system API. - -**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED - -**System capability**: SystemCapability.BundleManager.DistributedBundleFramework - -**Parameters** - -| Name | Type | Mandatory| Description | -| ----------- | -------------------------------------------- | ---- | ----------------------- | -| elementName | [ElementName](js-apis-bundleManager-elementName.md) | Yes | Target element name.| - -**Return value** - -| Type | Description | -| ------------------------------------------------------------ | --------------------------------- | -| Promise\<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)> | Promise used to return the **RemoteAbilityInfo** object obtained.| - -**Error codes** - -For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). - -| ID| Error Message | -|----------|-------------------------| -| 17700001 | The specified bundle name is not found. | -| 17700003 | The specified ability name is not found. | -| 17700007 | The specified device ID is not found. | -| 17700027 | The distributed service is not running. | - -**Example** - -```ts -try { - distributedBundle.getRemoteAbilityInfo( - { - deviceId: '1', - bundleName: 'com.example.application', - abilityName: 'MainAbility' - }).then(data => { - console.info('Operation succeed:' + JSON.stringify(data)); - }).catch(err => { - console.error('Operation failed:' + JSON.stringify(err)); - }); -} catch (err) { - console.error('Operation failed:' + JSON.stringify(err)); -} -``` - -## distributedBundle.getRemoteAbilityInfo - -getRemoteAbilityInfo(elementNames: Array\, callback: AsyncCallback\>): void; - -Obtains information about remote abilities that match the given element names. This API uses an asynchronous callback to return the result. - -**System API**: This is a system API. - -**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED - -**System capability**: SystemCapability.BundleManager.DistributedBundleFramework - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)> | Yes | **ElementName** array, whose maximum length is 10. | -| callback | AsyncCallback\> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of **RemoteAbilityInfo** objects obtained. Otherwise, **err** is an error object.| - -**Error codes** - -For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). - -| ID| Error Message | -|----------|-------------------------| -| 17700001 | The specified bundle name is not found. | -| 17700003 | The specified ability name is not found. | -| 17700007 | The specified device ID is not found. | -| 17700027 | The distributed service is not running. | - -**Example** - -```ts -try { - distributedBundle.getRemoteAbilityInfo( - [ - { - deviceId: '1', - bundleName: 'com.example.application1', - abilityName: 'MainAbility1' - }, - { - deviceId: '1', - bundleName: 'com.example.application2', - abilityName: 'MainAbility' - } - ], (err, data) => { - if (err) { - console.error('Operation failed:' + JSON.stringify(err)); - } else { - console.info('Operation succeed:' + JSON.stringify(data)); - } - }); -} catch (err) { - console.error('Operation failed:' + JSON.stringify(err)); -} -``` - -## distributedBundle.getRemoteAbilityInfo - -getRemoteAbilityInfo(elementNames: Array\): Promise\>; - -Obtains information about remote abilities that match the given element names and locales. This API uses a promise to return the result. - -**System API**: This is a system API. - -**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED - -**System capability**: SystemCapability.BundleManager.DistributedBundleFramework - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------------ | --------------------------------------------------- | ---- | ----------------------- | -| elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)> | Yes | **ElementName** array, whose maximum length is 10.| - -**Return value** - -| Type | Description | -| ------------------------------------------------------------ | --------------------------------- | -| Promise\> | Promise used to return the array of **RemoteAbilityInfo** objects obtained.| - -**Error codes** - -For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). - -| ID| Error Message | -|----------|-------------------------| -| 17700001 | The specified bundle name is not found. | -| 17700003 | The specified ability name is not found. | -| 17700007 | The specified device ID is not found. | -| 17700027 | The distributed service is not running. | - -**Example** - -```ts -try { - distributedBundle.getRemoteAbilityInfo( - [ - { - deviceId: '1', - bundleName: 'com.example.application', - abilityName: 'MainAbility' - }, - { - deviceId: '1', - bundleName: 'com.example.application2', - abilityName: 'MainAbility' - } - ]).then(data => { - console.info('Operation succeed:' + JSON.stringify(data)); - }).catch(err => { - console.error('Operation failed:' + JSON.stringify(err)); - }); -} catch (err) { - console.error('Operation failed:' + JSON.stringify(err)); -} -``` - -## distributedBundle.getRemoteAbilityInfo - -getRemoteAbilityInfo(elementName: ElementName, locale: string, callback: AsyncCallback\): void; - -Obtains information about the remote ability that matches the given element name and locale. This API uses an asynchronous callback to return the result. - -**System API**: This is a system API. - -**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED - -**System capability**: SystemCapability.BundleManager.DistributedBundleFramework - -**Parameters** - -| Name | Type | Mandatory| Description | -| ----------- | ------------------------------------------------------------ | ---- | -------------------------------------------------- | -| elementName | [ElementName](js-apis-bundleManager-elementName.md) | Yes | Target element name. | -| locale | string |Yes| Target locale.| -| callback | AsyncCallback<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the **RemoteAbilityInfo** object obtained. Otherwise, **err** is an error object.| - -**Error codes** - -For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). - -| ID| Error Message | -|----------|-------------------------| -| 17700001 | The specified bundle name is not found. | -| 17700003 | The specified ability name is not found. | -| 17700007 | The specified device ID is not found. | -| 17700027 | The distributed service is not running. | - -**Example** - -```ts -try { - distributedBundle.getRemoteAbilityInfo( - { - deviceId: '1', - bundleName: 'com.example.application', - abilityName: 'MainAbility' - }, 'zh-Hans-CN', (err, data) => { - if (err) { - console.error('Operation failed:' + JSON.stringify(err)); - } else { - console.info('Operation succeed:' + JSON.stringify(data)); - } - }); -} catch (err) { - console.error('Operation failed:' + JSON.stringify(err)); -} -``` - -## distributedBundle.getRemoteAbilityInfo - -getRemoteAbilityInfo(elementName: ElementName, locale: string): Promise\; - -Obtains information about the remote ability that matches the given element name and locale. This API uses a promise to return the result. - -**System API**: This is a system API. - -**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED - -**System capability**: SystemCapability.BundleManager.DistributedBundleFramework - -**Parameters** - -| Name | Type | Mandatory| Description | -| ----------- | -------------------------------------------- | ---- | ----------------------- | -| elementName | [ElementName](js-apis-bundleManager-elementName.md) | Yes | Target element name.| -| locale | string |Yes| Target locale.| - -**Return value** - -| Type | Description | -| ------------------------------------------------------------ | --------------------------------- | -| Promise\<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)> | Promise used to return the **RemoteAbilityInfo** object obtained.| - -**Error codes** - -For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). - -| ID| Error Message | -|----------|-------------------------| -| 17700001 | The specified bundle name is not found. | -| 17700003 | The specified ability name is not found. | -| 17700007 | The specified device ID is not found. | -| 17700027 | The distributed service is not running. | - -**Example** - -```ts -try { - distributedBundle.getRemoteAbilityInfo( - { - deviceId: '1', - bundleName: 'com.example.application', - abilityName: 'MainAbility' - }, 'zh-Hans-CN').then(data => { - console.info('Operation succeed:' + JSON.stringify(data)); - }).catch(err => { - console.error('Operation failed:' + JSON.stringify(err)); - }); -} catch (err) { - console.error('Operation failed:' + JSON.stringify(err)); -} -``` - -## distributedBundle.getRemoteAbilityInfo - -getRemoteAbilityInfo(elementNames: Array\, locale: string, callback: AsyncCallback\>): void; - -Obtains information about remote abilities that match the given element names and locales. This API uses an asynchronous callback to return the result. - -**System API**: This is a system API. - -**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED - -**System capability**: SystemCapability.BundleManager.DistributedBundleFramework - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------------ | ------------------------------------------------------------ | ---- | -------------------------------------------------- | -| elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)> | Yes | **ElementName** array, whose maximum length is 10. | -| locale | string |Yes| Target locale.| -| callback | AsyncCallback\> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of **RemoteAbilityInfo** objects obtained. Otherwise, **err** is an error object.| - -**Error codes** - -For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). - -| ID | Error Message | -|---------------|-------------------------| -| 17700001 | The specified bundle name is not found. | -| 17700003 | The specified ability name is not found. | -| 17700007 | The specified device ID is not found. | -| 17700027 | The distributed service is not running. | - -**Example** - -```ts -try { - distributedBundle.getRemoteAbilityInfo( - [ - { - deviceId: '1', - bundleName: 'com.example.application1', - abilityName: 'MainAbility1' - }, - { - deviceId: '1', - bundleName: 'com.example.application2', - abilityName: 'MainAbility' - } - ], 'zh-Hans-CN', (err, data) => { - if (err) { - console.error('Operation failed:' + JSON.stringify(err)); - } else { - console.info('Operation succeed:' + JSON.stringify(data)); - } - }); -} catch (err) { - console.error('Operation failed:' + JSON.stringify(err)); -} -``` - -## distributedBundle.getRemoteAbilityInfo - -getRemoteAbilityInfo(elementNames: Array\, locale: string): Promise\>; - -Obtains information about remote abilities that match the given element names and locales. This API uses a promise to return the result. - -**System API**: This is a system API. - -**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED - -**System capability**: SystemCapability.BundleManager.DistributedBundleFramework - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------------ | --------------------------------------------------- | ---- | ----------------------- | -| elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)> | Yes | **ElementName** array, whose maximum length is 10.| -| locale | string |Yes| Target locale.| - -**Return value** - -| Type | Description | -| ------------------------------------------------------------ | --------------------------------- | -| Promise\> | Promise used to return the array of **RemoteAbilityInfo** objects obtained.| - -**Error codes** - -For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). - -| ID| Error Message | -|----------|-------------------------| -| 17700001 | The specified bundle name is not found. | -| 17700003 | The specified ability name is not found. | -| 17700007 | The specified device ID is not found. | -| 17700027 | The distributed service is not running. | - -**Example** - -```ts -try { - distributedBundle.getRemoteAbilityInfo( - [ - { - deviceId: '1', - bundleName: 'com.example.application', - abilityName: 'MainAbility' - }, - { - deviceId: '1', - bundleName: 'com.example.application2', - abilityName: 'MainAbility' - } - ], 'zh-Hans-CN').then(data => { - console.info('Operation succeed:' + JSON.stringify(data)); - }).catch(err => { - console.error('Operation failed:' + JSON.stringify(err)); - }); -} catch (err) { - console.error('Operation failed:' + JSON.stringify(err)); -} -``` diff --git a/en/application-dev/reference/apis/js-apis-environment.md b/en/application-dev/reference/apis/js-apis-environment.md deleted file mode 100644 index 3f879c77b9..0000000000 --- a/en/application-dev/reference/apis/js-apis-environment.md +++ /dev/null @@ -1,106 +0,0 @@ -# Environment - -The **Environment** module provides APIs for obtaining the root directories of the storage and public files. - -> **NOTE** -> -> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. -> - The APIs of this module are system APIs and cannot be called by third-party applications. - -## Modules to Import - -```js -import environment from '@ohos.environment'; -``` - -## environment.getStorageDataDir - -getStorageDataDir():Promise<string> - -Obtains the root directory of the storage. This API uses a promise to return the result. - -**System capability**: SystemCapability.FileManagement.File.Environment - -**Return value** - -| Type | Description | -| --------------------- | ---------------- | -| Promise<string> | Promise returned with the root directory of the storage.| - -**Example** - - ```js - environment.getStorageDataDir().then(function(path){ - console.info("getStorageDataDir successfully:"+ path); - }).catch(function(error){ - console.info("getStorageDataDir failed with error:"+ error); - }); - ``` - -## environment.getStorageDataDir - -getStorageDataDir(callback:AsyncCallback<string>):void - -Obtains the root directory of the storage. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.FileManagement.File.Environment - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | --------------------------- | ---- | -------------------------------- | -| callback | AsyncCallback<string> | Yes | Asynchronous callback used to return the root directory of the storage.| - -**Example** - - ```js - environment.getStorageDataDir(function(error, path){ - // do something - }); - ``` - -## environment.getUserDataDir - -getUserDataDir():Promise<string> - -Obtains the root directory of public files. This API uses a promise to return the result. - -**System capability**: SystemCapability.FileManagement.File.Environment - -**Return value** - -| Type | Description | -| --------------------- | ------------------ | -| Promise<string> | Promise returned with the root directory of public files.| - -**Example** - - ```js - environment.getUserDataDir().then(function(path){ - console.info("getUserDataDir successfully:"+ path); - }).catch(function(error){ - console.info("getUserDataDir failed with error:"+ error); - }); - ``` - -## environment.getUserDataDir - -getUserDataDir(callback:AsyncCallback<string>): void - -Obtains the root directory of public files. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.FileManagement.File.Environment - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | --------------------------- | ---- | -------------------------------- | -| callback | AsyncCallback<string> | Yes | Asynchronous callback used to return the root directory of public files.| - -**Example** - - ```js - environment.getUserDataDir(function(error, path){ - // do something - }); - ``` diff --git a/en/application-dev/reference/apis/js-apis-resourceschedule-backgroundTaskManager.md b/en/application-dev/reference/apis/js-apis-resourceschedule-backgroundTaskManager.md index d5daa5d41e..663ebe8f9d 100644 --- a/en/application-dev/reference/apis/js-apis-resourceschedule-backgroundTaskManager.md +++ b/en/application-dev/reference/apis/js-apis-resourceschedule-backgroundTaskManager.md @@ -52,10 +52,10 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9900001 | Caller information verification failed for a transient task. | -| 9900002 | Transient task verification failed. | +| 9900001 | Caller information verification failed. | +| 9900002 | Background task verification failed. | **Example** @@ -100,10 +100,10 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9900001 | Caller information verification failed for a transient task. | -| 9900002 | Transient task verification failed. | +| 9900001 | Caller information verification failed. | +| 9900002 | Background task verification failed. | **Example** @@ -156,10 +156,10 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9900001 | Caller information verification failed for a transient task. | -| 9900002 | Transient task verification failed. | +| 9900001 | Caller information verification failed. | +| 9900002 | Background task verification failed. | **Example** @@ -201,10 +201,10 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9900001 | Caller information verification failed for a transient task. | -| 9900002 | Transient task verification failed. | +| 9900001 | Caller information verification failed. | +| 9900002 | Background task verification failed. | **Example** @@ -247,16 +247,16 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9800005 | Continuous task verification failed. | +| 9800005 | Background task verification failed. | | 9800006 | Notification verification failed. | | 9800007 | Task storage failed. | **Example** ```js -import UIAbility from '@ohos.app.ability.UIAbility'; +import Ability from '@ohos.application.Ability' import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import wantAgent from '@ohos.wantAgent'; @@ -268,13 +268,13 @@ function callback(error, data) { } } -export default class EntryAbility extends UIAbility { +export default class MainAbility extends Ability { onCreate(want, launchParam) { let wantAgentInfo = { wants: [ { bundleName: "com.example.myapplication", - abilityName: "EntryAbility" + abilityName: "MainAbility" } ], operationType: wantAgent.OperationType.START_ABILITY, @@ -326,26 +326,26 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9800005 | Continuous task verification failed. | +| 9800005 | Background task verification failed. | | 9800006 | Notification verification failed. | | 9800007 | Task storage failed. | **Example** ```js -import UIAbility from '@ohos.app.ability.UIAbility'; +import Ability from '@ohos.application.Ability' import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import wantAgent from '@ohos.wantAgent'; -export default class EntryAbility extends UIAbility { +export default class MainAbility extends Ability { onCreate(want, launchParam) { let wantAgentInfo = { wants: [ { bundleName: "com.example.myapplication", - abilityName: "EntryAbility" + abilityName: "MainAbility" } ], operationType: wantAgent.OperationType.START_ABILITY, @@ -392,16 +392,16 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9800005 | Continuous task verification failed. | +| 9800005 | Background task verification failed. | | 9800006 | Notification verification failed. | | 9800007 | Task storage failed. | **Example** ```js -import UIAbility from '@ohos.app.ability.UIAbility'; +import Ability from '@ohos.application.Ability' import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; function callback(error, data) { @@ -412,7 +412,7 @@ function callback(error, data) { } } -export default class EntryAbility extends UIAbility { +export default class MainAbility extends Ability { onCreate(want, launchParam) { try { backgroundTaskManager.stopBackgroundRunning(this.context, callback); @@ -453,19 +453,19 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9800005 | Continuous task verification failed. | +| 9800005 | Background task verification failed. | | 9800006 | Notification verification failed. | | 9800007 | Task storage failed. | **Example** ```js -import UIAbility from '@ohos.app.ability.UIAbility'; +import Ability from '@ohos.application.Ability' import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; -export default class EntryAbility extends UIAbility { +export default class MainAbility extends Ability { onCreate(want, launchParam) { try { backgroundTaskManager.stopBackgroundRunning(this.context).then(() => { @@ -506,9 +506,9 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 18700001 | Caller information verification failed when applying for efficiency resources. | +| 18700001 | Caller information verification failed. | **Example** @@ -549,9 +549,9 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 18700001 | Caller information verification failed when applying for efficiency resources. | +| 18700001 | Caller information verification failed. | **Example** diff --git a/en/application-dev/reference/apis/js-apis-resourceschedule-workScheduler.md b/en/application-dev/reference/apis/js-apis-resourceschedule-workScheduler.md index 0e7ad7e7c3..736335322c 100644 --- a/en/application-dev/reference/apis/js-apis-resourceschedule-workScheduler.md +++ b/en/application-dev/reference/apis/js-apis-resourceschedule-workScheduler.md @@ -39,7 +39,7 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes | 9700001 | Memory operation failed. | | 9700002 | Parcel operation failed. | | 9700003 | System service operation failed. | -| 9700004 | Checking workInfo failed. | +| 9700004 | Check workInfo failed. | | 9700005 | StartWork failed. | @@ -80,7 +80,7 @@ Instructs the **WorkSchedulerService** to stop the specified task. | Name | Type | Mandatory | Description | | ---------- | --------------------- | ---- | ---------- | | work | [WorkInfo](#workinfo) | Yes | Task to stop. | -| needCancel | boolean | Yes | Whether to cancel the task.| +| needCancel | boolean | No | Whether to cancel the task.| **Error codes** @@ -91,7 +91,7 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes | 9700001 | Memory operation failed. | | 9700002 | Parcel operation failed. | | 9700003 | System service operation failed. | -| 9700004 | Checking workInfo failed. | +| 9700004 | Check workInfo failed. | **Example** @@ -141,7 +141,7 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes | 9700001 | Memory operation failed. | | 9700002 | Parcel operation failed. | | 9700003 | System service operation failed. | -| 9700004 | Checking workInfo failed. | +| 9700004 | Check workInfo failed. | **Example** @@ -189,7 +189,7 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes | 9700001 | Memory operation failed. | | 9700002 | Parcel operation failed. | | 9700003 | System service operation failed. | -| 9700004 | Checking workInfo failed. | +| 9700004 | Check workInfo failed. | **Example** diff --git a/en/application-dev/reference/apis/js-apis-securityLabel.md b/en/application-dev/reference/apis/js-apis-securityLabel.md deleted file mode 100644 index d61e7c1b5a..0000000000 --- a/en/application-dev/reference/apis/js-apis-securityLabel.md +++ /dev/null @@ -1,179 +0,0 @@ -# Security Label - -The **secuityLabel** module provides APIs to manage file data security levels, including obtaining and setting file data security levels. - -> **NOTE**
-> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. - -## Modules to Import - -```js -import securityLabel from '@ohos.securityLabel'; -``` - -## Usage - -Before using the APIs provided by this module to perform operations on a file or directory, obtain the path of the application sandbox as follows: - -```js -import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); -let path = ''; -context.getFilesDir().then((data) => { - path = data; -}) -``` - -## securityLabel.setSecurityLabel - -setSecurityLabel(path:string, type:dataLevel):Promise<void> - -Sets the security label for a file in asynchronous mode. This API uses a promise to return the result. - -**System capability**: SystemCapability.FileManagement.File.FileIO - -**Parameters** - -| Name | Type | Mandatory| Description | -| --------- | ------ | ---- | -------------------------------------------- | -| path | string | Yes | File path. | -| type | dataLevel | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.| - -**Return value** - - | Type | Description | - | ------------------- | ---------------- | - | Promise<void> | Promise used to return the result. An empty value will be returned.| - -**Example** - - ```js - securityLabel.setSecurityLabel(path, "s0").then(function(){ - console.info("setSecurityLabel successfully"); - }).catch(function(error){ - console.info("setSecurityLabel failed with error:" + error); - }); - ``` - -## securityLabel.setSecurityLabel - -setSecurityLabel(path:string, type:dataLevel, callback: AsyncCallback<void>):void - -Sets the security label for a file in asynchronous mode. This API uses a callback to return the result. - -**System capability**: SystemCapability.FileManagement.File.FileIO - -**Parameters** - -| Name | Type | Mandatory| Description | -| --------- | ------------------------- | ---- | -------------------------------------------- | -| path | string | Yes | File path. | -| type | dataLevel | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.| -| callback | AsyncCallback<void> | Yes | Callback used to return the result. | - -**Example** - - ```js - securityLabel.setSecurityLabel(path, "s0", function(error){ - console.info("setSecurityLabel:" + JSON.stringify(error)); - }); - ``` -## securityLabel.setSecurityLabelSync - -setSecurityLabelSync(path:string, type:dataLevel):void - -Sets the security label for a file in synchronous mode. - -**System capability**: SystemCapability.FileManagement.File.FileIO - -**Parameters** - -| Name | Type | Mandatory| Description | -| --------- | ------ | ---- | -------------------------------------------- | -| path | string | Yes | File path. | -| type | dataLevel | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.| - -**Example** - -```js -securityLabel.setSecurityLabelSync(path, "s0"); -``` - -## securityLabel.getSecurityLabel - -getSecurityLabel(path:string):Promise<string> - -Obtains the security label of a file in asynchronous mode. This API uses a promise to return the result. - -**System capability**: SystemCapability.FileManagement.File.FileIO - -**Parameters** - - | Name| Type | Mandatory| Description | - | ------ | ------ | ---- | -------- | - | path | string | Yes | File path.| - -**Return value** - - | Type | Description | - | --------------------- | ------------ | - | Promise<string> | Promise used to return the security label obtained.| - -**Example** - - ```js - securityLabel.getSecurityLabel(path).then(function(type){ - console.log("getSecurityLabel successfully:" + type); - }).catch(function(err){ - console.log("getSecurityLabel failed with error:" + err); - }); - ``` - -## securityLabel.getSecurityLabel - -getSecurityLabel(path:string, callback:AsyncCallback<string>): void - -Obtains the security label of a file in asynchronous mode. This API uses a callback to return the result. - -**System capability**: SystemCapability.FileManagement.File.FileIO - -**Parameters** - - | Name | Type | Mandatory| Description | - | -------- | --------------------------- | ---- | -------------------------- | - | path | string | Yes | File path. | - | callback | AsyncCallback<string> | Yes | Callback used to return the security label obtained.| - -**Example** - - ```js - securityLabel.getSecurityLabel(path, function(err, type){ - console.log("getSecurityLabel successfully:" + type); - }); - ``` -## securityLabel.getSecurityLabelSync - -getSecurityLabelSync(path:string):string - -Obtains the security label of a file in synchronous mode. - -**System capability**: SystemCapability.FileManagement.File.FileIO - -**Parameters** - -| Name| Type | Mandatory| Description | -| ------ | ------ | ---- | -------- | -| path | string | Yes | File path.| - -**Return value** - -| Type | Description | -| ------ | ------------ | -| string | Security label obtained.| - -**Example** - -```js -let result = securityLabel.getSecurityLabelSync(path); -console.log("getSecurityLabel successfully:" + result); -``` diff --git a/en/application-dev/reference/apis/js-apis-workScheduler.md b/en/application-dev/reference/apis/js-apis-workScheduler.md deleted file mode 100644 index d897bc9171..0000000000 --- a/en/application-dev/reference/apis/js-apis-workScheduler.md +++ /dev/null @@ -1,361 +0,0 @@ -# Work Scheduler - -The **workScheduler** module provides the APIs for registering, canceling, and querying Work Scheduler tasks, which do not have real-time constraints. - -The system executes Work Scheduler tasks at an appropriate time, subject to the storage space, power consumption, temperature, and more. - -> **NOTE** -> -> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. -> - The APIs of this module can be used only in the stage model. -> - For details about the constraints on the Work Scheduler usage, see [Work Scheduler Overview](../../task-management/work-scheduler-overview.md). - - -## Modules to Import - -```js -import workScheduler from '@ohos.workScheduler'; -``` - -## workScheduler.startWork -startWork(work: WorkInfo): boolean - -Instructs the **WorkSchedulerService** to add the specified task to the execution queue. - -**System capability**: SystemCapability.ResourceSchedule.WorkScheduler - -**Parameters** - -| Name | Type | Mandatory | Description | -| ---- | --------------------- | ---- | -------------- | -| work | [WorkInfo](#workinfo) | Yes | Task to be added to the execution queue.| - -**Return value** - -| Type | Description | -| ------- | -------------------------------- | -| boolean | Returns **true** if the task is added to the execution queue; returns **false** otherwise.| - -**Example** - -```js - let workInfo = { - workId: 1, - batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW, - isRepeat: false, - isPersisted: true, - bundleName: "com.example.myapplication", - abilityName: "MyExtension", - parameters: { - mykey0: 1, - mykey1: "string value", - mykey2: true, - mykey3: 1.5 - } - } - var res = workScheduler.startWork(workInfo); - console.info(`workschedulerLog res: ${res}`); -``` - -## workScheduler.stopWork -stopWork(work: WorkInfo, needCancel?: boolean): boolean - -Instructs the **WorkSchedulerService** to stop the specified task. - -**System capability**: SystemCapability.ResourceSchedule.WorkScheduler - -**Parameters** - -| Name | Type | Mandatory | Description | -| ---------- | --------------------- | ---- | ---------- | -| work | [WorkInfo](#workinfo) | Yes | Task to stop. | -| needCancel | boolean | Yes | Whether to cancel the task.| - -**Return value** - -| Type | Description | -| ------- | ----------------------- | -| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| - -**Example** - -```js - let workInfo = { - workId: 1, - batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW, - isRepeat: false, - isPersisted: true, - bundleName: "com.example.myapplication", - abilityName: "MyExtension", - parameters: { - mykey0: 1, - mykey1: "string value", - mykey2: true, - mykey3: 1.5 - } - } - var res = workScheduler.stopWork(workInfo, false); - console.info(`workschedulerLog res: ${res}`); -``` - -## workScheduler.getWorkStatus -getWorkStatus(workId: number, callback : AsyncCallback\): void - -Obtains the latest task status. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.ResourceSchedule.WorkScheduler - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | ------------------------------------- | ---- | ---------------------------------------- | -| workId | number | Yes | Task ID. | -| callback | AsyncCallback\<[WorkInfo](#workinfo)> | Yes | Callback used to return the result. Returns the task status obtained from the **WorkSchedulerService** if the specified task ID is valid; returns **null** otherwise.| - -**Example** - -```js - workScheduler.getWorkStatus(50, (err, res) => { - if (err) { - console.info(`workschedulerLog getWorkStatus failed, because: ${err.code}`); - } else { - for (let item in res) { - console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`); - } - } - }); -``` - -## workScheduler.getWorkStatus -getWorkStatus(workId: number): Promise\ - -Obtains the latest task status. This API uses a promise to return the result. - -**System capability**: SystemCapability.ResourceSchedule.WorkScheduler - -**Parameters** - -| Name | Type | Mandatory | Description | -| ------ | ------ | ---- | -------- | -| workId | number | Yes | Task ID.| - -**Return value** - -| Type | Description | -| ------------------------------- | ---------------------------------------- | -| Promise\<[WorkInfo](#workinfo)> | Promise used to return the result. Returns the task status obtained from the **WorkSchedulerService** if the specified task ID is valid; returns **null** otherwise.| - -**Example** - -```js - workScheduler.getWorkStatus(50).then((res) => { - for (let item in res) { - console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`); - } - }).catch((err) => { - console.info(`workschedulerLog getWorkStatus failed, because: ${err.code}`); - }) -``` - -## workScheduler.obtainAllWorks -obtainAllWorks(callback : AsyncCallback\): Array\ - -Obtains all tasks associated with this application. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.ResourceSchedule.WorkScheduler - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | -------------------- | ---- | ------------------------------- | -| callback | AsyncCallback\ | Yes | Callback used to return all tasks associated with the current application. | - -**Return value** - -| Type | Description | -| ----------------------------- | --------------- | -| Array\<[WorkInfo](#workinfo)> | All tasks associated with the current application.| - -**Example** - -```js - workScheduler.obtainAllWorks((err, res) =>{ - if (err) { - console.info(`workschedulerLog obtainAllWorks failed, because: ${err.code}`); - } else { - console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`); - } - }); -``` - -## workScheduler.obtainAllWorks -obtainAllWorks(): Promise> - -Obtains all tasks associated with this application. This API uses a promise to return the result. - -**System capability**: SystemCapability.ResourceSchedule.WorkScheduler - -**Return value** - -| Type | Description | -| -------------------------------------- | ------------------------------ | -| Promise> | Promise used to return all tasks associated with the current application. | - -**Example** - -```js - workScheduler.obtainAllWorks().then((res) => { - console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`); - }).catch((err) => { - console.info(`workschedulerLog obtainAllWorks failed, because: ${err.code}`); - }) -``` - -## workScheduler.stopAndClearWorks -stopAndClearWorks(): boolean - -Stops and cancels all tasks associated with the current application. - -**System capability**: SystemCapability.ResourceSchedule.WorkScheduler - -**Example** - -```js - let res = workScheduler.stopAndClearWorks(); - console.info(`workschedulerLog res: ${res}`); -``` - -## workScheduler.isLastWorkTimeOut -isLastWorkTimeOut(workId: number, callback : AsyncCallback\): boolean - -Checks whether the last execution of the specified task timed out. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.ResourceSchedule.WorkScheduler - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | -------------------- | ---- | ---------------------------------------- | -| workId | number | Yes | Task ID. | -| callback | AsyncCallback\ | Yes | Callback used to return the result. Returns **true** if the last execution of the specified task timed out; returns **false** otherwise.| - -**Return value** - -| Type | Description | -| ------- | ---------------------------------------- | -| boolean | Callback used to return the result. Returns **true** if the last execution of the specified task timed out; returns **false** otherwise.| - -**Example** - -```js - workScheduler.isLastWorkTimeOut(500, (err, res) =>{ - if (err) { - console.info(`workschedulerLog isLastWorkTimeOut failed, because: ${err.code}`); - } else { - console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`); - } - }); -``` - -## workScheduler.isLastWorkTimeOut -isLastWorkTimeOut(workId: number): Promise\ - -Checks whether the last execution of the specified task timed out. This API uses a promise to return the result. - -**System capability**: SystemCapability.ResourceSchedule.WorkScheduler - -**Parameters** - -| Name | Type | Mandatory | Description | -| ------ | ------ | ---- | -------- | -| workId | number | Yes | Task ID.| - -**Return value** - -| Type | Description | -| ----------------- | ---------------------------------------- | -| Promise\ | Promise used to return the result. Returns **true** if the last execution of the specified task timed out; returns **false** otherwise.| - -**Example** - -```js - workScheduler.isLastWorkTimeOut(500) - .then(res => { - console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`); - }) - .catch(err => { - console.info(`workschedulerLog isLastWorkTimeOut failed, because: ${err.code}`); - }); -``` - -## WorkInfo -Provides detailed information about the task. For details about the constraints on configuring **WorkInfo**, see [Work Scheduler Overview](../../task-management/work-scheduler-overview.md). - -**System capability**: SystemCapability.ResourceSchedule.WorkScheduler - -| Name | Type | Mandatory | Description | -| --------------- | --------------------------------- | ---- | ---------------- | -| workId | number | Yes | Task ID. | -| bundleName | string | Yes | Name of the Work Scheduler task bundle. | -| abilityName | string | Yes | Name of the component to be notified by a Work Scheduler callback.| -| networkType | [NetworkType](#networktype) | No | Network type. | -| isCharging | boolean | No | Whether the device is charging. | -| chargerType | [ChargingType](#chargingtype) | No | Charging type. | -| batteryLevel | number | No | Battery level. | -| batteryStatus | [BatteryStatus](#batterystatus) | No | Battery status. | -| storageRequest | [StorageRequest](#storagerequest) | No | Storage status. | -| isRepeat | boolean | No | Whether the task is repeated. | -| repeatCycleTime | number | No | Repeat interval. | -| repeatCount | number | No | Number of repeat times. | -| isPersisted | boolean | No | Whether to enable persistent storage for the task. | -| isDeepIdle | boolean | No | Whether the device needs to enter the idle state. | -| idleWaitTime | number | No | Time to wait in the idle state. | -| parameters | {[key: string]: any} | No | Carried parameters. | - -## NetworkType -Enumerates the network types that can trigger the task. - -**System capability**: SystemCapability.ResourceSchedule.WorkScheduler - -| Name | Default Value | Description | -| ---------------------- | ---- | ----------------------- | -| NETWORK_TYPE_ANY | 0 | Any network type. | -| NETWORK_TYPE_MOBILE | 1 | Mobile network. | -| NETWORK_TYPE_WIFI | 2 | Wi-Fi network. | -| NETWORK_TYPE_BLUETOOTH | 3 | Bluetooth network.| -| NETWORK_TYPE_WIFI_P2P | 4 | Wi-Fi P2P network. | -| NETWORK_TYPE_ETHERNET | 5 | Ethernet. | - -## ChargingType -Enumerates the charging types that can trigger the task. - -**System capability**: SystemCapability.ResourceSchedule.WorkScheduler - -| Name | Default Value | Description | -| ------------------------- | ---- | -------------------- | -| CHARGING_PLUGGED_ANY | 0 | Any charging type.| -| CHARGING_PLUGGED_AC | 1 | DC charging. | -| CHARGING_PLUGGED_USB | 2 | USB charging. | -| CHARGING_PLUGGED_WIRELESS | 3 | Wireless charging. | - -## BatteryStatus -Enumerates the battery states that can trigger the task. - -**System capability**: SystemCapability.ResourceSchedule.WorkScheduler - -| Name | Default Value | Description | -| -------------------------- | ---- | -------------------------- | -| BATTERY_STATUS_LOW | 0 | A low battery alert is displayed. | -| BATTERY_STATUS_OKAY | 1 | The battery level is restored from low to normal. | -| BATTERY_STATUS_LOW_OR_OKAY | 2 | The battery level is restored from low to normal, or a low battery alert is displayed.| - -## StorageRequest -Enumerates the storage states that can trigger the task. - -**System capability**: SystemCapability.ResourceSchedule.WorkScheduler - -| Name | Default Value | Description | -| ------------------------- | ---- | ------------------------------ | -| STORAGE_LEVEL_LOW | 0 | The storage space is insufficient. | -| STORAGE_LEVEL_OKAY | 1 | The storage space is restored from insufficient to normal. | -| STORAGE_LEVEL_LOW_OR_OKAY | 2 | The storage space is restored from insufficient to normal, or the storage space is insufficient.| diff --git a/en/application-dev/task-management/workscheduler-extensionability.md b/en/application-dev/task-management/workscheduler-extensionability.md index 9f7547fcb3..f33f3be988 100644 --- a/en/application-dev/task-management/workscheduler-extensionability.md +++ b/en/application-dev/task-management/workscheduler-extensionability.md @@ -44,7 +44,7 @@ To create a WorkScheduler project in DevEco Studio, perform the following steps: Import the module. ```ts - import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility' + import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility'; ``` Implement the lifecycle callbacks for the WorkSchedulerExtensionAbility. @@ -53,27 +53,27 @@ To create a WorkScheduler project in DevEco Studio, perform the following steps: export default class workAbility extends WorkSchedulerExtensionAbility { // Callback invoked when the Work Scheduler task starts. onWorkStart(workInfo) { - console.log(`onWorkStart CommonEvent publish start ${JSON.stringify(workInfo)}`) + console.log(`onWorkStart CommonEvent publish start ${JSON.stringify(workInfo)}`); // Publish an upgrade notification. - let notificationRequest = notification.getNotificationContentBasic('upgrade', upgradeMessage, '') + let notificationRequest = notification.getNotificationContentBasic('upgrade', upgradeMessage, ''); notification.publish(notificationRequest, (err) => { if (err) { - console.log(`onWorkStart notification publish err ${JSON.stringify(err)}`) + console.log(`onWorkStart notification publish err ${JSON.stringify(err)}`); } - console.log(`onWorkStart notification publish success`) - }) + console.log(`onWorkStart notification publish success`); + }); } // Callback invoked when the Work Scheduler task stops. onWorkStop(workInfo) { // Publish an upgrade completion notification. - let notificationRequest = notification.getNotificationContentBasic('upgrade', 'upgrade success', '') + let notificationRequest = notification.getNotificationContentBasic('upgrade', 'upgrade success', ''); notification.publish(notificationRequest, (err) => { if (err) { - console.log(`onWorkStop notification publish err ${JSON.stringify(err)}`) + console.log(`onWorkStop notification publish err ${JSON.stringify(err)}`); } - console.log(`onWorkStop notification publish success`) - }) + console.log(`onWorkStop notification publish success`); + }); } } ``` @@ -82,25 +82,25 @@ To create a WorkScheduler project in DevEco Studio, perform the following steps: Import the module. - ```ts - import { workAbility } from '@ohos/library' - ``` + ```ts + import { workAbility } from '@ohos/library'; + ``` Inherit from **workAbility** and implement the lifecycle callbacks for the WorkSchedulerExtensionAbility. - ```ts + ```ts export default class WorkTest extends workAbility { onWorkStart(workInfo) { - console.log(`onWorkStartTest start ${JSON.stringify(workInfo)}`) - super.onWorkStart(workInfo) + console.log(`onWorkStartTest start ${JSON.stringify(workInfo)}`); + super.onWorkStart(workInfo); } - - onWorkStopTest(workInfo) { - super.onWorkStop(workInfo) - console.log(`onWorkStop value`) + + onWorkStopTest(workInfo) { + super.onWorkStop(workInfo); + console.log(`onWorkStop value`); } } - ``` + ``` ### Implementing Work Scheduler @@ -109,7 +109,7 @@ Inherit from **workAbility** and implement the lifecycle callbacks for the WorkS Import the module. ```ts - import workScheduler from '@ohos.resourceschedule.workScheduler' + import workScheduler from '@ohos.resourceschedule.workScheduler'; ``` Encapsulate the APIs for starting and stopping Work Scheduler tasks. @@ -124,13 +124,13 @@ Inherit from **workAbility** and implement the lifecycle callbacks for the WorkS } // Start the Work Scheduler task. startWork(bundleName: string, abilityName: string) { - this.workInfo.bundleName = bundleName - this.workInfo.abilityName = abilityName + this.workInfo.bundleName = bundleName; + this.workInfo.abilityName = abilityName; try { - workScheduler.startWork(this.workInfo) - console.log(`startWork success`) + workScheduler.startWork(this.workInfo); + console.log(`startWork success`); } catch (error) { - Logger.error(TAG, `startWork startwork failed. code is ${error.code} message is ${error.message}`) + Logger.error(TAG, `startWork startwork failed. code is ${error.code} message is ${error.message}`); prompt.showToast({ message: `${error.message}` }) @@ -139,10 +139,10 @@ Inherit from **workAbility** and implement the lifecycle callbacks for the WorkS // Stop the Work Scheduler task. stopWork(bundleName: string, abilityName: string) { - this.workInfo.bundleName = bundleName - this.workInfo.abilityName = abilityName - workScheduler.stopWork(this.workInfo, false) - console.log(`stopWork`) + this.workInfo.bundleName = bundleName; + this.workInfo.abilityName = abilityName; + workScheduler.stopWork(this.workInfo, false); + console.log(`stopWork`); } } ``` @@ -152,7 +152,7 @@ Inherit from **workAbility** and implement the lifecycle callbacks for the WorkS Import the module. ```ts - import { workAbility } from '@ohos/library' + import { workAbility } from '@ohos/library'; ``` Add the **Upgrade** button, which, when being clicked, will call the API encapsulated in **library** to start the Work Scheduler task. In the API, **bundleName** and **abilityName** are passed in, where the value of **abilityName** is **WorkTest**. @@ -163,7 +163,7 @@ Inherit from **workAbility** and implement the lifecycle callbacks for the WorkS .height(40) .fontSize(30) .onClick(() => { - this.work.startWork('ohos.samples.workscheduler', 'WorkTest') + this.work.startWork('ohos.samples.workscheduler', 'WorkTest'); }) ``` @@ -171,7 +171,7 @@ Inherit from **workAbility** and implement the lifecycle callbacks for the WorkS ```ts aboutToDisappear() { - this.work.stopWork('ohos.samples.workscheduler', 'WorkTest') + this.work.stopWork('ohos.samples.workscheduler', 'WorkTest'); } ``` -- GitLab