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" 17import { windowMock } from "./napi/ohos_window" 18 19const DataAbilityResultMock = { 20 uri: "[PC Preview] unknow uri", 21 count: "[PC Preview] unknow count" 22} 23const DataAbilityResultArrayMock = [ 24 DataAbilityResultMock 25] 26const getFileTypesArrayMock = [ 27 paramMock.paramStringMock 28] 29const PacMapTypeMock = { 30 PacMap: new Map([["[PC Preview] unknow PacMapKey", "[PC Preview] unknow PacMapValue"]]) 31} 32const ResultSetMock = { 33 columnNames: "[PC Preview] unknow columnNames", 34 columnCount: "[PC Preview] unknow columnCount", 35 rowCount: "[PC Preview] unknow rowCount", 36 rowIndex: "[PC Preview] unknow rowIndex", 37 isAtFirstRow: "[PC Preview] unknow isAtFirstRow", 38 isAtLastRow: "[PC Preview] unknow isAtLastRow", 39 isEnded: "[PC Preview] unknow isEnded", 40 isStarted: "[PC Preview] unknow isStarted", 41 isClose: "[PC Preview] unknow isClose", 42 getColumnIndex: function (...args) { 43 console.warn("ResultSet.getColumnIndex interface mocked in the Previewer. How this interface works on the Previewer" + 44 " may be different from that on a real device.") 45 return paramMock.paramNumberMock; 46 }, 47 getColumnName: function (...args) { 48 console.warn("ResultSet.getColumnName interface mocked in the Previewer. How this interface works on the Previewer" + 49 " may be different from that on a real device.") 50 return paramMock.paramStringMock; 51 }, 52 goTo: function (...args) { 53 console.warn("ResultSet.goTo interface mocked in the Previewer. How this interface works on the Previewer" + 54 " may be different from that on a real device.") 55 return paramMock.paramBooleanMock; 56 }, 57 goToRow: function (...args) { 58 console.warn("ResultSet.goToRow interface mocked in the Previewer. How this interface works on the Previewer" + 59 " may be different from that on a real device.") 60 return paramMock.paramBooleanMock; 61 }, 62 goToLastRow: function (...args) { 63 console.warn("ResultSet.goToLastRow interface mocked in the Previewer. How this interface works on the Previewer" + 64 " may be different from that on a real device.") 65 return paramMock.paramBooleanMock; 66 }, 67 goToFirstRow: function (...args) { 68 console.warn("ResultSet.goToFirstRow interface mocked in the Previewer. How this interface works on the Previewer" + 69 " may be different from that on a real device.") 70 return paramMock.paramBooleanMock; 71 }, 72 goToNextRow: function (...args) { 73 console.warn("ResultSet.goToNextRow interface mocked in the Previewer. How this interface works on the Previewer" + 74 " may be different from that on a real device.") 75 return paramMock.paramBooleanMock; 76 }, 77 goToPreviousRow: function (...args) { 78 console.warn("ResultSet.goToPreviousRow interface mocked in the Previewer. How this interface works on the Previewer" + 79 " may be different from that on a real device.") 80 return paramMock.paramBooleanMock; 81 }, 82 getBlob: function (...args) { 83 console.warn("ResultSet.getBlob interface mocked in the Previewer. How this interface works on the Previewer" + 84 " may be different from that on a real device.") 85 return paramMock.paramArrayMock; 86 }, 87 getString: function (...args) { 88 console.warn("ResultSet.getString interface mocked in the Previewer. How this interface works on the Previewer" + 89 " may be different from that on a real device.") 90 return paramMock.paramStringMock; 91 }, 92 getLong: function (...args) { 93 console.warn("ResultSet.getLong interface mocked in the Previewer. How this interface works on the Previewer" + 94 " may be different from that on a real device.") 95 return paramMock.paramNumberMock; 96 }, 97 getDouble: function (...args) { 98 console.warn("ResultSet.getDouble interface mocked in the Previewer. How this interface works on the Previewer" + 99 " may be different from that on a real device.") 100 return paramMock.paramNumberMock; 101 }, 102 isColumnNull: function (...args) { 103 console.warn("ResultSet.isColumnNull interface mocked in the Previewer. How this interface works on the Previewer" + 104 " may be different from that on a real device.") 105 return paramMock.paramBooleanMock; 106 }, 107 close: function () { 108 console.warn("ResultSet.isColumnNull interface mocked in the Previewer. How this interface works on the Previewer" + 109 " may be different from that on a real device.") 110 } 111} 112const DataAbilityHelperMock = { 113 openFile: function (...args) { 114 console.warn("DataAbilityHelper.openFile interface mocked in the Previewer. How this interface works on the Previewer" + 115 " may be different from that on a real device.") 116 const len = args.length 117 if (typeof args[len - 1] === 'function') { 118 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 119 } else { 120 return new Promise((resolve) => { 121 resolve(paramMock.paramNumberMock); 122 }) 123 } 124 }, 125 on: function (...args) { 126 console.warn("DataAbilityHelper.on interface mocked in the Previewer. How this interface works on the Previewer" + 127 " may be different from that on a real device.") 128 const len = args.length 129 if (typeof args[len - 1] === 'function') { 130 args[len - 1].call(this, paramMock.businessErrorMock) 131 } 132 }, 133 off: function (...args) { 134 console.warn("DataAbilityHelper.off interface mocked in the Previewer. How this interface works on the Previewer" + 135 " may 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) 139 } 140 }, 141 call: function (...args) { 142 console.warn("DataAbilityHelper.call interface mocked in the Previewer. How this interface works on the Previewer" + 143 " may be different from that on a real device.") 144 const len = args.length 145 if (typeof args[len - 1] === 'function') { 146 args[len - 1].call(this, paramMock.businessErrorMock, PacMapTypeMock) 147 } else { 148 return new Promise((resolve) => { 149 resolve(PacMapMock); 150 }) 151 } 152 }, 153 getType: function (...args) { 154 console.warn("DataAbilityHelper.getType interface mocked in the Previewer. How this interface works on the Previewer" + 155 " may be different from that on a real device.") 156 const len = args.length 157 if (typeof args[len - 1] === 'function') { 158 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 159 } else { 160 return new Promise((resolve) => { 161 resolve(paramMock.paramStringMock); 162 }) 163 } 164 }, 165 getFileTypes: function (...args) { 166 console.warn("DataAbilityHelper.getFileTypes interface mocked in the Previewer. How this interface works on the Previewer" + 167 " may be different from that on a real device.") 168 const len = args.length 169 if (typeof args[len - 1] === 'function') { 170 args[len - 1].call(this, paramMock.businessErrorMock, getFileTypesArrayMock) 171 } else { 172 return new Promise((resolve) => { 173 resolve(getFileTypesArrayMock); 174 }) 175 } 176 }, 177 normalizeUri: function (...args) { 178 console.warn("DataAbilityHelper.normalizeUri interface mocked in the Previewer. How this interface works on the Previewer" + 179 " may be different from that on a real device.") 180 const len = args.length 181 if (typeof args[len - 1] === 'function') { 182 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 183 } else { 184 return new Promise((resolve) => { 185 resolve(paramMock.paramStringMock); 186 }) 187 } 188 }, 189 denormalizeUri: function (...args) { 190 console.warn("DataAbilityHelper.denormalizeUri interface mocked in the Previewer. How this interface works on the Previewer" + 191 " may be different from that on a real device.") 192 const len = args.length 193 if (typeof args[len - 1] === 'function') { 194 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 195 } else { 196 return new Promise((resolve) => { 197 resolve(paramMock.paramStringMock); 198 }) 199 } 200 }, 201 notifyChange: function (...args) { 202 console.warn("DataAbilityHelper.notifyChange interface mocked in the Previewer. How this interface works on the Previewer" + 203 " may be different from that on a real device.") 204 const len = args.length 205 if (typeof args[len - 1] === 'function') { 206 args[len - 1].call(this, paramMock.businessErrorMock) 207 } else { 208 return new Promise((resolve) => { 209 resolve(); 210 }) 211 } 212 }, 213 insert: function (...args) { 214 console.warn("DataAbilityHelper.insert interface mocked in the Previewer. How this interface works on the Previewer" + 215 " may be different from that on a real device.") 216 const len = args.length 217 if (typeof args[len - 1] === 'function') { 218 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 219 } else { 220 return new Promise((resolve) => { 221 resolve(paramMock.paramNumberMock); 222 }) 223 } 224 }, 225 batchInsert: function (...args) { 226 console.warn("DataAbilityHelper.batchInsert interface mocked in the Previewer. How this interface works on the Previewer" + 227 " may be different from that on a real device.") 228 const len = args.length 229 if (typeof args[len - 1] === 'function') { 230 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 231 } else { 232 return new Promise((resolve) => { 233 resolve(paramMock.paramNumberMock); 234 }) 235 } 236 }, 237 delete: function (...args) { 238 console.warn("DataAbilityHelper.delete interface mocked in the Previewer. How this interface works on the Previewer" + 239 " may be different from that on a real device.") 240 const len = args.length 241 if (typeof args[len - 1] === 'function') { 242 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 243 } else { 244 return new Promise((resolve) => { 245 resolve(paramMock.paramNumberMock); 246 }) 247 } 248 }, 249 update: function (...args) { 250 console.warn("DataAbilityHelper.update interface mocked in the Previewer. How this interface works on the Previewer" + 251 " may be different from that on a real device.") 252 const len = args.length 253 if (typeof args[len - 1] === 'function') { 254 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 255 } else { 256 return new Promise((resolve) => { 257 resolve(paramMock.paramNumberMock); 258 }) 259 } 260 }, 261 query: function (...args) { 262 console.warn("DataAbilityHelper.query interface mocked in the Previewer. How this interface works on the Previewer" + 263 " may be different from that on a real device.") 264 const len = args.length 265 if (typeof args[len - 1] === 'function') { 266 args[len - 1].call(this, paramMock.businessErrorMock, ResultSetMock) 267 } else { 268 return new Promise((resolve) => { 269 resolve(ResultSetMock); 270 }) 271 } 272 }, 273 executeBatch: function (...args) { 274 console.warn("DataAbilityHelper.executeBatch interface mocked in the Previewer. How this interface works on the Previewer" + 275 " may be different from that on a real device.") 276 const len = args.length 277 if (typeof args[len - 1] === 'function') { 278 args[len - 1].call(this, paramMock.businessErrorMock, DataAbilityResultArrayMock) 279 } else { 280 return new Promise((resolve) => { 281 resolve(DataAbilityResultArrayMock); 282 }) 283 } 284 } 285} 286 287export function mockAbilityFeatureAbility() { 288 global.systemplugin.ability = {} 289 const WantMock = { 290 deviceId: "[PC Preview] unknow deviceId", 291 bundleName: "[PC Preview] unknow bundleName", 292 abilityName: "[PC Preview] unknow abilityName", 293 uri: "[PC Preview] unknow uri", 294 type: "[PC Preview] unknow type", 295 flag: "[PC Preview] unknow flag", 296 action: "[PC Preview] unknow action", 297 parameters: "[PC Preview] unknow parameters", 298 entities: "[PC Preview] unknow entities" 299 } 300 const AbilityResultMock = { 301 resultCode: "[PC Preview] unknow resultCode", 302 want: WantMock 303 } 304 const ContinuationStateMock = { 305 LOCAL_RUNNING: '0', 306 REMOTE_RUNNING: '1', 307 REPLICA_RUNNING: '2' 308 } 309 const PermissionRequestResultMock = { 310 requestCode: "[PC Preview] unknow requestCode", 311 permissions: ["[PC Preview] unknow permission", "[PC Preview] unknow permission"], 312 authResults: ["[PC Preview] unknow authResult", "[PC Preview] unknow authResult"] 313 } 314 const ModuleInfoMock = { 315 moduleName: "[PC Preview] unknow moduleName", 316 moduleSourceDir: "[PC Preview] unknow moduleSourceDir" 317 } 318 const CustomizeDataMock = { 319 name: "[PC Preview] unknow name", 320 value: "[PC Preview] unknow values" 321 } 322 const ApplicationInfoMock = { 323 name: "[PC Preview] unknow name", 324 description: "[PC Preview] unknow description", 325 descriptionId: "[PC Preview] unknow descriptionId", 326 systemApp: "[PC Preview] unknow systemApp", 327 enabled: "[PC Preview] unknow enabled", 328 label: "[PC Preview] unknow label", 329 labelId: "[PC Preview] unknow labelId", 330 icon: "[PC Preview] unknow icon", 331 iconId: "[PC Preview] unknow iconId", 332 process: "[PC Preview] unknow process", 333 supportedModes: "[PC Preview] unknow supportedModes", 334 moduleSourceDirs: ["[PC Preview] unknow moduleSourceDir", "[PC Preview] unknow moduleSourceDir"], 335 permissions: ["[PC Preview] unknow permission", "[PC Preview] unknow permission"], 336 moduleInfo: [ModuleInfoMock], 337 entryDir: "[PC Preview] unknow entryDir", 338 customizeData: new Map([["[PC Preview] unknow customizeDataKey", CustomizeDataMock]]) 339 } 340 const AbilityInfoMock = { 341 bundleName: "[PC Preview] unknow bundleName", 342 className: "[PC Preview] unknow className", 343 label: "[PC Preview] unknow label", 344 description: "[PC Preview] unknow description", 345 icon: "[PC Preview] unknow icon", 346 labelId: "[PC Preview] unknow labelId", 347 descriptionId: "[PC Preview] unknow descriptionId", 348 iconId: "[PC Preview] unknow iconId", 349 moduleName: "[PC Preview] unknow moduleName", 350 process: "[PC Preview] unknow process", 351 targetAbility: "[PC Preview] unknow targetAbility", 352 backgroundModes: "[PC Preview] unknow backgroundModes", 353 isVisible: "[PC Preview] unknow isVisible", 354 formEnabled: "[PC Preview] unknow formEnabled", 355 type: "[PC Preview] unknow type", 356 subType: "[PC Preview] unknow subType", 357 orientation: "[PC Preview] unknow orientation", 358 launchMode: "[PC Preview] unknow launchMode", 359 permissions: ["[PC Preview] unknow permission", "[PC Preview] unknow permission"], 360 deviceTypes: ["[PC Preview] unknow deviceType", "[PC Preview] unknow deviceType"], 361 deviceCapabilities: ["[PC Preview] unknow deviceCapabilities", "[PC Preview] unknow deviceCapabilities"], 362 readPermission: "[PC Preview] unknow readPermission", 363 writePermission: "[PC Preview] unknow writePermission", 364 applicationInfo: ApplicationInfoMock, 365 formEntity: "[PC Preview] unknow formEntity", 366 minFormHeight: "[PC Preview] unknow minFormHeight", 367 defaultFormHeight: "[PC Preview] unknow defaultFormHeight", 368 minFormWidth: "[PC Preview] unknow minFormWidth", 369 defaultFormWidth: "[PC Preview] unknow defaultFormWidth", 370 uri: "[PC Preview] unknow uri", 371 customizeData: new Map([["[PC Preview] unknow customizeDataKey", CustomizeDataMock]]) 372 } 373 const ProcessInfoMock = { 374 pid: "[PC Preview] unknow pid", 375 processName: "[PC Preview] unknow processName" 376 } 377 const HapModuleInfoMock = { 378 name: "[PC Preview] unknow name", 379 description: "[PC Preview] unknow description", 380 descriptionId: "[PC Preview] unknow descriptionId", 381 icon: "[PC Preview] unknow icon", 382 label: "[PC Preview] unknow label", 383 labelId: "[PC Preview] unknow labelId", 384 iconId: "[PC Preview] unknow iconId", 385 backgroundImg: "[PC Preview] unknow backgroundImg", 386 supportedModes: "[PC Preview] unknow supportedModes", 387 reqCapabilities: ["[PC Preview] unknow reqCapabilities", "[PC Preview] unknow reqCapabilities"], 388 deviceTypes: ["[PC Preview] unknow deviceTypes", "[PC Preview] unknow deviceTypes"], 389 abilityInfo: [AbilityInfoMock], 390 moduleName: "[PC Preview] unknow moduleName", 391 mainAbilityName: "[PC Preview] unknow mainAbilityName", 392 installationFree: "[PC Preview] unknow installationFree", 393 } 394 const ElementNameMock = { 395 deviceId: "[PC Preview] unknow deviceId", 396 bundleName: "[PC Preview] unknow bundleName", 397 abilityName: "[PC Preview] unknow abilityName", 398 uri: "[PC Preview] unknow uri", 399 shortName: "[PC Preview] unknow shortName", 400 } 401 const AppVersionInfoMock = { 402 appName: "[PC Preview] unknow appName", 403 versionCode: "[PC Preview] unknow versionCode", 404 versionName: "[PC Preview] unknow versionName" 405 } 406 const ContextMock = { 407 getCacheDir: function (...args) { 408 console.warn("Context.getCacheDir interface mocked in the Previewer. How this interface works on the Previewer" + 409 " may be different from that on a real device.") 410 const len = args.length 411 if (typeof args[len - 1] === 'function') { 412 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 413 } else { 414 return new Promise((resolve) => { 415 resolve(paramMock.paramStringMock) 416 }) 417 } 418 }, 419 getFilesDir: function (...args) { 420 console.warn("Context.getFilesDir interface mocked in the Previewer. How this interface works on the Previewer" + 421 " may be different from that on a real device.") 422 const len = args.length 423 if (typeof args[len - 1] === 'function') { 424 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 425 } else { 426 return new Promise((resolve) => { 427 resolve(paramMock.paramStringMock) 428 }) 429 } 430 }, 431 getExternalCacheDir: function (...args) { 432 console.warn("Context.getExternalCacheDir interface mocked in the Previewer. How this interface works on the" + 433 " Previewer may be different from that on a real device.") 434 const len = args.length 435 if (typeof args[len - 1] === 'function') { 436 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 437 } else { 438 return new Promise((resolve) => { 439 resolve(paramMock.paramStringMock) 440 }) 441 } 442 }, 443 getOrCreateLocalDir: function (...args) { 444 console.warn("Context.getOrCreateLocalDir interface mocked in the Previewer. How this interface works on the Previewer" + 445 " may be different from that on a real device.") 446 const len = args.length 447 if (typeof args[len - 1] === 'function') { 448 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 449 } else { 450 return new Promise((resolve) => { 451 resolve(paramMock.paramStringMock) 452 }) 453 } 454 }, 455 getOrCreateDistributedDir: function (...args) { 456 console.warn("Context.getOrCreateDistributedDir interface mocked in the Previewer. How this interface works on the Previewer" + 457 " may be different from that on a real device.") 458 const len = args.length 459 if (typeof args[len - 1] === 'function') { 460 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 461 } else { 462 return new Promise((resolve) => { 463 resolve(paramMock.paramStringMock) 464 }) 465 } 466 }, 467 verifyPermission: function (...args) { 468 console.warn("Context.verifyPermission interface mocked in the Previewer. How this interface works on the Previewer" + 469 " may be different from that on a real device.") 470 const len = args.length 471 if (typeof args[len - 1] === 'function') { 472 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 473 } else { 474 return new Promise((resolve) => { 475 resolve(paramMock.paramNumberMock) 476 }) 477 } 478 }, 479 compelVerifyPermission: function (...args) { 480 console.warn("Context.compelVerifyPermission interface mocked in the Previewer. How this interface works on the Previewer" + 481 " may be different from that on a real device.") 482 const len = args.length 483 if (typeof args[len - 1] === 'function') { 484 args[len - 1].call(this, paramMock.businessErrorMock) 485 } else { 486 return new Promise((resolve) => { 487 resolve() 488 }) 489 } 490 }, 491 authUriAccessPermission: function (...args) { 492 console.warn("Context.authUriAccessPermission interface mocked in the Previewer. How this interface works on the Previewer" + 493 " may be different from that on a real device.") 494 const len = args.length 495 if (typeof args[len - 1] === 'function') { 496 args[len - 1].call(this, paramMock.businessErrorMock) 497 } else { 498 return new Promise((resolve) => { 499 resolve() 500 }) 501 } 502 }, 503 unauthUriAccessPermission: function (...args) { 504 console.warn("Context.unauthUriAccessPermission interface mocked in the Previewer. How this interface works on the Previewer" + 505 " may be different from that on a real device.") 506 const len = args.length 507 if (typeof args[len - 1] === 'function') { 508 args[len - 1].call(this, paramMock.businessErrorMock) 509 } else { 510 return new Promise((resolve) => { 511 resolve() 512 }) 513 } 514 }, 515 requestPermissionsFromUser: function (...args) { 516 console.warn("Context.requestPermissionsFromUser interface mocked in the Previewer. How this interface works on the Previewer" + 517 " may be different from that on a real device.") 518 const len = args.length 519 if (typeof args[len - 1] === 'function') { 520 args[len - 1].call(this, paramMock.businessErrorMock, PermissionRequestResultMock) 521 } else { 522 return new Promise((resolve) => { 523 resolve(PermissionRequestResultMock) 524 }) 525 } 526 }, 527 getApplicationInfo: function (...args) { 528 console.warn("Context.getApplicationInfo interface mocked in the Previewer. How this interface works on the Previewer" + 529 " may be different from that on a real device.") 530 const len = args.length 531 if (typeof args[len - 1] === 'function') { 532 args[len - 1].call(this, paramMock.businessErrorMock, ApplicationInfoMock) 533 } else { 534 return new Promise((resolve) => { 535 resolve(ApplicationInfoMock) 536 }) 537 } 538 }, 539 getBundleName: function (...args) { 540 console.warn("Context.getBundleName interface mocked in the Previewer. How this interface works on the Previewer" + 541 " may be different from that on a real device.") 542 const len = args.length 543 if (typeof args[len - 1] === 'function') { 544 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 545 } else { 546 return new Promise((resolve) => { 547 resolve(paramMock.paramStringMock) 548 }) 549 } 550 }, 551 getDisplayOrientation: function (...args) { 552 console.warn("Context.getDisplayOrientation interface mocked in the Previewer. How this interface works on the Previewer" + 553 " may be different from that on a real device.") 554 const len = args.length 555 if (typeof args[len - 1] === 'function') { 556 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 557 } else { 558 return new Promise((resolve) => { 559 resolve(paramMock.paramNumberMock) 560 }) 561 } 562 }, 563 setDisplayOrientation: function (...args) { 564 console.warn("Context.setDisplayOrientation interface mocked in the Previewer. How this interface works on the Previewer" + 565 " may be different from that on a real device.") 566 const len = args.length 567 if (typeof args[len - 1] === 'function') { 568 args[len - 1].call(this, paramMock.businessErrorMock) 569 } else { 570 return new Promise((resolve) => { 571 resolve() 572 }) 573 } 574 }, 575 setShowOnLockScreen: function (...args) { 576 console.warn("Context.setShowOnLockScreen interface mocked in the Previewer. How this interface works on the Previewer" + 577 " may be different from that on a real device.") 578 const len = args.length 579 if (typeof args[len - 1] === 'function') { 580 args[len - 1].call(this, paramMock.businessErrorMock) 581 } else { 582 return new Promise((resolve) => { 583 resolve() 584 }) 585 } 586 }, 587 setWakeUpScreen: function (...args) { 588 console.warn("Context.setWakeUpScreen interface mocked in the Previewer. How this interface works on the Previewer" + 589 " may be different from that on a real device.") 590 const len = args.length 591 if (typeof args[len - 1] === 'function') { 592 args[len - 1].call(this, paramMock.businessErrorMock) 593 } else { 594 return new Promise((resolve) => { 595 resolve() 596 }) 597 } 598 }, 599 getProcessInfo: function (...args) { 600 console.warn("Context.getProcessInfo interface mocked in the Previewer. How this interface works on the Previewer" + 601 " may be different from that on a real device.") 602 const len = args.length 603 if (typeof args[len - 1] === 'function') { 604 args[len - 1].call(this, paramMock.businessErrorMock, ProcessInfoMock) 605 } else { 606 return new Promise((resolve) => { 607 resolve(ProcessInfoMock) 608 }) 609 } 610 }, 611 getAppType: function (...args) { 612 console.warn("Context.getAppType interface mocked in the Previewer. How this interface works on the Previewer" + 613 " may be different from that on a real device.") 614 const len = args.length 615 if (typeof args[len - 1] === 'function') { 616 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 617 } else { 618 return new Promise((resolve) => { 619 resolve(paramMock.paramStringMock) 620 }) 621 } 622 }, 623 getElementName: function (...args) { 624 console.warn("Context.getElementName interface mocked in the Previewer. How this interface works on the Previewer" + 625 " may be different from that on a real device.") 626 const len = args.length 627 if (typeof args[len - 1] === 'function') { 628 args[len - 1].call(this, paramMock.businessErrorMock, ElementNameMock) 629 } else { 630 return new Promise((resolve) => { 631 resolve(ElementNameMock) 632 }) 633 } 634 }, 635 getHapModuleInfo: function (...args) { 636 console.warn("Context.getHapModuleInfo interface mocked in the Previewer. How this interface works on the Previewer" + 637 " may be different from that on a real device.") 638 const len = args.length 639 if (typeof args[len - 1] === 'function') { 640 args[len - 1].call(this, paramMock.businessErrorMock, HapModuleInfoMock) 641 } else { 642 return new Promise((resolve) => { 643 resolve(HapModuleInfoMock) 644 }) 645 } 646 }, 647 getProcessName: function (...args) { 648 console.warn("Context.getProcessName interface mocked in the Previewer. How this interface works on the Previewer" + 649 " may be different from that on a real device.") 650 const len = args.length 651 if (typeof args[len - 1] === 'function') { 652 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 653 } else { 654 return new Promise((resolve) => { 655 resolve(paramMock.paramStringMock) 656 }) 657 } 658 }, 659 getCallingBundle: function (...args) { 660 console.warn("Context.getCallingBundle interface mocked in the Previewer. How this interface works on the Previewer" + 661 " may be different from that on a real device.") 662 const len = args.length 663 if (typeof args[len - 1] === 'function') { 664 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 665 } else { 666 return new Promise((resolve) => { 667 resolve(paramMock.paramStringMock) 668 }) 669 } 670 }, 671 printDrawnCompleted: function (...args) { 672 console.warn("Context.printDrawnCompleted interface mocked in the Previewer. How this interface works on the Previewer" + 673 " may be different from that on a real device.") 674 const len = args.length 675 if (typeof args[len - 1] === 'function') { 676 args[len - 1].call(this, paramMock.businessErrorMock) 677 } else { 678 return new Promise((resolve) => { 679 resolve() 680 }) 681 } 682 }, 683 isUpdatingConfigurations: function (...args) { 684 console.warn("Context.isUpdatingConfigurations interface mocked in the Previewer. How this interface works on the Previewer" + 685 " may be different from that on a real device.") 686 const len = args.length 687 if (typeof args[len - 1] === 'function') { 688 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) 689 } else { 690 return new Promise((resolve) => { 691 resolve(paramMock.paramBooleanMock) 692 }) 693 } 694 }, 695 getAppVersionInfo: function (...args) { 696 console.warn("Context.getAppVersionInfo interface mocked in the Previewer. How this interface works on the Previewer" + 697 " may be different from that on a real device.") 698 const len = args.length 699 if (typeof args[len - 1] === 'function') { 700 args[len - 1].call(this, paramMock.businessErrorMock, AppVersionInfoMock) 701 } else { 702 return new Promise((resolve) => { 703 resolve(AppVersionInfoMock) 704 }) 705 } 706 }, 707 getAbilityInfo: function (...args) { 708 console.warn("Context.getAbilityInfo interface mocked in the Previewer. How this interface works on the Previewer" + 709 " may be different from that on a real device.") 710 const len = args.length 711 if (typeof args[len - 1] === 'function') { 712 args[len - 1].call(this, paramMock.businessErrorMock, AbilityInfoMock) 713 } else { 714 return new Promise((resolve) => { 715 resolve(AbilityInfoMock) 716 }) 717 } 718 }, 719 getApplicationContext: function () { 720 console.warn("Context.getApplicationContext interface mocked in the Previewer. How this interface works on" + 721 " the Previewer may be different from that on a real device.") 722 return ContextMock; 723 } 724 } 725 global.systemplugin.ability.featureAbility = { 726 getWant: function (...args) { 727 console.warn("ability.featureAbility.getWant interface mocked in the Previewer. How this interface works on" + 728 " the Previewer may be different from that on a real device.") 729 const len = args.length 730 if (typeof args[len - 1] === 'function') { 731 args[len - 1].call(this, paramMock.businessErrorMock, WantMock) 732 } else { 733 return new Promise((resolve) => { 734 resolve(WantMock) 735 }) 736 } 737 }, 738 startAbility: function (...args) { 739 console.warn("ability.featureAbility.startAbility interface mocked in the Previewer. How this interface works" + 740 " on the Previewer may be different from that on a real device.") 741 const len = args.length 742 if (typeof args[len - 1] === 'function') { 743 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 744 } else { 745 return new Promise((resolve) => { 746 resolve(paramMock.paramNumberMock) 747 }) 748 } 749 }, 750 connectAbility: function (...args) { 751 console.warn("ability.featureAbility.connectAbility interface mocked in the Previewer. How this interface works" + 752 " on the Previewer may be different from that on a real device.") 753 return paramMock.paramNumberMock; 754 }, 755 disconnectAbility: function (...args) { 756 console.warn("ability.featureAbility.disconnectAbility interface mocked in the Previewer. How this interface works" + 757 " on the Previewer may be different from that on a real device.") 758 const len = args.length 759 if (typeof args[len - 1] === 'function') { 760 args[len - 1].call(this, paramMock.businessErrorMock) 761 } else { 762 return new Promise((resolve) => { 763 resolve() 764 }) 765 } 766 }, 767 getContext: function () { 768 console.warn("ability.featureAbility.getContext interface mocked in the Previewer. How this interface works on" + 769 " the Previewer may be different from that on a real device.") 770 return ContextMock; 771 }, 772 startAbilityForResult: function (...args) { 773 console.warn("ability.featureAbility.startAbilityForResult interface mocked in the Previewer. How this interface works" + 774 " on the Previewer may be different from that on a real device.") 775 const len = args.length 776 if (typeof args[len - 1] === 'function') { 777 args[len - 1].call(this, paramMock.businessErrorMock, AbilityResultMock) 778 } else { 779 return new Promise((resolve) => { 780 resolve(AbilityResultMock) 781 }) 782 } 783 }, 784 terminateSelfWithResult: function (...args) { 785 console.warn("ability.featureAbility.terminateSelfWithResult interface mocked in the Previewer. How this interface works" + 786 " on the Previewer may be different from that on a real device.") 787 const len = args.length 788 if (typeof args[len - 1] === 'function') { 789 args[len - 1].call(this, paramMock.businessErrorMock) 790 } else { 791 return new Promise((resolve) => { 792 resolve() 793 }) 794 } 795 }, 796 terminateSelf: function (...args) { 797 console.warn("ability.featureAbility.terminateSelf interface mocked in the Previewer. How this interface works on" + 798 " the Previewer may be different from that on a real device.") 799 const len = args.length 800 if (typeof args[len - 1] === 'function') { 801 args[len - 1].call(this, paramMock.businessErrorMock) 802 } else { 803 return new Promise((resolve) => { 804 resolve() 805 }) 806 } 807 }, 808 acquireDataAbilityHelper: function (...args) { 809 console.warn("ability.featureAbility.acquireDataAbilityHelper mocked in the Previewer. How this interface works on the Previewer may be" + 810 " different from that on a real device.") 811 return DataAbilityHelperMock; 812 }, 813 hasWindowFocus: function (...args) { 814 console.warn("ability.featureAbility.hasWindowFocus interface mocked in the Previewer. How this interface works" + 815 " on the Previewer may be different from that on a real device.") 816 const len = args.length 817 if (typeof args[len - 1] === 'function') { 818 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) 819 } else { 820 return new Promise((resolve) => { 821 resolve(paramMock.paramBooleanMock) 822 }) 823 } 824 }, 825 getAbilityMissionId: function (...args) { 826 console.warn("ability.featureAbility.getAbilityMissionId interface mocked in the Previewer. How this interface works" + 827 " on the Previewer may be different from that on a real device.") 828 const len = args.length 829 if (typeof args[len - 1] === 'function') { 830 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 831 } else { 832 return new Promise((resolve) => { 833 resolve(paramMock.paramNumberMock); 834 }) 835 } 836 }, 837 getWindow: function (...args) { 838 console.warn("ability.featureAbility.getWindow interface mocked in the Previewer. How this interface works" + 839 " on the Previewer may be different from that on a real device.") 840 const len = args.length 841 if (typeof args[len - 1] === 'function') { 842 args[len - 1].call(this, paramMock.businessErrorMock, windowMock) 843 } else { 844 return new Promise((resolve) => { 845 resolve(windowMock) 846 }) 847 } 848 }, 849 continueAbility: function (...args) { 850 console.warn("ability.featureAbility.continueAbility interface mocked in the Previewer. How this interface works" + 851 " on the Previewer may be different from that on a real device.") 852 const len = args.length 853 if (typeof args[len - 1] === 'function') { 854 args[len - 1].call(this, paramMock.businessErrorMock) 855 } else { 856 return new Promise((resolve) => { 857 resolve(); 858 }) 859 } 860 }, 861 getContinuationState: function (...args) { 862 console.warn("ability.featureAbility.getContinuationState interface mocked in the Previewer. How this interface works" + 863 " on the Previewer may be different from that on a real device.") 864 const len = args.length 865 if (typeof args[len - 1] === 'function') { 866 args[len - 1].call(this, paramMock.businessErrorMock, ContinuationStateMock) 867 } else { 868 return new Promise((resolve) => { 869 resolve(ContinuationStateMock) 870 }) 871 } 872 }, 873 getOriginalDeviceId: function (...args) { 874 console.warn("ability.featureAbility.getOriginalDeviceId interface mocked in the Previewer. How this interface works" + 875 " on the Previewer may be different from that on a real device.") 876 const len = args.length 877 if (typeof args[len - 1] === 'function') { 878 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 879 } else { 880 return new Promise((resolve) => { 881 resolve(paramMock.paramStringMock) 882 }) 883 } 884 }, 885 reverseContinueAbility: function (...args) { 886 console.warn("ability.featureAbility.reverseContinueAbility interface mocked in the Previewer. How this interface works" + 887 " on the Previewer may be different from that on a real device.") 888 const len = args.length 889 if (typeof args[len - 1] === 'function') { 890 args[len - 1].call(this, paramMock.businessErrorMock) 891 } else { 892 return new Promise((resolve) => { 893 resolve() 894 }) 895 } 896 }, 897 finishTaskSyncAnimation: function (...args) { 898 console.warn("ability.featureAbility.finishTaskSyncAnimation interface mocked in the Previewer. How this interface works on" + 899 " the Previewer may be different from that on a real device.") 900 }, 901 setTaskSyncAnimationParams: function (...args) { 902 console.warn("ability.featureAbility.setTaskSyncAnimationParams interface mocked in the Previewer. How this interface works on" + 903 " the Previewer may be different from that on a real device.") 904 const len = args.length 905 if (typeof args[len - 1] === 'function') { 906 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 907 } else { 908 return new Promise((resolve) => { 909 resolve(paramMock.paramNumberMock) 910 }) 911 } 912 }, 913 startAssistAbility: function (...args) { 914 console.warn("ability.featureAbility.startAssistAbility mocked in the Previewer. How this interface works on the Previewer may be" + 915 " different from that on a real device.") 916 }, 917 stopAssistAbility: function (...args) { 918 console.warn("ability.featureAbility.stopAssistAbility interface mocked in the Previewer. How this interface works" + 919 " on the Previewer may be different from that on a real device.") 920 const len = args.length 921 if (typeof args[len - 1] === 'function') { 922 args[len - 1].call(this, paramMock.businessErrorMock) 923 } else { 924 return new Promise((resolve) => { 925 resolve() 926 }) 927 } 928 }, 929 on: function (...args) { 930 console.warn("ability.featureAbility.on interface mocked in the Previewer. How this interface works" + 931 " on the Previewer may be different from that on a real device.") 932 const len = args.length 933 if (typeof args[len - 1] === 'function') { 934 if (args[0] == 'assistConnect') { 935 args[len - 1].call(this, global.systemplugin.ability.abilityAgent); 936 } else if (args[0] == 'assistConnectFailed') { 937 args[len - 1].call(this, paramMock.paramNumberMock); 938 } else { 939 args[len - 1].call(this, paramMock.paramNumberMock); 940 } 941 } 942 }, 943 off: function (...args) { 944 console.warn("ability.featureAbility.off interface mocked in the Previewer. How this interface works" + 945 " on the Previewer may be different from that on a real device.") 946 const len = args.length 947 if (typeof args[len - 1] === 'function') { 948 if (args[0] == 'assistConnect') { 949 args[len - 1].call(this, global.systemplugin.ability.abilityAgent); 950 } else if (args[0] == 'assistConnectFailed') { 951 args[len - 1].call(this, paramMock.paramNumberMock); 952 } else { 953 args[len - 1].call(this, paramMock.paramNumberMock); 954 } 955 } 956 } 957 } 958} 959export function mockAbilityParticleAbility() { 960 global.systemplugin.ability.particleAbility = { 961 startAbility: function (...args) { 962 console.warn("ability.particleAbility.startAbility interface mocked in the Previewer. How this interface works" + 963 " on the Previewer may be different from that on a real device.") 964 const len = args.length 965 if (typeof args[len - 1] === 'function') { 966 args[len - 1].call(this, paramMock.businessErrorMock) 967 } else { 968 return new Promise((resolve) => { 969 resolve() 970 }) 971 } 972 }, 973 connectAbility: function (...args) { 974 console.warn("ability.particleAbility.connectAbility interface mocked in the Previewer. How this interface works" + 975 " on the Previewer may be different from that on a real device.") 976 return paramMock.paramNumberMock; 977 }, 978 disconnectAbility: function (...args) { 979 console.warn("ability.particleAbility.disconnectAbility interface mocked in the Previewer. How this interface works" + 980 " on the Previewer may be different from that on a real device.") 981 const len = args.length 982 if (typeof args[len - 1] === 'function') { 983 args[len - 1].call(this, paramMock.businessErrorMock) 984 } else { 985 return new Promise((resolve) => { 986 resolve() 987 }) 988 } 989 }, 990 terminateSelf: function (...args) { 991 console.warn("ability.particleAbility.terminateSelf interface mocked in the Previewer. How this interface works" + 992 " on the Previewer may be different from that on a real device.") 993 const len = args.length 994 if (typeof args[len - 1] === 'function') { 995 args[len - 1].call(this, paramMock.businessErrorMock) 996 } else { 997 return new Promise((resolve) => { 998 resolve() 999 }) 1000 } 1001 }, 1002 acquireDataAbilityHelper: function (...args) { 1003 console.warn("ability.particleAbility.acquireDataAbilityHelper interface mocked in the Previewer. How this interface works" + 1004 " on the Previewer may be different from that on a real device.") 1005 return DataAbilityHelperMock; 1006 }, 1007 startBackgroundRunning: function (...args) { 1008 console.warn("ability.particleAbility.startBackgroundRunning interface mocked in the Previewer. How this interface works" + 1009 " on the Previewer may be different from that on a real device.") 1010 const len = args.length 1011 if (typeof args[len - 1] === 'function') { 1012 args[len - 1].call(this, paramMock.businessErrorMock) 1013 } else { 1014 return new Promise((resolve) => { 1015 resolve() 1016 }) 1017 } 1018 }, 1019 cancelBackgroundRunning: function (...args) { 1020 console.warn("ability.particleAbility.cancelBackgroundRunning interface mocked in the Previewer. How this interface works" + 1021 " on the Previewer may be different from that on a real device.") 1022 const len = args.length 1023 if (typeof args[len - 1] === 'function') { 1024 args[len - 1].call(this, paramMock.businessErrorMock) 1025 } else { 1026 return new Promise((resolve) => { 1027 resolve() 1028 }) 1029 } 1030 } 1031 } 1032} 1033export function mockAbilityFormManager() { 1034 const FormInfoMock = { 1035 bundleName: "[PC Preview] unknow bundleName", 1036 moduleName: "[PC Preview] unknow moduleName", 1037 abilityName: "[PC Preview] unknow abilityName", 1038 name: "[PC Preview] unknow name", 1039 description: "[PC Preview] unknow description", 1040 type: "[PC Preview] unknow type", 1041 jsComponentName: "[PC Preview] unknow jsComponentName", 1042 colorMode: "[PC Preview] unknow colorMode", 1043 isDefault: "[PC Preview] unknow isDefault", 1044 updateEnabled: "[PC Preview] unknow updateEnabled", 1045 formVisibleNotify: "[PC Preview] unknow formVisibleNotify", 1046 relatedBundleName: "[PC Preview] unknow relatedBundleName", 1047 scheduledUpdateTime: "[PC Preview] unknow scheduledUpdateTime", 1048 formConfigAbility: "[PC Preview] unknow formConfigAbility", 1049 updateDuration: "[PC Preview] unknow updateDuration", 1050 defaultDimension: "[PC Preview] unknow defaultDimension", 1051 supportDimensions: "[PC Preview] unknow supportDimensions", 1052 customizeDatas: "[PC Preview] unknow customizeDatas", 1053 jsonObject: "[PC Preview] unknow jsonObject" 1054 } 1055 const WantMock = { 1056 deviceId: "[PC Preview] unknow deviceId", 1057 bundleName: "[PC Preview] unknow bundleName", 1058 abilityName: "[PC Preview] unknow abilityName", 1059 uri: "[PC Preview] unknow uri", 1060 type: "[PC Preview] unknow type", 1061 flag: "[PC Preview] unknow flag", 1062 action: "[PC Preview] unknow action", 1063 parameters: "[PC Preview] unknow parameters", 1064 entities: "[PC Preview] unknow entities" 1065 } 1066 const FormStateMock = { 1067 UNKNOWN: '-1', 1068 DEFAULT: '0', 1069 READY: '1' 1070 } 1071 const FormInfoArrayMock = [ 1072 FormInfoMock 1073 ] 1074 const AcquireFormStateMock = { 1075 FormStateMock, 1076 WantMock 1077 } 1078 global.systemplugin.ability.formManager = { 1079 requestForm: function (...args) { 1080 console.warn("ability.formManager.requestForm interface mocked in the Previewer. How this interface works" + 1081 " on the Previewer may be different from that on a real device.") 1082 const len = args.length 1083 if (typeof args[len - 1] === 'function') { 1084 args[len - 1].call(this, paramMock.businessErrorMock) 1085 } else { 1086 return new Promise((resolve) => { 1087 resolve() 1088 }) 1089 } 1090 }, 1091 deleteForm: function (...args) { 1092 console.warn("ability.formManager.deleteForm interface mocked in the Previewer. How this interface works" + 1093 " on the Previewer may be different from that on a real device.") 1094 const len = args.length 1095 if (typeof args[len - 1] === 'function') { 1096 args[len - 1].call(this, paramMock.businessErrorMock) 1097 } else { 1098 return new Promise((resolve) => { 1099 resolve() 1100 }) 1101 } 1102 }, 1103 releaseForm: function (...args) { 1104 console.warn("ability.formManager.releaseForm interface mocked in the Previewer. How this interface works on the Previewer may" + 1105 " be different from that on a real device.") 1106 const len = args.length 1107 if (typeof args[len - 1] === 'function') { 1108 args[len - 1].call(this, paramMock.businessErrorMock); 1109 } else { 1110 return new Promise((resolve) => { 1111 resolve() 1112 }) 1113 } 1114 }, 1115 notifyVisibleForms: function (...args) { 1116 console.warn("ability.formManager.notifyVisibleForms interface mocked in the Previewer. How this interface works" + 1117 " on the Previewer may be different from that on a real device.") 1118 const len = args.length 1119 if (typeof args[len - 1] === 'function') { 1120 args[len - 1].call(this, paramMock.businessErrorMock) 1121 } else { 1122 return new Promise((resolve) => { 1123 resolve() 1124 }) 1125 } 1126 }, 1127 notifyInvisibleForms: function (...args) { 1128 console.warn("ability.formManager.notifyInvisibleForms interface mocked in the Previewer. How this interface works" + 1129 " on the Previewer may be different from that on a real device.") 1130 const len = args.length 1131 if (typeof args[len - 1] === 'function') { 1132 args[len - 1].call(this, paramMock.businessErrorMock) 1133 } else { 1134 return new Promise((resolve) => { 1135 resolve() 1136 }) 1137 } 1138 }, 1139 enableFormsUpdate: function (...args) { 1140 console.warn("ability.formManager.enableFormsUpdate interface mocked in the Previewer. How this interface works" + 1141 " on the Previewer may be different from that on a real device.") 1142 const len = args.length 1143 if (typeof args[len - 1] === 'function') { 1144 args[len - 1].call(this, paramMock.businessErrorMock) 1145 } else { 1146 return new Promise((resolve) => { 1147 resolve() 1148 }) 1149 } 1150 }, 1151 disableFormsUpdate: function (...args) { 1152 console.warn("ability.formManager.disableFormsUpdate interface mocked in the Previewer. How this interface works" + 1153 " on the Previewer may be different from that on a real device.") 1154 const len = args.length 1155 if (typeof args[len - 1] === 'function') { 1156 args[len - 1].call(this, paramMock.businessErrorMock) 1157 } else { 1158 return new Promise((resolve) => { 1159 resolve() 1160 }) 1161 } 1162 }, 1163 isSystemReady: function (...args) { 1164 console.warn("ability.formManager.isSystemReady interface mocked in the Previewer. How this interface works" + 1165 " on the Previewer may be different from that on a real device.") 1166 const len = args.length 1167 if (typeof args[len - 1] === 'function') { 1168 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) 1169 } else { 1170 return new Promise((resolve) => { 1171 resolve(paramMock.paramBooleanMock) 1172 }) 1173 } 1174 }, 1175 castTempForm: function (...args) { 1176 console.warn("ability.formManager.castTempForm interface mocked in the Previewer. How this interface works" + 1177 " on the Previewer may be different from that on a real device.") 1178 const len = args.length 1179 if (typeof args[len - 1] === 'function') { 1180 args[len - 1].call(this, paramMock.businessErrorMock) 1181 } else { 1182 return new Promise((resolve) => { 1183 resolve() 1184 }) 1185 } 1186 }, 1187 deleteInvalidForms: function (...args) { 1188 console.warn("ability.formManager.deleteInvalidForms interface mocked in the Previewer. How this interface works" + 1189 " on the Previewer may be different from that on a real device.") 1190 const len = args.length 1191 if (typeof args[len - 1] === 'function') { 1192 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 1193 } else { 1194 return new Promise((resolve) => { 1195 resolve(paramMock.paramNumberMock) 1196 }) 1197 } 1198 }, 1199 acquireFormState: function (...args) { 1200 console.warn("ability.formManager.acquireFormState interface mocked in the Previewer. How this interface works" + 1201 " on the Previewer may be different from that on a real device.") 1202 const len = args.length 1203 if (typeof args[len - 1] === 'function') { 1204 args[len - 1].call(this, paramMock.businessErrorMock, AcquireFormStateMock) 1205 } else { 1206 return new Promise((resolve) => { 1207 resolve(AcquireFormStateMock) 1208 }) 1209 } 1210 }, 1211 on: function (...args) { 1212 console.warn("ability.formManager.on interface mocked in the Previewer. How this interface works" + 1213 " on the Previewer may be different from that on a real device.") 1214 const len = args.length 1215 if (typeof args[len - 1] === 'function') { 1216 args[len - 1].call(this, paramMock.paramStringMock) 1217 } 1218 }, 1219 off: function (...args) { 1220 console.warn("ability.formManager.off interface mocked in the Previewer. How this interface works" + 1221 " on the Previewer may be different from that on a real device.") 1222 const len = args.length 1223 if (typeof args[len - 1] === 'function') { 1224 args[len - 1].call(this, paramMock.paramStringMock) 1225 } 1226 }, 1227 getAllFormsInfo: function (...args) { 1228 console.warn("ability.formManager.getAllFormsInfo interface mocked in the Previewer. How this interface works" + 1229 " on the Previewer may be different from that on a real device.") 1230 const len = args.length 1231 if (typeof args[len - 1] === 'function') { 1232 args[len - 1].call(this, paramMock.businessErrorMock, FormInfoArrayMock) 1233 } else { 1234 return new Promise((resolve) => { 1235 resolve(FormInfoArrayMock) 1236 }) 1237 } 1238 }, 1239 getFormsInfo: function (...args) { 1240 console.warn("ability.formManager.getFormsInfo interface mocked in the Previewer. How this interface works" + 1241 " on the Previewer may be different from that on a real device.") 1242 const len = args.length 1243 if (typeof args[len - 1] === 'function') { 1244 args[len - 1].call(this, paramMock.businessErrorMock, FormInfoArrayMock) 1245 } else { 1246 return new Promise((resolve) => { 1247 resolve(FormInfoArrayMock) 1248 }) 1249 } 1250 }, 1251 updateForm: function (...args) { 1252 console.warn("ability.formManager.updateForm interface mocked in the Previewer. How this interface works" + 1253 " on the Previewer may be different from that on a real device.") 1254 const len = args.length 1255 if (typeof args[len - 1] === 'function') { 1256 args[len - 1].call(this, paramMock.businessErrorMock) 1257 } else { 1258 return new Promise((resolve) => { 1259 resolve() 1260 }) 1261 } 1262 } 1263 } 1264} 1265export function mockAbilityContinuationRegisterManager() { 1266 const ContinuationResultMock = { 1267 id: "[PC Preview] unknow id", 1268 type: "[PC Preview] unknow type", 1269 name: "[PC Preview] unknow name" 1270 } 1271 global.systemplugin.ability.continuationRegisterManager = { 1272 on: function (...args) { 1273 console.warn("ability.ContinuationRegisterManager.on interface mocked in the Previewer. How this interface works on the Previewer" + 1274 " may be different from that on a real device.") 1275 const len = args.length 1276 if (typeof args[len - 1] === 'function') { 1277 if (args[0] === 'deviceConnect') { 1278 args[len - 1].call(this, ContinuationResultMock) 1279 } else { 1280 args[len - 1].call(this, paramMock.paramStringMock) 1281 } 1282 } 1283 }, 1284 off: function (...args) { 1285 console.warn("ability.ContinuationRegisterManager.off interface mocked in the Previewer. How this interface works on the Previewer" + 1286 " may be different from that on a real device.") 1287 const len = args.length 1288 if (typeof args[len - 1] === 'function') { 1289 if (args[0] === 'deviceConnect') { 1290 args[len - 1].call(this, ContinuationResultMock) 1291 } else { 1292 args[len - 1].call(this, paramMock.paramStringMock) 1293 } 1294 } 1295 }, 1296 register: function (...args) { 1297 console.warn("ability.ContinuationRegisterManager.register interface mocked in the Previewer. How this interface works" + 1298 " on the Previewer may be different from that on a real device.") 1299 const len = args.length 1300 if (typeof args[len - 1] === 'function') { 1301 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 1302 } else { 1303 return new Promise((resolve) => { 1304 resolve(paramMock.paramNumberMock) 1305 }) 1306 } 1307 }, 1308 unregister: function (...args) { 1309 console.warn("ability.ContinuationRegisterManager.unregister interface mocked in the Previewer. How this interface works" + 1310 " on the Previewer may be different from that on a real device.") 1311 const len = args.length 1312 if (typeof args[len - 1] === 'function') { 1313 args[len - 1].call(this, paramMock.businessErrorMock) 1314 } else { 1315 return new Promise((resolve) => { 1316 resolve() 1317 }) 1318 } 1319 }, 1320 updateConnectStatus: function (...args) { 1321 console.warn("ability.ContinuationRegisterManager.updateConnectStatus interface mocked in the Previewer. How this interface works" + 1322 " on the Previewer may be different from that on a real device.") 1323 const len = args.length 1324 if (typeof args[len - 1] === 'function') { 1325 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 1326 } else { 1327 return new Promise((resolve) => { 1328 resolve(paramMock.paramNumberMock) 1329 }) 1330 } 1331 }, 1332 showDeviceList: function (...args) { 1333 console.warn("ability.ContinuationRegisterManager.showDeviceList interface mocked in the Previewer. How this interface works" + 1334 " on the Previewer may be different from that on a real device.") 1335 const len = args.length 1336 if (typeof args[len - 1] === 'function') { 1337 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 1338 } else { 1339 return new Promise((resolve) => { 1340 resolve(paramMock.paramNumberMock) 1341 }) 1342 } 1343 }, 1344 disconnect: function (...args) { 1345 console.warn("ability.ContinuationRegisterManager.disconnect interface mocked in the Previewer. How this interface works" + 1346 " on the Previewer may be different from that on a real device.") 1347 const len = args.length 1348 if (typeof args[len - 1] === 'function') { 1349 args[len - 1].call(this, paramMock.businessErrorMock) 1350 } else { 1351 return new Promise((resolve) => { 1352 resolve() 1353 }) 1354 } 1355 } 1356 } 1357} 1358export function mockAbilityAbilityAgent() { 1359 global.systemplugin.ability.abilityAgent = { 1360 on: function (...args) { 1361 console.warn("ability.abilityAgent.on interface mocked in the Previewer. How this interface works" + 1362 " on the Previewer may be different from that on a real device.") 1363 const len = args.length 1364 if (typeof args[len - 1] === 'function') { 1365 if (args[0] == 'message') { 1366 args[len - 1].call(this, paramMock.paramStringMock); 1367 } else { 1368 args[len - 1].call(this, paramMock.paramNumberMock); 1369 } 1370 } 1371 }, 1372 off: function (...args) { 1373 console.warn("ability.abilityAgent.off interface mocked in the Previewer. How this interface works" + 1374 " on the Previewer may be different from that on a real device.") 1375 const len = args.length 1376 if (typeof args[len - 1] === 'function') { 1377 if (args[0] == 'message') { 1378 args[len - 1].call(this, paramMock.paramStringMock) 1379 } else { 1380 args[len - 1].call(this, paramMock.paramNumberMock) 1381 } 1382 } 1383 }, 1384 postMessage: function (...args) { 1385 console.warn("ability.abilityAgent.postMessage interface mocked in the Previewer. How this interface works" + 1386 " on the Previewer may be different from that on a real device.") 1387 const len = args.length 1388 if (typeof args[len - 1] === 'function') { 1389 args[len - 1].call(this, paramMock.businessErrorMock) 1390 } else { 1391 return new Promise((resolve) => { 1392 resolve() 1393 }) 1394 } 1395 } 1396 } 1397} 1398export function mockAbilityFormBindingData() { 1399 const FormBindingDataMock = { 1400 data: "[PC Preview] unknow data" 1401 } 1402 global.systemplugin.ability.formBindingData = { 1403 createFormBindingData: function (...args) { 1404 console.warn("ability.formBindingData.createFormBindingData interface mocked in the Previewer. How this interface works" + 1405 " on the Previewer may be different from that on a real device.") 1406 return FormBindingDataMock; 1407 } 1408 } 1409} 1410