1/* 2 * Copyright (c) 2021-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 mockDeviceManager() { 19 const DeviceType = { 20 UNKNOWN_TYPE: 0, 21 SPEAKER: 0x0A, 22 PHONE: 0x0E, 23 TABLET: 0x11, 24 WEARABLE: 0x6D, 25 CAR: 0x83, 26 TV: 0x9C 27 } 28 const DeviceStateChangeAction = { 29 ONLINE: 0, 30 READY: 1, 31 OFFLINE: 2, 32 CHANGE: 3 33 } 34 const DiscoverMode = { 35 DISCOVER_MODE_PASSIVE: 0x55, 36 DISCOVER_MODE_ACTIVE: 0xAA 37 } 38 const ExchangeMedium = { 39 AUTO: 0, 40 BLE: 1, 41 COAP: 2, 42 USB: 3 43 } 44 const ExchangeFreq = { 45 LOW: 0, 46 MID: 1, 47 HIGH: 2, 48 SUPER_HIGH: 3 49 } 50 const SubscribeCap = { 51 SUBSCRIBE_CAPABILITY_DDMP: 0, 52 SUBSCRIBE_CAPABILITY_OSD: 1 53 } 54 const deviceInfoMock = { 55 deviceId: "[PC Preview] unknow mDeviceId", 56 deviceName: "[PC Preview] unknow mDeviceName", 57 deviceType: DeviceType, 58 networkId: "[PC Preview] unknow mNetworkId", 59 range: "[PC Preview] unknow mRange" 60 } 61 const deviceStateChangeMock = { 62 action: 0, 63 device: deviceInfoMock 64 } 65 const SubscribeInfo = { 66 subscribeId: "[PC Preview] unknow mSubscribeId", 67 mode: DiscoverMode, 68 medium: ExchangeMedium, 69 freq: ExchangeFreq, 70 isSameAccount: "[PC Preview] unknow mIsSameAccount", 71 isWakeRemote: "[PC Preview] unknow mIsWakeRemote", 72 capability: SubscribeCap 73 } 74 const PublishInfo = { 75 publishId: "[PC Preview] unknow mPublishId", 76 mode: DiscoverMode, 77 freq: ExchangeFreq, 78 ranging : "[PC Preview] unknow mRanging" 79 } 80 const AuthParam = { 81 authType: "[PC Preview] unknow mAuthType", 82 extraInfo: {"key":"unknow any"} 83 } 84 const AuthInfo = { 85 authType: "[PC Preview] unknow mAuthType", 86 token: "[PC Preview] unknow mToken", 87 extraInfo: {"key":"unknow any"} 88 } 89 const deviceManagerMock = { 90 release: function () { 91 console.warn("DeviceManager.release interface mocked in the Previewer. How this interface works on the Previewer" + 92 " may be different from that on a real device.") 93 }, 94 getTrustedDeviceListSync: function () { 95 console.warn("DeviceManager.getTrustedDeviceListSync interface mocked in the Previewer. How this interface works on the" + 96 " Previewer may be different from that on a real device.") 97 var array = new Array(); 98 array.push(deviceInfoMock); 99 return array; 100 }, 101 getTrustedDeviceList: function (...args) { 102 console.warn("DeviceManager.getTrustedDeviceList interface mocked in the Previewer. How this interface works on the" + 103 " Previewer may be different from that on a real device.") 104 var array = new Array(); 105 array.push(deviceInfoMock); 106 const len = args.length 107 if (typeof args[len - 1] === 'function') { 108 args[len - 1].call(this, paramMock.businessErrorMock, array); 109 } else { 110 return new Promise((resolve, reject) => { 111 resolve(array); 112 }) 113 } 114 }, 115 getLocalDeviceInfoSync: function () { 116 console.warn("DeviceManager.getLocalDeviceInfoSync interface mocked in the Previewer. How this interface works on the" + 117 " Previewer may be different from that on a real device.") 118 return deviceInfoMock; 119 }, 120 getLocalDeviceInfo: function (...args) { 121 console.warn("DeviceManager.getLocalDeviceInfo interface mocked in the Previewer. How this interface works on the" + 122 " Previewer may be different from that on a real device.") 123 const len = args.length 124 if (typeof args[len - 1] === 'function') { 125 args[len - 1].call(this, paramMock.businessErrorMock, deviceInfoMock); 126 } else { 127 return new Promise((resolve, reject) => { 128 resolve(deviceInfoMock); 129 }) 130 } 131 }, 132 startDeviceDiscovery: function (...args) { 133 console.warn("DeviceManager.startDeviceDiscovery interface mocked in the Previewer. How this interface works on the" + 134 " Previewer may be different from that on a real device.") 135 }, 136 stopDeviceDiscovery: function (...args) { 137 console.warn("DeviceManager.stopDeviceDiscovery interface mocked in the Previewer. How this interface works on the" + 138 " Previewer may be different from that on a real device.") 139 }, 140 publishDeviceDiscovery: function (...args) { 141 console.warn("DeviceManager.publishDeviceDiscovery interface mocked in the Previewer. How this interface works on the" + 142 " Previewer may be different from that on a real device.") 143 }, 144 unPublishDeviceDiscovery: function (...args) { 145 console.warn("DeviceManager.unPublishDeviceDiscovery interface mocked in the Previewer. How this interface works on the" + 146 " Previewer may be different from that on a real device.") 147 }, 148 authenticateDevice: function (...args) { 149 console.warn("DeviceManager.authenticateDevice interface mocked in the Previewer. How this interface works on the" + 150 " Previewer may be different from that on a real device.") 151 const len = args.length 152 if (typeof args[len - 1] === 'function') { 153 args[len - 1].call(this, paramMock.businessErrorMock, { 154 deviceId: "[PC Preview] unknow deviceId", 155 pinToken: "[PC Preview] unknow pinToken" 156 }); 157 } 158 }, 159 unAuthenticateDevice: function (...args) { 160 console.warn("DeviceManager.unAuthenticateDevice interface mocked in the Previewer. How this interface works on the" + 161 " Previewer may be different from that on a real device.") 162 }, 163 verifyAuthInfo: function (...args) { 164 console.warn("DeviceManager.verifyAuthInfo interface mocked in the Previewer. How this interface works on the" + 165 " Previewer may be different from that on a real device.") 166 const len = args.length 167 if (typeof args[len - 1] === 'function') { 168 args[len - 1].call(this, paramMock.businessErrorMock, { 169 deviceId: "[PC Preview] unknow deviceId", 170 level: "[PC Preview] unknow level" 171 }); 172 } 173 }, 174 on: function (...args) { 175 console.warn("DeviceManager.on interface mocked in the Previewer. How this interface works on the Previewer may" + 176 " be different from that on a real device.") 177 const len = args.length 178 if (typeof args[len - 1] === 'function') { 179 if (args[0] == 'deviceStateChange') { 180 args[len - 1].call(this, paramMock.businessErrorMock, deviceStateChangeMock); 181 } else if (args[0] == 'deviceFound') { 182 args[len - 1].call(this, paramMock.businessErrorMock, { 183 subscribeId: "[PC Preview] unknow subscribeId", 184 device: deviceInfoMock 185 }); 186 } else if (args[0] == 'discoverFail') { 187 args[len - 1].call(this, paramMock.businessErrorMock, { 188 subscribeId: "[PC Preview] unknow subscribeId", 189 reason: "[PC Preview] unknow reason" 190 }); 191 } else if (args[0] == 'publishSuccess') { 192 args[len - 1].call(this, paramMock.businessErrorMock, { 193 publishId: "[PC Preview] unknow publishId", 194 }); 195 } else if (args[0] == 'publishFail') { 196 args[len - 1].call(this, paramMock.businessErrorMock, { 197 publishId: "[PC Preview] unknow publishId", 198 reason: "[PC Preview] unknow reason" 199 }); 200 } else { 201 args[len - 1].call(this); 202 } 203 } 204 }, 205 off: function (...args) { 206 console.warn("DeviceManager.off interface mocked in the Previewer. How this interface works on the Previewer may" + 207 " be different from that on a real device.") 208 } 209 } 210 const deviceManager = { 211 DeviceType, 212 DeviceStateChangeAction, 213 DiscoverMode, 214 ExchangeMedium, 215 ExchangeFreq, 216 SubscribeCap, 217 SubscribeInfo, 218 PublishInfo, 219 AuthParam, 220 AuthInfo, 221 createDeviceManager: function (...args) { 222 console.warn("distributedHardware.deviceManager.createDeviceManager interface mocked in the Previewer. How this interface works on the Previewer" + 223 " may be different from that on a real device.") 224 const len = args.length 225 if (typeof args[len - 1] === 'function') { 226 args[len - 1].call(this, paramMock.businessErrorMock, deviceManagerMock) 227 } 228 } 229 } 230 return deviceManager 231}