• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * @file
18 * @kit BackgroundTasksKit
19 */
20
21import { AsyncCallback } from './@ohos.base';
22
23/**
24 * Provides methods for managing device standby,
25 * including the methods for querying standby status and exemption list.
26 *
27 * @namespace deviceStandby
28 * @since 10
29 */
30declare namespace deviceStandby {
31
32  /**
33   * Returns the information about the specified exempted application.
34   *
35   * @permission ohos.permission.DEVICE_STANDBY_EXEMPTION
36   * @param { number } resourceTypes - the combination of {@link ResourceType} values.
37   * @param { AsyncCallback<Array<ExemptedAppInfo>> } callback - the callback of getExemptedApps.
38   * @throws { BusinessError } 201 - Permission denied.
39   * @throws { BusinessError } 202 - Not System App.
40   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
41   * 2. Incorrect parameter types. 3. Parameter verification failed.
42   * @throws { BusinessError } 9800001 - Memory operation failed.
43   * @throws { BusinessError } 9800002 - Parcel operation failed.
44   * @throws { BusinessError } 9800003 - Inner transact failed.
45   * @throws { BusinessError } 9800004 - System service operation failed.
46   * @throws { BusinessError } 18700001 - Caller information verification failed.
47   * @syscap SystemCapability.ResourceSchedule.DeviceStandby
48   * @systemapi Hide this for inner system use.
49   * @since 10
50   */
51  function getExemptedApps(resourceTypes: number, callback: AsyncCallback<Array<ExemptedAppInfo>>): void;
52
53  /**
54   * Returns the information about the specified exempted application.
55   *
56   * @permission ohos.permission.DEVICE_STANDBY_EXEMPTION
57   * @param { number } resourceTypes - the combination of {@link ResourceType} values.
58   * @returns { Promise<Array<ExemptedAppInfo>> } the promise returned by getExemptedApps.
59   * @throws { BusinessError } 201 - Permission denied.
60   * @throws { BusinessError } 202 - Not System App.
61   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
62   * 2. Incorrect parameter types. 3. Parameter verification failed.
63   * @throws { BusinessError } 9800001 - Memory operation failed.
64   * @throws { BusinessError } 9800002 - Parcel operation failed.
65   * @throws { BusinessError } 9800003 - Inner transact failed.
66   * @throws { BusinessError } 9800004 - System service operation failed.
67   * @throws { BusinessError } 18700001 - Caller information verification failed.
68   * @syscap SystemCapability.ResourceSchedule.DeviceStandby
69   * @systemapi Hide this for inner system use.
70   * @since 10
71   */
72  function getExemptedApps(resourceTypes: number): Promise<Array<ExemptedAppInfo>>;
73
74  /**
75   * Requests exemption resources.
76   *
77   * @permission ohos.permission.DEVICE_STANDBY_EXEMPTION
78   * @param { ResourceRequest } request - requesting or releasing resources.
79   * @throws { BusinessError } 201 - Permission denied.
80   * @throws { BusinessError } 202 - Not System App.
81   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
82   * 2. Incorrect parameter types. 3. Parameter verification failed.
83   * @throws { BusinessError } 9800001 - Memory operation failed.
84   * @throws { BusinessError } 9800002 - Parcel operation failed.
85   * @throws { BusinessError } 9800003 - Inner transact failed.
86   * @throws { BusinessError } 9800004 - System service operation failed.
87   * @throws { BusinessError } 18700001 - Caller information verification failed.
88   * @syscap SystemCapability.ResourceSchedule.DeviceStandby
89   * @systemapi Hide this for inner system use.
90   * @since 10
91   */
92  function requestExemptionResource(request: ResourceRequest): void;
93
94  /**
95   * Releases exemption resources.
96   *
97   * @permission ohos.permission.DEVICE_STANDBY_EXEMPTION
98   * @param { ResourceRequest } request - requesting or releasing resources.
99   * @throws { BusinessError } 201 - Permission denied.
100   * @throws { BusinessError } 202 - Not System App.
101   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
102   * 2. Incorrect parameter types. 3. Parameter verification failed.
103   * @throws { BusinessError } 9800001 - Memory operation failed.
104   * @throws { BusinessError } 9800002 - Parcel operation failed.
105   * @throws { BusinessError } 9800003 - Inner transact failed.
106   * @throws { BusinessError } 9800004 - System service operation failed.
107   * @throws { BusinessError } 18700001 - Caller information verification failed.
108   * @syscap SystemCapability.ResourceSchedule.DeviceStandby
109   * @systemapi Hide this for inner system use.
110   * @since 10
111   */
112  function releaseExemptionResource(request: ResourceRequest): void;
113
114  /**
115   * The type of exemption resources requested by the application.
116   *
117   * @enum { number }
118   * @syscap SystemCapability.ResourceSchedule.DeviceStandby
119   * @systemapi Hide this for inner system use.
120   * @since 10
121   */
122  export enum ResourceType {
123    /**
124     * The resource for non-standby network access.
125     *
126     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
127     * @systemapi Hide this for inner system use.
128     * @since 10
129     */
130    NETWORK = 1,
131
132    /**
133     * The resource for non-standby cpu running-lock.
134     *
135     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
136     * @systemapi Hide this for inner system use.
137     * @since 10
138     */
139    RUNNING_LOCK = 1 << 1,
140
141    /**
142     * The resource for non-standby timer.
143     *
144     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
145     * @systemapi Hide this for inner system use.
146     * @since 10
147     */
148    TIMER = 1 << 2,
149
150    /**
151     * The resource for non-standby workscheduler.
152     *
153     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
154     * @systemapi Hide this for inner system use.
155     * @since 10
156     */
157    WORK_SCHEDULER = 1 << 3,
158
159    /**
160     * The resource for non-standby automatic synchronization.
161     *
162     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
163     * @systemapi Hide this for inner system use.
164     * @since 10
165     */
166    AUTO_SYNC = 1 << 4,
167
168    /**
169     * The resource for non-standby push-kit.
170     *
171     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
172     * @systemapi Hide this for inner system use.
173     * @since 10
174     */
175    PUSH = 1 << 5,
176
177    /**
178     * The resource for non-standby freezing application.
179     *
180     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
181     * @systemapi Hide this for inner system use.
182     * @since 10
183     */
184    FREEZE = 1 << 6
185  }
186
187  /**
188   * Information about an exempted application.
189   *
190   * @interface ExemptedAppInfo
191   * @syscap SystemCapability.ResourceSchedule.DeviceStandby
192   * @systemapi Hide this for inner system use.
193   * @since 10
194   */
195  export interface ExemptedAppInfo {
196    /**
197     * The set of resource types that an application requests.
198     *
199     * @type { number }
200     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
201     * @systemapi Hide this for inner system use.
202     * @since 10
203     */
204    resourceTypes: number;
205
206    /**
207     * The application name.
208     *
209     * @type { string }
210     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
211     * @systemapi Hide this for inner system use.
212     * @since 10
213     */
214    name: string;
215
216    /**
217     * The exemption duration.
218     *
219     * @type { number }
220     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
221     * @systemapi Hide this for inner system use.
222     * @since 10
223     */
224    duration: number;
225  }
226
227  /**
228   * The request of standby resources.
229   *
230   * @interface ResourceRequest
231   * @syscap SystemCapability.ResourceSchedule.DeviceStandby
232   * @systemapi Hide this for inner system use.
233   * @since 10
234   */
235  export interface ResourceRequest {
236    /**
237     * The set of resource types that an application requests.
238     *
239     * @type { number }
240     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
241     * @systemapi Hide this for inner system use.
242     * @since 10
243     */
244    resourceTypes: number;
245
246    /**
247     * The application uid.
248     *
249     * @type { number }
250     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
251     * @systemapi Hide this for inner system use.
252     * @since 10
253     */
254    uid: number;
255
256    /**
257     * The application name.
258     *
259     * @type { string }
260     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
261     * @systemapi Hide this for inner system use.
262     * @since 10
263     */
264    name: string;
265
266    /**
267     * The exemption duration.
268     *
269     * @type { number }
270     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
271     * @systemapi Hide this for inner system use.
272     * @since 10
273     */
274    duration: number;
275
276    /**
277     * The reason for the request.
278     *
279     * @type { string }
280     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
281     * @systemapi Hide this for inner system use.
282     * @since 10
283     */
284    reason: string;
285  }
286}
287
288export default deviceStandby;