diff --git a/en/application-dev/dfx/apprecovery-guidelines.md b/en/application-dev/dfx/apprecovery-guidelines.md index 67176a77ff4cacda15de76a3390275f59f3a6aa4..4a82385816bd7f51ca0dadf85aff9961f84b94ca 100644 --- a/en/application-dev/dfx/apprecovery-guidelines.md +++ b/en/application-dev/dfx/apprecovery-guidelines.md @@ -1,62 +1,87 @@ -# Development of Application Recovery +# Application Recovery Development ## When to Use -During application running, some unexpected behaviors are inevitable. For example, unprocessed exceptions and errors are thrown, and the call or running constraints of the framework are violated. +During application running, some unexpected behaviors are inevitable. For example, unprocessed exceptions and errors are thrown, and the call or running constraints of the recovery framework are violated. -By default, the processes will exit as exception handling. However, if user data is generated during application use, process exits may interrupt user operations and cause data loss. -In this way, application recovery APIs may help you save temporary data, restart an application after it exits, and restore its status and data, which deliver a better user experience. +Process exit is treated as the default exception handling method. However, if user data is generated during application use, process exit may interrupt user operations and cause data loss. +Application recovery helps to restore the application state and save temporary data upon next startup in the case of an abnormal process exit, thus providing more consistent user experience. The application state includes two parts, namely, the page stack of the and the data saved in **onSaveState**. -Currently, the APIs support only the development of an application that adopts the stage model, single process, and single ability. +In API version 9, application recovery is supported only for a single ability of the application developed using the stage model. Application state saving and automatic restart are performed when a JsError occurs. + +In API version 10, application recovery is also supported for multiple abilities of the application developed using the stage model. Application state storage and restore are performed when an AppFreeze occurs. If an application is killed in control mode, the application state will be restored upon next startup. ## Available APIs -The application recovery APIs are provided by the **appRecovery** module, which can be imported via **import**. For details, please refer to [Development Example](#development-example). This document describes behaviors of APIs in API version 9, and the content will update with changes. +The application recovery APIs are provided by the **appRecovery** module, which can be imported via **import**. For details, see [Development Example](#development-example). ### Available APIs -| API | Description | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| enableAppRecovery(restart?: RestartFlag, saveOccasion?: SaveOccasionFlag, saveMode?: SaveModeFlag) : void; | Enables the application recovery function. | -| saveAppState(): boolean; | Saves the ability status of an application. | -| restartApp(): void; | Restarts the current process. If there is saved ability status, it will be passed to the **want** parameter's **wantParam** attribute of the **onCreate** lifecycle callback of the ability.| +| API | Description | +| ------------------------------------------------------------ | ---------------------------------------------------- | +| enableAppRecovery(restart?: RestartFlag, saveOccasion?: SaveOccasionFlag, saveMode?: SaveModeFlag) : void;9+ | Enables application recovery. After this API is called, the first ability that is displayed when the application is started from the initiator can be restored.| +| saveAppState(): boolean;9+ | Saves the state of the ability that supports recovery in the current application.| +| restartApp(): void;9+ | Restarts the current process and starts the ability specified by **setRestartWant**. If no ability is specified, a foreground ability that supports recovery is restarted.| +| saveAppState(context?: UIAbilityContext): boolean;10+ | Saves the ability state specified by **Context**.| +| setRestartWant(want: Want): void;10+ | Sets the abilities to restart when **restartApp** is actively called and **RestartFlag** is not **NO_RESTART**. The abilities must be under the same bundle name and must be a **UiAbility**.| + +No error will be thrown if the preceding APIs are used in the troubleshooting scenario. The following are some notes on API usage: + +**enableAppRecovery**: This API should be called during application initialization. For example, you can call this API in **onCreate** of **AbilityStage**. For details, see [Parameter Description](../reference/apis/js-apis-app-ability-appRecovery.md). + +**saveAppState**: After this API is called, the recovery framework invokes **onSaveState** for all abilities that support recovery in the current process. If you choose to save data in **onSaveState**, the related data and ability page stack are persistently stored in the local cache of the application. To save data of the specified ability, you need to specify the context corresponding to that ability. + +**setRestartWant**: This API specifies the ability to be restarted by **appRecovery**. + +**restartApp**: After this API is called, the recovery framework kills the current process and restarts the ability specified by **setRestartWant**, with **APP_RECOVERY** set as the startup cause. In API version 9 and scenarios where an ability is not specified by **setRestartWant**, the last foreground ability that supports recovery is started. If the no foreground ability supports recovery, the application crashes. If a saved state is available for the restarted ability, the saved state is passed as the **wantParam** attribute in the **want** parameter of the ability's **onCreate** callback. + +### Application State Management +Since API version 10, application recovery is not limited to automatic restart in the case of an exception. Therefore, you need to understand when the application will load the saved state. + +If the last exit of an application is not initiated by a user and a saved state is available for recovery, the startup reason is set to **APP_RECOVERY** when the application is started by the user next time, and the recovery state of the application is cleared. +The application recovery status flag is set when **saveAppState** is actively or passively called. The flag is cleared when the application exits normally or the saved state is consumed. (A normal exit is usually triggered by pressing the back key or clearing recent tasks.) -The APIs are used for troubleshooting and do not return any exception. Therefore, you need to be familiar with when they are used. +![Application recovery status management](./figures/application_recovery_status_management.png) -**enableAppRecovery**: This API should be called during application initialization. For example, you can call this API in **onCreate** of **AbilityStage**. For details, please refer to the [parameter description](../reference/apis/js-apis-app-ability-appRecovery.md). +### Application State Saving and Restore -**saveAppState**: After this API is called, the framework calls back **onSaveState** of the ability. If data saving is agreed to in this method, relevant data and the page stack of the ability are persisted to the local cache of the application. +API version 10 or later supports saving of the application state when an application is suspended. If a JsError occurs, **onSaveState** is called in the main thread. If an AppFreeze occurs, however, the main thread may be suspended, and therefore **onSaveState** is called in a non-main thread. The following figure shows the main service flow. -**restartApp**: After this API is called, the framework kills the current application process and restarts the ability in the foreground, with **APP_RECOVERY** specified as the startup cause. +![Application recovery from the freezing state](./figures/application_recovery_from_freezing.png) -### Framework Fault Management Process +When the application is suspended, the callback is not executed in the JS thread. Therefore, you are advised not to use the imported dynamic Native library or access the **thread_local** object created by the main thread in the code of the **onSaveState** callback. + +### Framework Fault Management Fault management is an important way for applications to deliver a better user experience. The application framework offers three methods for application fault management: fault listening, fault rectification, and fault query. -- Fault listening refers to the process of registering [ErrorObserver](../reference/apis/js-apis-application-errorManager.md#errorobserver) via [errorManager](../reference/apis/js-apis-application-errorManager.md), listening for fault occurrence, and notifying the fault listener. +- Fault listening refers to the process of registering an [ErrorObserver](../reference/apis/js-apis-inner-application-errorObserver.md) via [errorManager](../reference/apis/js-apis-app-ability-errorManager.md), listening for faults, and notifying the listener of the faults. + +- Fault rectification refers to the process of restoring the application state and data through [appRecovery](../reference/apis/js-apis-app-ability-appRecovery.md). -- Fault rectification refers to [appRecovery](../reference/apis/js-apis-app-ability-appRecovery.md) and restarts an application to restore its status previous to a fault. +- Fault query is the process of calling APIs of [faultLogger](../reference/apis/js-apis-faultLogger.md) to obtain the fault information. -- Fault query indicates that [faultLogger](../reference/apis/js-apis-faultLogger.md) obtains the fault information using its query API. +The figure below does not illustrate the time when [faultLogger](../reference/apis/js-apis-faultLogger.md) is called. You can refer to the [LastExitReason](../reference/apis/js-apis-app-ability-abilityConstant.md#abilityconstantlastexitreason) passed during application initialization to determine whether to call [faultLogger](../reference/apis/js-apis-faultLogger.md) to query information about the previous fault. -The figure below does not illustrate the time when [faultLogger](../reference/apis/js-apis-faultLogger.md) is called. You can refer to [LastExitReason](../reference/apis/js-apis-app-ability-abilityConstant.md#abilityconstantlastexitreason) passed during application initialization to determine whether to call [faultLogger](../reference/apis/js-apis-faultLogger.md) to query the information about the last fault. ![Fault rectification process](./figures/fault_rectification.png) -It is recommended that you call [errorManager](../reference/apis/js-apis-application-errorManager.md) to process the exception. After the processing is complete, you can call the status saving API and restart the application. -If you do not register [ErrorObserver](../reference/apis/js-apis-application-errorManager.md#errorobserver) or enable application recovery, the application process will exit according to the default processing logic of the system. Users can restart the application from the home screen. -If you have enabled application recovery, the framework first checks whether a fault allows for ability status saving and whether you have configured ability status saving. If so, [onSaveState](../reference/apis/js-apis-application-ability.md#abilityonsavestate) of [Ability](../reference/apis/js-apis-application-ability.md#ability) is called back. Finally, the application is restarted. +It is recommended that you call [errorManager](../reference/apis/js-apis-app-ability-errorManager.md) to handle the exception. After the processing is complete, you can call the **saveAppState** API and restart the application. + +If you do not register [ErrorObserver](../reference/apis/js-apis-inner-application-errorObserver.md) or enable application recovery, the application process will exit according to the default processing logic of the system. Users can restart the application from the home screen. + +If you have enabled application recovery, the recovery framework first checks whether application state saving is supported and whether the application state saving is enabled. If so, the recovery framework invokes [onSaveState](../reference/apis/js-apis-app-ability-uiAbility.md#uiabilityonsavestate) of the [Ability](../reference/apis/js-apis-app-ability-uiAbility.md). Finally, the application is restarted. -### Scenarios Supported by Application Fault Management APIs +### Supported Application Recovery Scenarios Common fault types include JavaScript application crash, application freezing, and C++ application crash. Generally, an application is closed when a crash occurs. Application freezing occurs when the application does not respond. The fault type can be ignored for the upper layer of an application. The recovery framework implements fault management in different scenarios based on the fault type. -| Fault | Fault Listening| Status Saving| Automatic Restart| Log Query| -| ------------------------------------------------------------ | -------- | -------- | -------- | -------- | -| [JS_CRASH](../reference/apis/js-apis-faultLogger.md#faulttype) | Supported | Supported | Supported | Supported | -| [APP_FREEZE](../reference/apis/js-apis-faultLogger.md#faulttype) | Not supported | Not supported | Supported | Supported | -| [CPP_CRASH](../reference/apis/js-apis-faultLogger.md#faulttype) | Not supported | Not supported | Not supported | Supported | +| Fault | Fault Listening | State Saving| Automatic Restart| Log Query| +| ----------|--------- |--------- |--------- |--------- | +| [JS_CRASH](../reference/apis/js-apis-faultLogger.md#faulttype) | Supported|Supported|Supported|Supported| +| [APP_FREEZE](../reference/apis/js-apis-faultLogger.md#faulttype) | Not supported|Supported|Supported|Supported| +| [CPP_CRASH](../reference/apis/js-apis-faultLogger.md#faulttype) | Not supported|Not supported|Not supported|Supported| -**Status Saving** in the table header means status saving when a fault occurs. To protect user data as much as possible in the application freezing fault, you can adopt either the periodic or automatic way, and the latter will save user data when an ability is switched to the background. +**State Saving** in the table header means saving of the application state when a fault occurs. To protect user data as much as possible when an AppFreeze occurs, you can adopt either the periodic or automatic way, and the latter will save user data when an ability is switched to the background. @@ -78,11 +103,23 @@ export default class MyAbilityStage extends AbilityStage { appRecovery.SaveModeFlag.SAVE_WITH_FILE); } } +``` +### Enabling Application Recovery for the Specified Abilities +Generally, the ability configuration list is named **module.json5**. +```json +{ + "abilities": [ + { + "name": "EntryAbility", + "recoverable": true, + }] +} + ``` ### Saving and Restoring Data -After enabling **appRecovery**, you can use this function by either actively or passively saving the status and restoring data in the ability. +After enabling **appRecovery**, you can use this function by either actively or passively saving the application state and restoring data in the ability. The following is an example of **EntryAbility**: #### Importing the Service Package @@ -93,9 +130,9 @@ import appRecovery from '@ohos.app.ability.appRecovery'; import AbilityConstant from '@ohos.app.ability.AbilityConstant'; ``` -#### Actively Saving Status and Restoring Data +#### Actively Saving the Application State and Restoring Data -- Define and register the [ErrorObserver](../reference/apis/js-apis-application-errorManager.md#errorobserver) callback. +- Define and register the [ErrorObserver](../reference/apis/js-apis-inner-application-errorObserver.md) callback. ```ts var registerId = -1; @@ -108,7 +145,7 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant'; } onWindowStageCreate(windowStage) { - // Main window is created. Set a main page for this ability. + // Main window is created, set main page for this ability console.log("[Demo] EntryAbility onWindowStageCreate") globalThis.registerObserver = (() => { @@ -125,7 +162,7 @@ After the callback triggers **appRecovery.saveAppState()**, **onSaveState(state, ```ts onSaveState(state, wantParams) { - // Save application data. + // Ability has called to save app data console.log("[Demo] EntryAbility onSaveState") wantParams["myData"] = "my1234567"; return AbilityConstant.onSaveResult.ALL_AGREE; @@ -134,7 +171,7 @@ After the callback triggers **appRecovery.saveAppState()**, **onSaveState(state, - Restore data. -After the callback triggers **appRecovery.restartApp()**, the application is restarted. After the restart, **onCreate(want, launchParam)** of **EntryAbility** is called, and the saved data is in **parameters** of **want**. +After the callback triggers **appRecovery.restartApp()**, the application is restarted. After the restart, **onCreate(want, launchParam)** of **EntryAbility** is called, and the saved data is stored in **parameters** of **want**. ```ts storage: LocalStorage @@ -150,11 +187,11 @@ onCreate(want, launchParam) { } ``` -- Deregister **ErrorObserver callback**. +- Unregister the **ErrorObserver** callback. ```ts onWindowStageDestroy() { - // Main window is destroyed to release UI resources. + // Main window is destroyed, release UI related resources console.log("[Demo] EntryAbility onWindowStageDestroy") globalThis.unRegisterObserver = (() => { @@ -165,9 +202,9 @@ onWindowStageDestroy() { } ``` -#### Passively Saving Status and Restoring Data +#### Passively Saving the Application State and Restoring Data -This is triggered by the recovery framework. You do not need to register **ErrorObserver callback**. You only need to implement **onSaveState** of the ability for status saving and **onCreate** of the ability for data restoration. +This is triggered by the recovery framework. You do not need to register an **ErrorObserver** callback. You only need to implement **onSaveState** for application state saving and **onCreate** for data restore. ```ts export default class EntryAbility extends Ability { @@ -184,7 +221,7 @@ export default class EntryAbility extends Ability { } onSaveState(state, wantParams) { - // Save application data. + // Ability has called to save app data console.log("[Demo] EntryAbility onSaveState") wantParams["myData"] = "my1234567"; return AbilityConstant.onSaveResult.ALL_AGREE; diff --git a/en/application-dev/dfx/figures/application_recovery_from_freezing.png b/en/application-dev/dfx/figures/application_recovery_from_freezing.png new file mode 100644 index 0000000000000000000000000000000000000000..968b4cefc5e898209cdae117c7f9f667bc9fbd64 Binary files /dev/null and b/en/application-dev/dfx/figures/application_recovery_from_freezing.png differ diff --git a/en/application-dev/dfx/figures/application_recovery_status_management.png b/en/application-dev/dfx/figures/application_recovery_status_management.png new file mode 100644 index 0000000000000000000000000000000000000000..762504c1d1027be87233e589988be2091640191b Binary files /dev/null and b/en/application-dev/dfx/figures/application_recovery_status_management.png differ diff --git a/en/application-dev/dfx/figures/fault_rectification.png b/en/application-dev/dfx/figures/fault_rectification.png index 67aa40592f7bcad23e216222e898c1f1327a4efb..e5831ac2b5aefc33a955ad98cd76f41ad28a7f70 100644 Binary files a/en/application-dev/dfx/figures/fault_rectification.png and b/en/application-dev/dfx/figures/fault_rectification.png differ diff --git a/en/application-dev/reference/apis/js-apis-call.md b/en/application-dev/reference/apis/js-apis-call.md index b6b2bddb6306e577053b5ea9e34c21acf23c9477..068a12cd46efce13b68a4fcf697306c4b5d8f256 100644 --- a/en/application-dev/reference/apis/js-apis-call.md +++ b/en/application-dev/reference/apis/js-apis-call.md @@ -14,110 +14,6 @@ To subscribe to the call status, use [`observer.on('callStateChange')`](js-apis- import call from '@ohos.telephony.call'; ``` -## call.dial(deprecated) - -dial\(phoneNumber: string, callback: AsyncCallback\): void - -Initiates a call. This API uses an asynchronous callback to return the result. - ->**NOTE** -> ->This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [dialCall](#calldialcall9). - -**Required Permissions**: ohos.permission.PLACE_CALL - -**System capability**: SystemCapability.Telephony.CallManager - -**Parameters** - -| Name | Type | Mandatory| Description | -| ----------- | ---------------------------- | ---- | --------------------------------------- | -| phoneNumber | string | Yes | Phone number. | -| callback | AsyncCallback<boolean> | Yes | Callback used to return the result.
- **true**: success
- **false**: failure| - -**Example** - -```js -call.dial("138xxxxxxxx", (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); -}); -``` - - -## call.dial(deprecated) - -dial\(phoneNumber: string, options: DialOptions, callback: AsyncCallback\): void - -Initiates a call. You can set call options as needed. This API uses an asynchronous callback to return the result. - ->**NOTE** -> ->This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [dialCall](#calldialcall9). - -**Required Permissions**: ohos.permission.PLACE_CALL - -**System capability**: SystemCapability.Telephony.CallManager - -**Parameters** - -| Name | Type | Mandatory| Description | -| ----------- | ---------------------------- | ---- | --------------------------------------- | -| phoneNumber | string | Yes | Phone number. | -| options | [DialOptions](#dialoptions) | Yes | Call option, which indicates whether the call is a voice call or video call. | -| callback | AsyncCallback<boolean> | Yes | Callback used to return the result.
- **true**: success
- **false**: failure| - -**Example** - -```js -call.dial("138xxxxxxxx", { - extras: false -}, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); -}); -``` - - -## call.dial(deprecated) - -dial\(phoneNumber: string, options?: DialOptions\): Promise - -Initiates a call. You can set call options as needed. This API uses a promise to return the result. - ->**NOTE** -> ->This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [dialCall](#calldialcall9). - -**Required Permissions**: ohos.permission.PLACE_CALL - -**System capability**: SystemCapability.Telephony.CallManager - -**Parameters** - -| Name | Type | Mandatory| Description | -| ----------- | --------------------------- | ---- | -------------------------------------- | -| phoneNumber | string | Yes | Phone number. | -| options | [DialOptions](#dialoptions) | No | Call option, which indicates whether the call is a voice call or video call.| - -**Return value** - -| Type | Description | -| ---------------------- | ------------------------------------------------------------ | -| Promise<boolean> | Promise used to return the result.
- **true**: success
- **false**: failure| - -**Example** - -```js -let promise = call.dial("138xxxxxxxx", { - extras: false -}); -promise.then(data => { - console.log(`dial success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { - console.error(`dial fail, promise: err->${JSON.stringify(err)}`); -}); -``` - - ## call.dialCall9+ dialCall\(phoneNumber: string, callback: AsyncCallback\): void @@ -260,6 +156,107 @@ promise.then(() => { }); ``` +## call.dial(deprecated) + +dial\(phoneNumber: string, callback: AsyncCallback\): void + +Initiates a call. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [dialCall](#calldialcall9). The substitute API is available only for system applications. + +**Required Permissions**: ohos.permission.PLACE_CALL + +**System capability**: SystemCapability.Telephony.CallManager + +**Parameters** + +| Name | Type | Mandatory| Description | +| ----------- | ---------------------------- | ---- | --------------------------------------- | +| phoneNumber | string | Yes | Phone number. | +| callback | AsyncCallback<boolean> | Yes | Callback used to return the result.
- **true**: success
- **false**: failure| + +**Example** + +```js +call.dial("138xxxxxxxx", (err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +}); +``` + + +## call.dial(deprecated) + +dial\(phoneNumber: string, options: DialOptions, callback: AsyncCallback\): void + +Initiates a call. You can set call options as needed. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [dialCall](#calldialcall9). The substitute API is available only for system applications. + +**Required Permissions**: ohos.permission.PLACE_CALL + +**System capability**: SystemCapability.Telephony.CallManager + +**Parameters** + +| Name | Type | Mandatory| Description | +| ----------- | ---------------------------- | ---- | --------------------------------------- | +| phoneNumber | string | Yes | Phone number. | +| options | [DialOptions](#dialoptions) | Yes | Call option, which indicates whether the call is a voice call or video call. | +| callback | AsyncCallback<boolean> | Yes | Callback used to return the result.
- **true**: success
- **false**: failure| + +**Example** + +```js +call.dial("138xxxxxxxx", { + extras: false +}, (err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +}); +``` + +## call.dial(deprecated) + +dial\(phoneNumber: string, options?: DialOptions\): Promise + +Initiates a call. You can set call options as needed. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [dialCall](#calldialcall9). The substitute API is available only for system applications. + +**Required Permissions**: ohos.permission.PLACE_CALL + +**System capability**: SystemCapability.Telephony.CallManager + +**Parameters** + +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | -------------------------------------- | +| phoneNumber | string | Yes | Phone number. | +| options | [DialOptions](#dialoptions) | No | Call option, which indicates whether the call is a voice call or video call.| + +**Return value** + +| Type | Description | +| ---------------------- | ------------------------------------------------------------ | +| Promise<boolean> | Promise used to return the result.
- **true**: success
- **false**: failure| + +**Example** + +```js +let promise = call.dial("138xxxxxxxx", { + extras: false +}); +promise.then(data => { + console.log(`dial success, promise: data->${JSON.stringify(data)}`); +}).catch(err => { + console.error(`dial fail, promise: err->${JSON.stringify(err)}`); +}); +``` ## call.makeCall7+ @@ -2387,7 +2384,7 @@ Subscribes to **callDetailsChange** events. This API uses an asynchronous callba | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------- | ---- | -------------------------- | -| type | string | Yes | Event type. This field has a fixed value of **callDetailsChange**.| +| type | string | Yes | Call event change. This field has a fixed value of **callDetailsChange**.| | callback | Callback<[CallAttributeOptions](#callattributeoptions7)> | Yes | Callback used to return the result. | **Error codes** @@ -2427,7 +2424,7 @@ Subscribes to **callEventChange** events. This API uses an asynchronous callback | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------ | ---- | -------------------------- | -| type | string | Yes | This interface is used to monitor the change of call events during a call. The parameter has a fixed value of callEventChange.| +| type | string | Yes | Call event change. This field has a fixed value of **callEventChange**.| | callback | Callback<[CallEventOptions](#calleventoptions8)> | Yes | Callback used to return the result. | **Error codes** @@ -2467,7 +2464,7 @@ Subscribes to **callDisconnectedCause** events. This API uses an asynchronous ca | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------ | ---- | -------------------------- | -| type | string | Yes | Event type. The field has a fixed value of **callDisconnectedCause**.| +| type | string | Yes | Call disconnection cause. This field has a fixed value of **callDisconnectedCause**.| | callback | Callback<[DisconnectedDetails](#disconnecteddetails9)> | Yes | Callback used to return the result. | **Error codes** @@ -2507,7 +2504,7 @@ Subscribes to **mmiCodeResult** events. This API uses an asynchronous callback t | Name | Type | Mandatory| Description | | -------- | -------------------------------------------- | ---- | --------------------- | -| type | string | Yes | Event type. The field has a fixed value of **mmiCodeResult**.| +| type | string | Yes | MMI code result. This field has a fixed value of **mmiCodeResult**.| | callback | Callback<[MmiCodeResults](#mmicoderesults9)> | Yes | Callback used to return the result. | **Error codes** @@ -2547,7 +2544,7 @@ Unsubscribes from **callDetailsChange** events. This API uses an asynchronous ca | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------------- | ---- | ---------------------------------- | -| type | string | Yes | Event type. The field has a fixed value of **callDetailsChange**.| +| type | string | Yes | Call details change. This field has a fixed value of **callDetailsChange**.| | callback | Callback<[CallAttributeOptions](#callattributeoptions7)> | No | Callback used to return the result. | **Error codes** @@ -2587,7 +2584,7 @@ Unsubscribes from **callEventChange** events. This API uses an asynchronous call | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------ | ---- | ---------------------------------- | -| type | string | Yes | Event type. The field has a fixed value of **callEventChange**.| +| type | string | Yes | Call event change. This field has a fixed value of **callEventChange**.| | callback | Callback<[CallEventOptions](#calleventoptions8)> | No | Callback used to return the result. | **Error codes** @@ -2627,7 +2624,7 @@ Unsubscribes from **callDisconnectedCause** events. This API uses an asynchronou | Name | Type | Mandatory| Description | | -------- | ---------------------------------------------------------- | ---- | ------------------- | -| type | string | Yes | Event type. The field has a fixed value of **callDisconnectedCause**.| +| type | string | Yes | Call disconnection cause. This field has a fixed value of **callDisconnectedCause**.| | callback | Callback<[DisconnectedDetails](#disconnecteddetails9)> | No | Callback used to return the result. | **Error codes** @@ -2667,7 +2664,7 @@ Unsubscribes from **mmiCodeResult** events. This API uses an asynchronous callba | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------ | ---- | ----------- | -| type | string | Yes | Event type. The field has a fixed value of **mmiCodeResult**.| +| type | string | Yes | MMI code result. This field has a fixed value of **mmiCodeResult**.| | callback | Callback<[MmiCodeResults](#mmicoderesults9)> | No | Callback used to return the result. | **Error codes** diff --git a/en/application-dev/reference/apis/js-apis-hichecker.md b/en/application-dev/reference/apis/js-apis-hichecker.md index 4d6d81f15430a456eb60f54e1b650df5ef112dbe..35c86ccd1c0143dea06b5f1a24634b6cc09a2187 100644 --- a/en/application-dev/reference/apis/js-apis-hichecker.md +++ b/en/application-dev/reference/apis/js-apis-hichecker.md @@ -122,7 +122,9 @@ try { addRule(rule: bigint): void -> **NOTE**
This API is deprecated since API version 9. You are advised to use [hichecker.addCheckRule](#hicheckeraddcheckrule9) instead. +> **NOTE** +> +> This API is deprecated since API version 9. You are advised to use [hichecker.addCheckRule](#hicheckeraddcheckrule9). Adds one or more rules. HiChecker detects unexpected operations or gives feedback based on the added rules. @@ -149,7 +151,9 @@ hichecker.addRule( removeRule(rule: bigint): void -> **NOTE**
This API is deprecated since API version 9. You are advised to use [hichecker.removeCheckRule](#hicheckerremovecheckrule9) instead. +> **NOTE** +> +> This API is deprecated since API version 9. You are advised to use [hichecker.removeCheckRule](#hicheckerremovecheckrule9). Removes one or more rules. The removed rules will become ineffective. @@ -200,7 +204,9 @@ hichecker.getRule(); // return 1n; contains(rule: bigint): boolean -> **NOTE**
This API is deprecated since API version 9. You are advised to use [hichecker.containsCheckRule](#hicheckercontainscheckrule9) instead. +> **NOTE** +> +> This API is deprecated since API version 9. You are advised to use [hichecker.containsCheckRule](#hicheckercontainscheckrule9). Checks whether the specified rule exists in the collection of added rules. If the rule is of the thread level, this operation is performed only on the current thread. diff --git a/en/application-dev/reference/apis/js-apis-hidebug.md b/en/application-dev/reference/apis/js-apis-hidebug.md index 364938ddfa2864850a1335cb886f41e3de2c1a9c..186b2dc92d8bf4fd2693f06b5b6e062bb9a7fc29 100644 --- a/en/application-dev/reference/apis/js-apis-hidebug.md +++ b/en/application-dev/reference/apis/js-apis-hidebug.md @@ -1,10 +1,10 @@ # @ohos.hidebug (HiDebug) -The **hidebug** module provides APIs for you to obtain the memory usage of an application, including the static heap memory (native heap) and proportional set size (PSS) occupied by the application process. You can also export VM memory slices and collect VM CPU profiling data. - -> **NOTE**
+> **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 **hidebug** module provides APIs for you to obtain the memory usage of an application, including the static heap memory (native heap) and proportional set size (PSS) occupied by the application process. You can also export VM memory slices and collect VM CPU profiling data. ## Modules to Import @@ -19,31 +19,25 @@ getNativeHeapSize(): bigint Obtains the total heap memory size of this application. -This API is defined but not implemented in OpenHarmony 3.1 Release. - **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Return value** -| Type | Description | +| Type | Description | | ------ | --------------------------- | | bigint | Total heap memory size of the application, in KB.| - **Example** ```js let nativeHeapSize = hidebug.getNativeHeapSize(); ``` - ## hidebug.getNativeHeapAllocatedSize getNativeHeapAllocatedSize(): bigint Obtains the allocated heap memory size of this application. -This API is defined but not implemented in OpenHarmony 3.1 Release. - **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Return value** @@ -58,15 +52,12 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. let nativeHeapAllocatedSize = hidebug.getNativeHeapAllocatedSize(); ``` - ## hidebug.getNativeHeapFreeSize getNativeHeapFreeSize(): bigint Obtains the free heap memory size of this application. -This API is defined but not implemented in OpenHarmony 3.1 Release. - **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Return value** @@ -80,7 +71,6 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. let nativeHeapFreeSize = hidebug.getNativeHeapFreeSize(); ``` - ## hidebug.getPss getPss(): bigint @@ -100,7 +90,6 @@ Obtains the size of the physical memory actually used by the application process let pss = hidebug.getPss(); ``` - ## hidebug.getSharedDirty getSharedDirty(): bigint @@ -135,7 +124,6 @@ Obtains the size of the private dirty memory of a process. | ------ | -------------------------- | | bigint | Size of the private dirty memory of the process, in KB.| - **Example** ```js let privateDirty = hidebug.getPrivateDirty(); @@ -163,76 +151,6 @@ For example, if the CPU usage is **50%**, **0.5** is returned. let cpuUsage = hidebug.getCpuUsage(); ``` -## hidebug.startProfiling(deprecated) - -startProfiling(filename : string) : void - -> **NOTE**
This API is deprecated since API version 9. You are advised to use [hidebug.startJsCpuProfiling](#hidebugstartjscpuprofiling9) instead. - -Starts the profiling method. `startProfiling()` and `stopProfiling()` are called in pairs. `startProfiling()` always occurs before `stopProfiling()`; that is, calling the functions in the sequence similar to the following is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`. - -**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------ | ---- | ------------------------------------------------------------ | -| filename | string | Yes | User-defined profile name. The `filename.json` file is generated in the `files` directory of the application based on the specified `filename`.| - -**Example** - -```js -hidebug.startProfiling("cpuprofiler-20220216"); -// code block -// ... -// code block -hidebug.stopProfiling(); -``` - - - -## hidebug.stopProfiling(deprecated) - -stopProfiling() : void - -> **NOTE**
This API is deprecated since API version 9. You are advised to use [hidebug.stopJsCpuProfiling](#hidebugstopjscpuprofiling9) instead. - -Stops the profiling method. `startProfiling()` and `stopProfiling()` are called in pairs. `startProfiling()` always occurs before `stopProfiling()`; that is, calling the functions in the sequence similar to the following is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`. - -**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug - -**Example** - -```js -hidebug.startProfiling("cpuprofiler-20220216"); -// code block -// ... -// code block -hidebug.stopProfiling(); -``` - -## hidebug.dumpHeapData(deprecated) - -dumpHeapData(filename : string) : void - -> **NOTE**
This API is deprecated since API version 9. You are advised to use [hidebug.dumpJsHeapData](#hidebugdumpjsheapdata9) instead. - -Exports the heap data. - -**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------ | ---- | ------------------------------------------------------------ | -| filename | string | Yes | User-defined heap file name. The `filename.heapsnapshot` file is generated in the `files` directory of the application based on the specified `filename`.| - -**Example** - -```js -hidebug.dumpHeapData("heap-20220216"); -``` - ## hidebug.getServiceDump9+ getServiceDump(serviceid : number, fd : number, args : Array\) : void @@ -360,3 +278,71 @@ try { console.info(error.message) } ``` + +## hidebug.startProfiling(deprecated) + +startProfiling(filename : string) : void + +> **NOTE**
This API is deprecated since API version 9. You are advised to use [hidebug.startJsCpuProfiling](#hidebugstartjscpuprofiling9) instead. + +Starts the profiling method. `startProfiling()` and `stopProfiling()` are called in pairs. `startProfiling()` always occurs before `stopProfiling()`; that is, calling the functions in the sequence similar to the following is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`. + +**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------ | ---- | ------------------------------------------------------------ | +| filename | string | Yes | User-defined profile name. The `filename.json` file is generated in the `files` directory of the application based on the specified `filename`.| + +**Example** + +```js +hidebug.startProfiling("cpuprofiler-20220216"); +// code block +// ... +// code block +hidebug.stopProfiling(); +``` + +## hidebug.stopProfiling(deprecated) + +stopProfiling() : void + +> **NOTE**
This API is deprecated since API version 9. You are advised to use [hidebug.stopJsCpuProfiling](#hidebugstopjscpuprofiling9) instead. + +Stops the profiling method. `startProfiling()` and `stopProfiling()` are called in pairs. `startProfiling()` always occurs before `stopProfiling()`; that is, calling the functions in the sequence similar to the following is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`. + +**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug + +**Example** + +```js +hidebug.startProfiling("cpuprofiler-20220216"); +// code block +// ... +// code block +hidebug.stopProfiling(); +``` + +## hidebug.dumpHeapData(deprecated) + +dumpHeapData(filename : string) : void + +> **NOTE**
This API is deprecated since API version 9. You are advised to use [hidebug.dumpJsHeapData](#hidebugdumpjsheapdata9) instead. + +Exports the heap data. + +**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------ | ---- | ------------------------------------------------------------ | +| filename | string | Yes | User-defined heap file name. The `filename.heapsnapshot` file is generated in the `files` directory of the application based on the specified `filename`.| + +**Example** + +```js +hidebug.dumpHeapData("heap-20220216"); +``` diff --git a/en/application-dev/reference/apis/js-apis-http.md b/en/application-dev/reference/apis/js-apis-http.md index fe4334e73571db595b352db308991a6fa816fd45..e884f1f348b6754b4f8c8703220a1dcd8a4eb19d 100644 --- a/en/application-dev/reference/apis/js-apis-http.md +++ b/en/application-dev/reference/apis/js-apis-http.md @@ -16,7 +16,7 @@ import http from '@ohos.net.http'; ## Examples ```js -// Import the http namespace. +// Import the HTTP namespace. import http from '@ohos.net.http'; // Each httpRequest corresponds to an HTTP request task and cannot be reused. @@ -112,7 +112,7 @@ Initiates an HTTP request to a given URL. This API uses an asynchronous callback **Error codes** -| Code | Error Message | +| ID | Error Message | |---------|-------------------------------------------------------| | 401 | Parameter error. | | 201 | Permission denied. | @@ -164,7 +164,7 @@ Initiates an HTTP request containing specified options to a given URL. This API **Error codes** -| Code | Error Message | +| ID | Error Message | |---------|-------------------------------------------------------| | 401 | Parameter error. | | 201 | Permission denied. | @@ -255,7 +255,7 @@ Initiates an HTTP request containing specified options to a given URL. This API **Error codes** -| Code | Error Message | +| ID | Error Message | |---------|-------------------------------------------------------| | 401 | Parameter error. | | 201 | Permission denied. | @@ -349,7 +349,7 @@ Initiates an HTTP request to a given URL. This API uses an asynchronous callback **Error codes** -| Code | Error Message | +| ID | Error Message | |---------|-------------------------------------------------------| | 401 | Parameter error. | | 201 | Permission denied. | @@ -395,7 +395,7 @@ Initiates an HTTP request to a given URL. This API uses an asynchronous callback **Error codes** -| Code | Error Message | +| ID | Error Message | |---------|-------------------------------------------------------| | 401 | Parameter error. | | 201 | Permission denied. | @@ -477,7 +477,7 @@ Initiates an HTTP request containing specified options to a given URL. This API **Error codes** -| Code | Error Message | +| ID | Error Message | |---------|-------------------------------------------------------| | 401 | Parameter error. | | 201 | Permission denied. | @@ -513,7 +513,7 @@ Initiates an HTTP request containing specified options to a given URL. This API >**NOTE** > For details about the error codes, see [HTTP Error Codes](../errorcodes/errorcode-net-http.md). -> The HTTP error code mapping is in the format of 2300000 + Curl error code. For more common error codes, see [Curl Error Codes](https://curl.se/libcurl/c/libcurl-errors.html). +> The HTTP error code mapping is in the format of 2300000 + Curl error code. For more common error codes, see: **Example** @@ -839,7 +839,7 @@ Enumerates the response codes for an HTTP request. | Name | Value | Description | | ----------------- | ---- | ------------------------------------------------------------ | -| OK | 200 | The request is successful. The request has been processed successfully. This return code is generally used for GET and POST requests. | +| OK | 200 | "OK." The request has been processed successfully. This return code is generally used for GET and POST requests. | | CREATED | 201 | "Created." The request has been successfully sent and a new resource is created. | | ACCEPTED | 202 | "Accepted." The request has been accepted, but the processing has not been completed. | | NOT_AUTHORITATIVE | 203 | "Non-Authoritative Information." The request is successful. | diff --git a/en/application-dev/reference/apis/js-apis-net-connection.md b/en/application-dev/reference/apis/js-apis-net-connection.md index adb1c8ee47ae8dc076f5b2c2f00b2c2ca92a2cd5..f5c48ddd07342118d752a82a00972aec398685ea 100644 --- a/en/application-dev/reference/apis/js-apis-net-connection.md +++ b/en/application-dev/reference/apis/js-apis-net-connection.md @@ -294,8 +294,8 @@ let httpProxy = { port: 8080, exclusionList: exclusionArray } -connection.setGlobalHttpProxy(httpProxy).then((error, data) => { - console.info(JSON.stringify(data)); +connection.setGlobalHttpProxy(httpProxy).then(() => { + console.info("success"); }).catch(error=>{ console.info(JSON.stringify(error)); }) @@ -436,8 +436,8 @@ Binds an application to the specified network, so that the application can acces ```js connection.getDefaultNet().then(function (netHandle) { - connection.setAppNet(netHandle).then((error, data) => { - console.log(JSON.stringify(data)) + connection.setAppNet(netHandle).then(() => { + console.log("success") }).catch(error => { console.log(JSON.stringify(error)) }) @@ -1097,7 +1097,7 @@ getAddressesByName(host: string, callback: AsyncCallback\>): Resolves the host name by using the default network to obtain all IP addresses. This API uses an asynchronous callback to return the result. -**Required permission**: ohos.permission.GET_NETWORK_INFO +**Required permissions**: ohos.permission.INTERNET **System capability**: SystemCapability.Communication.NetManager.Core @@ -1134,7 +1134,7 @@ getAddressesByName(host: string): Promise\> Resolves the host name by using the default network to obtain all IP addresses. This API uses a promise to return the result. -**Required permission**: ohos.permission.GET_NETWORK_INFO +**Required permissions**: ohos.permission.INTERNET **System capability**: SystemCapability.Communication.NetManager.Core @@ -1639,7 +1639,7 @@ getAddressesByName(host: string, callback: AsyncCallback\>): Resolves the host name by using the corresponding network to obtain all IP addresses. This API uses an asynchronous callback to return the result. -**Required permission**: ohos.permission.GET_NETWORK_INFO +**Required permissions**: ohos.permission.INTERNET **System capability**: SystemCapability.Communication.NetManager.Core @@ -1678,7 +1678,7 @@ getAddressesByName(host: string): Promise\> Resolves the host name by using the corresponding network to obtain all IP addresses. This API uses a promise to return the result. -**Required permission**: ohos.permission.GET_NETWORK_INFO +**Required permissions**: ohos.permission.INTERNET **System capability**: SystemCapability.Communication.NetManager.Core @@ -1721,7 +1721,7 @@ getAddressByName(host: string, callback: AsyncCallback\): void Resolves the host name by using the corresponding network to obtain the first IP address. This API uses an asynchronous callback to return the result. -**Required permission**: ohos.permission.GET_NETWORK_INFO +**Required permissions**: ohos.permission.INTERNET **System capability**: SystemCapability.Communication.NetManager.Core @@ -1760,7 +1760,7 @@ getAddressByName(host: string): Promise\ Resolves the host name by using the corresponding network to obtain the first IP address. This API uses a promise to return the result. -**Required permission**: ohos.permission.GET_NETWORK_INFO +**Required permissions**: ohos.permission.INTERNET **System capability**: SystemCapability.Communication.NetManager.Core diff --git a/en/application-dev/reference/apis/js-apis-observer.md b/en/application-dev/reference/apis/js-apis-observer.md index 3c46e47479de6cacc6a0a2613f0aa422aad9aff8..b0e30e22190f5242d16e4be0b815bcf4c4109f30 100644 --- a/en/application-dev/reference/apis/js-apis-observer.md +++ b/en/application-dev/reference/apis/js-apis-observer.md @@ -25,13 +25,15 @@ Registers an observer for network status change events. This API uses an asynchr **Parameters** -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Network status change event. | +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------------------- | ---- | ---------------------------------------------------------------- | +| type | string | Yes | Network status change event. This field has a fixed value of **networkStateChange**. | | callback | Callback\<[NetworkState](js-apis-radio.md#networkstate)\> | Yes | Callback used to return the result. For details, see [NetworkState](js-apis-radio.md#networkstate).| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -62,14 +64,16 @@ Registers an observer for network status change events of the SIM card in the sp **Parameters** -| Name| Type | Mandatory| Description | -| ------ | ------ | ---- | -------------------------------------- | -| type | string | Yes | Network status change event. | -| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2| +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------------------- | ---- | ---------------------------------------------------------------- | +| type | string | Yes | Network status change event. This field has a fixed value of **networkStateChange**. | +| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2 | | callback | Callback\<[NetworkState](js-apis-radio.md#networkstate)\> | Yes | Callback used to return the result. For details, see [NetworkState](js-apis-radio.md#networkstate).| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -104,7 +108,7 @@ Unregisters the observer for network status change events. This API uses an asyn | Name | Type | Mandatory| Description | | -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Network status change event. | +| type | string | Yes | Network status change event. This field has a fixed value of **networkStateChange**. | | callback | Callback\<[NetworkState](js-apis-radio.md#networkstate)\> | No | Callback used to return the result. For details, see [NetworkState](js-apis-radio.md#networkstate).| | ID| Error Message | @@ -138,12 +142,14 @@ Registers an observer for signal status change events. This API uses an asynchro **Parameters** | Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Signal information change event. | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | +| type | string | Yes | Signal status change event. This field has a fixed value of **signalInfoChange**. | | callback | Callback\> | Yes | Callback used to return the result. For details, see [SignalInformation](js-apis-radio.md#signalinformation).| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -172,14 +178,16 @@ Registers an observer for signal status change events of the SIM card in the spe **Parameters** -| Name| Type | Mandatory| Description | -| ------ | ------ | ---- | -------------------------------------- | -| type | string | Yes | Signal information change event. | -| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | +| type | string | Yes | Signal status change event. This field has a fixed value of **signalInfoChange**. | +| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2 | | callback | Callback\> | Yes | Callback used to return the result. For details, see [SignalInformation](js-apis-radio.md#signalinformation).| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -214,11 +222,13 @@ Unregisters the observer for signal status change events. This API uses an async | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Signal information change event. | +| type | string | Yes | Signal status change event. This field has a fixed value of **signalInfoChange**. | | callback | Callback\> | No | Callback used to return the result. For details, see [SignalInformation](js-apis-radio.md#signalinformation).| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -255,7 +265,7 @@ Registers an observer for cell information change events. This API uses an async | Name | Type | Mandatory| Description | | -------- | --------------------------------------------------------- | ---- |------------------------------------------------------------| -| type | string | Yes | Cell information change event. This field has a fixed value of **cellInfoChange**. | +| type | string | Yes | Cell information change event. This field has a fixed value of **cellInfoChange**. | | callback | Callback\<[CellInformation](js-apis-radio.md#cellinformation8)\> | Yes | Callback used to return the result.| **Error codes** @@ -370,12 +380,14 @@ Registers an observer for call status change events. This API uses an asynchrono **Parameters** | Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Call status change event. | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | +| type | string | Yes | Call status change event. This field has a fixed value of **callStateChange**. | | callback | Callback\<{ state: [CallState](js-apis-call.md#callstate), number: string }\> | Yes | Callback function. For details, see [CallState](js-apis-call.md#callstate) in call.
**number**: phone number.| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -404,13 +416,15 @@ Registers an observer for call status change events. This API uses an asynchrono **Parameters** | Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Call status change event. | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | +| type | string | Yes | Call status change event. This field has a fixed value of **callStateChange**. | | slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2 | | callback | Callback\<{ state: [CallState](js-apis-call.md#callstate), number: string }\> | Yes | Callback function. For details, see [CallState](js-apis-call.md#callstate) in call.
**number**: phone number.| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -443,12 +457,14 @@ Unregisters the observer for call status change events. This API uses an asynchr **Parameters** | Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Call status change event. | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | +| type | string | Yes | Call status change event. This field has a fixed value of **callStateChange**. | | callback | Callback\<{ state: [CallState](js-apis-call.md#callstate), number: string }\> | No | Callback function. For details, see [CallState](js-apis-call.md#callstate) in call.
**number**: phone number.| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -482,11 +498,13 @@ Registers an observer for connection status change events of the cellular data l | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Connection status change event of the cellular data link. | +| type | string | Yes | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.| | callback | Callback\<{ state: [DataConnectState](js-apis-telephony-data.md#dataconnectstate), network: [RatType](js-apis-radio.md#radiotechnology) }\> | Yes | Callback used to return the result. For details, see [DataConnectState](js-apis-telephony-data.md#dataconnectstate) and [RadioTechnology](js-apis-radio.md#radiotechnology).| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -516,12 +534,14 @@ Registers an observer for connection status change events of the cellular data l | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Connection status change event of the cellular data link. | +| type | string | Yes | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.| | slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2 | | callback | Callback\<{ state: [DataConnectState](js-apis-telephony-data.md#dataconnectstate), network: [RatType](js-apis-radio.md#radiotechnology) }\> | Yes | Callback used to return the result. For details, see [DataConnectState](js-apis-telephony-data.md#dataconnectstate) and [RadioTechnology](js-apis-radio.md#radiotechnology).| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -555,11 +575,13 @@ Unregisters the observer for connection status change events of the cellular dat | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Connection status change event of the cellular data link. | +| type | string | Yes | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.| | callback | Callback\<{ state: [DataConnectState](js-apis-telephony-data.md#dataconnectstate), network: [RatType](js-apis-radio.md#radiotechnology) }\> | No | Callback used to return the result. For details, see [DataConnectState](js-apis-telephony-data.md#dataconnectstate) and [RadioTechnology](js-apis-radio.md#radiotechnology).| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -593,11 +615,13 @@ Registers an observer for the uplink and downlink data flow status change events | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Uplink and downlink data flow status change event of the cellular data service. | +| type | string | Yes | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**. | | callback | Callback\<[DataFlowType](js-apis-telephony-data.md#dataflowtype)\> | Yes | Callback used to return the result. For details, see [DataFlowType](js-apis-telephony-data.md#dataflowtype).| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -627,12 +651,14 @@ Registers an observer for the uplink and downlink data flow status change events | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Uplink and downlink data flow status change event of the cellular data service. | -| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2 | +| type | string | Yes | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**. | +| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2 | | callback | Callback\<[DataFlowType](js-apis-telephony-data.md#dataflowtype)\> | Yes | Callback used to return the result. For details, see [DataFlowType](js-apis-telephony-data.md#dataflowtype).| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -664,13 +690,15 @@ Unregisters the observer for the uplink and downlink data flow status change eve **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Uplink and downlink data flow status change event of the cellular data service. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**. | | callback | Callback\<[DataFlowType](js-apis-telephony-data.md#dataflowtype)\> | No | Callback used to return the result. For details, see [DataFlowType](js-apis-telephony-data.md#dataflowtype).| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -703,12 +731,14 @@ Registers an observer for SIM card status change events. This API uses an asynch **Parameters** | Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | SIM card status change event. | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | +| type | string | Yes | SIM status change event. This field has a fixed value of **simStateChange**. | | callback | Callback\<[SimStateData](#simstatedata7)\> | Yes | Callback used to return the result.| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -738,12 +768,14 @@ Registers an observer for status change events of the SIM card in the specified | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | SIM card status change event. | +| type | string | Yes | SIM status change event. This field has a fixed value of **simStateChange**. | | slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2 | | callback | Callback\<[SimStateData](#simstatedata7)\> | Yes | Callback used to return the result.| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -777,11 +809,13 @@ Unregisters the observer for SIM card status change events. This API uses an asy | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | SIM card status change event. | +| type | string | Yes | SIM status change event. This field has a fixed value of **simStateChange**. | | callback | Callback\<[SimStateData](#simstatedata7)\> | No | Callback used to return the result.| **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | diff --git a/en/application-dev/reference/apis/js-apis-radio.md b/en/application-dev/reference/apis/js-apis-radio.md index 448ccd3dc7d40a17edfdb7b0862cefe3a2377f9e..15c1fc484dd8987dd26c9229beeb200ba8a711e9 100644 --- a/en/application-dev/reference/apis/js-apis-radio.md +++ b/en/application-dev/reference/apis/js-apis-radio.md @@ -32,6 +32,8 @@ Obtains the RAT used in the CS and PS domains for the SIM card in the specified **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -75,6 +77,8 @@ Obtains the RAT used in the CS and PS domains for the SIM card in the specified **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -115,6 +119,8 @@ Obtains the network status. This API uses an asynchronous callback to return the **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -152,6 +158,8 @@ Obtains the network status. This API uses an asynchronous callback to return the **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -195,6 +203,8 @@ Obtains the network status. This API uses a promise to return the result. **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -234,6 +244,8 @@ Obtains the network selection mode of the SIM card in the specified slot. This A **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -274,6 +286,8 @@ Obtains the network selection mode of the SIM card in the specified slot. This A **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -312,6 +326,8 @@ Obtains the ISO country code of the network with which the SIM card in the speci **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -352,6 +368,8 @@ Obtains the ISO country code of the network with which the SIM card in the speci **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -389,6 +407,8 @@ Obtains the ID of the slot in which the primary card is located. This API uses a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 8300001 | Invalid parameter value. | @@ -421,6 +441,8 @@ Obtains the ID of the slot in which the primary card is located. This API uses a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 8300001 | Invalid parameter value. | @@ -457,6 +479,8 @@ Obtains a list of signal strengths of the network with which the SIM card in the **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -497,6 +521,8 @@ Obtains a list of signal strengths of the network with which the SIM card in the **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -644,6 +670,8 @@ Checks whether the radio service is enabled on the primary SIM card. This API us **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -681,6 +709,8 @@ Checks whether the radio service is enabled on the SIM card in the specified slo **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -724,6 +754,8 @@ Checks whether the radio service is enabled on the SIM card in the specified slo **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -763,6 +795,8 @@ Obtains the carrier name for the SIM card in the specified slot. This API uses a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -803,6 +837,8 @@ Obtains the carrier name for the SIM card in the specified slot. This API uses a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -844,6 +880,8 @@ Sets the ID of the slot in which the primary card is located. This API uses an a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -858,8 +896,8 @@ Sets the ID of the slot in which the primary card is located. This API uses an a ```js let slotId = 0; -radio.setPrimarySlotId(slotId, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +radio.setPrimarySlotId(slotId, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -890,6 +928,8 @@ Sets the ID of the slot in which the primary card is located. This API uses a pr **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -905,9 +945,9 @@ Sets the ID of the slot in which the primary card is located. This API uses a pr ```js let slotId = 0; let promise = radio.setPrimarySlotId(slotId); -promise.then(data => { - console.log(`setPrimarySlotId success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`setPrimarySlotId success.`); +}).catch((err) => { console.log(`setPrimarySlotId failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -932,6 +972,8 @@ Obtains the IMEI of the SIM card in a card slot. This API uses an asynchronous c **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -971,6 +1013,8 @@ Obtains the IMEI of the SIM card in the specified card slot. This API uses an as **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1016,6 +1060,8 @@ Obtains the IMEI of the SIM card in the specified card slot. This API uses a pro **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1057,6 +1103,8 @@ Obtains the MEID of the SIM card in a card slot. This API uses an asynchronous c **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1096,6 +1144,8 @@ Obtains the MEID of the SIM card in the specified card slot. This API uses an as **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1141,6 +1191,8 @@ Obtains the MEID of the SIM card in the specified card slot. This API uses a pro **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1182,6 +1234,8 @@ Obtains the unique device ID of the SIM card in a card slot. This API uses an as **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1221,6 +1275,8 @@ Obtains the unique device ID of the SIM card in the specified card slot. This AP **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1266,6 +1322,8 @@ Obtains the unique device ID of the SIM card in the specified card slot. This AP **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1307,6 +1365,8 @@ Sends a cell location update request. This API uses an asynchronous callback to **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1319,8 +1379,8 @@ Sends a cell location update request. This API uses an asynchronous callback to **Example** ```js -radio.sendUpdateCellLocationRequest((err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +radio.sendUpdateCellLocationRequest((err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -1345,6 +1405,8 @@ Sends a cell location update request for the SIM card in the specified slot. Thi **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1358,8 +1420,8 @@ Sends a cell location update request for the SIM card in the specified slot. Thi ```js let slotId = 0; -radio.sendUpdateCellLocationRequest(slotId, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +radio.sendUpdateCellLocationRequest(slotId, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -1389,6 +1451,8 @@ Sends a cell location update request for the SIM card in the specified slot. Thi **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1402,10 +1466,9 @@ Sends a cell location update request for the SIM card in the specified slot. Thi ```js let slotId = 0; -let promise = radio.sendUpdateCellLocationRequest(slotId); -promise.then(data => { - console.log(`sendUpdateCellLocationRequest success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +radio.sendUpdateCellLocationRequest(slotId).then(() => { + console.log(`sendUpdateCellLocationRequest success.`); +}).catch((err) => { console.log(`sendUpdateCellLocationRequest failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -1430,6 +1493,8 @@ Obtains cell information. This API uses an asynchronous callback to return the r **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1469,6 +1534,8 @@ Obtains cell information for the SIM card in the specified slot. This API uses a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1514,6 +1581,8 @@ Obtains cell information for the SIM card in the specified slot. This API uses a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1556,6 +1625,8 @@ Sets the network selection mode. This API uses an asynchronous callback to retur **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1580,8 +1651,8 @@ let networkSelectionModeOptions={ networkInformation: networkInformation, resumeSelection: true } -radio.setNetworkSelectionMode(networkSelectionModeOptions, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +radio.setNetworkSelectionMode(networkSelectionModeOptions, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -1611,6 +1682,8 @@ Sets the network selection mode. This API uses a promise to return the result. **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1636,9 +1709,9 @@ let networkSelectionModeOptions={ resumeSelection: true } let promise = radio.setNetworkSelectionMode(networkSelectionModeOptions); -promise.then(data => { - console.log(`setNetworkSelectionMode success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`setNetworkSelectionMode success.`); +}).catch((err) => { console.log(`setNetworkSelectionMode failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -1664,6 +1737,8 @@ Obtains network search information for the SIM card in the specified slot. This **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1707,6 +1782,8 @@ Obtains network search information for the SIM card in the specified slot. This **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1745,6 +1822,8 @@ Obtains the NR option mode. This API uses an asynchronous callback to return the **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -1781,6 +1860,8 @@ Obtains the NR option mode for the SIM card in the specified slot. This API uses **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -1823,6 +1904,8 @@ Obtains the NR option mode for the SIM card in the specified slot. This API uses **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -1863,6 +1946,8 @@ Turns on the radio function. This API uses an asynchronous callback to return th **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1875,8 +1960,8 @@ Turns on the radio function. This API uses an asynchronous callback to return th **Example** ```js -radio.turnOnRadio((err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +radio.turnOnRadio((err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -1902,6 +1987,8 @@ Turns on the radio function for the SIM card in the specified slot. This API use **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1915,8 +2002,8 @@ Turns on the radio function for the SIM card in the specified slot. This API use ```js let slotId = 0; -radio.turnOnRadio(slotId, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +radio.turnOnRadio(slotId, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -1947,6 +2034,8 @@ Turns on the radio function for the SIM card in the specified slot. This API use **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1960,10 +2049,9 @@ Turns on the radio function for the SIM card in the specified slot. This API use ```js let slotId = 0; -let promise = radio.turnOnRadio(slotId); -promise.then(data => { - console.log(`turnOnRadio success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +radio.turnOnRadio(slotId).then(() => { + console.log(`turnOnRadio success.`); +}).catch((err) => { console.error(`turnOnRadio failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -1988,6 +2076,8 @@ Turns off the radio function. This API uses an asynchronous callback to return t **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2000,8 +2090,8 @@ Turns off the radio function. This API uses an asynchronous callback to return t **Example** ```js -radio.turnOffRadio((err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +radio.turnOffRadio((err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -2027,6 +2117,8 @@ Turns off the radio function for the SIM card in the specified slot. This API us **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2040,8 +2132,8 @@ Turns off the radio function for the SIM card in the specified slot. This API us ```js let slotId = 0; -radio.turnOffRadio(slotId, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +radio.turnOffRadio(slotId, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -2072,6 +2164,8 @@ Turns off the radio function for the SIM card in the specified slot. This API us **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2085,10 +2179,9 @@ Turns off the radio function for the SIM card in the specified slot. This API us ```js let slotId = 0; -let promise = radio.turnOffRadio(slotId); -promise.then(data => { - console.log(`turnOffRadio success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +radio.turnOffRadio(slotId).then(() => { + console.log(`turnOffRadio success.`); +}).catch((err) => { console.error(`turnOffRadio failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -2115,6 +2208,8 @@ Sets the preferred network for the SIM card in the specified slot. This API uses **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2127,8 +2222,9 @@ Sets the preferred network for the SIM card in the specified slot. This API uses **Example** ```js -radio.setPreferredNetwork(0, 1, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +let slotId = 0; +radio.setPreferredNetwork(slotId, radio.PreferredNetworkMode.PREFERRED_NETWORK_MODE_GSM, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -2159,7 +2255,9 @@ Sets the preferred network for the SIM card in the specified slot. This API uses **Error codes** -| ID| Error Message | +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + +| ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | | 401 | Parameter error. | @@ -2171,10 +2269,10 @@ Sets the preferred network for the SIM card in the specified slot. This API uses **Example** ```js -let promise = radio.setPreferredNetwork(0, 1); -promise.then(data => { - console.log(`setPreferredNetwork success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +let slotId = 0; +radio.setPreferredNetwork(slotId, radio.PreferredNetworkMode.PREFERRED_NETWORK_MODE_GSM).then(() => { + console.log(`setPreferredNetwork success.`); +}).catch((err) => { console.log(`setPreferredNetwork failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -2200,6 +2298,8 @@ Obtains the preferred network for the SIM card in the specified slot. This API u **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2243,6 +2343,8 @@ Obtains the preferred network for the SIM card in the specified slot. This API u **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2285,6 +2387,8 @@ Obtains the IMS registration status of the specified IMS service type for the SI **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2329,6 +2433,8 @@ Obtains the IMS registration status of the specified IMS service type for the SI **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2372,6 +2478,8 @@ Enables listening for **imsRegStateChange** events. This API uses an asynchronou **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2412,6 +2520,8 @@ Disables listening for **imsRegStateChange** events. This API uses an asynchrono **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | diff --git a/en/application-dev/reference/apis/js-apis-resource-manager.md b/en/application-dev/reference/apis/js-apis-resource-manager.md index 41d18e140d9442384c32d7ccbd94ccc153b8ca07..cc24c7ab23912cb3abb8f2ee648c0be026565aac 100644 --- a/en/application-dev/reference/apis/js-apis-resource-manager.md +++ b/en/application-dev/reference/apis/js-apis-resource-manager.md @@ -13,7 +13,7 @@ The Resource Manager module provides APIs to obtain information about applicatio import resourceManager from '@ohos.resourceManager'; ``` -## How to Use +## Instruction Since API version 9, the stage model allows an application to obtain a **ResourceManager** object based on **context** and call its resource management APIs without first importing the required bundle. This approach, however, is not applicable to the FA model. For the FA model, you need to import the required bundle and then call the [getResourceManager](#resourcemanagergetresourcemanager) API to obtain a **ResourceManager** object. For details about how to reference context in the stage model, see [Context in the Stage Model](../../application-models/application-context-stage.md). @@ -78,7 +78,7 @@ Obtains the **ResourceManager** object of an application based on the specified | Name | Type | Mandatory | Description | | ---------- | ---------------------------------------- | ---- | ----------------------------- | -| bundleName | string | Yes | Bundle name of the target application. | +| bundleName | string | Yes | Bundle name of the application. | | callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes | Callback used to return the result.| **Example** @@ -118,7 +118,7 @@ Obtains the **ResourceManager** object of this application. This API uses a prom console.log("error is " + error); }); ``` -> **NOTE**
> In the sample code, **0x1000000** indicates the resource ID, which can be found in the compiled **ResourceTable.txt** file. +> **NOTE**
In the sample code, **0x1000000** indicates the resource ID, which can be found in the compiled **ResourceTable.txt** file. ## resourceManager.getResourceManager @@ -135,7 +135,7 @@ Obtains the **ResourceManager** object of an application based on the specified | Name | Type | Mandatory | Description | | ---------- | ------ | ---- | ------------- | -| bundleName | string | Yes | Bundle name of the target application.| +| bundleName | string | Yes | Bundle name of the application.| **Return value** @@ -171,12 +171,12 @@ Enumerates the device types. | Name | Value | Description | | -------------------- | ---- | ---- | -| DEVICE_TYPE_PHONE | 0x00 | Phone. | -| DEVICE_TYPE_TABLET | 0x01 | Tablet. | -| DEVICE_TYPE_CAR | 0x02 | Head unit. | -| DEVICE_TYPE_PC | 0x03 | PC. | -| DEVICE_TYPE_TV | 0x04 | TV. | -| DEVICE_TYPE_WEARABLE | 0x06 | Wearable. | +| DEVICE_TYPE_PHONE | 0x00 | Phone | +| DEVICE_TYPE_TABLET | 0x01 | Tablet | +| DEVICE_TYPE_CAR | 0x02 | Head unit | +| DEVICE_TYPE_PC | 0x03 | PC | +| DEVICE_TYPE_TV | 0x04 | TV | +| DEVICE_TYPE_WEARABLE | 0x06 | Wearable | ## ScreenDensity @@ -278,7 +278,7 @@ Defines the capability of accessing application resources. > **NOTE** > -> - The methods involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm. +> - The APIs involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm. > > - Resource files are defined in the **resources** directory of the project. You can obtain the resource ID using **$r(resource address).id**, for example, **$r('app.string.test').id**. @@ -645,7 +645,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco getMediaContent(resId: number, callback: AsyncCallback<Uint8Array>): void -Obtains the content of the media file corresponding to the specified resource name. This API uses an asynchronous callback to return the result. +Obtains the content of the media file corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager @@ -1658,7 +1658,7 @@ Obtains the string corresponding to the specified resource name. This API uses a | Type | Description | | --------------------- | ---------- | -| Promise<string> | Promise used to return the result.| +| Promise<string> | String corresponding to the resource name.| For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). @@ -1770,7 +1770,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco getMediaByName(resName: string, callback: AsyncCallback<Uint8Array>): void -Obtains the content of the media file corresponding to the specified resource name. This API uses an asynchronous callback to return the result. +Obtains the content of the media file corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager @@ -2036,7 +2036,7 @@ Obtains the string corresponding to the specified resource ID. This API returns | Type | Description | | ------ | ----------- | -| string | String corresponding to the specified resource ID.| +| string | Promise used to return the result.| For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). @@ -2075,7 +2075,7 @@ Obtains the string corresponding to the specified resource object. This API retu | Type | Description | | ------ | ---------------- | -| string | String corresponding to the resource object.| +| string | Promise used to return the result.| For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). @@ -2119,7 +2119,7 @@ Obtains the string corresponding to the specified resource name. This API return | Type | Description | | ------ | ---------- | -| string | String corresponding to the resource name.| +| string | String corresponding to the specified resource name.| For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). @@ -2395,6 +2395,142 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco } ``` +### getDrawableDescriptor10+ + +getDrawableDescriptor(resId: number, density?: number): DrawableDescriptor; + +Obtains the **DrawableDescriptor** object based on the specified resource ID. This API returns the result synchronously. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| +| [density](#screendensity) | number | No | Screen density. The default value is **0**.| + +**Return value** + +| Type | Description | +| ------ | ---------- | +| DrawableDescriptor | **DrawableDescriptor** object corresponding to the resource ID.| + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +**Error codes** + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | + +**Example** + ```ts + try { + this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id); + } catch (error) { + console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`) + } + try { + this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120); + } catch (error) { + console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`) + } + ``` + +### getDrawableDescriptor10+ + +getDrawableDescriptor(resource: Resource, density?: number): DrawableDescriptor; + +Obtains the **DrawableDescriptor** object based on the specified resource. This API returns the result synchronously. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------- | ---- | ---- | +| resource | [Resource](#resource9) | Yes | Resource object.| +| [density](#screendensity) | number | No | Screen density. The default value is **0**.| + +**Return value** + +| Type | Description | +| ------- | ----------------- | +| DrawableDescriptor | **DrawableDescriptor** object corresponding to the resource ID.| + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +**Error codes** + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | + +**Example** + ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.media.icon').id + }; + try { + this.context.resourceManager.getDrawableDescriptor(resource); + } catch (error) { + console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`) + } + try { + this.context.resourceManager.getDrawableDescriptor(resource, 120); + } catch (error) { + console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`) + } + ``` + +### getDrawableDescriptorByName10+ + +getDrawableDescriptorByName(resName: string, density?: number): DrawableDescriptor; + +Obtains the **DrawableDescriptor** object based on the specified resource name. This API returns the result synchronously. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---- | +| resName | string | Yes | Resource name.| +| [density](#screendensity) | number | No | Screen density. The default value is **0**.| + +**Return value** + +| Type | Description | +| ------ | --------- | +| DrawableDescriptor | **DrawableDescriptor** object corresponding to the resource ID.| + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +**Error codes** + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | + +**Example** + ```ts + try { + this.context.resourceManager.getDrawableDescriptorByName('icon'); + } catch (error) { + console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`) + } + try { + this.context.resourceManager.getDrawableDescriptorByName('icon', 120); + } catch (error) { + console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`) + } + ``` ### getString(deprecated) @@ -2530,7 +2666,7 @@ This API is deprecated since API version 9. You are advised to use [getStringArr getMedia(resId: number, callback: AsyncCallback<Uint8Array>): void -Obtains the content of the media file corresponding to the specified resource name. This API uses an asynchronous callback to return the result. +Obtains the content of the media file corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9) instead. diff --git a/en/application-dev/reference/apis/js-apis-sim.md b/en/application-dev/reference/apis/js-apis-sim.md index f8d5e0d75a5425fcade12cd6f8f90e8cc5ee720a..6736cc90eca295e17310c295409a781f679db7d4 100644 --- a/en/application-dev/reference/apis/js-apis-sim.md +++ b/en/application-dev/reference/apis/js-apis-sim.md @@ -134,13 +134,14 @@ Checks whether the application (caller) has been granted the operator permission **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | | 8300003 | System internal error. | -| 8300004 | Do not have sim card. | | 8300999 | Unknown error code. | **Example** @@ -173,13 +174,14 @@ Checks whether the application (caller) has been granted the operator permission **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | | 8300003 | System internal error. | -| 8300004 | Do not have sim card. | | 8300999 | Unknown error code. | **Example** @@ -210,6 +212,8 @@ Obtains the ISO country code of the SIM card in the specified slot. This API use **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -250,6 +254,8 @@ Obtains the ISO country code of the SIM card in the specified slot. This API use **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -288,6 +294,8 @@ Obtains the public land mobile network \(PLMN\) ID of the SIM card in the specif **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -328,6 +336,8 @@ Obtains the PLMN ID of the SIM card in the specified slot. This API uses a promi **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -366,6 +376,8 @@ Obtains the service provider name (SPN) of the SIM card in the specified slot. T **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -406,6 +418,8 @@ Obtains the SPN of the SIM card in the specified slot. This API uses a promise t **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -444,13 +458,14 @@ Obtains the state of the SIM card in the specified slot. This API uses an asynch **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | | 8300003 | System internal error. | -| 8300004 | Do not have sim card. | | 8300999 | Unknown error code. | **Example** @@ -484,13 +499,14 @@ Obtains the state of the SIM card in the specified slot. This API uses a promise **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | | 8300003 | System internal error. | -| 8300004 | Do not have sim card. | | 8300999 | Unknown error code. | **Example** @@ -521,6 +537,8 @@ Obtains the type of the SIM card in the specified slot. This API uses an asynchr **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -561,6 +579,8 @@ Obtains the type of the SIM card in the specified slot. This API uses a promise **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -599,13 +619,14 @@ Checks whether the SIM card in the specified slot is installed. This API uses an **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | | 8300003 | System internal error. | -| 8300004 | Do not have sim card. | | 8300999 | Unknown error code. | **Example** @@ -639,13 +660,14 @@ Checks whether the SIM card in the specified slot is installed. This API uses a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | | 8300003 | System internal error. | -| 8300004 | Do not have sim card. | | 8300999 | Unknown error code. | **Example** @@ -680,6 +702,8 @@ Obtains SIM card account information. This API uses an asynchronous callback to **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -726,6 +750,8 @@ Obtains SIM card account information. This API uses a promise to return the resu **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -768,6 +794,8 @@ Obtains the account information list of the active SIM card. This API uses an as **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -807,6 +835,8 @@ Obtains the account information list of the active SIM card. This API uses a pro **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -849,6 +879,8 @@ Sets the default slot ID of the SIM card that provides voice services. This API **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -863,8 +895,8 @@ Sets the default slot ID of the SIM card that provides voice services. This API **Example** ```js -sim.setDefaultVoiceSlotId(0, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sim.setDefaultVoiceSlotId(0, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -895,6 +927,8 @@ Sets the default slot ID of the SIM card that provides voice services. This API **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -910,9 +944,9 @@ Sets the default slot ID of the SIM card that provides voice services. This API ```js let promise = sim.setDefaultVoiceSlotId(0); -promise.then(data => { - console.log(`setDefaultVoiceSlotId success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`setDefaultVoiceSlotId success.`); +}).catch((err) => { console.log(`setDefaultVoiceSlotId failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -939,6 +973,8 @@ Sets a display name for the SIM card in the specified slot. This API uses an asy **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -953,8 +989,8 @@ Sets a display name for the SIM card in the specified slot. This API uses an asy ```js let name = "ShowName"; -sim.setShowName(0, name, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sim.setShowName(0, name, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -985,6 +1021,8 @@ Sets a display name for the SIM card in the specified slot. This API uses a prom **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1000,9 +1038,9 @@ Sets a display name for the SIM card in the specified slot. This API uses a prom ```js let name = "ShowName"; let promise = sim.setShowName(0, name); -promise.then(data => { - console.log(`setShowName success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`setShowName success.`); +}).catch((err) => { console.log(`setShowName failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -1028,6 +1066,8 @@ Obtains the name of the SIM card in the specified slot. This API uses an asynchr **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1073,6 +1113,8 @@ Obtains the name of the SIM card in the specified slot. This API uses a promise **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1116,6 +1158,8 @@ Sets a display number for the SIM card in the specified slot. This API uses an a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1130,8 +1174,8 @@ Sets a display number for the SIM card in the specified slot. This API uses an a ```js let number = '+861xxxxxxxxxx'; -sim.setShowNumber(0, number, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sim.setShowNumber(0, number, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -1163,6 +1207,8 @@ Sets a display number for the SIM card in the specified slot. This API uses a pr **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1178,9 +1224,9 @@ Sets a display number for the SIM card in the specified slot. This API uses a pr ```js let number = '+861xxxxxxxxxx'; let promise = sim.setShowNumber(0, number); -promise.then(data => { - console.log(`setShowNumber success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`setShowNumber success.`); +}).catch((err) => { console.log(`setShowNumber failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -1206,6 +1252,8 @@ Obtains the display number of the SIM card in the specified slot. This API uses **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1251,6 +1299,8 @@ Obtains the display number of the SIM card in the specified slot. This API uses **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1293,6 +1343,8 @@ Activates a SIM card in a specified card slot. This API uses an asynchronous cal **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1306,8 +1358,8 @@ Activates a SIM card in a specified card slot. This API uses an asynchronous cal **Example** ```js -sim.activateSim(0, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sim.activateSim(0, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -1338,6 +1390,8 @@ Activates the SIM card in the specified slot. This API uses a promise to return **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1352,9 +1406,9 @@ Activates the SIM card in the specified slot. This API uses a promise to return ```js let promise = sim.activateSim(0); -promise.then(data => { - console.log(`activateSim success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`activateSim success.`); +}).catch((err) => { console.log(`activateSim failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -1380,6 +1434,8 @@ Disables the SIM card in the specified slot. This API uses an asynchronous callb **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1393,8 +1449,8 @@ Disables the SIM card in the specified slot. This API uses an asynchronous callb **Example** ```js -sim.deactivateSim(0, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sim.deactivateSim(0, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -1425,6 +1481,8 @@ Disables the SIM card in the specified slot. This API uses a promise to return t **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1439,9 +1497,9 @@ Disables the SIM card in the specified slot. This API uses a promise to return t ```js let promise = sim.deactivateSim(0); -promise.then(data => { - console.log(`deactivateSim success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`deactivateSim success.`); +}).catch((err) => { console.log(`deactivateSim failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -1468,6 +1526,8 @@ Sets the lock status of the SIM card in the specified slot. This API uses an asy **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1520,6 +1580,8 @@ Sets the lock status of the SIM card in the specified slot. This API uses a prom **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1569,6 +1631,8 @@ Obtains the lock status of the SIM card in the specified slot. This API uses an **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1616,6 +1680,8 @@ Obtains the lock status of the SIM card in the specified slot. This API uses a p **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1661,6 +1727,8 @@ Changes the PIN of the SIM card in the specified slot. This API uses an asynchro **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1709,6 +1777,8 @@ Changes the PIN of the SIM card in the specified slot. This API uses a promise t **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1754,6 +1824,8 @@ Changes PIN 2 of the SIM card in the specified slot. This API uses an asynchrono **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1802,6 +1874,8 @@ Changes PIN 2 of the SIM card in the specified slot. This API uses a promise to **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1846,6 +1920,8 @@ Unlocks the PIN of the SIM card in the specified slot. This API uses an asynchro **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1894,6 +1970,8 @@ Unlocks the PIN of the SIM card in the specified slot. This API uses a promise t **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1940,6 +2018,8 @@ Unlocks the PUK of the SIM card in the specified slot. This API uses an asynchro **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -1990,6 +2070,8 @@ Unlocks the PUK of the SIM card in the specified slot. This API uses a promise t **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2036,6 +2118,8 @@ Unlocks PIN 2 of the SIM card in the specified slot. This API uses an asynchrono **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2084,6 +2168,8 @@ Unlocks PIN 2 of the SIM card in the specified slot. This API uses a promise to **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2130,6 +2216,8 @@ Unlocks PUK 2 of the SIM card in the specified slot. This API uses an asynchrono **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2180,6 +2268,8 @@ Unlocks PUK 2 of the SIM card in the specified slot. This API uses a promise to **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2245,6 +2335,8 @@ Obtains the ICCID of the SIM card in the specified slot. This API uses an asynch **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2290,6 +2382,8 @@ Obtains the ICCID of the SIM card in the specified slot. This API uses a promise **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2332,6 +2426,8 @@ Obtains the voice mailbox alpha identifier of the SIM card in the specified slot **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2377,6 +2473,8 @@ Obtains the voice mailbox alpha identifier of the SIM card in the specified slot **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2419,6 +2517,8 @@ Obtains the voice mailbox number of the SIM card in the specified slot. This API **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2464,6 +2564,8 @@ Obtains the voice mailbox number of the SIM card in the specified slot. This API **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2509,6 +2611,8 @@ Sets voice mailbox information for the SIM card in the specified slot. This API **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2523,8 +2627,8 @@ Sets voice mailbox information for the SIM card in the specified slot. This API **Example** ```js -sim.setVoiceMailInfo(0, "mail", "xxx@xxx.com", (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sim.setVoiceMailInfo(0, "mail", "xxx@xxx.com", (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -2557,6 +2661,8 @@ Sets voice mailbox information for the SIM card in the specified slot. This API **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2572,9 +2678,9 @@ Sets voice mailbox information for the SIM card in the specified slot. This API ```js let promise = sim.setVoiceMailInfo(0, "mail", "xxx@xxx.com"); -promise.then(data => { - console.log(`setVoiceMailInfo success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`setVoiceMailInfo success.`); +}).catch((err) => { console.log(`setVoiceMailInfo failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -2600,6 +2706,8 @@ Obtains the MSISDN of the SIM card in the specified slot. This API uses an async **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2645,6 +2753,8 @@ Obtains the MSISDN of the SIM card in the specified slot. This API uses a promis **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2687,6 +2797,8 @@ Obtains the group identifier level 1 (GID1) of the SIM card in the specified slo **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2732,6 +2844,8 @@ Obtains the GID1 of the SIM card in the specified slot. This API uses a promise **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2774,6 +2888,8 @@ Obtains the international mobile subscriber identity (IMSI) of the SIM card in t **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2819,6 +2935,8 @@ Obtains the IMSI of the SIM card in the specified slot. This API uses a promise **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2861,6 +2979,8 @@ Obtains the carrier configuration of the SIM card in the specified slot. This AP **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2868,7 +2988,6 @@ Obtains the carrier configuration of the SIM card in the specified slot. This AP | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | | 8300003 | System internal error. | -| 8300004 | Do not have sim card. | | 8300999 | Unknown error code. | **Example** @@ -2906,6 +3025,8 @@ Obtains the carrier configuration of the SIM card in the specified slot. This AP **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2913,7 +3034,6 @@ Obtains the carrier configuration of the SIM card in the specified slot. This AP | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | | 8300003 | System internal error. | -| 8300004 | Do not have sim card. | | 8300999 | Unknown error code. | **Example** @@ -2949,6 +3069,8 @@ Queries contact numbers of the SIM card in the specified slot. This API uses an **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -2996,6 +3118,8 @@ Queries contact numbers of the SIM card in the specified slot. This API uses a p **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -3041,6 +3165,8 @@ Adds contact numbers for the SIM card in the specified slot. This API uses an as **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -3060,8 +3186,8 @@ let diallingNumbersInof = { number: "138xxxxxxxx", pin2: "1234" }; -sim.addIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sim.addIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -3094,6 +3220,8 @@ Adds contact numbers for the SIM card in the specified slot. This API uses a pro **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -3113,9 +3241,9 @@ let diallingNumbersInof = { number: "138xxxxxxxx" }; let promise = sim.addIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof); -promise.then(data => { - console.log(`addIccDiallingNumbers success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`addIccDiallingNumbers success.`); +}).catch((err) => { console.log(`addIccDiallingNumbers failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -3143,6 +3271,8 @@ Deletes contact numbers from the SIM card in the specified slot. This API uses a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -3163,8 +3293,8 @@ let diallingNumbersInof = { recordNumber: 123, pin2: "1234" }; -sim.delIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sim.delIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -3197,6 +3327,8 @@ Deletes contact numbers from the SIM card in the specified slot. This API uses a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -3216,9 +3348,9 @@ let diallingNumbersInof = { number: "138xxxxxxxx" }; let promise = sim.delIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof); -promise.then(data => { - console.log(`delIccDiallingNumbers success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`delIccDiallingNumbers success.`); +}).catch((err) => { console.log(`delIccDiallingNumbers failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -3246,6 +3378,8 @@ Updates contact numbers for the SIM card in the specified slot. This API uses an **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -3266,8 +3400,8 @@ let diallingNumbersInof = { recordNumber: 123, pin2: "1234" }; -sim.updateIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sim.updateIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -3300,6 +3434,8 @@ Updates contact numbers for the SIM card in the specified slot. This API uses a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -3320,9 +3456,9 @@ let diallingNumbersInof = { recordNumber: 123 }; let promise = sim.updateIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof); -promise.then(data => { - console.log(`updateIccDiallingNumbers success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`updateIccDiallingNumbers success.`); +}).catch((err) => { console.log(`updateIccDiallingNumbers failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -3349,6 +3485,8 @@ Sends an envelope command to the SIM card in the specified slot. This API uses a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -3362,8 +3500,8 @@ Sends an envelope command to the SIM card in the specified slot. This API uses a **Example** ```js -sim.sendEnvelopeCmd(0, "ls", (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sim.sendEnvelopeCmd(0, "ls", (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -3395,6 +3533,8 @@ Sends an envelope command to the SIM card in the specified slot. This API uses a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -3409,9 +3549,9 @@ Sends an envelope command to the SIM card in the specified slot. This API uses a ```js let promise = sim.sendEnvelopeCmd(0, "ls"); -promise.then(data => { - console.log(`sendEnvelopeCmd success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`sendEnvelopeCmd success.`); +}).catch((err) => { console.log(`sendEnvelopeCmd failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -3438,6 +3578,8 @@ Sends a terminal response command to the SIM card in the specified slot. This AP **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -3451,8 +3593,8 @@ Sends a terminal response command to the SIM card in the specified slot. This AP **Example** ```js -sim.sendTerminalResponseCmd(0, "ls", (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sim.sendTerminalResponseCmd(0, "ls", (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -3484,6 +3626,8 @@ Sends a terminal response command to the SIM card in the specified slot. This AP **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -3498,9 +3642,9 @@ Sends a terminal response command to the SIM card in the specified slot. This AP ```js let promise = sim.sendTerminalResponseCmd(0, "ls"); -promise.then(data => { - console.log(`sendTerminalResponseCmd success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`sendTerminalResponseCmd success.`); +}).catch((err) => { console.log(`sendTerminalResponseCmd failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -3528,6 +3672,8 @@ Unlocks the SIM card in the specified slot. This API uses an asynchronous callba **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -3579,6 +3725,8 @@ Unlocks the SIM card in the specified slot. This API uses a promise to return th **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -3622,6 +3770,8 @@ Obtains the opkey of the SIM card in the specified slot. This API uses an asynch **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -3629,7 +3779,6 @@ Obtains the opkey of the SIM card in the specified slot. This API uses an asynch | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | | 8300003 | System internal error. | -| 8300004 | Do not have sim card. | | 8300999 | Unknown error code. | **Example** @@ -3671,6 +3820,8 @@ Obtains the opkey of the SIM card in the specified slot. This API uses a promise **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -3678,7 +3829,6 @@ Obtains the opkey of the SIM card in the specified slot. This API uses a promise | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | | 8300003 | System internal error. | -| 8300004 | Do not have sim card. | | 8300999 | Unknown error code. | **Example** @@ -3709,6 +3859,8 @@ Obtains the OpName of the SIM card in the specified slot. This API uses an async **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -3716,7 +3868,6 @@ Obtains the OpName of the SIM card in the specified slot. This API uses an async | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | | 8300003 | System internal error. | -| 8300004 | Do not have sim card. | | 8300999 | Unknown error code. | **Example** @@ -3758,6 +3909,8 @@ Obtains the OpName of the SIM card in the specified slot. This API uses a promis **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -3765,7 +3918,6 @@ Obtains the OpName of the SIM card in the specified slot. This API uses a promis | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | | 8300003 | System internal error. | -| 8300004 | Do not have sim card. | | 8300999 | Unknown error code. | **Example** @@ -3847,17 +3999,17 @@ Enumerates personalized lock types. **System capability**: SystemCapability.Telephony.CoreService -| Name | Value | Description | -| ------------ | ---- | ----------------------------------------------- | -| PN_PIN_LOCK | 0 | Personalized network PIN lock. For details, see *3GPP TS 22.022 [33]*. | +| Name | Value | Description | +| ------------ | ---- | ------------------------------------------------ | +| PN_PIN_LOCK | 0 | Personalized network PIN lock. For details, see *3GPP TS 22.022 [33]*. | | PN_PUK_LOCK | 1 | Personalized network PUK lock. | -| PU_PIN_LOCK | 2 | Personalized network subset PIN lock. For details, see *3GPP TS 22.022 [33]*. | +| PU_PIN_LOCK | 2 | Personalized network subset PIN lock. For details, see *3GPP TS 22.022 [33]*. | | PU_PUK_LOCK | 3 | Personalized network subset PUK lock. | -| PP_PIN_LOCK | 4 | Personalized service provider PIN lock. For details, see *3GPP TS 22.022 [33]*.| +| PP_PIN_LOCK | 4 | Personalized service provider PIN lock. For details, see *3GPP TS 22.022 [33]*. | | PP_PUK_LOCK | 5 | Personalized service provider PUK lock. | -| PC_PIN_LOCK | 6 | Personalized corporate PIN lock. For details, see *3GPP TS 22.022 [33]*. | +| PC_PIN_LOCK | 6 | Personalized corporate PIN lock. For details, see *3GPP TS 22.022 [33]*. | | PC_PUK_LOCK | 7 | Personalized corporate PUK lock. | -| SIM_PIN_LOCK | 8 | Personalized SIM card PIN lock. For details, see *3GPP TS 22.022 [33]*. | +| SIM_PIN_LOCK | 8 | Personalized SIM card PIN lock. For details, see *3GPP TS 22.022 [33]*. | | SIM_PUK_LOCK | 9 | Personalized SIM card PUK lock. | ## LockStatusResponse7+ diff --git a/en/application-dev/reference/apis/js-apis-sms.md b/en/application-dev/reference/apis/js-apis-sms.md index c3a1f35f5140514d466ae481876fe1114c2b43e8..464f34595cc67c5051524d2f7f6ef0753bede543 100644 --- a/en/application-dev/reference/apis/js-apis-sms.md +++ b/en/application-dev/reference/apis/js-apis-sms.md @@ -91,6 +91,19 @@ Sends an SMS message. | ------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | | options | [SendMessageOptions](#sendmessageoptions) | Yes | Options (including the callback) for sending an SMS message.| +**Error codes** + +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + +| ID| Error Message | +| -------- | -------------------------------------------- | +| 201 | Permission denied. | +| 401 | Parameter error. | +| 8300001 | Invalid parameter value. | +| 8300002 | Operation failed. Cannot connect to service. | +| 8300003 | System internal error. | +| 8300999 | Unknown error code. | + **Example** ```js @@ -179,6 +192,8 @@ Sets the default slot ID of the SIM card used to send SMS messages. This API use **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -192,8 +207,8 @@ Sets the default slot ID of the SIM card used to send SMS messages. This API use **Example** ```js -sms.setDefaultSmsSlotId(0, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sms.setDefaultSmsSlotId(0, (err) => { + console.log(`callback: err->${JSON.stringify(err)}.`); }); ``` @@ -224,6 +239,8 @@ Sets the default slot ID of the SIM card used to send SMS messages. This API use **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -238,9 +255,9 @@ Sets the default slot ID of the SIM card used to send SMS messages. This API use ```js let promise = sms.setDefaultSmsSlotId(0); -promise.then(data => { - console.log(`setDefaultSmsSlotId success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`setDefaultSmsSlotId success.`); +}).catch((err) => { console.error(`setDefaultSmsSlotId failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -267,6 +284,8 @@ Sets the short message service center (SMSC) address. This API uses an asynchron **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -281,8 +300,8 @@ Sets the short message service center (SMSC) address. This API uses an asynchron ```js let slotId = 0; let smscAddr = '+861xxxxxxxxxx'; -sms.setSmscAddr(slotId, smscAddr, (err,data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sms.setSmscAddr(slotId, smscAddr, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -314,6 +333,8 @@ Sets the SMSC address. This API uses a promise to return the result. **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -329,9 +350,9 @@ Sets the SMSC address. This API uses a promise to return the result. let slotId = 0; let smscAddr = '+861xxxxxxxxxx'; let promise = sms.setSmscAddr(slotId, smscAddr); -promise.then(data => { - console.log(`setSmscAddr success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`setSmscAddr success.`); +}).catch((err) => { console.error(`setSmscAddr failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -358,6 +379,8 @@ Obtains the SMSC address. This API uses an asynchronous callback to return the r **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -403,6 +426,8 @@ Obtains the SMSC address. This API uses a promise to return the result. **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -464,6 +489,8 @@ Splits an SMS message into multiple segments. This API uses an asynchronous call **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -509,6 +536,8 @@ Splits an SMS message into multiple segments. This API uses a promise to return **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -551,6 +580,8 @@ Adds a SIM message. This API uses an asynchronous callback to return the result. **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -569,8 +600,8 @@ let simMessageOptions = { pdu: "xxxxxx", status: sms.SimMessageStatus.SIM_MESSAGE_STATUS_READ }; -sms.addSimMessage(simMessageOptions, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sms.addSimMessage(simMessageOptions, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -601,6 +632,8 @@ Adds a SIM message. This API uses a promise to return the result. **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -620,9 +653,9 @@ let simMessageOptions = { status: sms.SimMessageStatus.SIM_MESSAGE_STATUS_READ }; let promise = sms.addSimMessage(simMessageOptions); -promise.then(data => { - console.log(`addSimMessage success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`addSimMessage success.`); +}).catch((err) => { console.error(`addSimMessage failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -649,6 +682,8 @@ Deletes a SIM message. This API uses an asynchronous callback to return the resu **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -663,8 +698,8 @@ Deletes a SIM message. This API uses an asynchronous callback to return the resu ```js let slotId = 0; let msgIndex = 1; -sms.delSimMessage(slotId, msgIndex, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sms.delSimMessage(slotId, msgIndex, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -696,6 +731,8 @@ Deletes a SIM message. This API uses a promise to return the result. **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -711,9 +748,9 @@ Deletes a SIM message. This API uses a promise to return the result. let slotId = 0; let msgIndex = 1; let promise = sms.delSimMessage(slotId, msgIndex); -promise.then(data => { - console.log(`delSimMessage success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`delSimMessage success.`); +}).catch((err) => { console.error(`delSimMessage failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -739,6 +776,8 @@ Updates a SIM message. This API uses an asynchronous callback to return the resu **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -758,8 +797,8 @@ let updateSimMessageOptions = { pdu: "xxxxxxx", smsc: "test" }; -sms.updateSimMessage(updateSimMessageOptions, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sms.updateSimMessage(updateSimMessageOptions, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -790,6 +829,8 @@ Updates a SIM message. This API uses a promise to return the result. **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -810,9 +851,9 @@ let updateSimMessageOptions = { smsc: "test" }; let promise = sms.updateSimMessage(updateSimMessageOptions); -promise.then(data => { - console.log(`updateSimMessage success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`updateSimMessage success.`); +}).catch((err) => { console.error(`updateSimMessage failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -838,6 +879,8 @@ Obtains all SIM card messages. This API uses an asynchronous callback to return **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -883,6 +926,8 @@ Obtains all SIM card messages. This API uses a promise to return the result. **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -925,6 +970,8 @@ Sets the cell broadcast configuration. This API uses an asynchronous callback to **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -944,8 +991,8 @@ let cbConfigOptions = { endMessageId: 200, ranType: sms.RanType.TYPE_GSM }; -sms.setCBConfig(cbConfigOptions, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +sms.setCBConfig(cbConfigOptions, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -976,6 +1023,8 @@ Sets the cell broadcast configuration. This API uses a promise to return the res **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -996,9 +1045,9 @@ let cbConfigOptions = { ranType: sms.RanType.TYPE_GSM }; let promise = sms.setCBConfig(cbConfigOptions); -promise.then(data => { - console.log(`setCBConfig success, promise: data->${JSON.stringify(data)}`); -}).catch(err => { +promise.then(() => { + console.log(`setCBConfig success.`); +}).catch((err) => { console.error(`setCBConfig failed, promise: err->${JSON.stringify(err)}`); }); ``` @@ -1024,6 +1073,8 @@ Obtains SMS message segment information. This API uses an asynchronous callback **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -1068,6 +1119,8 @@ Obtains SMS message segment information. This API uses a promise to return the r **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -1107,6 +1160,8 @@ Checks whether SMS is supported on IMS. This API uses an asynchronous callback t **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -1149,6 +1204,8 @@ This API uses an asynchronous callback to return the result. This API uses a pro **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -1187,9 +1244,10 @@ Obtains the SMS format supported by the IMS. This API uses an asynchronous callb **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | -| 201 | Permission denied. | | 401 | Parameter error. | | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | @@ -1223,9 +1281,10 @@ Obtains the SMS format supported by the IMS. This API uses a promise to return t **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | -| 201 | Permission denied. | | 401 | Parameter error. | | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | @@ -1262,6 +1321,8 @@ Decodes MMS messages. This API uses an asynchronous callback to return the resul **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -1304,6 +1365,8 @@ Decodes MMS messages. This API uses a promise to return the result. **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -1343,6 +1406,8 @@ MMS message code. This API uses an asynchronous callback to return the result. **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | @@ -1393,6 +1458,8 @@ MMS message code. This API uses a promise to return the result. **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 401 | Parameter error. | diff --git a/en/application-dev/reference/apis/js-apis-telephony-data.md b/en/application-dev/reference/apis/js-apis-telephony-data.md index 4521aa0eac78b15b8c5644b53aac44fc59b2f648..7e244574143dd04bedd6c8f74a6206b0263f7584 100644 --- a/en/application-dev/reference/apis/js-apis-telephony-data.md +++ b/en/application-dev/reference/apis/js-apis-telephony-data.md @@ -100,6 +100,8 @@ Sets the default slot of the SIM card used for mobile data. This API uses an asy **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -114,8 +116,8 @@ Sets the default slot of the SIM card used for mobile data. This API uses an asy **Example** ```js -data.setDefaultCellularDataSlotId(0, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +data.setDefaultCellularDataSlotId(0, (err) => { + console.log(`callback: err->${JSON.stringify(err)}.`); }); ``` @@ -145,6 +147,8 @@ Sets the default slot of the SIM card used for mobile data. This API uses a prom **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -160,8 +164,8 @@ Sets the default slot of the SIM card used for mobile data. This API uses a prom ```js let promise = data.setDefaultCellularDataSlotId(0); -promise.then((data) => { - console.log(`setDefaultCellularDataSlotId success, promise: data->${JSON.stringify(data)}`); +promise.then(() => { + console.log(`setDefaultCellularDataSlotId success.`); }).catch((err) => { console.error(`setDefaultCellularDataSlotId fail, promise: err->${JSON.stringify(err)}`); }); @@ -279,6 +283,8 @@ Checks whether the cellular data service is enabled. This API uses an asynchrono **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -314,6 +320,8 @@ Checks whether the cellular data service is enabled. This API uses a promise to **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -353,6 +361,8 @@ Checks whether roaming is enabled for the cellular data service. This API uses a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -394,6 +404,8 @@ Checks whether roaming is enabled for the cellular data service. This API uses a **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -434,6 +446,8 @@ Enables the cellular data service. This API uses an asynchronous callback to ret **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -446,8 +460,8 @@ Enables the cellular data service. This API uses an asynchronous callback to ret **Example** ```js -data.enableCellularData((err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +data.enableCellularData((err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -471,6 +485,8 @@ Enables the cellular data service. This API uses a promise to return the result. **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -484,8 +500,8 @@ Enables the cellular data service. This API uses a promise to return the result. ```js let promise = data.enableCellularData(); -promise.then((data) => { - console.log(`enableCellularData success, promise: data->${JSON.stringify(data)}`); +promise.then(() => { + console.log(`enableCellularData success.`); }).catch((err) => { console.error(`enableCellularData fail, promise: err->${JSON.stringify(err)}`); }); @@ -511,6 +527,8 @@ Disables the cellular data service. This API uses an asynchronous callback to re **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -523,8 +541,8 @@ Disables the cellular data service. This API uses an asynchronous callback to re **Example** ```js -data.disableCellularData((err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +data.disableCellularData((err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -548,6 +566,8 @@ Disables the cellular data service. This API uses a promise to return the result **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -561,8 +581,8 @@ Disables the cellular data service. This API uses a promise to return the result ```js let promise = data.disableCellularData(); -promise.then((data) => { - console.log(`disableCellularData success, promise: data->${JSON.stringify(data)}`); +promise.then(() => { + console.log(`disableCellularData success.`); }).catch((err) => { console.error(`disableCellularData fail, promise: err->${JSON.stringify(err)}`); }); @@ -589,6 +609,8 @@ Enables the cellular data roaming service. This API uses an asynchronous callbac **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -601,8 +623,8 @@ Enables the cellular data roaming service. This API uses an asynchronous callbac **Example** ```js -data.enableCellularDataRoaming(0, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +data.enableCellularDataRoaming(0, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -632,6 +654,8 @@ Enables the cellular data roaming service. This API uses a promise to return the **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -645,8 +669,8 @@ Enables the cellular data roaming service. This API uses a promise to return the ```js let promise = data.enableCellularDataRoaming(0); -promise.then((data) => { - console.log(`enableCellularDataRoaming success, promise: data->${JSON.stringify(data)}`); +promise.then(() => { + console.log(`enableCellularDataRoaming success.`); }).catch((err) => { console.error(`enableCellularDataRoaming fail, promise: err->${JSON.stringify(err)}`); }); @@ -673,6 +697,8 @@ Disables the cellular data roaming service. This API uses an asynchronous callba **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -685,8 +711,8 @@ Disables the cellular data roaming service. This API uses an asynchronous callba **Example** ```js -data.disableCellularDataRoaming(0, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +data.disableCellularDataRoaming(0, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); }); ``` @@ -716,6 +742,8 @@ Disables the cellular data roaming service. This API uses a promise to return th **Error codes** +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + | ID| Error Message | | -------- | -------------------------------------------- | | 201 | Permission denied. | @@ -729,8 +757,8 @@ Disables the cellular data roaming service. This API uses a promise to return th ```js let promise = data.disableCellularDataRoaming(0); -promise.then((data) => { - console.log(`disableCellularDataRoaming success, promise: data->${JSON.stringify(data)}`); +promise.then(() => { + console.log(`disableCellularDataRoaming success.`); }).catch((err) => { console.error(`disableCellularDataRoaming fail, promise: err->${JSON.stringify(err)}`); }); diff --git a/en/device-dev/subsystems/Readme-EN.md b/en/device-dev/subsystems/Readme-EN.md index 3c97fc6d362ffb32a79bab32490658047cde7aad..48abe9e925388d38780f85266985ff7532988f89 100644 --- a/en/device-dev/subsystems/Readme-EN.md +++ b/en/device-dev/subsystems/Readme-EN.md @@ -50,10 +50,6 @@ - [Sensor Overview](subsys-sensor-overview.md) - [Sensor Usage Guidelines](subsys-sensor-guide.md) - [Sensor Usage Example](subsys-sensor-demo.md) -- USB - - [USB Overview](subsys-usbservice-overview.md) - - [USB Usage Guidelines](subsys-usbservice-guide.md) - - [USB Usage Example](subsys-usbservice-demo.md) - Application Framework - [Application Framework Overview](subsys-application-framework-overview.md) - [Setting Up a Development Environment](subsys-application-framework-envbuild.md) diff --git a/en/device-dev/subsystems/subsys-usbservice-demo.md b/en/device-dev/subsystems/subsys-usbservice-demo.md deleted file mode 100644 index e78028f32a2f5b20d27267809d35b6bdcd1a0369..0000000000000000000000000000000000000000 --- a/en/device-dev/subsystems/subsys-usbservice-demo.md +++ /dev/null @@ -1,185 +0,0 @@ -# USB Usage Example - - -```cpp -#include -#include -#include -#include -#include -#include -#include "if_system_ability_manager.h" -#include "ipc_skeleton.h" -#include "iremote_object.h" -#include "iservice_registry.h" -#include "iusb_srv.h" -#include "string_ex.h" -#include "system_ability_definition.h" -#include "usb_common.h" -#include "usb_device.h" -#include "usb_errors.h" -#include "usb_request.h" -#include "usb_server_proxy.h" -#include "usb_srv_client.h" - -const int32_t REQUESTYPE = ((1 << 7) | (0 << 5) | (0 & 0x1f)); -const int32_t REQUESTCMD = 6; -const int32_t VALUE = (2 << 8) + 0; -const int32_t TIMEOUT = 5000; -const int32_t ITFCLASS = 10; -const int32_t PRAMATYPE = 2; -const int32_t BUFFERLENGTH = 21; - -void GetType(OHOS::USB::USBEndpoint &tep, OHOS::USB::USBEndpoint &outEp, bool &outEpFlg) -{ - if ((tep.GetType() == PRAMATYPE)) { - if (tep.GetDirection() == 0) { - outEp = tep; - outEpFlg = true; - } - } -} - -bool SelectEndpoint(OHOS::USB::USBConfig config, - std::vector interfaces, - OHOS::USB::UsbInterface &interface, - OHOS::USB::USBEndpoint &outEp, - bool &outEpFlg) -{ - for (int32_t i = 0; i < config.GetInterfaceCount(); ++i) { - OHOS::USB::UsbInterface tif = interfaces[i]; - std::vector mEndpoints = tif.GetEndpoints(); - for (int32_t j = 0; j < tif.GetEndpointCount(); ++j) { - OHOS::USB::USBEndpoint tep = mEndpoints[j]; - if ((tif.GetClass() == ITFCLASS) && (tif.GetSubClass() == 0) && (tif.GetProtocol() == PRAMATYPE)) { - GetType(tep, outEp, outEpFlg); - } - } - if (outEpFlg) { - interface = interfaces[i]; - return true; - } - std::cout << std::endl; - } - return false; -} - -int OpenDeviceTest(OHOS::USB::UsbSrvClient &Instran, OHOS::USB::UsbDevice device, OHOS::USB::USBDevicePipe &pip) -{ - int ret = Instran.RequestRight(device.GetName()); - std::cout << "device RequestRight ret = " << ret << std::endl; - if (0 != ret) { - std::cout << "device RequestRight failed = " << ret << std::endl; - } - ret = Instran.OpenDevice(device, pip); - return ret; -} - -int CtrTransferTest(OHOS::USB::UsbSrvClient &Instran, OHOS::USB::USBDevicePipe &pip) -{ - std::cout << "usb_device_test : << Control Transfer >> " << std::endl; - std::vector vData; - const OHOS::USB::UsbCtrlTransfer tctrl = {REQUESTYPE, REQUESTCMD, VALUE, 0, TIMEOUT}; - int ret = Instran.ControlTransfer(pip, tctrl, vData); - if (ret != 0) { - std::cout << "control message read failed width ret = " << ret << std::endl; - } else { - } - std::cout << "control message read success" << std::endl; - - return ret; -} - -int ClaimTest(OHOS::USB::UsbSrvClient &Instran, - OHOS::USB::USBDevicePipe &pip, - OHOS::USB::UsbInterface &interface, - bool interfaceFlg) -{ - if (interfaceFlg) { - std::cout << "ClaimInterface InterfaceInfo:" << interface.ToString() << std::endl; - int ret = Instran.ClaimInterface(pip, interface, true); - if (ret != 0) { - std::cout << "ClaimInterface failed width ret = " << ret << std::endl; - } else { - std::cout << "ClaimInterface success" << std::endl; - } - } - return 0; -} - -int BulkTransferTest(OHOS::USB::UsbSrvClient &Instran, - OHOS::USB::USBDevicePipe &pip, - OHOS::USB::USBEndpoint &outEp, - bool interfaceFlg, - bool outEpFlg) -{ - if (interfaceFlg) { - std::cout << "usb_device_test : << Bulk transfer start >> " << std::endl; - if (outEpFlg) { - uint8_t buffer[50] = "hello world 123456789"; - std::vector vData(buffer, buffer + BUFFERLENGTH); - int ret = Instran.BulkTransfer(pip, outEp, vData, TIMEOUT); - if (ret != 0) { - std::cout << "Bulk transfer write failed width ret = " << ret << std::endl; - } else { - std::cout << "Bulk transfer write success" << std::endl; - } - return ret; - } - } - return 0; -} - -int main(int argc, char **argv) -{ - std::cout << "usb_device_test " << std::endl; - static OHOS::USB::UsbSrvClient &Instran = OHOS::USB::UsbSrvClient::GetInstance(); - // GetDevices - std::vector deviceList; - int32_t ret = Instran.GetDevices(deviceList); - if (ret != 0) { - return OHOS::USB::UEC_SERVICE_INVALID_VALUE; - } - if (deviceList.empty()) { - return OHOS::USB::UEC_SERVICE_INVALID_VALUE; - } - - OHOS::USB::UsbDevice device = deviceList[0]; - std::vector configs = device.GetConfigs(); - OHOS::USB::USBConfig config = configs[0]; - std::vector interfaces = config.GetInterfaces(); - OHOS::USB::UsbInterface interface; - OHOS::USB::USBEndpoint outEp; - bool interfaceFlg = false; - bool outEpFlg = false; - interfaceFlg = SelectEndpoint(config, interfaces, interface, outEp, outEpFlg); - - // OpenDevice - std::cout << "usb_device_test : << OpenDevice >> test begin -> " << std::endl; - OHOS::USB::USBDevicePipe pip; - ret = OpenDeviceTest(Instran, device, pip); - if (ret != 0) { - return OHOS::USB::UEC_SERVICE_INVALID_VALUE; - } - - // ControlTransfer - CtrTransferTest(Instran, pip); - - // ClaimInterface - ClaimTest(Instran, pip, interface, interfaceFlg); - - // BulkTransferWrite - BulkTransferTest(Instran, pip, outEp, interfaceFlg, outEpFlg); - - // CloseDevice - std::cout << "usb_device_test : << Close Device >> " << std::endl; - ret = Instran.Close(pip); - if (ret == 0) { - std::cout << "Close device failed width ret = " << ret << std::endl; - return OHOS::USB::UEC_SERVICE_INVALID_VALUE; - } else { - std::cout << "Close Device success" << std::endl; - } - return 0; -} -``` diff --git a/en/device-dev/subsystems/subsys-usbservice-guide.md b/en/device-dev/subsystems/subsys-usbservice-guide.md deleted file mode 100644 index 8f95d32cb3f671474f961ffc728729a86585c6dd..0000000000000000000000000000000000000000 --- a/en/device-dev/subsystems/subsys-usbservice-guide.md +++ /dev/null @@ -1,55 +0,0 @@ -# USB Usage Guidelines - - -The following procedure uses bulk transfer as an example. - -## Procedure - -1. Obtain a USB service instance. - -```cpp -static OHOS::USB::UsbSrvClient &g_usbClient = OHOS::USB::UsbSrvClient::GetInstance(); -``` - -2. Obtain the USB device list. - -```cpp -std::vector deviceList; -int32_t ret = g_usbClient.GetDevices(deviceList); -``` - -3. Apply for device access permissions. - -```cpp -int32_t ret = g_usbClient.RequestRight(device.GetName()); -``` - -4. Open the USB device. - -```cpp -USBDevicePipe pip; -int32_t et = g_usbClient.OpenDevice(device, pip); -``` - -5. Configure the USB interface. - -```cpp -ret = g_usbClient.ClaimInterface(pip, interface, true); // **interface** indicates an interface of the USB device in **deviceList**. -``` - -6. Transfer data. - -```cpp -srvClient.BulkTransfer(pipe, endpoint, vdata, timeout); -``` -Parameter description: -- **pipe**: pipe for data transfer of the USB device opened. -- **endpoint**: endpoint for data transfer on the USB device. -- **vdata**: binary data block to be transferred or read. -- **timeout**: timeout duration of data transfer. - -7. Close the USB device. - -```cpp -ret = g_usbClient.Close(pip); -``` diff --git a/en/device-dev/subsystems/subsys-usbservice-overview.md b/en/device-dev/subsystems/subsys-usbservice-overview.md deleted file mode 100644 index e4cc9c9ccd95ee4f8d72f949b778360cae860c1a..0000000000000000000000000000000000000000 --- a/en/device-dev/subsystems/subsys-usbservice-overview.md +++ /dev/null @@ -1,338 +0,0 @@ -# USB - -## Introduction - -### Function Description - -USB devices are classified into two types: USB host and USB device. On OpenHarmony, you can use the port service to switch between the host mode and device mode. In host mode, you can obtain the list of connected USB devices, manage device access permissions, and perform bulk transfer or control transfer between the host and connected devices. In device mode, you can switch between functions including HDC (debugging), ACM (serial port), and ECM (Ethernet port). - -### Basic Concepts - -- USB service - - An abstraction of underlying hardware-based USB devices. Your application can access the USB devices via the USB service. With the APIs provided by the USB service, you can obtain the list of connected USB devices, manage device access permissions, and perform data transfer or control transfer between the host and connected devices. - -- USB API - - A collection of JS APIs provided for the upper layer through NAPI. Your application can use USB APIs to implement various basic functions, for example, query of the USB device list, USB device plug notification, USB host and device mode switching, bulk transfer, control transfer, right management, and function switching in device mode. - -- USB Service layer - - A layer implemented by using the C++ programming language. It consists of four modules: Host, Device, Port, and Right. HDI-based APIs provided by USB Service are mainly used to implement management of USB device list, USB functions, USB ports, and USB device access permissions. The USB Service layer interacts with the HAL layer to receive, parse, and distribute data, manages foreground and background policies, and performs USB device management and right control. - -- USB HAL layer - - A layer implemented by using the C programming language. Based on the Host Driver Development Kit (SDK) and Device DDK, USB HAL encapsulates basic USB device operations, provides C++ APIs for the upper layer, and receives information from the kernel through the Hardware Driver Foundation (HDF) framework. - -### Working Principles - -The USB subsystem logically consists of three parts: USB API, USB Service, and USB HAL. The following figure shows how the USB service is implemented. - - **Figure 1** USB service architecture - ![USB service architecture](figures/en-us_image_0000001267088285.png) - -- USB API: provides USB APIs that implement various basic functions, for example, query of the USB device list, bulk data transfer, control transfer, and right management. - -- USB Service: receives, parses, and distributes Hardware Abstraction Layer (HAL) data, manages and controls foreground and background policies, and manages devices. - -- USB HAL: provides driver capability APIs that can be directly called in user mode. - -## Usage Guidelines - -### When to Use - -In Host mode, you can obtain the list of connected devices, enable or disable the devices, manage device access permissions, and perform data transfer or control transfer. - -### APIs - - **Table 1** Host-specific APIs - -| API | Description | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| int32_t OpenDevice(const UsbDevice &device, USBDevicePipe &pip); | Opens a USB device to set up a connection. | -| bool HasRight(std::string deviceName); | Checks whether the application has the permission to access the device. | -| int32_t RequestRight(std::string deviceName); | Requests the temporary permission for a given application to access the USB device. | -| int32_t GetDevices(std::vector &deviceList); | Obtains the USB device list. | -| int32_t ClaimInterface(USBDevicePipe &pip, const UsbInterface &interface, bool force); | Claims a USB interface exclusively. This must be done before data transfer. | -| int32_t ReleaseInterface(USBDevicePipe &pip, const UsbInterface &interface); | Releases a USB interface. This is usually done after data transfer. | -| int32_t BulkTransfer(USBDevicePipe &pip, const USBEndpoint &endpoint, std::vector &vdata, int32_t timeout); | Performs a bulk transfer on a specified endpoint. The data transfer direction is determined by the endpoint direction.| -| int32_t ControlTransfer(USBDevicePipe &pip, const UsbCtrlTransfer &ctrl, std::vector &vdata); | Performs control transfer for endpoint 0 of the device. The data transfer direction is determined by the request type. | -| int32_t SetConfiguration(USBDevicePipe &pip, const USBConfig &config); | Sets the current configuration of the USB device. | -| int32_t SetInterface(USBDevicePipe &pipe, const UsbInterface &interface); | Sets the alternate settings for the specified USB interface. This allows you to switch between two interfaces with the same ID but different alternate settings.| -| int32_t GetRawDescriptors(std::vector &vdata); | Obtains the raw USB descriptor. | -| int32_t GetFileDescriptor(); | Obtains the file descriptor. | -| bool Close(const USBDevicePipe &pip); | Closes a USB device to release all system resources related to the device. | -| int32_t PipeRequestWait(USBDevicePipe &pip, int64_t timeout, UsbRequest &req); | Obtains the isochronous transfer result. | -| int32_t RequestInitialize(UsbRequest &request); | Initializes the isochronous transfer request. | -| int32_t RequestFree(UsbRequest &request); | Frees the isochronous transfer request. | -| int32_t RequestAbort(UsbRequest &request); | Cancels the data transfer request to be processed. | -| int32_t RequestQueue(UsbRequest &request); | Sends or receives requests for isochronous transfer on a specified endpoint. The data transfer direction is determined by the endpoint direction.| -| int32_t RegBulkCallback(USBDevicePipe &pip, const USBEndpoint &endpoint, const sptr &cb); | Registers an asynchronous callback for bulk transfer. | -| int32_t UnRegBulkCallback(USBDevicePipe &pip, const USBEndpoint &endpoint); | Unregisters the asynchronous callback for bulk transfer. | -| int32_t BulkRead(USBDevicePipe &pip, const USBEndpoint &endpoint, sptr &ashmem); | Reads data asynchronously during bulk transfer. | -| int32_t BulkWrite(USBDevicePipe &pip, const USBEndpoint &endpoint, sptr &ashmem); | Writes data asynchronously during bulk transfer. | -| int32_t BulkCancel(USBDevicePipe &pip, const USBEndpoint &endpoint); | Cancels bulk transfer. The asynchronous read and write operations on the current USB interface will be cancelled. | - - **Table 2** Device-specific APIs - -| API | Description | -| -------------------------------------------------- | ------------------------------------------------------ | -| int32_t GetCurrentFunctions(int32_t &funcs); | Obtains the numeric mask combination for the current USB function list in Device mode. | -| int32_t SetCurrentFunctions(int32_t funcs); | Sets the current USB function list in Device mode. | -| int32_t UsbFunctionsFromString(std::string funcs); | Converts the string descriptor of a given USB function list to a numeric mask combination.| -| std::string UsbFunctionsToString(int32_t funcs); | Converts the numeric mask combination of a given USB function list to a string descriptor.| - - **Table 3** Port-specific APIs - -| API | Description | -| ------------------------------------------------------------ | -------------------------------------------------------- | -| int32_t GetSupportedModes(int32_t portId, int32_t &supportedModes); | Obtains the mask combination for the supported mode list of a given port. | -| int32_t SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole); | Sets the role types supported by a specified port, which can be **powerRole** (for charging) and **dataRole** (for data transfer).| -| int32_t GetPorts(std::vector &usbPorts); | Obtains the USB port descriptor list. | - -### How to Use - -The following uses bulk transfer as an example to illustrate the development procedure. - -1. Obtain a USB service instance. - - ```cpp - static OHOS::USB::UsbSrvClient &g_usbClient = OHOS::USB::UsbSrvClient::GetInstance(); - ``` - -2. Obtain the USB device list. - - ```cpp - std::vector deviceList; - int32_t ret = g_usbClient.GetDevices(deviceList); - ``` - -3. Apply for device access permissions. - - ```cpp - int32_t ret = g_usbClient.RequestRight(device.GetName()); - ``` - -4. Open a camera device. - - ```cpp - USBDevicePipe pip; - int32_t et = g_usbClient.OpenDevice(device, pip); - ``` - -5. Configure the USB interface. - - ```cpp - // interface indicates an interface of the USB device in deviceList. - ret = g_usbClient.ClaimInterface(pip, interface, true); - ``` - -6. Perform data transfer. - - ```cpp - // pipe indicates the pipe for data transfer after the USB device is opened. endpoint indicates the endpoint for data transfer on the USB device. vdata indicates the binary data block to be transferred or read. timeout indicates the timeout duration of data transfer. - srvClient.BulkTransfer(pipe, endpoint, vdata, timeout); - ``` - -7. Closes a device. - - ```cpp - ret = g_usbClient.Close(pip); - ``` - -### Sample Code - -```cpp -#include -#include -#include -#include -#include -#include -#include "if_system_ability_manager.h" -#include "ipc_skeleton.h" -#include "iremote_object.h" -#include "iservice_registry.h" -#include "iusb_srv.h" -#include "string_ex.h" -#include "system_ability_definition.h" -#include "usb_common.h" -#include "usb_device.h" -#include "usb_errors.h" -#include "usb_request.h" -#include "usb_server_proxy.h" -#include "usb_srv_client.h" - -const int32_t REQUESTYPE = ((1 << 7) | (0 << 5) | (0 & 0x1f)); -const int32_t REQUESTCMD = 6; -const int32_t VALUE = (2 << 8) + 0; -const int32_t TIMEOUT = 5000; -const int32_t ITFCLASS = 10; -const int32_t PRAMATYPE = 2; -const int32_t BUFFERLENGTH = 21; - -void GetType(OHOS::USB::USBEndpoint &tep, OHOS::USB::USBEndpoint &outEp, bool &outEpFlg) -{ - if ((tep.GetType() == PRAMATYPE)) { - if (tep.GetDirection() == 0) { - outEp = tep; - outEpFlg = true; - } - } -} - -bool SelectEndpoint(OHOS::USB::USBConfig config, - std::vector interfaces, - OHOS::USB::UsbInterface &interface, - OHOS::USB::USBEndpoint &outEp, - bool &outEpFlg) -{ - for (int32_t i = 0; i < config.GetInterfaceCount(); ++i) { - OHOS::USB::UsbInterface tif = interfaces[i]; - std::vector mEndpoints = tif.GetEndpoints(); - for (int32_t j = 0; j < tif.GetEndpointCount(); ++j) { - OHOS::USB::USBEndpoint tep = mEndpoints[j]; - if ((tif.GetClass() == ITFCLASS) && (tif.GetSubClass() == 0) && (tif.GetProtocol() == PRAMATYPE)) { - GetType(tep, outEp, outEpFlg); - } - } - if (outEpFlg) { - interface = interfaces[i]; - return true; - } - std::cout << std::endl; - } - return false; -} - -int OpenDeviceTest(OHOS::USB::UsbSrvClient &Instran, OHOS::USB::UsbDevice device, OHOS::USB::USBDevicePipe &pip) -{ - int ret = Instran.RequestRight(device.GetName()); - std::cout << "device RequestRight ret = " << ret << std::endl; - if (0 != ret) { - std::cout << "device RequestRight failed = " << ret << std::endl; - } - ret = Instran.OpenDevice(device, pip); - return ret; -} - -int CtrTransferTest(OHOS::USB::UsbSrvClient &Instran, OHOS::USB::USBDevicePipe &pip) -{ - std::cout << "usb_device_test : << Control Transfer >> " << std::endl; - std::vector vData; - const OHOS::USB::UsbCtrlTransfer tctrl = {REQUESTYPE, REQUESTCMD, VALUE, 0, TIMEOUT}; - int ret = Instran.ControlTransfer(pip, tctrl, vData); - if (ret != 0) { - std::cout << "control message read failed width ret = " << ret << std::endl; - } else { - } - std::cout << "control message read success" << std::endl; - - return ret; -} - -int ClaimTest(OHOS::USB::UsbSrvClient &Instran, - OHOS::USB::USBDevicePipe &pip, - OHOS::USB::UsbInterface &interface, - bool interfaceFlg) -{ - if (interfaceFlg) { - std::cout << "ClaimInterface InterfaceInfo:" << interface.ToString() << std::endl; - int ret = Instran.ClaimInterface(pip, interface, true); - if (ret != 0) { - std::cout << "ClaimInterface failed width ret = " << ret << std::endl; - } else { - std::cout << "ClaimInterface success" << std::endl; - } - } - return 0; -} - -int BulkTransferTest(OHOS::USB::UsbSrvClient &Instran, - OHOS::USB::USBDevicePipe &pip, - OHOS::USB::USBEndpoint &outEp, - bool interfaceFlg, - bool outEpFlg) -{ - if (interfaceFlg) { - std::cout << "usb_device_test : << Bulk transfer start >> " << std::endl; - if (outEpFlg) { - uint8_t buffer[50] = "hello world 123456789"; - std::vector vData(buffer, buffer + BUFFERLENGTH); - int ret = Instran.BulkTransfer(pip, outEp, vData, TIMEOUT); - if (ret != 0) { - std::cout << "Bulk transfer write failed width ret = " << ret << std::endl; - } else { - std::cout << "Bulk transfer write success" << std::endl; - } - return ret; - } - } - return 0; -} - -int main(int argc, char **argv) -{ - std::cout << "usb_device_test " << std::endl; - static OHOS::USB::UsbSrvClient &Instran = OHOS::USB::UsbSrvClient::GetInstance(); - // GetDevices - std::vector deviceList; - int32_t ret = Instran.GetDevices(deviceList); - if (ret != 0) { - return OHOS::USB::UEC_SERVICE_INVALID_VALUE; - } - if (deviceList.empty()) { - return OHOS::USB::UEC_SERVICE_INVALID_VALUE; - } - - OHOS::USB::UsbDevice device = deviceList[0]; - std::vector configs = device.GetConfigs(); - OHOS::USB::USBConfig config = configs[0]; - std::vector interfaces = config.GetInterfaces(); - OHOS::USB::UsbInterface interface; - OHOS::USB::USBEndpoint outEp; - bool interfaceFlg = false; - bool outEpFlg = false; - interfaceFlg = SelectEndpoint(config, interfaces, interface, outEp, outEpFlg); - - // OpenDevice - std::cout << "usb_device_test : << OpenDevice >> test begin -> " << std::endl; - OHOS::USB::USBDevicePipe pip; - ret = OpenDeviceTest(Instran, device, pip); - if (ret != 0) { - return OHOS::USB::UEC_SERVICE_INVALID_VALUE; - } - - // ControlTransfer - CtrTransferTest(Instran, pip); - - // ClaimInterface - ClaimTest(Instran, pip, interface, interfaceFlg); - - // BulkTransferWrite - BulkTransferTest(Instran, pip, outEp, interfaceFlg, outEpFlg); - - // CloseDevice - std::cout << "usb_device_test : << Close Device >> " << std::endl; - ret = Instran.Close(pip); - if (ret == 0) { - std::cout << "Close device failed width ret = " << ret << std::endl; - return OHOS::USB::UEC_SERVICE_INVALID_VALUE; - } else { - std::cout << "Close Device success" << std::endl; - } - return 0; -} -``` - -### Repositories Involved - -[Driver subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/driver.md) - -[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral/blob/master/README_zh.md) - -[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md) - -[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README_zh.md) - -[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md)