未验证 提交 b43a6ede 编写于 作者: O openharmony_ci 提交者: Gitee

!21705 翻译完成:0801 master EN更新cherry-pick到4.0 beta2

Merge pull request !21705 from wusongqing/cherry-pick-1690858628
...@@ -23,32 +23,37 @@ For details about the APIs, see [native_window](../reference/native-apis/_native ...@@ -23,32 +23,37 @@ 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. 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** **Header File**
```c++ ```c++
#include <ace/xcomponent/native_interface_xcomponent.h>
#include <native_window/external_window.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. Obtain an **OHNativeWindow** instance.
1. Define **XComponent** in an .ets file.
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 ```ts
XComponent({ id: 'xcomponentId', type: 'surface', libraryname: 'nativerender'}) XComponent({ id: 'xcomponentId', type: 'surface', libraryname: 'entry'})
.onLoad((context) => { .width(360)
this.context = context; .height(360)
})
.onDestroy(() => {
})
``` ```
2. Obtain **NativeXComponent** at the native C++ layer. 2. Obtain **NativeXComponent** at the native C++ layer.
```c++ ```c++
napi_value exportInstance = nullptr; napi_value exportInstance = nullptr;
// Parse the attribute of the wrapped NativeXComponent pointer.
napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance); napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance);
OH_NativeXComponent *nativeXComponent = nullptr; OH_NativeXComponent *nativeXComponent = nullptr;
// Use the napi_unwrap API to parse the NativeXComponent instance pointer.
napi_unwrap(env, exportInstance, reinterpret_cast<void**>(&nativeXComponent)); 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**. 3. Define **OH_NativeXComponent_Callback**.
```c++ ```c++
...@@ -56,48 +61,50 @@ The following describes how to use the native APIs provided by **NativeWindow** ...@@ -56,48 +61,50 @@ The following describes how to use the native APIs provided by **NativeWindow**
void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window) void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window)
{ {
// Obtain an OHNativeWindow instance. // Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = window; OHNativeWindow* nativeWindow = static_cast<OHNativeWindow*>(window);
// ... // ...
} }
void OnSurfaceChangedCB(OH_NativeXComponent* component, void* window) void OnSurfaceChangedCB(OH_NativeXComponent* component, void* window)
{ {
// Obtain an OHNativeWindow instance. // Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = window; OHNativeWindow* nativeWindow = static_cast<OHNativeWindow*>(window);
// ... // ...
} }
void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window)
{ {
// Obtain an OHNativeWindow instance. // Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = window; OHNativeWindow* nativeWindow = static_cast<OHNativeWindow*>(window);
// ... // ...
} }
void DispatchTouchEventCB(OH_NativeXComponent* component, void* window) void DispatchTouchEventCB(OH_NativeXComponent* component, void* window)
{ {
// Obtain an OHNativeWindow instance. // Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = window; OHNativeWindow* nativeWindow = static_cast<OHNativeWindow*>(window);
// ... // ...
} }
``` ```
```c++ ```c++
// Initialize OH_NativeXComponent_Callback. // Initialize OH_NativeXComponent_Callback.
OH_NativeXComponent_Callback callback_; OH_NativeXComponent_Callback callback;
callback_->OnSurfaceCreated = OnSurfaceCreatedCB; callback.OnSurfaceCreated = OnSurfaceCreatedCB;
callback_->OnSurfaceChanged = OnSurfaceChangedCB; callback.OnSurfaceChanged = OnSurfaceChangedCB;
callback_->OnSurfaceDestroyed = OnSurfaceDestroyedCB; callback.OnSurfaceDestroyed = OnSurfaceDestroyedCB;
callback_->DispatchTouchEvent = DispatchTouchEventCB; callback.DispatchTouchEvent = DispatchTouchEventCB;
``` ```
4. Register **OH_NativeXComponent_Callback** with **NativeXComponent**. 4. Register **OH_NativeXComponent_Callback** with **NativeXComponent**.
```c++ ```c++
OH_NativeXComponent_RegisterCallback(nativeXComponent, &callback_); // Register the callback.
OH_NativeXComponent_RegisterCallback(nativeXComponent, &callback);
``` ```
2. Set the attributes of an **OHNativeWindowBuffer** by using **OH_NativeWindow_NativeWindowHandleOpt**. 2. Set the attributes of an **OHNativeWindowBuffer** by using **OH_NativeWindow_NativeWindowHandleOpt**.
```c++ ```c++
// Set the width and height of the OHNativeWindowBuffer. // Set the width and height of the OHNativeWindowBuffer.
code = SET_BUFFER_GEOMETRY; int32_t code = SET_BUFFER_GEOMETRY;
int32_t width = 0x100; int32_t width = 0x100;
int32_t height = 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. // Set the step of the OHNativeWindowBuffer.
code = SET_STRIDE; code = SET_STRIDE;
int32_t stride = 0x8; int32_t stride = 0x8;
...@@ -109,18 +116,27 @@ The following describes how to use the native APIs provided by **NativeWindow** ...@@ -109,18 +116,27 @@ The following describes how to use the native APIs provided by **NativeWindow**
OHNativeWindowBuffer* buffer = nullptr; OHNativeWindowBuffer* buffer = nullptr;
int fenceFd; int fenceFd;
// Obtain the OHNativeWindowBuffer instance by calling OH_NativeWindow_NativeWindowRequestBuffer. // Obtain the OHNativeWindowBuffer instance by calling OH_NativeWindow_NativeWindowRequestBuffer.
OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow_, &buffer, &fenceFd); OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &buffer, &fenceFd);
// Obtain the buffer handle by calling OH_NativeWindow_GetNativeBufferHandleFromNative. // Obtain the buffer handle by calling OH_NativeWindow_GetBufferHandleFromNative.
BufferHandle* bufferHandle = OH_NativeWindow_GetNativeBufferHandleFromNative(buffer); 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++ ```c++
auto image = static_cast<uint8_t *>(buffer->sfbuffer->GetVirAddr());
static uint32_t value = 0x00; static uint32_t value = 0x00;
value++; value++;
uint32_t *pixel = static_cast<uint32_t *>(mappedAddr); // Use the address obtained by mmap() to access the memory.
uint32_t *pixel = static_cast<uint32_t *>(image);
for (uint32_t x = 0; x < width; x++) { for (uint32_t x = 0; x < width; x++) {
for (uint32_t y = 0; y < height; y++) { for (uint32_t y = 0; y < height; y++) {
*pixel++ = value; *pixel++ = value;
...@@ -133,5 +149,15 @@ The following describes how to use the native APIs provided by **NativeWindow** ...@@ -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. // 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}; Region region{nullptr, 0};
// Flush the buffer to the consumer through OH_NativeWindow_NativeWindowFlushBuffer, for example, by displaying it on the screen. // 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() { ...@@ -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<sup>7+</sup>
release():Promise\<void> release():Promise\<void>
...@@ -1590,7 +1699,7 @@ Creates an array of **PixelMap** objects based on image decoding parameters. Thi ...@@ -1590,7 +1699,7 @@ Creates an array of **PixelMap** objects based on image decoding parameters. Thi
| Type | Description | | 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** **Example**
...@@ -1618,7 +1727,7 @@ Creates an array of **PixelMap** objects based on the default parameters. This A ...@@ -1618,7 +1727,7 @@ Creates an array of **PixelMap** objects based on the default parameters. This A
| Name | Type | Mandatory| Description | | 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** **Example**
...@@ -1641,7 +1750,7 @@ Creates an array of **PixelMap** objects based on image decoding parameters. Thi ...@@ -1641,7 +1750,7 @@ Creates an array of **PixelMap** objects based on image decoding parameters. Thi
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------------------- | | -------- | -------------------- | ---- | ---------------------------------- |
| options | [DecodingOptions](#decodingoptions7) | Yes| Image decoding parameters.| | 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** **Example**
...@@ -2795,7 +2904,29 @@ Describes the exchangeable image file format (EXIF) data of an image. ...@@ -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. | | 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. | | 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. | | 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> ## ImageFormat<sup>9+</sup>
......
...@@ -2080,7 +2080,7 @@ let result = that.encodeSync(array); ...@@ -2080,7 +2080,7 @@ let result = that.encodeSync(array);
### encodeToStringSync<sup>9+</sup> ### encodeToStringSync<sup>9+</sup>
encodeToStringSync(src: Uint8Array): string encodeToStringSync(src: Uint8Array, options?: Type): string
Encodes the input content. Encodes the input content.
...@@ -2091,6 +2091,7 @@ Encodes the input content. ...@@ -2091,6 +2091,7 @@ Encodes the input content.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ---------- | ---- | ------------------- | | ------ | ---------- | ---- | ------------------- |
| src | Uint8Array | Yes | Uint8Array to encode.| | 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** **Return value**
...@@ -2102,14 +2103,14 @@ Encodes the input content. ...@@ -2102,14 +2103,14 @@ Encodes the input content.
```js ```js
let that = new util.Base64Helper(); let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]); 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); let result = that.encodeToStringSync(array, util.Type.MIME);
``` ```
### decodeSync<sup>9+</sup> ### decodeSync<sup>9+</sup>
decodeSync(src: Uint8Array | string): Uint8Array decodeSync(src: Uint8Array | string, options?: Type): Uint8Array
Decodes the input content. Decodes the input content.
...@@ -2120,6 +2121,7 @@ Decodes the input content. ...@@ -2120,6 +2121,7 @@ Decodes the input content.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------------------------------ | ---- | ----------------------------- | | ------ | ------------------------------ | ---- | ----------------------------- |
| src | Uint8Array&nbsp;\|&nbsp;string | Yes | Uint8Array or string to decode.| | 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** **Return value**
...@@ -2131,8 +2133,8 @@ Decodes the input content. ...@@ -2131,8 +2133,8 @@ Decodes the input content.
```js ```js
let that = new util.Base64Helper(); let that = new util.Base64Helper();
let buff = 'czEz'; let buff = 'TWFuaXNkaXN0aW5ndWlzaGVkbm90b25seWJ5aGlzcmVhc29uYnV0Ynl0aGlzc2luZ3VsYXJwYXNz\r\naW9uZnJvbW90aGVyYW5pbWFsc3doaWNoaXNhbHVzdG9mdGhlbWluZGV4Y2VlZHN0aGVzaG9ydHZl\r\naGVtZW5jZW9mYW55Y2FybmFscGxlYXN1cmU=\r\n';
let result = that.decodeSync(buff); let result = that.decodeSync(buff, util.Type.MIME);
``` ```
...@@ -2172,7 +2174,7 @@ that.encode(array).then(val=>{ ...@@ -2172,7 +2174,7 @@ that.encode(array).then(val=>{
### encodeToString<sup>9+</sup> ### 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. Encodes the input content asynchronously.
...@@ -2183,6 +2185,7 @@ Encodes the input content asynchronously. ...@@ -2183,6 +2185,7 @@ Encodes the input content asynchronously.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ---------- | ---- | ----------------------- | | ------ | ---------- | ---- | ----------------------- |
| src | Uint8Array | Yes | Uint8Array to encode asynchronously.| | 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** **Return value**
...@@ -2194,16 +2197,16 @@ Encodes the input content asynchronously. ...@@ -2194,16 +2197,16 @@ Encodes the input content asynchronously.
```js ```js
let that = new util.Base64Helper(); let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]); 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).then(val=>{ that.encodeToString(array, util.Type.MIME).then(val=>{
console.log(val) // Add information as required.
}) })
``` ```
### decode<sup>9+</sup> ### 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. Decodes the input content asynchronously.
...@@ -2214,6 +2217,7 @@ Decodes the input content asynchronously. ...@@ -2214,6 +2217,7 @@ Decodes the input content asynchronously.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------------------------------ | ---- | --------------------------------- | | ------ | ------------------------------ | ---- | --------------------------------- |
| src | Uint8Array&nbsp;\|&nbsp;string | Yes | Uint8Array or string to decode asynchronously.| | 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** **Return value**
...@@ -2225,15 +2229,25 @@ Decodes the input content asynchronously. ...@@ -2225,15 +2229,25 @@ Decodes the input content asynchronously.
```js ```js
let that = new util.Base64Helper(); let that = new util.Base64Helper();
let array = new Uint8Array([99,122,69,122]); let array = 'TWFuaXNkaXN0aW5ndWlzaGVkbm90b25seWJ5aGlzcmVhc29uYnV0Ynl0aGlzc2luZ3VsYXJwYXNz\r\naW9uZnJvbW90aGVyYW5pbWFsc3doaWNoaXNhbHVzdG9mdGhlbWluZGV4Y2VlZHN0aGVzaG9ydHZl\r\naGVtZW5jZW9mYW55Y2FybmFscGxlYXN1cmU=\r\n';
let rarray = new Uint8Array([115,49,51]); that.decode(array, util.Type.MIME).then(val=>{
that.decode(array).then(val=>{ // Add information as required.
for (var i = 0; i < rarray.length; i++) {
console.log(val[i].toString())
}
}) })
``` ```
## 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> ## 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. 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. ...@@ -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. | | 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.| | 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** **Example**
```js ```js
...@@ -888,6 +897,15 @@ Unsubscribes from the gesture navigation status change event. ...@@ -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.| | 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.| | 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** **Example**
```js ```js
...@@ -2744,7 +2762,7 @@ try { ...@@ -2744,7 +2762,7 @@ try {
### on('avoidAreaChange')<sup>9+</sup> ### 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. 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 ...@@ -2755,7 +2773,7 @@ Subscribes to the event indicating changes to the area where the window cannot b
| Name | Type | Mandatory| Description | | 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.| | 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** **Example**
...@@ -2772,7 +2790,7 @@ try { ...@@ -2772,7 +2790,7 @@ try {
### off('avoidAreaChange')<sup>9+</sup> ### 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. 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 ...@@ -2783,7 +2801,7 @@ Unsubscribes from the event indicating changes to the area where the window cann
| Name | Type | Mandatory | Description | | 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.| | 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** **Example**
...@@ -3122,7 +3140,16 @@ class TestRemoteObject extends rpc.RemoteObject { ...@@ -3122,7 +3140,16 @@ class TestRemoteObject extends rpc.RemoteObject {
} }
let token = new TestRemoteObject('testObject'); let token = new TestRemoteObject('testObject');
let windowClass = null;
let config = {name: "dialogWindow", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context};
try { 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, () => { windowClass.bindDialogTarget(token, () => {
console.info('Dialog Window Need Destroy.'); console.info('Dialog Window Need Destroy.');
}, (err) => { }, (err) => {
...@@ -3195,7 +3222,16 @@ class TestRemoteObject extends rpc.RemoteObject { ...@@ -3195,7 +3222,16 @@ class TestRemoteObject extends rpc.RemoteObject {
} }
let token = new TestRemoteObject('testObject'); let token = new TestRemoteObject('testObject');
let windowClass = null;
let config = {name: "dialogWindow", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context};
try { 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, () => { let promise = windowClass.bindDialogTarget(token, () => {
console.info('Dialog Window Need Destroy.'); console.info('Dialog Window Need Destroy.');
}); });
...@@ -3246,7 +3282,16 @@ import window from '@ohos.window'; ...@@ -3246,7 +3282,16 @@ import window from '@ohos.window';
export default class ServiceExtAbility extends ServiceExtensionAbility { export default class ServiceExtAbility extends ServiceExtensionAbility {
onRequest(want, startId) { onRequest(want, startId) {
console.info('onRequest'); console.info('onRequest');
let windowClass = null;
let config = {name: "dialogWindow", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context};
try { 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 requestInfo = dialogRequest.getRequestInfo(want)
windowClass.bindDialogTarget(requestInfo, () => { windowClass.bindDialogTarget(requestInfo, () => {
console.info('Dialog Window Need Destroy.'); console.info('Dialog Window Need Destroy.');
...@@ -3258,7 +3303,7 @@ export default class ServiceExtAbility extends ServiceExtensionAbility { ...@@ -3258,7 +3303,7 @@ export default class ServiceExtAbility extends ServiceExtensionAbility {
console.info('Succeeded in binding dialog target.'); console.info('Succeeded in binding dialog target.');
}); });
} catch(err) { } 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'; ...@@ -3306,7 +3351,16 @@ import window from '@ohos.window';
export default class ServiceExtAbility extends ServiceExtensionAbility { export default class ServiceExtAbility extends ServiceExtensionAbility {
onRequest(want, startId) { onRequest(want, startId) {
console.info('onRequest'); console.info('onRequest');
let windowClass = null;
let config = {name: "dialogWindow", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context};
try { 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 requestInfo = dialogRequest.getRequestInfo(want)
let promise = windowClass.bindDialogTarget(requestInfo, () => { let promise = windowClass.bindDialogTarget(requestInfo, () => {
console.info('Dialog Window Need Destroy.'); console.info('Dialog Window Need Destroy.');
...@@ -3317,7 +3371,7 @@ export default class ServiceExtAbility extends ServiceExtensionAbility { ...@@ -3317,7 +3371,7 @@ export default class ServiceExtAbility extends ServiceExtensionAbility {
console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)); console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err));
}); });
} catch(err) { } catch(err) {
console.error('getRequestInfo err = ' + JSON.stringify(err)) console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err))
} }
} }
} }
......
...@@ -125,7 +125,7 @@ Abilities and widgets can be queried, added, refreshed, and deleted across devic ...@@ -125,7 +125,7 @@ Abilities and widgets can be queried, added, refreshed, and deleted across devic
- The distributed camera supports video recording. - 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 #### Distributed data management
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册