> 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.
...
@@ -13,11 +13,6 @@ import rpc from '@ohos.rpc';
...
@@ -13,11 +13,6 @@ import rpc from '@ohos.rpc';
```
```
## Required Permissions
None
## MessageParcel
## MessageParcel
Provides methods for reading and writing basic data types and arrays, inter-process communication (IPC) objects, interface tokens, and sequenceable objects.
Provides methods for reading and writing basic data types and arrays, inter-process communication (IPC) objects, interface tokens, and sequenceable objects.
...
@@ -29,14 +24,15 @@ create(): MessageParcel
...
@@ -29,14 +24,15 @@ create(): MessageParcel
Creates a **MessageParcel** object. This method is a static method.
Creates a **MessageParcel** object. This method is a static method.
Reads the remote object from this **MessageParcel** object. You can use this method to deserialize the **MessageParcel** object to generate an **IRemoteObject**. The remote objects are read in the order in which they are written to this **MessageParcel** object.
Reads the remote object from this **MessageParcel** object. You can use this method to deserialize the **MessageParcel** object to generate an **IRemoteObject**. The remote objects are read in the order in which they are written to this **MessageParcel** object.
Reads the interface token from this **MessageParcel** object. The interface tokens are read in the order in which they are written into the **MessageParcel** object.
Reads the interface token from this **MessageParcel** object. The interface tokens are read in the order in which they are written into the **MessageParcel** object.
| number | 128 MB, which is the maximum amount of raw data that can be held by this **MessageParcel** object. |
| number | 128 MB, which is the maximum amount of raw data that can be held by this **MessageParcel** object.|
| [IRemoteObject](#iremoteobject) | Returns the [RemoteObject](#ashmem8) if it is the caller; returns the [IRemoteObject](#iremoteobject), the holder of this **RemoteProxy** object, if the caller is a [RemoteProxy](#remoteproxy) object.|
- Example
- Example
```
```
class TestAbility extends rpc.RemoteObject {
class TestAbility extends rpc.RemoteObject {
asObject() {
asObject() {
...
@@ -2296,7 +2319,7 @@ Obtains a proxy or remote object. This method must be implemented by its derived
...
@@ -2296,7 +2319,7 @@ Obtains a proxy or remote object. This method must be implemented by its derived
```
```
- Example
- Example
```
```
class TestProxy {
class TestProxy {
constructor(remote) {
constructor(remote) {
...
@@ -2311,7 +2334,7 @@ Obtains a proxy or remote object. This method must be implemented by its derived
...
@@ -2311,7 +2334,7 @@ Obtains a proxy or remote object. This method must be implemented by its derived
## DeathRecipient
## DeathRecipient
Subscribes to death notifications of a remote object. When the remote object is dead, the local end will receive a notification and [onRemoteDied](#onremotedied) will be called. A remote object is dead when the process holding the object is terminated or the device of the remote object is shut down or restarted. If the local and remote objects belong to different devices, the remote object is dead when the device holding the remote object is detached from the network.
Subscribes to death notifications of a remote object. When the remote object is dead, the local end will receive a notification and **[onRemoteDied](#onremotedied)** will be called. A remote object is dead when the process holding the object is terminated or the device of the remote object is shut down or restarted. If the local and remote objects belong to different devices, the remote object is dead when the device holding the remote object is detached from the network.
### onRemoteDied
### onRemoteDied
...
@@ -2320,8 +2343,10 @@ onRemoteDied(): void
...
@@ -2320,8 +2343,10 @@ onRemoteDied(): void
Called to perform subsequent operations when a death notification of the remote object is received.
Called to perform subsequent operations when a death notification of the remote object is received.
Sends a **MessageParcel** message to the peer process in synchronous or asynchronous mode. If **options** indicates the asynchronous mode, a promise will be fulfilled immediately and the **reply** message does not contain any content. If **options** indicates the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool. |
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes | **MessageParcel** object holding the data to send. |
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
| Promise<number><sup>7</sup><br>Promise<SendRequestResult><sup>8+</sup> | Promise used to return the result. The value **0** will be returned if the request is sent successfully. Otherwise, an error code will be returned.<sup>7</sup><br>Promise used to return the **sendRequestResult** object.<sup>8+</sup> |
Sends a **MessageParcel** message to the peer process in synchronous or asynchronous mode. If **options** indicates the asynchronous mode, a callback will be invoked immediately and the **reply** message does not contain any content. If **options** indicates the synchronous mode, a callback will be invoked when the response to **sendRequest** is returned, and the **reply** message contains the returned information.
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.
| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool. |
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes | **MessageParcel** object holding the data to send. |
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
Adds a callback for receiving death notifications of the remote object. This method is called if the remote object process matching the **RemoteProxy** object is killed.
Adds a callback for receiving death notifications of the remote object. This method is called if the remote object process matching the **RemoteProxy** object is killed.
Sends a **MessageParcel** message to the peer process in synchronous or asynchronous mode. If **options** indicates the asynchronous mode, a promise will be fulfilled immediately and the **reply** message does not contain any content. If **options** indicates the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool. |
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes | **MessageParcel** object holding the data to send. |
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
| Promise<number><sup>7</sup><br>Promise<SendRequestResult><sup>8+</sup> | Promise used to return the result. The value **0** will be returned if the request is sent successfully. Otherwise, an error code will be returned.<sup>7</sup><br>Promise used to return the **sendRequestResult** object.<sup>8+</sup> |
- Example:<sup>7</sup>
- Example<sup>7</sup>
```
```
import FA from "@ohos.ability.featureAbility";
import FA from "@ohos.ability.featureAbility";
let proxy;
let proxy;
...
@@ -2508,8 +2563,8 @@ Sends a **MessageParcel** message to the peer process in synchronous or asynchro
...
@@ -2508,8 +2563,8 @@ Sends a **MessageParcel** message to the peer process in synchronous or asynchro
}
}
};
};
let want = {
let want = {
"bundleName": "com.huawei.server",
"bundleName": "com.ohos.server",
"abilityName": "com.huawei.server.MainAbility",
"abilityName": "com.ohos.server.MainAbility",
};
};
FA.connectAbility(want, connect);
FA.connectAbility(want, connect);
let option = new rpc.MessageOption();
let option = new rpc.MessageOption();
...
@@ -2535,8 +2590,8 @@ Sends a **MessageParcel** message to the peer process in synchronous or asynchro
...
@@ -2535,8 +2590,8 @@ Sends a **MessageParcel** message to the peer process in synchronous or asynchro
});
});
```
```
- Example<sup>8+</sup>
- Example:<sup>8+</sup>
```
```
import FA from "@ohos.ability.featureAbility";
import FA from "@ohos.ability.featureAbility";
let proxy;
let proxy;
...
@@ -2553,8 +2608,8 @@ Sends a **MessageParcel** message to the peer process in synchronous or asynchro
...
@@ -2553,8 +2608,8 @@ Sends a **MessageParcel** message to the peer process in synchronous or asynchro
}
}
};
};
let want = {
let want = {
"bundleName": "com.huawei.server",
"bundleName": "com.ohos.server",
"abilityName": "com.huawei.server.MainAbility",
"abilityName": "com.ohos.server.MainAbility",
};
};
FA.connectAbility(want, connect);
FA.connectAbility(want, connect);
let option = new rpc.MessageOption();
let option = new rpc.MessageOption();
...
@@ -2586,20 +2641,21 @@ Sends a **MessageParcel** message to the peer process in synchronous or asynchro
...
@@ -2586,20 +2641,21 @@ Sends a **MessageParcel** message to the peer process in synchronous or asynchro
Sends a **MessageParcel** message to the peer process in synchronous or asynchronous mode. If **options** indicates the asynchronous mode, a callback will be invoked immediately and the **reply** message does not contain any content. If **options** indicates the synchronous mode, a callback will be invoked when the response to **sendRequest** is returned, and the **reply** message contains the returned information.
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.
| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool. |
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes | **MessageParcel** object holding the data to send. |
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
| syncFlags | number | No | Specifies whether the **SendRequest** is called synchronously (default) or asynchronously. |
| syncFlags | number | No| Call flag, which can be synchronous or asynchronous. The default value is **synchronous**.|
| waitTime | number | No | Maximum wait time for an RPC call. The default value is **TF_WAIT_TIME**. |
| waitTime | number | No| Maximum wait time for an RPC call. The default value is **TF_WAIT_TIME**.|
### getFlags
### getFlags
getFlags(): number
getFlags(): number
Obtains the **SendRequest**call flag, which can be synchronous or asynchronous.
Obtains the call flag, which can be synchronous or asynchronous.
@@ -3015,14 +3043,15 @@ static getCallingPid(): number
...
@@ -3015,14 +3043,15 @@ static getCallingPid(): number
Obtains the PID of the caller. This method is invoked by the **RemoteObject** object in the **onRemoteRequest** method. If this method is not invoked in the IPC context (**onRemoteRequest**), the PID of the process will be returned.
Obtains the PID of the caller. This method is invoked by the **RemoteObject** object in the **onRemoteRequest** method. If this method is not invoked in the IPC context (**onRemoteRequest**), the PID of the process will be returned.
@@ -3040,14 +3069,15 @@ static getCallingUid(): number
...
@@ -3040,14 +3069,15 @@ static getCallingUid(): number
Obtains the UID of the caller. This method is invoked by the **RemoteObject** object in the **onRemoteRequest** method. If this method is not invoked in the IPC context (**onRemoteRequest**), the UID of the process will be returned.
Obtains the UID of the caller. This method is invoked by the **RemoteObject** object in the **onRemoteRequest** method. If this method is not invoked in the IPC context (**onRemoteRequest**), the UID of the process will be returned.
| boolean | Returns**true** if the local and remote processes are on the same device; returns **false** otherwise.|
- Example
- Example
```
```
class Stub extends rpc.RemoteObject {
class Stub extends rpc.RemoteObject {
onRemoteRequest(code, data, reply, option) {
onRemoteRequest(code, data, reply, option) {
...
@@ -3140,19 +3199,21 @@ static flushCommands(object : IRemoteObject): number
...
@@ -3140,19 +3199,21 @@ static flushCommands(object : IRemoteObject): number
Flushes all suspended commands from the specified **RemoteProxy** to the corresponding **RemoteObject**. It is recommended that this method be called before any time-sensitive operation is performed.
Flushes all suspended commands from the specified **RemoteProxy** to the corresponding **RemoteObject**. It is recommended that this method be called before any time-sensitive operation is performed.
| number | Returns **0** if the operation is successful; returns an error code if the input object is null or a **RemoteObject**, or the operation fails. |
| number | Returns**0** if the operation is successful; returns an error code if the input object is null or a **RemoteObject**, or if the operation fails.|
- Example
- Example
```
```
let remoteObject = new rpc.RemoteObject("aaa", 3);
let remoteObject = new rpc.RemoteObject("aaa", 3);
let ret = rpc.IPCSkeleton.flushCommands(remoteObject);
let ret = rpc.IPCSkeleton.flushCommands(remoteObject);
Restores the UID and PID of the remote user. It is usually called when the UID and PID of the remote user are required. The UID and PID of the remote user are returned by **resetCallingIdentity**.
Restores the UID and PID of the remote user. It is usually called when the UID and PID of the remote user are required. The UID and PID of the remote user are returned by **resetCallingIdentity**.
Sends a **MessageParcel** message to the peer process in synchronous or asynchronous mode. If **options** indicates the asynchronous mode, a promise will be fulfilled immediately and the **reply** message does not contain any content. If **options** indicates the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool. |
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes | **MessageParcel** object holding the data to send. |
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
| Promise<number><sup>7</sup><br>Promise<SendRequestResult><sup>8+</sup> | Promise used to return the result. The value **0** will be returned if the request is sent successfully. Otherwise, an error code will be returned.<sup>7</sup><br>Promise used to return the **sendRequestResult** object.<sup>8+</sup> |
- Example<sup>7</sup>
- Example<sup>7</sup>
```
```
class TestRemoteObject extends rpc.RemoteObject {
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
constructor(descriptor) {
...
@@ -3293,7 +3361,7 @@ Sends a **MessageParcel** message to the peer process in synchronous or asynchro
...
@@ -3293,7 +3361,7 @@ Sends a **MessageParcel** message to the peer process in synchronous or asynchro
- Example<sup>8+</sup>
- Example<sup>8+</sup>
```
```
class TestRemoteObject extends rpc.RemoteObject {
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
constructor(descriptor) {
...
@@ -3330,20 +3398,22 @@ Sends a **MessageParcel** message to the peer process in synchronous or asynchro
...
@@ -3330,20 +3398,22 @@ Sends a **MessageParcel** message to the peer process in synchronous or asynchro
Sends a **MessageParcel** message to the peer process in synchronous or asynchronous mode. If **options** indicates the asynchronous mode, a callback will be invoked immediately and the **reply** message does not contain any content. If **options** indicates the synchronous mode, a callback will be invoked when the response to **sendRequest** is returned, and the **reply** message contains the returned information.
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.
| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool. |
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes | **MessageParcel** object holding the data to send. |
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
@@ -3550,36 +3632,40 @@ Binds an interface descriptor to an **IRemoteBroker** object.
...
@@ -3550,36 +3632,40 @@ Binds an interface descriptor to an **IRemoteBroker** object.
Provides methods related to anonymous shared memory objects, including creating, closing, mapping, and unmapping an **Ashmem** object, reading data from and writing data to an **Ashmem** object, obtaining the **Ashmem** size, and setting **Ashmem** protection.
Provides methods related to anonymous shared memory objects, including creating, closing, mapping, and unmapping an **Ashmem** object, reading data from and writing data to an **Ashmem** object, obtaining the **Ashmem** size, and setting **Ashmem** protection.
The following table describes the protection types of the mapped memory.
The table below describes the protection types of the mapped memory.
Creates an **Ashmem** object by copying the file descriptor (FD) of an existing **Ashmem** object. The two **Ashmem** objects point to the same shared memory region.
Creates an **Ashmem** object by copying the file descriptor (FD) of an existing Ashmem object. The two **Ashmem** objects point to the same shared memory region.