提交 02ff519d 编写于 作者: Mr-YX's avatar Mr-YX 提交者: Gitee

Merge branch 'master' of gitee.com:openharmony/docs into master

Signed-off-by: Mr-YX's avatarmr-yx <496043997@qq.com>
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
## IDL Overview ## IDL Overview
To ensure successful communications between the client and server, interfaces recognized by both parties must be defined. The OpenHarmony Interface Definition Language (IDL) is a tool for defining such interfaces. OpenHarmony IDL decomposes objects to be transferred into primitives that can be understood by the operating system and encapsulates cross-boundary objects based on developers' requirements. To ensure successful communications between the client and server, interfaces recognized by both parties must be defined. The OpenHarmony Interface Definition Language (IDL) is a tool for defining such interfaces. OpenHarmony IDL decomposes objects to be transferred into primitives that can be understood by the operating system and encapsulates cross-boundary objects based on developers' requirements.
**Figure 1** IDL interface description **Figure 1** IDL interface description
![IDL-interface-description](./figures/IDL-interface-description.png) ![IDL-interface-description](./figures/IDL-interface-description.png)
...@@ -29,16 +29,16 @@ IDL has the following advantages: ...@@ -29,16 +29,16 @@ IDL has the following advantages:
#### Primitive Type #### Primitive Type
| IDL Primitive Type| C++ Primitive Type| TS Primitive Type| | IDL Primitive Type| C++ Primitive Type| TS Primitive Type|
| -------- | -------- | -------- | | -------- | -------- | -------- |
|void | void | void | |void | void | void |
|boolean | bool | boolean | |boolean | bool | boolean |
|byte | int8_t | number | |byte | int8_t | number |
|short | int16_t | number | |short | int16_t | number |
|int | int32_t | number | |int | int32_t | number |
|long | int64_t | number | |long | int64_t | number |
|float | float | number | |float | float | number |
|double | double | number | |double | double | number |
|String | std::string | string | |String | std::string | string |
The preceding table lists the primitive types supported by IDL and the mappings to the C++ and TS primitive types. The preceding table lists the primitive types supported by IDL and the mappings to the C++ and TS primitive types.
...@@ -47,29 +47,34 @@ The sequenceable type is declared using the keyword **sequenceable**. This type ...@@ -47,29 +47,34 @@ The sequenceable type is declared using the keyword **sequenceable**. This type
In C++, the declaration is placed in the file header in the format of **sequenceable includedir..namespace.typename**. It can be in any of the following forms: In C++, the declaration is placed in the file header in the format of **sequenceable includedir..namespace.typename**. It can be in any of the following forms:
``` ```cpp
sequenceable includedir..namespace.typename sequenceable includedir..namespace.typename
sequenceable includedir...typename sequenceable includedir...typename
sequenceable namespace.typename sequenceable namespace.typename
``` ```
In the preceding information, **includedir** indicates the directory where the header file of the type is located, and the dot (.) is used as the separator. **namespace** indicates the namespace where the type is located, and the dot (.) is used as the separator. **typename** indicates the data type, which can contain only English characters. **includedir** and **namespace** are separated by two dots (..). If the declaration statement does not contain two dots, all characters except the last typename will be parsed as a namespace. Example: In the preceding information, **includedir** indicates the directory where the header file of the type is located, and the dot (.) is used as the separator. **namespace** indicates the namespace where the type is located, and the dot (.) is used as the separator. **typename** indicates the data type, which can contain only English characters. **includedir** and **namespace** are separated by two dots (..). If the declaration statement does not contain two dots, all characters except the last typename will be parsed as a namespace. Example:
```
```cpp
sequenceable a.b..C.D sequenceable a.b..C.D
``` ```
The preceding statement is parsed into the following code in the C++ header file: The preceding statement is parsed into the following code in the C++ header file:
```
```cpp
#include "a/b/d.h" #include "a/b/d.h"
using C::D; using C::D;
``` ```
In TS, the declaration is placed in the file header in the format of **sequenceable namespace.typename;**. It can be in the following form: In TS, the declaration is placed in the file header in the format of **sequenceable namespace.typename;**. It can be in the following form:
``` ```ts
sequenceable idl.MySequenceable sequenceable idl.MySequenceable
``` ```
In the preceding information, **namespace** indicates the namespace to which the data type belongs, **typename** indicates the data type name, and **MySequenceable** indicates that data can be passed during IPC using **Parcel** objects. The sequenceable type is not defined in the IDL file, but in the .ts file. Therefore, IDL adds the following statement to the generated .ts file based on the declaration: In the preceding information, **namespace** indicates the namespace to which the data type belongs, **typename** indicates the data type name, and **MySequenceable** indicates that data can be passed during IPC using **Parcel** objects. The sequenceable type is not defined in the IDL file, but in the .ts file. Therefore, IDL adds the following statement to the generated .ts file based on the declaration:
``` ```ts
import MySequenceable from "./my_sequenceable" import MySequenceable from "./my_sequenceable"
``` ```
...@@ -80,19 +85,19 @@ The interface type refers to interfaces defined in IDL files. The interfaces def ...@@ -80,19 +85,19 @@ The interface type refers to interfaces defined in IDL files. The interfaces def
The declaration form in C++ is similar to that of the sequenceable type. The declaration form is as follows: The declaration form in C++ is similar to that of the sequenceable type. The declaration form is as follows:
``` ```cpp
interface includedir..namespace.typename interface includedir..namespace.typename
``` ```
In TS, the declaration form is as follows: In TS, the declaration form is as follows:
``` ```ts
interface namespace.interfacename interface namespace.interfacename
``` ```
In the preceding information, **namespace** indicates the namespace to which the interface belongs, and **interfacename** indicates the name of the interface. For example, **interface OHOS.IIdlTestObserver;** declares the **IIdlTestObserver** interface defined in another IDL file. This interface can be used as the parameter type or return value type of a method in the current file. IDL adds the following statement to the generated .ts file based on the statement: In the preceding information, **namespace** indicates the namespace to which the interface belongs, and **interfacename** indicates the name of the interface. For example, **interface OHOS.IIdlTestObserver;** declares the **IIdlTestObserver** interface defined in another IDL file. This interface can be used as the parameter type or return value type of a method in the current file. IDL adds the following statement to the generated .ts file based on the statement:
``` ```ts
import IIdlTestObserver from "./i_idl_test_observer" import IIdlTestObserver from "./i_idl_test_observer"
``` ```
...@@ -100,9 +105,9 @@ import IIdlTestObserver from "./i_idl_test_observer" ...@@ -100,9 +105,9 @@ import IIdlTestObserver from "./i_idl_test_observer"
The array type is represented by T[], where **T** can be the primitive, sequenceable, interface, or array type. In C++, this type is generated as **std::vector&lt;T&gt;**. The array type is represented by T[], where **T** can be the primitive, sequenceable, interface, or array type. In C++, this type is generated as **std::vector&lt;T&gt;**.
The table below lists the mappings between the IDL array type and TS and C++ data types. The table below lists the mappings between the IDL array type and TS and C++ data types.
|IDL Data Type | C++ Data Type | TS Data Type | |IDL Data Type | C++ Data Type | TS Data Type |
| -------- | -------- | -------- | | ------- | -------- | -------- |
|T[] | std::vector&lt;T&gt; | T[] | |T[] | std::vector&lt;T&gt; | T[] |
#### Container Type #### Container Type
IDL supports two container types: List and Map. The List container is represented in the format of **List&lt;T&gt;**. The Map container is represented in the format of **Map<KT,VT>**, where **T**, **KT**, and **VT** can be of the primitive, sequenceable, interface, array, or container type. IDL supports two container types: List and Map. The List container is represented in the format of **List&lt;T&gt;**. The Map container is represented in the format of **Map<KT,VT>**, where **T**, **KT**, and **VT** can be of the primitive, sequenceable, interface, array, or container type.
...@@ -114,26 +119,32 @@ In TS, the List container type is not supported, and the Map container type is g ...@@ -114,26 +119,32 @@ In TS, the List container type is not supported, and the Map container type is g
The table below lists the mappings between the IDL container type and TS and C++ data types. The table below lists the mappings between the IDL container type and TS and C++ data types.
|IDL Data Type | C++ Data Type | TS Data Type | |IDL Data Type | C++ Data Type | TS Data Type |
| -------- | -------- | -------- | | -------- | -------- | ------- |
|List&lt;T&gt; | std::list | Not supported| |List&lt;T&gt; | std::list | Not supported |
|Map<KT,VT> | std::map | Map | |Map<KT,VT> | std::map | Map |
### Specifications for Compiling IDL Files ### Specifications for Compiling IDL Files
Only one interface type can be defined in an IDL file, and the interface name must be the same as the file name. The interface definition of the IDL file is described in Backus-Naur form (BNF). The basic definition format is as follows: Only one interface type can be defined in an IDL file, and the interface name must be the same as the file name. The interface definition of the IDL file is described in Backus-Naur form (BNF). The basic definition format is as follows:
``` ```
[<*interface_attr_declaration*>]interface<*interface_name_with_namespace*>{<*method_declaration*>} [<*interface_attr_declaration*>]interface<*interface_name_with_namespace*>{<*method_declaration*>}
``` ```
In the preceding information, <*interface_attr_declaration*> declares interface attributes. Currently, only the **oneway** attribute is supported, indicating that all methods in the interface are unidirectional. Such a method returns value without waiting for the execution to complete. This attribute is optional. If this attribute is not set, synchronous call is used. The interface name must contain the complete interface header file directory, namespace, and method declaration. Empty interfaces are not allowed. In the preceding information, <*interface_attr_declaration*> declares interface attributes. Currently, only the **oneway** attribute is supported, indicating that all methods in the interface are unidirectional. Such a method returns value without waiting for the execution to complete. This attribute is optional. If this attribute is not set, synchronous call is used. The interface name must contain the complete interface header file directory, namespace, and method declaration. Empty interfaces are not allowed.
The method declaration format in the interface is as follows: The method declaration format in the interface is as follows:
``` ```
[<*method_attr_declaration*>]<*result_type*><*method_declaration*> [<*method_attr_declaration*>]<*result_type*><*method_declaration*>
``` ```
In the preceding information, <*method_attr_declaration*> describes the interface attributes. Currently, only the **oneway** attribute is supported, indicating that the method is unidirectional. Such a method returns value without waiting for the execution to complete. This attribute is optional. If this attribute is not set, synchronous call is used. <*result_type*> indicates the type of the return value, and <*method_declaration*> indicates the method name and parameter declaration. In the preceding information, <*method_attr_declaration*> describes the interface attributes. Currently, only the **oneway** attribute is supported, indicating that the method is unidirectional. Such a method returns value without waiting for the execution to complete. This attribute is optional. If this attribute is not set, synchronous call is used. <*result_type*> indicates the type of the return value, and <*method_declaration*> indicates the method name and parameter declaration.
The parameter declaration format is as follows: The parameter declaration format is as follows:
``` ```
[<*formal_param_attr*>]<*type*><*identifier*> [<*formal_param_attr*>]<*type*><*identifier*>
``` ```
The value of <*formal_param_attr*> can be **in**, **out**, or **inout**, indicating that the parameter is an input parameter, an output parameter, or both an input and an output parameter, respectively. A **oneway** method does not allow **output** or **inout** parameters or return values. The value of <*formal_param_attr*> can be **in**, **out**, or **inout**, indicating that the parameter is an input parameter, an output parameter, or both an input and an output parameter, respectively. A **oneway** method does not allow **output** or **inout** parameters or return values.
## How to Develop ## How to Develop
...@@ -144,20 +155,20 @@ The value of <*formal_param_attr*> can be **in**, **out**, or **inout**, indicat ...@@ -144,20 +155,20 @@ The value of <*formal_param_attr*> can be **in**, **out**, or **inout**, indicat
You can use C++ to create IDL files. An example IDL file is as follows: You can use C++ to create IDL files. An example IDL file is as follows:
``` ```cpp
interface OHOS.IIdlTestService { interface OHOS.IIdlTestService {
int TestIntTransaction([in] int data); int TestIntTransaction([in] int data);
void TestStringTransaction([in] String data); void TestStringTransaction([in] String data);
} }
``` ```
You can run the **./idl -gen-cpp -d dir -c dir/iTest.idl** command (**-d** indicates the output directory) to generate the interface file, stub file, and proxy file in the **dir** directory in the execution environment. The names of the generated interface class files are the same as that of the IDL file, except that the file name extensions are **.h** and **.cpp**. For example, for **IIdlTestService.idl**, the generated files are **i_idl_test_service.h**, **idl_test_service_proxy.h**, **idl_test_service_stub.h**, **idl_test_service_proxy.cpp**, and **idl_test_service_stub.cpp**. You can run the **./idl -gen-cpp -d dir -c dir/iTest.idl** command (**-d** indicates the output directory) to generate the interface file, stub file, and proxy file in the **dir** directory in the execution environment. The names of the generated interface class files are the same as that of the IDL file, except that the file name extensions are **.h** and **.cpp**. For example, the files generated for **IIdlTestService.idl** are **i_idl_test_service.h**, **idl_test_service_proxy.h**, **idl_test_service_stub.h**, **idl_test_service_proxy.cpp**, and **idl_test_service_stub.cpp**.
#### Exposing Interfaces on the Server #### Exposing Interfaces on the Server
The stub class generated by IDL is an abstract implementation of the interface class and declares all methods in the IDL file. The stub class generated by IDL is an abstract implementation of the interface class and declares all methods in the IDL file.
``` ```cpp
#ifndef OHOS_IDLTESTSERVICESTUB_H #ifndef OHOS_IDLTESTSERVICESTUB_H
#define OHOS_IDLTESTSERVICESTUB_H #define OHOS_IDLTESTSERVICESTUB_H
#include <iremote_stub.h> #include <iremote_stub.h>
...@@ -182,7 +193,7 @@ private: ...@@ -182,7 +193,7 @@ private:
You need to inherit the interface class defined in the IDL file and implement the methods in the class. In addition, you need to register the defined services with SAMGR during service initialization. In the following code snippet, **TestService** inherits the **IdlTestServiceStub** interface class and implements the **TestIntTransaction** and **TestStringTransaction** methods. You need to inherit the interface class defined in the IDL file and implement the methods in the class. In addition, you need to register the defined services with SAMGR during service initialization. In the following code snippet, **TestService** inherits the **IdlTestServiceStub** interface class and implements the **TestIntTransaction** and **TestStringTransaction** methods.
``` ```cpp
#ifndef OHOS_IPC_TEST_SERVICE_H #ifndef OHOS_IPC_TEST_SERVICE_H
#define OHOS_IPC_TEST_SERVICE_H #define OHOS_IPC_TEST_SERVICE_H
...@@ -207,7 +218,7 @@ private: ...@@ -207,7 +218,7 @@ private:
The sample code for registering a service is as follows: The sample code for registering a service is as follows:
``` ```cpp
#include "test_service.h" #include "test_service.h"
#include <string_ex.h> #include <string_ex.h>
...@@ -259,12 +270,11 @@ ErrCode TestService::TestStringTransaction(const std::string &data) ...@@ -259,12 +270,11 @@ ErrCode TestService::TestStringTransaction(const std::string &data)
} // namespace OHOS } // namespace OHOS
``` ```
#### Calling Methods from the Client for IPC #### Calling Methods from the Client for IPC
The C++ client obtains the service proxy defined in the system through SAMGR and then invokes the interface provided by the proxy. The sample code is as follows: The C++ client obtains the service proxy defined in the system through SAMGR and then invokes the interface provided by the proxy. The sample code is as follows:
``` ```cpp
#include "test_client.h" #include "test_client.h"
#include "if_system_ability_manager.h" #include "if_system_ability_manager.h"
...@@ -316,16 +326,13 @@ void TestClient::StartStringTransaction() ...@@ -316,16 +326,13 @@ void TestClient::StartStringTransaction()
} // namespace OHOS } // namespace OHOS
``` ```
### Development Using TS ### Development Using TS
#### Creating an IDL File #### Creating an IDL File
You can use TS to create IDL files. An example IDL file is as follows: You can use TS to create IDL files. An example IDL file is as follows:
``` ```ts
interface OHOS.IIdlTestService { interface OHOS.IIdlTestService {
int TestIntTransaction([in] int data); int TestIntTransaction([in] int data);
void TestStringTransaction([in] String data); void TestStringTransaction([in] String data);
...@@ -338,7 +345,7 @@ Run the **./idl -c IIdlTestService.idl -gen-ts -d /data/ts/** command (**-d** in ...@@ -338,7 +345,7 @@ Run the **./idl -c IIdlTestService.idl -gen-ts -d /data/ts/** command (**-d** in
The stub class generated by IDL is an abstract implementation of the interface class and declares all methods in the IDL file. The stub class generated by IDL is an abstract implementation of the interface class and declares all methods in the IDL file.
``` ```ts
import {testIntTransactionCallback} from "./i_idl_test_service"; import {testIntTransactionCallback} from "./i_idl_test_service";
import {testStringTransactionCallback} from "./i_idl_test_service"; import {testStringTransactionCallback} from "./i_idl_test_service";
import IIdlTestService from "./i_idl_test_service"; import IIdlTestService from "./i_idl_test_service";
...@@ -387,7 +394,7 @@ export default class IdlTestServiceStub extends rpc.RemoteObject implements IIdl ...@@ -387,7 +394,7 @@ export default class IdlTestServiceStub extends rpc.RemoteObject implements IIdl
You need to inherit the interface class defined in the IDL file and implement the methods in the class. The following code snippet shows how to inherit the **IdlTestServiceStub** interface class and implement the **testIntTransaction** and **testStringTransaction** methods. You need to inherit the interface class defined in the IDL file and implement the methods in the class. The following code snippet shows how to inherit the **IdlTestServiceStub** interface class and implement the **testIntTransaction** and **testStringTransaction** methods.
``` ```ts
import {testIntTransactionCallback} from "./i_idl_test_service" import {testIntTransactionCallback} from "./i_idl_test_service"
import {testStringTransactionCallback} from "./i_idl_test_service" import {testStringTransactionCallback} from "./i_idl_test_service"
import IdlTestServiceStub from "./idl_test_service_stub" import IdlTestServiceStub from "./idl_test_service_stub"
...@@ -408,7 +415,7 @@ class IdlTestImp extends IdlTestServiceStub { ...@@ -408,7 +415,7 @@ class IdlTestImp extends IdlTestServiceStub {
After the service implements the interface, the interface needs to be exposed to the client for connection. If your service needs to expose this interface, extend **Ability** and implement **onConnect()** to return **IRemoteObject** so that the client can interact with the service process. The following code snippet shows how to expose the **IRemoteAbility** interface to the client: After the service implements the interface, the interface needs to be exposed to the client for connection. If your service needs to expose this interface, extend **Ability** and implement **onConnect()** to return **IRemoteObject** so that the client can interact with the service process. The following code snippet shows how to expose the **IRemoteAbility** interface to the client:
``` ```ts
export default { export default {
onStart() { onStart() {
console.info('ServiceAbility onStart'); console.info('ServiceAbility onStart');
...@@ -442,7 +449,7 @@ export default { ...@@ -442,7 +449,7 @@ export default {
When the client calls **connectAbility()** to connect to a Service ability, the **onConnect** callback in **onAbilityConnectDone** of the client receives the **IRemoteObject** instance returned by the **onConnect()** method of the Service ability. The client and Service ability are in different applications. Therefore, the directory of the client application must contain a copy of the .idl file (the SDK automatically generates the proxy class). The **onConnect** callback then uses the **IRemoteObject** instance to create the **testProxy** instance of the **IdlTestServiceProxy** class and calls the related IPC method. The sample code is as follows: When the client calls **connectAbility()** to connect to a Service ability, the **onConnect** callback in **onAbilityConnectDone** of the client receives the **IRemoteObject** instance returned by the **onConnect()** method of the Service ability. The client and Service ability are in different applications. Therefore, the directory of the client application must contain a copy of the .idl file (the SDK automatically generates the proxy class). The **onConnect** callback then uses the **IRemoteObject** instance to create the **testProxy** instance of the **IdlTestServiceProxy** class and calls the related IPC method. The sample code is as follows:
``` ```ts
import IdlTestServiceProxy from './idl_test_service_proxy' import IdlTestServiceProxy from './idl_test_service_proxy'
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
...@@ -495,7 +502,7 @@ To create a class that supports the sequenceable type, perform the following ope ...@@ -495,7 +502,7 @@ To create a class that supports the sequenceable type, perform the following ope
The following is an example of the **MySequenceable** class code: The following is an example of the **MySequenceable** class code:
``` ```ts
import rpc from '@ohos.rpc'; import rpc from '@ohos.rpc';
export default class MySequenceable { export default class MySequenceable {
constructor(num: number, str: string) { constructor(num: number, str: string) {
...@@ -523,8 +530,6 @@ export default class MySequenceable { ...@@ -523,8 +530,6 @@ export default class MySequenceable {
} }
``` ```
## How to Develop for Interworking Between C++ and TS ## How to Develop for Interworking Between C++ and TS
### TS Proxy and C++ Stub Development ### TS Proxy and C++ Stub Development
...@@ -535,7 +540,7 @@ export default class MySequenceable { ...@@ -535,7 +540,7 @@ export default class MySequenceable {
2. Create a service object, inherit the interface class defined in the C++ stub file, and implement the methods in the class. An example is as follows: 2. Create a service object, inherit the interface class defined in the C++ stub file, and implement the methods in the class. An example is as follows:
``` ```cpp
class IdlTestServiceImpl : public IdlTestServiceStub { class IdlTestServiceImpl : public IdlTestServiceStub {
public: public:
IdlTestServiceImpl() = default; IdlTestServiceImpl() = default;
...@@ -558,7 +563,7 @@ export default class MySequenceable { ...@@ -558,7 +563,7 @@ export default class MySequenceable {
C++ provides C++ service objects to TS in the format of native APIs. For example, C++ provides a **GetNativeObject** method, which is used to create an **IdlTestServiceImpl** instance. Using the **NAPI_ohos_rpc_CreateJsRemoteObject** method, you can create a JS remote object for the TS application. C++ provides C++ service objects to TS in the format of native APIs. For example, C++ provides a **GetNativeObject** method, which is used to create an **IdlTestServiceImpl** instance. Using the **NAPI_ohos_rpc_CreateJsRemoteObject** method, you can create a JS remote object for the TS application.
``` ```cpp
NativeValue* GetNativeObject(NativeEngine& engine, NativeCallbackInfo& info) NativeValue* GetNativeObject(NativeEngine& engine, NativeCallbackInfo& info)
{ {
sptr<IdlTestServiceImpl> impl = new IdlTestServiceImpl(); sptr<IdlTestServiceImpl> impl = new IdlTestServiceImpl();
...@@ -572,8 +577,7 @@ NativeValue* GetNativeObject(NativeEngine& engine, NativeCallbackInfo& info) ...@@ -572,8 +577,7 @@ NativeValue* GetNativeObject(NativeEngine& engine, NativeCallbackInfo& info)
Use TS to construct an IDL file and run commands to generate interfaces, stub files, and proxy files. An example proxy file is as follows: Use TS to construct an IDL file and run commands to generate interfaces, stub files, and proxy files. An example proxy file is as follows:
``` ```ts
import {testIntTransactionCallback} from "./i_idl_test_service"; import {testIntTransactionCallback} from "./i_idl_test_service";
import {testStringTransactionCallback} from "./i_idl_test_service"; import {testStringTransactionCallback} from "./i_idl_test_service";
import IIdlTestService from "./i_idl_test_service"; import IIdlTestService from "./i_idl_test_service";
...@@ -634,7 +638,7 @@ export default class IdlTestServiceProxy implements IIdlTestService { ...@@ -634,7 +638,7 @@ export default class IdlTestServiceProxy implements IIdlTestService {
2. Construct a TS proxy and transfers the remote C++ service object to it. 2. Construct a TS proxy and transfers the remote C++ service object to it.
3. Use the TS proxy to call the method declared in the IDL file to implement the interworking between the TS proxy and C++ stub. The following is an example: 3. Use the TS proxy to call the method declared in the IDL file to implement the interworking between the TS proxy and C++ stub. The following is an example:
``` ```ts
import IdlTestServiceProxy from './idl_test_service_proxy' import IdlTestServiceProxy from './idl_test_service_proxy'
import nativeMgr from 'nativeManager'; import nativeMgr from 'nativeManager';
......
...@@ -74,9 +74,9 @@ The ability assistant enables you to start applications, atomic services, and te ...@@ -74,9 +74,9 @@ The ability assistant enables you to start applications, atomic services, and te
| -l/--mission-list | type (All logs are printed if this parameter is left unspecified.)| Prints mission stack information.<br>The following values are available for **type**:<br>NORMAL <br>DEFAULT_STANDARD<br>DEFAULT_SINGLE<br>LAUNCHER | | -l/--mission-list | type (All logs are printed if this parameter is left unspecified.)| Prints mission stack information.<br>The following values are available for **type**:<br>NORMAL <br>DEFAULT_STANDARD<br>DEFAULT_SINGLE<br>LAUNCHER |
| -e/--extension | elementName | Prints extended component information. | | -e/--extension | elementName | Prints extended component information. |
| -u/--userId | UserId | Prints stack information of a specified user ID. This parameter must be used together with other parameters. Example commands: aa **dump -a -u 100** and **aa dump -d -u 100**.| | -u/--userId | UserId | Prints stack information of a specified user ID. This parameter must be used together with other parameters. Example commands: aa **dump -a -u 100** and **aa dump -d -u 100**.|
| -d/--data | | Prints Data ability information. | | -d/--data | - | Prints Data ability information. |
| -i/--ability | AbilityRecord ID | Prints detailed information about a specified ability. | | -i/--ability | AbilityRecord ID | Prints detailed information about a specified ability. |
| -c/--client | | Prints detailed ability information. This parameter must be used together with other parameters. Example commands: **aa dump -a -c** and **aa dump -i 21 -c**.| | -c/--client | - | Prints detailed ability information. This parameter must be used together with other parameters. Example commands: **aa dump -a -c** and **aa dump -i 21 -c**.|
**Method** **Method**
......
...@@ -6,12 +6,13 @@ ...@@ -6,12 +6,13 @@
The OpenHarmony application framework has two models: Feature Ability (FA) model and stage model. Correspondingly, there are two sets of context mechanisms. **application/BaseContext** is a common context base class. It uses the **stageMode** attribute to specify whether the context is used for the stage model. The OpenHarmony application framework has two models: Feature Ability (FA) model and stage model. Correspondingly, there are two sets of context mechanisms. **application/BaseContext** is a common context base class. It uses the **stageMode** attribute to specify whether the context is used for the stage model.
- FA Model - FA model
Only the methods in **app/Context** can be used for the context in the FA model. Both the application-level context and ability-level context are instances of this type. If an ability-level method is invoked in the application-level context, an error occurs. Therefore, you must pay attention to the actual meaning of the **Context** instance.
- Stage Model
Only the methods in **app/Context** can be used for the context in the FA model. Both the application-level context and ability-level context are instances of this type. If an ability-level method is invoked in the application-level context, an error occurs. Therefore, you must pay attention to the actual meaning of the **Context** instance.
- Stage model
The stage model has the following types of contexts: **application/Context**, **application/ApplicationContext**, **application/AbilityStageContext**, **application/ExtensionContext**, **application/AbilityContext**, and **application/FormExtensionContext**. For details about these contexts and how to use them, see [Context in the Stage Model](#context-in-the-stage-model). The stage model has the following types of contexts: **application/Context**, **application/ApplicationContext**, **application/AbilityStageContext**, **application/ExtensionContext**, **application/AbilityContext**, and **application/FormExtensionContext**. For details about these contexts and how to use them, see [Context in the Stage Model](#context-in-the-stage-model).
![contextIntroduction](figures/contextIntroduction.png) ![contextIntroduction](figures/contextIntroduction.png)
...@@ -45,6 +46,34 @@ export default { ...@@ -45,6 +46,34 @@ export default {
} }
``` ```
### Common Context-related Methods in the FA Model
The following context-related methods are available in the FA model:
```javascript
setDisplayOrientation(orientation: bundle.DisplayOrientation, callback: AsyncCallback<void>): void
setDisplayOrientation(orientation: bundle.DisplayOrientation): Promise<void>;
```
The methods are used to set the display orientation of the current ability.
**Example**
```javascript
import featureAbility from '@ohos.ability.featureAbility'
import bundle from '../@ohos.bundle';
export default {
onCreate() {
// Obtain the context and call related APIs.
let context = featureAbility.getContext();
context.setDisplayOrientation(bundle.DisplayOrientation.LANDSCAPE).then(() => {
console.log("Set display orientation.")
})
console.info('Application onCreate')
},
onDestroy() {
console.info('Application onDestroy')
},
}
```
## Context in the Stage Model ## Context in the Stage Model
The following describes the contexts provided by the stage model in detail. The following describes the contexts provided by the stage model in detail.
......
...@@ -10,25 +10,26 @@ Basic concepts: ...@@ -10,25 +10,26 @@ Basic concepts:
- Widget host: an application that displays the widget content and controls the position where the widget is displayed in the host application. - Widget host: an application that displays the widget content and controls the position where the widget is displayed in the host application.
- Widget Manager: a resident agent that manages widgets added to the system and provides functions such as periodic widget update. - Widget Manager: a resident agent that manages widgets added to the system and provides functions such as periodic widget update.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br> > **NOTE**
>
> The widget host and provider do not keep running all the time. The Widget Manager starts the widget provider to obtain widget information when a widget is added, deleted, or updated. > The widget host and provider do not keep running all the time. The Widget Manager starts the widget provider to obtain widget information when a widget is added, deleted, or updated.
You only need to develop widget content as the widget provider. The system automatically handles the work done by the widget host and Widget Manager. You only need to develop widget content as the widget provider. The system automatically handles the work done by the widget host and Widget Manager.
The widget provider controls the widget content to display, component layout, and click events bound to components. The widget provider controls the widget content to display, component layout, and click events bound to components.
## Scenario ## Development Overview
Form ability development refers to the development conducted by the widget provider based on the [Feature Ability (FA) model](fa-brief.md). As a widget provider, you need to carry out the following operations: In FA widget development, you need to carry out the following operations as a widget provider based on the [Feature Ability (FA) model](fa-brief.md).
- Develop the lifecycle callbacks in **LifecycleForm**. - Develop the lifecycle callbacks in **LifecycleForm**.
- Create a **FormBindingData** instance. - Create a **FormBindingData** instance.
- Update a widget through **FormProvider**. - Update a widget through **FormProvider**.
- Develop the widget UI page. - Develop the widget UI pages.
## Available APIs ## Available APIs
The table below describes the lifecycle callbacks provided **LifecycleForm**. The table below describes the lifecycle callbacks provided in **LifecycleForm**.
**Table 1** LifecycleForm APIs **Table 1** LifecycleForm APIs
...@@ -37,7 +38,7 @@ The table below describes the lifecycle callbacks provided **LifecycleForm**. ...@@ -37,7 +38,7 @@ The table below describes the lifecycle callbacks provided **LifecycleForm**.
| onCreate(want: Want): formBindingData.FormBindingData | Called to notify the widget provider that a **Form** instance (widget) has been created. | | onCreate(want: Want): formBindingData.FormBindingData | Called to notify the widget provider that a **Form** instance (widget) has been created. |
| onCastToNormal(formId: string): void | Called to notify the widget provider that a temporary widget has been converted to a normal one.| | onCastToNormal(formId: string): void | Called to notify the widget provider that a temporary widget has been converted to a normal one.|
| onUpdate(formId: string): void | Called to notify the widget provider that a widget has been updated. | | onUpdate(formId: string): void | Called to notify the widget provider that a widget has been updated. |
| onVisibilityChange(newStatus: { [key: string]: number }): void | Called to notify the widget provider of the change of widget visibility. | | onVisibilityChange(newStatus: { [key: string]: number }): void | Called to notify the widget provider of the change in widget visibility. |
| onEvent(formId: string, message: string): void | Called to instruct the widget provider to receive and process a widget event. | | onEvent(formId: string, message: string): void | Called to instruct the widget provider to receive and process a widget event. |
| onDestroy(formId: string): void | Called to notify the widget provider that a **Form** instance (widget) has been destroyed. | | onDestroy(formId: string): void | Called to notify the widget provider that a **Form** instance (widget) has been destroyed. |
| onAcquireFormState?(want: Want): formInfo.FormState | Called when the widget provider receives the status query result of a widget. | | onAcquireFormState?(want: Want): formInfo.FormState | Called when the widget provider receives the status query result of a widget. |
...@@ -73,7 +74,7 @@ To create a widget in the FA model, you need to implement the lifecycles of **Li ...@@ -73,7 +74,7 @@ To create a widget in the FA model, you need to implement the lifecycles of **Li
export default { export default {
onCreate(want) { onCreate(want) {
console.log('FormAbility onCreate'); console.log('FormAbility onCreate');
// Persistently store widget information for subsequent use, such as during widget instance retrieval or update. // Persistently store widget information for subsequent use, such as widget instance retrieval or update.
let obj = { let obj = {
"title": "titleOnCreate", "title": "titleOnCreate",
"detail": "detailOnCreate" "detail": "detailOnCreate"
...@@ -120,7 +121,7 @@ To create a widget in the FA model, you need to implement the lifecycles of **Li ...@@ -120,7 +121,7 @@ To create a widget in the FA model, you need to implement the lifecycles of **Li
Configure the **config.json** file for the widget. Configure the **config.json** file for the widget.
- The **js** module in the **config.json** file provides the JavaScript resources of the widget. The internal field structure is described as follows: - The **js** module in the **config.json** file provides the JavaScript resources of the widget. The internal structure is described as follows:
| Field| Description | Data Type| Default | | Field| Description | Data Type| Default |
| -------- | ------------------------------------------------------------ | -------- | ------------------------ | | -------- | ------------------------------------------------------------ | -------- | ------------------------ |
...@@ -144,7 +145,7 @@ Configure the **config.json** file for the widget. ...@@ -144,7 +145,7 @@ Configure the **config.json** file for the widget.
}] }]
``` ```
- The **abilities** module in the **config.json** file corresponds to the **LifecycleForm** of the widget. The internal field structure is described as follows: - The **abilities** module in the **config.json** file corresponds to the **LifecycleForm** of the widget. The internal structure is described as follows:
| Field | Description | Data Type | Default | | Field | Description | Data Type | Default |
| ------------------- | ------------------------------------------------------------ | ---------- | ------------------------ | | ------------------- | ------------------------------------------------------------ | ---------- | ------------------------ |
...@@ -195,7 +196,7 @@ Configure the **config.json** file for the widget. ...@@ -195,7 +196,7 @@ Configure the **config.json** file for the widget.
``` ```
### Persistently Store Widget Data ### Persistently Storing Widget Data
Mostly, the widget provider is started only when it needs to obtain information about a widget. The Widget Manager supports multi-instance management and uses the widget ID to identify an instance. If the widget provider supports widget data modification, it must persistently store the data based on the widget ID, so that it can access the data of the target widget when obtaining, updating, or starting a widget. Mostly, the widget provider is started only when it needs to obtain information about a widget. The Widget Manager supports multi-instance management and uses the widget ID to identify an instance. If the widget provider supports widget data modification, it must persistently store the data based on the widget ID, so that it can access the data of the target widget when obtaining, updating, or starting a widget.
...@@ -206,7 +207,7 @@ Mostly, the widget provider is started only when it needs to obtain information ...@@ -206,7 +207,7 @@ Mostly, the widget provider is started only when it needs to obtain information
let formId = want.parameters["ohos.extra.param.key.form_identity"]; let formId = want.parameters["ohos.extra.param.key.form_identity"];
let formName = want.parameters["ohos.extra.param.key.form_name"]; let formName = want.parameters["ohos.extra.param.key.form_name"];
let tempFlag = want.parameters["ohos.extra.param.key.form_temporary"]; let tempFlag = want.parameters["ohos.extra.param.key.form_temporary"];
// Persistently store widget information for subsequent use, such as widget instance retrieval and update. // Persistently store widget information for subsequent use, such as widget instance retrieval or update.
// The storeFormInfo API is not implemented here. For details about the implementation, see "FA Model Widget" provided in "Samples". // The storeFormInfo API is not implemented here. For details about the implementation, see "FA Model Widget" provided in "Samples".
storeFormInfo(formId, formName, tempFlag, want); storeFormInfo(formId, formName, tempFlag, want);
...@@ -233,21 +234,43 @@ You should override **onDestroy** to delete widget data. ...@@ -233,21 +234,43 @@ You should override **onDestroy** to delete widget data.
For details about the persistence method, see [Lightweight Data Store Development](../database/database-preference-guidelines.md). For details about the persistence method, see [Lightweight Data Store Development](../database/database-preference-guidelines.md).
Note that the **Want** passed by the widget host to the widget provider contains a temporary flag, indicating whether the requested widget is a temporary one. Note that the **Want** passed by the widget host to the widget provider contains a flag that indicates whether the requested widget is a temporary one.
- Normal widget: a widget that will be persistently used by the widget host - Normal widget: a widget that will be persistently used by the widget host
- Temporary widget: a widget that is temporarily used by the widget host - Temporary widget: a widget that is temporarily used by the widget host
Data of a temporary widget is not persistently stored. If the widget framework is killed and restarted, data of a temporary widget will be deleted. However, the widget provider is not notified of which widget is deleted, and still keeps the data. Therefore, the widget provider should implement data clearing. In addition, the widget host may convert a temporary widget into a normal one. If the conversion is successful, the widget provider should process the widget ID and store the data persistently. This prevents the widget provider from deleting persistent data when clearing temporary widgets. Data of a temporary widget is not persistently stored. If the widget framework is killed and restarted, data of a temporary widget will be deleted. However, the widget provider is not notified of which widget is deleted, and still keeps the data. Therefore, the widget provider should implement data clearing. In addition, the widget host may convert a temporary widget into a normal one. If the conversion is successful, the widget provider should process the widget ID and store the data persistently. This prevents the widget provider from deleting persistent data when clearing temporary widgets.
### Developing the Widget UI Page ### Updating Widget Data
When a widget application initiates a data update upon a scheduled or periodic update, the application obtains the latest data and calls **updateForm** to update the widget. The code snippet is as follows:
```javascript
onUpdate(formId) {
// To support scheduled update, periodic update, or update requested by the widget host, override this method for widget data update.
console.log('FormAbility onUpdate');
let obj = {
"title": "titleOnUpdate",
"detail": "detailOnUpdate"
};
let formData = formBindingData.createFormBindingData(obj);
// Call the updateForm method to update the widget. Only the data passed through the input parameter is updated. Other information remains unchanged.
formProvider.updateForm(formId, formData).catch((error) => {
console.log('FormAbility updateForm, error:' + JSON.stringify(error));
});
}
```
### Developing Widget UI Pages
You can use HML, CSS, and JSON to develop the UI page for a JavaScript-programmed widget. You can use HML, CSS, and JSON to develop the UI page for a JavaScript-programmed widget.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**
>
> Currently, only the JavaScript-based web-like development paradigm can be used to develop the widget UI. > Currently, only the JavaScript-based web-like development paradigm can be used to develop the widget UI.
- HML: - In the HML file:
```html ```html
<div class="container"> <div class="container">
<stack> <stack>
...@@ -262,7 +285,7 @@ You can use HML, CSS, and JSON to develop the UI page for a JavaScript-programme ...@@ -262,7 +285,7 @@ You can use HML, CSS, and JSON to develop the UI page for a JavaScript-programme
</div> </div>
``` ```
- CSS: - In the CSS file:
```css ```css
.container { .container {
...@@ -303,7 +326,7 @@ You can use HML, CSS, and JSON to develop the UI page for a JavaScript-programme ...@@ -303,7 +326,7 @@ You can use HML, CSS, and JSON to develop the UI page for a JavaScript-programme
} }
``` ```
- JSON: - In the JSON file:
```json ```json
{ {
"data": { "data": {
......
...@@ -37,6 +37,8 @@ You can override the lifecycle callbacks provided by the Page ability in the **a ...@@ -37,6 +37,8 @@ You can override the lifecycle callbacks provided by the Page ability in the **a
The ability supports two launch types: singleton and multi-instance. The ability supports two launch types: singleton and multi-instance.
You can specify the launch type by setting **launchType** in the **config.json** file. You can specify the launch type by setting **launchType** in the **config.json** file.
**Table 1** Introduction to startup mode
| Launch Type | Description |Description | | Launch Type | Description |Description |
| ----------- | ------- |---------------- | | ----------- | ------- |---------------- |
| standard | Multi-instance | A new instance is started each time an ability starts.| | standard | Multi-instance | A new instance is started each time an ability starts.|
...@@ -48,7 +50,7 @@ By default, **singleton** is used. ...@@ -48,7 +50,7 @@ By default, **singleton** is used.
## Development Guidelines ## Development Guidelines
### Available APIs ### Available APIs
**Table 1** APIs provided by featureAbility **Table 2** APIs provided by featureAbility
| API | Description | | API | Description |
| --------------------------------------------------- | --------------- | | --------------------------------------------------- | --------------- |
...@@ -86,8 +88,10 @@ By default, **singleton** is used. ...@@ -86,8 +88,10 @@ By default, **singleton** is used.
); );
``` ```
### Starting a Remote Page Ability (Applying only to System Applications) ### Starting a Remote Page Ability
>Note: The **getTrustedDeviceListSync** API of the **DeviceManager** class is open only to system applications. Therefore, remote Page ability startup applies only to system applications. >Note
>
>This feature applies only to system applications, since the **getTrustedDeviceListSync** API of the **DeviceManager** class is open only to system applications.
**Modules to Import** **Modules to Import**
...@@ -176,7 +180,7 @@ In the cross-device scenario, the application must also apply for the data synch ...@@ -176,7 +180,7 @@ In the cross-device scenario, the application must also apply for the data synch
### Lifecycle APIs ### Lifecycle APIs
**Table 2** Lifecycle callbacks **Table 3** Lifecycle callbacks
| API | Description | | API | Description |
| ------------ | ------------------------------------------------------------ | | ------------ | ------------------------------------------------------------ |
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
A widget is a set of UI components used to display important information or operations for an application. It provides users with direct access to a desired application service, without requiring them to open the application. A widget is a set of UI components used to display important information or operations for an application. It provides users with direct access to a desired application service, without requiring them to open the application.
A widget displays brief information about an application on the UI of another application (host application, currently system applications only) and provides basic interactive functions such as opening a UI page or sending a message. A widget displays brief information about an application on the UI of another application (host application, currently system applications only) and provides basic interactive functions such as opening a UI page or sending a message.
Basic concepts: Basic concepts:
...@@ -252,7 +252,28 @@ Note that the **Want** passed by the widget host to the widget provider contains ...@@ -252,7 +252,28 @@ Note that the **Want** passed by the widget host to the widget provider contains
Data of a temporary widget is not persistently stored. If it is deleted from the Widget Manager due to exceptions, such as crash of the widget framework, the widget provider will not be notified of which widget is deleted, and still keeps the data. In light of this, the widget provider should implement data clearing. If the widget host successfully converts a temporary widget into a normal one, the widget provider should also process the widget ID and store the data persistently. This prevents the widget provider from deleting the widget data when clearing temporary widgets. Data of a temporary widget is not persistently stored. If it is deleted from the Widget Manager due to exceptions, such as crash of the widget framework, the widget provider will not be notified of which widget is deleted, and still keeps the data. In light of this, the widget provider should implement data clearing. If the widget host successfully converts a temporary widget into a normal one, the widget provider should also process the widget ID and store the data persistently. This prevents the widget provider from deleting the widget data when clearing temporary widgets.
### Updating Widget Data
When a widget application initiates a data update upon a scheduled or periodic update, the application obtains the latest data and calls **updateForm** to update the widget. The sample code is as follows:
```javascript
onUpdate(formId) {
// To support scheduled update, periodic update, or update requested by the widget host, override this method for widget data update.
console.log('FormAbility onUpdate');
let obj = {
"title": "titleOnUpdate",
"detail": "detailOnUpdate"
};
let formData = formBindingData.createFormBindingData(obj);
// Call the updateForm method to update the widget. Only the data passed through the input parameter is updated. Other information remains unchanged.
formProvider.updateForm(formId, formData).catch((error) => {
console.log('FormAbility updateForm, error:' + JSON.stringify(error));
});
}
```
### Developing the Widget UI Page ### Developing the Widget UI Page
You can use HML, CSS, and JSON to develop the UI page for a JavaScript-programmed widget. You can use HML, CSS, and JSON to develop the UI page for a JavaScript-programmed widget.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
......
# Service Extension Ability Development # Service Extension Ability Development
## When to Use ## When to Use
**ExtensionAbility** is the base class of the new Extension component in the stage model. It is used to process missions without UIs. The lifecycle of an Extension ability is simple, and it does not involve foreground or background. **ServiceExtensionAbility** is extended from **ExtensionAbility**. **ExtensionAbility** is the base class of the new Extension component in the stage model. It is used to process missions without UIs. The lifecycle of an Extension ability is simple and does not involve foreground or background states. **ServiceExtensionAbility** is extended from **ExtensionAbility**.
You can customize a class that inherits from **ServiceExtensionAbility** and override the lifecycle callbacks in the base class to perform service logic operations during the initialization, connection, and disconnection processes. You can customize a class that inherits from **ServiceExtensionAbility** and override the lifecycle callbacks in the base class to perform service logic operations during the initialization, connection, and disconnection processes.
## Available APIs ## Available APIs
**Table 1** ServiceExtensionAbility lifecycle callbacks **Table 1** ServiceExtensionAbility lifecycle APIs
|API|Description| |API|Description|
|:------|:------| |:------|:------|
|onCreate|Called for the initialization when **startAbility** or **connectAbility** is invoked for a given ability for the first time.| |onCreate(want: Want): void|Called for the initialization when **startAbility** or **connectAbility** is invoked for a given ability for the first time.|
|onRequest|Called each time **startAbility** is invoked for a given ability. The initial value of **startId** is 1, and the value is incremented by one each time **startAbility** is invoked for that ability.| |onRequest(want: Want, startId: number): void|Called each time **startAbility** is invoked for a given ability. The initial value of **startId** is **1**, and the value is incremented by one each time **startAbility** is invoked for that ability.|
|onConnect|Called when **connectAbility** is invoked for a given ability. This callback is not invoked for repeated calling of **connectAbility** for a specific ability. However, it will be invoked when **disconnectAbility** is called to disconnect an ability and then **connectAbility** is called to connect the ability again. The returned result is a **RemoteObject**.| |onConnect(want: Want): rpc.RemoteObject|Called when **connectAbility** is invoked for a given ability. This callback is not invoked for repeated calling of **connectAbility** for a specific ability. However, it will be invoked unless **connectAbility** is called after the ability has been disconnected using **disconnectAbility**. The returned result is a **RemoteObject**.|
|onDisconnect|Called when **disconnectAbility** is called for a given ability. If the Extension ability is started by **connectAbility** and is not bound by other applications, the **onDestroy** callback will also be triggered to destroy the Extension ability.| |onDisconnect(want: Want): void|Called when **disconnectAbility** is called for a given ability. If the Extension ability is started by **connectAbility** and is not bound to other applications, the **onDestroy** callback will also be triggered to destroy the Extension ability.|
|onDestroy|Called when **terminateSelf** is invoked to terminate the ability.| |onDestroy(): void|Called when **terminateSelf** is invoked to terminate the ability.|
## Constraints ## Constraints
- Currently, OpenHarmony does not support creation of a Service Extension ability for third-party applications. OpenHarmony does not support creation of a Service Extension ability for third-party applications.
## How to Develop ## How to Develop
1. Create a Service Extension ability. 1. Declare the Service Extension ability in the **module.json** file by setting its **type** attribute to **service**. The following is a configuration example of the **module.json** file:
Customize a class that inherits from **ServiceExtensionAbility** in the .ts file and override the lifecycle callbacks of the base class. The code sample is as follows:
```js ```json
import rpc from '@ohos.rpc' "extensionAbilities":[{
class StubTest extends rpc.RemoteObject { "name": "ServiceExtAbility",
constructor(des) { "icon": "$media:icon",
super(des); "description": "service",
} "type": "service",
onRemoteRequest(code, data, reply, option) { "visible": true,
} "srcEntrance": "./ets/ServiceExtAbility/ServiceExtAbility.ts"
} }]
```
class ServiceExt extends ServiceExtensionAbility {
onCreate(want) {
console.log('onCreate, want:' + want.abilityName);
}
onRequest(want, startId) {
console.log('onRequest, want:' + want.abilityName);
}
onConnect(want) {
console.log('onConnect , want:' + want.abilityName);
return new StubTest("test");
}
onDisconnect(want) {
console.log('onDisconnect, want:' + want.abilityName);
}
onDestroy() {
console.log('onDestroy');
}
}
```
2. Register the Service Extension ability. 2. Customize a class that inherits from **ServiceExtensionAbility** in the .ts file in the directory where the Service Extension ability is defined and overwrite the lifecycle callbacks of the base class. The code sample is as follows:
Declare the Service Extension ability in the **module.json** file by setting its **type** attribute to **service**. ```js
import rpc from '@ohos.rpc'
**module.json configuration example** class StubTest extends rpc.RemoteObject {
constructor(des) {
```json super(des);
"extensionAbilities":[{ }
"name": "ServiceExtAbility", onRemoteRequest(code, data, reply, option) {
"icon": "$media:icon", }
"description": "service", }
"type": "service",
"visible": true,
"srcEntrance": "./ets/ServiceExtAbility/ServiceExtAbility.ts"
}]
```
## Development Example
The following sample is provided to help you better understand how to develop a Service Extension ability:
- [ServiceExtensionAbility](https://gitee.com/openharmony/app_samples/tree/master/ability/ServiceExtAbility)
This sample shows how to create a Service Extension ability in the **ServiceExtAbility.ts** file in the **ServiceExtensionAbility** directory. class ServiceExt extends ServiceExtensionAbility {
console.log('onCreate, want:' + want.abilityName);
}
onRequest(want, startId) {
console.log('onRequest, want:' + want.abilityName);
}
onConnect(want) {
console.log('onConnect , want:' + want.abilityName);
return new StubTest("test");
}
onDisconnect(want) {
console.log('onDisconnect, want:' + want.abilityName);
}
onDestroy() {
console.log('onDestroy');
}
}
```
## Samples
The following sample is provided to help you better understand how to develop Service Extension abilities:
- [`ServiceExtAbility`: Stage Extension Ability Creation and Usage (eTS, API version 9)](https://gitee.com/openharmony/app_samples/tree/master/ability/StageCallAbility)
...@@ -89,7 +89,7 @@ The RDB provides **RdbPredicates** for you to set database operation conditions. ...@@ -89,7 +89,7 @@ The RDB provides **RdbPredicates** for you to set database operation conditions.
| RdbPredicates | endWrap(): RdbPredicates | Adds a right parenthesis to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with a right parenthesis.| | RdbPredicates | endWrap(): RdbPredicates | Adds a right parenthesis to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with a right parenthesis.|
| RdbPredicates | or(): RdbPredicates | Adds the OR condition to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with the OR condition.| | RdbPredicates | or(): RdbPredicates | Adds the OR condition to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with the OR condition.|
| RdbPredicates | and(): RdbPredicates | Adds the AND condition to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with the AND condition.| | RdbPredicates | and(): RdbPredicates | Adds the AND condition to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with the AND condition.|
| RdbPredicates | contains(field: string, value: string): RdbPredicats | Sets the **RdbPredicates** to match a string containing the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified string.| | RdbPredicates | contains(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string containing the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified string.|
| RdbPredicates | beginsWith(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that starts with the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | beginsWith(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that starts with the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | endsWith(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that ends with the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | endsWith(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that ends with the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | isNull(field: string): RdbPredicates | Sets the **RdbPredicates** to match the field whose value is null.<br>- **field**: column name in the database table.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | isNull(field: string): RdbPredicates | Sets the **RdbPredicates** to match the field whose value is null.<br>- **field**: column name in the database table.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
......
...@@ -12,7 +12,7 @@ Real-time location of the device is recommended for location-sensitive services. ...@@ -12,7 +12,7 @@ Real-time location of the device is recommended for location-sensitive services.
The following table describes APIs available for obtaining device location information. The following table describes APIs available for obtaining device location information.
**Table1** APIs for obtaining device location information **Table 1** APIs for obtaining device location information
| API | Description | | API | Description |
| -------- | -------- | | -------- | -------- |
...@@ -54,7 +54,9 @@ The following table describes APIs available for obtaining device location infor ...@@ -54,7 +54,9 @@ The following table describes APIs available for obtaining device location infor
## How to Develop ## How to Develop
1. Before using basic location capabilities, check whether your application has been granted the permission to access the device location information. If not, your application needs to obtain the permission from the user. For details, see . To learn more about the APIs for obtaining device location information, see [Geolocation](../reference/apis/js-apis-geolocation.md).
1. Before using basic location capabilities, check whether your application has been granted the permission to access the device location information. If not, your application needs to obtain the permission from the user. For details, see the following section.
The system provides the following location permissions: The system provides the following location permissions:
- ohos.permission.LOCATION - ohos.permission.LOCATION
...@@ -108,7 +110,7 @@ The following table describes APIs available for obtaining device location infor ...@@ -108,7 +110,7 @@ The following table describes APIs available for obtaining device location infor
``` ```
**Table2** Common use cases of the location function **Table 2** Common use cases of the location function
| Use&nbsp;Case | Constant | Description | | Use&nbsp;Case | Constant | Description |
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -139,7 +141,7 @@ The following table describes APIs available for obtaining device location infor ...@@ -139,7 +141,7 @@ The following table describes APIs available for obtaining device location infor
``` ```
**Table3** Location priority policies **Table 3** Location priority policies
| Policy | Constant | Description | | Policy | Constant | Description |
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -174,7 +176,7 @@ The following table describes APIs available for obtaining device location infor ...@@ -174,7 +176,7 @@ The following table describes APIs available for obtaining device location infor
geolocation.off('locationChange', locationChange); geolocation.off('locationChange', locationChange);
``` ```
If your application does not need the real-time device location, it can use the last known device location cached in the system instead. If your application does not need the real-time device location, it can use the last known device location cached in the system instead.
``` ```
geolocation.getLastLocation((data) => { geolocation.getLastLocation((data) => {
......
...@@ -17,7 +17,7 @@ APIs are provided to access the system language and region information. ...@@ -17,7 +17,7 @@ APIs are provided to access the system language and region information.
| ohos.i18n | isRTL(locale: string): boolean<sup>7+</sup> | Checks whether the locale uses a right-to-left (RTL) language. | | ohos.i18n | isRTL(locale: string): boolean<sup>7+</sup> | Checks whether the locale uses a right-to-left (RTL) language. |
| ohos.i18n | is24HourClock(): boolean<sup>7+</sup> | Checks whether the system uses a 24-hour clock. | | ohos.i18n | is24HourClock(): boolean<sup>7+</sup> | Checks whether the system uses a 24-hour clock. |
| ohos.i18n | getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string | Obtains the localized display of a language. | | ohos.i18n | getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string | Obtains the localized display of a language. |
| ohos.i18n | getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string | Obtains the localized display of a country. | | ohos.i18n | getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string | Obtains the localized display of a country name. |
### How to Develop ### How to Develop
...@@ -70,7 +70,7 @@ APIs are provided to access the system language and region information. ...@@ -70,7 +70,7 @@ APIs are provided to access the system language and region information.
``` ```
7. Obtain the localized display of a country.<br> 7. Obtain the localized display of a country.<br>
Call the **getDisplayCountry** method to obtain the localized display of a country. **country** indicates the country to be localized, **locale** indicates the locale, and **sentenceCase** indicates whether the first letter of the result must be capitalized. Call the **getDisplayCountry** method to obtain the localized display of a country name. **country** indicates the country code (a two-letter code in compliance with ISO-3166, for example, CN), **locale** indicates the locale, and **sentenceCase** indicates whether the first letter of the result must be capitalized.
``` ```
var country = "US"; var country = "US";
......
...@@ -26,6 +26,20 @@ Use [Locale](../reference/apis/js-apis-intl.md) APIs to maximize or minimize loc ...@@ -26,6 +26,20 @@ Use [Locale](../reference/apis/js-apis-intl.md) APIs to maximize or minimize loc
1. Instantiate a **Locale** object.<br> 1. Instantiate a **Locale** object.<br>
Create a **Locale** object by using the **Locale** constructor. This method receives a string representing the locale and an optional [Attributes](../reference/apis/js-apis-intl.md) list. Create a **Locale** object by using the **Locale** constructor. This method receives a string representing the locale and an optional [Attributes](../reference/apis/js-apis-intl.md) list.
A **Locale** object consists of four parts: language, script, region, and extension, which are separated by using a hyphen (-).
- Language: mandatory. It is represented by a two-letter or three-letter code as defined in ISO-639. For example, **en** indicates English and **zh** indicates Chinese.
- Script: optional. It is represented by a four-letter code as defined in ISO-15924. The first letter is in uppercase, and the remaining three letters are in lowercase. For example, **Hant** represents the traditional Chinese, and **Hans** represents the simplified Chinese.
- Country or region: optional. It is represented by two-letter code as defined in ISO-3166. Both letters are in uppercase. For example, **CN** represents China, and **US** represents the United States.
- Extensions: optional. Each extension consists of two parts, key and value. Currently, the extensions listed in the following table are supported (see BCP 47 Extensions). Extensions can be in any sequence and are written in the format of **-key-value**. They are appended to the language, script, and region by using **-u**. For example, **zh-u-nu-latn-ca-chinese** indicates that the Latin numbering system and Chinese calendar system are used. Extensions can also be passed via the second parameter.
| Extended Parameter ID| Description|
| -------- | -------- |
| ca | Calendar algorithm.|
| co | Collation type.|
| hc | Hour cycle.|
| nu | Numbering system.|
| kn | Whether numeric collation is used when sorting or comparing strings.|
| kf | Whether upper case or lower case is considered when sorting or comparing strings.|
``` ```
var locale = "zh-CN"; var locale = "zh-CN";
......
...@@ -75,6 +75,8 @@ grantUserGrantedPermission(tokenID: number, permissionName: string, permissionFl ...@@ -75,6 +75,8 @@ grantUserGrantedPermission(tokenID: number, permissionName: string, permissionFl
Grants a user granted permission to an application. This API uses a promise to return the result. Grants a user granted permission to an application. This API uses a promise to return the result.
This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.GRANT_SENSITIVE_PERMISSIONS **Required permissions**: ohos.permission.GRANT_SENSITIVE_PERMISSIONS
**System capability**: SystemCapability.Security.AccessToken **System capability**: SystemCapability.Security.AccessToken
...@@ -111,6 +113,8 @@ grantUserGrantedPermission(tokenID: number, permissionName: string, permissionFl ...@@ -111,6 +113,8 @@ grantUserGrantedPermission(tokenID: number, permissionName: string, permissionFl
Grants a user granted permission to an application. This API uses an asynchronous callback to return the result. Grants a user granted permission to an application. This API uses an asynchronous callback to return the result.
This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.GRANT_SENSITIVE_PERMISSIONS **Required permissions**: ohos.permission.GRANT_SENSITIVE_PERMISSIONS
**System capability**: SystemCapability.Security.AccessToken **System capability**: SystemCapability.Security.AccessToken
...@@ -145,6 +149,8 @@ revokeUserGrantedPermission(tokenID: number, permissionName: string, permissionF ...@@ -145,6 +149,8 @@ revokeUserGrantedPermission(tokenID: number, permissionName: string, permissionF
Revokes a user granted permission given to an application. This API uses a promise to return the result. Revokes a user granted permission given to an application. This API uses a promise to return the result.
This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.REVOKE_SENSITIVE_PERMISSIONS **Required permissions**: ohos.permission.REVOKE_SENSITIVE_PERMISSIONS
**System capability**: SystemCapability.Security.AccessToken **System capability**: SystemCapability.Security.AccessToken
...@@ -181,6 +187,8 @@ revokeUserGrantedPermission(tokenID: number, permissionName: string, permissionF ...@@ -181,6 +187,8 @@ revokeUserGrantedPermission(tokenID: number, permissionName: string, permissionF
Revokes a user granted permission given to an application. This API uses an asynchronous callback to return the result. Revokes a user granted permission given to an application. This API uses an asynchronous callback to return the result.
This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.REVOKE_SENSITIVE_PERMISSIONS **Required permissions**: ohos.permission.REVOKE_SENSITIVE_PERMISSIONS
**System capability**: SystemCapability.Security.AccessToken **System capability**: SystemCapability.Security.AccessToken
...@@ -215,7 +223,9 @@ getPermissionFlags(tokenID: number, permissionName: string): Promise&lt;number&g ...@@ -215,7 +223,9 @@ getPermissionFlags(tokenID: number, permissionName: string): Promise&lt;number&g
Obtains the flags of the specified permission of a given application. This API uses a promise to return the result. Obtains the flags of the specified permission of a given application. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_SENSITIVE_PERMISSIONS, GRANT_SENSITIVE_PERMISSIONS, or REVOKE_SENSITIVE_PERMISSIONS This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.GET_SENSITIVE_PERMISSIONS, ohos.permission.GRANT_SENSITIVE_PERMISSIONS, or ohos.permission.REVOKE_SENSITIVE_PERMISSIONS
**System capability**: SystemCapability.Security.AccessToken **System capability**: SystemCapability.Security.AccessToken
......
...@@ -320,10 +320,10 @@ arrayList.add(2); ...@@ -320,10 +320,10 @@ arrayList.add(2);
arrayList.add(4); arrayList.add(4);
arrayList.add(5); arrayList.add(5);
arrayList.add(4); arrayList.add(4);
arrayList.replaceAllElements((value, index) => { arrayList.replaceAllElements((value: number, index: number)=> {
return value = 2 * value; return value = 2 * value;
}); });
arrayList.replaceAllElements((value, index) => { arrayList.replaceAllElements((value: number, index: number) => {
return value = value - 2; return value = value - 2;
}); });
``` ```
...@@ -394,8 +394,8 @@ arrayList.add(2); ...@@ -394,8 +394,8 @@ arrayList.add(2);
arrayList.add(4); arrayList.add(4);
arrayList.add(5); arrayList.add(5);
arrayList.add(4); arrayList.add(4);
arrayList.sort((a, b) => a - b); arrayList.sort((a: number, b: number) => a - b);
arrayList.sort((a, b) => b - a); arrayList.sort((a: number, b: number) => b - a);
arrayList.sort(); arrayList.sort();
``` ```
......
...@@ -128,6 +128,7 @@ Cancels the suspension delay. ...@@ -128,6 +128,7 @@ Cancels the suspension delay.
**Example** **Example**
```js ```js
let id = 1;
backgroundTaskManager.cancelSuspendDelay(id); backgroundTaskManager.cancelSuspendDelay(id);
``` ```
...@@ -313,14 +314,14 @@ Provides the information about the suspension delay. ...@@ -313,14 +314,14 @@ Provides the information about the suspension delay.
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
| Name | Value| Description | | Name | Value| Description |
| ----------------------- | ------ | ---------------------------- | | ----------------------- | ------ | ------------------------------------------------------------ |
| DATA_TRANSFER | 1 | Data transfer. | | DATA_TRANSFER | 1 | Data transfer. |
| AUDIO_PLAYBACK | 2 | Audio playback. | | AUDIO_PLAYBACK | 2 | Audio playback. |
| AUDIO_RECORDING | 3 | Audio recording. | | AUDIO_RECORDING | 3 | Audio recording. |
| LOCATION | 4 | Positioning and navigation. | | LOCATION | 4 | Positioning and navigation. |
| BLUETOOTH_INTERACTION | 5 | Bluetooth-related task. | | BLUETOOTH_INTERACTION | 5 | Bluetooth-related task. |
| MULTI_DEVICE_CONNECTION | 6 | Multi-device connection. | | MULTI_DEVICE_CONNECTION | 6 | Multi-device connection. |
| WIFI_INTERACTION | 7 | WLAN-related (reserved). | | WIFI_INTERACTION | 7 | WLAN-related.<br>This is a system API and cannot be called by third-party applications.|
| VOIP | 8 | Voice and video call (reserved). | | VOIP | 8 | Audio and video calls.<br>This is a system API and cannot be called by third-party applications.|
| TASK_KEEPING | 9 | Computing task (effective only for specific devices).| | TASK_KEEPING | 9 | Computing task (effective only for specific devices). |
# Configuration Policy # Configuration Policy
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module are system APIs and cannot be called by third-party applications.
The configuration policy provides the capability of obtaining the custom configuration directory and file path based on the predefined custom configuration level. The configuration policy provides the capability of obtaining the custom configuration directory and file path based on the predefined custom configuration level.
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module are system APIs and cannot be called by third-party applications.
## Modules to Import ## Modules to Import
``` ```js
import configPolicy from '@ohos.configPolicy'; import configPolicy from '@ohos.configPolicy';
``` ```
## getOneCfgFile ## getOneCfgFile
getOneCfgFile(relPath: string, callback: AsyncCallback&lt;string&gt;): void getOneCfgFile(relPath: string, callback: AsyncCallback&lt;string&gt;)
Obtains the path of a configuration file with the specified name and highest priority. This API uses an asynchronous callback to return the result. Obtains the path of a configuration file with the specified name and highest priority. This API uses an asynchronous callback to return the result.
For example, if the **config.xml** file is stored in **/system/etc/config.xml** and **/sys-pod/etc/config.xml** (in ascending order of priority), then **/sys-pod/etc/config.xml** is returned. For example, if the **config.xml** file is stored in **/system/etc/config.xml** and **/sys_pod/etc/config.xml** (in ascending order of priority), then **/sys_pod/etc/config.xml** is returned.
**System capability**: SystemCapability.Customization.ConfigPolicy **System capability**: SystemCapability.Customization.ConfigPolicy
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | --------------------------- | ---- | --------------------- |
| relPath | string | Yes| Name of the configuration file.| | relPath | string | Yes | Name of the configuration file. |
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the path of the configuration file.| | callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the path of the configuration file.|
**Example** **Example**
``` ```js
configPolicy.getOneCfgFile('config.xml', (error, value) => { configPolicy.getOneCfgFile('etc/config.xml', (error, value) => {
if (error == undefined) { if (error == undefined) {
console.log(value); console.log("value is " + value);
} else { } else {
console.log(error); console.log("error occurs "+ error);
} }
}); });
``` ```
...@@ -48,19 +50,19 @@ Obtains the path of a configuration file with the specified name and highest pri ...@@ -48,19 +50,19 @@ Obtains the path of a configuration file with the specified name and highest pri
**System capability**: SystemCapability.Customization.ConfigPolicy **System capability**: SystemCapability.Customization.ConfigPolicy
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | ------- | ------ | ---- | ----- |
| relPath | string | Yes| Name of the configuration file.| | relPath | string | Yes | Name of the configuration file.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | --------------------- | ------------ |
| Promise&lt;string&gt; | Promise used to return the path of the configuration file.| | Promise&lt;string&gt; | Promise used to return the path of the configuration file.|
**Example** **Example**
``` ```js
configPolicy.getOneCfgFile('config.xml').then(value => { configPolicy.getOneCfgFile('etc/config.xml').then(value => {
console.log(value); console.log("value is " + value);
}).catch(error => { }).catch(error => {
console.log("getOneCfgFile promise " + error); console.log("getOneCfgFile promise " + error);
}); });
...@@ -69,26 +71,25 @@ Obtains the path of a configuration file with the specified name and highest pri ...@@ -69,26 +71,25 @@ Obtains the path of a configuration file with the specified name and highest pri
## getCfgFiles ## getCfgFiles
getCfgFiles(relPath: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void getCfgFiles(relPath: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;)
Obtains all configuration files with the specified name and lists them in ascending order of priority. This API uses an asynchronous callback to return the result. For example, if the **config.xml** file is stored in **/system/etc/config.xml** Obtains all configuration files with the specified name and lists them in ascending order of priority. This API uses an asynchronous callback to return the result. For example, if the **config.xml** file is stored in **/system/etc/config.xml** and **/sys_pod/etc/config.xml**, then **/system/etc/config.xml, /sys_pod/etc/config.xml** is returned.
and **/sys-pod/etc/config.xml**, then **/system/etc/config.xml, /sys-pod/etc/config.xml** is returned.
**System capability**: SystemCapability.Customization.ConfigPolicy **System capability**: SystemCapability.Customization.ConfigPolicy
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | ---------------------------------------- | ---- | ------------- |
| relPath | string | Yes| Name of the configuration file.| | relPath | string | Yes | Name of the configuration file. |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes| Callback used to return the file list.| | callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes | Callback used to return the file list.|
**Example** **Example**
``` ```js
configPolicy.getCfgFiles('config.xml', (error, value) => { configPolicy.getCfgFiles('etc/config.xml', (error, value) => {
if (error == undefined) { if (error == undefined) {
console.log(value); console.log("value is " + value);
} else { } else {
console.log(error); console.log("error occurs "+ error);
} }
}); });
``` ```
...@@ -103,19 +104,19 @@ Obtains all configuration files with the specified name and lists them in ascend ...@@ -103,19 +104,19 @@ Obtains all configuration files with the specified name and lists them in ascend
**System capability**: SystemCapability.Customization.ConfigPolicy **System capability**: SystemCapability.Customization.ConfigPolicy
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | ------- | ------ | ---- | ----- |
| relPath | string | Yes| Name of the configuration file.| | relPath | string | Yes | Name of the configuration file.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ---------------------------------- | ---- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the file list.| | Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the file list.|
**Example** **Example**
``` ```js
configPolicy.getCfgFiles('config.xml').then(value => { configPolicy.getCfgFiles('etc/config.xml').then(value => {
console.log(value); console.log("value is " + value);
}).catch(error => { }).catch(error => {
console.log("getCfgFiles promise " + error); console.log("getCfgFiles promise " + error);
}); });
...@@ -124,24 +125,24 @@ Obtains all configuration files with the specified name and lists them in ascend ...@@ -124,24 +125,24 @@ Obtains all configuration files with the specified name and lists them in ascend
## getCfgDirList ## getCfgDirList
getCfgDirList(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void getCfgDirList(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;)
Obtains the configuration level directory list. This API uses an asynchronous callback to return the result. Obtains the configuration level directory list. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Customization.ConfigPolicy **System capability**: SystemCapability.Customization.ConfigPolicy
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | ---------------------------------------- | ---- | ----------------- |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes| Callback used to return the configuration level directory list.| | callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes | Callback used to return the configuration level directory list.|
**Example** **Example**
``` ```js
configPolicy.getCfgDirList((error, value) => { configPolicy.getCfgDirList((error, value) => {
if (error == undefined) { if (error == undefined) {
console.log(value); console.log("value is " + value);
} else { } else {
console.log(error); console.log("error occurs "+ error);
} }
}); });
``` ```
...@@ -156,14 +157,14 @@ Obtains the configuration level directory list. This API uses a promise to retur ...@@ -156,14 +157,14 @@ Obtains the configuration level directory list. This API uses a promise to retur
**System capability**: SystemCapability.Customization.ConfigPolicy **System capability**: SystemCapability.Customization.ConfigPolicy
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ---------------------------------- | -------- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the configuration level directory list.| | Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the configuration level directory list.|
**Example** **Example**
``` ```js
configPolicy.getCfgDirList().then(value => { configPolicy.getCfgDirList().then(value => {
console.log(value); console.log("value is " + value);
}).catch(error => { }).catch(error => {
console.log("getCfgDirList promise " + error); console.log("getCfgDirList promise " + error);
}); });
......
...@@ -1204,7 +1204,7 @@ promise.then(async (ret) => { ...@@ -1204,7 +1204,7 @@ promise.then(async (ret) => {
``` ```
### update<sup>9+</sup> ### update<sup>9+</sup>
update(table: string, values: ValuesBucket, predicates: DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void
Updates data in the database based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result. Updates data in the database based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.
...@@ -1215,19 +1215,19 @@ Updates data in the database based on the specified **DataSharePredicates** obje ...@@ -1215,19 +1215,19 @@ Updates data in the database based on the specified **DataSharePredicates** obje
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| table | string | Yes| Name of the target table.| | table | string | Yes| Name of the target table.|
| values | [ValuesBucket](#valuesbucket) | Yes| Rows of data to be updated in the database. The key-value pair is associated with the column name in the target table.| | values | [ValuesBucket](#valuesbucket) | Yes| Rows of data to be updated in the database. The key-value pair is associated with the column name in the target table.|
| predicates | DataSharePredicates | Yes| Update conditions specified by the **DataSharePredicates** object.| | predicates | [DataSharePredicates](js-apis-data-DataSharePredicates.md#datasharepredicates) | Yes| Update conditions specified by the **DataSharePredicates** object.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of rows updated.| | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of rows updated.|
**Example** **Example**
```js ```js
import dataShare from '@ohos.data.dataShare' import dataSharePredicates from '@ohos.data.dataSharePredicates'
const valueBucket = { const valueBucket = {
"NAME": "Rose", "NAME": "Rose",
"AGE": 22, "AGE": 22,
"SALARY": 200.5, "SALARY": 200.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} }
let predicates = new dataShare.DataSharePredicates() let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
rdbStore.update("EMPLOYEE", valueBucket, predicates, function (err, ret) { rdbStore.update("EMPLOYEE", valueBucket, predicates, function (err, ret) {
if (err) { if (err) {
...@@ -1239,7 +1239,7 @@ rdbStore.update("EMPLOYEE", valueBucket, predicates, function (err, ret) { ...@@ -1239,7 +1239,7 @@ rdbStore.update("EMPLOYEE", valueBucket, predicates, function (err, ret) {
``` ```
### update<sup>9+</sup> ### update<sup>9+</sup>
update(table: string, values: ValuesBucket, predicates: DataSharePredicates):Promise&lt;number&gt; update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates):Promise&lt;number&gt;
Updates data in the database based on the specified **DataSharePredicates** object. This API uses a promise to return the result. Updates data in the database based on the specified **DataSharePredicates** object. This API uses a promise to return the result.
...@@ -1250,7 +1250,7 @@ Updates data in the database based on the specified **DataSharePredicates** obje ...@@ -1250,7 +1250,7 @@ Updates data in the database based on the specified **DataSharePredicates** obje
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| table | string | Yes| Name of the target table.| | table | string | Yes| Name of the target table.|
| values | [ValuesBucket](#valuesbucket) | Yes| Rows of data to be updated in the database. The key-value pair is associated with the column name in the target table.| | values | [ValuesBucket](#valuesbucket) | Yes| Rows of data to be updated in the database. The key-value pair is associated with the column name in the target table.|
| predicates | DataSharePredicates | Yes| Update conditions specified by the **DataSharePredicates** object.| | predicates | [DataSharePredicates](js-apis-data-DataSharePredicates.md#datasharepredicates) | Yes| Update conditions specified by the **DataSharePredicates** object.|
**Return value** **Return value**
| Type| Description| | Type| Description|
...@@ -1259,14 +1259,14 @@ Updates data in the database based on the specified **DataSharePredicates** obje ...@@ -1259,14 +1259,14 @@ Updates data in the database based on the specified **DataSharePredicates** obje
**Example** **Example**
```js ```js
import dataShare from '@ohos.data.dataShare' import dataSharePredicates from '@ohos.data.dataSharePredicates'
const valueBucket = { const valueBucket = {
"NAME": "Rose", "NAME": "Rose",
"AGE": 22, "AGE": 22,
"SALARY": 200.5, "SALARY": 200.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} }
let predicates = new dataShare.DataSharePredicates() let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
let promise = rdbStore.update("EMPLOYEE", valueBucket, predicates) let promise = rdbStore.update("EMPLOYEE", valueBucket, predicates)
promise.then(async (ret) => { promise.then(async (ret) => {
...@@ -1337,7 +1337,7 @@ promise.then((rows) => { ...@@ -1337,7 +1337,7 @@ promise.then((rows) => {
### delete<sup>9+</sup> ### delete<sup>9+</sup>
delete(table: string, predicates: DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void delete(table: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void
Deletes data from the database based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result. Deletes data from the database based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.
...@@ -1348,13 +1348,13 @@ Deletes data from the database based on the specified **DataSharePredicates** ob ...@@ -1348,13 +1348,13 @@ Deletes data from the database based on the specified **DataSharePredicates** ob
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| table | string | Yes| Name of the target table.| | table | string | Yes| Name of the target table.|
| predicates | DataSharePredicates | Yes| Conditions specified by the **DataSharePredicates** object for deleting data.| | predicates | [DataSharePredicates](js-apis-data-DataSharePredicates.md#datasharepredicates) | Yes| Conditions specified by the **DataSharePredicates** object for deleting data.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.| | callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.|
**Example** **Example**
```js ```js
import dataShare from '@ohos.data.dataShare' import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataShare.DataSharePredicates() let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
rdbStore.delete("EMPLOYEE", predicates, function (err, rows) { rdbStore.delete("EMPLOYEE", predicates, function (err, rows) {
if (err) { if (err) {
...@@ -1376,7 +1376,7 @@ Deletes data from the database based on the specified **DataSharePredicates** ob ...@@ -1376,7 +1376,7 @@ Deletes data from the database based on the specified **DataSharePredicates** ob
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| table | string | Yes| Name of the target table.| | table | string | Yes| Name of the target table.|
| predicates | DataSharePredicates | Yes| Conditions specified by the **DataSharePredicates** object for deleting data.| | predicates | [DataSharePredicates](js-apis-data-DataSharePredicates.md#datasharepredicates) | Yes| Conditions specified by the **DataSharePredicates** object for deleting data.|
**Return value** **Return value**
| Type| Description| | Type| Description|
...@@ -1385,8 +1385,8 @@ Deletes data from the database based on the specified **DataSharePredicates** ob ...@@ -1385,8 +1385,8 @@ Deletes data from the database based on the specified **DataSharePredicates** ob
**Example** **Example**
```js ```js
import dataShare from '@ohos.data.dataShare' import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataShare.DataSharePredicates() let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
let promise = rdbStore.delete("EMPLOYEE", predicates) let promise = rdbStore.delete("EMPLOYEE", predicates)
promise.then((rows) => { promise.then((rows) => {
...@@ -1460,7 +1460,7 @@ Queries data in the database based on specified conditions. This API uses a prom ...@@ -1460,7 +1460,7 @@ Queries data in the database based on specified conditions. This API uses a prom
### query<sup>9+</sup> ### query<sup>9+</sup>
query(predicates: DataSharePredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void query(predicates: dataSharePredicates.DataSharePredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
Queries data in the database based on specified conditions. This API uses an asynchronous callback to return the result. Queries data in the database based on specified conditions. This API uses an asynchronous callback to return the result.
...@@ -1469,14 +1469,14 @@ Queries data in the database based on specified conditions. This API uses an asy ...@@ -1469,14 +1469,14 @@ Queries data in the database based on specified conditions. This API uses an asy
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| predicates | DataSharePredicates | Yes| Query conditions specified by the **DataSharePredicates** object.| | predicates | [DataSharePredicates](js-apis-data-DataSharePredicates.md#datasharepredicates) | Yes| Query conditions specified by the **DataSharePredicates** object.|
| columns | Array&lt;string&gt; | Yes| Columns to query. If this parameter is not specified, the query applies to all columns.| | columns | Array&lt;string&gt; | Yes| Columns to query. If this parameter is not specified, the query applies to all columns.|
| callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| | callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
**Example** **Example**
```js ```js
import dataShare from '@ohos.data.dataShare' import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataShare.DataSharePredicates() let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Rose") predicates.equalTo("NAME", "Rose")
rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) { rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
if (err) { if (err) {
...@@ -1490,7 +1490,7 @@ rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], ...@@ -1490,7 +1490,7 @@ rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"],
### query<sup>9+</sup> ### query<sup>9+</sup>
query(predicates: DataSharePredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt; query(predicates: dataSharePredicates.DataSharePredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;
Queries data in the database based on specified conditions. This API uses a promise to return the result. Queries data in the database based on specified conditions. This API uses a promise to return the result.
...@@ -1499,7 +1499,7 @@ Queries data in the database based on specified conditions. This API uses a prom ...@@ -1499,7 +1499,7 @@ Queries data in the database based on specified conditions. This API uses a prom
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| predicates | DataSharePredicates | Yes| Query conditions specified by the **DataSharePredicates** object.| | predicates | [DataSharePredicates](js-apis-data-DataSharePredicates.md#datasharepredicates) | Yes| Query conditions specified by the **DataSharePredicates** object.|
| columns | Array&lt;string&gt; | No| Columns to query. If this parameter is not specified, the query applies to all columns.| | columns | Array&lt;string&gt; | No| Columns to query. If this parameter is not specified, the query applies to all columns.|
**Return value** **Return value**
...@@ -1509,8 +1509,8 @@ Queries data in the database based on specified conditions. This API uses a prom ...@@ -1509,8 +1509,8 @@ Queries data in the database based on specified conditions. This API uses a prom
**Example** **Example**
```js ```js
import dataShare from '@ohos.data.dataShare' import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataShare.DataSharePredicates() let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Rose") predicates.equalTo("NAME", "Rose")
let promise = rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) let promise = rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
promise.then((resultSet) => { promise.then((resultSet) => {
......
# Display # Display
Provides APIs for managing displays, such as obtaining information about the default display, obtaining information about all displays, and listening for the addition and removal of displays.
> **NOTE**<br/> > **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -139,7 +141,7 @@ Obtains all the display objects. ...@@ -139,7 +141,7 @@ Obtains all the display objects.
| Type | Description | | Type | Description |
| ----------------------------------------------- | ------------------------------------------------------- | | ----------------------------------------------- | ------------------------------------------------------- |
| Promise&lt;Array&lt;[Display](#display)&gt;&gt; | Promise used to return an array containing all the display objects.| | Promise&lt;Array&lt;[Display](#display)&gt;&gt; | Promise used to return all the display objects.|
**Example** **Example**
...@@ -163,7 +165,7 @@ Enables listening. ...@@ -163,7 +165,7 @@ Enables listening.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Listening type. The available values are as follows:<br>-&nbsp;**add**: listening for whether a display is added<br>-&nbsp;**remove**: listening for whether a display is removed<br>-&nbsp;**change**: listening for whether a display is changed| | type | string | Yes| Listening type. The available values are as follows:<br>- **add**: listening for whether a display is added<br>- **remove**: listening for whether a display is removed<br>- **change**: listening for whether a display is changed|
| callback | Callback&lt;number&gt; | Yes| Callback used to return the ID of the display.| | callback | Callback&lt;number&gt; | Yes| Callback used to return the ID of the display.|
**Example** **Example**
...@@ -186,7 +188,7 @@ Disables listening. ...@@ -186,7 +188,7 @@ Disables listening.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Listening type. The available values are as follows:<br>-&nbsp;**add**: listening for whether a display is added<br>-&nbsp;**remove**: listening for whether a display is removed<br>-&nbsp;**change**: listening for whether a display is changed| | type | string | Yes| Listening type. The available values are as follows:<br>- **add**: listening for whether a display is added<br>- **remove**: listening for whether a display is removed<br>- **change**: listening for whether a display is changed|
| callback | Callback&lt;number&gt; | No| Callback used to return the ID of the display.| | callback | Callback&lt;number&gt; | No| Callback used to return the ID of the display.|
**Example** **Example**
......
...@@ -576,13 +576,12 @@ Provides KV store configuration. ...@@ -576,13 +576,12 @@ Provides KV store configuration.
Defines the KV store types. Defines the KV store types.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
| Name | Default Value| Description | | Name | Default Value| Description |
| --- | ---- | ----------------------- | | --- | ---- | ----------------------- |
| DEVICE_COLLABORATION | 0 | Device KV store. | | DEVICE_COLLABORATION | 0 | Device KV store. <br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore |
| SINGLE_VERSION | 1 | Single KV store. | | SINGLE_VERSION | 1 | Single KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
| MULTI_VERSION | 2 | Multi-version KV store. This type is not supported currently. | | MULTI_VERSION | 2 | Multi-version KV store. This type is not supported currently. <br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore|
## SecurityLevel ## SecurityLevel
......
# HiAppEvent # HiAppEvent
This module provides the application event logging functions, such as writing application events to the event file and managing the event logging configuration.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br> > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......
...@@ -23,7 +23,7 @@ Checks whether logs are printable based on the specified service domain, log tag ...@@ -23,7 +23,7 @@ Checks whether logs are printable based on the specified service domain, log tag
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | --------------------- | ---- | ------------------------------------------------------------ | | ------ | --------------------- | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| level | [LogLevel](#loglevel) | Yes | Log level. | | level | [LogLevel](#loglevel) | Yes | Log level. |
...@@ -67,7 +67,7 @@ DEBUG logs are not recorded in official versions by default. They are available ...@@ -67,7 +67,7 @@ DEBUG logs are not recorded in official versions by default. They are available
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.| | format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| | args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
...@@ -98,7 +98,7 @@ Prints INFO logs. ...@@ -98,7 +98,7 @@ Prints INFO logs.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.| | format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| | args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
...@@ -129,7 +129,7 @@ Prints WARN logs. ...@@ -129,7 +129,7 @@ Prints WARN logs.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.| | format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| | args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
...@@ -160,7 +160,7 @@ Prints ERROR logs. ...@@ -160,7 +160,7 @@ Prints ERROR logs.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.| | format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| | args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
...@@ -191,7 +191,7 @@ Prints FATAL logs. ...@@ -191,7 +191,7 @@ Prints FATAL logs.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.| | format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| | args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
......
# Distributed Call Chain Tracing # Distributed Call Chain Tracing
This module implements call chain tracing throughout a service process. It provides functions such as starting and stopping call chain tracing and configuring trace points.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br> > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> 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 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.
......
# Performance Tracing # Performance Tracing
This module provides the functions of tracing service processes and monitoring the system performance. It provides the data needed for hiTraceMeter to carry out performance analysis.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br> > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> 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 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.
......
...@@ -1461,7 +1461,7 @@ Obtains the **TimeZone** object corresponding to the specified time zone ID. ...@@ -1461,7 +1461,7 @@ Obtains the **TimeZone** object corresponding to the specified time zone ID.
``` ```
## RelativeTimeFormat<sup>8+</sup> ## TimeZone<sup>8+</sup>
### getID<sup>8+</sup> ### getID<sup>8+</sup>
......
...@@ -364,10 +364,10 @@ list.add(2); ...@@ -364,10 +364,10 @@ list.add(2);
list.add(4); list.add(4);
list.add(5); list.add(5);
list.add(4); list.add(4);
list.replaceAllElements((value, index) => { list.replaceAllElements((value: number, index: number) => {
return value = 2 * value; return value = 2 * value;
}); });
list.replaceAllElements((value, index) => { list.replaceAllElements((value: number, index: number) => {
return value = value - 2; return value = value - 2;
}); });
``` ```
...@@ -439,8 +439,8 @@ list.add(2); ...@@ -439,8 +439,8 @@ list.add(2);
list.add(4); list.add(4);
list.add(5); list.add(5);
list.add(4); list.add(4);
list.sort((a, b) => a - b); list.sort((a: number, b: number) => a - b);
list.sort((a, b) => b - a); list.sort((a: number, b: number) => b - a);
``` ```
### getSubList ### getSubList
...@@ -472,9 +472,9 @@ list.add(2); ...@@ -472,9 +472,9 @@ list.add(2);
list.add(4); list.add(4);
list.add(5); list.add(5);
list.add(4); list.add(4);
let result = list.subList(2, 4); let result = list.getSubList(2, 4);
let result1 = list.subList(4, 3); let result1 = list.getSubList(4, 3);
let result2 = list.subList(2, 6); let result2 = list.getSubList(2, 6);
``` ```
### clear ### clear
......
...@@ -23,17 +23,20 @@ matchMediaSync(condition: string): MediaQueryListener ...@@ -23,17 +23,20 @@ matchMediaSync(condition: string): MediaQueryListener
Sets the media query criteria and returns the corresponding listening handle. Sets the media query criteria and returns the corresponding listening handle.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------ | ---- | ---------- | | --------- | ------ | ---- | ---------------------------------------- |
| condition | string | Yes | Matching condition of a media event.| | condition | string | Yes | Matching condition of a media event. For details, see "Syntax of Media Query Conditions" in [Media Query](../../ui/ui-ts-layout-mediaquery.md). |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------ | ---------------------- | | ------------------ | ---------------------- |
| MediaQueryListener | Listening handle to a media event, which is used to register or unregister the listening callback.| | MediaQueryListener | Listening handle to a media event, which is used to register or deregister the listening callback.|
**Example** **Example**
```js ```js
listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events. listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events.
``` ```
...@@ -43,6 +46,7 @@ listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for ...@@ -43,6 +46,7 @@ listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for
Media query handle, including the first query result when the handle is applied for. Media query handle, including the first query result when the handle is applied for.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
### Attributes ### Attributes
...@@ -58,6 +62,8 @@ on(type: 'change', callback: Callback&lt;MediaQueryResult&gt;): void ...@@ -58,6 +62,8 @@ on(type: 'change', callback: Callback&lt;MediaQueryResult&gt;): void
Registers a callback with the corresponding query condition by using the handle. This callback is triggered when the media attributes change. Registers a callback with the corresponding query condition by using the handle. This callback is triggered when the media attributes change.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------------------------- | ---- | ---------------- | | -------- | -------------------------------- | ---- | ---------------- |
...@@ -72,12 +78,15 @@ Registers a callback with the corresponding query condition by using the handle. ...@@ -72,12 +78,15 @@ Registers a callback with the corresponding query condition by using the handle.
off(type: 'change', callback?: Callback&lt;MediaQueryResult&gt;): void off(type: 'change', callback?: Callback&lt;MediaQueryResult&gt;): void
Unregisters a callback with the corresponding query condition by using the handle, so that no callback is triggered when the media attributes change. Deregisters a callback with the corresponding query condition by using the handle, so that no callback is triggered when the media attributes change.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------------------------- | ---- | ----------------------------- | | -------- | -------------------------------- | ---- | ----------------------------- |
| type | boolean | Yes | Must enter the string **change**. | | type | boolean | Yes | Must enter the string **change**. |
| callback | Callback&lt;MediaQueryResult&gt; | No | Callback to be unregistered. If the default value is used, all callbacks of the handle are unregistered.| | callback | Callback&lt;MediaQueryResult&gt; | No | Callback to be deregistered. If the default value is used, all callbacks of the handle are deregistered.|
**Example** **Example**
```js ```js
...@@ -92,7 +101,7 @@ Unregisters a callback with the corresponding query condition by using the handl ...@@ -92,7 +101,7 @@ Unregisters a callback with the corresponding query condition by using the handl
} }
} }
listener.on('change', onPortrait) // Register a callback. listener.on('change', onPortrait) // Register a callback.
listener.off('change', onPortrait) // Unregister a callback. listener.off('change', onPortrait) // Deregister a callback.
``` ```
...@@ -132,7 +141,7 @@ struct MediaQueryExample { ...@@ -132,7 +141,7 @@ struct MediaQueryExample {
} }
aboutToAppear() { aboutToAppear() {
portraitFunc = this.onPortrait.bind(this) //bind current js instance portraitFunc = this.onPortrait.bind(this) // Bind the current JS instance.
this.listener.on('change', portraitFunc) this.listener.on('change', portraitFunc)
} }
......
# Page Routing # Page Routing
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **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 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.
> - Page routing APIs can be invoked only after page rendering is complete. Do not call the APIs in **onInit** and **onReady** when the page is still in the rendering phase. > - Page routing APIs can be invoked only after page rendering is complete. Do not call the APIs in **onInit** and **onReady** when the page is still in the rendering phase.
...@@ -190,6 +190,8 @@ getLength(): string ...@@ -190,6 +190,8 @@ getLength(): string
Obtains the number of pages in the current stack. Obtains the number of pages in the current stack.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
...@@ -275,7 +277,7 @@ Enables the display of a confirm dialog box before returning to the previous pag ...@@ -275,7 +277,7 @@ Enables the display of a confirm dialog box before returning to the previous pag
Describes the confirm dialog box. Describes the confirm dialog box.
**System capability**: SystemCapability.ArkUI.ArkUI.Lite **System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
......
# Screenshot # Screenshot
Provides APIs for you to set information such as the region to capture and the size of the screen region when capturing a screen.
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs provided by this module are system APIs.
## Modules to Import ## Modules to Import
...@@ -17,11 +20,12 @@ Describes screenshot options. ...@@ -17,11 +20,12 @@ Describes screenshot options.
**System capability**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ------------- | ---- | ------------------------------------------------------------ | | ---------------------- | ------------- | ---- | ------------------------------------------------------------ |
| screenRect | [Rect](#rect) | No | Region of the screen to capture. If this parameter is null, the full screen will be captured.| | screenRect | [Rect](#rect) | No | Region of the screen to capture. If this parameter is null, the full screen will be captured. |
| imageSize | [Size](#size) | No | Size of the screen region to capture. If this parameter is null, the full screen will be captured.| | imageSize | [Size](#size) | No | Size of the screen region to capture. If this parameter is null, the full screen will be captured. |
| rotation | number | No | Rotation angle of the screenshot. Currently, the value can be **0** only. The default value is **0**.| | rotation | number | No | Rotation angle of the screenshot. Currently, the value can be **0** only. The default value is **0**. |
| displayId<sup>8+</sup> | number | No | ID of the [display](js-apis-display.md#display) device on which the screen region is to be captured.|
## Rect ## Rect
...@@ -63,7 +67,7 @@ Takes a screenshot and saves it as a **PixelMap** object. This method uses a cal ...@@ -63,7 +67,7 @@ Takes a screenshot and saves it as a **PixelMap** object. This method uses a cal
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [ScreenshotOptions](#screenshotoptions) | No | Screenshot options, which consist of **screenRect**, **imageSize**, and **rotation**. You need to set these parameters.| | options | [ScreenshotOptions](#screenshotoptions) | No | Consists of **screenRect**, **imageSize**, **rotation**, and **displayId**. You can set them separately.|
| callback | AsyncCallback&lt;image.PixelMap&gt; | Yes | Callback used to return a **PixelMap** object. | | callback | AsyncCallback&lt;image.PixelMap&gt; | Yes | Callback used to return a **PixelMap** object. |
**Example** **Example**
...@@ -78,7 +82,8 @@ Takes a screenshot and saves it as a **PixelMap** object. This method uses a cal ...@@ -78,7 +82,8 @@ Takes a screenshot and saves it as a **PixelMap** object. This method uses a cal
"imageSize": { "imageSize": {
"width": 300, "width": 300,
"height": 300}, "height": 300},
"rotation": 0 "rotation": 0,
"displayId": 0
}; };
screenshot.save(ScreenshotOptions, (err, data) => { screenshot.save(ScreenshotOptions, (err, data) => {
if (err) { if (err) {
...@@ -103,13 +108,13 @@ Takes a screenshot and saves it as a **PixelMap** object. This method uses a pro ...@@ -103,13 +108,13 @@ Takes a screenshot and saves it as a **PixelMap** object. This method uses a pro
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | --------------------------------------- | ---- | ------------------------------------------------------------ | | ------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [ScreenshotOptions](#screenshotoptions) | No | Screenshot options, which consist of **screenRect**, **imageSize**, and **rotation**. You need to set these parameters.| | options | [ScreenshotOptions](#screenshotoptions) | No | Consists of **screenRect**, **imageSize**, **rotation**, and **displayId**. You can set them separately.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------- | ----------------------------------------------- | | ----------------------------- | ----------------------------------------------- |
| Promise&lt;image.PixelMap&gt; | Promise used to return an **image.PixelMap** object.| | Promise&lt;image.PixelMap&gt; | Promise used to return a **PixelMap** object.|
**Example** **Example**
...@@ -123,7 +128,8 @@ Takes a screenshot and saves it as a **PixelMap** object. This method uses a pro ...@@ -123,7 +128,8 @@ Takes a screenshot and saves it as a **PixelMap** object. This method uses a pro
"imageSize": { "imageSize": {
"width": 300, "width": 300,
"height": 300}, "height": 300},
"rotation": 0 "rotation": 0,
"displayId": 0
}; };
let promise = screenshot.save(ScreenshotOptions); let promise = screenshot.save(ScreenshotOptions);
promise.then(() => { promise.then(() => {
......
...@@ -319,10 +319,10 @@ vector.add(2); ...@@ -319,10 +319,10 @@ vector.add(2);
vector.add(4); vector.add(4);
vector.add(5); vector.add(5);
vector.add(4); vector.add(4);
vector.replaceAllElements((value, index) => { vector.replaceAllElements((value: number, index: number) => {
return value = 2 * value; return value = 2 * value;
}); });
vector.replaceAllElements((value, index) => { vector.replaceAllElements((value: number, index: number) => {
return value = value - 2; return value = value - 2;
}); });
``` ```
...@@ -394,8 +394,8 @@ vector.add(2); ...@@ -394,8 +394,8 @@ vector.add(2);
vector.add(4); vector.add(4);
vector.add(5); vector.add(5);
vector.add(4); vector.add(4);
vector.sort((a, b) => a - b); vector.sort((a: number, b: number) => a - b);
vector.sort((a, b) => b - a); vector.sort((a: number, b: number) => b - a);
vector.sort(); vector.sort();
``` ```
...@@ -620,7 +620,7 @@ vector.add(2); ...@@ -620,7 +620,7 @@ vector.add(2);
vector.add(4); vector.add(4);
vector.add(5); vector.add(5);
vector.add(4); vector.add(4);
let result = vector.toSting(); let result = vector.toString();
``` ```
### copyToArray ### copyToArray
......
...@@ -223,14 +223,14 @@ Sets a custom drag image. ...@@ -223,14 +223,14 @@ Sets a custom drag image.
| Name | Type | Mandatory | Name | | Name | Type | Mandatory | Name |
| -------- | -------- | ---- | ---------------------------------------- | | -------- | -------- | ---- | ---------------------------------------- |
| pixelmap | PixelMap | Yes | Image transferred from the frontend. For details, see [PixelMap](../apis/js-apis-image.md#pixelmap7).| | pixelmap | [PixelMap](../apis/js-apis-image.md#pixelmap7) | Yes | Image transferred from the frontend. |
| offsetX | number | Yes | Horizontal offset relative to the image. | | offsetX | number | Yes | Horizontal offset relative to the image. |
| offsetY | number | Yes | Vertical offset relative to the image. | | offsetY | number | Yes | Vertical offset relative to the image. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---- | ------------------------ | | ---- | ------------------------ |
| bool | Operation result. The value **true** means that the operation is successful, and **false** means otherwise.| | boolean | Operation result. The value **true** means that the operation is successful, and **false** means otherwise.|
**Example** **Example**
......
# Focus Control # Focus Control
> **NOTE**<br>
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
> This attribute is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
## Required Permissions ## Required Permissions
...@@ -12,66 +11,57 @@ None ...@@ -12,66 +11,57 @@ None
## Attributes ## Attributes
| **Name** | **Type** | **Default Value** | **Description** | | Name| Type| Default Value| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| focusable | boolean | false | Whether the current component is focusable. | | focusable | boolean | false | Whether the current component is focusable.|
| tabIndex<sup>9+<sup> | number | 0 | How the current component participates in sequential keyboard navigation.<br>- **tabIndex** >= 0: The component is focusable in sequential keyboard navigation, with its order defined by the value. A component with a larger value is focused after one with a smaller value. If multiple components share the same **tabIndex** value, their focus order follows their position in the component tree.<br>- **tabIndex** < 0 (usually **tabIndex** = -1): The component is focusable, but cannot be reached through sequential keyboard navigation. |
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**<br>
> The following components support focus control: **&lt;Button&gt;**, **&lt;Text&gt;**, **&lt;Image&gt;**, **&lt;List&gt;**, and **&lt;Grid&gt;**. > The following components support focus control: **\<Button>**, **\<Text>**, **\<Image>**, **\<List>**, and **\<Grid>**.
## Example ## Example
```ts
``` // xxx.ets
@Entry @Entry
@Component @Component
struct FocusableExample { struct FocusableExample {
@State textOne: string = '' @State text1: string = 'TabIndex=3'
@State textTwo: string = '' @State text2: string = 'TabIndex=2'
@State textThree: string = 'The third button cannot be focused' @State text3: string = 'focusable=false'
@State oneButtonColor: string = '#FF0000' @State text4: string = 'TabIndex=-1'
@State twoButtonColor: string = '#FFC0CB' @State text5: string = 'TabIndex=1'
@State threeButtonColor: string = '#87CEFA' @State text6: string = 'TabIndex=1'
@State text7: string = 'focusable=true'
@State text8: string = 'focusable=true'
build() { build() {
Column({ space:20 }){ Column({ space:20 }){
Button(this.textOne) Button(this.text1) // This component is the fourth component that is focused when the Tab key is pressed.
.backgroundColor(this.oneButtonColor)
.width(300).height(70).fontColor(Color.Black) .width(300).height(70).fontColor(Color.Black)
.focusable(true) .tabIndex(3)
.onFocus(() => { Button(this.text2) // This component is the third component that is focused when the Tab key is pressed.
this.textOne = 'First Button onFocus'
this.oneButtonColor = '#AFEEEE'
})
.onBlur(() => {
this.textOne = 'First Button onBlur'
this.oneButtonColor = '#FFC0CB'
})
Button(this.textTwo)
.backgroundColor(this.twoButtonColor)
.width(300).height(70).fontColor(Color.Black) .width(300).height(70).fontColor(Color.Black)
.focusable(true) .tabIndex(2)
.onFocus(() => { Button(this.text3) // This component is not focusable.
this.textTwo = 'Second Button onFocus'
this.twoButtonColor = '#AFEEEE'
})
.onBlur(() => {
this.textTwo = 'Second Button onBlur'
this.twoButtonColor = '#FFC0CB'
})
Button(this.textThree)
.backgroundColor(this.threeButtonColor)
.width(300).height(70).fontColor(Color.Black) .width(300).height(70).fontColor(Color.Black)
.focusable(false) .focusable(false)
.onFocus(() => { Button(this.text4) // This component is focusable, but cannot be reached through sequential keyboard navigation.
this.textThree = 'Third Button onFocus' .width(300).height(70).fontColor(Color.Black)
this.threeButtonColor = '#AFEEEE' .tabIndex(-1)
}) Button(this.text5) // This component is the first component that is focused when the Tab key is pressed.
.onBlur(() => { .width(300).height(70).fontColor(Color.Black)
this.textThree = 'Third Button onBlur' .tabIndex(1)
this.threeButtonColor = '#FFC0CB' Button(this.text6) // This component is the second component that is focused when the Tab key is pressed.
}) .width(300).height(70).fontColor(Color.Black)
.tabIndex(1)
Button(this.text7) // This component is the fifth component that is focused when the Tab key is pressed.
.width(300).height(70).fontColor(Color.Black)
.focusable(true)
Button(this.text8) // This component is the sixth component that is focused when the Tab key is pressed.
.width(300).height(70).fontColor(Color.Black)
.focusable(true)
}.width('100%').margin({ top:20 }) }.width('100%').margin({ top:20 })
} }
} }
......
# Standard Libraries Supported by Native APIs # Native Standard Libraries Supported by OpenHarmony
## Introduction ## Overview
...@@ -12,20 +12,22 @@ ...@@ -12,20 +12,22 @@
| :-------- | :----------------------------------------------------------- | | :-------- | :----------------------------------------------------------- |
| C standard library | C11 standard library implemented by [libc, libm, and libdl](https://en.cppreference.com/w/c/header). | | C standard library | C11 standard library implemented by [libc, libm, and libdl](https://en.cppreference.com/w/c/header). |
| C++ standard library ([libc++](https://libcxx.llvm.org/))| An implementation of the C++ standard library. | | C++ standard library ([libc++](https://libcxx.llvm.org/))| An implementation of the C++ standard library. |
| [OpenSL ES](https://www.khronos.org/registry/OpenSL-ES/)| An embedded cross-platform audio processing library.| | Open Sound Library for Embedded Systems ([OpenSL ES](https://www.khronos.org/registry/OpenSL-ES/))| An embedded, cross-platform audio processing library.|
| [zlib](https://zlib.net/) | A general data compression library implemented in C/C++.| | [zlib](https://zlib.net/) | A general data compression library implemented in C/C++.|
| [EGL](https://www.khronos.org/egl/) | A standard software interface between rendering APIs and the underlying native window system.|
| Open Graphics Library for Embedded Systems ([OpenGL ES](https://www.khronos.org/opengles/))| A cross-platform software interface for rendering 3D graphics on embedded and mobile systems.|
## C Standard Library ## C Standard Library
C11 standard library implemented by [libc, libm, and libdl](https://en.cppreference.com/w/c/header). The C standard library is a C11 standard library implemented by:
libc: provides thread-related functions and a majority of standard functions. libc: provides thread-related functions and a majority of standard functions.
libm: provides basic mathematical functions. libm: provides basic mathematical functions.
libdl: provides functions related to dynamic linking, such as dlopen. libdl: provides functions related to dynamic linking, such as **dlopen**.
**Version** **Version**
...@@ -39,7 +41,7 @@ C standard library includes a set of header files in accordance with standard C ...@@ -39,7 +41,7 @@ C standard library includes a set of header files in accordance with standard C
[Native API Symbols Not Exported](musl-peculiar-symbol.md) [Native API Symbols Not Exported](musl-peculiar-symbol.md)
## C++ Standard Library ## libc++
...@@ -57,7 +59,7 @@ The C++11 and C++14 standards are supported, and the C++17 and C++20 standards a ...@@ -57,7 +59,7 @@ The C++11 and C++14 standards are supported, and the C++17 and C++20 standards a
[OpenSL ES](https://www.khronos.org/registry/OpenSL-ES/) is an embedded cross-platform audio processing library. [OpenSL ES](https://www.khronos.org/registry/OpenSL-ES/) is an embedded, cross-platform audio processing library.
...@@ -66,3 +68,31 @@ The C++11 and C++14 standards are supported, and the C++17 and C++20 standards a ...@@ -66,3 +68,31 @@ The C++11 and C++14 standards are supported, and the C++17 and C++20 standards a
[zlib](https://zlib.net/) is a general data compression library implemented in C/C++. [zlib](https://zlib.net/) is a general data compression library implemented in C/C++.
## EGL
EGL is an interface between Khronos rendering APIs (such as OpenGL ES and OpenVG) and the underlying native window system. OpenHarmony supports EGL.
**Symbols Exported from the Standard Library**
[EGL Symbols Exported from Native APIs](../third_party_opengl/egl-symbol.md)
## OpenGL ES
OpenGL is a cross-platform software interface for 3D graphics processing. [OpenGL ES](https://www.khronos.org/opengles/) is a OpenGL specification for embedded devices. OpenHarmony supports OpenGL ES 3.0.
**Capabilities**
OpenGL ES 3.0
**Symbols Exported from the Standard Library**
[OpenGL ES 3.0 Symbols Exported from Native APIs](../third_party_opengl/openglesv3-symbol.md)
**EGL Symbols Exported from Native APIs**
|Type|Symbol|Remarks|
| --- | --- | --- |
|FUNC|eglChooseConfig|
|FUNC|eglCopyBuffers|
|FUNC|eglCreateContext|
|FUNC|eglCreatePbufferSurface|
|FUNC|eglCreatePixmapSurface|
|FUNC|eglCreateWindowSurface|
|FUNC|eglDestroyContext|
|FUNC|eglDestroySurface|
|FUNC|eglGetConfigAttrib|
|FUNC|eglGetConfigs|
|FUNC|eglGetCurrentDisplay|
|FUNC|eglGetCurrentSurface|
|FUNC|eglGetDisplay|
|FUNC|eglGetError|
|FUNC|eglGetProcAddress|
|FUNC|eglInitialize|
|FUNC|eglMakeCurrent|
|FUNC|eglQueryContext|
|FUNC|eglQueryString|
|FUNC|eglQuerySurface|
|FUNC|eglSwapBuffers|
|FUNC|eglTerminate|
|FUNC|eglWaitGL|
|FUNC|eglWaitNative|
|FUNC|eglBindTexImage|
|FUNC|eglReleaseTexImage|
|FUNC|eglSurfaceAttrib|
|FUNC|eglSwapInterval|
|FUNC|eglBindAPI|
|FUNC|eglQueryAPI|
|FUNC|eglCreatePbufferFromClientBuffer|
|FUNC|eglReleaseThread|
|FUNC|eglWaitClient|
|FUNC|eglGetCurrentContext|
|FUNC|eglCreateSync|
|FUNC|eglDestroySync|
|FUNC|eglClientWaitSync|
|FUNC|eglGetSyncAttrib|
|FUNC|eglCreateImage|
|FUNC|eglDestroyImage|
|FUNC|eglGetPlatformDisplay|
|FUNC|eglCreatePlatformWindowSurface|
|FUNC|eglCreatePlatformPixmapSurface|
|FUNC|eglWaitSync|
...@@ -11,5 +11,5 @@ ...@@ -11,5 +11,5 @@
- [HUKS Overview](huks-overview.md) - [HUKS Overview](huks-overview.md)
- [HUKS Development](huks-guidelines.md) - [HUKS Development](huks-guidelines.md)
- hapsigner - hapsigner
- [hapsigner Overview](hapsigntool-overview.md)
- [hapsigner Guide](hapsigntool-guidelines.md) - [hapsigner Guide](hapsigntool-guidelines.md)
...@@ -74,7 +74,10 @@ The table below describes the APLs. ...@@ -74,7 +74,10 @@ The table below describes the APLs.
| system_basic| The apps of this level provide basic system services. | | system_basic| The apps of this level provide basic system services. |
| Normal | The apps of this level are normal apps. | | Normal | The apps of this level are normal apps. |
By default, apps are of the normal APL. For the app of the system_basic or system_core APL, declare the app APL level in the **apl** field in the app's profile, and use the profile signing tool to generate a certificate when developing the app installation package. For details about the signing process, see [Hapsigner Guide](hapsigntool-guidelines.md). By default, apps are of the normal APL.
For the app of the system_basic or system_core APL, declare the app APL level in the **apl** field in the app's profile, and use the profile signing tool to generate a certificate when developing the app installation package. For details about the signing process, see [Hapsigner Guide](hapsigntool-guidelines.md).
### Permission Levels ### Permission Levels
The permissions open to apps vary with the permission level. The permission levels include the following in ascending order of seniority. The permissions open to apps vary with the permission level. The permission levels include the following in ascending order of seniority.
...@@ -105,9 +108,24 @@ The Access Control List (ACL) makes low-level apps have high-level permissions. ...@@ -105,9 +108,24 @@ The Access Control List (ACL) makes low-level apps have high-level permissions.
**Example** **Example**
The APL of app A is normal. App A needs to have permission B (system_basic level) and permission C (normal level). In this case, you can use the ACL to grant permission B to app A. The APL of app A is normal. App A needs to have permission B (system_basic level) and permission C (normal level).
In this case, you can use the ACL to grant permission B to app A.
For details, see [Using the ACL](#using-the-acl). For details, see [Using the ACL](#using-the-acl).
For details about whether the ACL is enabled for a permission, see [Permission List](permission-list.md).
### Using the ACL
If the permission required by an app has higher level than the app's APL, you can use the ACL to grant the permissions required.
In addition to the preceding [authorization processes](#authorization-processes), you must declare the ACL.
In other words, in addition to declaring the required permissions in the **config.json** file, you must declare the high-level permissions in the app's [profile](accesstoken-guidelines.md#declaring-the-acl). The subsequent steps of authorization are the same.
**NOTE**
Declare the target ACL in the **acl** field of the app's profile in the app installation package, and generate a certificate using the profile signing tool. For details about the signing process, see [Hapsigner Guide](hapsigntool-guidelines.md).
## Permission Authorization Modes ## Permission Authorization Modes
...@@ -129,7 +147,7 @@ Permissions can be classified into the following types based on the authorizatio ...@@ -129,7 +147,7 @@ Permissions can be classified into the following types based on the authorizatio
The user_grant permission list must also be presented on the details page of the app in the app store. The user_grant permission list must also be presented on the details page of the app in the app store.
## Authorization Processes ### Authorization Processes
The process for an app obtaining the required permissions varies depending on the permission authorization mode. The process for an app obtaining the required permissions varies depending on the permission authorization mode.
...@@ -153,18 +171,6 @@ The procedure is as follows: ...@@ -153,18 +171,6 @@ The procedure is as follows:
- Check the app's permission each time before the operation requiring the permission is performed. - Check the app's permission each time before the operation requiring the permission is performed.
- To check whether a user has granted specific permissions to your app, use the [verifyAccessToken](../reference/apis/js-apis-abilityAccessCtrl.md#verifyaccesstoken) method. This method returns [PERMISSION_GRANTED](../reference/apis/js-apis-abilityAccessCtrl.md#grantstatus) or [PERMISSION_DENIED](../reference/apis/js-apis-abilityAccessCtrl.md#grantstatus). For details about the sample code, see [Access Control Development](accesstoken-guidelines.md). - To check whether a user has granted specific permissions to your app, use the [verifyAccessToken](../reference/apis/js-apis-abilityAccessCtrl.md) method. This method returns [PERMISSION_GRANTED](../reference/apis/js-apis-abilityAccessCtrl.md) or [PERMISSION_DENIED](../reference/apis/js-apis-abilityAccessCtrl.md). For details about the sample code, see [Access Control Development](accesstoken-guidelines.md).
- Users must be able to understand and control the authorization of user_grant permissions. During the running process, the app requiring user authorization must proactively call the API to dynamically request the authorization. Then, the system displays a dialog box asking the user to grant the requested permission. The user will determine whether to grant the permission based on the running context of the app. - Users must be able to understand and control the authorization of user_grant permissions. During the running process, the app requiring user authorization must proactively call the API to dynamically request the authorization. Then, the system displays a dialog box asking the user to grant the requested permission. The user will determine whether to grant the permission based on the running context of the app.
- The permission authorized is not permanent, because the user may revoke the authorization at any time. Therefore, even if the user has granted the requested permission to the app, the app must check for the permission before calling the API controlled by this permission. - The permission authorized is not permanent, because the user may revoke the authorization at any time. Therefore, even if the user has granted the requested permission to the app, the app must check for the permission before calling the API controlled by this permission.
### Using the ACL
If the permission required by an app has higher level than the app's APL, you can use the ACL to grant the permissions required.
In addition to the preceding [authorization processes](#authorization-processes), you must declare the ACL.
In other words, in addition to declaring the required permissions in the **config.json** file, you must declare the high-level permissions in the app's [profile](accesstoken-guidelines.md). The subsequent steps of authorization are the same.
**NOTE**
Declare the target ACL in the **acl** field of the app's profile in the app installation package, and generate a certificate using the profile signing tool. For details about the signing process, see [Hapsigner Guide](hapsigntool-guidelines.md).
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册