diff --git a/runtime/main/extend/systemplugin/index.js b/runtime/main/extend/systemplugin/index.js index 1d72eb482d77b0f2d64bf547aa6acbb998ad79ec..d27c956debd6bb59f81ae8ed90b12d8d6d75cd1c 100644 --- a/runtime/main/extend/systemplugin/index.js +++ b/runtime/main/extend/systemplugin/index.js @@ -63,7 +63,6 @@ import { mockUserauth } from './userIAM' import { mockVibrator } from './vibrator' import { mockWebSocket, mockHttp, mockMdns, mockSocket, mockHotspot, mockStatistics, mockConnection } from './net' -import { mockWifi } from './ohos/wifi' import { mockWindow } from './window' import { mockWorkScheduler } from './ohos/workScheduler' @@ -141,7 +140,6 @@ export function mockSystemPlugin() { mockStatistics() mockConnection() mockDeviceInfo() - mockWifi() mockResourceManager() mockOhosNfc() mockDataStorage() diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 8d5da916dbc3e8c65e3598adfb8b29d8a17d6690..8efebc2a510dfbd229372d7b631d4ebba77d6dc9 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -28,6 +28,7 @@ import { mockRdb } from './rdb' import { mockInputDevice } from './inputDevice' import { mockVibrator } from './vibrator' import { mockSensor } from './sensor' +import { mockWifi } from './wifi' export function mockRequireNapiFun() { global.requireNapi = function (...args) { @@ -92,6 +93,8 @@ export function mockRequireNapiFun() { return mockVibrator(); case "sensor": return mockSensor(); + case "wifi": + return mockWifi(); default: return global.requireNapiPreview(...args); } diff --git a/runtime/main/extend/systemplugin/ohos/wifi.js b/runtime/main/extend/systemplugin/napi/wifi.js old mode 100644 new mode 100755 similarity index 42% rename from runtime/main/extend/systemplugin/ohos/wifi.js rename to runtime/main/extend/systemplugin/napi/wifi.js index 3af7a40025617b5f2645f9d7aadf8a3b3b194aa1..feb980687872b723f8ad3234a99b356e276ac360 --- a/runtime/main/extend/systemplugin/ohos/wifi.js +++ b/runtime/main/extend/systemplugin/napi/wifi.js @@ -1,151 +1,284 @@ -import { paramMock } from "../utils" - -export function mockWifi() { - const linkedInfoMock = { - ssid: '[PC preview] unknow ssid', - bssid: '[PC preview] unknow bssid', - networkId: '[PC preview] unknow networkId', - rssi: '[PC preview] unknow rssi', - band: '[PC preview] unknow band', - linkSpeed: '[PC preview] unknow linkSpeed', - frequency: '[PC preview] unknow frequency', - isHidden: '[PC preview] unknow isHidden', - isRestricted: '[PC preview] unknow isRestricted', - chload: '[PC preview] unknow chload', - snr: '[PC preview] unknow snr', - macAddress: '[PC preview] unknow macAddress', - ipAddress: '[PC preview] unknow ipAddress', - suppState: '[PC preview] unknow suppState', - connState: '[PC preview] unknow connState' - } - - const ipInfoMock = { - ipAddress: '[PC preview] unknow ipAddress', - gateway: '[PC preview] unknow gateway', - netmask: '[PC preview] unknow netmask', - primaryDns: '[PC preview] unknow primaryDns', - secondDns: '[PC preview] unknow secondDns', - serverIp: '[PC preview] unknow serverIp', - leaseDuration: '[PC preview] unknow leaseDuration' - } - - const wifiScanInfoMock = { - ssid: '[PC preview] unknow ssid', - bssid: '[PC preview] unknow bssid', - capabilities: '[PC preview] unknow capabilities', - securityType: '[PC preview] unknow securityType', - rssi: '[PC preview] unknow rssi', - band: '[PC preview] unknow band', - frequency: '[PC preview] unknow frequency', - channelWidth: '[PC preview] unknow channelWidth', - timestamp: '[PC preview] unknow timestamp', - } - - global.ohosplugin.wifi = { - getLinkedInfo: function (...args) { - console.warn("wifi.getLinkedInfo interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, linkedInfoMock) - } else { - return new Promise((resolve) => { - resolve(linkedInfoMock) - }) - } - }, - - isConnected: function (...args) { - console.warn("wifi.isConnected interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - - isWifiActive: function (...args) { - console.warn("wifi.isWifiActive interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - - getSignalLevel: function (...args) { - console.warn("wifi.getSignalLevel interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramNumberMock; - }, - - isFeatureSupported: function (...args) { - console.warn("wifi.isFeatureSupported interface mocked in the Previewer." + - " How this interface works on the Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - - addUntrustedConfig: function (...args) { - console.warn("wifi.addUntrustedConfig interface mocked in the Previewer." + - " How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) - } else { - return new Promise((resolve) => { - resolve(paramMock.paramBooleanMock) - }) - } - }, - - removeUntrustedConfig: function (...args) { - console.warn("wifi.removeUntrustedConfig interface mocked in the Previewer." + - " How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) - } else { - return new Promise((resolve) => { - resolve(paramMock.paramBooleanMock) - }) - } - }, - - scan: function (...args) { - console.warn("wifi.scan interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - - getIpInfo: function (...args) { - console.warn("wifi.getIpInfo interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return ipInfoMock; - }, - - getScanInfos: function (...args) { - console.warn("wifi.getScanInfos interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, [wifiScanInfoMock]) - } else { - return new Promise((resolve) => { - resolve([wifiScanInfoMock]) - }) - } - }, - - getCountryCode: function (...args) { - console.warn("wifi.getCountryCode interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramStringMock; - }, - - on: function (...args) { - console.warn("wifi.on interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return; - }, - - off: function (...args) { - console.warn("wifi.off interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return; - } - } -} \ No newline at end of file +import { paramMock } from "../utils" + +export function mockWifi() { + const linkedInfoMock = { + ssid: '[PC preview] unknow ssid', + bssid: '[PC preview] unknow bssid', + networkId: '[PC preview] unknow networkId', + rssi: '[PC preview] unknow rssi', + band: '[PC preview] unknow band', + linkSpeed: '[PC preview] unknow linkSpeed', + frequency: '[PC preview] unknow frequency', + isHidden: '[PC preview] unknow isHidden', + isRestricted: '[PC preview] unknow isRestricted', + chload: '[PC preview] unknow chload', + snr: '[PC preview] unknow snr', + macAddress: '[PC preview] unknow macAddress', + ipAddress: '[PC preview] unknow ipAddress', + suppState: '[PC preview] unknow suppState', + connState: '[PC preview] unknow connState' + } + + const ipInfoMock = { + ipAddress: '[PC preview] unknow ipAddress', + gateway: '[PC preview] unknow gateway', + netmask: '[PC preview] unknow netmask', + primaryDns: '[PC preview] unknow primaryDns', + secondDns: '[PC preview] unknow secondDns', + serverIp: '[PC preview] unknow serverIp', + leaseDuration: '[PC preview] unknow leaseDuration' + } + + const wifiScanInfoMock = { + ssid: '[PC preview] unknow ssid', + bssid: '[PC preview] unknow bssid', + securityType: '[PC preview] unknow securityType', + rssi: '[PC preview] unknow rssi', + band: '[PC preview] unknow band', + frequency: '[PC preview] unknow frequency', + timestamp: '[PC preview] unknow timestamp', + } + + const wifiDeviceConfigMock = { + ssid: '[PC preview] unknow ssid', + bssid: '[PC preview] unknow bssid', + preSharedKey: '[PC preview] unknow preSharedKey', + isHiddenSsid: '[PC preview] unknow isHiddenSsid', + securityType: '[PC preview] unknow securityType', + } + + const wifiHotspotConfigMock = { + ssid: '[PC preview] unknow ssid', + securityType: '[PC preview] unknow securityType', + band: '[PC preview] unknow band', + preSharedKey: '[PC preview] unknow preSharedKey', + maxConn: '[PC preview] unknow maxConn', + } + + const wifiStationInfoMock = { + name: '[PC preview] unknow name', + macAddress: '[PC preview] unknow macAddress', + ipAddress: '[PC preview] unknow ipAddress', + } + + const EventListenerClass = class EventListener { + constructor() { + this.on = function (...args) { + console.warn("wifi.on interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return; + } + this.off = function (...args) { + console.warn("wifi.off interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return; + } + } + } + + const wifi = { + enableWifi: function (...args) { + console.warn("wifi.enableWifi interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + disableWifi: function (...args) { + console.warn("wifi.disableWifi interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + isWifiActive: function (...args) { + console.warn("wifi.isWifiActive interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + scan: function (...args) { + console.warn("wifi.scan interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + getScanInfos: function (...args) { + console.warn("wifi.getScanInfos interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [wifiScanInfoMock]) + } else { + return new Promise((resolve) => { + resolve([wifiScanInfoMock]) + }) + } + }, + + addDeviceConfig: function (...args) { + console.warn("wifi.addDeviceConfig interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramNumberMock) + }) + } + }, + + connectToNetwork: function (...args) { + console.warn("wifi.connectToNetwork interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + connectToDevice: function (...args) { + console.warn("wifi.connectToDevice interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + disconnect: function (...args) { + console.warn("wifi.disconnect interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + getSignalLevel: function (...args) { + console.warn("wifi.getSignalLevel interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + + getLinkedInfo: function (...args) { + console.warn("wifi.getLinkedInfo interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, linkedInfoMock) + } else { + return new Promise((resolve) => { + resolve(linkedInfoMock) + }) + } + }, + + isConnected: function (...args) { + console.warn("wifi.isConnected interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + getSupportedFeatures: function (...args) { + console.warn("wifi.getSupportedFeatures interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + + isFeatureSupported: function (...args) { + console.warn("wifi.isFeatureSupported interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + getDeviceMacAddress: function (...args) { + console.warn("wifi.getDeviceMacAddress interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return [paramMock.paramArrayMock]; + }, + + getIpInfo: function (...args) { + console.warn("wifi.getIpInfo interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return ipInfoMock; + }, + + getCountryCode: function (...args) { + console.warn("wifi.getCountryCode interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramStringMock; + }, + + reassociate: function (...args) { + console.warn("wifi.reassociate interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + reconnect: function (...args) { + console.warn("wifi.reconnect interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + getDeviceConfigs: function (...args) { + console.warn("wifi.getDeviceConfigs interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return [wifiDeviceConfigMock]; + }, + + updateNetwork: function (...args) { + console.warn("wifi.updateNetwork interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + + disableNetwork: function (...args) { + console.warn("wifi.disableNetwork interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + removeAllNetwork: function (...args) { + console.warn("wifi.removeAllNetwork interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + removeDevice: function (...args) { + console.warn("wifi.removeDevice interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + enableHotspot: function (...args) { + console.warn("wifi.enableHotspot interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + disableHotspot: function (...args) { + console.warn("wifi.disableHotspot interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + isHotspotActive: function (...args) { + console.warn("wifi.isHotspotActive interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + setHotspotConfig: function (...args) { + console.warn("wifi.setHotspotConfig interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + getHotspotConfig: function (...args) { + console.warn("wifi.getHotspotConfig interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return wifiHotspotConfigMock; + }, + + getStations: function (...args) { + console.warn("wifi.getStations interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return [wifiStationInfoMock]; + }, + + EventListener: EventListenerClass + } + return wifi; +}