• 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 { paramMock } from "../utils"
17
18export function mockBackgroundTaskManager() {
19    const DelaySuspendInfoMock = {
20        requestId: '[PC preview] unknown requestId',
21        actualDelayTime: '[PC preview] unknown actualDelayTime',
22    };
23    const backgroundTaskManager = {
24        BackgroundMode : {
25            DATA_TRANSFER: 1,
26            AUDIO_PLAYBACK: 2,
27            AUDIO_RECORDING: 3,
28            LOCATION: 4,
29            BLUETOOTH_INTERACTION: 5,
30            MULTI_DEVICE_CONNECTION: 6,
31            WIFI_INTERACTION: 7,
32            VOIP: 8,
33            TASK_KEEPING: 9
34        },
35        requestSuspendDelay: function (...args) {
36            console.warn("backgroundTaskManager.requestSuspendDelay interface mocked in the Previewer. How this interface works on the" +
37                " Previewer may be different from that on a real device.")
38            const len = args.length;
39            if (typeof args[len - 1] === 'function') {
40                args[len - 1].call(this, paramMock.businessErrorMock)
41                return DelaySuspendInfoMock;
42            }
43        },
44        cancelSuspendDelay: function (...args) {
45            console.warn("backgroundTaskManager.cancelSuspendDelay interface mocked in the Previewer. How this interface works on the" +
46                " Previewer may be different from that on a real device.")
47        },
48        getRemainingDelayTime: function (...args) {
49            console.warn("backgroundTaskManager.getRemainingDelayTime interface mocked in the Previewer. How this interface works on the" +
50                " Previewer may be different from that on a real device.")
51            const len = args.length
52            if (typeof args[len - 1] === 'function') {
53                args[len - 1].call(this, paramMock.businessErrorMock, DelaySuspendInfoMock.actualDelayTime)
54            } else {
55                return new Promise((resolve) => {
56                    resolve(DelaySuspendInfoMock.actualDelayTime)
57                });
58            }
59        },
60        startBackgroundRunning: function (...args) {
61            console.warn("backgroundTaskManager.startBackgroundRunning interface mocked in the Previewer. How this interface works on the" +
62                " Previewer may be different from that on a real device.")
63            const len = args.length
64            if (typeof args[len - 1] === 'function') {
65                args[len - 1].call(this, paramMock.businessErrorMock);
66            } else {
67                return new Promise((resolve) => {
68                    resolve();
69                });
70            }
71        },
72        stopBackgroundRunning: function (...args) {
73            console.warn("backgroundTaskManager.stopBackgroundRunning interface mocked in the Previewer. How this interface works on the" +
74                " Previewer may be different from that on a real device.")
75            const len = args.length
76            if (typeof args[len - 1] === 'function') {
77                args[len - 1].call(this, paramMock.businessErrorMock);
78            } else {
79                return new Promise((resolve) => {
80                    resolve();
81                });
82            }
83        }
84    };
85    return backgroundTaskManager;
86}