• 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"
17import { AppStateDataClass as _AppStateData } from "./application/AppStateData"
18import { ProcessRunningInfo } from "./application/ProcessRunningInfo"
19import { AppStateDataClass as _AbilityStateData } from "./application/AppStateData"
20import { ApplicationStateObserverClass as _ApplicationStateObserver } from "./application/ApplicationStateObserver"
21import { ProcessDataClass as _ProcessData } from "./application/ProcessData"
22
23export function mockAppManager() {
24  const appManager = {
25    registerApplicationStateObserver: function (...args) {
26      console.warn('appManager.registerApplicationStateObserver interface mocked in the Previewer. How this interface works on the' +
27        ' Previewer may be different from that on a real device.');
28      return paramMock.paramNumberMock;
29    },
30    unregisterApplicationStateObserver: function (...args) {
31      console.warn('appManager.unregisterApplicationStateObserver interface mocked in the Previewer. How this interface works on the' +
32        ' Previewer may be different from that on a real device.');
33      const len = args.length;
34      if (typeof args[len - 1] === 'function') {
35        args[len - 1].call(this, paramMock.businessErrorMock);
36      } else {
37        return new Promise((resolve) => {
38          resolve();
39        });
40      }
41    },
42    getForegroundApplications: function (...args) {
43      console.warn('appManager.getForegroundApplications interface mocked in the Previewer. How this interface works on the' +
44        ' Previewer may be different from that on a real device.');
45      const len = args.length;
46      if (typeof args[len - 1] === 'function') {
47        args[len - 1].call(this, paramMock.businessErrorMock, [new _AppStateData()]);
48      } else {
49        return new Promise((resolve) => {
50          resolve([new _AppStateData()]);
51        });
52      }
53    },
54    killProcessWithAccount: function (...args) {
55      console.warn('appManager.killProcessWithAccount interface mocked in the Previewer. How this interface works on the' +
56        ' Previewer may be different from that on a real device.');
57      const len = args.length;
58      if (typeof args[len - 1] === 'function') {
59        args[len - 1].call(this, paramMock.businessErrorMock);
60      } else {
61        return new Promise((resolve) => {
62          resolve();
63        });
64      }
65    },
66    isRunningInStabilityTest: function (...args) {
67      console.warn('appManager.isRunningInStabilityTest interface mocked in the Previewer. How this interface works on the' +
68        ' Previewer may be different from that on a real device.');
69      const len = args.length;
70      if (typeof args[len - 1] === 'function') {
71        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
72      } else {
73        return new Promise((resolve) => {
74          resolve(paramMock.paramBooleanMock);
75        });
76      }
77    },
78    getProcessRunningInfos: function (...args) {
79      console.warn('appManager.getProcessRunningInfos interface mocked in the Previewer. How this interface works on the' +
80        ' Previewer may be different from that on a real device.');
81      const len = args.length;
82      if (typeof args[len - 1] === 'function') {
83        args[len - 1].call(this, paramMock.businessErrorMock, [ProcessRunningInfo]);
84      } else {
85        return new Promise((resolve) => {
86          resolve([ProcessRunningInfo]);
87        });
88      }
89    },
90    killProcessesByBundleName: function (...args) {
91      console.warn('appManager.killProcessesByBundleName interface mocked in the Previewer. How this interface works on the' +
92        ' Previewer may be different from that on a real device.');
93      const len = args.length;
94      if (typeof args[len - 1] === 'function') {
95        args[len - 1].call(this, paramMock.businessErrorMock);
96      } else {
97        return new Promise((resolve) => {
98          resolve();
99        });
100      }
101    },
102    clearUpApplicationData: function (...args) {
103      console.warn('appManager.clearUpApplicationData interface mocked in the Previewer. How this interface works on the' +
104        ' Previewer may be different from that on a real device.');
105      const len = args.length;
106      if (typeof args[len - 1] === 'function') {
107        args[len - 1].call(this, paramMock.businessErrorMock);
108      } else {
109        return new Promise((resolve) => {
110          resolve();
111        });
112      }
113    },
114    isRamConstrainedDevice: function (...args) {
115      console.warn('appManager.isRamConstrainedDevice interface mocked in the Previewer. How this interface works on the' +
116        ' Previewer may be different from that on a real device.');
117      const len = args.length;
118      if (typeof args[len - 1] === 'function') {
119        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
120      } else {
121        return new Promise((resolve) => {
122          resolve(paramMock.paramBooleanMock);
123        });
124      }
125    },
126    getAppMemorySize: function (...args) {
127      console.warn('appManager.getAppMemorySize interface mocked in the Previewer. How this interface works on the' +
128        ' Previewer may be different from that on a real device.');
129      const len = args.length;
130      if (typeof args[len - 1] === 'function') {
131        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
132      } else {
133        return new Promise((resolve) => {
134          resolve(paramMock.paramNumberMock);
135        });
136      }
137    },
138    AbilityStateData: new _AbilityStateData(),
139    AppStateData: new _AppStateData(),
140    ApplicationStateObserver: new _ApplicationStateObserver(),
141    ProcessData: new _ProcessData(),
142    ProcessRunningInfo
143  }
144  return appManager
145}