提交 80c1df77 编写于 作者: 田雨 提交者: Gitee

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

Signed-off-by: N田雨 <tianyu55@huawei.com>
...@@ -129,8 +129,10 @@ zh-cn/device-dev/subsystems/subsys-toolchain-hdc-guide.md @Austin23 ...@@ -129,8 +129,10 @@ zh-cn/device-dev/subsystems/subsys-toolchain-hdc-guide.md @Austin23
zh-cn/device-dev/subsystems/subsys-toolchain-hiperf.md @Austin23 zh-cn/device-dev/subsystems/subsys-toolchain-hiperf.md @Austin23
zh-cn/device-dev/subsystems/subsys-xts-guide.md @Austin23 zh-cn/device-dev/subsystems/subsys-xts-guide.md @Austin23
zh-cn/application-dev/ability/ @RayShih zh-cn/application-dev/ability/ @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen
zh-cn/application-dev/ui/ @HelloCrease zh-cn/application-dev/IDL/ @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen
zh-cn/application-dev/device-usage-statistics/ @RayShih @shuaytao @wangzhen107 @inter515
zh-cn/application-dev/ui/ @HelloCrease @qieqiewl @tomatodevboy @niulihua
zh-cn/application-dev/notification/ @RayShih zh-cn/application-dev/notification/ @RayShih
zh-cn/application-dev/windowmanager/ @ge-yafang zh-cn/application-dev/windowmanager/ @ge-yafang
zh-cn/application-dev/webgl/ @ge-yafang zh-cn/application-dev/webgl/ @ge-yafang
...@@ -445,8 +447,19 @@ zh-cn/application-dev/reference/apis/js-apis-formextensioncontext.md @RayShih @l ...@@ -445,8 +447,19 @@ zh-cn/application-dev/reference/apis/js-apis-formextensioncontext.md @RayShih @l
zh-cn/application-dev/reference/apis/js-apis-formhost.md @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen zh-cn/application-dev/reference/apis/js-apis-formhost.md @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen
zh-cn/application-dev/reference/apis/js-apis-formInfo.md @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen zh-cn/application-dev/reference/apis/js-apis-formInfo.md @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen
zh-cn/application-dev/reference/apis/js-apis-formprovider.md @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen zh-cn/application-dev/reference/apis/js-apis-formprovider.md @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen
zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md @ge-yafang
zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-context.md @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-context.md @ge-yafang
zh-cn/application-dev/reference/apis/js-apis-inputmethod-subtype.md @ge-yafang
zh-cn/application-dev/reference/errorcodes/errcode-inputmethod-framework.md @ge-yafang
zh-cn/application-dev/reference/errorcodes/errcode-usb.md @ge-yafang
zh-cn/application-dev/reference/errorcodes/errorcode-datashare.md @ge-yafang
zh-cn/application-dev/reference/errorcodes/errorcode-colorspace-manager.md @ge-yafang
zh-cn/application-dev/reference/errorcodes/errorcode-display.md @ge-yafang
zh-cn/application-dev/reference/errorcodes/errorcode-distributed-data_object.md @ge-yafang
zh-cn/application-dev/reference/errorcodes/errorcode-distributedKVStore.md @ge-yafang
zh-cn/application-dev/reference/errorcodes/errorcode-pasteboard.md @ge-yafang
zh-cn/application-dev/reference/errorcodes/errorcode-preferences.md @ge-yafang
zh-cn/application-dev/reference/errorcodes/errorcode-window.md @ge-yafang
zh-cn/application-dev/reference/apis/js-apis-application-quickFixManager.md @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen zh-cn/application-dev/reference/apis/js-apis-application-quickFixManager.md @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen
zh-cn/application-dev/reference/apis/js-apis-missionManager.md @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen zh-cn/application-dev/reference/apis/js-apis-missionManager.md @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen
zh-cn/application-dev/reference/apis/js-apis-particleAbility.md @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen zh-cn/application-dev/reference/apis/js-apis-particleAbility.md @RayShih @littlejerry1 @gwang2008 @ccllee @chengxingzhen
......
...@@ -18,15 +18,15 @@ ...@@ -18,15 +18,15 @@
- master:最新开发版本。 - master:最新开发版本。
- OpenHarmony 3.2 Beta2版本:点击[此处](zh-cn/release-notes/OpenHarmony-v3.2-beta2.md)了解版本详情。 - OpenHarmony 3.2 Beta3版本:点击[此处](zh-cn/release-notes/OpenHarmony-v3.2-beta3.md)了解版本详情。
- OpenHarmony 3.1 Release版本:点击[此处](zh-cn/release-notes/OpenHarmony-v3.1-release.md)了解版本详情。 - OpenHarmony 3.1 Release版本:点击[此处](zh-cn/release-notes/OpenHarmony-v3.1-release.md)了解版本详情。
已更新至OpenHarmony 3.1.1 Release,点击[此处](zh-cn/release-notes/OpenHarmony-v3.1.1-release.md)了解版本详情。 版本已更新至OpenHarmony 3.1.3 Release,点击[此处](zh-cn/release-notes/OpenHarmony-v3.1.3-release.md)了解版本详情。
- OpenHarmony 3.0 LTS版本:点击[此处](zh-cn/release-notes/OpenHarmony-v3.0-LTS.md)了解版本详情。 - OpenHarmony 3.0 LTS版本:点击[此处](zh-cn/release-notes/OpenHarmony-v3.0-LTS.md)了解版本详情。
该版本已更新至OpenHarmony 3.0.5 LTS,点击[此处](zh-cn/release-notes/OpenHarmony-v3.0.5-LTS.md)了解版本详情。 该版本已更新至OpenHarmony 3.0.6 LTS,点击[此处](zh-cn/release-notes/OpenHarmony-v3.0.6-LTS.md)了解版本详情。
- OpenHarmony 2.2 Beta2版本:点击[此处](zh-cn/release-notes/OpenHarmony-v2.2-beta2.md)了解版本详情。 - OpenHarmony 2.2 Beta2版本:点击[此处](zh-cn/release-notes/OpenHarmony-v2.2-beta2.md)了解版本详情。
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
### 历史稳定版本 ### 历史稳定版本
OpenHarmony_v1.x_release:OpenHarmony 1.1.4 LTS稳定版本,点击[此处](zh-cn/release-notes/OpenHarmony-v1-1-4-LTS.md)了解版本详情。 OpenHarmony_v1.x_release:OpenHarmony 1.1.5 LTS稳定版本,点击[此处](zh-cn/release-notes/OpenHarmony-v1.1.5-LTS.md)了解版本详情。
如需了解更多版本详情,点击[此处](zh-cn/release-notes/) 如需了解更多版本详情,点击[此处](zh-cn/release-notes/)
......
...@@ -68,13 +68,13 @@ ...@@ -68,13 +68,13 @@
- [@ohos.bundle](js-apis-Bundle.md) - [@ohos.bundle](js-apis-Bundle.md)
- [@ohos.bundle.defaultAppManager](js-apis-bundle-defaultAppManager.md) - [@ohos.bundle.defaultAppManager](js-apis-bundle-defaultAppManager.md)
- [@ohos.bundle.innerBundleManager)](js-apis-Bundle-InnerBundleManager.md) - [@ohos.bundle.innerBundleManager)](js-apis-Bundle-InnerBundleManager.md)
- [@ohos.bundleState](js-apis-deviceUsageStatistics.md)
- [@ohos.distributedBundle)](js-apis-Bundle-distributedBundle.md) - [@ohos.distributedBundle)](js-apis-Bundle-distributedBundle.md)
- [@ohos.zlib](js-apis-zlib.md) - [@ohos.zlib](js-apis-zlib.md)
- bundle/[AbilityInfo](js-apis-bundle-AbilityInfo.md) - bundle/[AbilityInfo](js-apis-bundle-AbilityInfo.md)
- bundle/[ApplicationInfo](js-apis-bundle-ApplicationInfo.md) - bundle/[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)
- bundle/[BundleInfo](js-apis-bundle-BundleInfo.md) - bundle/[BundleInfo](js-apis-bundle-BundleInfo.md)
- bundle/[BundleInstaller](js-apis-bundle-BundleInstaller.md) - bundle/[BundleInstaller](js-apis-bundle-BundleInstaller.md)
- bundle/[BundleStatusCallback](js-apis-Bundle-BundleStatusCallback.md)
- bundle/[CustomizeData](js-apis-bundle-CustomizeData.md) - bundle/[CustomizeData](js-apis-bundle-CustomizeData.md)
- bundle/[DispatchInfo](js-apis-dispatchInfo.md) - bundle/[DispatchInfo](js-apis-dispatchInfo.md)
- bundle/[ElementName](js-apis-bundle-ElementName.md) - bundle/[ElementName](js-apis-bundle-ElementName.md)
...@@ -96,6 +96,7 @@ ...@@ -96,6 +96,7 @@
- [@ohos.animation.windowAnimationManager](js-apis-windowAnimationManager.md) - [@ohos.animation.windowAnimationManager](js-apis-windowAnimationManager.md)
- [@ohos.display ](js-apis-display.md) - [@ohos.display ](js-apis-display.md)
- [@ohos.effectKit](js-apis-effectKit.md) - [@ohos.effectKit](js-apis-effectKit.md)
- [@ohos.graphics.colorSpaceManager](js-apis-colorSpaceManager.md)
- [@ohos.screen](js-apis-screen.md) - [@ohos.screen](js-apis-screen.md)
- [@ohos.screenshot](js-apis-screenshot.md) - [@ohos.screenshot](js-apis-screenshot.md)
- [@ohos.window](js-apis-window.md) - [@ohos.window](js-apis-window.md)
...@@ -284,3 +285,4 @@ ...@@ -284,3 +285,4 @@
- [@system.sensor](js-apis-system-sensor.md) - [@system.sensor](js-apis-system-sensor.md)
- [@system.storage](js-apis-system-storage.md) - [@system.storage](js-apis-system-storage.md)
- [@system.vibrator](js-apis-system-vibrate.md) - [@system.vibrator](js-apis-system-vibrate.md)
- [console](js-apis-logs.md)
# BundleStatusCallback
The **BundleStatusCallback** module provides bundle callback information, which is obtained through [innerBundleManager.on](js-apis-Bundle-InnerBundleManager.md).
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## BundleStatusCallback
**System API**: This is a system API and cannot be called by third-party applications.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Description |
| ------ | --------------------------------------------- | -------------------------------------- |
| add | (bundleName : string, userId: number) => void | Callback invoked when a **launcherStatusCallback** is added.|
| update | (bundleName : string, userId: number) => void | Callback invoked when a **launcherStatusCallback** is updated.|
| remove | (bundleName : string, userId: number) => void | Callback invoked when a **launcherStatusCallback** is removed.|
...@@ -106,8 +106,8 @@ This is a system API and cannot be called by third-party applications. ...@@ -106,8 +106,8 @@ This is a system API and cannot be called by third-party applications.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------------------- | --------------------- | ---- | ---------------------------------------------------- | | -------------------- | --------------------- | ---- | ---------------------------------------------------- |
| type | "BundleStatusChange" | Yes | Event type. | | type | string | Yes | Event type. Only **BundleStatusChange** is supported. |
| bundleStatusCallback | BundleStatusCallback | Yes | Callback to register. | | bundleStatusCallback | [BundleStatusCallback](js-apis-Bundle-BundleStatusCallback.md) | Yes | Callback to register. |
| callback | AsyncCallback\<string> | Yes | Callback used to return a successful result or error information.| | callback | AsyncCallback\<string> | Yes | Callback used to return a successful result or error information.|
## innerBundleManager.on ## innerBundleManager.on
...@@ -131,9 +131,9 @@ This is a system API and cannot be called by third-party applications. ...@@ -131,9 +131,9 @@ This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------------------- | -------------------- | ---- | ------------------ | | -------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------ |
| type | "BundleStatusChange" | Yes | Event type. | | type | string | Yes | Event type. Only **BundleStatusChange** is supported.|
| bundleStatusCallback | BundleStatusCallback | Yes | Callback to register.| | bundleStatusCallback | [BundleStatusCallback](js-apis-Bundle-BundleStatusCallback.md) | Yes | Callback to register. |
**Return value** **Return value**
...@@ -163,7 +163,7 @@ This is a system API and cannot be called by third-party applications. ...@@ -163,7 +163,7 @@ This is a system API and cannot be called by third-party applications.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ---------------------------------------------------- | | -------- | --------------------- | ---- | ---------------------------------------------------- |
| type | "BundleStatusChange" | Yes | Event type. | | type | string | Yes | Event type. Only **BundleStatusChange** is supported. |
| callback | AsyncCallback\<string> | Yes | Callback used to return a successful result or error information.| | callback | AsyncCallback\<string> | Yes | Callback used to return a successful result or error information.|
## innerBundleManager.off ## innerBundleManager.off
...@@ -187,8 +187,8 @@ This is a system API and cannot be called by third-party applications. ...@@ -187,8 +187,8 @@ This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ---- | -------------------- | ---- | ---------------- | | ---- | ------ | ---- | ------------------------------------------ |
| type | "BundleStatusChange" | Yes | Event type.| | type | string | Yes | Event type. Only **BundleStatusChange** is supported.|
**Return value** **Return value**
......
# ElementName # ElementName
The **ElementName** module provides the element name information. The **ElementName** module provides the element name information, which can be obtained through [Context.getElementName](js-apis-Context.md).
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## ElementName ## ElementName<sup>(deprecated)<sup>
**System capability**: SystemCapability.BundleManager.BundleFramework > This API is deprecated since API version 9. You are advised to use [ElementName](js-apis-bundleManager-elementName.md) instead.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ----------------------- | ---------| ---- | ---- | ------------------------- | | ----------------------- | ---------| ---- | ---- | ------------------------- |
| deviceId | string | Yes | Yes | Device ID. | | deviceId | string | Yes | Yes | Device ID. |
| bundleName | string | Yes | Yes | Bundle name of the application. | | bundleName | string | Yes | Yes | Bundle name of the application. |
| abilityName | string | Yes | Yes | Name of the ability. | | abilityName | string | Yes | Yes | Name of the ability. |
| uri | string | Yes | Yes | URI. | | uri | string | Yes | Yes | Resource ID. |
| shortName | string | Yes | Yes | Short name of the ability. | | shortName | string | Yes | Yes | Short name of the ability. |
| moduleName<sup>9+</sup> | string | Yes | Yes | Name of the HAP file to which the ability belongs. | | moduleName<sup>9+</sup> | string | Yes | Yes | Name of the HAP file to which the ability belongs. |
<!--no_check-->
\ No newline at end of file
# Color Space Management
The **colorSpaceManager** module provides APIs for creating and managing color space objects and obtaining basic color space attributes.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import colorSpaceManager from '@ohos.graphics.colorSpaceManager';
```
## ColorSpace
Enumerates the color space types.
**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core
| Name | Value | Description |
| --------------------------- | ------ | ----------------------- |
| UNKNOWN | 0 | Unknown type.|
| ADOBE_RGB_1998 | 1 | Adobe RGB (1998).|
| DCI_P3 | 2 | DCI-P3.|
| DISPLAY_P3 | 3 | Display P3.|
| SRGB | 4 | SRGB.<br>This is the default color space type.|
| CUSTOM | 5 | Custom type.|
## ColorSpacePrimaries
Defines the color space primaries. A color space is defined by chromaticity coordinates of the red, green, and blue additive primaries, the white point, and the gamma.
**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core
| Name | Type| Readable| Writable| Description |
| ---------------------------- | -------- | ---- | ---- | ----------------------------------------------------- |
| redX | number | Yes | Yes | X coordinate of the red color in the color space.|
| redY | number | Yes | Yes | Y coordinate of the red color in the color space.|
| greenX | number | Yes | Yes | X coordinate of the green color in the color space.|
| greenY | number | Yes | Yes | Y coordinate of the green color in the color space.|
| blueX | number | Yes | Yes | X coordinate of the blue color in the color space.|
| blueY | number | Yes | Yes | Y coordinate of the blue color in the color space.|
| whitePointX | number | Yes | Yes | X coordinate of the white point in the color space.|
| whitePointY | number | Yes | Yes | Y coordinate of the white point in the color space.|
## colorSpaceManager.create
create(colorSpaceName: ColorSpace): ColorSpaceManager
Creates a standard color space object.
**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core
**Parameters**
| Parameter | Type | Mandatory| Description |
| --------------- | ------------------------ | ---- | -----------------------------|
| colorSpaceName | [ColorSpace](#colorspace)| Yes | Type of the color space.<br>**UNKNOWN** and **CUSTOM** cannot be used when creating standard color space objects. |
**Return value**
| Type | Description |
| ------------------ | ------------------------ |
| [ColorSpaceManager](#colorspacemanager) | Color space object created. |
**Example**
```js
let colorSpace = null;
try {
colorSpace = colorSpaceManager.create(colorSpaceManager.ColorSpace.SRGB);
} catch (err) {
console.log(`Failed to create SRGB colorSpace. Cause: ` + JSON.stringify(err));
}
```
## colorSpaceManager.create
create(primaries: ColorSpacePrimaries, gamma: number): ColorSpaceManager
Creates a custom color space object.
**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core
**Parameters**
| Parameter | Type | Mandatory| Description |
| --------------- | ------------------------------------------ | ---- | -----------------------------|
| primaries | [ColorSpacePrimaries](#colorspaceprimaries)| Yes | Primaries of the color space. |
| gamma | number | Yes | Gamma of the color space. |
**Return value**
| Type | Description |
| ------------------ | ------------------------ |
| [ColorSpaceManager](#colorspacemanager) | Color space object created.<br>The color space type is **CUSTOM** of [ColorSpace](#colorspace).|
**Example**
```js
let colorSpace = null;
try {
let primaries = {
redX: 0.1,
redY: 0.1,
greenX: 0.2,
greenY: 0.2,
blueX: 0.3,
blueY: 0.3,
whitePointX: 0.4,
whitePointY: 0.4
};
let gamma = 2.2;
colorSpace = colorSpaceManager.create(primaries, gamma);
} catch (err) {
console.log(`Failed to create colorSpace with customized primaries and gamma. Cause: ` + JSON.stringify(err));
}
```
## ColorSpaceManager
Implements management of color space objects.
Before calling any of the following APIs, you must use [create()](#colorspacemanagercreate) to create a color space object.
### getColorSpaceName
getColorSpaceName(): ColorSpace
Obtains the color space type.
**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core
**Return value**
| Type | Description |
| ------------------ | ------------------------ |
| [ColorSpace](#colorspace) | Color space type.|
**Example**
```js
try {
let csType = colorSpace.getColorSpaceName();
} catch (err) {
console.log(`Fail to get colorSpace's name. Cause: ` + JSON.stringify(err));
}
```
### getWhitePoint
getWhitePoint(): Array\<number\>
Obtains the coordinates of the white point of the color space.
**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core
**Return value**
| Type | Description |
| ------------------ | ------------------------ |
| Array\<number\> | Coordinates [x, y] of the white point.|
**Example**
```js
try {
let wp = colorSpace.getWhitePoint();
} catch (err) {
console.log(`Failed to get white point. Cause: ` + JSON.stringify(err));
}
```
### getGamma
getGamma(): number
Obtains the gamma of the color space.
**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core
**Return value**
| Type | Description |
| ------------------ | ------------------------ |
| number | Gamma of the color space.|
**Example**
```js
try {
let gamma = colorSpace.getGamma();
} catch (err) {
console.log(`Failed to get gamma. Cause: ` + JSON.stringify(err));
}
```
...@@ -47,8 +47,9 @@ Starts an ability with the **want** parameter. This API uses an asynchronous cal ...@@ -47,8 +47,9 @@ Starts an ability with the **want** parameter. This API uses an asynchronous cal
```js ```js
let want = { let want = {
"bundleName": "com.example.myapp", 'bundleName': 'com.example.myapp',
"abilityName": "MyAbility"}; 'abilityName': 'MyAbility'
};
this.context.startAbility(want, (err) => { this.context.startAbility(want, (err) => {
console.log('startAbility result:' + JSON.stringify(err)); console.log('startAbility result:' + JSON.stringify(err));
}); });
...@@ -79,8 +80,8 @@ Starts an ability with the mandatory **want** and optional **options** parameter ...@@ -79,8 +80,8 @@ Starts an ability with the mandatory **want** and optional **options** parameter
```js ```js
let want = { let want = {
"bundleName": "com.example.myapp", 'bundleName': 'com.example.myapp',
"abilityName": "MyAbility" 'abilityName': 'MyAbility'
}; };
this.context.startAbility(want).then((data) => { this.context.startAbility(want).then((data) => {
console.log('success:' + JSON.stringify(data)); console.log('success:' + JSON.stringify(data));
...@@ -110,15 +111,15 @@ Starts an ability with the **want** and **options** parameters. This API uses an ...@@ -110,15 +111,15 @@ Starts an ability with the **want** and **options** parameters. This API uses an
```js ```js
var want = { var want = {
"deviceId": "", 'deviceId': '',
"bundleName": "com.extreme.test", 'bundleName': 'com.extreme.test',
"abilityName": "MainAbility" 'abilityName': 'MainAbility'
}; };
var options = { var options = {
windowMode: 0, windowMode: 0,
}; };
this.context.startAbility(want, options, (error) => { this.context.startAbility(want, options, (error) => {
console.log("error.code = " + error.code) console.log('error.code = ' + error.code)
}) })
``` ```
......
...@@ -73,7 +73,7 @@ Takes a screenshot and saves it as a **PixelMap** object. This API uses an async ...@@ -73,7 +73,7 @@ Takes a screenshot and saves it as a **PixelMap** object. This API uses an async
**Example** **Example**
```js ```js
var screenshotOptions = { let screenshotOptions = {
"screenRect": { "screenRect": {
"left": 200, "left": 200,
"top": 100, "top": 100,
...@@ -85,14 +85,18 @@ Takes a screenshot and saves it as a **PixelMap** object. This API uses an async ...@@ -85,14 +85,18 @@ Takes a screenshot and saves it as a **PixelMap** object. This API uses an async
"rotation": 0, "rotation": 0,
"displayId": 0 "displayId": 0
}; };
try {
screenshot.save(screenshotOptions, (err, pixelMap) => { screenshot.save(screenshotOptions, (err, pixelMap) => {
if (err) { if (err) {
console.log('Failed to save screenshot: ' + JSON.stringify(err)); console.log('Failed to save screenshot. Code: ' + JSON.stringify(err));
return; return;
} }
console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
pixelMap.release(); // Release the memory in time after the PixelMap is used. pixelMap.release(); // Release the memory in time after the PixelMap is used.
}); });
} catch (exception) {
console.error('Failed to save screenshot. Code: ' + JSON.stringify(exception));
};
``` ```
## screenshot.save ## screenshot.save
...@@ -114,14 +118,18 @@ Takes a screenshot and saves it as a **PixelMap** object. This API uses an async ...@@ -114,14 +118,18 @@ Takes a screenshot and saves it as a **PixelMap** object. This API uses an async
**Example** **Example**
```js ```js
try {
screenshot.save((err, pixelMap) => { screenshot.save((err, pixelMap) => {
if (err) { if (err) {
console.log('Failed to save screenshot: ' + JSON.stringify(err)); console.log('Failed to save screenshot. Code: ' + JSON.stringify(err));
return; return;
} }
console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
pixelMap.release(); // Release the memory in time after the PixelMap is used. pixelMap.release(); // Release the memory in time after the PixelMap is used.
}); });
} catch (exception) {
console.error('Failed to save screenshot. Code: ' + JSON.stringify(exception));
};
``` ```
## screenshot.save ## screenshot.save
...@@ -149,7 +157,7 @@ Takes a screenshot and saves it as a **PixelMap** object. This API uses a promis ...@@ -149,7 +157,7 @@ Takes a screenshot and saves it as a **PixelMap** object. This API uses a promis
**Example** **Example**
```js ```js
var screenshotOptions = { let screenshotOptions = {
"screenRect": { "screenRect": {
"left": 200, "left": 200,
"top": 100, "top": 100,
...@@ -161,11 +169,15 @@ Takes a screenshot and saves it as a **PixelMap** object. This API uses a promis ...@@ -161,11 +169,15 @@ Takes a screenshot and saves it as a **PixelMap** object. This API uses a promis
"rotation": 0, "rotation": 0,
"displayId": 0 "displayId": 0
}; };
try {
let promise = screenshot.save(screenshotOptions); let promise = screenshot.save(screenshotOptions);
promise.then((pixelMap) => { promise.then((pixelMap) => {
console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
pixelMap.release(); // Release the memory in time after the PixelMap is used. pixelMap.release(); // Release the memory in time after the PixelMap is used.
}).catch((err) => { }).catch((err) => {
console.log('Failed to save screenshot: ' + JSON.stringify(err)); console.log('Failed to save screenshot. Code: ' + JSON.stringify(err));
}); });
} catch (exception) {
console.error('Failed to save screenshot. Code: ' + JSON.stringify(exception));
};
``` ```
...@@ -31,8 +31,8 @@ Zips a file. This API uses a promise to return the result. ...@@ -31,8 +31,8 @@ Zips a file. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ---------------------------------------------------- | | -------------- | ------------------------------------------------------------ |
| Promise\<void> | Returns **ERROR_CODE_OK** if the operation is successful; returns **ERROR_CODE_ERRNO** otherwise.| | Promise\<void> | Returns [ERROR_CODE_OK](#ziperrorcode) if the operation is successful.<br>Returns [ERROR_CODE_ERRNO](#ziperrorcode) if the operation fails.|
**Example 1** **Example 1**
...@@ -96,7 +96,7 @@ Unzips a file. This API uses a promise to return the result. ...@@ -96,7 +96,7 @@ Unzips a file. This API uses a promise to return the result.
| Type | Description | | Type | Description |
| -------------- | ------------------------------------------------------------ | | -------------- | ------------------------------------------------------------ |
| Promise\<void> | Returns **ERROR_CODE_OK** if the operation is successful; returns **ERROR_CODE_ERRNO** otherwise.| | Promise\<void> | Returns [ERROR_CODE_OK](#ziperrorcode) if the operation is successful.<br>Returns [ERROR_CODE_ERRNO](#ziperrorcode) if the operation fails.|
**Example** **Example**
......
...@@ -137,9 +137,9 @@ ...@@ -137,9 +137,9 @@
| Name | Description | | Name | Description |
| -------- | ---------------------- | | -------- | ---------------------- |
| Top | Top edge in the vertical direction. | | Top | Top edge in the vertical direction. |
| Center<sup>(deprecated) </sup> | Center position in the vertical direction.<br> This API is deprecated since API version 9. | | Center<sup>(deprecated) </sup> | Center position in the vertical direction.<br>This API is deprecated since API version 9. |
| Bottom | Bottom edge in the vertical direction. | | Bottom | Bottom edge in the vertical direction. |
| Baseline<sup>(deprecated) </sup> | Text baseline position in the cross axis direction.<br> This API is deprecated since API version 9.| | Baseline<sup>(deprecated) </sup> | Text baseline position in the cross axis direction.<br>This API is deprecated since API version 9. |
| Start | Start position in the horizontal direction. | | Start | Start position in the horizontal direction. |
| Middle<sup>(deprecated) </sup> | Center position in the horizontal direction.<br>This API is deprecated since API version 9. | | Middle<sup>(deprecated) </sup> | Center position in the horizontal direction.<br>This API is deprecated since API version 9. |
| End | End position in the horizontal direction. | | End | End position in the horizontal direction. |
...@@ -249,7 +249,7 @@ ...@@ -249,7 +249,7 @@
| End | The child components are aligned with the end edge of the main axis. The last component is aligned with the main-end, and other components are aligned with the next one.| | End | The child components are aligned with the end edge of the main axis. The last component is aligned with the main-end, and other components are aligned with the next one.|
| SpaceBetween | The child components are evenly distributed along the main axis. The space between any two adjacent components is the same. The first component is aligned with the main-start, the last component is aligned with the main-end, and the remaining components are distributed so that the space between any two adjacent components is the same.| | SpaceBetween | The child components are evenly distributed along the main axis. The space between any two adjacent components is the same. The first component is aligned with the main-start, the last component is aligned with the main-end, and the remaining components are distributed so that the space between any two adjacent components is the same.|
| SpaceAround | The child components are evenly distributed along the main axis. The space between any two adjacent components is the same. The space between the first component and main-start, and that between the last component and cross-main are both half the size of the space between two adjacent components.| | SpaceAround | The child components are evenly distributed along the main axis. The space between any two adjacent components is the same. The space between the first component and main-start, and that between the last component and cross-main are both half the size of the space between two adjacent components.|
| SpaceEvenly | The child components are equally distributed along the main axis. The space between the first component and main-start, the space between the last component and main-end, and the space between two adjacent components are the same.| | SpaceEvenly | The child components are evenly distributed along the main axis. The space between the first component and main-start, the space between the last component and main-end, and the space between any two adjacent components are the same. |
## ItemAlign ## ItemAlign
...@@ -355,9 +355,9 @@ ...@@ -355,9 +355,9 @@
| Name | Description | | Name | Description |
| -------- | -------------------------------------- | | -------- | -------------------------------------- |
| Clip | Extra-long text is truncated. | | Clip | Extra-long text is clipped. |
| Ellipsis | An ellipsis (...) is used to represent clipped text.| | Ellipsis | An ellipsis (...) is used to represent clipped text.|
| None | No truncation or ellipsis is used for extra-long text. | | None | No clipping or ellipsis is used for extra-long text. |
## TextDecorationType ## TextDecorationType
...@@ -413,9 +413,9 @@ ...@@ -413,9 +413,9 @@
| Name | Description | | Name | Description |
| ----------- | -------------------- | | ----------- | -------------------- |
| None | Copy and paste is not allowed. | | None | Copy is not allowed. |
| InApp | Intra-application copy and paste is allowed.| | InApp | Intra-application copy is allowed.|
| LocalDevice | Intra-device copy and paste is allowed.| | LocalDevice | Intra-device copy is allowed.|
## HitTestMode<sup>9+</sup> ## HitTestMode<sup>9+</sup>
......
# Display Error Codes
## 1400001 Invalid Display or Screen
**Error Message**
Invalid display or screen.
**Description**
This error code is reported when an invalid display, including a virtual screen, is operated.
**Possible Causes**
1. The virtual screen has not been created.
2. The virtual screen has been destroyed.
**Procedure**
1. Before operating the virtual screen, check whether the virtual screen has been created.
2. Check whether the virtual screen has been destroyed.
## 1400002 Unauthorized Operation
**Error Message**
Unauthorized operation.
**Description**
This error code is reported when the API does not have the required permissions to operate an object.
**Possible Causes**
The virtual screen object of another process is operated.
**Procedure**
Check whether unauthorized operations are performed on the object of another process. If yes, delete the operations.
## 1400003 Abnormal Display Manager Service
**Error Message**
This display manager service works abnormally.
**Description**
This error code is reported when the display manager service is abnormal.
**Possible Causes**
1. The display manager service is not started normally.
2. The bottom-layer graphics synthesis and rendering are abnormal.
**Procedure**
Try again later or restart the device.
# Window Error Codes
## 1300001 Repeated Operation
**Error Message**
Repeated operation.
**Description**
This error code is reported when a repeated operation is performed.
**Possible Causes**
The window to create already exists.
**Procedure**
Before creating a window, check whether the window already exists. If it already exists, use it directly.
## 1300002 Abnormal Window State
**Error Message**
This window state is abnormal.
**Description**
This error code is reported when you operate a window in an abnormal state, for example, a window that has been destroyed.
**Possible Causes**
The window has been destroyed when being operated.
**Procedure**
Before operating the window, check whether it exists.
## 1300003 Abnormal Window Manager Service
**Error Message**
This window manager service works abnormally.
**Description**
This error code is reported when the window manager service is abnormal.
**Possible Causes**
The internal services of the window are not started normally.
**Procedure**
Try again later or restart the device.
## 1300004 Unauthorized Operation
**Error Message**
Unauthorized operation.
**Description**
This error code is reported when the API does not have the required permissions to operate an object.
**Possible Causes**
The window object of another process is operated.
**Procedure**
Check whether unauthorized operations are performed on the object of another process. If yes, delete the operations.
## 1300005 Abnormal Window Stage
**Error Message**
This window stage is abnormal.
**Description**
This error code is reported when you operate a window stage in the abnormal state, for example, a window stage that has been destroyed.
**Possible Causes**
The window stage has been destroyed when being operated.
**Procedure**
Before operating a window stage, check whether it exists.
## 1300006 Abnormal Window Context
**Error Message**
This window context is abnormal.
**Description**
This error code is reported when you operate a window context in the abnormal state, for example, a window context that has been destroyed.
**Possible Causes**
The window context has been destroyed when being operated.
**Procedure**
Before operating the window context, check whether it exists.
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
- Access Control - Access Control
- [Access Control (Permission) Overview](accesstoken-overview.md) - [Access Control (Permission) Overview](accesstoken-overview.md)
- [Guide for Requesting Permissions from User](accesstoken-guidelines.md) - [Permission Application Guide](accesstoken-guidelines.md)
- [Application Permission List](permission-list.md) - [Permission Verification Guide](permission-verify-guidelines.md)
- [App Permission List](permission-list.md)
- User Authentication - User Authentication
- [User Authentication Overview](userauth-overview.md) - [User Authentication Overview](userauth-overview.md)
- [User Authentication Development](userauth-guidelines.md) - [User Authentication Development](userauth-guidelines.md)
......
# Guide for Requesting Permissions from User # Permission Application Guide
## When to Use ## When to Use
...@@ -115,7 +115,7 @@ The permission level of **ohos.permission.PERMISSION2** is **system_basic**, whi ...@@ -115,7 +115,7 @@ The permission level of **ohos.permission.PERMISSION2** is **system_basic**, whi
In addition to declaring all the permissions in the configuration file, you must declare the permissions whose levels are higher that the app's APL in the app's profile. For details about the fields in the profile, see [HarmonyAppProvision Configuration File](../quick-start/app-provision-structure.md). In addition to declaring all the permissions in the configuration file, you must declare the permissions whose levels are higher that the app's APL in the app's profile. For details about the fields in the profile, see [HarmonyAppProvision Configuration File](../quick-start/app-provision-structure.md).
In this example, declare the permission under the **acls** field: For example, declare the required permission in the **acls** field:
```json ```json
{ {
......
# Access Control (Permission) Overview # Access Control (Permission) Overview
AccessTokenManager (ATM) implements unified app permission management based on access tokens on OpenHarmony. OpenHarmony AccessTokenManager (ATM) implements unified app permission management based on access tokens.
By default, apps can access limited system resources. However, in some cases, an app needs to access excess data (including personal data) and functions of the system or another app to implement extended functions. The system or apps must also share their data or functions through interfaces in an explicit manner. OpenHarmony uses app permissions to perform access control and prevent improper or malicious use of these data or functions. By default, apps can access limited system resources. However, in some cases, an app needs to access excess data (including personal data) and functions of the system or another app to implement extended functions. The system or apps must also explicitly share their data or functions through APIs. OpenHarmony uses app permissions to perform access control and prevent improper or malicious use of these data or functions.
App permissions are used to protect the following objects: App permissions are used to protect the following objects:
...@@ -11,7 +11,7 @@ App permissions are used to protect the following objects: ...@@ -11,7 +11,7 @@ App permissions are used to protect the following objects:
Without the required permissions, an app cannot access or perform operations on the target object. Permissions must be clearly defined for apps. With well-defined app permissions, the system can standardize the behavior of apps and protect user privacy. Before an app accesses the target object, the target object verifies the app's permissions and denies the access if the app does not have required permissions. Without the required permissions, an app cannot access or perform operations on the target object. Permissions must be clearly defined for apps. With well-defined app permissions, the system can standardize the behavior of apps and protect user privacy. Before an app accesses the target object, the target object verifies the app's permissions and denies the access if the app does not have required permissions.
Currently, ATM verifies app permissions based on the token identity (Token ID). A token ID identifies an app. The ATM manages app permissions based on the app's token ID. Currently, ATM verifies app permissions based on the token identity (token ID). A token ID identifies an app. ATM manages app permissions based on the app's token ID.
## Basic Principles for Permission Management ## Basic Principles for Permission Management
...@@ -19,37 +19,52 @@ Observe the following principles for permission management: ...@@ -19,37 +19,52 @@ Observe the following principles for permission management:
- Provide clear description about the app functions and scenarios for each permission required by the app so that users can clearly know why and when these permissions are required. Do not induce or mislead users' authorization. The permissions on an app must comply with the description provided in the app. - Provide clear description about the app functions and scenarios for each permission required by the app so that users can clearly know why and when these permissions are required. Do not induce or mislead users' authorization. The permissions on an app must comply with the description provided in the app.
- Use the principle of least authority for user permissions. Allow only necessary permissions for service functions. - Use the principle of least authority for user permissions. Allow only necessary permissions for service functions.
- When an app is started for the first time, avoid frequently displaying dialog boxes to request permissions. Allow the app to apply for permissions only when it needs to use the corresponding service functions. - When an app is started for the first time, avoid frequently displaying dialog boxes to request multiple permissions. Allow the app to apply for the permission only when it needs to use the corresponding service function.
- If a user rejects to authorize a permission, the user can still use functions irrelevant to this permission and can register and access the app. - If a user rejects to grant a permission, the user can still use functions irrelevant to this permission and can register and access the app.
- Provide no more message if a user rejects the authorization required by a function. Provide onscreen instructions to direct the user to grant the permission in **Settings** if the user triggers this function again or needs to use this function. - Provide no more message if a user rejects the authorization required by a function. Provide onscreen instructions to direct the user to grant the permission in **Settings** if the user triggers this function again or needs to use this function.
- All the permissions granted to apps must come from the [Permission List](permission-list.md). Custom permissions are not allowed for apps currently. - All the permissions granted to apps must come from the [App Permission List](permission-list.md). Custom permissions are not allowed for apps currently.
## Permission Workflow ## Permission Workflows
Determine the permissions required for an app to access data or perform an operation. Declare the required permissions in the app installation package. ### Permission Application and Use
Determine whether the required permissions need to be authorized by users. If yes, provide a dialog box dynamically to request user authorization. Determine the permissions required by an app, and declare the required permissions in the app installation package.
After the user grants permissions to the app, the app can access the data or perform the operation. Determine whether the required permissions need user authorization. If yes, display a dialog box dynamically to request user authorization.
The figure below shows the permission workflow. After the user grants the permissions, the app can access the data or perform the operation.
The figure below illustrates the process.
![](figures/permission-workflow.png) ![](figures/permission-workflow.png)
1. You can refer to the figure below to determine whether an app can apply for a permission. 1. Refer to the figure below to determine whether an app can apply for a permission.
![](figures/permission-application-process.png) ![](figures/permission-application-process.png)
1. See [Permission Levels](#permission-levels) for details about the mapping between the application Ability Privilege Level (APL) and permission level. 1. See [Permission Levels](#permission-levels) for details about the mapping between the application Ability Privilege Level (APL) and permission level.
2. The permission authorization modes include user_grant (permission granted by the user) and system_grant (permission granted by the system). For details, see [Permission Authorization Modes](#permission-authorization-mode). 2. The permission authorization modes include user_grant (permission granted by the user) and system_grant (permission granted by the system). For details, see [Permission Types](#permission-types).
3. A low-APL app can have a high-level permission by using the Access Control List (ACL). For details, see [ACL](#acl).
### Permission Verification
To protect sensitive data and eliminate security threads on core abilities, you can use the permissions in the [App Permission List](permission-list.md) to protect the related API from unauthorized calling. Each time before the API is called, a permission verification is performed to check whether the caller has the required permission. The API can be called only after the permission verification is successful.
The figure below shows the permission verification process.
![](figures/permission-verify-process.png)
3. A low-level app can have a high-level permission by using the Access Control List (ACL). For details, see [ACL](#acl). 1: An app permission can be used to control the access to an API that has sensitive data involved or security threats on the core abilities.
2: Select the permission from the [App Permission List](permission-list.md). For example, if contact information is involved in an API provided by an app, you can use the contact-related permissions to protect the API.
3: Use **verifyAccessToken()** to check whether the caller has the required permission. For details, see [Permission Verification Guide](permission-verify-guidelines.md).
## Permission Levels ## Permission Levels
To protect user privacy, ATM defines different permission levels based on the sensitivity of the data involved or the security threat of the ability. ATM defines different permission levels based on the sensitivity of the data involved or the security threat of the ability to protect user privacy.
### App APLs ### App APLs
...@@ -59,21 +74,21 @@ The table below describes the APLs. ...@@ -59,21 +74,21 @@ The table below describes the APLs.
| APL | Description | | APL | Description |
| ---------------- | -------------------------------------- | | ---------------- | -------------------------------------- |
| system_core | The apps of this level provide core abilities of the operating system.| | system_core | The apps of this level provide core abilities of the operating system (OS). |
| system_basic| The apps of this level provide basic system services. | | system_basic| The apps of this level provide basic system services. |
| Normal | The apps of this level are normal apps. | | Normal | The apps of this level are normal apps. |
By default, apps are of the normal APL. The default APL of apps is **normal**.
For the app of the system_basic or system_core APL, declare the APL in the **apl** field of **bundle-info** in the app's profile when developing the application installation package. To set an app's APL to **system_basic** or **system_core**, declare the APL in the **apl** field of **bundle-info** in the app's profile when developing the app's installation package.
Then, use the [hapsigner](hapsigntool-overview.md) tool to generate a certificate or use DevEco Studio to [have your app automatically signed](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ohos-auto-configuring-signature-information-0000001271659465#section161281722111). Then, use the [hapsigner](hapsigntool-overview.md) tool to generate a certificate or use DevEco Studio to [have your app automatically signed](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ohos-auto-configuring-signature-information-0000001271659465#section161281722111).
> **CAUTION**<br>The method of declaring the app's APL in its profile applies only to the application or service in debug phase. For a commercial app, apply for a release certificate and profile in the corresponding app market. > **CAUTION**<br>The method of changing the app's APL in its profile applies only to the app or service in debug mode. For a commercial app, apply for a release certificate and profile in the corresponding app market.
The following is an example. The following is an example.
This example shows only the modification of the **apl** field. Set other fields based on service requirements. For details about the fields in the profile, see [HarmonyAppProvision Configuration File](../quick-start/app-provision-structure.md). This example shows only the modification of the **apl** field. Set other fields based on your requirements. For details about the fields in the profile, see [HarmonyAppProvision Configuration File](../quick-start/app-provision-structure.md).
```json ```json
{ {
...@@ -100,17 +115,17 @@ The permissions open to apps vary with the permission level. The permission leve ...@@ -100,17 +115,17 @@ The permissions open to apps vary with the permission level. The permission leve
- **system_basic** - **system_basic**
The system_basic permission allows access to resources related to basic operating system services. The basic services are basic functions provided or preconfigured by the system, such as system setting and identity authentication. Access to these resources may have considerable risks to user privacy and other apps. The system_basic permission allows access to resources related to basic OS services. The basic services are basic functions provided or preconfigured by the system, such as system settings and identity authentication. Access to these resources may have considerable risks to user privacy and other apps.
The permissions of this level are available only to apps of the system_basic or system_core APL. The permissions of this level are available only to apps of the system_basic or system_core APL.
- **system_core** - **system_core**
The system_core permission allows access to core resources of the operating system. These resources are the underlying core services of the system. If these resources are corrupted, the OS cannot run properly. The system_core permission allows access to core resources of the OS. These resources are underlying core services of the system. If these resources are corrupted, the OS cannot run properly.
The permissions of this type are not open to third-party apps currently. The system_core permissions are not open to third-party apps currently.
## Permission Authorization Modes ## Permission Types
Permissions can be classified into the following types based on the authorization mode: Permissions can be classified into the following types based on the authorization mode:
...@@ -126,65 +141,70 @@ Permissions can be classified into the following types based on the authorizatio ...@@ -126,65 +141,70 @@ Permissions can be classified into the following types based on the authorizatio
This type of permissions must be declared in the app installation package and authorized by users dynamically during the running of the app. The app has the permission only after user authorization. This type of permissions must be declared in the app installation package and authorized by users dynamically during the running of the app. The app has the permission only after user authorization.
For example, in the [Permission List](permission-list.md), the permissions for the microphone and camera are user_grant. The list provides reasons for using the permissions. For example, in the [App Permission List](permission-list.md), the permissions for microphones and cameras are user_grant. The list provides reasons for using the permissions.
The user_grant permission list must also be presented on the details page of the app in the app store. The user_grant permission list must also be presented on the details page of the app in the app store.
### Authorization Processes ### Authorization Processes
The process for an app obtaining the required permissions varies depending on the permission authorization mode. As described in [Permission Workflows](permission-workflows), you need to first apply for the required permissions for the app.
- Applying for permissions
You need to [declare the required permissions](accesstoken-guidelines.md#declaring-permissions) in the configuration file.
- For a system_grant permission, you need to [declare the permission](accesstoken-guidelines.md#declaring-permissions) in the configuration file. The permission will be pre-granted when the app is installed. - Authorizing permissions
- For a user_grant permission, you need to [declare the permission](accesstoken-guidelines.md#declaring-permissions) in the configuration file and trigger user authorization through a dialog box during the running of the app. - The system_grant permission will be pre-granted when the app is installed.
- For a user_grant permission, you need to trigger user authorization through a dialog box during the running of the app. For details, see [Requesting User Authorization](#requesting-user-authorization).
### Permission Authorization Process (user_grant) ### Requesting User Authorization
The procedure is as follows: The procedure is as follows:
1. In the configuration file, declare the permissions required by the app. For details, see [Access Control Development](accesstoken-guidelines.md). 1. In the configuration file, declare the permissions required by the app. For details, see [Access Control Development](accesstoken-guidelines.md).
2. Associate the object that requires the permissions in the app with the target permissions. In this way, the user knows the operations to be granted with the specified permissions. 2. Associate the target objects in the app with the related permissions. This allows the users to know the operations that need user authorization.
3. Check whether the user has granted the required permissions to the app when the app is running. If yes, the app can access the data or perform the operation. If the user has not granted the permissions to the app, display a dialog box requesting the user authorization when the app attempts to access the data. 3. Use an API to dynamically trigger a dialog box requesting user authorization when the target object is accessed. The API first checks whether the user has granted the required permissions to the app. If yes, the app can access the data or perform the operation. Otherwise, a dialog box will be displayed to request user authorization.
4. Check the user authorization result. Allow the next step only after the user has granted the permissions to the app. 4. Check the user authorization result. Allow the subsequent operation only after the user has granted the permissions to the app.
**Precautions** **Precautions**
- Check the app's permission each time before the operation requiring the permission is performed. - Check the app's permission each time before the operation requiring the permission is performed.
- To check whether a user has granted specific permissions to your app, use the [verifyAccessToken](../reference/apis/js-apis-abilityAccessCtrl.md) method. This method returns [PERMISSION_GRANTED](../reference/apis/js-apis-abilityAccessCtrl.md) or [PERMISSION_DENIED](../reference/apis/js-apis-abilityAccessCtrl.md). For details about the sample code, see [Access Control Development](accesstoken-guidelines.md). - To check whether a user has granted specific permissions to an app, use the [verifyAccessToken](../reference/apis/js-apis-abilityAccessCtrl.md) method. This method returns [PERMISSION_GRANTED](../reference/apis/js-apis-abilityAccessCtrl.md) or [PERMISSION_DENIED](../reference/apis/js-apis-abilityAccessCtrl.md). For details about the sample code, see [Access Control Development](accesstoken-guidelines.md).
- Users must be able to understand and control the authorization of user_grant permissions. During the running process, the app requiring user authorization must proactively call the API to dynamically request the authorization. Then, the system displays a dialog box asking the user to grant the requested permission. The user will determine whether to grant the permission based on the running context of the app. - Users must be able to understand and control the authorization of user_grant permissions. During the running process, the app requiring user authorization must proactively call an API to dynamically request the authorization. Then, the system displays a dialog box asking the user to grant the permission. The user will determine whether to grant the permission based on the running context of the app.
- The permission authorized is not permanent, because the user may revoke the authorization at any time. Therefore, even if the user has granted the requested permission to the app, the app must check for the permission before calling the API controlled by this permission. - The permission authorized is not permanent, because the user may revoke the authorization at any time. Therefore, even if the user has granted the requested permission to the app, the app must check for the permission before calling the API controlled by this permission.
## ACL ## ACL
As described above, permission levels and app APLs are in one-to-one correspondence. In principle, **an app with a lower APL cannot apply for higher permissions by default**. As described above, permission levels and app APLs are in one-to-one correspondence. In principle, **an app with a lower APL cannot apply for higher permissions by default**.
The ACL makes low-level apps have high-level permissions. The ACL makes low-APL apps have high-level permissions.
**Example** **Example**
The APL of app A is normal. App A needs to have permission B (system_basic level) and permission C (normal level). The APL of app A is **normal**. App A needs to have permission B (system_basic level) and permission C (normal level).
In this case, you can use the ACL to grant permission B to app A. In this case, you can use the ACL to grant permission B to app A.
For details, see [Using the ACL](#using-the-acl). For details, see [Using the ACL](#using-the-acl).
For details about whether a permission can be enabled through the ACL, see the [Permission List](permission-list.md). For details about whether a permission can be enabled through the ACL, see the [App Permission List](permission-list.md).
### Using the ACL ### Using the ACL
If the permission required by an app has higher level than the app's APL, you can use the ACL to grant the permissions required. If the permission required by an app has higher level than the app's APL, you can use the ACL to grant the permission required.
In addition to the preceding [authorization processes](#authorization-processes), you must declare the ACL. In addition to the preceding [authorization processes](#authorization-processes), you must declare the ACL.
In other words, in addition to declaring the required permissions in the app's configuration file, you must [declare the ACL](accesstoken-guidelines.md#declaring-the-acl) in the app's profile. The subsequent steps of authorization are the same. That is, you need to declare the required permissions in the app's configuration file, and [declare the ACL](accesstoken-guidelines.md#declaring-the-acl) in the app's profile. The subsequent steps of authorization are the same.
**NOTICE** **NOTICE**
When developing an app installation package, you must declare the allowed ACLs in the **acls** field in the app's profile. Then, use the [hapsigner](hapsigntool-overview.md) tool to generate a certificate. When developing an app installation package, you must declare the ACL in the **acls** field in the app's profile. Then, use the [hapsigner](hapsigntool-overview.md) tool to generate a certificate.
> **CAUTION**<br>The method of declaring the app's APL in its profile applies only to the application or service in debug phase. For a commercial app, apply for a release certificate and profile in the corresponding app market. > **CAUTION**<br>The method of changing the app's APL in its profile applies only to the app or service in debug mode. For a commercial app, apply for a release certificate and profile in the corresponding app market.
```json ```json
{ {
......
# Application Permission List # App Permission List
Before applying for required permissions, read and understand the [permission workflow](accesstoken-overview.md#permission-workflow). Then, determine whether the app can apply for the target permissions based on the table below. Before applying for required permissions, read and understand the [permission workflows](accesstoken-overview.md#permission-workflows). Then, determine whether the app can apply for the target permissions based on the table below.
For details about permission usage examples, see [Access Control Development](accesstoken-guidelines.md). For details about permission usage examples, see [Permission Application Guide](accesstoken-guidelines.md).
| Permission | APL | Authorization Mode | Enable ACL| Description | | Permission | APL | Authorization Mode | Enable ACL| Description |
| -------------------------------------------------------- | ------------ | ------------ | ------- | ------------------------------------------- | | -------------------------------------------------------- | ------------ | ------------ | ------- | ------------------------------------------- |
......
# Permission Verification Guide
## When to Use
To protect sensitive data and eliminate security threads on core abilities, you can use the permissions in the [App Permission List](permission-list.md) to protect the related API from unauthorized calling. Each time before the API is called, a permission verification is performed to check whether the caller has the required permission.
## Available APIs
The table below lists only the API used in this guide. For more information, see [AbilityContext](../reference/apis/js-apis-ability-context.md).
| API | Description |
| ------------------------------------------------------------ | --------------------------------------------------- |
| verifyAccessToken(tokenID: number, permissionName: string): Promise&lt;GrantStatus&gt; | Checks whether an application process has the specified permission.|
## Example
The procedure is as follows:
1. Obtain the caller's identity (**tokenId**).
2. Determine the permission to verify, which is **ohos.permission.PERMISSION** in this example.
3. Call **verifyAccessToken()** to perform a permission verification of the caller.
4. Proceed based on the permission verification result.
```js
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import rpc from '@ohos.rpc'
class Stub extends rpc.RemoteObject {
onRemoteRequest(code, data, reply, option) {
let callerTokenId = rpc.IPCSkeleton.getCallingTokenId();
console.log("RpcServer: getCallingTokenId result: " + callerTokenId);
var atManager = abilityAccessCtrl.createAtManager();
var result = await atManager.verifyAccessToken(tokenID, "ohos.permission.PERMISSION");
if (result == abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) {
// Allow the caller to invoke the API provided by the app.
} else {
// Deny the caller's access to the API.
}
return true;
}
}
```
> **NOTE**<br>
> You can use **getCallingTokenId** to obtain the caller's **tokenId**. For details, see [RPC](../reference/apis/js-apis-rpc.md#getcallingtokenid8).
...@@ -40,6 +40,22 @@ For easier maintenance and evolution, comply with the following principles when ...@@ -40,6 +40,22 @@ For easier maintenance and evolution, comply with the following principles when
12. When software introduction depends on other dependency software, it is not allowed to nest the dependency software in the subdirectory of the software introduction, and all dependency softwares must be placed in separate repository, and name it in the format of **third_party_*****softwareName***, because nested placement of dependency software may lead to multiple versions of the same software, old versions of security vulnerabilities cannot be fixed in a timely, and will risk the opensource compliance issues. 12. When software introduction depends on other dependency software, it is not allowed to nest the dependency software in the subdirectory of the software introduction, and all dependency softwares must be placed in separate repository, and name it in the format of **third_party_*****softwareName***, because nested placement of dependency software may lead to multiple versions of the same software, old versions of security vulnerabilities cannot be fixed in a timely, and will risk the opensource compliance issues.
- Dependency software are named in the compiled BUILD.gn with part name by prefixing the newly software introduction name, e.g. part_name = "software_introduction_name_dependency software_name". - Dependency software are named in the compiled BUILD.gn with part name by prefixing the newly software introduction name, e.g. part_name = "software_introduction_name_dependency software_name".
- The inter-component dependencies between software introduction and dependency software are resolved via external_deps. - The inter-component dependencies between software introduction and dependency software are resolved via external_deps.
13. OpenHarmony's archiving directory requirements for third-party software introduction.
- If you don't have a really good reason to store it elsewhere and under one of the permitted licenses belongs in third_party.
- For the dedicated third-party software introduction which belongs to the specail devboard, and is is not suitable introduced into the OpenHarmony platform, you could apply to store it in the following locations, Naming it in the format of **softwareName**, where **softwareName** must be an official name, and create README.OpenSource description file in the corresponding directory; Creating BUILD.gn to build it independently to support the automatic collection of open source obligation declaration.
```
device/soc/$(SOC_COMPANY)/third_party
device/board/$(BOARD_COMPANY)/third_party
vendor/$(PRODUCT_COMPANY)/third_party
```
14. Precompiled binary or toolchain used in the OpenHarmony, the following information needs to be provided.
- The source code corresponding to the pre-compiled binary or toolchain, which needs to store the corresponding source code in the OpenHarmony community, and provide the corresponding build guide, and provide open source obligation statement guide;
- Third-party software introduction for precompiled binary or toolchain, need to meet the principles 1 ~ 13;
- The [prebuilt toolchain's description documentation](./prebuilts-readme-template.md): including source code acquisition address, build instructions, update methods, archived in the toolchain root directory with the toolchain build;
- The root directory corresponding to the pre-compiled binary or toolchain needs to provide notice file of the full open source obligation statement;
- If the precompiled binary files come from upstream service platform (e.g. npm packages, etc.). We need to provide the following information in the place where the binary is archived, first we need to provide a general description with the name **README**, include the following information: background description of the introduction and official website; next we need to provide a opensource obligation statement file with the name **NOTICE**, include the following information: software name, version, copyrights, and license information of every third-party open-source software.
### Software Introduction Process ### Software Introduction Process
...@@ -64,10 +80,10 @@ Follow the process described in the [SIG Management Regulations](https://gitee.c ...@@ -64,10 +80,10 @@ Follow the process described in the [SIG Management Regulations](https://gitee.c
| Check Item| Description| Self-Check Result Example| | Check Item| Description| Self-Check Result Example|
| :----- | :----- | :----- | | :----- | :----- | :----- |
| Software name| Provide the official name of the software and the repository name to which the software is introduced. The repository name is in the format of **third_party**_**softwareName**.| third_party_**softwareName**| | Software name| Provide the official name of the software and the repository name to which the software is introduced. The repository name is in the format of **third_party**_**softwareName**.| third_party_**softwareName**|
| Official website| Provide the official website link of the software.| https://softwaresite | | Official website| Provide the official website link of the software.| <https://softwaresite> |
| Software version| Provide the version number of the software to be introduced. The version number must be an official version number released by the community. Do not modify the version number or introduce a version that is not officially released.| 1.0.0 | | Software version| Provide the version number of the software to be introduced. The version number must be an official version number released by the community. Do not modify the version number or introduce a version that is not officially released.| 1.0.0 |
| Software version release date| Provide the official release date of the software version.| 2021.01.01 | | Software version release date| Provide the official release date of the software version.| 2021.01.01 |
| Software version address| Provide the official download URL of the version. Note that the URL must be able to locate the release package of the specific version.| https://gitee.com/softwarecodesite/v1.0.0.zip | | Software version address| Provide the official download URL of the version. Note that the URL must be able to locate the release package of the specific version.| <https://gitee.com/softwarecodesite/v1.0.0.zip> |
| Software license| Provide the official license name of the version and the relative path of the license file. If there are multiple licenses, list them all and describe their relationship, for example, And, Or, or different licenses for different directories.| Apache-2.0 | | Software license| Provide the official license name of the version and the relative path of the license file. If there are multiple licenses, list them all and describe their relationship, for example, And, Or, or different licenses for different directories.| Apache-2.0 |
| Software lifecycle| Describe whether the software has an LTS version, how frequent a version is released, code submitted to the community in the last year, issue resolution status, and whether end of maintenance or evolution is notified.| No LTS version; one version released every six months; 10 code submissions in the last six months| | Software lifecycle| Describe whether the software has an LTS version, how frequent a version is released, code submitted to the community in the last year, issue resolution status, and whether end of maintenance or evolution is notified.| No LTS version; one version released every six months; 10 code submissions in the last six months|
| Security vulnerabilities| List disclosed security vulnerabilities in the software, including the vulnerability number, severity, link, and whether patches or solutions are available.| No disclosed vulnerabilities.| | Security vulnerabilities| List disclosed security vulnerabilities in the software, including the vulnerability number, severity, link, and whether patches or solutions are available.| No disclosed vulnerabilities.|
...@@ -121,9 +137,9 @@ Confirm the issues found by the OAT tool and configure the **OAT.xml** file. For ...@@ -121,9 +137,9 @@ Confirm the issues found by the OAT tool and configure the **OAT.xml** file. For
] ]
``` ```
#### PMC Review #### Open source software introduction Review
Refer to the [SIG Management Regulations](https://gitee.com/openharmony/community/tree/master/sig). The PMC will arrange the SIG request review and repository construction based on the received PR. Refer to the [SIG-Architecture](https://gitee.com/openharmony/community/blob/master/sig/sig-architecture/sig-architecture_cn.md). The SIG-Architecture will arrange the review of the applying of creating new repository.
### License Requirements for Third-Party Open-Source Software ### License Requirements for Third-Party Open-Source Software
...@@ -131,66 +147,66 @@ Refer to the [SIG Management Regulations](https://gitee.com/openharmony/communit ...@@ -131,66 +147,66 @@ Refer to the [SIG Management Regulations](https://gitee.com/openharmony/communit
2. The software license must be compatible with the license for the code repository. 2. The software license must be compatible with the license for the code repository.
3. The following licenses for third-party open-source software are recommended in the OpenHarmony project: 3. The following licenses for third-party open-source software are recommended in the OpenHarmony project:
* Apache License 2.0 - Apache License 2.0
* Mulan Permissive Software License, Version 2 - Mulan Permissive Software License, Version 2
* BSD 2-clause - BSD 2-clause
* BSD 3-clause - BSD 3-clause
* DOM4J License - DOM4J License
* PostgreSQL License - PostgreSQL License
* Eclipse Distribution License 1.0 - Eclipse Distribution License 1.0
* MIT - MIT
* ISC - ISC
* ICU - ICU
* University of Illinois/NCSA - University of Illinois/NCSA
* W3C Software License - W3C Software License
* zlib/libpng - zlib/libpng
* Academic Free License 3.0 - Academic Free License 3.0
* Python Software Foundation License - Python Software Foundation License
* Python Imaging Library Software License - Python Imaging Library Software License
* Boost Software License Version 1.0 - Boost Software License Version 1.0
* WTF Public License - WTF Public License
* UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE - UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE
* Zope Public License 2.0 - Zope Public License 2.0
4. The following licenses for third-party open-source software are not recommended in the OpenHarmony project: 4. The following licenses for third-party open-source software are not recommended in the OpenHarmony project:
* GNU GPL 1, 2, 3 - GNU GPL 1, 2, 3
* GNU Affero GPL 3 - GNU Affero GPL 3
* GNU LGPL 2, 2.1, 3 - GNU LGPL 2, 2.1, 3
* QPL - QPL
* Sleepycat License - Sleepycat License
* Server Side Public License (SSPL) version 1 - Server Side Public License (SSPL) version 1
* Code Project Open License (CPOL) - Code Project Open License (CPOL)
* BSD-4-Clause/BSD-4-Clause (University of California-Specific) - BSD-4-Clause/BSD-4-Clause (University of California-Specific)
* Facebook BSD+Patents license - Facebook BSD+Patents license
* NPL 1.0/NPL 1.1 - NPL 1.0/NPL 1.1
* The Solipsistic Eclipse Public License - The Solipsistic Eclipse Public License
* The "Don't Be A Dick" Public License - The "Don't Be A Dick" Public License
* JSON License - JSON License
* Binary Code License (BCL) - Binary Code License (BCL)
* Intel Simplified Software License - Intel Simplified Software License
* JSR-275 License - JSR-275 License
* Microsoft Limited Public License - Microsoft Limited Public License
* Amazon Software License (ASL) - Amazon Software License (ASL)
* Java SDK for Satori RTM license - Java SDK for Satori RTM license
* Redis Source Available License (RSAL) - Redis Source Available License (RSAL)
* Booz Allen Public License - Booz Allen Public License
* Creative Commons Non-Commercial - Creative Commons Non-Commercial
* Sun Community Source License 3.0 - Sun Community Source License 3.0
* Common Development and Distribution Licenses: CDDL 1.0 and CDDL 1.1 - Common Development and Distribution Licenses: CDDL 1.0 and CDDL 1.1
* Common Public License: CPL 1.0 - Common Public License: CPL 1.0
* Eclipse Public License: EPL 1.0 - Eclipse Public License: EPL 1.0
* IBM Public License: IPL 1.0 - IBM Public License: IPL 1.0
* Mozilla Public Licenses: MPL 1.0, MPL 1.1, and MPL 2.0 - Mozilla Public Licenses: MPL 1.0, MPL 1.1, and MPL 2.0
* Sun Public License: SPL 1.0 - Sun Public License: SPL 1.0
* Open Software License 3.0 - Open Software License 3.0
* Erlang Public License - Erlang Public License
* UnRAR License - UnRAR License
* SIL Open Font License - SIL Open Font License
* Ubuntu Font License Version 1.0 - Ubuntu Font License Version 1.0
* IPA Font License Agreement v1.0 - IPA Font License Agreement v1.0
* Ruby License - Ruby License
* Eclipse Public License 2.0: EPL 2.0 - Eclipse Public License 2.0: EPL 2.0
If you want to introduce the software that complies with the unrecommended licenses listed in **4** or other licenses that are not mentioned, send an email to oh-legal@openatom.io. If you want to introduce the software that complies with the unrecommended licenses listed in **4** or other licenses that are not mentioned, send an email to oh-legal@openatom.io.
......
Prebuilts for Clang/LLVM-based tools used in OpenHarmony
====================================================
1. For the latest version of this doc, please make sure to visit:
[OpenHarmony Clang/LLVM-based Tools Readme Doc](https://gitee.com/openharmony/third_party_llvm-project/blob/master/llvm-build/README.md)
2. Build Instructions
------------------
```
# Get source code
repo init -u https://gitee.com/openharmony/manifest.git -b llvm_toolchain-dev
repo sync -c
repo forall -c 'git lfs pull'
cp -r toolchain/llvm-project/llvm-build toolchain
# Build Clang/LLVM-based prebuilts tool
./toolchain/llvm-project/llvm-build/env_prepare.sh
python3 ./toolchain/llvm-build/build.py
```
3. Update Prebuilts
----------------
From an OpenHarmony project run:
```
$ ./build/prebuilts_download.sh
```
# 常见问题 # 常见问题
- [开发语言常见问题](faqs-language.md)
- [Ability框架开发常见问题](faqs-ability.md) - [Ability框架开发常见问题](faqs-ability.md)
- [应用程序包管理开发常见问题](faqs-bundle.md)
- [ArkUI组件(ArkTS)开发常见问题](faqs-ui-ets.md)
- [ArkUI Web组件(ArkTS)开发常见问题](faqs-web-arkts.md)
- [UI框架(JS)开发常见问题](faqs-ui-js.md) - [UI框架(JS)开发常见问题](faqs-ui-js.md)
- [UI框架(ArkTS)开发常见问题](faqs-ui-ets.md) - [公共事件与通知开发常见问题](faqs-event-notification.md)
- [图形图像开发常见问题](faqs-graphics.md) - [图形图像开发常见问题](faqs-graphics.md)
- [文件管理开发常见问题](faqs-file-management.md) - [文件管理开发常见问题](faqs-file-management.md)
- [媒体开发常见问题](faqs-media.md)
- [网络与连接开发常见问题](faqs-connectivity.md) - [网络与连接开发常见问题](faqs-connectivity.md)
- [数据管理开发常见问题](faqs-data-management.md) - [数据管理开发常见问题](faqs-data-management.md)
- [设备管理开发常见问题](faqs-device-management.md) - [设备管理开发常见问题](faqs-device-management.md)
- [DFX开发常见问题](faqs-dfx.md)
- [国际化开发常见问题](faqs-international.md)
- [Native API使用常见问题](faqs-native.md) - [Native API使用常见问题](faqs-native.md)
- [三四方库使用常见问题](faqs-third-party-library.md) - [三四方库使用常见问题](faqs-third-party-library.md)
- [IDE使用常见问题](faqs-ide.md) - [IDE使用常见问题](faqs-ide.md)
......
# Ability框架开发常见问题 # Ability框架开发常见问题
## Stage模型中是否有类似FA模型的DataAbility的开发指导文档 ## Stage模型中是否有类似FA模型的DataAbility的开发指导文档
适用于:OpenHarmony SDK 3.2.3.5版本, API9 Stage模型 适用于:OpenHarmony SDK 3.2.3.5版本, API9 Stage模型
Stage模型中DataShareExtensionAbility提供了向其他应用共享以及管理其数据的方法。 Stage模型中DataShareExtensionAbility提供了向其他应用共享以及管理其数据的方法。
参考文档:[数据共享开发指导](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/database/database-datashare-guidelines.md) 参考文档:[数据共享开发指导](../database/database-datashare-guidelines.md)
## 拉起Ability为什么在界面上没反应? ## 拉起Ability在界面上没反应
适用于:OpenHarmony SDK 3.2.5.3版本,API9 Stage模型 适用于:OpenHarmony SDK 3.2.5.3版本,API9 Stage模型
...@@ -22,11 +20,37 @@ Stage模型中DataShareExtensionAbility提供了向其他应用共享以及管 ...@@ -22,11 +20,37 @@ Stage模型中DataShareExtensionAbility提供了向其他应用共享以及管
参考文档:[OpenHarmony版本转测试信息](https://gitee.com/openharmony-sig/oh-inner-release-management/blob/master/Release-Testing-Version.md) 参考文档:[OpenHarmony版本转测试信息](https://gitee.com/openharmony-sig/oh-inner-release-management/blob/master/Release-Testing-Version.md)
## 调用方法的时候,如何解决方法内部的this变成undefined? ## 如何将Ability的UI界面设置成透明
适用于:OpenHarmony SDK 3.2.3.5版本,API9 Stage模型
将最上层容器组件背景色设置为透明,然后通过设置XComponent组件的opacity属性值为0.01来实现。
示例:
```
build() {
Stack() {
XComponent({
id: 'componentId',
type: 'surface',
})
.width('100%')
.height('100%')
.opacity(0.01)
// 页面内容
}
.width('100%')
.height('100%')
.backgroundColor('rgba(255,255,255, 0)')
}
```
## 调用方法的时候,如何解决方法内部的this变成undefined
适用于:OpenHarmony SDK 3.2.5.3版本,API9 Stage模型 适用于:OpenHarmony SDK 3.2.5.3版本,API9 Stage模型
方式一:在调用方法的时候加上.bind(this) 方式一:在调用方法的时候加上.bind(this)
方式二:使用箭头函数。 方式二:使用箭头函数。
...@@ -36,9 +60,9 @@ Stage模型中DataShareExtensionAbility提供了向其他应用共享以及管 ...@@ -36,9 +60,9 @@ Stage模型中DataShareExtensionAbility提供了向其他应用共享以及管
Ability配置中缺少startWindowIcon属性配置,需要在module.json5中abilities中配置startWindowIcon。 Ability配置中缺少startWindowIcon属性配置,需要在module.json5中abilities中配置startWindowIcon。
参考文档:[Stage模型配置文件](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/stage-structure.md) 参考文档:[Stage模型配置文件](../quick-start/stage-structure.md)
示例: 示例:
``` ```
{ {
...@@ -59,4 +83,138 @@ Ability配置中缺少startWindowIcon属性配置,需要在module.json5中abil ...@@ -59,4 +83,138 @@ Ability配置中缺少startWindowIcon属性配置,需要在module.json5中abil
使用Ability的onConfigurationUpdated回调实现,系统语言、颜色模式以及Display相关的参数,比如方向、Density,发生变化时触发该回调。 使用Ability的onConfigurationUpdated回调实现,系统语言、颜色模式以及Display相关的参数,比如方向、Density,发生变化时触发该回调。
参考文档:[Ability开发指导](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/ability/stage-ability.md) 参考文档:[Ability开发指导](../ability/stage-ability.md)
## Stage模型是否推荐用globalThis去获取Context
适用于:OpenHarmony SDK 3.2.5.5版本,API9 Stage模型
不推荐,Stage模型使用globalThis去获取Context是错误的使用方式。在Stage模型中,整个应用进程共用一个js虚拟机实例,其中可以运行多个Ability实例,共用一个global对象。在同一个js虚拟机内的不同的Ability中使用globalThis获取Context,存在被覆盖从而发生错误的风险。
推荐使用方式参考:[Stage模型和Context详细介绍](../ability/context-userguide.md#stage%E6%A8%A1%E5%9E%8B%E5%92%8Ccontext%E8%AF%A6%E7%BB%86%E4%BB%8B%E7%BB%8D)
## 如何在应用A中去获取应用B的Hap包的安装路径
适用于:OpenHarmony SDK 3..0以上版本, API9 Stage模型
首先需要申请系统权限,具体参看文档:[自动化签名](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ohos-auto-configuring-signature-information-0000001271659465)。导入bundle模块,通过调用bundle.getApplicationInfo()接口,通过包名获取应用信息。然后通过application.moduleSourceDirs获取应用存储路径。
## 调用方使用startAbilityForResult,被调用方如何返回数据
适用于:OpenHarmony SDK3.0, API9 Stage模型
被调用方使用AbilityContext.terminateSelfWithResult方法,销毁被调用方ability,传递参数给startAbilityForResult回调函数,具体用法请参考[AbilityContext](../reference/apis/js-apis-ability-context.md#abilitycontextterminateselfwithresult)
## FA卡片上架后在用户的服务中心展示时可否触发生命周期,从而实现用户没有打开过FA应用的情况下获取到用户的登录信息?
适用于:OpenHarmony SDK 3.2.5.5版本, API8 FA模型
服务卡片在添加卡片后就触发了oncreat()生命周期,在不启用app的情况下也可以显示相关的用户信息-静默登录,但服务卡片目前要在app安装之后手动添加。
## 如何获取context
适用于:OpenHarmony SDK 3.2.7.5版本, API9 Stage模型
在MainAbility.ts文件中可以直接使用this.context获取context,在组件页面中可以使用getContext(this)获取context。
## 访问控制管理模块abilityAccessCtrl中grantUserGrantedPermission方法在API8语法校验提示未定义
适用于:OpenHarmony SDK 3.0版本, API8 FA模型
当前SDK有fullSDK和publicSDK两个版本,IDE默认下载的是publicSDK。其中,publicSDK版本不会包含系统API,如果要用系统API,需要使用fullSDK。具体参考[full-SDK替换指南](../quick-start/full-sdk-switch-guide.md)
## public sdk支持哪几种ExtensionAbility(ServiceExtensionAbility、FormExtensionAbility、DataShareExtensionAbility)
适用于:OpenHarmony SDK 3.2.5.6版本, API9 Stage模型
上述ExtensionAbility 中,public sdk 仅可以使用FormExtensionAbility。ServiceExtensionAbility和DataShareExtensionAbility 为系统接口,需要使用full sdk。
Public SDK : 面向应用开发者提供,不包含需要使用系统权限的系统接口。
Full SDK : 面向OEM厂商提供,包含了需要使用系统权限的系统接口。
## 服务卡片无法循环播放gif图
适用于:OpenHarmony SDK 3.2.5.6版本, API9 Stage模型
目前暂不支持播放GIF图片。
## 如何通过卡片点击实现业务登录场景
适用于:OpenHarmony SDK 3.2.5.5版本, API9 Stage模型
可以通过点击卡片拉起响应的Ability后,通过Ability来实现业务登录场景。
## 如何跳转到设置中应用详情页面。
使用于:OpenHarmony SDK 3.2.6.5版本
参考如下代码实现,示例:
```
this.context.startAbility(
{
action: "action.settings.app.info",
parameters: { "settingsParamBundleName": "your app bundlename" }
})
```
## 如何监听屏幕旋转
使用于:OpenHarmony SDK 3.2.5.5版本,API9 Stage模型
参考如下代码实现,示例:
```
let listener = mediaquery.matchMediaSync('(orientation: landscape)')
onPortrait(mediaQueryResult) {
if (mediaQueryResult.matches) {
// do something here
} else {
// do something here
}
}
listener.on('change', onPortrait)
```
## 如何控制checkbox选中切换过程中阴影背景的大小
使用于:OpenHarmony SDK 3.2.5.5版本,API9 Stage模型
设置checkbox组件padding属性,可控制阴影大小
## 如何设置卡片背景为透明
适用:OpenHarmony SDK 3.2.5.5版本
1. 在卡片根目录widget新建widget/resources/styles/default.json文件
2. 在default.json中书写如下代码:
```
{
"style": {
"app_background": "#00000000"
}
}
```
## FA卡片如何的传参和接参
适用:OpenHarmony SDK 3.2.5.5版本
使用featureAbility.getWant()和featureAbility.getContext()在json文件中router跳转发送数据,在js文件中用featureAblity方法接收
## router.disableAlertBeforeBackPage和router.enableAlertBeforeBackPage怎么触发
适用:OpenHarmony SDK 3.2.5.5版本
需要满足两个条件
1. router.disableAlertBeforeBackPage和router.enableAlertBeforeBackPage类似一个开关,disableAlertBeforeBackPage是返回上一级页面时关闭弹窗提示,enableAlertBeforeBackPage是打开弹窗提示,默认是关闭的,当你需要使用时,首先要在一个函数里面开启功能,然后再执行跳转
2. 必须要使用系统的返回按键才能触发效果。
<!--no_check-->
\ No newline at end of file
# 应用程序包管理开发常见问题
## 如何获取应用配置的versionCode和versionName
适用于:OpenHarmony SDK 3.2.3.5版本,API9 Stage模型
通过\@ohos.bundle模块buniple.getBundleInfo()接口获取包信息bundleInfo,然后分别通过bundleInfo.versionCode、bundleInfo.versionName
参考文档:[Bundle模块](../reference/apis/js-apis-Bundle.md#bundlegetbundleinfo)
## 如何获取应用自身的bundleName
适用于:OpenHarmony SDK 3.2.3.5版本,API9 Stage模型
通过可以context.abilityInfo.bundleName获取。
参考文档:[AbilityContext](../reference/apis/js-apis-ability-context.md#%E5%B1%9E%E6%80%A7)[AbilityInfo](../reference/apis/js-apis-bundle-AbilityInfo.md)
## 如何获取应用图标
适用于:OpenHarmony SDK 3.2.3.5版本,API9 Stage模型
通过\@ohos.bundle模块 getAbilityIcon 接口获取,需要配置权限:ohos.permission.GET_BUNDLE_INFO。
参考文档:[Bundle模块](../reference/apis/js-apis-Bundle.md#bundlegetbundleinfo)
## 如何判断某个应用是否为系统应用
使用于:OpenHarmony SDK 3.2.5.5版本,API9 Stage模型
使用bundle模块的getApplicationInfo接口获取待检验的应用的ApplicaitonInfo,根据ApplicaitonInfo中systemApp字段判断,若为true,则是系统应用,否则为非系统应用。
<!--no_check-->
\ No newline at end of file
# 网络与连接开发常见问题 # 网络与连接开发常见问题
## 网络请求中extraData支持哪几种的数据格式
## Post请求时,extraData支持哪几种的数据格式?
适用于:OpenHarmony SDK 3.2.2.5版本, API9 Stage模型 适用于:OpenHarmony SDK 3.2.2.5版本, API9 Stage模型
...@@ -14,13 +12,13 @@ extraData代表发送请求的额外数据,支持如下数据: ...@@ -14,13 +12,13 @@ extraData代表发送请求的额外数据,支持如下数据:
3. 开发者传入string对象,开发者需要自行编码,将编码后的string传入。 3. 开发者传入string对象,开发者需要自行编码,将编码后的string传入。
## 如何理解http请求的错误码28 ## 如何理解http请求的错误码28
适用于:OpenHarmony SDK 3.2.2.5版本,API9 Stage模型 适用于:OpenHarmony SDK 3.2.2.5版本,API9 Stage模型
错误码28代表CURLE_OPERATION_TIMEDOUT,操作超时。网络请求底层使用libcurl库,更多错误码可以查看相应文档。 错误码28代表CURLE_OPERATION_TIMEDOUT,操作超时。网络请求底层使用libcurl库,更多错误码可以查看相应文档。
参考文档:[开发指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-http.md#response%E5%B8%B8%E7%94%A8%E9%94%99%E8%AF%AF%E7%A0%81)[Curl错误码](https://curl.se/libcurl/c/libcurl-errors.html) 参考文档:[开发指南](../reference/apis/js-apis-http.md#response%E5%B8%B8%E7%94%A8%E9%94%99%E8%AF%AF%E7%A0%81)[Curl错误码](https://curl.se/libcurl/c/libcurl-errors.html)
## \@ohos.net.http.d.ts的response错误码返回6是什么意思? ## \@ohos.net.http.d.ts的response错误码返回6是什么意思?
...@@ -28,4 +26,81 @@ extraData代表发送请求的额外数据,支持如下数据: ...@@ -28,4 +26,81 @@ extraData代表发送请求的额外数据,支持如下数据:
6表示地址无法解析主机,可以尝试ping一下request中的url,确认是否可以ping通。 6表示地址无法解析主机,可以尝试ping一下request中的url,确认是否可以ping通。
更多错误码参考[Response常用错误码](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-http.md#response%E5%B8%B8%E7%94%A8%E9%94%99%E8%AF%AF%E7%A0%81)或者[Curl错误码](https://curl.se/libcurl/c/libcurl-errors.html) 更多错误码参考[Response常用错误码](../reference/apis/js-apis-http.md#response%E5%B8%B8%E7%94%A8%E9%94%99%E8%AF%AF%E7%A0%81)或者[Curl错误码](https://curl.se/libcurl/c/libcurl-errors.html)
## 调用camera拍摄的照片怎么上传到服务器
适用于:所有版本
具体开发参考文档:[上传下载](https://gitee.com/openharmony/app_samples/tree/master/Network/UploadDownload)
## OpenHarmony的http接口如何设置cookie
适用于:OpenHarmony SDK 3.2.6.5版本,API9 Stage模型
HttpRequestOptions中的header是一个Object类型,可以直接在header里设置cookie,具体开发参考文档:[数据请求](../reference/apis/js-apis-http.md#request)
## http请求的官方示例代码里的extra data部分怎么写
适用于:OpenHarmony SDK 3.2.6.5版本,API9 Stage模型
1. 鼠标移到extraData, ctrl+鼠标左键,跳转到sdk中,里面有关于extraData的传参说明。可以发现文档中对extraData的定义是这样的 extraData?: string | Object,也就是extraData支持string 和 Object两种类型。
2. 这两种写法都可以实现:
a.extraData:"data to send";
b. extraData:{ data:"data to send", },
## 设备连接wifi后,如何获取当前设备的IP地址
适用于:OpenHarmony SDK 3.2.7.5版本,API9 Stage模型
使用wifi模块获取ipInfo,然后转换为IP常用格式,注意wifi.getIpInfo()接口需要权限 ohos.permission.GET_WIFI_INFO。
示例:
```
import wifi from '@ohos.wifi'
@Entry
@Component
struct Page {
@State ip: string = '点击获取ip'
resolveIP(ip) {
if (ip < 0 || ip > 0xFFFFFFFF) {
throw ("The number is not normal!");
}
return (ip >>> 24) + "." + (ip >> 16 & 0xFF) + "." + (ip >> 8 & 0xFF) + "." + (ip & 0xFF);
}
build() {
Row() {
Column() {
Text(this.ip)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(()=>{
this.ip = this.resolveIP(wifi.getIpInfo().ipAddress)
})
}
.width('100%')
}
.height('100%')
}
}
```
## 如何判断当前是否有网络
适用于:OpenHarmony SDK 3.2.6.5版本,API9 Stage模型
通过如下hasDefaultNet接口判断是否有网络,注意需要申请 ohos.permission.GET_NETWORK_INFO 权限
```
connection.hasDefaultNet().then((has)=> {
console.log("hasDefaultNet " + JSON.stringify(has))
})
```
<!--no_check-->
\ No newline at end of file
...@@ -16,6 +16,60 @@ PixelMap应该被转换成相应的ArrayBuffer再放进数据库。 ...@@ -16,6 +16,60 @@ PixelMap应该被转换成相应的ArrayBuffer再放进数据库。
示例: 示例:
```shell
```
hdc_std file recv /data/app/el2/100/database/com.xxxx.xxxx/entry/db/test.db ./test.db hdc_std file recv /data/app/el2/100/database/com.xxxx.xxxx/entry/db/test.db ./test.db
``` ```
## 数据库在系统层面是否有锁机制,开发过程中是否需要关系数据库加锁问题
适用于:OpenHarmony SDK 3.2.5.5版本,API9 Stage模型
系统提供的分布式数据服务、关系型数据库和首选项均有锁机制,开发者无需关注。
## 数据库中加事务与不加事务的区别?
适用于:所有版本
在rdb中进行数据操作时,有可能会导致操作失败,出现意料之外的情况。当对数据库进行大量操作时,此种情况会导致部分数据操作失败,部分操作成功,导致部分数据丢失,可能会导致应用程序发生异常甚至崩溃。加事务后,则会将某一批操作组合成一个整体,要么同时成功,要么同时失败,则不会导致强关联的数据部分缺失的情况出现。
## 关系型数据库rdb支持哪些数据类型?
适用于:OpenHarmony SDK 3.0版本以上,API9 Stage模型
关系型数据库rdb支持的数据类型有:number、string、boolean。其中number为数组类型,支持Double,Long,Float,Int,Int64,最大精度为十进制17位数字。
## 如何查看数据库db文件
适用于:OpenHarmony SDK 3.2.6.5版本,API9 Stage模型
1. 执行 hdc_std shell 命令进入系统
2. 找到绝对路径:/data/app/el2/&lt;userId默认是100&gt;/database/&lt;bundleName&gt;
或找到沙箱路径:
a. 执行 ps -ef | grep hapName 命令找到对应应用的进程ID,
b. 数据库沙箱路径为:/proc/&lt;应用进程ID&gt;/root/data/storage/el2/database/。
3. 在数据库的绝对路径或者沙箱路径下执行 find ./ -name "\*.db" 即可找到数据库文件。
## 如何存储长文本数据
适用于:OpenHarmony SDK 3.2.5.5版本,API 9
- 首选项Preferences数据中的Value为string类型时最大支持8192字节。
- 分布式数据管理KV数据模型Value最大支持4M。
参考文档:[首选项概述](../database/database-preference-overview.md)[分布式数据服务概述](../database/database-mdds-overview.md)
## Stage模型数据共享DataShare开发
适用于:OpenHarmony SDK 3.2.5.5版本,API 9
Stage模型DataShare不可与FA模型DataAbility混用,连接的服务端应用需使用DataShareExtensionAbility实现。
参考文档:[数据共享开发指导](../database/database-datashare-guidelines.md)
<!--no_check-->
\ No newline at end of file
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
适用于:IDE 3.0.0.991 适用于:IDE 3.0.0.991
1. 给预览器新建Profile 1. 给预览器新建Profile
![zh-cn_image_0000001361254285](figures/zh-cn_image_0000001361254285.png) ![zh-cn_image_0000001361254285](figures/zh-cn_image_0000001361254285.png)
2. 新建Profile的具体参数可参考如下配置: 2. 新建Profile的具体参数可参考如下配置:
...@@ -49,3 +50,4 @@ ...@@ -49,3 +50,4 @@
连接需要认证的网络后,用浏览器打开任意网址就可以进入认证页面。 连接需要认证的网络后,用浏览器打开任意网址就可以进入认证页面。
如果开发板上没有浏览器,可以安装[浏览器Sample应用](https://gitee.com/openharmony/app_samples/tree/master/device/Browser) 如果开发板上没有浏览器,可以安装[浏览器Sample应用](https://gitee.com/openharmony/app_samples/tree/master/device/Browser)
<!--no_check-->
\ No newline at end of file
# 设备管理开发常见问题 # 设备管理开发常见问题
## 如何获取设备的dpi值 ## 如何获取设备的dpi值
适用于:OpenHarmony SDK 3.2.2.5版本,API9 Stage模型 适用于:OpenHarmony SDK 3.2.2.5版本,API9 Stage模型
导入@ohos.display包,通过getDefaultDisplay方法获取。 导入\@ohos.display包,通过getDefaultDisplay方法获取。
示例: 示例:
...@@ -22,3 +20,32 @@ display.getDefaultDisplay((err, data) => { ...@@ -22,3 +20,32 @@ display.getDefaultDisplay((err, data) => {
console.info('Test densityDPI:' + JSON.stringify(data.densityDPI)); console.info('Test densityDPI:' + JSON.stringify(data.densityDPI));
}); });
``` ```
## 如何获取当前运行设备类型(穿戴、平板等)
适用于:OpenHarmony SDK 3.2.2.5版本,API9 Stage模型
导入\@ohos.deviceInfo包,然后通过deviceInfo.deviceType获取设备类型。
参考文档:[设备信息](../reference/apis/js-apis-device-info.md)
## 如何获取设备系统版本
适用于:OpenHarmony SDK 3.2.5.5版本,API9 Stage模型
通过[deviceInfo](../reference/apis/js-apis-device-info.md)对象的osFullName属性获取设备系统版本。
## OpenHarmony设备如何获取UDID?
适用于:OpenHarmony SDK3.0, API9 Stage模型
1、如果想获取连接设备的udid,可使用 hdc shell bm get --udid命令;
2、如果想在代码中获得,参考文档 [udid](../reference/apis/js-apis-device-info.md)
## 开发快捷键功能
适用于:OpenHarmony SDK 3.2.6.5版本,API9 Stage模型
快捷键功能开发请使用组合按键api,具体可参考[组合按键(InputConsumer)](../reference/apis/js-apis-inputconsumer.md)
<!--no_check-->
\ No newline at end of file
# DFX开发常见问题
## 程序打开直接崩溃了,如何定位问题
使用于:OpenHarmony SDK 3.2.5.5版本
1.通过业务日志打印,定位崩溃的代码位置。
2.通过Crash文件查看报错信息,Crash文件路径是:/data/log/faultlog/faultlogger/。
## UiTest测试框架无法获取控件问题
使用于:OpenHarmony SDK 3.2.5.5版本
检查系统配置项 persist.ace.testmode.enabled 是开启。
通过hdc_std shell param get persist.ace.testmode.enabled 查看,若配置项为0,
可通过命令hdc_std shell param set persist.ace.testmode.enabled 1 开启配置。
## C++代码中hilog的格式参数类型为%d或者%s时,日志打印为何显示private
直接使用%d、%s等格式化参数时,标准系统默认使用private替换真实数据进行打印,防止数据泄露。如果需要打印出真实数据,需要使用%{public}d替换%d或者%{public}s替换%s。
## 如何解决hilog.debug日志无法打印
适用于:OpenHarmony SDK 3.2.5.5版本,API9 Stage模型
通过hdc_std命令 hdc_std shell hilog -b D开启调试开关
## 应用如何打印日志是使用hilog还是console,hilog接口参数domain的设置范围是什么
适用于:OpenHarmony SDK 3.2.2.5版本
推荐使用[hilog日志系统](../reference/apis/js-apis-hilog.md)进行日志打印,接口参数domain的设置范围可以参考[开发指南](../reference/apis/js-apis-hilog.md#hilogisloggable)
## hilog日志打印长度限制是多少,是否可以配置
适用于:OpenHarmony SDK 3.2.2.5版本
日志打印的长度限制为1024个字符,该长度不能配置。
## hilog接口的tag参数是否支持用空格隔开的多个字符串
适用于:OpenHarmony SDK 3.2.6.5版本,API9 Stage模型
不支持。
## hilog中没有使用{public}标识的数据,如何打印真实数据
适用于:OpenHarmony SDK 3.2.6.5版本,API9 Stage模型
使用命令:hdc_std shell hilog -p off
<!--no_check-->
\ No newline at end of file
# 公共事件与通知开发常见问题
## emitter数据大小限制
适用于:OpenHarmony SDK 3.2.5.3版本,API9 Stage模型
emitter数据大小限制不超过10240。
## 如何实现点击Notification通知打开对应App
适用于:OpenHarmony SDK 3.2.5.5版本,API9 Stage模型
通过配置Notification.publish发布通知接口的参数NotificationRequest中wantAgent属性实现
参考文档:[Notification](../reference/apis/js-apis-notification.md#notificationpublish)[WantAgent](../reference/apis/js-apis-wantAgent.md)
示例:
```
import WantAgent from '@ohos.wantAgent';
async function publishNotification() {
let wantAgentInfo = {
wants: [
{
bundleName: "com.example.notification",
abilityName: "MainAbility",
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
}
const wantAgent = await WantAgent.getWantAgent(wantAgentInfo)
let contentType = Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT;
await Notification.publish({
content: {
contentType: contentType,
normal: {
title: "测试标题",
text: "测试内容",
}
},
id: 1,
wantAgent: wantAgent
})
prompt.showToast({ message: "发送成功" })
}
```
<!--no_check-->
\ No newline at end of file
# 文件管理开发常见问题 # 文件管理开发常见问题
## fileio.rmdir是递归删除吗?
适用于:OpenHarmony SDK 3.2.6.3版本,API9 Stage模型
是递归删除。
## 如何实现如果文件不存在则创建文件
适用于:OpenHarmony SDK 3.2.6.3版本,API9 Stage模型
可以通过调用函数fileio.open(filePath, 0o100, 0o666)来实现,第二个参数0o100表示若文件不存在,则创建文件。使用该选项时必须指定第三个参数 mode。
## 使用fileio进行文件复制,传入沙箱路径报错call fail callback fail, code: 202, data: json arguments illegal)
适用于:OpenHarmony SDK 3.2.6.3版本,API9 Stage模型
使用fileio模块进行文件复制时,文件路径前缀中不能以“file:///”开头。
## fileIo将数据写入流文件writeSync接口,length传参问题
适用于:OpenHarmony SDK 3.2.6.5版本,API9 Stage模型
一个中文字符length为3,英文字符为1,当前buffer为string类型时,length项需要开发者手动换算;如果要写入全部内容,可直接忽略length项,length长度超长时会导致接口报错。
## 如何读取应用沙箱之外的文件
适用于:OpenHarmony SDK 3.2.6.5版本,API9 Stage模型
fileio中接口入参为path时只能是从context获取到的本应用沙箱路径,若要访问其他路径的数据,如公共数据图片视频等,需要通过数据所有者打开文件返回fd进行操作。
比如向mediaLibrary请求读取/写入某文件,然后通过打开代表特定文件的URI后返回的fd进行操作,操作步骤如下:
1. 通过媒体查询获取文件fileAsset对象;
2. 通过fileAsset.open方法返回的fd;
3. 将fd作为fileIo接口参数进行文件读写操作;
## 如何解决文件的中文内容乱码
适用于:OpenHarmony SDK 3.2.5.5版本,API9 Stage模型
读取文件内容的buffer数据后,通过util.TextDecoder对文件内容进行解码。
示例:
```
import util from '@ohos.util'
async function readFile(path) {
let stream = fileio.createStreamSync(path, "r+");
let readOut = await stream.read(new ArrayBuffer(4096));
let textDecoder = new util.TextDecoder("utf-8", { ignoreBOM: true });
let buffer = new Uint8Array(readOut.buffer)
let readString = textDecoder.decode(buffer, { stream: false });
console.log("[Demo] 读取的文件内容:" + readString);
}
```
## 调用媒体库getAlbums方法,没有收到返回,也没有捕获到异常是为什么 ## 调用媒体库getAlbums方法,没有收到返回,也没有捕获到异常是为什么
...@@ -34,3 +91,23 @@ getAlbums方法需要权限:ohos.permission.READ_MEDIA,从[OpenHarmony权限 ...@@ -34,3 +91,23 @@ getAlbums方法需要权限:ohos.permission.READ_MEDIA,从[OpenHarmony权限
}) })
} }
``` ```
## 如何解决多次通过媒体库FetchFileResult获取文件应用崩溃
适用于:OpenHarmonySDK 3.2.5.5版本,API9 Stage模型
通过FetchFileResult.close()方法,在FetchFileResult对象每次调用完,释放并使其失效。
## 在Stage模型下调用mediaLibrary.getMediaLibrary()接口,IDE报错
适用于:OpenHarmonySDK 3.25.5版本,API9 Stage模型
Stage模型下,获取媒体库实例应该调用mediaLibrary.getMediaLibrary(context: Context)。
## 调用mediaLibrary.getFileAssets()接口返回的内容如何排序
适用于:OpenHarmonySDK 3.2.5.5版本,API9 Stage模型
通过[MediaFetchOptions](../reference/apis/js-apis-medialibrary.md#mediafetchoptions7)对象参数里面的order属性进行排序。
<!--no_check-->
\ No newline at end of file
# hdc_std命令使用常见问题 # hdc_std命令使用常见问题
## 日志的常用命令 ## 日志的常用命令
适用于:OpenHarmony SDK 3.2.2.5版本 适用于:OpenHarmony SDK 3.2.2.5版本
...@@ -26,19 +24,7 @@ ...@@ -26,19 +24,7 @@
执行完命令后重启DevEco Studio。 执行完命令后重启DevEco Studio。
## 应用如何打印日志是使用hilog还是console,hilog接口参数domain的设置范围是什么? ## 用IDE安装HAP包到开发板上无法打开
适用于:OpenHarmony SDK 3.2.2.5版本
推荐使用[hilog日志系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-hilog.md)进行日志打印,接口参数domain的设置范围可以参考[开发指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-hilog.md#hilogisloggable)
## hilog日志打印长度限制是多少,是否可以配置
适用于:OpenHarmony SDK 3.2.2.5版本
日志打印的长度限制为1024个字符,该长度不能配置。
## 为什么有时候直接用IDE安装HAP包到开发板上无法打开?
适用于:OpenHarmony SDK 3.2.5.3版本,API9 Stage模型 适用于:OpenHarmony SDK 3.2.5.3版本,API9 Stage模型
...@@ -50,14 +36,53 @@ ...@@ -50,14 +36,53 @@
可以使用hdc_std file send上传文件。 可以使用hdc_std file send上传文件。
## 如何让RK3568开发板不熄屏 ## 如何让RK3568开发板不熄屏
适用于:OpenHarmony SDK 3.2.5.3版本,API9 Stage模型 适用于:OpenHarmony SDK 3.2.5.3版本,API9 Stage模型
输入命令hdc_std shell "power-shell setmode 602" 输入命令hdc_std shell "power-shell setmode 602"
## 如何通过命令启动Ability ## 如何通过命令启动Ability
适用于:OpenHarmony SDK 3.2.5.3版本,API9 Stage模型 适用于:OpenHarmony SDK 3.2.5.3版本,API9 Stage模型
输入命令hdc_std shell aa start -a AbilityName -b bundleName -m moduleName 输入命令hdc_std shell aa start -a AbilityName -b bundleName -m moduleName
## 如何修改开发板中文件目录为可读写权限
适用于:OpenHarmony SDK 3.2.5.6版本,API9 Stage模型
输入命令 hdc_std shell mount -o remount,rw /
## 如何解决hdc_std file recv 使用报错:Unkonw file option -r
适用于:OpenHarmony SDK 3.2.5.6版本,API9 Stage模型
1. 使用设备镜像或者同版本SDK中配套的hdc工具进行使用。
2. hdc工具指定的路径不要包含中文和空格。
## 如何使用命令卸载应用
适用于:OpenHarmony SDK 3.2.2.5版本
输入命令hdc_std uninstall [-k] [package_name]
## 如何查看系统是32位还是64位
适用于:OpenHarmony SDK 3.2.5.5版本
使用命令:hdc_std shell getconf LONG_BIT
若返回64则为64位系统,否则为32位系统。
## 如何查看组件树结构
适用于:OpenHarmony SDK 3.2.5.5版本
1. 使用命令hdc_std shell 进入命令行界面。
2. 输入 aa dump -a 找到abilityID。
3. aa dump -i [abilityID] -c -render 查看组件树。
<!--no_check-->
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册