1/* 2 * Copyright (c) 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 18const NetworkState = { 19 longOperatorName: "[PC Preview] unknow longOperatorName", 20 shortOperatorName: "[PC Preview] unknow shortOperatorName", 21 plmnNumeric: "[PC Preview] unknow plmnNumeric", 22 isRoaming: "[PC Preview] unknow isRoaming", 23 regState: "[PC Preview] unknow regState", 24 nsaState: "[PC Preview] unknow nsaState", 25 isCaActive: "[PC Preview] unknow isCaActive", 26 isEmergency: "[PC Preview] unknow isEmergency", 27} 28const SignalInformation = { 29 signalType: "[PC Preview] unknow signalType", 30 signalLevel: "[PC Preview] unknow signalLevel" 31} 32const DataFlowType = "[PC Preview] unknow DataFlowType" 33const DataConnectState = "[PC Preview] unknow DataConnectState" 34const CellInformation = { 35 networkType: "[PC Preview] unknow networkType", 36 isCamped: "[PC Preview] unknow isCamped", 37 timeStamp: "[PC Preview] unknow timeStamp", 38 signalInformation: "[PC Preview] unknow signalInformation", 39 data: "[PC Preview] unknow unkown data" 40} 41export function mockRadio() { 42 const NetworkSearchResult = { 43 isNetworkSearchSuccess: "[PC Preview] unknow isNetworkSearchSuccess", 44 networkSearchResult: [{ 45 operatorName: "[PC Preview] unknow operatorName", 46 operatorNumeric: "[PC Preview] unknow operatorNumeric", 47 state: "[PC Preview] unknow state", 48 radioTech: "[PC Preview] unknow radioTech" 49 }] 50 } 51 const PreferredNetworkMode = "[PC Preview] unknow PreferredNetworkMode" 52 const NrOptionMode = "[PC Preview] unknow NrOptionMode" 53 const NetworkSelectionMode = "[PC Preview] unknow unkown NetworkSelectionMode" 54 const radio = { 55 getRadioTech: function (...args) { 56 console.warn("telephony.radio.getRadioTech interface mocked in the Previewer. How this interface works on the Previewer may" + 57 " be different from that on a real device.") 58 const len = args.length 59 if (typeof args[len - 1] === 'function') { 60 args[len - 1].call(this, paramMock.businessErrorMock, { 61 psRadioTech: "[PC Preview] unknow psRadioTech", 62 csRadioTech: "[PC Preview] unknow csRadioTech" 63 }); 64 } else { 65 return new Promise((resolve, reject) => { 66 resolve({ 67 psRadioTech: "[PC Preview] unknow psRadioTech", 68 csRadioTech: "[PC Preview] unknow csRadioTech" 69 }); 70 }) 71 } 72 }, 73 getNetworkState: function (...args) { 74 console.warn("telephony.radio.getNetworkState interface mocked in the Previewer. How this interface works on the Previewer may" + 75 " be different from that on a real device.") 76 const len = args.length 77 if (typeof args[len - 1] === 'function') { 78 args[len - 1].call(this, paramMock.businessErrorMock, NetworkState); 79 } else { 80 return new Promise((resolve, reject) => { 81 resolve(NetworkState); 82 }) 83 } 84 }, 85 sendUpdateCellLocationRequest: function (...args) { 86 console.warn("telephony.radio.sendUpdateCellLocationRequest interface mocked in the Previewer. How this interface works on the Previewer may" + 87 " be different from that on a real device.") 88 const len = args.length 89 if (typeof args[len - 1] === 'function') { 90 args[len - 1].call(this, paramMock.businessErrorMock); 91 } else { 92 return new Promise((resolve, reject) => { 93 resolve(); 94 }) 95 } 96 }, 97 getCellInformation: function (...args) { 98 console.warn("telephony.radio.getCellInformation interface mocked in the Previewer. How this interface works on the Previewer may" + 99 " be different from that on a real device.") 100 const len = args.length 101 if (typeof args[len - 1] === 'function') { 102 args[len - 1].call(this, paramMock.businessErrorMock, [CellInformation]); 103 } else { 104 return new Promise((resolve, reject) => { 105 resolve([CellInformation]); 106 }) 107 } 108 }, 109 getNetworkSelectionMode: function (...args) { 110 console.warn("telephony.radio.getNetworkSelectionMode interface mocked in the Previewer. How this interface works on the Previewer may" + 111 " be different from that on a real device.") 112 const len = args.length 113 if (typeof args[len - 1] === 'function') { 114 args[len - 1].call(this, paramMock.businessErrorMock, NetworkSelectionMode); 115 } else { 116 return new Promise((resolve, reject) => { 117 resolve(NetworkSelectionMode); 118 }) 119 } 120 }, 121 setNetworkSelectionMode: function (...args) { 122 console.warn("telephony.radio.setNetworkSelectionMode interface mocked in the Previewer. How this interface works on the Previewer may" + 123 " be different from that on a real device.") 124 const len = args.length 125 if (typeof args[len - 1] === 'function') { 126 args[len - 1].call(this, paramMock.businessErrorMock); 127 } else { 128 return new Promise((resolve, reject) => { 129 resolve(); 130 }) 131 } 132 }, 133 getNetworkSearchInformation: function (...args) { 134 console.warn("telephony.radio.getNetworkSearchInformation interface mocked in the Previewer. How this interface works on the Previewer may" + 135 " be different from that on a real device.") 136 const len = args.length 137 if (typeof args[len - 1] === 'function') { 138 args[len - 1].call(this, paramMock.businessErrorMock, NetworkSearchResult); 139 } else { 140 return new Promise((resolve, reject) => { 141 resolve(NetworkSearchResult); 142 }) 143 } 144 }, 145 getISOCountryCodeForNetwork: function (...args) { 146 console.warn("telephony.radio.getISOCountryCodeForNetwork interface mocked in the Previewer. How this interface works on the Previewer may" + 147 " be different from that on a real device.") 148 const len = args.length 149 if (typeof args[len - 1] === 'function') { 150 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 151 } else { 152 return new Promise((resolve, reject) => { 153 resolve(paramMock.paramStringMock); 154 }) 155 } 156 }, 157 getNrOptionMode: function (...args) { 158 console.warn("telephony.radio.getNrOptionMode interface mocked in the Previewer. How this interface works on the Previewer may" + 159 " be different from that on a real device.") 160 const len = args.length 161 if (typeof args[len - 1] === 'function') { 162 args[len - 1].call(this, paramMock.businessErrorMock, NrOptionMode); 163 } else { 164 return new Promise((resolve, reject) => { 165 resolve(NrOptionMode); 166 }) 167 } 168 }, 169 getIMEI: function (...args) { 170 console.warn("telephony.radio.getIMEI interface mocked in the Previewer. How this interface works on the Previewer may" + 171 " be different from that on a real device.") 172 const len = args.length 173 if (typeof args[len - 1] === 'function') { 174 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 175 } else { 176 return new Promise((resolve, reject) => { 177 resolve(paramMock.paramStringMock); 178 }) 179 } 180 }, 181 getMEID: function (...args) { 182 console.warn("telephony.radio.getMEID interface mocked in the Previewer. How this interface works on the Previewer may" + 183 " be different from that on a real device.") 184 const len = args.length 185 if (typeof args[len - 1] === 'function') { 186 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 187 } else { 188 return new Promise((resolve, reject) => { 189 resolve(paramMock.paramStringMock); 190 }) 191 } 192 }, 193 getUniqueDeviceId: function (...args) { 194 console.warn("telephony.radio.getUniqueDeviceId interface mocked in the Previewer. How this interface works on the Previewer may" + 195 " be different from that on a real device.") 196 const len = args.length 197 if (typeof args[len - 1] === 'function') { 198 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 199 } else { 200 return new Promise((resolve, reject) => { 201 resolve(paramMock.paramStringMock); 202 }) 203 } 204 }, 205 getPrimarySlotId: function (...args) { 206 console.warn("telephony.radio.getPrimarySlotId 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, paramMock.paramNumberMock); 211 } else { 212 return new Promise((resolve, reject) => { 213 resolve(paramMock.paramNumberMock); 214 }) 215 } 216 }, 217 getSignalInformation: function (...args) { 218 console.warn("telephony.radio.getSignalInformation interface mocked in the Previewer. How this interface works on the Previewer may" + 219 " be different from that on a real device.") 220 const len = args.length 221 if (typeof args[len - 1] === 'function') { 222 args[len - 1].call(this, paramMock.businessErrorMock, [SignalInformation]); 223 } else { 224 return new Promise((resolve, reject) => { 225 resolve([SignalInformation]); 226 }) 227 } 228 }, 229 isNrSupported: function () { 230 console.warn("telephony.radio.isNrSupported interface mocked in the Previewer. How this interface works on the Previewer may" + 231 " be different from that on a real device.") 232 return paramMock.paramBooleanMock; 233 }, 234 isRadioOn: function (...args) { 235 console.warn("telephony.radio.isRadioOn interface mocked in the Previewer. How this interface works on the Previewer may" + 236 " be different from that on a real device.") 237 const len = args.length 238 if (typeof args[len - 1] === 'function') { 239 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 240 } else { 241 return new Promise((resolve, reject) => { 242 resolve(paramMock.paramBooleanMock); 243 }) 244 } 245 }, 246 turnOnRadio: function (...args) { 247 console.warn("telephony.radio.turnOnRadio interface mocked in the Previewer. How this interface works on the Previewer may" + 248 " be different from that on a real device.") 249 const len = args.length 250 if (typeof args[len - 1] === 'function') { 251 args[len - 1].call(this, paramMock.businessErrorMock); 252 } else { 253 return new Promise((resolve, reject) => { 254 resolve(); 255 }) 256 } 257 }, 258 turnOffRadio: function (...args) { 259 console.warn("telephony.radio.turnOffRadio interface mocked in the Previewer. How this interface works on the Previewer may" + 260 " be different from that on a real device.") 261 const len = args.length 262 if (typeof args[len - 1] === 'function') { 263 args[len - 1].call(this, paramMock.businessErrorMock); 264 } else { 265 return new Promise((resolve, reject) => { 266 resolve(); 267 }) 268 } 269 }, 270 getOperatorName: function (...args) { 271 console.warn("telephony.radio.getOperatorName interface mocked in the Previewer. How this interface works on the Previewer may" + 272 " be different from that on a real device.") 273 const len = args.length 274 if (typeof args[len - 1] === 'function') { 275 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 276 } else { 277 return new Promise((resolve, reject) => { 278 resolve(paramMock.paramStringMock); 279 }) 280 } 281 }, 282 setPreferredNetwork: function (...args) { 283 console.warn("telephony.radio.setPreferredNetwork interface mocked in the Previewer. How this interface works on the Previewer may" + 284 " be different from that on a real device.") 285 const len = args.length 286 if (typeof args[len - 1] === 'function') { 287 args[len - 1].call(this, paramMock.businessErrorMock); 288 } else { 289 return new Promise((resolve, reject) => { 290 resolve(); 291 }) 292 } 293 }, 294 getPreferredNetwork: function (...args) { 295 console.warn("telephony.radio.getPreferredNetwork interface mocked in the Previewer. How this interface works on the Previewer may" + 296 " be different from that on a real device.") 297 const len = args.length 298 if (typeof args[len - 1] === 'function') { 299 args[len - 1].call(this, paramMock.businessErrorMock, PreferredNetworkMode); 300 } else { 301 return new Promise((resolve, reject) => { 302 resolve(PreferredNetworkMode); 303 }) 304 } 305 }, 306 getIMEISV: function (...args) { 307 console.warn("telephony.radio.getIMEISV interface mocked in the Previewer. How this interface works on the Previewer may" + 308 " be different from that on a real device.") 309 const len = args.length 310 if (typeof args[len - 1] === 'function') { 311 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 312 } else { 313 return new Promise((resolve, reject) => { 314 resolve(paramMock.paramStringMock); 315 }) 316 } 317 } 318 } 319 return radio 320}