From 644b42dfe571d78ac635365f4653539214466595 Mon Sep 17 00:00:00 2001 From: geraltxu <36860135+geraltxu@users.noreply.github.com> Date: Thu, 18 May 2023 17:45:24 +0800 Subject: [PATCH] =?UTF-8?q?=E9=95=BF=E5=BE=85=E6=9C=BA=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xufanghan --- .../device-standby-use-guide.md | 37 +++ .../js-apis-resourceschedule-deviceStandby.md | 239 ++++++++++++++++++ 2 files changed, 276 insertions(+) create mode 100644 zh-cn/application-dev/device_standby/device-standby-use-guide.md create mode 100644 zh-cn/application-dev/reference/apis/js-apis-resourceschedule-deviceStandby.md diff --git a/zh-cn/application-dev/device_standby/device-standby-use-guide.md b/zh-cn/application-dev/device_standby/device-standby-use-guide.md new file mode 100644 index 0000000000..df27f6c091 --- /dev/null +++ b/zh-cn/application-dev/device_standby/device-standby-use-guide.md @@ -0,0 +1,37 @@ +# 设备待机空闲部件开发指南 +## 场景介绍 +当前设备在待机状态及睡眠状态,应用不会被冻结、任务不会被延迟、时钟时间不会变慢、CPU锁不会释放、网络不会停止,导致灭屏功耗大。 +设备灭屏/锁屏情况下,保持一段时间后进入待机空闲模式,限制后台应用使用资源,降低功耗。
+解决以下场景
+一、采集系统设备进入待机空闲特征
+二、检测设备进入浅睡眠状态和深睡眠状态
+三、设备每隔一段时间暂停睡眠,进入维护状态
+四、检测到设备进入待机空闲状态,触发资源管控 + +本文档旨在帮助开发者理解设备待机空闲下的相关功能和资源使用规范。 +## 待机低续航模式介绍 +待机低续航模式会延迟应用后台cpu和网络活动,从而延长电池续航时间。 +
包括: +
1.应用限网:限制访问网络 +
2.work待机任务:延迟应用的work任务响应 +
3.running_lock锁:释放应用的锁 +
4.Timer响应:延迟应用的timer响应 +## 接口说明 +### 一、返回当前是否进入待机功耗续航模式 +isDeviceInStandby() +
+功能描述:返回当前是否进入待机低功耗续航模式。 +
+举例:push客户端应用获取待机状态管控消息推送缓存 +### 二、获取豁免信息 +getExemptionListApps() +
+功能描述:获取豁免信息 +
+举例:push客户端应用获取push限网豁免名单 +### 三、更新调用者豁免信息 +applyExemptionAppResource()、unapplyExemptionAppResource() +
+功能描述:更新调用者豁免信息 +
+举例:针对系统应用可以申请临时豁免,临时放行待机状态管控该应用使用资源限制 diff --git a/zh-cn/application-dev/reference/apis/js-apis-resourceschedule-deviceStandby.md b/zh-cn/application-dev/reference/apis/js-apis-resourceschedule-deviceStandby.md new file mode 100644 index 0000000000..62f49c63e1 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-resourceschedule-deviceStandby.md @@ -0,0 +1,239 @@ +# @ohos.resourceschedule.deviceStandby(设备待机空闲部件功能) +本模块提供设备待机空闲部件管理功能 +
+API使用场景: +
+如果用户长时间没有主动使用设备,且屏幕已关闭,则系统会使设备进入待机低功耗续航模式。待机续航模式会延迟应用后台CPU和网络活动,从而延长电池续航时间。 包括: +
+1、应用限网:通过iptable防火墙限制后台应用访问网络 +
+2、Work待机任务:延迟应用的work任务响应 +
+3、running_lock锁:临时释放应用的background running_lock锁 +
+4、Timer响应:延迟应用的timer响应 +
+5、待规划:停止wifi扫描、停止蓝牙扫描、云同步账户等 + +> **说明:** +> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## 导入模块 +```js +import deviceStandby from '@ohos.resourceschedule.deviceStandby'; +``` +## deviceStandby.isDeviceInStandby +function isDeviceInStandby(callback: AsyncCallback): void; +
+当前设备是否进入待机低功耗续航模式 +
+**系统能力:** SystemCapability.ResourceSchedule.DeviceStandby.Idle + +**参数**: + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------------ | +| callback | Callback<void> | 是 | 延迟即将超时的回调函数,一般在超时前6秒通过此回调通知应用。 | + +**错误码**: + +以下错误码的详细介绍请参见[@ohos.resourceschedule.backgroundTaskManager (后台任务管理)](../errorcodes/errorcode-backgroundTaskMgr.md)错误码。 + +| 错误码ID | 错误信息 | +| ---- | --------------------- | +| 201 | Permission denied. | +| 401 | Parameter error. | +| 9800001 | Memory operation failed. | +| 9800002 | Parcel operation failed. | +| 9800003 | IPC failed. | | +| 9800004 | System service operation failed. | +| 18700001 | Caller information verification failed when applying for efficiency resources. | + +## deviceStandby.isDeviceInStandby +function isDeviceInStandby(): Promise<boolean> +
+当前设备是否进入待机低功耗续航模式 +
+**系统能力:** SystemCapability.ResourceSchedule.DeviceStandby.Idle + +**返回值**: + +| 类型 | 说明 | +| --------------------- | ---------------------------------------- | +| Promise<boolean> | 指定的Promise回调方法。返回是否进入待机低功耗续航模式。| + +**错误码**: +以下错误码的详细介绍请参见[@ohos.resourceschedule.backgroundTaskManager (后台任务管理)](../errorcodes/errorcode-backgroundTaskMgr.md)错误码。 + +| 错误码ID | 错误信息 | +| ---- | --------------------- | +| 201 | Permission denied. | +| 401 | Parameter error. | +| 9800001 | Memory operation failed. | +| 9800002 | Parcel operation failed. | +| 9800003 | IPC failed. | | +| 9800004 | System service operation failed. | +| 18700001 | Caller information verification failed when applying for efficiency resources. | + +## deviceStandby.getExemptionListApps +function getExemptionListApps(resourceTypes: number, callback: AsyncCallback): void; +
+返回豁免应用名单 +
+**系统能力:** SystemCapability.ResourceSchedule.DeviceStandby.Exemption +
+**系统API:** 此接口为系统接口。 + +**参数**: + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------------ | +| resourceTypes |number | 是 | 资源类型,具体结构见文末枚举 | +| callback | AsyncCallback | 是 | 回调函数,具体结构见文末 | + +**错误码**: + +以下错误码的详细介绍请参见[@ohos.resourceschedule.backgroundTaskManager (后台任务管理)](../errorcodes/errorcode-backgroundTaskMgr.md)错误码。 + +| 错误码ID | 错误信息 | +| ---- | --------------------- | +| 201 | Permission denied. | +| 202 | Not System App. | +| 401 | Parameter error. | +| 9800001 | Memory operation failed. | +| 9800002 | Parcel operation failed. | +| 9800003 | IPC failed. | | +| 9800004 | System service operation failed. | +| 18700001 | Caller information verification failed when applying for efficiency resources. | +## deviceStandby.getExemptionListApps +function getExemptionListApps(resourceTypes: number): Promise; +
+返回豁免应用名单 +
+**系统能力:** SystemCapability.ResourceSchedule.DeviceStandby.Exemption +
+**系统API:** 此接口为系统接口。 + +**参数**: + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------------ | +| resourceTypes |number | 是 | 资源类型。 | + +**返回值**: + +| 类型 | 说明 | +| --------------------- | ---------------------------------------- | +| Promise | 指定的Promise回调方法。返回豁免应用名单,具体结构见文末| + +**错误码**: + +以下错误码的详细介绍请参见[@ohos.resourceschedule.backgroundTaskManager (后台任务管理)](../errorcodes/errorcode-backgroundTaskMgr.md)错误码。 + +| 错误码ID | 错误信息 | +| ---- | --------------------- | +| 201 | Permission denied. | +| 202 | Not System App. | +| 401 | Parameter error. | +| 9800001 | Memory operation failed. | +| 9800002 | Parcel operation failed. | +| 9800003 | IPC failed. | | +| 9800004 | System service operation failed. | +| 18700001 | Caller information verification failed when applying for efficiency resources. | + +## deviceStandby.applyExemptionAppResource +function applyExemptionAppResource(request: ResourceRequest): void; +
+订阅申请豁免 +
+**系统能力:** SystemCapability.ResourceSchedule.DeviceStandby.Exemption +
+**系统API:** 此接口为系统接口。 + +**参数**: + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------------ | +| request |ResourceRequest | 是 | 请求豁免应用信息数据结构,具体结构见文末请求体 | + +**错误码**: + +以下错误码的详细介绍请参见[@ohos.resourceschedule.backgroundTaskManager (后台任务管理)](../errorcodes/errorcode-backgroundTaskMgr.md)错误码。 + +| 错误码ID | 错误信息 | +| ---- | --------------------- | +| 201 | Permission denied. | +| 202 | Not System App. | +| 401 | Parameter error. | +| 9800001 | Memory operation failed. | +| 9800002 | Parcel operation failed. | +| 9800003 | IPC failed. | | +| 9800004 | System service operation failed. | +| 18700001 | Caller information verification failed when applying for efficiency resources. | + +## deviceStandby.unapplyExemptionAppResource +function unapplyExemptionAppResource(request: ResourceRequest): void; +
+去除订阅申请豁免 +
+**系统能力:** SystemCapability.ResourceSchedule.DeviceStandby.Exemption +
+**系统API:** 此接口为系统接口。 + +**参数**: + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------------ | +| request |ResourceRequest | 是 | 请求豁免应用信息数据结构,具体结构见文末请求体 | + +**错误码**: + +以下错误码的详细介绍请参见[@ohos.resourceschedule.backgroundTaskManager (后台任务管理)](../errorcodes/errorcode-backgroundTaskMgr.md)错误码。 + +| 错误码ID | 错误信息 | +| ---- | --------------------- | +| 201 | Permission denied. | +| 202 | Not System App. | +| 401 | Parameter error. | +| 9800001 | Memory operation failed. | +| 9800002 | Parcel operation failed. | +| 9800003 | IPC failed. | | +| 9800004 | System service operation failed. | +| 18700001 | Caller information verification failed when applying for efficiency resources. | + +## 枚举类和请求体 +### ResourceType +The resource type of exemption application. +
+ +|名称 |枚举值 |说明| +| ------------ | ------------ |--------------| +|NETWORK |1 |The resource for non-standby network access.| +|RUNNING_LOCK |1 << 1 |The resource for non-standby cpu-runninglock.| +|TIMER |1 << 2 |The resource for non-standby timer.| +|WORK_SCHEDULER |1 << 3 |The resource for non-standby workscheduler.| +|AUTO_SYNC |1 << 4 |The resource for non-standby Automatic synchronization.| +|PUSH |1 << 5 |The resource for non-standby pushkit.| +|FREEZE |1 << 6 |The resource for non-standby freezing application.| + +### ExemptionAppInfo +The information of exemption application. +
+ +|对象名 |类型 |说明 | +| ------------ | ------------ | ------------ | +|resourceTypes | number |The set of resource types that app wants to apply. | +|name |string | The app name. | +|duration | number | The exemption duration. | + +### ResourceRequest +The request of standby resources. +
+ +|对象名 |类型 |说明 | +| ------------ | ------------ | ------------ | +|resourceTypes | number |The set of resource types that app wants to apply. | +|uid | number |The app uid. | +|name |string | The app name. | +|duration | number | The exemption duration. | +|reason |string | The apply reason. | \ No newline at end of file -- GitLab