• 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. 2. Incorrect parameter types. 3. Parameter verification failed.
41   * @throws { BusinessError } 9800001 - Memory operation failed.
42   * @throws { BusinessError } 9800002 - Parcel operation failed.
43   * @throws { BusinessError } 9800003 - Inner transact failed.
44   * @throws { BusinessError } 9800004 - System service operation failed.
45   * @throws { BusinessError } 18700001 - Caller information verification failed.
46   * @syscap SystemCapability.ResourceSchedule.DeviceStandby
47   * @systemapi Hide this for inner system use.
48   * @since 10
49   */
50  function getExemptedApps(resourceTypes: number, callback: AsyncCallback<Array<ExemptedAppInfo>>): void;
51
52  /**
53   * Returns the information about the specified exempted application.
54   *
55   * @permission ohos.permission.DEVICE_STANDBY_EXEMPTION
56   * @param { number } resourceTypes - the combination of {@link ResourceType} values.
57   * @returns { Promise<Array<ExemptedAppInfo>> } the promise returned by getExemptedApps.
58   * @throws { BusinessError } 201 - Permission denied.
59   * @throws { BusinessError } 202 - Not System App.
60   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
61   * @throws { BusinessError } 9800001 - Memory operation failed.
62   * @throws { BusinessError } 9800002 - Parcel operation failed.
63   * @throws { BusinessError } 9800003 - Inner transact failed.
64   * @throws { BusinessError } 9800004 - System service operation failed.
65   * @throws { BusinessError } 18700001 - Caller information verification failed.
66   * @syscap SystemCapability.ResourceSchedule.DeviceStandby
67   * @systemapi Hide this for inner system use.
68   * @since 10
69   */
70  function getExemptedApps(resourceTypes: number): Promise<Array<ExemptedAppInfo>>;
71
72  /**
73   * Requests exemption resources.
74   *
75   * @permission ohos.permission.DEVICE_STANDBY_EXEMPTION
76   * @param { ResourceRequest } request - requesting or releasing resources.
77   * @throws { BusinessError } 201 - Permission denied.
78   * @throws { BusinessError } 202 - Not System App.
79   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
80   * @throws { BusinessError } 9800001 - Memory operation failed.
81   * @throws { BusinessError } 9800002 - Parcel operation failed.
82   * @throws { BusinessError } 9800003 - Inner transact failed.
83   * @throws { BusinessError } 9800004 - System service operation failed.
84   * @throws { BusinessError } 18700001 - Caller information verification failed.
85   * @syscap SystemCapability.ResourceSchedule.DeviceStandby
86   * @systemapi Hide this for inner system use.
87   * @since 10
88   */
89  function requestExemptionResource(request: ResourceRequest): void;
90
91  /**
92   * Releases exemption resources.
93   *
94   * @permission ohos.permission.DEVICE_STANDBY_EXEMPTION
95   * @param { ResourceRequest } request - requesting or releasing resources.
96   * @throws { BusinessError } 201 - Permission denied.
97   * @throws { BusinessError } 202 - Not System App.
98   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
99   * @throws { BusinessError } 9800001 - Memory operation failed.
100   * @throws { BusinessError } 9800002 - Parcel operation failed.
101   * @throws { BusinessError } 9800003 - Inner transact failed.
102   * @throws { BusinessError } 9800004 - System service operation failed.
103   * @throws { BusinessError } 18700001 - Caller information verification failed.
104   * @syscap SystemCapability.ResourceSchedule.DeviceStandby
105   * @systemapi Hide this for inner system use.
106   * @since 10
107   */
108  function releaseExemptionResource(request: ResourceRequest): void;
109
110  /**
111   * The type of exemption resources requested by the application.
112   *
113   * @enum { number }
114   * @syscap SystemCapability.ResourceSchedule.DeviceStandby
115   * @systemapi Hide this for inner system use.
116   * @since 10
117   */
118  export enum ResourceType {
119    /**
120     * The resource for non-standby network access.
121     *
122     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
123     * @systemapi Hide this for inner system use.
124     * @since 10
125     */
126    NETWORK = 1,
127
128    /**
129     * The resource for non-standby cpu running-lock.
130     *
131     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
132     * @systemapi Hide this for inner system use.
133     * @since 10
134     */
135    RUNNING_LOCK = 1 << 1,
136
137    /**
138     * The resource for non-standby timer.
139     *
140     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
141     * @systemapi Hide this for inner system use.
142     * @since 10
143     */
144    TIMER = 1 << 2,
145
146    /**
147     * The resource for non-standby workscheduler.
148     *
149     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
150     * @systemapi Hide this for inner system use.
151     * @since 10
152     */
153    WORK_SCHEDULER = 1 << 3,
154
155    /**
156     * The resource for non-standby automatic synchronization.
157     *
158     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
159     * @systemapi Hide this for inner system use.
160     * @since 10
161     */
162    AUTO_SYNC = 1 << 4,
163
164    /**
165     * The resource for non-standby push-kit.
166     *
167     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
168     * @systemapi Hide this for inner system use.
169     * @since 10
170     */
171    PUSH = 1 << 5,
172
173    /**
174     * The resource for non-standby freezing application.
175     *
176     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
177     * @systemapi Hide this for inner system use.
178     * @since 10
179     */
180    FREEZE = 1 << 6
181  }
182
183  /**
184   * Information about an exempted application.
185   *
186   * @interface ExemptedAppInfo
187   * @syscap SystemCapability.ResourceSchedule.DeviceStandby
188   * @systemapi Hide this for inner system use.
189   * @since 10
190   */
191  export interface ExemptedAppInfo {
192    /**
193     * The set of resource types that an application requests.
194     *
195     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
196     * @systemapi Hide this for inner system use.
197     * @since 10
198     */
199    resourceTypes: number;
200
201    /**
202     * The application name.
203     *
204     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
205     * @systemapi Hide this for inner system use.
206     * @since 10
207     */
208    name: string;
209
210    /**
211     * The exemption duration.
212     *
213     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
214     * @systemapi Hide this for inner system use.
215     * @since 10
216     */
217    duration: number;
218  }
219
220  /**
221   * The request of standby resources.
222   *
223   * @interface ResourceRequest
224   * @syscap SystemCapability.ResourceSchedule.DeviceStandby
225   * @systemapi Hide this for inner system use.
226   * @since 10
227   */
228  export interface ResourceRequest {
229    /**
230     * The set of resource types that an application requests.
231     *
232     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
233     * @systemapi Hide this for inner system use.
234     * @since 10
235     */
236    resourceTypes: number;
237
238    /**
239     * The application uid.
240     *
241     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
242     * @systemapi Hide this for inner system use.
243     * @since 10
244     */
245    uid: number;
246
247    /**
248     * The application name.
249     *
250     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
251     * @systemapi Hide this for inner system use.
252     * @since 10
253     */
254    name: string;
255
256    /**
257     * The exemption duration.
258     *
259     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
260     * @systemapi Hide this for inner system use.
261     * @since 10
262     */
263    duration: number;
264
265    /**
266     * The reason for the request.
267     *
268     * @syscap SystemCapability.ResourceSchedule.DeviceStandby
269     * @systemapi Hide this for inner system use.
270     * @since 10
271     */
272    reason: string;
273  }
274}
275
276export default deviceStandby;