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