• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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
16import {AsyncCallback} from './@ohos.base';
17
18/**
19 * Work scheduler interface.
20 *
21 * @namespace workScheduler
22 * @StageModelOnly
23 * @since 9
24 */
25declare namespace workScheduler {
26    /**
27     * The info of work.
28     *
29     * @interface WorkInfo
30     * @syscap SystemCapability.ResourceSchedule.WorkScheduler
31     * @StageModelOnly
32     * @since 9
33     */
34    export interface WorkInfo {
35        /**
36         * The id of the current work.
37         *
38         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
39         * @since 9
40         */
41        workId: number;
42        /**
43         * The bundle name of the current work.
44         *
45         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
46         * @since 9
47         */
48        bundleName: string;
49        /**
50         * The ability name of the current work.
51         *
52         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
53         * @since 9
54         */
55        abilityName: string;
56        /**
57         * Whether the current work will be saved.
58         *
59         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
60         * @since 9
61         */
62        isPersisted?: boolean;
63        /**
64         * The network type of the current work.
65         *
66         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
67         * @since 9
68         */
69        networkType?: NetworkType;
70        /**
71         * Whether a charging state has been set for triggering the work.
72         *
73         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
74         * @since 9
75         */
76        isCharging?: boolean;
77        /**
78         * The charger type based on which the work is triggered.
79         *
80         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
81         * @since 9
82         */
83        chargerType?: ChargingType;
84        /**
85         * The battery level for triggering a work.
86         *
87         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
88         * @since 9
89         */
90        batteryLevel?: number;
91        /**
92         * The battery status for triggering a work.
93         *
94         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
95         * @since 9
96         */
97        batteryStatus?: BatteryStatus;
98        /**
99         * Whether a storage state has been set for triggering the work.
100         *
101         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
102         * @since 9
103         */
104        storageRequest?: StorageRequest;
105        /**
106         * The interval at which the work is repeated.
107         *
108         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
109         * @since 9
110         */
111        repeatCycleTime?: number;
112        /**
113         * Whether the work has been set to repeat at the specified interval.
114         *
115         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
116         * @since 9
117         */
118        isRepeat?: boolean;
119        /**
120         * The repeat of the current work.
121         *
122         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
123         * @since 9
124         */
125        repeatCount?: number;
126        /**
127         * Whether the device deep idle state has been set for triggering the work.
128         *
129         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
130         * @since 9
131         */
132        isDeepIdle?: boolean;
133        /**
134         * The idle wait time based on which the work is triggered.
135         *
136         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
137         * @since 9
138         */
139        idleWaitTime?: number;
140        /**
141         * The parameters of the work. The value is only supported basic type(Number, String, Boolean).
142         *
143         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
144         * @since 9
145         */
146        parameters?: {[key: string]: number | string | boolean};
147    }
148
149    /**
150     * Add a work to the queue. A work can be executed only when it meets the preset triggering condition
151     * <p> and complies with the rules of work scheduler manager. </p>
152     *
153     * @param { WorkInfo } work - The info of work.
154     * @throws { BusinessError } 401 - Parameter error.
155     * @throws { BusinessError } 9700001 - Memory operation failed.
156     * @throws { BusinessError } 9700002 - Parcel operation failed.
157     * @throws { BusinessError } 9700003 - System service operation failed.
158     * @throws { BusinessError } 9700004 - Check workInfo failed.
159     * @throws { BusinessError } 9700005 - StartWork failed.
160     * @syscap SystemCapability.ResourceSchedule.WorkScheduler
161     * @StageModelOnly
162     * @since 9
163     */
164    function startWork(work: WorkInfo): void;
165
166    /**
167     * Stop a work.
168     *
169     * @param { WorkInfo } work - The info of work.
170     * @param { boolean } needCancel - True if need to be canceled after being stopped, otherwise false.
171     * @throws { BusinessError } 401 - Parameter error.
172     * @throws { BusinessError } 9700001 - Memory operation failed.
173     * @throws { BusinessError } 9700002 - Parcel operation failed.
174     * @throws { BusinessError } 9700003 - System service operation failed.
175     * @throws { BusinessError } 9700004 - Check workInfo failed.
176     * @syscap SystemCapability.ResourceSchedule.WorkScheduler
177     * @StageModelOnly
178     * @since 9
179     */
180    function stopWork(work: WorkInfo, needCancel?: boolean): void;
181
182    /**
183     * Obtains the work info of the wordId.
184     *
185     * @param { number } workId - The id of work.
186     * @param { AsyncCallback<WorkInfo> } callback - The callback of the function.
187     * @throws { BusinessError } 401 - Parameter error.
188     * @throws { BusinessError } 9700001 - Memory operation failed.
189     * @throws { BusinessError } 9700002 - Parcel operation failed.
190     * @throws { BusinessError } 9700003 - System service operation failed.
191     * @throws { BusinessError } 9700004 - Check workInfo failed.
192     * @syscap SystemCapability.ResourceSchedule.WorkScheduler
193     * @StageModelOnly
194     * @since 9
195     */
196    function getWorkStatus(workId: number, callback: AsyncCallback<WorkInfo>): void;
197
198    /**
199     * Obtains the work info of the wordId.
200     *
201     * @param { number } workId - The id of work.
202     * @returns { Promise<WorkInfo> } The promise returned by the function.
203     * @throws { BusinessError } 401 - Parameter error.
204     * @throws { BusinessError } 9700001 - Memory operation failed.
205     * @throws { BusinessError } 9700002 - Parcel operation failed.
206     * @throws { BusinessError } 9700003 - System service operation failed.
207     * @throws { BusinessError } 9700004 - Check workInfo failed.
208     * @syscap SystemCapability.ResourceSchedule.WorkScheduler
209     * @StageModelOnly
210     * @since 9
211     */
212    function getWorkStatus(workId: number): Promise<WorkInfo>;
213
214    /**
215     * Get all works of the calling application.
216     *
217     * @param { AsyncCallback<void> } callback - The callback of the function.
218     * @returns { Array<WorkInfo> } the work info list.
219     * @throws { BusinessError } 401 - Parameter error.
220     * @throws { BusinessError } 9700001 - Memory operation failed.
221     * @throws { BusinessError } 9700002 - Parcel operation failed.
222     * @throws { BusinessError } 9700003 - System service operation failed.
223     * @syscap SystemCapability.ResourceSchedule.WorkScheduler
224     * @StageModelOnly
225     * @since 9
226     */
227    function obtainAllWorks(callback: AsyncCallback<void>): Array<WorkInfo>;
228
229    /**
230     * Get all works of the calling application.
231     *
232     * @returns { Promise<Array<WorkInfo>> } The work info list.
233     * @throws { BusinessError } 401 - Parameter error.
234     * @throws { BusinessError } 9700001 - Memory operation failed.
235     * @throws { BusinessError } 9700002 - Parcel operation failed.
236     * @throws { BusinessError } 9700003 - System service operation failed.
237     * @syscap SystemCapability.ResourceSchedule.WorkScheduler
238     * @StageModelOnly
239     * @since 9
240     */
241    function obtainAllWorks(): Promise<Array<WorkInfo>>;
242
243    /**
244     * Stop all and clear all works of the calling application.
245     *
246     * @throws { BusinessError } 401 - Parameter error.
247     * @throws { BusinessError } 9700001 - Memory operation failed.
248     * @throws { BusinessError } 9700002 - Parcel operation failed.
249     * @throws { BusinessError } 9700003 - System service operation failed.
250     * @syscap SystemCapability.ResourceSchedule.WorkScheduler
251     * @StageModelOnly
252     * @since 9
253     */
254    function stopAndClearWorks(): void;
255
256    /**
257     * Check whether last work running is timeout. The interface is for repeating work.
258     *
259     * @param { number } workId - The id of work.
260     * @param { AsyncCallback<void> } callback - The callback of the function.
261     * @returns { boolean } true if last work running is timeout, otherwise false.
262     * @throws { BusinessError } 401 - Parameter error.
263     * @throws { BusinessError } 9700001 - Memory operation failed.
264     * @throws { BusinessError } 9700002 - Parcel operation failed.
265     * @throws { BusinessError } 9700003 - System service operation failed.
266     * @throws { BusinessError } 9700004 - Check workInfo failed.
267     * @syscap SystemCapability.ResourceSchedule.WorkScheduler
268     * @StageModelOnly
269     * @since 9
270     */
271    function isLastWorkTimeOut(workId: number, callback: AsyncCallback<void>): boolean;
272
273    /**
274     * Check whether last work running is timeout. The interface is for repeating work.
275     *
276     * @param { number } workId - The id of work.
277     * @returns { Promise<boolean> } True if last work running is timeout, otherwise false.
278     * @throws { BusinessError } 401 - Parameter error.
279     * @throws { BusinessError } 9700001 - Memory operation failed.
280     * @throws { BusinessError } 9700002 - Parcel operation failed.
281     * @throws { BusinessError } 9700003 - System service operation failed.
282     * @throws { BusinessError } 9700004 - Check workInfo failed.
283     * @syscap SystemCapability.ResourceSchedule.WorkScheduler
284     * @StageModelOnly
285     * @since 9
286     */
287    function isLastWorkTimeOut(workId: number): Promise<boolean>;
288
289    /**
290     * Describes network type.
291     *
292     * @name NetworkType
293     * @enum { number }
294     * @syscap SystemCapability.ResourceSchedule.WorkScheduler
295     * @StageModelOnly
296     * @since 9
297    */
298    export enum NetworkType {
299        /**
300         * Describes any network connection.
301         *
302         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
303         * @since 9
304         */
305        NETWORK_TYPE_ANY = 0,
306        /**
307         * Describes a mobile network connection.
308         *
309         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
310         * @since 9
311         */
312        NETWORK_TYPE_MOBILE,
313        /**
314         * Describes a wifi network connection.
315         *
316         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
317         * @since 9
318         */
319        NETWORK_TYPE_WIFI,
320        /**
321         * Describes a bluetooth network connection.
322         *
323         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
324         * @since 9
325         */
326        NETWORK_TYPE_BLUETOOTH,
327        /**
328         * Describes a wifi p2p network connection.
329         *
330         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
331         * @since 9
332         */
333        NETWORK_TYPE_WIFI_P2P,
334        /**
335         * Describes a wifi wire network connection.
336         *
337         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
338         * @since 9
339         */
340        NETWORK_TYPE_ETHERNET
341    }
342
343    /**
344     * Describes charging type.
345     *
346     * @name ChargingType
347     * @enum { number }
348     * @syscap SystemCapability.ResourceSchedule.WorkScheduler
349     * @StageModelOnly
350     * @since 9
351    */
352    export enum ChargingType {
353        /**
354         * Describes any charger is connected.
355         *
356         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
357         * @since 9
358         */
359        CHARGING_PLUGGED_ANY = 0,
360        /**
361         * Describes ac charger is connected.
362         *
363         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
364         * @since 9
365         */
366        CHARGING_PLUGGED_AC,
367        /**
368         * Describes usb charger is connected.
369         *
370         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
371         * @since 9
372         */
373        CHARGING_PLUGGED_USB,
374        /**
375         * Describes wireless charger is connected.
376         *
377         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
378         * @since 9
379         */
380        CHARGING_PLUGGED_WIRELESS
381    }
382
383    /**
384     * Describes the battery status.
385     *
386     * @name BatteryStatus
387     * @enum { number }
388     * @syscap SystemCapability.ResourceSchedule.WorkScheduler
389     * @StageModelOnly
390     * @since 9
391    */
392    export enum BatteryStatus {
393        /**
394         * Describes battery status is to low.
395         *
396         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
397         * @since 9
398         */
399        BATTERY_STATUS_LOW = 0,
400        /**
401         * Describes battery status is to ok.
402         *
403         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
404         * @since 9
405         */
406        BATTERY_STATUS_OKAY,
407        /**
408         * Describes battery status is to low or ok.
409         *
410         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
411         * @since 9
412         */
413        BATTERY_STATUS_LOW_OR_OKAY
414    }
415
416    /**
417     * Describes the storage request.
418     *
419     * @name StorageRequest
420     * @enum { number }
421     * @syscap SystemCapability.ResourceSchedule.WorkScheduler
422     * @StageModelOnly
423     * @since 9
424    */
425    export enum StorageRequest {
426        /**
427         * Describes storage is to low.
428         *
429         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
430         * @since 9
431         */
432        STORAGE_LEVEL_LOW = 0,
433        /**
434         * Describes storage is to ok.
435         *
436         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
437         * @since 9
438         */
439        STORAGE_LEVEL_OKAY,
440        /**
441         * Describes storage is to low or ok.
442         *
443         * @syscap SystemCapability.ResourceSchedule.WorkScheduler
444         * @since 9
445         */
446        STORAGE_LEVEL_LOW_OR_OKAY
447    }
448}
449export default workScheduler;