• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 mockWifi() {
19  const EapMethod = {
20    EAP_NONE : 0,
21    EAP_PEAP : 1,
22    EAP_TLS : 2,
23    EAP_TTLS : 3,
24    EAP_PWD : 4,
25    EAP_SIM : 5,
26    EAP_AKA : 6,
27    EAP_AKA_PRIME : 7,
28    EAP_UNAUTH_TLS : 8,
29  }
30
31  const Phase2Method = {
32    PHASE2_NONE : 0,
33    PHASE2_PAP : 1,
34    PHASE2_MSCHAP : 2,
35    PHASE2_MSCHAPV2 : 3,
36    PHASE2_GTC : 4,
37    PHASE2_SIM : 5,
38    PHASE2_AKA : 6,
39    PHASE2_AKA_PRIME : 7,
40  }
41
42  const WifiSecurityType = {
43    WIFI_SEC_TYPE_INVALID : 0,
44    WIFI_SEC_TYPE_OPEN : 1,
45    WIFI_SEC_TYPE_WEP : 2,
46    WIFI_SEC_TYPE_PSK : 3,
47    WIFI_SEC_TYPE_SAE : 4,
48    WIFI_SEC_TYPE_EAP : 5,
49    WIFI_SEC_TYPE_EAP_SUITE_B : 6,
50    WIFI_SEC_TYPE_OWE : 7,
51    WIFI_SEC_TYPE_WAPI_CERT : 8,
52    WIFI_SEC_TYPE_WAPI_PSK : 9,
53  }
54
55  const IpType = {
56    STATIC : 0,
57    DHCP : 1,
58    UNKNOWN : 2,
59  }
60
61  const SuppState = {
62    DISCONNECTED : 0,
63    INTERFACE_DISABLED : 1,
64    INACTIVE : 2,
65    SCANNING : 3,
66    AUTHENTICATING : 4,
67    ASSOCIATING : 5,
68    ASSOCIATED : 6,
69    FOUR_WAY_HANDSHAKE : 7,
70    GROUP_HANDSHAKE : 8,
71    COMPLETED : 9,
72    UNINITIALIZED : 10,
73    INVALID : 11,
74  }
75
76  const ConnState = {
77    SCANNING : 0,
78    CONNECTING : 1,
79    AUTHENTICATING : 2,
80    OBTAINING_IPADDR : 3,
81    CONNECTED : 4,
82    DISCONNECTING : 5,
83    DISCONNECTED : 6,
84    UNKNOWN : 7,
85  }
86
87  const P2pConnectState = {
88    DISCONNECTED : 0,
89    CONNECTED : 1,
90  }
91
92  const P2pDeviceStatus = {
93    CONNECTED : 0,
94    INVITED : 1,
95    FAILED : 2,
96    AVAILABLE : 3,
97    UNAVAILABLE : 4,
98  }
99
100  const WifiLinkedInfo = {
101    ssid: '[PC preview] unknow ssid',
102    bssid: '[PC preview] unknow bssid',
103    networkId: '[PC preview] unknow networkId',
104    rssi: '[PC preview] unknow rssi',
105    band: '[PC preview] unknow band',
106    linkSpeed: '[PC preview] unknow linkSpeed',
107    frequency: '[PC preview] unknow frequency',
108    isHidden: '[PC preview] unknow isHidden',
109    isRestricted: '[PC preview] unknow isRestricted',
110    chload: '[PC preview] unknow chload',
111    snr: '[PC preview] unknow snr',
112    macType: '[PC preview] unknow macType',
113    macAddress: '[PC preview] unknow macAddress',
114    ipAddress: '[PC preview] unknow ipAddress',
115    suppState: SuppState.INVALID,
116    connState: ConnState.DISCONNECTED,
117  }
118
119  const IpInfo = {
120    ipAddress: '[PC preview] unknow ipAddress',
121    gateway: '[PC preview] unknow gateway',
122    netmask: '[PC preview] unknow netmask',
123    primaryDns: '[PC preview] unknow primaryDns',
124    secondDns: '[PC preview] unknow secondDns',
125    serverIp: '[PC preview] unknow serverIp',
126    leaseDuration: '[PC preview] unknow leaseDuration',
127  }
128
129  const WifiInfoElem = {
130    eid: '[PC preview] unknow eid',
131    content: '[PC preview] unknow content',
132  }
133
134  const WifiScanInfo = {
135    ssid: '[PC preview] unknow ssid',
136    bssid: '[PC preview] unknow bssid',
137    capabilities: '[PC preview] unknow capabilities',
138    securityType: WifiSecurityType.WIFI_SEC_TYPE_OPEN,
139    rssi: '[PC preview] unknow rssi',
140    band: '[PC preview] unknow band',
141    frequency: '[PC preview] unknow frequency',
142    channelWidth: '[PC preview] unknow channelWidth',
143    centerFrequency0: '[PC preview] unknow centerFrequency0',
144    centerFrequency1: '[PC preview] unknow centerFrequency1',
145    infoElems: [WifiInfoElem],
146    timestamp: '[PC preview] unknow timestamp',
147  }
148
149  const IpConfig = {
150    ipAddress: '[PC preview] unknow ipAddress',
151    gateway: '[PC preview] unknow gateway',
152    dnsServers: [paramMock.paramNumberMock],
153    domains: [paramMock.paramStringMock],
154  }
155
156  const WifiEapConfig = {
157    eapMethod: EapMethod.EAP_NONE,
158    phase2Method: Phase2Method.PHASE2_NONE,
159    identity: '[PC preview] unknow identity',
160    anonymousIdentity: '[PC preview] unknow anonymousIdentity',
161    password: '[PC preview] unknow password',
162    caCertAliases: '[PC preview] unknow caCertAliases',
163    caPath: '[PC preview] unknow caPath',
164    clientCertAliases: '[PC preview] unknow clientCertAliases',
165    altSubjectMatch: '[PC preview] unknow altSubjectMatch',
166    domainSuffixMatch: '[PC preview] unknow domainSuffixMatch',
167    realm: '[PC preview] unknow realm',
168    plmn: '[PC preview] unknow plmn',
169    eapSubId: '[PC preview] unknow eapSubId',
170  }
171
172  const WifiDeviceConfig = {
173    ssid: '[PC preview] unknow ssid',
174    bssid: '[PC preview] unknow bssid',
175    preSharedKey: '[PC preview] unknow preSharedKey',
176    isHiddenSsid: '[PC preview] unknow isHiddenSsid',
177    securityType: WifiSecurityType.WIFI_SEC_TYPE_OPEN,
178    creatorUid: '[PC preview] unknow creatorUid',
179    disableReason: '[PC preview] unknow disableReason',
180    netId: '[PC preview] unknow netId',
181    randomMacType: '[PC preview] unknow randomMacType',
182    randomMacAddr: '[PC preview] unknow randomMacAddr',
183    ipType: IpType.DHCP,
184    staticIp: IpConfig,
185    eapConfig: WifiEapConfig,
186  }
187
188  const WifiHotspotConfig = {
189    ssid: '[PC preview] unknow ssid',
190    securityType: WifiSecurityType.WIFI_SEC_TYPE_OPEN,
191    band: '[PC preview] unknow band',
192    preSharedKey: '[PC preview] unknow preSharedKey',
193    maxConn: '[PC preview] unknow maxConn',
194  }
195
196  const WifiStationInfo = {
197    name: '[PC preview] unknow name',
198    macAddress: '[PC preview] unknow macAddress',
199    ipAddress: '[PC preview] unknow ipAddress',
200  }
201
202  const P2pLinkedInfo = {
203    connectState: P2pConnectState.DISCONNECTED,
204    isGroupOwner: '[PC preview] unknow isGroupOwner',
205    groupOwnerAddr: '[PC preview] unknow groupOwnerAddr',
206  }
207
208  const WifiP2pDevice = {
209    deviceName: '[PC preview] unknow deviceName',
210    deviceAddress: '[PC preview] unknow deviceAddress',
211    primaryDeviceType: '[PC preview] unknow primaryDeviceType',
212    deviceStatus: P2pDeviceStatus.UNAVAILABLE,
213    groupCapabilitys: '[PC preview] unknow groupCapabilitys',
214  }
215
216  const P2pGroupInfo = {
217    isP2pGo: '[PC preview] unknow connectState',
218    ownerInfo: WifiP2pDevice,
219    passphrase: '[PC preview] unknow passphrase',
220    interface: '[PC preview] unknow interface',
221    groupName: '[PC preview] unknow groupName',
222    networkId: '[PC preview] unknow networkId',
223    frequency: '[PC preview] unknow frequency',
224    clientDevices: [WifiP2pDevice],
225    goIpAddress: '[PC preview] unknow goIpAddress',
226  }
227
228  const wifi = {
229    enableWifi: function (...args) {
230      console.warn("wifi.enableWifi interface mocked in the Previewer. How this interface works on the Previewer" +
231        " may be different from that on a real device.")
232      return paramMock.paramBooleanMock;
233    },
234
235    disableWifi: function (...args) {
236      console.warn("wifi.disableWifi interface mocked in the Previewer. How this interface works on the Previewer" +
237        " may be different from that on a real device.")
238      return paramMock.paramBooleanMock;
239    },
240
241    isWifiActive: function (...args) {
242      console.warn("wifi.isWifiActive interface mocked in the Previewer. How this interface works on the Previewer" +
243        " may be different from that on a real device.")
244      return paramMock.paramBooleanMock;
245    },
246
247    scan: function (...args) {
248      console.warn("wifi.scan interface mocked in the Previewer. How this interface works on the Previewer" +
249        " may be different from that on a real device.")
250      return paramMock.paramBooleanMock;
251    },
252
253    getScanInfos: function (...args) {
254      console.warn("wifi.getScanInfos interface mocked in the Previewer. How this interface works on the Previewer" +
255        " may be different from that on a real device.")
256      const len = args.length
257      if (typeof args[len - 1] === 'function') {
258        args[len - 1].call(this, paramMock.businessErrorMock, [WifiScanInfo])
259      } else {
260        return new Promise((resolve) => {
261          resolve([WifiScanInfo])
262        })
263      }
264    },
265
266    getScanInfosSync: function (...args) {
267      console.warn("wifi.getScanInfosSync interface mocked in the Previewer." +
268        " How this interface works on the Previewer may be different from that on a real device.")
269      return [WifiScanInfo];
270    },
271
272    addDeviceConfig: function (...args) {
273      console.warn("wifi.addDeviceConfig interface mocked in the Previewer." +
274        " How this interface works on the Previewer may be different from that on a real device.")
275      const len = args.length
276      if (typeof args[len - 1] === 'function') {
277        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
278      } else {
279        return new Promise((resolve) => {
280          resolve(paramMock.paramNumberMock)
281        })
282      }
283    },
284
285    addUntrustedConfig: function (...args) {
286      console.warn("wifi.addUntrustedConfig interface mocked in the Previewer." +
287        " How this interface works on the Previewer may be different from that on a real device.")
288      const len = args.length
289      if (typeof args[len - 1] === 'function') {
290        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
291      } else {
292        return new Promise((resolve) => {
293          resolve(paramMock.paramBooleanMock)
294        })
295      }
296    },
297
298    removeUntrustedConfig: function (...args) {
299      console.warn("wifi.removeUntrustedConfig interface mocked in the Previewer." +
300        " How this interface works on the Previewer may be different from that on a real device.")
301      const len = args.length
302      if (typeof args[len - 1] === 'function') {
303        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
304      } else {
305        return new Promise((resolve) => {
306          resolve(paramMock.paramBooleanMock)
307        })
308      }
309    },
310
311    addCandidateConfig: function (...args) {
312      console.warn("wifi.addCandidateConfig interface mocked in the Previewer." +
313        " How this interface works on the Previewer may be different from that on a real device.")
314      const len = args.length
315      if (typeof args[len - 1] === 'function') {
316        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
317      } else {
318        return new Promise((resolve) => {
319          resolve(paramMock.paramNumberMock)
320        })
321      }
322    },
323
324    removeCandidateConfig: function (...args) {
325      console.warn("wifi.removeCandidateConfig interface mocked in the Previewer." +
326        " How this interface works on the Previewer may be different from that on a real device.")
327      const len = args.length
328      if (typeof args[len - 1] === 'function') {
329        args[len - 1].call(this, paramMock.businessErrorMock)
330      } else {
331        return new Promise((resolve) => {
332          resolve()
333        })
334      }
335    },
336
337    getCandidateConfigs: function (...args) {
338      console.warn("wifi.getCandidateConfigs interface mocked in the Previewer." +
339        " How this interface works on the Previewer may be different from that on a real device.")
340      return [WifiDeviceConfig];
341    },
342
343    connectToCandidateConfig: function (...args) {
344      console.warn("wifi.connectToCandidateConfig interface mocked in the Previewer. " +
345        "How this interface works on the Previewer may be different from that on a real device.")
346      return;
347    },
348
349    connectToNetwork: function (...args) {
350      console.warn("wifi.connectToNetwork interface mocked in the Previewer. " +
351        "How this interface works on the Previewer may be different from that on a real device.")
352      return paramMock.paramBooleanMock;
353    },
354
355    connectToDevice: function (...args) {
356      console.warn("wifi.connectToDevice interface mocked in the Previewer. How this interface works on the Previewer" +
357        " may be different from that on a real device.")
358      return paramMock.paramBooleanMock;
359    },
360
361    disconnect: function (...args) {
362      console.warn("wifi.disconnect interface mocked in the Previewer. How this interface works on the Previewer" +
363        " may be different from that on a real device.")
364      return paramMock.paramBooleanMock;
365    },
366
367    getSignalLevel: function (...args) {
368      console.warn("wifi.getSignalLevel interface mocked in the Previewer. How this interface works on the Previewer" +
369        " may be different from that on a real device.")
370      return paramMock.paramNumberMock;
371    },
372
373    getLinkedInfo: function (...args) {
374      console.warn("wifi.getLinkedInfo interface mocked in the Previewer. How this interface works on the Previewer" +
375        " may be different from that on a real device.")
376      const len = args.length
377      if (typeof args[len - 1] === 'function') {
378        args[len - 1].call(this, paramMock.businessErrorMock, WifiLinkedInfo)
379      } else {
380        return new Promise((resolve) => {
381          resolve(WifiLinkedInfo)
382        })
383      }
384    },
385
386    isConnected: function (...args) {
387      console.warn("wifi.isConnected interface mocked in the Previewer. How this interface works on the Previewer" +
388        " may be different from that on a real device.")
389      return paramMock.paramBooleanMock;
390    },
391
392    getSupportedFeatures: function (...args) {
393      console.warn("wifi.getSupportedFeatures interface mocked in the Previewer." +
394        " How this interface works on the Previewer may be different from that on a real device.")
395      return paramMock.paramNumberMock;
396    },
397
398    isFeatureSupported: function (...args) {
399      console.warn("wifi.isFeatureSupported interface mocked in the Previewer." +
400        " How this interface works on the Previewer may be different from that on a real device.")
401      return paramMock.paramBooleanMock;
402    },
403
404    getDeviceMacAddress: function (...args) {
405      console.warn("wifi.getDeviceMacAddress interface mocked in the Previewer." +
406        " How this interface works on the Previewer may be different from that on a real device.")
407      return [paramMock.paramArrayMock];
408    },
409
410    getIpInfo: function (...args) {
411      console.warn("wifi.getIpInfo interface mocked in the Previewer. How this interface works on the Previewer" +
412        " may be different from that on a real device.")
413      return IpInfo;
414    },
415
416    getCountryCode: function (...args) {
417      console.warn("wifi.getCountryCode interface mocked in the Previewer. How this interface works on the Previewer" +
418        " may be different from that on a real device.")
419      return paramMock.paramStringMock;
420    },
421
422    reassociate: function (...args) {
423      console.warn("wifi.reassociate interface mocked in the Previewer." +
424        " How this interface works on the Previewer may be different from that on a real device.")
425      return paramMock.paramBooleanMock;
426    },
427
428    reconnect: function (...args) {
429      console.warn("wifi.reconnect interface mocked in the Previewer." +
430        " How this interface works on the Previewer may be different from that on a real device.")
431      return paramMock.paramBooleanMock;
432    },
433
434    getDeviceConfigs: function (...args) {
435      console.warn("wifi.getDeviceConfigs interface mocked in the Previewer." +
436        " How this interface works on the Previewer may be different from that on a real device.")
437      return [WifiDeviceConfig];
438    },
439
440    updateNetwork: function (...args) {
441      console.warn("wifi.updateNetwork interface mocked in the Previewer." +
442        " How this interface works on the Previewer may be different from that on a real device.")
443      return paramMock.paramNumberMock;
444    },
445
446    disableNetwork: function (...args) {
447      console.warn("wifi.disableNetwork interface mocked in the Previewer." +
448        " How this interface works on the Previewer may be different from that on a real device.")
449      return paramMock.paramBooleanMock;
450    },
451
452    removeAllNetwork: function (...args) {
453      console.warn("wifi.removeAllNetwork interface mocked in the Previewer." +
454        " How this interface works on the Previewer may be different from that on a real device.")
455      return paramMock.paramBooleanMock;
456    },
457
458    removeDevice: function (...args) {
459      console.warn("wifi.removeDevice interface mocked in the Previewer." +
460        " How this interface works on the Previewer may be different from that on a real device.")
461      return paramMock.paramBooleanMock;
462    },
463
464    enableHotspot: function (...args) {
465      console.warn("wifi.enableHotspot interface mocked in the Previewer." +
466        " How this interface works on the Previewer may be different from that on a real device.")
467      return paramMock.paramBooleanMock;
468    },
469
470    disableHotspot: function (...args) {
471      console.warn("wifi.disableHotspot interface mocked in the Previewer." +
472        " How this interface works on the Previewer may be different from that on a real device.")
473      return paramMock.paramBooleanMock;
474    },
475
476    isHotspotDualBandSupported: function (...args) {
477      console.warn("wifi.isHotspotDualBandSupported interface mocked in the Previewer." +
478        " How this interface works on the Previewer may be different from that on a real device.")
479      return paramMock.paramBooleanMock;
480    },
481
482    isHotspotActive: function (...args) {
483      console.warn("wifi.isHotspotActive interface mocked in the Previewer." +
484        " How this interface works on the Previewer may be different from that on a real device.")
485      return paramMock.paramBooleanMock;
486    },
487
488    setHotspotConfig: function (...args) {
489      console.warn("wifi.setHotspotConfig interface mocked in the Previewer." +
490        " How this interface works on the Previewer may be different from that on a real device.")
491      return paramMock.paramBooleanMock;
492    },
493
494    getHotspotConfig: function (...args) {
495      console.warn("wifi.getHotspotConfig interface mocked in the Previewer." +
496        " How this interface works on the Previewer may be different from that on a real device.")
497      return WifiHotspotConfig;
498    },
499
500    getStations: function (...args) {
501      console.warn("wifi.getStations interface mocked in the Previewer." +
502        " How this interface works on the Previewer may be different from that on a real device.")
503      return [WifiStationInfo];
504    },
505
506    on: function (...args) {
507      console.warn("wifi.on interface mocked in the Previewer." +
508        " How this interface works on the Previewer may be different from that on a real device.")
509    },
510
511    off: function (...args) {
512      console.warn("wifi.off interface mocked in the Previewer." +
513        " How this interface works on the Previewer may be different from that on a real device.")
514    },
515
516    getP2pLinkedInfo: function (...args) {
517      console.warn("wifi.getP2pLinkedInfo interface mocked in the Previewer. " +
518        "How this interface works on the Previewer may be different from that on a real device.")
519      const len = args.length
520      if (typeof args[len - 1] === 'function') {
521        args[len - 1].call(this, paramMock.businessErrorMock, P2pLinkedInfo)
522      } else {
523        return new Promise((resolve) => {
524          resolve(P2pLinkedInfo)
525        })
526      }
527    },
528
529    getCurrentGroup: function (...args) {
530      console.warn("wifi.getCurrentGroup interface mocked in the Previewer. How this interface works on the Previewer" +
531        " may be different from that on a real device.")
532      const len = args.length
533      if (typeof args[len - 1] === 'function') {
534        args[len - 1].call(this, paramMock.businessErrorMock, P2pGroupInfo)
535      } else {
536        return new Promise((resolve) => {
537          resolve(P2pGroupInfo)
538        })
539      }
540    },
541
542    getP2pPeerDevices: function (...args) {
543      console.warn("wifi.getP2pPeerDevices interface mocked in the Previewer. How this interface works on the Previewer" +
544        " may be different from that on a real device.")
545      const len = args.length
546      if (typeof args[len - 1] === 'function') {
547        args[len - 1].call(this, paramMock.businessErrorMock, [WifiP2pDevice])
548      } else {
549        return new Promise((resolve) => {
550          resolve([WifiP2pDevice])
551        })
552      }
553    },
554
555    getP2pLocalDevice: function (...args) {
556      console.warn("wifi.getP2pLocalDevice interface mocked in the Previewer. How this interface works on the Previewer" +
557        " may be different from that on a real device.")
558      const len = args.length
559      if (typeof args[len - 1] === 'function') {
560        args[len - 1].call(this, paramMock.businessErrorMock, WifiP2pDevice)
561      } else {
562        return new Promise((resolve) => {
563          resolve(WifiP2pDevice)
564        })
565      }
566    },
567
568    createGroup: function (...args) {
569      console.warn("wifi.createGroup interface mocked in the Previewer. How this interface works on the Previewer" +
570        " may be different from that on a real device.")
571      return paramMock.paramBooleanMock;
572    },
573
574    removeGroup: function (...args) {
575      console.warn("wifi.removeGroup interface mocked in the Previewer. How this interface works on the Previewer" +
576        " may be different from that on a real device.")
577      return paramMock.paramBooleanMock;
578    },
579
580    p2pConnect: function (...args) {
581      console.warn("wifi.p2pConnect interface mocked in the Previewer. How this interface works on the Previewer" +
582        " may be different from that on a real device.")
583      return paramMock.paramBooleanMock;
584    },
585
586    p2pCancelConnect: function (...args) {
587      console.warn("wifi.p2pCancelConnect interface mocked in the Previewer. " +
588        "How this interface works on the Previewer may be different from that on a real device.")
589      return paramMock.paramBooleanMock;
590    },
591
592    startDiscoverDevices: function (...args) {
593      console.warn("wifi.startDiscoverDevices interface mocked in the Previewer. " +
594        "How this interface works on the Previewer may be different from that on a real device.")
595      return paramMock.paramBooleanMock;
596    },
597
598    stopDiscoverDevices: function (...args) {
599      console.warn("wifi.stopDiscoverDevices interface mocked in the Previewer. " +
600        "How this interface works on the Previewer may be different from that on a real device.")
601      return paramMock.paramBooleanMock;
602    },
603
604    deletePersistentGroup: function (...args) {
605      console.warn("wifi.deletePersistentGroup interface mocked in the Previewer. " +
606        "How this interface works on the Previewer may be different from that on a real device.")
607      return paramMock.paramBooleanMock;
608    },
609
610    getP2pGroups: function (...args) {
611      console.warn("wifi.getP2pGroups interface mocked in the Previewer. How this interface works on the Previewer" +
612        " may be different from that on a real device.")
613      const len = args.length
614      if (typeof args[len - 1] === 'function') {
615        args[len - 1].call(this, paramMock.businessErrorMock, [P2pGroupInfo])
616      } else {
617        return new Promise((resolve) => {
618          resolve([P2pGroupInfo])
619        })
620      }
621    },
622
623    setDeviceName: function (...args) {
624      console.warn("wifi.setDeviceName interface mocked in the Previewer. How this interface works on the Previewer" +
625        " may be different from that on a real device.")
626      return paramMock.paramBooleanMock;
627    },
628  }
629  return wifi;
630}
631