• 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 DelaySuspendInfo = {
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        ResourceType : {
36            CPU: 1,
37            COMMON_EVENT: 1 << 1,
38            TIMER: 1 << 2,
39            WORK_SCHEDULER: 1 << 3,
40            BLUETOOTH: 1 << 4,
41            GPS: 1 << 5,
42            AUDIO: 1 << 6,
43        },
44        EfficiencyResourcesRequest : {
45            resourceTypes: '[PC preview] unknown resourceTypes',
46            isApply: '[PC preview] unknown isApply',
47            timeOut: '[PC preview] unknown timeOut',
48            isPersist: '[PC preview] unknown isPersist',
49            isProcess: '[PC preview] unknown isProcess',
50            reason: '[PC preview] unknown reason',
51        },
52        requestSuspendDelay: function (...args) {
53            console.warn("backgroundTaskManager.requestSuspendDelay interface mocked in the Previewer. How this interface works on the" +
54                " Previewer may be different from that on a real device.")
55            const len = args.length;
56            if (typeof args[len - 1] === 'function') {
57                args[len - 1].call(this, paramMock.businessErrorMock)
58                return DelaySuspendInfo;
59            }
60        },
61        cancelSuspendDelay: function (...args) {
62            console.warn("backgroundTaskManager.cancelSuspendDelay interface mocked in the Previewer. How this interface works on the" +
63                " Previewer may be different from that on a real device.")
64        },
65        getRemainingDelayTime: function (...args) {
66            console.warn("backgroundTaskManager.getRemainingDelayTime interface mocked in the Previewer. How this interface works on the" +
67                " Previewer may be different from that on a real device.")
68            const len = args.length
69            if (typeof args[len - 1] === 'function') {
70                args[len - 1].call(this, paramMock.businessErrorMock, DelaySuspendInfo.actualDelayTime)
71            } else {
72                return new Promise((resolve) => {
73                    resolve(DelaySuspendInfo.actualDelayTime)
74                });
75            }
76        },
77        startBackgroundRunning: function (...args) {
78            console.warn("backgroundTaskManager.startBackgroundRunning interface mocked in the Previewer. How this interface works on the" +
79                " Previewer may be different from that on a real device.")
80            const len = args.length
81            if (typeof args[len - 1] === 'function') {
82                args[len - 1].call(this, paramMock.businessErrorMock);
83            } else {
84                return new Promise((resolve) => {
85                    resolve();
86                });
87            }
88        },
89        stopBackgroundRunning: function (...args) {
90            console.warn("backgroundTaskManager.stopBackgroundRunning interface mocked in the Previewer. How this interface works on the" +
91                " Previewer may be different from that on a real device.")
92            const len = args.length
93            if (typeof args[len - 1] === 'function') {
94                args[len - 1].call(this, paramMock.businessErrorMock);
95            } else {
96                return new Promise((resolve) => {
97                    resolve();
98                });
99            }
100        },
101        applyEfficiencyResources: function(...args) {
102            console.warn("backgroundTaskManager.applyEfficiencyResources interface mocked in the Previewer. How this interface works on the" +
103                " Previewer may be different from that on a real device.")
104            return paramMock.paramBooleanMock;
105        },
106        resetAllEfficiencyResources: function(...args) {
107            console.warn("backgroundTaskManager.resetAllEfficiencyResources interface mocked in the Previewer. How this interface works on the" +
108                " Previewer may be different from that on a real device.")
109        }
110    };
111    return backgroundTaskManager;
112}