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