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

!19607 待机模块api文档修改

Merge pull request !19607 from geraltxu/master
# @ohos.resourceschedule.deviceStandby(设备待机模块) # @ohos.resourceschedule.deviceStandby(设备待机模块)
当设备长时间未被使用或通过按键,可以使设备进入待机模式。待机模式不影响应用使用,还可以延长电池续航时间。通过本模块接口,可查询设备是否为待机模式,以及使应用灵活申请开启或关闭待机模式 当设备长时间未被使用或通过按键,可以使设备进入待机模式。待机模式不影响应用使用,还可以延长电池续航时间。通过本模块接口,可查询设备或应用是否为待机模式,以及为应用申请或取消待机资源管控
> **说明:** > **说明**:
> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 >
> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。<br>
> - 需要检查是否已经配置请求相应的权限: ohos.permission.DEVICE_STANDBY_EXEMPTION
## 导入模块 ## 导入模块
```js ```js
import deviceStandby from '@ohos.resourceschedule.deviceStandby'; import deviceStandby from '@ohos.resourceschedule.deviceStandby';
``` ```
## deviceStandby.isDeviceInStandby ## deviceStandby.isDeviceInStandby
isDeviceInStandby(callback: AsyncCallback&lt;boolean&gt;): void; isDeviceInStandby(callback: AsyncCallback&lt;boolean&gt;): void;
...@@ -33,6 +36,20 @@ isDeviceInStandby(callback: AsyncCallback&lt;boolean&gt;): void; ...@@ -33,6 +36,20 @@ isDeviceInStandby(callback: AsyncCallback&lt;boolean&gt;): void;
| 9800004 | System service operation failed. | | 9800004 | System service operation failed. |
| 18700001 | Caller information verification failed when applying for efficiency resources. | | 18700001 | Caller information verification failed when applying for efficiency resources. |
**示例**
try{
deviceStandby.isDeviceInStandby((err, res) => {
if (err) {
console.log('DEVICE_STANDBY isDeviceInStandby callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('DEVICE_STANDBY isDeviceInStandby callback succeeded, result: ' + JSON.stringify(res));
}
});
} catch(error) {
console.log('DEVICE_STANDBY isDeviceInStandby throw error, code is: ' + error.code + ',message is: ' + error.message);
}
## deviceStandby.isDeviceInStandby ## deviceStandby.isDeviceInStandby
isDeviceInStandby(): Promise&lt;boolean&gt; isDeviceInStandby(): Promise&lt;boolean&gt;
...@@ -58,6 +75,18 @@ isDeviceInStandby(): Promise&lt;boolean&gt; ...@@ -58,6 +75,18 @@ isDeviceInStandby(): Promise&lt;boolean&gt;
| 9800004 | System service operation failed. | | 9800004 | System service operation failed. |
| 18700001 | Caller information verification failed when applying for efficiency resources. | | 18700001 | Caller information verification failed when applying for efficiency resources. |
**示例**
try{
deviceStandby.isDeviceInStandby().then( res => {
console.log('DEVICE_STANDBY isDeviceInStandby promise succeeded, result: ' + JSON.stringify(res));
}).catch( err => {
console.log('DEVICE_STANDBY isDeviceInStandby promise failed. code is: ' + err.code + ',message is: ' + err.message);
});
} catch (error) {
console.log('DEVICE_STANDBY isDeviceInStandby throw error, code is: ' + error.code + ',message is: ' + error.message);
}
## deviceStandby.getExemptedApps ## deviceStandby.getExemptedApps
getExemptedApps(resourceTypes: number, callback: AsyncCallback<Array&lt;ExemptedAppInfo&gt;>): void; getExemptedApps(resourceTypes: number, callback: AsyncCallback<Array&lt;ExemptedAppInfo&gt;>): void;
...@@ -86,6 +115,23 @@ getExemptedApps(resourceTypes: number, callback: AsyncCallback<Array&lt;Exempted ...@@ -86,6 +115,23 @@ getExemptedApps(resourceTypes: number, callback: AsyncCallback<Array&lt;Exempted
| 9800004 | System service operation failed. | | 9800004 | System service operation failed. |
| 18700001 | Caller information verification failed when applying for efficiency resources. | | 18700001 | Caller information verification failed when applying for efficiency resources. |
**示例**
try{
deviceStandby.getExemptedApps(resourceTypes, (err, res) => {
if (err) {
console.log('DEVICE_STANDBY getExemptedApps callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('DEVICE_STANDBY getExemptedApps callback success.');
for (let i = 0; i < res.length; i++) {
console.log('DEVICE_STANDBY getExemptedApps callback result ' + JSON.stringify(res[i]));
}
}
});
} catch (error) {
console.log('DEVICE_STANDBY getExemptedApps throw error, code is: ' + error.code + ',message is: ' + error.message);
}
## deviceStandby.getExemptedApps ## deviceStandby.getExemptedApps
getExemptedApps(resourceTypes: number): Promise<Array&lt;ExemptedAppInfo&gt;>; getExemptedApps(resourceTypes: number): Promise<Array&lt;ExemptedAppInfo&gt;>;
...@@ -122,10 +168,25 @@ getExemptedApps(resourceTypes: number): Promise<Array&lt;ExemptedAppInfo&gt;>; ...@@ -122,10 +168,25 @@ getExemptedApps(resourceTypes: number): Promise<Array&lt;ExemptedAppInfo&gt;>;
| 9800004 | System service operation failed. | | 9800004 | System service operation failed. |
| 18700001 | Caller information verification failed when applying for efficiency resources. | | 18700001 | Caller information verification failed when applying for efficiency resources. |
**示例**
try{
deviceStandby.getExemptedApps(resourceTypes).then( res => {
console.log('DEVICE_STANDBY getExemptedApps promise success.');
for (let i = 0; i < res.length; i++) {
console.log('DEVICE_STANDBY getExemptedApps promise result ' + JSON.stringify(res[i]));
}
}).catch( err => {
console.log('DEVICE_STANDBY getExemptedApps promise failed. code is: ' + err.code + ',message is: ' + err.message);
});
} catch (error) {
console.log('DEVICE_STANDBY getExemptedApps throw error, code is: ' + error.code + ',message is: ' + error.message);
}
## deviceStandby.requestExemptionResource ## deviceStandby.requestExemptionResource
requestExemptionResource(request: ResourceRequest): void; requestExemptionResource(request: ResourceRequest): void;
订阅申请豁免,为应用申请临时不进入待机管控能力 应用订阅申请豁免,使应用临时不进入待机管控
**系统能力:** SystemCapability.ResourceSchedule.DeviceStandby.Exemption **系统能力:** SystemCapability.ResourceSchedule.DeviceStandby.Exemption
...@@ -149,10 +210,43 @@ requestExemptionResource(request: ResourceRequest): void; ...@@ -149,10 +210,43 @@ requestExemptionResource(request: ResourceRequest): void;
| 9800004 | System service operation failed. | | 9800004 | System service operation failed. |
| 18700001 | Caller information verification failed when applying for efficiency resources. | | 18700001 | Caller information verification failed when applying for efficiency resources. |
**示例**
let resRequest = {
resourceTypes: 1,
uid:10003,
name:"com.example.app",
duration:10,
reason:"apply",
};
// 异步方法promise方式
try{
deviceStandby.requestExemptionResource(resRequest).then( () => {
console.log('DEVICE_STANDBY requestExemptionResource promise succeeded.');
}).catch( err => {
console.log('DEVICE_STANDBY requestExemptionResource promise failed. code is: ' + err.code + ',message is: ' + err.message);
});
} catch (error) {
console.log('DEVICE_STANDBY requestExemptionResource throw error, code is: ' + error.code + ',message is: ' + error.message);
}
// 异步方法callback方式
try{
deviceStandby.requestExemptionResource(resRequest, (err) => {
if (err) {
console.log('DEVICE_STANDBY requestExemptionResource callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('DEVICE_STANDBY requestExemptionResource callback succeeded.');
}
});
} catch (error) {
console.log('DEVICE_STANDBY requestExemptionResource throw error, code is: ' + error.code + ',message is: ' + error.message);
}
## deviceStandby.releaseExemptionResource ## deviceStandby.releaseExemptionResource
releaseExemptionResource(request: ResourceRequest): void; releaseExemptionResource(request: ResourceRequest): void;
去除订阅申请豁免,去除应用暂时不进入待机管控的能力 取消应用订阅申请豁免
**系统能力:** SystemCapability.ResourceSchedule.DeviceStandby.Exemption **系统能力:** SystemCapability.ResourceSchedule.DeviceStandby.Exemption
...@@ -176,6 +270,39 @@ releaseExemptionResource(request: ResourceRequest): void; ...@@ -176,6 +270,39 @@ releaseExemptionResource(request: ResourceRequest): void;
| 9800004 | System service operation failed. | | 9800004 | System service operation failed. |
| 18700001 | Caller information verification failed when applying for efficiency resources. | | 18700001 | Caller information verification failed when applying for efficiency resources. |
**示例**
let resRequest = {
resourceTypes: 1,
uid:10003,
name:"com.demo.app",
duration:10,
reason:"unapply",
};
// 异步方法promise方式
try{
deviceStandby.releaseExemptionResource(resRequest).then( () => {
console.log('DEVICE_STANDBY releaseExemptionResource promise succeeded.');
}).catch( err => {
console.log('DEVICE_STANDBY releaseExemptionResource promise failed. code is: ' + err.code + ',message is: ' + err.message);
});
} catch (error) {
console.log('DEVICE_STANDBY releaseExemptionResource throw error, code is: ' + error.code + ',message is: ' + error.message);
}
// 异步方法callback方式
try{
deviceStandby.releaseExemptionResource(resRequest, (err) => {
if (err) {
console.log('DEVICE_STANDBY releaseExemptionResource callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('DEVICE_STANDBY releaseExemptionResource callback succeeded.');
}
});
} catch (error) {
console.log('DEVICE_STANDBY releaseExemptionResource throw error, code is: ' + error.code + ',message is: ' + error.message);
}
## ResourceType ## ResourceType
非待机应用资源枚举。 非待机应用资源枚举。
<br> <br>
...@@ -194,20 +321,20 @@ releaseExemptionResource(request: ResourceRequest): void; ...@@ -194,20 +321,20 @@ releaseExemptionResource(request: ResourceRequest): void;
豁免应用信息,不进入待机管控的应用信息。 豁免应用信息,不进入待机管控的应用信息。
<br> <br>
|名称 |类型 |说明 | |名称 |类型 | 必填 |说明 |
| ------------ | ------------ | ------------ | | ------------ | ------------ |------------ | ------------ |
|resourceTypes | number |应用的资源类型 | |resourceTypes | number | 是 |应用的资源类型 |
|name |string | 应用名 | |name |string | 是 | 应用名 |
|duration | number | 豁免时长 | |duration | number | 是 | 豁免时长 |
## ResourceRequest ## ResourceRequest
待机资源请求体。 待机资源请求体。
<br> <br>
|名称 |类型 |说明 | |名称 |类型 | 必填 |说明 |
| ------------ | ------------ | ------------ | | ------------ | ------------ |------------| ------------ |
|resourceTypes | number |应用的资源类型 | |resourceTypes | number | 是 |应用的资源类型 |
|uid | number |应用uid | |uid | number | 是 |应用uid |
|name |string | 应用名称 | |name |string | 是 | 应用名称 |
|duration | number | 豁免时长 | |duration | number | 是 | 豁免时长 |
|reason |string | 申请原因 | |reason |string | 是 | 申请原因 |
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册