1/* 2 * Copyright (c) 2021 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" 17export const PreferredNetworkMode = { 18 PREFERRED_NETWORK_MODE_GSM: 1, 19 PREFERRED_NETWORK_MODE_WCDMA: 2, 20 PREFERRED_NETWORK_MODE_LTE: 3, 21 PREFERRED_NETWORK_MODE_LTE_WCDMA: 4, 22 PREFERRED_NETWORK_MODE_LTE_WCDMA_GSM: 5, 23 PREFERRED_NETWORK_MODE_WCDMA_GSM: 6, 24 PREFERRED_NETWORK_MODE_CDMA: 7, 25 PREFERRED_NETWORK_MODE_EVDO: 8, 26 PREFERRED_NETWORK_MODE_EVDO_CDMA: 9, 27 PREFERRED_NETWORK_MODE_WCDMA_GSM_EVDO_CDMA: 10, 28 PREFERRED_NETWORK_MODE_LTE_EVDO_CDMA: 11, 29 PREFERRED_NETWORK_MODE_LTE_WCDMA_GSM_EVDO_CDMA: 12, 30 PREFERRED_NETWORK_MODE_TDSCDMA: 13, 31 PREFERRED_NETWORK_MODE_TDSCDMA_GSM: 14, 32 PREFERRED_NETWORK_MODE_TDSCDMA_WCDMA: 15, 33 PREFERRED_NETWORK_MODE_TDSCDMA_WCDMA_GSM: 16, 34 PREFERRED_NETWORK_MODE_LTE_TDSCDMA: 17, 35 PREFERRED_NETWORK_MODE_LTE_TDSCDMA_GSM: 18, 36 PREFERRED_NETWORK_MODE_LTE_TDSCDMA_WCDMA: 19, 37 PREFERRED_NETWORK_MODE_LTE_TDSCDMA_WCDMA_GSM: 20, 38 PREFERRED_NETWORK_MODE_TDSCDMA_WCDMA_GSM_EVDO_CDMA: 21, 39 PREFERRED_NETWORK_MODE_LTE_TDSCDMA_WCDMA_GSM_EVDO_CDMA: 22, 40 PREFERRED_NETWORK_MODE_NR: 31, 41 PREFERRED_NETWORK_MODE_NR_LTE: 32, 42 PREFERRED_NETWORK_MODE_NR_LTE_WCDMA: 33, 43 PREFERRED_NETWORK_MODE_NR_LTE_WCDMA_GSM: 34, 44 PREFERRED_NETWORK_MODE_NR_LTE_EVDO_CDMA: 35, 45 PREFERRED_NETWORK_MODE_NR_LTE_WCDMA_GSM_EVDO_CDMA: 36, 46 PREFERRED_NETWORK_MODE_NR_LTE_TDSCDMA: 37, 47 PREFERRED_NETWORK_MODE_NR_LTE_TDSCDMA_GSM: 38, 48 PREFERRED_NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA: 39, 49 PREFERRED_NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA_GSM: 40, 50 PREFERRED_NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA_GSM_EVDO_CDMA: 41, 51 PREFERRED_NETWORK_MODE_MAX_VALUE: 99, 52}; 53export const RadioTechnology = { 54 RADIO_TECHNOLOGY_UNKNOWN: 0, 55 RADIO_TECHNOLOGY_GSM: 1, 56 RADIO_TECHNOLOGY_1XRTT: 2, 57 RADIO_TECHNOLOGY_WCDMA: 3, 58 RADIO_TECHNOLOGY_HSPA: 4, 59 RADIO_TECHNOLOGY_HSPAP: 5, 60 RADIO_TECHNOLOGY_TD_SCDMA: 6, 61 RADIO_TECHNOLOGY_EVDO: 7, 62 RADIO_TECHNOLOGY_EHRPD: 8, 63 RADIO_TECHNOLOGY_LTE: 9, 64 RADIO_TECHNOLOGY_LTE_CA: 10, 65 RADIO_TECHNOLOGY_IWLAN: 11, 66 RADIO_TECHNOLOGY_NR: 12 67} 68export const NetworkType = { 69 NETWORK_TYPE_UNKNOWN: "[PC Preview] unknow NETWORK_TYPE_UNKNOWN", 70 NETWORK_TYPE_GSM: "[PC Preview] unknow NETWORK_TYPE_GSM", 71 NETWORK_TYPE_CDMA: "[PC Preview] unknow NETWORK_TYPE_CDMA", 72 NETWORK_TYPE_WCDMA: "[PC Preview] unknow NETWORK_TYPE_WCDMA", 73 NETWORK_TYPE_TDSCDMA: "[PC Preview] unknow NETWORK_TYPE_TDSCDMA", 74 NETWORK_TYPE_LTE: "[PC Preview] unknow NETWORK_TYPE_LTE", 75 NETWORK_TYPE_NR: "[PC Preview] unknow NETWORK_TYPE_NR", 76}; 77export const WcdmaCellInformation = { 78 lac: "[PC Preview] unknow lac", 79 cellId: "[PC Preview] unknow cellId", 80 psc: "[PC Preview] unknow psc", 81 uarfcn: "[PC Preview] unknow uarfcn", 82 mcc: "[PC Preview] unknow mcc", 83 mnc: "[PC Preview] unknow mnc", 84} 85export const NetworkSelectionModeOptions = { 86 slotId: "[PC Preview] unknow slotId", 87 selectMode: NetworkSelectionMode, 88 networkInformation: NetworkInformation, 89 resumeSelection: "[PC Preview] unknow resumeSelection", 90} 91export const NsaState = { 92 NSA_STATE_NOT_SUPPORT: 1, 93 NSA_STATE_NO_DETECT: 2, 94 NSA_STATE_CONNECTED_DETECT: 3, 95 NSA_STATE_IDLE_DETECT: 4, 96 NSA_STATE_DUAL_CONNECTED: 5, 97 NSA_STATE_SA_ATTACHED: 6 98} 99export const NetworkInformation = { 100 operatorName: "[PC Preview] unknow operatorName", 101 operatorNumeric: "[PC Preview] unknow operatorNumeric", 102 state: NetworkInformationState, 103 radioTech: "[PC Preview] unknow radioTech", 104} 105export const NetworkInformationState = { 106 NETWORK_UNKNOWN: "[PC Preview] unknow NETWORK_UNKNOWN", 107 NETWORK_AVAILABLE: "[PC Preview] unknow NETWORK_AVAILABLE", 108 NETWORK_CURRENT: "[PC Preview] unknow NETWORK_CURRENT", 109 NETWORK_FORBIDDEN: "[PC Preview] unknow NETWORK_FORBIDDEN", 110} 111export const TdscdmaCellInformation = { 112 lac: "[PC Preview] unknow lac", 113 cellId: "[PC Preview] unknow cellId", 114 cpid: "[PC Preview] unknow cpid", 115 uarfcn: "[PC Preview] unknow uarfcn", 116 mcc: "[PC Preview] unknow mcc", 117 mnc: "[PC Preview] unknow mnc", 118} 119export const NetworkState = { 120 longOperatorName: "[PC Preview] unknow longOperatorName", 121 shortOperatorName: "[PC Preview] unknow shortOperatorName", 122 plmnNumeric: "[PC Preview] unknow plmnNumeric", 123 isRoaming: "[PC Preview] unknow isRoaming", 124 regState: RegState, 125 cfgTech: RadioTechnology, 126 nsaState: NsaState, 127 isCaActive: "[PC Preview] unknow isCaActive", 128 isEmergency: "[PC Preview] unknow isEmergency", 129} 130export const NrCellInformation = { 131 nrArfcn: "[PC Preview] unknow nrArfcn", 132 pci: "[PC Preview] unknow pci", 133 tac: "[PC Preview] unknow tac", 134 nci: "[PC Preview] unknow nci", 135 mcc: "[PC Preview] unknow mcc", 136 mnc: "[PC Preview] unknow mnc", 137} 138export const NetworkSelectionMode = { 139 NETWORK_SELECTION_UNKNOWN: "[PC Preview] unknow NETWORK_SELECTION_UNKNOWN", 140 NETWORK_SELECTION_AUTOMATIC: "[PC Preview] unknow NETWORK_SELECTION_AUTOMATIC", 141 NETWORK_SELECTION_MANUAL: "[PC Preview] unknow NETWORK_SELECTION_MANUAL", 142}; 143export const GsmCellInformation = { 144 lac: "[PC Preview] unknow lac", 145 cellId: "[PC Preview] unknow cellId", 146 arfcn: "[PC Preview] unknow arfcn", 147 bsic: "[PC Preview] unknow bsic", 148 mcc: "[PC Preview] unknow mcc", 149 mnc: "[PC Preview] unknow mnc", 150} 151export const LteCellInformation = { 152 cgi: "[PC Preview] unknow cgi", 153 pci: "[PC Preview] unknow pci", 154 tac: "[PC Preview] unknow tac", 155 earfcn: "[PC Preview] unknow earfcn", 156 bandwidth: "[PC Preview] unknow bandwidth", 157 mcc: "[PC Preview] unknow mcc", 158 mnc: "[PC Preview] unknow mnc", 159 isSupportEndc: "[PC Preview] unknow isSupportEndc", 160} 161export const RegState = { 162 REG_STATE_NO_SERVICE: 0, 163 REG_STATE_IN_SERVICE: 1, 164 REG_STATE_EMERGENCY_CALL_ONLY: 2, 165 REG_STATE_POWER_OFF: 3, 166}; 167export const CdmaCellInformation = { 168 baseId: "[PC Preview] unknow baseId", 169 latitude: "[PC Preview] unknow latitude", 170 longitude: "[PC Preview] unknow longitude", 171 nid: "[PC Preview] unknow nid", 172 sid: "[PC Preview] unknow sid" 173} 174export const NrOptionMode = { 175 NR_OPTION_UNKNOWN: "[PC Preview] unknow NR_OPTION_UNKNOWN", 176 NR_OPTION_NSA_ONLY: "[PC Preview] unknow NR_OPTION_NSA_ONLY", 177 NR_OPTION_SA_ONLY: "[PC Preview] unknow NR_OPTION_SA_ONLY", 178 NR_OPTION_NSA_AND_SA: "[PC Preview] unknow NR_OPTION_NSA_AND_SA", 179}; 180export const CellInformation = { 181 networkType: NetworkType, 182 isCamped: "[PC Preview] unknow isCamped", 183 timeStamp: "[PC Preview] unknow timeStamp", 184 signalInformation: SignalInformation, 185 data: CdmaCellInformation, 186}; 187export const SignalInformation = { 188 signalType: NetworkType, 189 signalLevel: "[PC Preview] unknow signalLevel", 190}; 191export const NetworkSearchResult = { 192 isNetworkSearchSuccess: "[PC Preview] unknow isNetworkSearchSuccess", 193 networkSearchResult: [NetworkInformation], 194} 195export function mockRadio() { 196 const radio = { 197 RegState, 198 NrOptionMode, 199 PreferredNetworkMode, 200 RadioTechnology, 201 NetworkType, 202 NetworkInformationState, 203 NsaState, 204 NetworkSelectionMode, 205 getRadioTech: function (...args) { 206 console.warn("telephony.radio.getRadioTech interface mocked in the Previewer. How this interface works on the Previewer may" + 207 " be different from that on a real device.") 208 const len = args.length 209 if (typeof args[len - 1] === 'function') { 210 args[len - 1].call(this, paramMock.businessErrorMock, { 211 psRadioTech: "[PC Preview] unknow psRadioTech", 212 csRadioTech: "[PC Preview] unknow csRadioTech" 213 }); 214 } else { 215 return new Promise((resolve, reject) => { 216 resolve({ 217 psRadioTech: "[PC Preview] unknow psRadioTech", 218 csRadioTech: "[PC Preview] unknow csRadioTech" 219 }); 220 }) 221 } 222 }, 223 getNetworkState: function (...args) { 224 console.warn("telephony.radio.getNetworkState interface mocked in the Previewer. How this interface works on the Previewer may" + 225 " be different from that on a real device.") 226 const len = args.length 227 if (typeof args[len - 1] === 'function') { 228 args[len - 1].call(this, NetworkState); 229 } else { 230 return new Promise((resolve, reject) => { 231 resolve(NetworkState); 232 }) 233 } 234 }, 235 sendUpdateCellLocationRequest: function (...args) { 236 console.warn("telephony.radio.sendUpdateCellLocationRequest interface mocked in the Previewer. How this interface works on the Previewer may" + 237 " be different from that on a real device.") 238 const len = args.length 239 if (typeof args[len - 1] === 'function') { 240 args[len - 1].call(this, paramMock.businessErrorMock); 241 } else { 242 return new Promise((resolve, reject) => { 243 resolve(); 244 }) 245 } 246 }, 247 setPrimarySlotId: function (...args) { 248 console.warn("telephony.radio.setPrimarySlotId interface mocked in the Previewer. How this interface works on the Previewer may" + 249 " be different from that on a real device.") 250 const len = args.length 251 if (typeof args[len - 1] === 'function') { 252 args[len - 1].call(this, paramMock.businessErrorMock); 253 } else { 254 return new Promise((resolve, reject) => { 255 resolve(); 256 }) 257 } 258 }, 259 getCellInformation: function (...args) { 260 console.warn("telephony.radio.getCellInformation interface mocked in the Previewer. How this interface works on the Previewer may" + 261 " be different from that on a real device.") 262 const len = args.length 263 if (typeof args[len - 1] === 'function') { 264 args[len - 1].call(this, paramMock.businessErrorMock, [CellInformation]); 265 } else { 266 return new Promise((resolve, reject) => { 267 resolve([CellInformation]); 268 }) 269 } 270 }, 271 getNetworkSelectionMode: function (...args) { 272 console.warn("telephony.radio.getNetworkSelectionMode interface mocked in the Previewer. How this interface works on the Previewer may" + 273 " be different from that on a real device.") 274 const len = args.length 275 if (typeof args[len - 1] === 'function') { 276 args[len - 1].call(this, paramMock.businessErrorMock, NetworkSelectionMode); 277 } else { 278 return new Promise((resolve, reject) => { 279 resolve(NetworkSelectionMode); 280 }) 281 } 282 }, 283 setNetworkSelectionMode: function (...args) { 284 console.warn("telephony.radio.setNetworkSelectionMode interface mocked in the Previewer. How this interface works on the Previewer may" + 285 " be different from that on a real device.") 286 const len = args.length 287 if (typeof args[len - 1] === 'function') { 288 args[len - 1].call(this, paramMock.businessErrorMock); 289 } else { 290 return new Promise((resolve, reject) => { 291 resolve(); 292 }) 293 } 294 }, 295 getNetworkSearchInformation: function (...args) { 296 console.warn("telephony.radio.getNetworkSearchInformation interface mocked in the Previewer. How this interface works on the Previewer may" + 297 " be different from that on a real device.") 298 const len = args.length 299 if (typeof args[len - 1] === 'function') { 300 args[len - 1].call(this, paramMock.businessErrorMock, NetworkSearchResult); 301 } else { 302 return new Promise((resolve, reject) => { 303 resolve(NetworkSearchResult); 304 }) 305 } 306 }, 307 getISOCountryCodeForNetwork: function (...args) { 308 console.warn("telephony.radio.getISOCountryCodeForNetwork interface mocked in the Previewer. How this interface works on the Previewer may" + 309 " be different from that on a real device.") 310 const len = args.length 311 if (typeof args[len - 1] === 'function') { 312 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 313 } else { 314 return new Promise((resolve, reject) => { 315 resolve(paramMock.paramStringMock); 316 }) 317 } 318 }, 319 getNrOptionMode: function (...args) { 320 console.warn("telephony.radio.getNrOptionMode interface mocked in the Previewer. How this interface works on the Previewer may" + 321 " be different from that on a real device.") 322 const len = args.length 323 if (typeof args[len - 1] === 'function') { 324 args[len - 1].call(this, paramMock.businessErrorMock, NrOptionMode); 325 } else { 326 return new Promise((resolve, reject) => { 327 resolve(NrOptionMode); 328 }) 329 } 330 }, 331 getIMEI: function (...args) { 332 console.warn("telephony.radio.getIMEI interface mocked in the Previewer. How this interface works on the Previewer may" + 333 " be different from that on a real device.") 334 const len = args.length 335 if (typeof args[len - 1] === 'function') { 336 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 337 } else { 338 return new Promise((resolve, reject) => { 339 resolve(paramMock.paramStringMock); 340 }) 341 } 342 }, 343 getMEID: function (...args) { 344 console.warn("telephony.radio.getMEID interface mocked in the Previewer. How this interface works on the Previewer may" + 345 " be different from that on a real device.") 346 const len = args.length 347 if (typeof args[len - 1] === 'function') { 348 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 349 } else { 350 return new Promise((resolve, reject) => { 351 resolve(paramMock.paramStringMock); 352 }) 353 } 354 }, 355 getUniqueDeviceId: function (...args) { 356 console.warn("telephony.radio.getUniqueDeviceId interface mocked in the Previewer. How this interface works on the Previewer may" + 357 " be different from that on a real device.") 358 const len = args.length 359 if (typeof args[len - 1] === 'function') { 360 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 361 } else { 362 return new Promise((resolve, reject) => { 363 resolve(paramMock.paramStringMock); 364 }) 365 } 366 }, 367 getPrimarySlotId: function (...args) { 368 console.warn("telephony.radio.getPrimarySlotId interface mocked in the Previewer. How this interface works on the Previewer may" + 369 " be different from that on a real device.") 370 const len = args.length 371 if (typeof args[len - 1] === 'function') { 372 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 373 } else { 374 return new Promise((resolve, reject) => { 375 resolve(paramMock.paramNumberMock); 376 }) 377 } 378 }, 379 getSignalInformation: function (...args) { 380 console.warn("telephony.radio.getSignalInformation interface mocked in the Previewer. How this interface works on the Previewer may" + 381 " be different from that on a real device.") 382 const len = args.length 383 if (typeof args[len - 1] === 'function') { 384 args[len - 1].call(this, paramMock.businessErrorMock, [SignalInformation]); 385 } else { 386 return new Promise((resolve, reject) => { 387 resolve([SignalInformation]); 388 }) 389 } 390 }, 391 isNrSupported: function () { 392 console.warn("telephony.radio.isNrSupported interface mocked in the Previewer. How this interface works on the Previewer may" + 393 " be different from that on a real device.") 394 return paramMock.paramBooleanMock; 395 }, 396 isRadioOn: function (...args) { 397 console.warn("telephony.radio.isRadioOn interface mocked in the Previewer. How this interface works on the Previewer may" + 398 " be different from that on a real device.") 399 const len = args.length 400 if (typeof args[len - 1] === 'function') { 401 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 402 } else { 403 return new Promise((resolve, reject) => { 404 resolve(paramMock.paramBooleanMock); 405 }) 406 } 407 }, 408 turnOnRadio: function (...args) { 409 console.warn("telephony.radio.turnOnRadio interface mocked in the Previewer. How this interface works on the Previewer may" + 410 " be different from that on a real device.") 411 const len = args.length 412 if (typeof args[len - 1] === 'function') { 413 args[len - 1].call(this, paramMock.businessErrorMock); 414 } else { 415 return new Promise((resolve, reject) => { 416 resolve(); 417 }) 418 } 419 }, 420 turnOffRadio: function (...args) { 421 console.warn("telephony.radio.turnOffRadio interface mocked in the Previewer. How this interface works on the Previewer may" + 422 " be different from that on a real device.") 423 const len = args.length 424 if (typeof args[len - 1] === 'function') { 425 args[len - 1].call(this, paramMock.businessErrorMock); 426 } else { 427 return new Promise((resolve, reject) => { 428 resolve(); 429 }) 430 } 431 }, 432 getOperatorName: function (...args) { 433 console.warn("telephony.radio.getOperatorName interface mocked in the Previewer. How this interface works on the Previewer may" + 434 " be different from that on a real device.") 435 const len = args.length 436 if (typeof args[len - 1] === 'function') { 437 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 438 } else { 439 return new Promise((resolve, reject) => { 440 resolve(paramMock.paramStringMock); 441 }) 442 } 443 }, 444 setPreferredNetwork: function (...args) { 445 console.warn("telephony.radio.setPreferredNetwork interface mocked in the Previewer. How this interface works on the Previewer may" + 446 " be different from that on a real device.") 447 const len = args.length 448 if (typeof args[len - 1] === 'function') { 449 args[len - 1].call(this, paramMock.businessErrorMock); 450 } else { 451 return new Promise((resolve, reject) => { 452 resolve(); 453 }) 454 } 455 }, 456 getPreferredNetwork: function (...args) { 457 console.warn("telephony.radio.getPreferredNetwork interface mocked in the Previewer. How this interface works on the Previewer may" + 458 " be different from that on a real device.") 459 const len = args.length 460 if (typeof args[len - 1] === 'function') { 461 args[len - 1].call(this, paramMock.businessErrorMock, PreferredNetworkMode); 462 } else { 463 return new Promise((resolve, reject) => { 464 resolve(PreferredNetworkMode); 465 }) 466 } 467 }, 468 getIMEISV: function (...args) { 469 console.warn("telephony.radio.getIMEISV interface mocked in the Previewer. How this interface works on the Previewer may" + 470 " be different from that on a real device.") 471 const len = args.length 472 if (typeof args[len - 1] === 'function') { 473 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 474 } else { 475 return new Promise((resolve, reject) => { 476 resolve(paramMock.paramStringMock); 477 }) 478 } 479 } 480 } 481 return radio 482}