提交 325b6c95 编写于 作者: G Gloria

Update docs against 20134+20689+20504+20880+20427+20850+21156+2098421037

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 7acd5f8f
......@@ -23,81 +23,88 @@ For details about the APIs, see [native_window](../reference/native-apis/_native
The following describes how to use the native APIs provided by **NativeWindow** to request a graphics buffer, write the produced graphics content to the buffer, and flush the buffer to the graphics queue.
**Adding Dynamic Link Libraries**
Add the following libraries to **CMakeLists.txt**:
```txt
libace_ndk.z.so
libnative_window.so
```
**Header File**
```c++
#include <ace/xcomponent/native_interface_xcomponent.h>
#include <native_window/external_window.h>
```
1. Obtain an **OHNativeWindow** instance, which can be obtained by running the APIs provided by [OH_NativeXComponent_Callback](../reference/native-apis/_o_h___native_x_component___callback.md).
1. Define **XComponent** in an .ets file.
1. Obtain an **OHNativeWindow** instance.
You can call the APIs provided by [OH_NativeXComponent_Callback](../reference/native-apis/_o_h___native_x_component___callback.md) to obtain an **OHNativeWindow** instance. An example code snippet is provided below. For details about how to use the **\<XComponent>**, see [XComponent Development](xcomponent-guidelines.md).
1. Add an **\<XComponent>** to the .ets file.
```ts
XComponent({ id: 'xcomponentId', type: 'surface', libraryname: 'nativerender'})
.onLoad((context) => {
this.context = context;
})
.onDestroy(() => {
})
XComponent({ id: 'xcomponentId', type: 'surface', libraryname: 'entry'})
.width(360)
.height(360)
```
2. Obtain **NativeXComponent** at the native C++ layer.
```c++
napi_value exportInstance = nullptr;
// Parse the attribute of the wrapped NativeXComponent pointer.
napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance);
OH_NativeXComponent *nativeXComponent = nullptr;
// Use the napi_unwrap API to parse the NativeXComponent instance pointer.
napi_unwrap(env, exportInstance, reinterpret_cast<void**>(&nativeXComponent));
```
3. Define **OH_NativeXComponent_Callback**.
```c++
// Define the callback.
void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window)
{
// Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = static_cast<OHNativeWindow*>(window);
// ...
}
void OnSurfaceChangedCB(OH_NativeXComponent* component, void* window)
{
// Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = static_cast<OHNativeWindow*>(window);
// ...
}
void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window)
{
// Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = static_cast<OHNativeWindow*>(window);
// ...
}
void DispatchTouchEventCB(OH_NativeXComponent* component, void* window)
{
// Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = static_cast<OHNativeWindow*>(window);
// ...
}
```
```c++
// Initialize OH_NativeXComponent_Callback.
OH_NativeXComponent_Callback callback;
callback.OnSurfaceCreated = OnSurfaceCreatedCB;
callback.OnSurfaceChanged = OnSurfaceChangedCB;
callback.OnSurfaceDestroyed = OnSurfaceDestroyedCB;
callback.DispatchTouchEvent = DispatchTouchEventCB;
```
2. Obtain **NativeXComponent** at the native C++ layer.
```c++
napi_value exportInstance = nullptr;
napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance);
OH_NativeXComponent *nativeXComponent = nullptr;
napi_unwrap(env, exportInstance, reinterpret_cast<void**>(&nativeXComponent));
char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = { };
uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize);
```
3. Define **OH_NativeXComponent_Callback**.
```c++
// Define the callback.
void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window)
{
// Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = window;
// ...
}
void OnSurfaceChangedCB(OH_NativeXComponent* component, void* window)
{
// Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = window;
// ...
}
void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window)
{
// Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = window;
// ...
}
void DispatchTouchEventCB(OH_NativeXComponent* component, void* window)
{
// Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = window;
// ...
}
```
```c++
// Initialize OH_NativeXComponent_Callback.
OH_NativeXComponent_Callback callback_;
callback_->OnSurfaceCreated = OnSurfaceCreatedCB;
callback_->OnSurfaceChanged = OnSurfaceChangedCB;
callback_->OnSurfaceDestroyed = OnSurfaceDestroyedCB;
callback_->DispatchTouchEvent = DispatchTouchEventCB;
```
4. Register **OH_NativeXComponent_Callback** with **NativeXComponent**.
```c++
OH_NativeXComponent_RegisterCallback(nativeXComponent, &callback_);
```
```c++
// Register the callback.
OH_NativeXComponent_RegisterCallback(nativeXComponent, &callback);
```
2. Set the attributes of an **OHNativeWindowBuffer** by using **OH_NativeWindow_NativeWindowHandleOpt**.
```c++
// Set the width and height of the OHNativeWindowBuffer.
code = SET_BUFFER_GEOMETRY;
int32_t code = SET_BUFFER_GEOMETRY;
int32_t width = 0x100;
int32_t height = 0x100;
ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, width, height);
// The nativeWindow instance is obtained from the callback in the previous step.
int32_t ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, width, height);
// Set the step of the OHNativeWindowBuffer.
code = SET_STRIDE;
int32_t stride = 0x8;
......@@ -109,18 +116,27 @@ The following describes how to use the native APIs provided by **NativeWindow**
OHNativeWindowBuffer* buffer = nullptr;
int fenceFd;
// Obtain the OHNativeWindowBuffer instance by calling OH_NativeWindow_NativeWindowRequestBuffer.
OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow_, &buffer, &fenceFd);
// Obtain the buffer handle by calling OH_NativeWindow_GetNativeBufferHandleFromNative.
BufferHandle* bufferHandle = OH_NativeWindow_GetNativeBufferHandleFromNative(buffer);
OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &buffer, &fenceFd);
// Obtain the buffer handle by calling OH_NativeWindow_GetBufferHandleFromNative.
BufferHandle* bufferHandle = OH_NativeWindow_GetBufferHandleFromNative(buffer);
```
4. Map memory.
```c++
#include <sys/mman.h>
// Use mmap() to obtain the memory virtual address of buffer handle.
void* mappedAddr = mmap(bufferHandle->virAddr, bufferHandle->size, PROT_READ | PROT_WRITE, MAP_SHARED, bufferHandle->fd, 0);
if (mappedAddr == MAP_FAILED) {
// mmap failed
}
```
4. Write the produced content to the **OHNativeWindowBuffer**.
5. Write the produced content to the **OHNativeWindowBuffer**.
```c++
auto image = static_cast<uint8_t *>(buffer->sfbuffer->GetVirAddr());
static uint32_t value = 0x00;
value++;
uint32_t *pixel = static_cast<uint32_t *>(image);
uint32_t *pixel = static_cast<uint32_t *>(mappedAddr); // Use the address obtained by mmap() to access the memory.
for (uint32_t x = 0; x < width; x++) {
for (uint32_t y = 0; y < height; y++) {
*pixel++ = value;
......@@ -133,5 +149,15 @@ The following describes how to use the native APIs provided by **NativeWindow**
// Set the refresh region. If Rect in Region is a null pointer or rectNumber is 0, all contents in the OHNativeWindowBuffer are changed.
Region region{nullptr, 0};
// Flush the buffer to the consumer through OH_NativeWindow_NativeWindowFlushBuffer, for example, by displaying it on the screen.
OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow_, buffer, fenceFd, region);
OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, buffer, fenceFd, region);
```
6. Unmap memory.
```c++
// Unmap the memory when the memory is no longer required.
int result = munmap(mappedAddr, bufferHandle->size);
if (result == -1) {
// munmap failed
}
```
<!--no_check-->
\ No newline at end of file
......@@ -926,6 +926,115 @@ async function Demo() {
}
```
### marshalling<sup>10+</sup>
marshalling(sequence: rpc.MessageSequence): void
Marshals this **PixelMap** object and writes it to a **MessageSequence** object.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------------------- | ------------------------------------------------------ | ---- | ---------------------------------------- |
| sequence | [rpc.MessageSequence](js-apis-rpc.md#messagesequence9) | Yes | **MessageSequence** object. |
**Error codes**
For details about the error codes, see [ResponseCode](#responsecode).
| ID| Error Message|
| ------- | --------------------------------------------|
| 62980115 | If the input parameter invalid |
| 62980097 | If the ipc error |
**Example**
```js
import image from '@ohos.multimedia.image'
import rpc from '@ohos.rpc'
class MySequence {
pixel_map;
constructor(pixelmap) {
this.pixel_map = pixelmap;
}
marshalling(messageSequence) {
this.pixel_map.marshalling(messageSequence);
return true;
}
async unmarshalling(messageSequence) {
await image.unmarshalling(messageSequence).then(async (pixelMap) => {
this.pixel_map = pixelMap;
})
return true;
}
}
async function Demo() {
let parcelable = new MySequence(pixelmap);
let data = rpc.MessageSequence.create();
data.writeParcelable(parcelable);
}
```
### unmarshalling<sup>10+</sup>
unmarshalling(sequence: rpc.MessageSequence): Promise\<PixelMap>
Unmarshals a **MessageSequence** object to obtain a **PixelMap** object.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- |
| sequence | [rpc.MessageSequence](js-apis-rpc.md#messagesequence9) | Yes | **MessageSequence** object that stores the **PixelMap** information. |
**Return value**
| Type | Description |
| -------------------------------- | --------------------- |
| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.|
**Error codes**
For details about the error codes, see [ResponseCode](#responsecode).
| ID| Error Message|
| ------- | --------------------------------------------|
| 62980115 | If the input parameter invalid |
| 62980097 | If the ipc error |
**Example**
```js
import image from '@ohos.multimedia.image'
import rpc from '@ohos.rpc'
class MySequence {
pixel_map;
constructor(pixelmap) {
this.pixel_map = pixelmap;
}
marshalling(messageSequence) {
this.pixel_map.marshalling(messageSequence);
return true;
}
async unmarshalling(messageSequence) {
await image.unmarshalling(messageSequence).then(async (pixelMap) => {
this.pixel_map = pixelMap;
})
return true;
}
}
async function Demo() {
let pixel_map = undefined;
let ret = new MySequence(pixel_map);
let data = rpc.MessageSequence.create();
await data.readParcelable(ret);
}
```
### release<sup>7+</sup>
release():Promise\<void>
......@@ -1590,7 +1699,7 @@ Creates an array of **PixelMap** objects based on image decoding parameters. Thi
| Type | Description |
| -------------------------------- | --------------------- |
| Promise<Array<[PixelMap](#pixelmap7)>> | Promise used to return an array of **PixeMap** objects.|
| Promise<Array<[PixelMap](#pixelmap7)>> | Promise used to return an array of **PixelMap** objects.|
**Example**
......@@ -1618,7 +1727,7 @@ Creates an array of **PixelMap** objects based on the default parameters. This A
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | Yes | Callback used to return an array of **PixeMap** objects.|
| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | Yes | Callback used to return an array of **PixelMap** objects.|
**Example**
......@@ -1641,7 +1750,7 @@ Creates an array of **PixelMap** objects based on image decoding parameters. Thi
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------------------- |
| options | [DecodingOptions](#decodingoptions7) | Yes| Image decoding parameters.|
| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | Yes | Callback used to return an array of **PixeMap** objects.|
| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | Yes | Callback used to return an array of **PixelMap** objects.|
**Example**
......@@ -2795,7 +2904,29 @@ Describes the exchangeable image file format (EXIF) data of an image.
| SCENE_TYPE<sup>9+</sup> | "SceneType" | Shooting scene type, for example, portrait, scenery, motion, and night. |
| ISO_SPEED_RATINGS<sup>9+</sup> | "ISOSpeedRatings" | ISO sensitivity or ISO speed, for example, 400. |
| F_NUMBER<sup>9+</sup> | "FNumber" | Aperture, for example, f/1.8. |
| DATE_TIME<sup>10+</sup> | "DateTime" | Date and time. |
| GPS_TIME_STAMP<sup>10+</sup> | "GPSTimeStamp" | GPS timestamp. |
| GPS_DATE_STAMP<sup>10+</sup> | "GPSDateStamp" | GPS date stamp. |
| IMAGE_DESCRIPTION<sup>10+</sup> | "ImageDescription" | Image description. |
| MAKE<sup>10+</sup> | "Make" | Vendor. |
| PHOTO_MODE<sup>10+</sup> | "PhotoMode " | Photo mode. |
| SENSITIVITY_TYPE<sup>10+</sup> | "SensitivityType" | Sensitivity type. |
| STANDARD_OUTPUT_SENSITIVITY<sup>10+</sup> | "StandardOutputSensitivity" | Standard output sensitivity. |
| RECOMMENDED_EXPOSURE_INDEX<sup>10+</sup> | "RecommendedExposureIndex" | Recommended exposure index. |
| ISO_SPEED<sup>10+</sup> | "ISOSpeedRatings" | ISO speed. |
| APERTURE_VALUE<sup>10+</sup> | "ApertureValue" | Aperture value. |
| EXPOSURE_BIAS_VALUE<sup>10+</sup> | "ExposureBiasValue" | Exposure bias value. |
| METERING_MODE<sup>10+</sup> | "MeteringMode" | Metering mode. |
| LIGHT_SOURCE<sup>10+</sup> | "LightSource" | Light source. |
| FLASH <sup>10+</sup> | "Flash" | Flash status. |
| FOCAL_LENGTH <sup>10+</sup> | "FocalLength" | Focal length. |
| USER_COMMENT <sup>10+</sup> | "UserComment" | User comment. |
| PIXEL_X_DIMENSION <sup>10+</sup> | "PixelXDimension" | Pixel X dimension. |
| PIXEL_Y_DIMENSION<sup>10+</sup> | "PixelYDimension" | Pixel Y dimension. |
| WHITE_BALANCE <sup>10+</sup> | "WhiteBalance" | White balance. |
| FOCAL_LENGTH_IN_35_MM_FILM <sup>10+</sup> | "FocalLengthIn35mmFilm" | Focal length in 35mm film. |
| CAPTURE_MODE <sup>10+</sup> | "HwMnoteCaptureMode" | Capture mode. |
| PHYSICAL_APERTURE <sup>10+</sup> | "HwMnotePhysicalAperture" | Physical aperture. |
## ImageFormat<sup>9+</sup>
......
......@@ -2080,7 +2080,7 @@ let result = that.encodeSync(array);
### encodeToStringSync<sup>9+</sup>
encodeToStringSync(src: Uint8Array): string
encodeToStringSync(src: Uint8Array, options?: Type): string
Encodes the input content.
......@@ -2091,6 +2091,7 @@ Encodes the input content.
| Name| Type | Mandatory| Description |
| ------ | ---------- | ---- | ------------------- |
| src | Uint8Array | Yes | Uint8Array to encode.|
| options<sup>10+</sup> | [Type](#type10) | No | Encoding format.<br>The following values are available:<br>- **util.Type.BASIC** (default value): The output can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). There is no carriage return or line feed character.<br>- **util.Type.MIME**: The output can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). Each line of the output contains a maximum of 76 characters, ended with '\r\n'.|
**Return value**
......@@ -2102,14 +2103,14 @@ Encodes the input content.
```js
let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]);
let result = that.encodeToStringSync(array);
let array = new Uint8Array([77,97,110,105,115,100,105,115,116,105,110,103,117,105,115,104,101,100,110,111,116,111,110,108,121,98,121,104,105,115,114,101,97,115,111,110,98,117,116,98,121,116,104,105,115,115,105,110,103,117,108,97,114,112,97,115,115,105,111,110,102,114,111,109,111,116,104,101,114,97,110,105,109,97,108,115,119,104,105,99,104,105,115,97,108,117,115,116,111,102,116,104,101,109,105,110,100,101,120,99,101,101,100,115,116,104,101,115,104,111,114,116,118,101,104,101,109,101,110,99,101,111,102,97,110,121,99,97,114,110,97,108,112,108,101,97,115,117,114,101]);
let result = that.encodeToStringSync(array, util.Type.MIME);
```
### decodeSync<sup>9+</sup>
decodeSync(src: Uint8Array | string): Uint8Array
decodeSync(src: Uint8Array | string, options?: Type): Uint8Array
Decodes the input content.
......@@ -2120,6 +2121,7 @@ Decodes the input content.
| Name| Type | Mandatory| Description |
| ------ | ------------------------------ | ---- | ----------------------------- |
| src | Uint8Array&nbsp;\|&nbsp;string | Yes | Uint8Array or string to decode.|
| options<sup>10+</sup> | [Type](#type10) | No | Encoding format.<br>The following values are available:<br>- **util.Type.BASIC** (default value): The input can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). There is no carriage return or line feed character.<br>- **util.Type.MIME**: The input can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). Each line of the input contains a maximum of 76 characters, ended with '\r\n'.|
**Return value**
......@@ -2131,8 +2133,8 @@ Decodes the input content.
```js
let that = new util.Base64Helper();
let buff = 'czEz';
let result = that.decodeSync(buff);
let buff = 'TWFuaXNkaXN0aW5ndWlzaGVkbm90b25seWJ5aGlzcmVhc29uYnV0Ynl0aGlzc2luZ3VsYXJwYXNz\r\naW9uZnJvbW90aGVyYW5pbWFsc3doaWNoaXNhbHVzdG9mdGhlbWluZGV4Y2VlZHN0aGVzaG9ydHZl\r\naGVtZW5jZW9mYW55Y2FybmFscGxlYXN1cmU=\r\n';
let result = that.decodeSync(buff, util.Type.MIME);
```
......@@ -2172,7 +2174,7 @@ that.encode(array).then(val=>{
### encodeToString<sup>9+</sup>
encodeToString(src: Uint8Array): Promise&lt;string&gt;
encodeToString(src: Uint8Array, options?: Type): Promise&lt;string&gt;
Encodes the input content asynchronously.
......@@ -2183,6 +2185,7 @@ Encodes the input content asynchronously.
| Name| Type | Mandatory| Description |
| ------ | ---------- | ---- | ----------------------- |
| src | Uint8Array | Yes | Uint8Array to encode asynchronously.|
| options<sup>10+</sup> | [Type](#type10) | No | Encoding format.<br>The following values are available:<br>- **util.Type.BASIC** (default value): The output can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). There is no carriage return or line feed character.<br>- **util.Type.MIME**: The output can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). Each line of the output contains a maximum of 76 characters, ended with '\r\n'.|
**Return value**
......@@ -2194,16 +2197,16 @@ Encodes the input content asynchronously.
```js
let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]);
that.encodeToString(array).then(val=>{
console.log(val)
let array = new Uint8Array([77,97,110,105,115,100,105,115,116,105,110,103,117,105,115,104,101,100,110,111,116,111,110,108,121,98,121,104,105,115,114,101,97,115,111,110,98,117,116,98,121,116,104,105,115,115,105,110,103,117,108,97,114,112,97,115,115,105,111,110,102,114,111,109,111,116,104,101,114,97,110,105,109,97,108,115,119,104,105,99,104,105,115,97,108,117,115,116,111,102,116,104,101,109,105,110,100,101,120,99,101,101,100,115,116,104,101,115,104,111,114,116,118,101,104,101,109,101,110,99,101,111,102,97,110,121,99,97,114,110,97,108,112,108,101,97,115,117,114,101]);
that.encodeToString(array, util.Type.MIME).then(val=>{
// Add information as required.
})
```
### decode<sup>9+</sup>
decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt;
decode(src: Uint8Array | string, options?: Type): Promise&lt;Uint8Array&gt;
Decodes the input content asynchronously.
......@@ -2214,6 +2217,7 @@ Decodes the input content asynchronously.
| Name| Type | Mandatory| Description |
| ------ | ------------------------------ | ---- | --------------------------------- |
| src | Uint8Array&nbsp;\|&nbsp;string | Yes | Uint8Array or string to decode asynchronously.|
| options<sup>10+</sup> | [Type](#type10) | No | Encoding format.<br>The following values are available:<br>- **util.Type.BASIC** (default value): The input can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). There is no carriage return or line feed character.<br>- **util.Type.MIME**: The input can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). Each line of the input contains a maximum of 76 characters, ended with '\r\n'.|
**Return value**
......@@ -2225,15 +2229,25 @@ Decodes the input content asynchronously.
```js
let that = new util.Base64Helper();
let array = new Uint8Array([99,122,69,122]);
let rarray = new Uint8Array([115,49,51]);
that.decode(array).then(val=>{
for (var i = 0; i < rarray.length; i++) {
console.log(val[i].toString())
}
let array = 'TWFuaXNkaXN0aW5ndWlzaGVkbm90b25seWJ5aGlzcmVhc29uYnV0Ynl0aGlzc2luZ3VsYXJwYXNz\r\naW9uZnJvbW90aGVyYW5pbWFsc3doaWNoaXNhbHVzdG9mdGhlbWluZGV4Y2VlZHN0aGVzaG9ydHZl\r\naGVtZW5jZW9mYW55Y2FybmFscGxlYXN1cmU=\r\n';
that.decode(array, util.Type.MIME).then(val=>{
// Add information as required.
})
```
## Type<sup>10+</sup>
Enumerates the Base64 encoding formats.
**System capability**: SystemCapability.Utils.Lang
| Name | Value | Description |
| -------- | ------------------------ | ---------------- |
| BASIC | 0 | Basic format.|
| MIME | 1 | MIME format.|
## types<sup>8+</sup>
Provides APIs to check different types of built-in objects, such as ArrayBuffer, Map, and Set, so as to avoid exceptions or crashes caused by type errors.
......
......@@ -859,6 +859,15 @@ Subscribes to the gesture navigation status change event.
| type | string | Yes | Event type. The value is fixed at **'gestureNavigationEnabledChange'**, indicating the gesture navigation status change event. |
| callback | Callback&lt;boolean&gt; | Yes | Callback used to return the gesture navigation status. The value **true** means that the gesture navigation status is changed to enabled, and **false** means that the gesture navigation status is changed to disabled.|
**Error codes**
For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md).
| ID| Error Message|
| ------- | -------------------------------------------- |
| 1300002 | This window state is abnormal. |
| 1300003 | This window manager service works abnormally. |
**Example**
```js
......@@ -888,6 +897,15 @@ Unsubscribes from the gesture navigation status change event.
| type | string | Yes| Event type. The value is fixed at **'gestureNavigationEnabledChange'**, indicating the gesture navigation status change event.|
| callback | Callback&lt;boolean&gt; | No| Callback function that has been used for registering the listener. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.|
**Error codes**
For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md).
| ID| Error Message|
| ------- | -------------------------------------------- |
| 1300002 | This window state is abnormal. |
| 1300003 | This window manager service works abnormally. |
**Example**
```js
......@@ -2744,7 +2762,7 @@ try {
### on('avoidAreaChange')<sup>9+</sup>
on(type: 'avoidAreaChange', callback: Callback&lt;{AvoidAreaType, AvoidArea}&gt;): void
on(type: 'avoidAreaChange', callback: Callback&lt;{ type: AvoidAreaType, area: AvoidArea}&gt;): void
Subscribes to the event indicating changes to the area where the window cannot be displayed.
......@@ -2755,7 +2773,7 @@ Subscribes to the event indicating changes to the area where the window cannot b
| Name | Type | Mandatory| Description |
| -------- |------------------------------------------------------------------| ---- |--------------------------------------|
| type | string | Yes | Event type. The value is fixed at **'avoidAreaChange'**, indicating the event of changes to the area where the window cannot be displayed.|
| callback | Callback&lt;{[AvoidAreaType](#avoidareatype7), [AvoidArea](#avoidarea7)}&gt; | Yes | Callback used to return the area and area type.|
| callback | Callback&lt;{ type: [AvoidAreaType](#avoidareatype7), area: [AvoidArea](#avoidarea7) }&gt; | Yes | Callback used to return the area and area type.|
**Example**
......@@ -2772,7 +2790,7 @@ try {
### off('avoidAreaChange')<sup>9+</sup>
off(type: 'avoidAreaChange', callback?: Callback&lt;{AvoidAreaType, AvoidArea}&gt;): void
off(type: 'avoidAreaChange', callback?: Callback&lt;{ type: AvoidAreaType, area: AvoidArea }&gt;): void
Unsubscribes from the event indicating changes to the area where the window cannot be displayed.
......@@ -2783,7 +2801,7 @@ Unsubscribes from the event indicating changes to the area where the window cann
| Name | Type | Mandatory | Description |
| -------- |-----------------------------------------------------------------------------|-----|------------------------------------|
| type | string | Yes | Event type. The value is fixed at **'avoidAreaChange'**, indicating the event of changes to the area where the window cannot be displayed.|
| callback | Callback&lt;{[AvoidAreaType](#avoidareatype7), [AvoidArea](#avoidarea7)}&gt; | No | Callback used to return the area and area type. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.|
| callback | Callback&lt;{ type: [AvoidAreaType](#avoidareatype7), area: [AvoidArea](#avoidarea7) }&gt; | No | Callback used to return the area and area type. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.|
**Example**
......@@ -3122,7 +3140,16 @@ class TestRemoteObject extends rpc.RemoteObject {
}
let token = new TestRemoteObject('testObject');
let windowClass = null;
let config = {name: "dialogWindow", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context};
try {
window.createWindow(config, (err, data) => {
if (err.code) {
console.error('Failed to create the window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
});
windowClass.bindDialogTarget(token, () => {
console.info('Dialog Window Need Destroy.');
}, (err) => {
......@@ -3195,7 +3222,16 @@ class TestRemoteObject extends rpc.RemoteObject {
}
let token = new TestRemoteObject('testObject');
let windowClass = null;
let config = {name: "dialogWindow", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context};
try {
window.createWindow(config, (err, data) => {
if (err.code) {
console.error('Failed to create the window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
});
let promise = windowClass.bindDialogTarget(token, () => {
console.info('Dialog Window Need Destroy.');
});
......@@ -3246,7 +3282,16 @@ import window from '@ohos.window';
export default class ServiceExtAbility extends ServiceExtensionAbility {
onRequest(want, startId) {
console.info('onRequest');
let windowClass = null;
let config = {name: "dialogWindow", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context};
try {
window.createWindow(config, (err, data) => {
if (err.code) {
console.error('Failed to create the window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
});
let requestInfo = dialogRequest.getRequestInfo(want)
windowClass.bindDialogTarget(requestInfo, () => {
console.info('Dialog Window Need Destroy.');
......@@ -3258,7 +3303,7 @@ export default class ServiceExtAbility extends ServiceExtensionAbility {
console.info('Succeeded in binding dialog target.');
});
} catch(err) {
console.error('getRequestInfo err = ' + JSON.stringify(err))
console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err))
}
}
}
......@@ -3306,7 +3351,16 @@ import window from '@ohos.window';
export default class ServiceExtAbility extends ServiceExtensionAbility {
onRequest(want, startId) {
console.info('onRequest');
let windowClass = null;
let config = {name: "dialogWindow", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context};
try {
window.createWindow(config, (err, data) => {
if (err.code) {
console.error('Failed to create the window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
});
let requestInfo = dialogRequest.getRequestInfo(want)
let promise = windowClass.bindDialogTarget(requestInfo, () => {
console.info('Dialog Window Need Destroy.');
......@@ -3317,7 +3371,7 @@ export default class ServiceExtAbility extends ServiceExtensionAbility {
console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err));
});
} catch(err) {
console.error('getRequestInfo err = ' + JSON.stringify(err))
console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err))
}
}
}
......
# Distributed Remote Startup<a name="EN-US_TOPIC_0000001051071561"></a>
## Overview<a name="section186634310418"></a>
The Distributed Manager Service sets up a distributed service platform in OpenHarmony by using a proxy between the primary and secondary devices. With the Distributed Manager Service, the primary device \(OpenHarmony-powered smart TV\) can start a Feature Ability \(FA\) deployed on the secondary device \(a memory-constrained OpenHarmony device such as an IP camera or a lite wearable\).
For example, if a user presses the **Remind Me** button for a TV program on the smart TV, the smart TV will start the corresponding reminder FA on the lite wearable to remind the user when the particular TV program is available.
## Basic Concepts<a name="section982651246"></a>
- FA
Feature Ability, representing an ability with a UI for interacting with users
- Remote startup
Cross-device FA startup, which is the counterpart of local FA startup
## Available APIs<a name="section125479541744"></a>
The following table describes the API that can be used by smart TVs to remotely start an FA. This API is provided in the **AbilitySlice** class. For details, see the Java API reference for OpenHarmony application development.
**Table 1** API for remotely starting an FA on the distributed network
<a name="table1731550155318"></a>
<table><thead align="left"><tr id="row4419501537"><th class="cellrowborder" valign="top" width="57.38999999999999%" id="mcps1.2.3.1.1"><p id="p54150165315"><a name="p54150165315"></a><a name="p54150165315"></a>Method</p>
</th>
<th class="cellrowborder" valign="top" width="42.61%" id="mcps1.2.3.1.2"><p id="p941150145313"><a name="p941150145313"></a><a name="p941150145313"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row34145016535"><td class="cellrowborder" valign="top" width="57.38999999999999%" headers="mcps1.2.3.1.1 "><p id="p1682733119213"><a name="p1682733119213"></a><a name="p1682733119213"></a>void startAbility(Want want)</p>
</td>
<td class="cellrowborder" valign="top" width="42.61%" headers="mcps1.2.3.1.2 "><p id="p13562171015712"><a name="p13562171015712"></a><a name="p13562171015712"></a>Remotely starts an FA based on the specified <strong id="b8984536181113"><a name="b8984536181113"></a><a name="b8984536181113"></a>Want</strong> information. If the name and type of the <strong id="b599520304618"><a name="b599520304618"></a><a name="b599520304618"></a>want</strong> parameter are different from those used in the integrated development environment (IDE), use the parameter name and type in the IDE.</p>
</td>
</tr>
</tbody>
</table>
**Table 2** Description of the want parameter
<a name="table02120432364"></a>
<table><thead align="left"><tr id="row172294315361"><th class="cellrowborder" valign="top" width="14.000000000000002%" id="mcps1.2.4.1.1"><p id="p722144318360"><a name="p722144318360"></a><a name="p722144318360"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="17%" id="mcps1.2.4.1.2"><p id="p10227434363"><a name="p10227434363"></a><a name="p10227434363"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="69%" id="mcps1.2.4.1.3"><p id="p22284383616"><a name="p22284383616"></a><a name="p22284383616"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row3228436365"><td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.2.4.1.1 "><p id="p1391227193713"><a name="p1391227193713"></a><a name="p1391227193713"></a>want</p>
</td>
<td class="cellrowborder" valign="top" width="17%" headers="mcps1.2.4.1.2 "><p id="p20993611193719"><a name="p20993611193719"></a><a name="p20993611193719"></a>ohos.aafwk.content.Want</p>
</td>
<td class="cellrowborder" valign="top" width="69%" headers="mcps1.2.4.1.3 "><p id="p10555172211377"><a name="p10555172211377"></a><a name="p10555172211377"></a>When you use <strong id="b1013275220199"><a name="b1013275220199"></a><a name="b1013275220199"></a>startAbility(Want want)</strong> to remotely start an FA, you must first specify the <strong id="b1125035416223"><a name="b1125035416223"></a><a name="b1125035416223"></a>deviceId</strong>, <strong id="b16473135811222"><a name="b16473135811222"></a><a name="b16473135811222"></a>bundleName</strong>, and <strong id="b157931324230"><a name="b157931324230"></a><a name="b157931324230"></a>abilityName</strong> attributes of the target FA in the <strong id="b34832152239"><a name="b34832152239"></a><a name="b34832152239"></a>Want</strong> object.</p>
</td>
</tr>
</tbody>
</table>
## Limitations and Constraints<a name="section1165911177314"></a>
- The primary device can remotely start an FA of the secondary device, but the secondary device cannot remotely start an FA of the primary device.
- Before the remote startup, ensure that the two OpenHarmony devices are on the same network segment and can ping each other on the distributed network. Otherwise, the remote startup fails.
- Currently, only the FAs that have the same public key \(that is, the same Huawei certificate\) can be started between the primary and secondary devices.
## How to Develop<a name="section34171333656"></a>
To enable the primary device \(smart TV\) to start an FA of the secondary device \(assuming that the target FA has been developed\), perform the following steps:
1. Complete FA development for the smart TV on DevEco Studio.
2. Obtain the IDs of online secondary devices.
```
// Import the header files required for device selection.
import ohos.distributedschedule.interwork.DeviceInfo;
import ohos.distributedschedule.interwork.DeviceManager;
// Obtain the online device list.
List<DeviceInfo> deviceInfoListOnline = DeviceManager.getDmsDeviceList(DeviceInfo.FLAG_GET_ONLINE_DEVICE);
String remote_device_id;
if (deviceInfoListOnline.size() > 0)
{
remote_device_id = deviceInfoListOnline[0].GetDeviceId(); // Obtain the ID of the first device in the online device list.
}
```
3. Create a **Want** instance. You should first create an **ElementName** object with **deviceId**, **bundleName**, **abilityName** specified and add this object to the **Want** instance. Then, set the multi-device startup flag **Want.FLAG\_ABILITYSLICE\_MULTI\_DEVICE** to the **Want** instance to enable remote FA startup.
```
// Import related header files.
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Want;
import ohos.bundle.ElementName;
// Start the remote FA on the secondary device.
Want want = new Want(); // Create a Want instance that encapsulates information about the remote FA to start.
// Use the device ID obtained in step 2 and specify the FA information.
ElementName name = new ElementName(remote_device_id, "com.huawei.remote_package_name", "remote_class_name");
want.setElement(name); // Add information about the target FA for startup to the Want instance.
want.setFlags(Want.FLAG_ABILITYSLICE_MULTI_DEVICE); // Set the multi-device startup flag. If this flag is not set, remote FA startup will be unavailable.
startAbility(want); // Start the specified FA based on the want parameter. If the name and type of the want parameter are different from those used in the IDE, use the parameter name and type in the IDE.
```
......@@ -125,7 +125,7 @@ Abilities and widgets can be queried, added, refreshed, and deleted across devic
- The distributed camera supports video recording.
- Users can import account authentication information to the device security authentication system. Devices with the same login account can automatically complete authentication and networking.
- Users can use the device management native APIs to import account authentication information to the device security authentication system. Devices with the same login account can automatically complete authentication and networking.
#### Distributed data management
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册