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 mockUpdate() { 19 const Updater = { 20 checkNewVersion: function (...args) { 21 console.warn("Updater.checkNewVersion interface mocked in the Previewer. How this interface works on the" + 22 " Previewer may be different from that on a real device.") 23 const len = args.length 24 if (len > 0 && typeof args[len - 1] === 'function') { 25 args[len - 1].call(this, paramMock.businessErrorMock, CheckResult); 26 } else { 27 return new Promise((resolve, reject) => { 28 resolve(CheckResult); 29 }) 30 } 31 }, 32 getNewVersionInfo: function (...args) { 33 console.warn("Updater.getNewVersionInfo interface mocked in the Previewer. How this interface works" + 34 " on the Previewer may be different from that on a real device.") 35 const len = args.length 36 if (len > 0 && typeof args[len - 1] === 'function') { 37 args[len - 1].call(this, paramMock.businessErrorMock, NewVersionInfo); 38 } else { 39 return new Promise((resolve, reject) => { 40 resolve(NewVersionInfo); 41 }) 42 } 43 }, 44 getNewVersionDescription: function (...args) { 45 console.warn("Updater.getNewVersionDescription interface mocked in the Previewer. How this interface works" + 46 " on the Previewer may be different from that on a real device.") 47 const len = args.length 48 if (len > 0 && typeof args[len - 1] === 'function') { 49 args[len - 1].call(this, paramMock.businessErrorMock, [ComponentDescription]); 50 } else { 51 return new Promise((resolve, reject) => { 52 resolve([ComponentDescription]); 53 }) 54 } 55 }, 56 getCurrentVersionInfo: function (...args) { 57 console.warn("Updater.getCurrentVersionInfo interface mocked in the Previewer. How this interface works" + 58 " on the Previewer may be different from that on a real device.") 59 const len = args.length 60 if (len > 0 && typeof args[len - 1] === 'function') { 61 args[len - 1].call(this, paramMock.businessErrorMock, CurrentVersionInfo); 62 } else { 63 return new Promise((resolve, reject) => { 64 resolve(CurrentVersionInfo); 65 }) 66 } 67 }, 68 getCurrentVersionDescription: function (...args) { 69 console.warn("Updater.getCurrentVersionDescription interface mocked in the Previewer. How this interface works" + 70 " on the Previewer may be different from that on a real device.") 71 const len = args.length 72 if (len > 0 && typeof args[len - 1] === 'function') { 73 args[len - 1].call(this, paramMock.businessErrorMock, [ComponentDescription]); 74 } else { 75 return new Promise((resolve, reject) => { 76 resolve([ComponentDescription]); 77 }) 78 } 79 }, 80 getTaskInfo: function (...args) { 81 console.warn("Updater.getTaskInfo interface mocked in the Previewer. How this interface works on the" + 82 " Previewer may be different from that on a real device.") 83 const len = args.length 84 if (len > 0 && typeof args[len - 1] === 'function') { 85 args[len - 1].call(this, paramMock.businessErrorMock, TaskInfo); 86 } else { 87 return new Promise((resolve, reject) => { 88 resolve(TaskInfo); 89 }) 90 } 91 }, 92 download: function (...args) { 93 console.warn("Updater.download interface mocked in the Previewer. How this interface works on the" + 94 " Previewer may be different from that on a real device.") 95 const len = args.length 96 if (len > 0 && typeof args[len - 1] === 'function') { 97 args[len - 1].call(this, paramMock.businessErrorMock); 98 } else { 99 return new Promise((resolve, reject) => { 100 resolve(); 101 }) 102 } 103 }, 104 resumeDownload: function (...args) { 105 console.warn("Updater.resumeDownload interface mocked in the Previewer. How this interface works on the" + 106 " Previewer may be different from that on a real device.") 107 const len = args.length 108 if (len > 0 && typeof args[len - 1] === 'function') { 109 args[len - 1].call(this, paramMock.businessErrorMock); 110 } else { 111 return new Promise((resolve, reject) => { 112 resolve(); 113 }) 114 } 115 }, 116 pauseDownload: function (...args) { 117 console.warn("Updater.pauseDownload interface mocked in the Previewer. How this interface works on the" + 118 " Previewer may be different from that on a real device.") 119 const len = args.length 120 if (len > 0 && typeof args[len - 1] === 'function') { 121 args[len - 1].call(this, paramMock.businessErrorMock); 122 } else { 123 return new Promise((resolve, reject) => { 124 resolve(); 125 }) 126 } 127 }, 128 upgrade: function (...args) { 129 console.warn("Updater.upgrade interface mocked in the Previewer. How this interface works on the" + 130 " Previewer may be different from that on a real device.") 131 const len = args.length 132 if (len > 0 && typeof args[len - 1] === 'function') { 133 args[len - 1].call(this, paramMock.businessErrorMock); 134 } else { 135 return new Promise((resolve, reject) => { 136 resolve(); 137 }) 138 } 139 }, 140 clearError: function (...args) { 141 console.warn("Updater.clearError interface mocked in the Previewer. How this interface works on the" + 142 " Previewer may be different from that on a real device.") 143 const len = args.length 144 if (len > 0 && typeof args[len - 1] === 'function') { 145 args[len - 1].call(this, paramMock.businessErrorMock); 146 } else { 147 return new Promise((resolve, reject) => { 148 resolve(); 149 }) 150 } 151 }, 152 getUpgradePolicy: function (...args) { 153 console.warn("Updater.getUpgradePolicy interface mocked in the Previewer. How this interface works on the" + 154 " Previewer may be different from that on a real device.") 155 const len = args.length 156 if (len > 0 && typeof args[len - 1] === 'function') { 157 args[len - 1].call(this, paramMock.businessErrorMock, UpgradePolicy); 158 } else { 159 return new Promise((resolve, reject) => { 160 resolve(UpgradePolicy); 161 }) 162 } 163 }, 164 setUpgradePolicy: function (...args) { 165 console.warn("Updater.setUpgradePolicy interface mocked in the Previewer. How this interface works on the" + 166 " Previewer may be different from that on a real device.") 167 const len = args.length 168 if (len > 0 && typeof args[len - 1] === 'function') { 169 args[len - 1].call(this, paramMock.businessErrorMock); 170 } else { 171 return new Promise((resolve, reject) => { 172 resolve(); 173 }) 174 } 175 }, 176 terminateUpgrade: function (...args) { 177 console.warn("Updater.terminateUpgrade interface mocked in the Previewer. How this interface works on the" + 178 " Previewer may be different from that on a real device.") 179 const len = args.length 180 if (len > 0 && typeof args[len - 1] === 'function') { 181 args[len - 1].call(this, paramMock.businessErrorMock); 182 } else { 183 return new Promise((resolve, reject) => { 184 resolve(); 185 }) 186 } 187 }, 188 on: function (...args) { 189 console.warn("Updater.on interface mocked in the Previewer. How this interface works on the" + 190 " Previewer may be different from that on a real device.") 191 const len = args.length 192 if (len > 0 && typeof args[len - 1] === 'function') { 193 args[len - 1].call(this, EventInfo); 194 } 195 }, 196 off: function (...args) { 197 console.warn("Updater.off interface mocked in the Previewer. How this interface works on the" + 198 " Previewer may be different from that on a real device.") 199 const len = args.length 200 if (len > 0 && typeof args[len - 1] === 'function') { 201 args[len - 1].call(this, EventInfo); 202 } 203 }, 204 } 205 const Restorer = { 206 factoryReset: function (...args) { 207 console.warn("Restorer.factoryReset interface mocked in the Previewer. How this interface works on the" + 208 " Previewer may be different from that on a real device.") 209 const len = args.length 210 if (len > 0 && typeof args[len - 1] === 'function') { 211 args[len - 1].call(this, paramMock.businessErrorMock); 212 } else { 213 return new Promise((resolve, reject) => { 214 resolve(); 215 }) 216 } 217 }, 218 } 219 const LocalUpdater = { 220 verifyUpgradePackage: function (...args) { 221 console.warn("LocalUpdater.verifyUpgradePackage interface mocked in the Previewer. How this interface" + 222 " works on the Previewer may be different from that on a real device.") 223 const len = args.length 224 if (len > 0 && typeof args[len - 1] === 'function') { 225 args[len - 1].call(this, paramMock.businessErrorMock); 226 } else { 227 return new Promise((resolve, reject) => { 228 resolve(); 229 }) 230 } 231 }, 232 applyNewVersion: function (...args) { 233 console.warn("LocalUpdater.applyNewVersion interface mocked in the Previewer. How this interface works" + 234 " on the Previewer may be different from that on a real device.") 235 const len = args.length 236 if (len > 0 && typeof args[len - 1] === 'function') { 237 args[len - 1].call(this, paramMock.businessErrorMock); 238 } else { 239 return new Promise((resolve, reject) => { 240 resolve(); 241 }) 242 } 243 }, 244 on: function (...args) { 245 console.warn("LocalUpdater.on interface mocked in the Previewer. How this interface works on the" + 246 " Previewer may be different from that on a real device.") 247 const len = args.length 248 if (len > 0 && typeof args[len - 1] === 'function') { 249 args[len - 1].call(this, EventInfo); 250 } 251 }, 252 off: function (...args) { 253 console.warn("LocalUpdater.off interface mocked in the Previewer. How this interface works on the" + 254 " Previewer may be different from that on a real device.") 255 const len = args.length 256 if (len > 0 && typeof args[len - 1] === 'function') { 257 args[len - 1].call(this, EventInfo); 258 } 259 }, 260 } 261 const update = { 262 BusinessVendor, 263 BusinessSubType, 264 ComponentType, 265 UpgradeAction, 266 EffectiveMode, 267 DescriptionType, 268 NetType, 269 Order, 270 UpgradeStatus, 271 EventClassify, 272 EventId, 273 UpgradeInfo, 274 BusinessType, 275 DownloadOptions, 276 ResumeDownloadOptions, 277 PauseDownloadOptions, 278 UpgradeOptions, 279 ClearOptions, 280 EventClassifyInfo, 281 UpgradeFile, 282 DescriptionOptions, 283 DescriptionFormat, 284 getOnlineUpdater: function (...args) { 285 console.warn("update.getOnlineUpdater interface mocked in the Previewer. How this interface works on the" + 286 " Previewer may be different from that on a real device.") 287 return Updater; 288 }, 289 getRestorer: function (...args) { 290 console.warn("update.getRestorer interface mocked in the Previewer. How this interface works on the" + 291 " Previewer may be different from that on a real device.") 292 return Restorer; 293 }, 294 getLocalUpdater: function (...args) { 295 console.warn("update.getLocalUpdater interface mocked in the Previewer. How this interface works on the" + 296 " Previewer may be different from that on a real device.") 297 return LocalUpdater; 298 } 299 } 300 return update; 301} 302 303const BusinessVendor = { 304 PUBLIC: "public", 305} 306 307const BusinessSubType = { 308 FIRMWARE: 1, 309} 310 311const ComponentType = { 312 OTA: 1, 313} 314 315const UpgradeAction = { 316 UPGRADE: "upgrade", 317 RECOVERY: "recovery", 318} 319 320const EffectiveMode = { 321 COLD: 1, 322 LIVE: 2, 323 LIVE_AND_COLD: 3, 324} 325 326const DescriptionType = { 327 CONTENT: 0, 328 URI: 1, 329} 330 331const NetType = { 332 CELLULAR: 1, 333 METERED_WIFI: 2, 334 NOT_METERED_WIFI: 4, 335 WIFI: 6, 336 CELLULAR_AND_WIFI: 7 337} 338 339const Order = { 340 DOWNLOAD: 1, 341 INSTALL: 2, 342 DOWNLOAD_AND_INSTALL: 3, 343 APPLY: 4, 344 INSTALL_AND_APPLY: 6 345} 346 347const UpgradeStatus = { 348 WAITING_DOWNLOAD: 20, 349 DOWNLOADING: 21, 350 DOWNLOAD_PAUSED: 22, 351 DOWNLOAD_FAIL: 23, 352 WAITING_INSTALL: 30, 353 UPDATING: 31, 354 WAITING_APPLY: 40, 355 APPLYING: 41, 356 UPGRADE_SUCCESS: 50, 357 UPGRADE_FAIL: 51, 358} 359 360const EventClassify = { 361 TASK: 0x01000000, 362} 363 364const EventId = { 365 EVENT_TASK_BASE: 0x01000000, 366 EVENT_TASK_RECEIVE: 0x01000001, 367 EVENT_TASK_CANCEL: 0x01000010, 368 EVENT_DOWNLOAD_WAIT: 0x01000011, 369 EVENT_DOWNLOAD_START: 0x01000100, 370 EVENT_DOWNLOAD_UPDATE: 0x01000101, 371 EVENT_DOWNLOAD_PAUSE: 0x01000110, 372 EVENT_DOWNLOAD_RESUME: 0x01000111, 373 EVENT_DOWNLOAD_SUCCESS: 0x01001000, 374 EVENT_DOWNLOAD_FAIL: 0x01001001, 375 EVENT_UPGRADE_WAIT: 0x01001010, 376 EVENT_UPGRADE_START: 0x01001011, 377 EVENT_UPGRADE_UPDATE: 0x01001100, 378 EVENT_APPLY_WAIT: 0x01001101, 379 EVENT_APPLY_START: 0x01001110, 380 EVENT_UPGRADE_SUCCESS: 0x01001111, 381 EVENT_UPGRADE_FAIL: 0x01010000, 382} 383 384const VersionDigestInfo = { 385 versionDigest: "[PC Preview] unknown versionDigest", 386} 387 388const DescriptionInfo = { 389 descriptionType: DescriptionType.CONTENT, 390 content: "[PC Preview] unknown content", 391} 392 393const VersionComponent = { 394 componentId: "[PC Preview] unknown componentId", 395 componentType: ComponentType.OTA, 396 upgradeAction: UpgradeAction.UPGRADE, 397 displayVersion: "[PC Preview] unknown displayVersion", 398 innerVersion: "[PC Preview] unknown innerVersion", 399 size: "[PC Preview] unknown size", 400 effectiveMode: EffectiveMode.COLD, 401 descriptionInfo: DescriptionInfo, 402} 403 404const NewVersionInfo = { 405 versionDigestInfo: VersionDigestInfo, 406 versionComponents: [VersionComponent], 407} 408 409const CheckResult = { 410 isExistNewVersion: "[PC Preview] unknown isExistNewVersion", 411 newVersionInfo: NewVersionInfo, 412} 413 414const CurrentVersionInfo = { 415 osVersion: "[PC Preview] unknown osVersion", 416 deviceName: "[PC Preview] unknown deviceName", 417 versionComponents: [VersionComponent], 418} 419 420const UpgradePeriod = { 421 start: "[PC Preview] unknown start", 422 end: "[PC Preview] unknown end", 423} 424 425const UpgradePolicy = { 426 downloadStrategy: "[PC Preview] unknown downloadStrategy", 427 autoUpgradeStrategy: "[PC Preview] unknown autoUpgradeStrategy", 428 autoUpgradePeriods: [UpgradePeriod], 429} 430 431const ErrorMessage = { 432 errorCode: "[PC Preview] unknown errorCode", 433 errorMessage: "[PC Preview] unknown errorMessage", 434} 435 436const TaskBody = { 437 versionDigestInfo: VersionDigestInfo, 438 status: UpgradeStatus.WAITING_DOWNLOAD, 439 subStatus: "[PC Preview] unknown subStatus", 440 progress: "[PC Preview] unknown progress", 441 installMode: "[PC Preview] unknown installMode", 442 errorMessages: [ErrorMessage], 443 versionComponents: [VersionComponent], 444} 445 446const TaskInfo = { 447 existTask: "[PC Preview] unknown existTask", 448 taskBody: TaskBody, 449} 450 451const EventInfo = { 452 eventId: EventId.EVENT_TASK_RECEIVE, 453 taskBody: TaskBody, 454} 455 456const UpgradeInfo = { 457 upgradeApp: "[PC Preview] unknown upgradeApp", 458 businessType: BusinessType 459} 460 461const BusinessType = { 462 vendor: BusinessVendor, 463 subType: BusinessSubType 464} 465 466const DownloadOptions = { 467 allowNetwork: NetType, 468 order: Order 469} 470 471const ResumeDownloadOptions = { 472 allowNetwork: NetType 473} 474 475const PauseDownloadOptions = { 476 isAllowAutoResume: true 477} 478 479const UpgradeOptions = { 480 order: Order 481} 482 483const ClearOptions = { 484 status: UpgradeStatus 485} 486 487const EventClassifyInfo = { 488 eventClassify: EventClassify, 489 extraInfo: "[PC Preview] unknown extraInfo" 490} 491 492const UpgradeFile = { 493 fileType: ComponentType, 494 filePath: "[PC Preview] unknown filePath" 495} 496 497const DescriptionOptions = { 498 format: DescriptionFormat, 499 language: "[PC Preview] unknown language", 500} 501 502const ComponentDescription = { 503 componentId: "[PC Preview] unknown componentId", 504 descriptionInfo: DescriptionInfo, 505} 506 507const DescriptionFormat = { 508 STANDARD: 0, 509 SIMPLIFIED : 1, 510}