• 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
16/**
17 * @file
18 */
19
20import { AsyncCallback, Callback } from './@ohos.base';
21import { WantAgent } from './@ohos.wantAgent';
22import Context from './application/BaseContext';
23
24/**
25 * Manages background tasks.
26 *
27 * @namespace backgroundTaskManager
28 * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
29 * @since 7
30 * @deprecated since 9
31 * @useinstead ohos.resourceschedule.backgroundTaskManager
32 */
33declare namespace backgroundTaskManager {
34  /**
35   * The info of delay suspend.
36   *
37   * @name DelaySuspendInfo
38   * @interface DelaySuspendInfo
39   * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
40   * @since 7
41   * @deprecated since 9
42   * @useinstead ohos.resourceschedule.backgroundTaskManager.DelaySuspendInfo
43   */
44  interface DelaySuspendInfo {
45    /**
46     * The unique identifier of the delay request.
47     *
48     * @type { number }
49     * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
50     * @since 7
51     * @deprecated since 9
52     * @useinstead ohos.resourceschedule.backgroundTaskManager.DelaySuspendInfo
53     */
54    requestId: number;
55    /**
56     * The actual delay duration (ms).
57     *
58     * @type { number }
59     * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
60     * @since 7
61     * @deprecated since 9
62     * @useinstead ohos.resourceschedule.backgroundTaskManager.DelaySuspendInfo
63     */
64    actualDelayTime: number;
65  }
66
67  /**
68   * Cancels delayed transition to the suspended state.
69   *
70   * @param { number } requestId Indicates the identifier of the delay request.
71   * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
72   * @since 7
73   * @deprecated since 9
74   * @useinstead ohos.resourceschedule.backgroundTaskManager.cancelSuspendDelay
75   */
76  function cancelSuspendDelay(requestId: number): void;
77
78  /**
79   * Obtains the remaining time before an application enters the suspended state.
80   *
81   * @param { number } requestId Indicates the identifier of the delay request.
82   * @param { AsyncCallback<number> } callback - The callback of the remaining delay time.
83   * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
84   * @since 7
85   * @deprecated since 9
86   * @useinstead ohos.resourceschedule.backgroundTaskManager.getRemainingDelayTime
87   */
88  function getRemainingDelayTime(requestId: number, callback: AsyncCallback<number>): void;
89
90  /**
91   * Obtains the remaining time before an application enters the suspended state.
92   *
93   * @param { number } requestId Indicates the identifier of the delay request.
94   * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
95   * @since 7
96   * @deprecated since 9
97   * @useinstead ohos.resourceschedule.backgroundTaskManager.getRemainingDelayTime
98   */
99  function getRemainingDelayTime(requestId: number): Promise<number>;
100
101  /**
102   * Requests delayed transition to the suspended state.
103   *
104   * @param { string } reason Indicates the reason for delayed transition to the suspended state.
105   * @param { Callback<void> } callback The callback delay time expired.
106   * @returns { DelaySuspendInfo } Info of delay request
107   * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
108   * @since 7
109   * @deprecated since 9
110   * @useinstead ohos.resourceschedule.backgroundTaskManager.requestSuspendDelay
111   */
112  function requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspendInfo;
113
114  /**
115   * Service ability uses this method to request start running in background.
116   * system will publish a notification related to the this service.
117   *
118   * @permission ohos.permission.KEEP_BACKGROUND_RUNNING
119   * @param { Context } context app running context.
120   * @param { BackgroundMode } bgMode Indicates which background mode to request.
121   * @param { WantAgent } wantAgent Indicates which ability to start when user click the notification bar.
122   * @param { AsyncCallback<void> } callback - The callback of the function.
123   * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
124   * @since 8
125   * @deprecated since 9
126   * @useinstead ohos.resourceschedule.backgroundTaskManager.startBackgroundRunning
127   */
128  function startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent, callback: AsyncCallback<void>): void;
129
130  /**
131   * Service ability uses this method to request start running in background.
132   * system will publish a notification related to the this service.
133   *
134   * @permission ohos.permission.KEEP_BACKGROUND_RUNNING
135   * @param { Context } context app running context.
136   * @param { BackgroundMode } bgMode Indicates which background mode to request.
137   * @param { WantAgent } wantAgent Indicates which ability to start when user click the notification bar.
138   * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
139   * @since 8
140   * @deprecated since 9
141   * @useinstead ohos.resourceschedule.backgroundTaskManager.startBackgroundRunning
142   */
143  function startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent): Promise<void>;
144
145  /**
146   * Service ability uses this method to request stop running in background.
147   *
148   * @param { Context } context - App running context.
149   * @param { AsyncCallback<void> } callback - The callback of the function.
150   * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
151   * @since 8
152   * @deprecated since 9
153   * @useinstead ohos.resourceschedule.backgroundTaskManager.stopBackgroundRunning
154   */
155  function stopBackgroundRunning(context: Context, callback: AsyncCallback<void>): void;
156
157  /**
158   * Service ability uses this method to request stop running in background.
159   *
160   * @param { Context } context - App running context.
161   * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
162   * @since 8
163   * @deprecated since 9
164   * @useinstead ohos.resourceschedule.backgroundTaskManager.stopBackgroundRunning
165   */
166  function stopBackgroundRunning(context: Context): Promise<void>;
167
168  /**
169   * Supported background mode.
170   *
171   * @enum { number }
172   * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
173   * @since 8
174   * @deprecated since 9
175   * @useinstead ohos.resourceschedule.backgroundTaskManager.BackgroundMode
176   */
177  export enum BackgroundMode {
178    /**
179     * data transfer mode
180     *
181     * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
182     * @since 8
183     * @deprecated since 9
184     */
185    DATA_TRANSFER = 1,
186
187    /**
188     * audio playback mode
189     *
190     * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
191     * @since 8
192     * @deprecated since 9
193     */
194    AUDIO_PLAYBACK = 2,
195
196    /**
197     * audio recording mode
198     *
199     * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
200     * @since 8
201     * @deprecated since 9
202     */
203    AUDIO_RECORDING = 3,
204
205    /**
206     * location mode
207     *
208     * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
209     * @since 8
210     * @deprecated since 9
211     */
212    LOCATION = 4,
213
214    /**
215     * bluetooth interaction mode
216     *
217     * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
218     * @since 8
219     * @deprecated since 9
220     */
221    BLUETOOTH_INTERACTION = 5,
222
223    /**
224     * multi-device connection mode
225     *
226     * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
227     * @since 8
228     * @deprecated since 9
229     */
230    MULTI_DEVICE_CONNECTION = 6,
231
232    /**
233     * wifi interaction mode
234     *
235     * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
236     * @systemapi Hide this for inner system use.
237     * @since 8
238     * @deprecated since 9
239     */
240    WIFI_INTERACTION = 7,
241
242    /**
243     * Voice over Internet Phone mode
244     *
245     * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
246     * @systemapi Hide this for inner system use.
247     * @since 8
248     * @deprecated since 9
249     */
250    VOIP = 8,
251
252    /**
253     * background continuous calculate mode, for example 3D render.
254     * only supported in particular device
255     *
256     * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
257     * @since 8
258     * @deprecated since 9
259     */
260    TASK_KEEPING = 9,
261  }
262}
263
264export default backgroundTaskManager;
265