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" 17 18export function mockDistributedSchedule() { 19 const ModuleInfoMock = { 20 moduleName: "[PC Preview] unknow moduleName", 21 moduleSourceDir: "[PC Preview] unknow moduleSourceDir" 22 } 23 const CustomizeDataMock = { 24 name: "[PC Preview] unknow name", 25 value: "[PC Preview] unknow values" 26 } 27 const ApplicationInfoMock = { 28 name: "[PC Preview] unknow name", 29 description: "[PC Preview] unknow description", 30 descriptionId: "[PC Preview] unknow descriptionId", 31 systemApp: "[PC Preview] unknow systemApp", 32 enabled: "[PC Preview] unknow enabled", 33 label: "[PC Preview] unknow label", 34 labelId: "[PC Preview] unknow labelId", 35 icon: "[PC Preview] unknow icon", 36 iconId: "[PC Preview] unknow iconId", 37 process: "[PC Preview] unknow process", 38 supportedModes: "[PC Preview] unknow supportedModes", 39 moduleSourceDirs: ["[PC Preview] unknow moduleSourceDir", "[PC Preview] unknow moduleSourceDir"], 40 permissions: ["[PC Preview] unknow permission", "[PC Preview] unknow permission"], 41 moduleInfo: [ModuleInfoMock], 42 entryDir: "[PC Preview] unknow entryDir", 43 customizeData: new Map([["[PC Preview] unknow customizeDataKey", CustomizeDataMock]]) 44 } 45 const AbilityInfoMock = { 46 bundleName: "[PC Preview] unknow bundleName", 47 className: "[PC Preview] unknow name", 48 label: "[PC Preview] unknow label", 49 description: "[PC Preview] unknow description", 50 icon: "[PC Preview] unknow icon", 51 labelId: "[PC Preview] unknow labelId", 52 descriptionId: "[PC Preview] unknow descriptionId", 53 iconId: "[PC Preview] unknow iconId", 54 moduleName: "[PC Preview] unknow moduleName", 55 process: "[PC Preview] unknow process", 56 targetAbility: "[PC Preview] unknow targetAbility", 57 backgroundModes: "[PC Preview] unknow backgroundModes", 58 isVisible: "[PC Preview] unknow isVisible", 59 formEnabled: "[PC Preview] unknow formEnabled", 60 type: "[PC Preview] unknow type", 61 subType: "[PC Preview] unknow subType", 62 orientation: "[PC Preview] unknow orientation", 63 launchMode: "[PC Preview] unknow launchMode", 64 permissions: ["[PC Preview] unknow permission", "[PC Preview] unknow permission"], 65 deviceTypes: ["[PC Preview] unknow deviceType", "[PC Preview] unknow deviceType"], 66 deviceCapabilities: ["[PC Preview] unknow deviceCapabilities", "[PC Preview] unknow deviceCapabilities"], 67 readPermission: "[PC Preview] unknow readPermission", 68 writePermission: "[PC Preview] unknow writePermission", 69 applicationInfo: ApplicationInfoMock, 70 formEntity: "[PC Preview] unknow formEntity", 71 minFormHeight: "[PC Preview] unknow minFormHeight", 72 defaultFormHeight: "[PC Preview] unknow defaultFormHeight", 73 minFormWidth: "[PC Preview] unknow minFormWidth", 74 defaultFormWidth: "[PC Preview] unknow defaultFormWidth", 75 uri: "[PC Preview] unknow uri", 76 customizeData: new Map([["[PC Preview] unknow customizeDataKey", CustomizeDataMock]]) 77 } 78 global.systemplugin.distributedSchedule = { 79 stopDistributedService: function (...args) { 80 console.warn("distributedSchedule.stopDistributedService interface mocked in the Previewer. " + 81 "How this interface works on the Previewer" + 82 " may be different from that on a real device.") 83 const len = args.length 84 if (typeof args[len - 1] === 'function') { 85 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 86 } else { 87 return new Promise((resolve) => { 88 resolve(paramMock.paramStringMock) 89 }) 90 } 91 }, 92 startDistributedService: function (...args) { 93 console.warn("distributedSchedule.startDistributedService interface mocked in the Previewer. " + 94 "How this interface works on the Previewer" + 95 " may be different from that on a real device.") 96 const len = args.length 97 if (typeof args[len - 1] === 'function') { 98 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 99 } else { 100 return new Promise((resolve) => { 101 resolve(paramMock.paramStringMock) 102 }) 103 } 104 }, 105 queryRemoteAbilityByWant: function (...args) { 106 console.warn("distributedSchedule.queryRemoteAbilityByWant interface mocked in the Previewer. " + 107 "How this interface works on the Previewer" + 108 " may be different from that on a real device.") 109 var array = new Array(); 110 array.push(AbilityInfoMock); 111 const len = args.length 112 if (typeof args[len - 1] === 'function') { 113 args[len - 1].call(this, paramMock.businessErrorMock, array) 114 } else { 115 return new Promise((resolve) => { 116 resolve(array) 117 }) 118 } 119 } 120 } 121}