1e41f4b71Sopenharmony_ci# @ohos.resourceschedule.deviceStandby (Device Standby) (System API)
2e41f4b71Sopenharmony_ciA device enters standby mode if it is unused for a long period of time or after the Power button is pressed. The standby mode prolongs the battery life without affecting the use of applications. The **deviceStandby** module provides APIs for you to check whether a device is in standby mode and request or cancel standby resource control for an application.
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci>  **NOTE**
5e41f4b71Sopenharmony_ci>
6e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
7e41f4b71Sopenharmony_ci>
8e41f4b71Sopenharmony_ci> The APIs provided by this module are system APIs.
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Modules to Import
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci```ts
13e41f4b71Sopenharmony_ciimport deviceStandby from '@ohos.resourceschedule.deviceStandby';
14e41f4b71Sopenharmony_ci```
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## deviceStandby.getExemptedApps
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_cigetExemptedApps(resourceTypes: number, callback: AsyncCallback<Array&lt;ExemptedAppInfo&gt;>): void
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ciObtains the list of applications that can still use resources of the specified types when the device is in standby mode. This API uses an asynchronous callback to return the result.
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ResourceSchedule.DeviceStandby
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.DEVICE_STANDBY_EXEMPTION
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**Parameters**
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci| Name     | Type                  | Mandatory  | Description                            |
30e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------ |
31e41f4b71Sopenharmony_ci| ResourceTypes|number | Yes   | Resource types. For details, see [ResourceType](#resourcetype).|
32e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array&lt;[ExemptedAppInfo](#exemptedappinfo)&gt;> | Yes   |Callback used to return the exempted application information.|
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci**Error codes**
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ciFor details about the error codes, see [backgroundTaskManager Error Codes](errorcode-backgroundTaskMgr.md) and [Universal Error Codes](../errorcode-universal.md).
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci| ID | Error Message            |
39e41f4b71Sopenharmony_ci| ---- | --------------------- |
40e41f4b71Sopenharmony_ci| 201  | Permission denied. |
41e41f4b71Sopenharmony_ci| 202 | Not System App. |
42e41f4b71Sopenharmony_ci| 401 | Parameter error. |
43e41f4b71Sopenharmony_ci| 9800001 | Memory operation failed. |
44e41f4b71Sopenharmony_ci| 9800002 | Parcel operation failed. |
45e41f4b71Sopenharmony_ci| 9800003 | Inner transact failed. |
46e41f4b71Sopenharmony_ci| 9800004 | System service operation failed. |
47e41f4b71Sopenharmony_ci| 18700001 | Caller information verification failed. |
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci**Example**
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci```ts
52e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_cilet resourceTypes: deviceStandby.ResourceType  = deviceStandby.ResourceType.TIMER | deviceStandby.ResourceType.NETWORK;
55e41f4b71Sopenharmony_cideviceStandby.getExemptedApps(resourceTypes, (err: BusinessError, res: Array<deviceStandby.ExemptedAppInfo>) => {
56e41f4b71Sopenharmony_ci  if (err) {
57e41f4b71Sopenharmony_ci    console.log('DEVICE_STANDBY getExemptedApps callback failed. code is: ' + err.code + ',message is: ' + err.message);
58e41f4b71Sopenharmony_ci  } else {
59e41f4b71Sopenharmony_ci    console.log('DEVICE_STANDBY getExemptedApps callback success.');
60e41f4b71Sopenharmony_ci    for (let i = 0; i < res.length; i++) {
61e41f4b71Sopenharmony_ci      console.log('DEVICE_STANDBY getExemptedApps callback result ' + JSON.stringify(res[i]));
62e41f4b71Sopenharmony_ci    }
63e41f4b71Sopenharmony_ci  }
64e41f4b71Sopenharmony_ci});
65e41f4b71Sopenharmony_ci```
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci## deviceStandby.getExemptedApps
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_cigetExemptedApps(resourceTypes: number): Promise<Array&lt;ExemptedAppInfo&gt;>
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ciObtains the list of applications that can still use resources of the specified types when the device is in standby mode. This API uses a promise to return the result.
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ResourceSchedule.DeviceStandby
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.DEVICE_STANDBY_EXEMPTION
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci**Parameters**
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci| Name     | Type                  | Mandatory  | Description                            |
81e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------ |
82e41f4b71Sopenharmony_ci| ResourceTypes|number | Yes   |Resource types. For details, see [ResourceType](#resourcetype).|
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**Return value**
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci| Type                   | Description                                      |
87e41f4b71Sopenharmony_ci| --------------------- | ---------------------------------------- |
88e41f4b71Sopenharmony_ci| Promise<Array&lt;[ExemptedAppInfo](#exemptedappinfo)&gt;> | Promise used to return the exempted application information.|
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**Error codes**
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ciFor details about the error codes, see [backgroundTaskManager Error Codes](errorcode-backgroundTaskMgr.md) and [Universal Error Codes](../errorcode-universal.md).
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci| ID | Error Message            |
95e41f4b71Sopenharmony_ci| ---- | --------------------- |
96e41f4b71Sopenharmony_ci| 201  | Permission denied. |
97e41f4b71Sopenharmony_ci| 202 | Not System App. |
98e41f4b71Sopenharmony_ci| 401 | Parameter error. |
99e41f4b71Sopenharmony_ci| 9800001 | Memory operation failed. |
100e41f4b71Sopenharmony_ci| 9800002 | Parcel operation failed. |
101e41f4b71Sopenharmony_ci| 9800003 | Inner transact failed. |
102e41f4b71Sopenharmony_ci| 9800004 | System service operation failed. |
103e41f4b71Sopenharmony_ci| 18700001 | Caller information verification failed. |
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci**Example**
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci```ts
108e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_cilet resourceTypes: deviceStandby.ResourceType = deviceStandby.ResourceType.TIMER | deviceStandby.ResourceType.NETWORK;
111e41f4b71Sopenharmony_cideviceStandby.getExemptedApps(resourceTypes).then( (res: Array<deviceStandby.ExemptedAppInfo>) => {
112e41f4b71Sopenharmony_ci  console.log('DEVICE_STANDBY getExemptedApps promise success.');
113e41f4b71Sopenharmony_ci  for (let i = 0; i < res.length; i++) {
114e41f4b71Sopenharmony_ci    console.log('DEVICE_STANDBY getExemptedApps promise result ' + JSON.stringify(res[i]));
115e41f4b71Sopenharmony_ci  }
116e41f4b71Sopenharmony_ci}).catch( (err: BusinessError) => {
117e41f4b71Sopenharmony_ci  console.log('DEVICE_STANDBY getExemptedApps promise failed. code is: ' + err.code + ',message is: ' + err.message);
118e41f4b71Sopenharmony_ci});
119e41f4b71Sopenharmony_ci```
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci## deviceStandby.requestExemptionResource
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_cirequestExemptionResource(request: ResourceRequest): void
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ciRequests exemption, so that the application can use restricted resources when the device is in standby mode.
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ResourceSchedule.DeviceStandby
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.DEVICE_STANDBY_EXEMPTION
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci**Parameters**
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci| Name     | Type                  | Mandatory  | Description                            |
135e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------ |
136e41f4b71Sopenharmony_ci| request |[ResourceRequest](#resourcerequest)| Yes   | Request body.|
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci**Error codes**
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ciFor details about the error codes, see [backgroundTaskManager Error Codes](errorcode-backgroundTaskMgr.md) and [Universal Error Codes](../errorcode-universal.md).
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci| ID | Error Message            |
143e41f4b71Sopenharmony_ci| ---- | --------------------- |
144e41f4b71Sopenharmony_ci| 201  | Permission denied. |
145e41f4b71Sopenharmony_ci| 202 | Not System App. |
146e41f4b71Sopenharmony_ci| 401 | Parameter error. |
147e41f4b71Sopenharmony_ci| 9800001 | Memory operation failed. |
148e41f4b71Sopenharmony_ci| 9800002 | Parcel operation failed. |
149e41f4b71Sopenharmony_ci| 9800003 | Inner transact failed. |
150e41f4b71Sopenharmony_ci| 9800004 | System service operation failed. |
151e41f4b71Sopenharmony_ci| 18700001 | Caller information verification failed. |
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci**Example**
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci```ts
156e41f4b71Sopenharmony_cilet resRequest: deviceStandby.ResourceRequest = {
157e41f4b71Sopenharmony_ci  resourceTypes: deviceStandby.ResourceType.TIMER,
158e41f4b71Sopenharmony_ci  uid:10003,
159e41f4b71Sopenharmony_ci  name:"com.example.app",
160e41f4b71Sopenharmony_ci  duration:10,
161e41f4b71Sopenharmony_ci  reason:"apply",
162e41f4b71Sopenharmony_ci};
163e41f4b71Sopenharmony_cideviceStandby.requestExemptionResource(resRequest);
164e41f4b71Sopenharmony_ci```
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci## deviceStandby.releaseExemptionResource
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_cireleaseExemptionResource(request: ResourceRequest): void
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ciCancels exemption for the application.
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ResourceSchedule.DeviceStandby
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.DEVICE_STANDBY_EXEMPTION
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ci**Parameters**
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_ci| Name     | Type                  | Mandatory  | Description                            |
180e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------ |
181e41f4b71Sopenharmony_ci| request |[ResourceRequest](#resourcerequest)| Yes   | Request body.|
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci**Error codes**
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ciFor details about the error codes, see [backgroundTaskManager Error Codes](errorcode-backgroundTaskMgr.md) and [Universal Error Codes](../errorcode-universal.md).
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci| ID | Error Message            |
188e41f4b71Sopenharmony_ci| ---- | --------------------- |
189e41f4b71Sopenharmony_ci| 201  | Permission denied. |
190e41f4b71Sopenharmony_ci| 202 | Not System App. |
191e41f4b71Sopenharmony_ci| 401 | Parameter error. |
192e41f4b71Sopenharmony_ci| 9800001 | Memory operation failed. |
193e41f4b71Sopenharmony_ci| 9800002 | Parcel operation failed. |
194e41f4b71Sopenharmony_ci| 9800003 | Inner transact failed. |
195e41f4b71Sopenharmony_ci| 9800004 | System service operation failed. |
196e41f4b71Sopenharmony_ci| 18700001 | Caller information verification failed. |
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci**Example**
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci```ts
201e41f4b71Sopenharmony_cilet resRequest: deviceStandby.ResourceRequest = {
202e41f4b71Sopenharmony_ci  resourceTypes: deviceStandby.ResourceType.TIMER,
203e41f4b71Sopenharmony_ci  uid:10003,
204e41f4b71Sopenharmony_ci  name:"com.demo.app",
205e41f4b71Sopenharmony_ci  duration:10,
206e41f4b71Sopenharmony_ci  reason:"unapply",
207e41f4b71Sopenharmony_ci};
208e41f4b71Sopenharmony_cideviceStandby.releaseExemptionResource(resRequest);
209e41f4b71Sopenharmony_ci```
210e41f4b71Sopenharmony_ci
211e41f4b71Sopenharmony_ci## ResourceType
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ciEnumerates the types of resources that can be used by exempted applications.
214e41f4b71Sopenharmony_ci
215e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ResourceSchedule.DeviceStandby
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ci|Name  |Value  |Description|
219e41f4b71Sopenharmony_ci| ------------ | ------------ |--------------|
220e41f4b71Sopenharmony_ci|NETWORK    |1   |Network access resource.|
221e41f4b71Sopenharmony_ci|RUNNING_LOCK    |2   |CPU running lock resource.|
222e41f4b71Sopenharmony_ci|TIMER     |4   | Timer task resource.|
223e41f4b71Sopenharmony_ci|WORK_SCHEDULER     |8   | Work task resource.|
224e41f4b71Sopenharmony_ci|AUTO_SYNC      |16   | Automatic synchronization resource.|
225e41f4b71Sopenharmony_ci|PUSH     |32   | Push kit resource.|
226e41f4b71Sopenharmony_ci|FREEZE       |64   | Freezing application resource.|
227e41f4b71Sopenharmony_ci
228e41f4b71Sopenharmony_ci## ExemptedAppInfo
229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ciDefines the information about an exempted application.
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ResourceSchedule.DeviceStandby
233e41f4b71Sopenharmony_ci
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ci|Name |Type  | Mandatory  |Description  |
236e41f4b71Sopenharmony_ci| ------------ | ------------ |------------ | ------------ |
237e41f4b71Sopenharmony_ci|resourceTypes   | number  | Yes  |Resource types. For details, see [ResourceType](#resourcetype).  |
238e41f4b71Sopenharmony_ci|name   |string   | Yes  |  Name of the application. |
239e41f4b71Sopenharmony_ci|duration   | number  | Yes  | Exemption duration.|
240e41f4b71Sopenharmony_ci
241e41f4b71Sopenharmony_ci## ResourceRequest
242e41f4b71Sopenharmony_ci
243e41f4b71Sopenharmony_ciDefines the message used to request to be an exempted application.
244e41f4b71Sopenharmony_ci
245e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ResourceSchedule.DeviceStandby
246e41f4b71Sopenharmony_ci
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci|Name  |Type  | Mandatory  |Description  |
249e41f4b71Sopenharmony_ci| ------------ | ------------ |------------| ------------ |
250e41f4b71Sopenharmony_ci|resourceTypes   | number  | Yes  |Resource types. For details, see [ResourceType](#resourcetype).  |
251e41f4b71Sopenharmony_ci|uid   | number  | Yes  |UID of the application.  |
252e41f4b71Sopenharmony_ci|name   |string   | Yes  | Name of the application. |
253e41f4b71Sopenharmony_ci|duration   | number  | Yes  | Exemption duration.|
254e41f4b71Sopenharmony_ci|reason   |string   | Yes  |  Reason for the request. |
255