• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import {paramMock} from "./utils"
2
3export function mockDeviceManager() {
4    const deviceInfoMock = {
5        deviceId: "[PC Preview] unknow mNetworkId",
6        deviceName: "[PC Preview] unknow mDeviceName",
7        deviceType: 0x0E
8    }
9    const deviceStateChangeMock = {
10        action: 0,
11        device: deviceInfoMock
12    }
13    const deviceManagerMock = {
14        release: function () {
15            console.warn("DeviceManager.release interface mocked in the Previewer. How this interface works on the Previewer" +
16                " may be different from that on a real device.")
17            return
18        },
19        getTrustedDeviceListSync: function () {
20            console.warn("DeviceManager.getTrustedDeviceListSync interface mocked in the Previewer. How this interface works on the" +
21                " Previewer may be different from that on a real device.")
22            var array = new Array();
23            array.push(deviceInfoMock);
24            return array ;
25        },
26        getTrustedDeviceList: function (...args) {
27            console.warn("DeviceManager.getTrustedDeviceList interface mocked in the Previewer. How this interface works on the" +
28                " Previewer may be different from that on a real device.")
29            var array = new Array();
30            array.push(deviceInfoMock);
31            const len = args.length
32            if (typeof args[len - 1] === 'function') {
33                args[len - 1].call(this, paramMock.businessErrorMock, array);
34            } else {
35                return new Promise((resolve, reject) => {
36                    resolve(array);
37                })
38            }
39        },
40        getLocalDeviceInfoSync: function () {
41            console.warn("DeviceManager.getLocalDeviceInfoSync interface mocked in the Previewer. How this interface works on the" +
42                " Previewer may be different from that on a real device.")
43            return deviceInfoMock;
44        },
45        getLocalDeviceInfo: function (...args) {
46            console.warn("DeviceManager.getLocalDeviceInfo interface mocked in the Previewer. How this interface works on the" +
47                " Previewer may be different from that on a real device.")
48            const len = args.length
49            if (typeof args[len - 1] === 'function') {
50                args[len - 1].call(this, paramMock.businessErrorMock, deviceInfoMock);
51            } else {
52                return new Promise((resolve, reject) => {
53                    resolve(deviceInfoMock);
54                })
55            }
56        },
57        on: function (...args) {
58            console.warn("DeviceManager.on interface mocked in the Previewer. How this interface works on the Previewer may" +
59                " be different from that on a real device.")
60            const len = args.length
61            if (typeof args[len - 1] === 'function') {
62                if (args[0] == 'deviceStateChange') {
63                    args[len - 1].call(this, paramMock.businessErrorMock, deviceStateChangeMock);
64                } else {
65                    args[len - 1].call(this);
66                }
67            }
68        },
69        off: function (...args) {
70            console.warn("DeviceManager.off interface mocked in the Previewer. How this interface works on the Previewer may" +
71                " be different from that on a real device.")
72        }
73    }
74    global.systemplugin.distributedHardware = global.systemplugin.distributedHardware || {};
75    global.systemplugin.distributedHardware.deviceManager = {
76        createDeviceManager: function (...args) {
77            console.warn("distributedHardware.deviceManager.createDeviceManager interface mocked in the Previewer. How this interface works on the Previewer" +
78                " may be different from that on a real device.")
79            const len = args.length
80            if (typeof args[len - 1] === 'function') {
81                args[len - 1].call(this, paramMock.businessErrorMock, deviceManagerMock)
82            }
83        }
84    }
85}