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 */ 15import { ApplicationInfo } from "../bundle/applicationInfo" 16import { BaseContextClass as BaseContext } from "./BaseContext" 17 18const ResourceManager = { 19 getString: function(...args) { 20 console.warn("ResourceManager.getString interface mocked in the Previewer. " + 21 "How this interface works on the Previewer may be different from that on a real device.") 22 const len = args.length 23 if (typeof args[len - 1] === 'function') { 24 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 25 } else { 26 return new Promise((resolve, reject) => { 27 resolve(paramMock.paramStringMock); 28 }) 29 } 30 }, 31 32 getStringArray: function(...args) { 33 console.warn("ResourceManager.getStringArray interface mocked in the Previewer. " + 34 "How this interface works on the Previewer may be different from that on a real device.") 35 const len = args.length 36 if (typeof args[len - 1] === 'function') { 37 args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paramStringMock]); 38 } else { 39 return new Promise((resolve, reject) => { 40 resolve([paramMock.paramStringMock]); 41 }) 42 } 43 }, 44 45 getMedia: function(...args) { 46 console.warn("ResourceManager.getMedia interface mocked in the Previewer. " + 47 "How this interface works on the Previewer may be different from that on a real device.") 48 const len = args.length 49 if (typeof args[len - 1] === 'function') { 50 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); 51 } else { 52 return new Promise((resolve, reject) => { 53 resolve(paramMock.paramArrayMock); 54 }) 55 } 56 }, 57 58 getMediaBase64: function(...args) { 59 console.warn("ResourceManager.getMediaBase64 interface mocked in the Previewer. " + 60 "How this interface works on the Previewer may be different from that on a real device.") 61 const len = args.length 62 if (typeof args[len - 1] === 'function') { 63 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); 64 } else { 65 return new Promise((resolve, reject) => { 66 resolve(paramMock.paramArrayMock); 67 }) 68 } 69 }, 70 71 getPluralString: function(...args) { 72 console.warn("ResourceManager.getPluralString interface mocked in the Previewer. " + 73 "How this interface works on the Previewer may be different from that on a real device.") 74 const len = args.length 75 if (typeof args[len - 1] === 'function') { 76 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 77 } else { 78 return new Promise((resolve, reject) => { 79 resolve(paramMock.paramStringMock); 80 }) 81 } 82 }, 83 84 getConfiguration: function(...args) { 85 console.warn("ResourceManager.getConfiguration interface mocked in the Previewer. " + 86 "How this interface works on the Previewer may be different from that on a real device.") 87 const len = args.length 88 if (typeof args[len - 1] === 'function') { 89 args[len - 1].call(this, paramMock.businessErrorMock, new ConfigurationClass()); 90 } else { 91 return new Promise((resolve, reject) => { 92 resolve(new ConfigurationClass()); 93 }) 94 } 95 }, 96 97 getDeviceCapability: function(...args) { 98 console.warn("ResourceManager.getDeviceCapability interface mocked in the Previewer. " + 99 "How this interface works on the Previewer may 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, new DeviceCapabilityClass()); 103 } else { 104 return new Promise((resolve, reject) => { 105 resolve(new DeviceCapabilityClass()); 106 }) 107 } 108 }, 109 110 release: function() { 111 console.warn("ResourceManager.release interface mocked in the Previewer. " + 112 "How this interface works on the Previewer may be different from that on a real device.") 113 }, 114 115 getRawFile: function(...args) { 116 console.warn("ResourceManager.getRawFile interface mocked in the Previewer. " + 117 "How this interface works on the Previewer may be different from that on a real device.") 118 const len = args.length 119 if (typeof args[len - 1] === 'function') { 120 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); 121 } else { 122 return new Promise((resolve, reject) => { 123 resolve(paramMock.paramArrayMock); 124 }) 125 } 126 }, 127 128 getRawFileDescriptor: function(...args) { 129 console.warn("ResourceManager.getRawFileDescriptor interface mocked in the Previewer. " + 130 "How this interface works on the Previewer may be different from that on a real device.") 131 const len = args.length 132 if (typeof args[len - 1] === 'function') { 133 args[len - 1].call(this, paramMock.businessErrorMock, RawFileDescriptor); 134 } else { 135 return new Promise((resolve, reject) => { 136 resolve(RawFileDescriptor); 137 }) 138 } 139 }, 140 141 closeRawFileDescriptor: function(...args) { 142 console.warn("ResourceManager.closeRawFileDescriptor interface mocked in the Previewer. " + 143 "How this interface works on the Previewer 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, paramMock.paramStringMock); 147 } else { 148 return new Promise((resolve, reject) => { 149 resolve(paramMock.paramStringMock); 150 }) 151 } 152 }, 153 154 getStringByName: function(...args) { 155 console.warn("ResourceManager.getStringByName interface mocked in the Previewer. " + 156 "How this interface works on the Previewer may be different from that on a real device.") 157 const len = args.length 158 if (typeof args[len - 1] === 'function') { 159 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 160 } else { 161 return new Promise((resolve, reject) => { 162 resolve(paramMock.paramStringMock); 163 }) 164 } 165 }, 166 167 getStringArrayByName: function(...args) { 168 console.warn("ResourceManager.getStringArrayByName interface mocked in the Previewer. " + 169 "How this interface works on the Previewer may be different from that on a real device.") 170 const len = args.length 171 if (typeof args[len - 1] === 'function') { 172 args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paramStringMock]); 173 } else { 174 return new Promise((resolve, reject) => { 175 resolve([paramMock.paramStringMock]); 176 }) 177 } 178 }, 179 180 getMediaByName: function(...args) { 181 console.warn("ResourceManager.getMediaByName interface mocked in the Previewer. " + 182 "How this interface works on the Previewer may be different from that on a real device.") 183 const len = args.length 184 if (typeof args[len - 1] === 'function') { 185 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); 186 } else { 187 return new Promise((resolve, reject) => { 188 resolve(paramMock.paramArrayMock); 189 }) 190 } 191 }, 192 193 getMediaBase64ByName: function(...args) { 194 console.warn("ResourceManager.getMediaBase64ByName interface mocked in the Previewer. " + 195 "How this interface works on the Previewer may 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.paramArrayMock); 199 } else { 200 return new Promise((resolve, reject) => { 201 resolve(paramMock.paramArrayMock); 202 }) 203 } 204 }, 205 206 getPluralStringByName: function(...args) { 207 console.warn("ResourceManager.getPluralStringByName interface mocked in the Previewer. " + 208 "How this interface works on the Previewer may be different from that on a real device.") 209 const len = args.length 210 if (typeof args[len - 1] === 'function') { 211 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 212 } else { 213 return new Promise((resolve, reject) => { 214 resolve(paramMock.paramStringMock); 215 }) 216 } 217 }, 218 219 getStringSync: function(...args) { 220 console.warn("ResourceManager.getStringSync interface mocked in the Previewer. " + 221 "How this interface works on the Previewer may be different from that on a real device.") 222 return paramMock.paramStringMock; 223 }, 224 225 getStringByNameSync: function(...args) { 226 console.warn("ResourceManager.getStringByNameSync interface mocked in the Previewer. " + 227 "How this interface works on the Previewer may be different from that on a real device.") 228 return paramMock.paramStringMock; 229 }, 230 231 getBoolean: function(...args) { 232 console.warn("ResourceManager.getBoolean interface mocked in the Previewer. " + 233 "How this interface works on the Previewer may be different from that on a real device.") 234 return paramMock.paramBooleanMock; 235 }, 236 237 getBooleanByName: function(...args) { 238 console.warn("ResourceManager.getBooleanByName interface mocked in the Previewer. " + 239 "How this interface works on the Previewer may be different from that on a real device.") 240 return paramMock.paramBooleanMock; 241 }, 242 243 getNumber: function(...args) { 244 console.warn("ResourceManager.getNumber interface mocked in the Previewer. " + 245 "How this interface works on the Previewer may be different from that on a real device.") 246 return paramMock.paramNumberMock; 247 }, 248 249 getNumberByName: function(...args) { 250 console.warn("ResourceManager.getNumberByName interface mocked in the Previewer. " + 251 "How this interface works on the Previewer may be different from that on a real device.") 252 return paramMock.paramNumberMock; 253 } 254} 255const EventHubClass = class EventHub { 256 constructor() { 257 console.warn('EventHub.constructor interface mocked in the Previewer. How this interface works on' + 258 ' the Previewer may be different from that on a real device.'); 259 this.on = function (...args) { 260 console.warn("EventHub.on interface mocked in the Previewer. How this interface works on the Previewer" + 261 " may be different from that on a real device.") 262 }; 263 this.off = function (...args) { 264 console.warn("EventHub.off interface mocked in the Previewer. How this interface works on the Previewer" + 265 " may be different from that on a real device.") 266 }; 267 this.emit = function (...args) { 268 console.warn("EventHub.emit interface mocked in the Previewer. How this interface works on the Previewer" + 269 " may be different from that on a real device.") 270 }; 271 } 272} 273export const ContextClass = class Context extends BaseContext { 274 constructor() { 275 super(); 276 console.warn('Context.constructor interface mocked in the Previewer. How this interface works on' + 277 ' the Previewer may be different from that on a real device.'); 278 this.resourceManager = ResourceManager; 279 this.applicationInfo = ApplicationInfo; 280 this.cacheDir = "[PC Preview] unknow cacheDir"; 281 this.tempDir = "[PC Preview] unknow tempDir"; 282 this.filesDir = "[PC Preview] unknow filesDir"; 283 this.databaseDir = "[PC Preview] unknow databaseDir"; 284 this.preferencesDir = "[PC Preview] unknow preferencesDir"; 285 this.storageDir = "[PC Preview] unknow storageDir"; 286 this.bundleCodeDir = "[PC Preview] unknow bundleCodeDir"; 287 this.distributedFilesDir = "[PC Preview] unknow distributedFilesDir"; 288 this.eventHub = new EventHubClass(); 289 this.area = AreaMode; 290 this.createBundleContext = function (...args) { 291 console.warn("Context.createBundleContext interface mocked in the Previewer. How this interface works on the Previewer" + 292 " may be different from that on a real device.") 293 return new ContextClass(); 294 }; 295 this.createModuleContext = function (...args) { 296 console.warn("Context.createModuleContext interface mocked in the Previewer. How this interface works on the Previewer" + 297 " may be different from that on a real device.") 298 return new ContextClass(); 299 }; 300 this.getApplicationContext = function () { 301 console.warn("Context.getApplicationContext interface mocked in the Previewer. How this interface works on the Previewer" + 302 " may be different from that on a real device.") 303 return new ContextClass(); 304 }; 305 this.switchArea = function (...args) { 306 console.warn("Context.switchArea interface mocked in the Previewer. How this interface works on the Previewer" + 307 " may be different from that on a real device.") 308 }; 309 } 310} 311export const AreaMode = { 312 EL1: 0, 313 EL2: 1 314}