diff --git a/runtime/main/extend/systemplugin/ability.js b/runtime/main/extend/systemplugin/ability.js index 6036f493..e69545de 100644 --- a/runtime/main/extend/systemplugin/ability.js +++ b/runtime/main/extend/systemplugin/ability.js @@ -14,7 +14,7 @@ */ import { paramMock } from "./utils" -import { windowMock } from "./window" +import { windowMock } from "./napi/ohos_window" const DataAbilityResultMock = { uri: "[PC Preview] unknow uri", diff --git a/runtime/main/extend/systemplugin/bytrace.js b/runtime/main/extend/systemplugin/bytrace.js deleted file mode 100644 index eaff3c70..00000000 --- a/runtime/main/extend/systemplugin/bytrace.js +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { paramMock } from "./utils" - -export function mockBytrace() { - const bytrace = { - startTrace: function (...args) { - console.warn("bytrace.startTrace interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - }, - finishTrace: function (...args) { - console.warn("bytrace.finishTrace interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - }, - traceByValue: function (...args) { - console.warn("bytrace.traceByValue interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - } - } - return bytrace -} diff --git a/runtime/main/extend/systemplugin/index.js b/runtime/main/extend/systemplugin/index.js index d7baabe0..e9e92371 100644 --- a/runtime/main/extend/systemplugin/index.js +++ b/runtime/main/extend/systemplugin/index.js @@ -27,39 +27,14 @@ import { import { mockAppAbilityManager } from './ohos/app' import { mockBattery } from './battery' -import { mockBrightness } from './brightness' -import { mockBluetooth } from './bluetooth' import { mockOhosBluetooth } from './ohos/bluetooth' -import { mockCall, mockData, mockRadio, mockSim, mockSMS, mockObserver } from './telephony' -import { mockBundleState } from './ohos/bundleState' -import { mockCipher } from './cipher' -import { mockDataStorage } from './data' -import { mockDeviceInfo } from './deviceInfo' import { mockDistributedSchedule } from './distributedSchedule' -import { mockDocument } from './document' import { mockFetch } from './fetch' import { mockFeatureAbility } from './featureAbility' -import { mockFile } from './file' import { mockGeolocation } from './geolocation' -import { mockInputMethod } from './inputMethod' -import { mockInputMethodEngine } from './inputMethodEngine' -import { mockNetwork } from './network' -import { mockOhosNfc } from './ohos/nfc' import { mockNotification } from './notification' import { mockCommonEvent } from './ohos/commonEvent' -import { mockWantAgent } from './ohos/wantAgent' -import { mockOhosBatteryinfo } from './batteryinfo' import { mockOhosRequest } from './ohos/request' - -import { mockPasteBoard } from './ohos/pasteboard' -import { mockSystemTime } from './ohos/systemTime' -import { mockSystemTimer } from './ohos/systemTimer' -import { mockWallpaper } from './ohos/wallpaper' -import { mockReminderAgent } from './ohos/reminderAgent' -import { mockRequest } from './request' - -import { mockResourceManager } from './resourceManager' - import { mockSensor } from './sensor' import { mockStorage } from './storage' import { mockStorageInfoManager } from './ohos/storageInfoManager' @@ -67,28 +42,14 @@ import { mockSystemPackage } from './systemPackage' import { mockUserauth } from './userIAM' import { mockVibrator } from './vibrator' - -import { mockWebSocket, mockHttp, mockMdns, mockSocket, mockHotspot, mockStatistics, mockConnection } from './net' -import { mockWindow } from './window' - import { mockRequireNapiFun } from './napi' import { mockAccessibility } from './accessibility' import { mockAI } from './ai' -import { mockDisplay } from './display' -import { mockDeviceManager } from './deviceManager' -import { mockScreenshot } from './screenshot' -import { mockContact } from './contact' -import { mockScreenLock } from "./screenLock" -import { mockAppAccount } from './ohos/appAccount' -import { mockOsAccount } from './ohos/osAccount' -import { mockOhosGeolocation } from './ohos/geolocation' -import { mockInputMonitor } from './ohos/inputMonitor' import { mockUserIAMUserAuth } from './ohos/userIAMuserAuth.js' import { mockBundleManager } from './ohos/bundleManager' import { mockPackageManager } from './ohos/packageManager' -import { mockZlib } from './napi/zlib' +import { mockZlib } from './napi/ohos_zlib' import { mockCalendar } from "./calendar" -import { mockHuks } from "./huks" export function mockSystemPlugin() { global.regeneratorRuntime = regeneratorRuntime @@ -98,54 +59,20 @@ export function mockSystemPlugin() { mockNotification() mockCommonEvent() - mockWantAgent() mockFetch() - mockRequest() mockStorage() - mockFile() mockVibrator() mockSensor() mockGeolocation() - mockNetwork() - mockBrightness() mockBattery() mockSystemPackage() mockFeatureAbility() - mockBluetooth() mockOhosBluetooth() - mockCipher() - mockOhosBatteryinfo() mockUserauth() mockDistributedSchedule() - mockDocument() - mockPasteBoard() - mockSystemTime() - mockSystemTimer() - mockWallpaper() - mockInputMethod() - mockInputMethodEngine() mockOhosRequest() - mockCall() - mockData() - mockRadio() - mockSim() - mockSMS() - mockObserver() - mockWebSocket() - mockHttp() - mockMdns() - mockSocket() - mockHotspot() - mockStatistics() - mockConnection() - mockDeviceInfo() - mockResourceManager() - mockOhosNfc() - mockDataStorage() - mockWindow() mockAbilityFeatureAbility() mockAbilityContinuationRegisterManager() - mockReminderAgent() mockRequireNapiFun() mockAbilityDataUriUtils() mockAccessibility() @@ -154,22 +81,11 @@ export function mockSystemPlugin() { mockAbilityAbilityAgent() mockAbilityFormBindingData() mockAI() - mockDisplay() - mockDeviceManager() - mockScreenshot() mockStorageInfoManager() - mockContact() - mockScreenLock() mockAppAbilityManager() - mockAppAccount() - mockOsAccount() - mockBundleState() - mockOhosGeolocation() mockUserIAMUserAuth() - mockInputMonitor() mockBundleManager() mockPackageManager() mockZlib() mockCalendar() - mockHuks() } diff --git a/runtime/main/extend/systemplugin/napi/application/abilityContext.js b/runtime/main/extend/systemplugin/napi/application/abilityContext.js index 9c44d6b0..3cdb1802 100644 --- a/runtime/main/extend/systemplugin/napi/application/abilityContext.js +++ b/runtime/main/extend/systemplugin/napi/application/abilityContext.js @@ -14,8 +14,8 @@ */ import { paramMock } from "../../utils" -import { MessageParcelClass } from "../rpc" -import { ContextClass } from "../applicationServiceExtAbility" +import { MessageParcelClass } from "../ohos_rpc" +import { ContextClass } from "../ohos_application_ServiceExtAbility" const ModuleInfoMock = { moduleName: '[PC preview] unknow moduleName', diff --git a/runtime/main/extend/systemplugin/napi/distributedDataObject.js b/runtime/main/extend/systemplugin/napi/distributedDataObject.js deleted file mode 100644 index 83f413c8..00000000 --- a/runtime/main/extend/systemplugin/napi/distributedDataObject.js +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { paramMock } from "../utils" - -export function mockDistributedObject() { - const DistributedObject = { - setSessionId: function (...args) { - console.warn("DistributedObject.setSessionId interface mocked in the Previewer." + - " How this interface works on the Previewer may be different from that on a real device.") - }, - on: function (...args) { - console.warn("DistributedObject.on interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") - }, - off: function (...args) { - console.warn("DistributedObject.off interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") - } - }; - const distributedObjectMock = { - createDistributedObject: function (...args) { - console.warn("distributedObject.createDistributedObject interface mocked in the Previewer." + - " How this interface works on the Previewer may be different from that on a real device."); - return DistributedObject; - }, - genSessionId: function (...args) { - console.warn("distributedObject.genSessionId interface mocked in the Previewer." + - " How this interface works on the Previewer may be different from that on a real device."); - return 'just test'; - } - }; - return distributedObjectMock; -} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index a3c9e0ff..f8f9b628 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -13,99 +13,218 @@ * limitations under the License. */ -import { mockSystemParameter } from './systemParameter' -import { mockAbility } from './applicationAbility' -import { mockFormExtension } from './applicationFormExtension' -import { mockServiceExtensionAbility } from './applicationServiceExtensionAbility' -import { mockAbilityStage } from './applicationAbilityStage' -import { mockFormBindingData } from './applicationFormBindingData' -import { mockAbilityManager } from './applicationAbilityManager' -import { mockAppManager } from './applicationAppManager' -import { mockDataShareExtensionAbility } from './applicationDataShareExtensionAbility' -import { mockMissionManager } from "./applicationMissionManager" -import { mockServiceExtAbility } from "./applicationServiceExtAbility" -import { mockUriPermissionManager } from "./applicationUriPermissionManager" -import { mockCommonEvent } from './commonEvent' -import { mockNotification } from './notification' -import { mockFileio } from './fileio' -import { mockWorker } from './worker' -import { mockUtil } from './util' -import { mockPower } from './power' -import { mockRunninglock } from './runninglock' -import { mockThermal } from './thermal' -import { mockBatteryStatistics } from './batteryStatistics' -import { mockIntl } from './intl' -import { mockI18N } from './i18n' -import { mockRpc } from './rpc' -import { mockBytrace } from './bytrace' +import { mockSystemParameter } from './ohos_systemparameter' +import { mockAbility } from './ohos_application_Ability' +import { mockFormExtension } from './ohos_application_FormExtension' +import { mockServiceExtensionAbility } from './ohos_application_ServiceExtensionAbility' +import { mockAbilityStage } from './ohos_application_AbilityStage' +import { mockFormBindingData } from './ohos_application_formBindingData' +import { mockAbilityManager } from './ohos_application_abilityManager' +import { mockAppManager } from './ohos_application_appManager' +import { mockDataShareExtensionAbility } from './ohos_application_DataShareExtensionAbility' +import { mockMissionManager } from "./ohos_application_missionManager" +import { mockServiceExtAbility } from "./ohos_application_ServiceExtAbility" +import { mockUriPermissionManager } from "./ohos_application_uriPermissionManager" +import { mockCommonEvent } from './ohos_commonEvent' +import { mockNotification } from './ohos_notification' +import { mockFileio } from './ohos_fileio' +import { mockWorker } from './ohos_worker' +import { mockUtil } from './ohos_util' +import { mockPower } from './ohos_power' +import { mockRunninglock } from './ohos_runninglock' +import { mockThermal } from './ohos_thermal' +import { mockBatteryStatistics } from './ohos_batteryStatistics' +import { mockIntl } from './ohos_intl' +import { mockI18N } from './ohos_i18n' +import { mockRpc } from './ohos_rpc' import { mockwebgl } from './webgl' import { mockwebgl2 } from './webgl2' -import { mockProcess } from './process' -import { mockUrl } from './url' -import { mockHiAppEvent } from './hiAppEvent' -import { mockHilog } from './hilog' +import { mockProcess } from './ohos_process' +import { mockUrl } from './ohos_url' +import { mockHiAppEvent } from './ohos_hiAppEvent' +import { mockHilog } from './ohos_hilog' import { mockTv } from './tv' import { mockDtv } from './dtv' -import { mockDistributedAccount } from './distributedAccount' -import { mockEmitter } from './emitter' -import { mockDistributedData } from './distributedData' -import { mockDistributedObject } from './distributedDataObject' -import { mockDataAbility } from './dataAbility' -import { mockStorage } from './storage' -import { mockRdb } from './rdb' -import { mockDataShare } from './dataShare' -import { mockInputDevice } from './inputDevice' -import { mockVibrator } from './vibrator' -import { mockSensor } from './sensor' -import { mockWifi } from './wifi' -import { mockUsb } from './usb' -import { mockBundle } from './bundle' -import { mockInnerBundle } from './innerBundleManager' -import { mockUri } from './uri' -import { mockXml } from './xml' -import { mockConvertXml } from './convertxml' -import { mockStatfs } from './statfs' -import { mockFileManager } from "./filemanager" -import { mockEnvironment } from "./environment" -import { mockStorageStatistics } from "./storageStatistics" -import { mockVolumeManager } from "./volumeManager" -import { mockSettings } from './settings' -import { mockAbilityAccessCtrl } from './abilityAccessCtrl' -import { mockConfigPolicy } from './configPolicy' -import { mockUpdate } from './update' -import { mockBackgroundTaskManager } from './backgroundTaskManager' -import { mockSecurityLabel } from './securitylabel' -import { mockWorkScheduler } from './workScheduler' -import { mockWorkSchedulerExtensionAbility } from './WorkSchedulerExtensionAbility' -import { mockUserAuth } from './userAuth' -import { mockArrayList } from './arraylist' -import { mockDeque } from './deque' -import { mockHashMap } from './hashmap' -import { mockHashSet } from './hashset' -import { mockLightWeightMap } from './lightweightmap' -import { mockLightWeightSet } from './lightweightset' -import { mockLinkedList } from './linkedlist' -import { mockList } from './list' -import { mockPlainArray } from './plainarray' -import { mockQueue } from './queue' -import { mockStack } from './stack' -import { mockTreeMap } from './treemap' -import { mockTreeSet } from './treeset' -import { mockVector } from './vector' -import { mockMultimediaCamera } from './multimediaCamera' -import { mockMultimediaAudio } from './multimediaAudio' -import { mockMultimediaImage } from './multimediaImage' -import { mockMultimediaMedia } from './multimediaMedia' -import { mockMultimediaMediaLibrary } from './multimediaMediaLibrary' - - - +import { mockDistributedAccount } from './ohos_account_distributedAccount' +import { mockEmitter } from './ohos_events_emitter' +import { mockDistributedData } from './ohos_data_distributedData' +import { mockDistributedObject } from './ohos_data_distributedDataObject' +import { mockDataAbility } from './ohos_data_dataAbility' +import { mockStorage } from './system_storage' +import { mockRdb } from './ohos_data_rdb' +import { mockDataShare } from './ohos_data_dataShare' +import { mockInputDevice } from './ohos_multimodalInput_inputDevice' +import { mockVibrator } from './ohos_vibrator' +import { mockSensor } from './ohos_sensor' +import { mockWifi } from './ohos_wifi' +import { mockUsb } from './ohos_usb' +import { mockBundle } from './ohos_bundle' +import { mockInnerBundle } from './ohos_bundle_innerBundleManager' +import { mockUri } from './ohos_uri' +import { mockXml } from './ohos_xml' +import { mockConvertXml } from './ohos_convertxml' +import { mockStatfs } from './ohos_statfs' +import { mockFileManager } from "./ohos_fileManager" +import { mockEnvironment } from "./ohos_environment" +import { mockStorageStatistics } from "./ohos_storageStatistics" +import { mockVolumeManager } from "./ohos_volumeManager" +import { mockSettings } from './ohos_settings' +import { mockAbilityAccessCtrl } from './ohos_abilityAccessCtrl' +import { mockConfigPolicy } from './ohos_configPolicy' +import { mockUpdate } from './ohos_update' +import { mockBackgroundTaskManager } from './ohos_backgroundTaskManager' +import { mockSecurityLabel } from './ohos_securitylabel' +import { mockWorkScheduler } from './ohos_workScheduler' +import { mockWorkSchedulerExtensionAbility } from './ohos_WorkSchedulerExtensionAbility' +import { mockUserAuth } from './ohos_userIAM_userAuth' +import { mockArrayList } from './ohos_util_Arraylist' +import { mockDeque } from './ohos_util_Deque' +import { mockHashMap } from './ohos_util_HashMap' +import { mockHashSet } from './ohos_util_HashSet' +import { mockLightWeightMap } from './ohos_util_LightWeightMap' +import { mockLightWeightSet } from './ohos_util_LightWeightSet' +import { mockLinkedList } from './ohos_util_LinkedList' +import { mockList } from './ohos_util_List' +import { mockPlainArray } from './ohos_util_PlainArray' +import { mockQueue } from './ohos_util_Queue' +import { mockStack } from './ohos_util_Stack' +import { mockTreeMap } from './ohos_util_TreeMap' +import { mockTreeSet } from './ohos_util_TreeSet' +import { mockVector } from './ohos_util_Vector' +import { mockMultimediaCamera } from './ohos_multimedia_camera' +import { mockMultimediaAudio } from './ohos_multimedia_audio' +import { mockMultimediaImage } from './ohos_multimedia_image' +import { mockMultimediaMedia } from './ohos_multimedia_media' +import { mockMultimediaMediaLibrary } from './ohos_multimedia_mediaLibrary' +import { mockOhosBatteryinfo } from './ohos_batteryInfo' +import { mockBluetooth } from './ohos_bluetooth' +import { mockBrightness } from './ohos_brightness' +import { mockBytrace } from './ohos_bytrace' +import { mockCipher } from './system_cipher' +import { mockContact } from './ohos_contact' +import { mockDataStorage } from './ohos_data_Storage' +import { mockDeviceInfo } from './ohos_deviceInfo' +import { mockDeviceManager } from './ohos_distributedHardware_deviceManager' +import { mockDisplay } from './ohos_display' +import { mockHuks } from './ohos_security_huks' +import { mockInputMethod } from './ohos_inputmethod' +import { mockInputMethodEngine } from './ohos_inputmethodengine' +import { mockConnection } from './ohos_net_connection' +import { mockHttp } from './ohos_net_http' +import { mockSocket } from './ohos_net_socket' +import { mockWebSocket } from './ohos_net_webSocket' +import { mockNetwork } from './ohos_network' +import { mockNfcCardEmulation } from './ohos_nfc_cardEmulation' +import { mockController } from './ohos_nfc_controller' +import { mockTag } from './ohos_nfc_tag' +import { mockPasteBoard } from './ohos_pasteboard' +import { mockRequest } from './ohos_request' +import { mockScreenLock } from './ohos_screenLock' +import { mockCall } from './ohos_telephony_call' +import { mockData } from './ohos_telephony_data' +import { mockObserver } from './ohos_telephony_observer' +import { mockRadio } from './ohos_telephony_radio' +import { mockSim } from './ohos_telephony_sim' +import { mockSMS } from './ohos_telephony_sms' +import { mockWindow } from './ohos_window' +import { mockAppAccount } from './ohos_account_appAccount' +import { mockOhosGeolocation } from './ohos_geolocation' +import { mockInputMonitor } from './ohos_multimodalInput_inputMonitor' +import { mockOsAccount } from './ohos_account_osAccount' +import { mockReminderAgent } from './ohos_reminderAgent' +import { mockSystemTime } from './ohos_systemTime' +import { mockSystemTimer } from './ohos_systemTimer' +import { mockWallpaper } from './ohos_wallpaper' +import { mockWantAgent } from './ohos_wantAgent' +import { mockScreenshot } from './ohos_screenshot' export function mockRequireNapiFun() { global.requireNapi = function (...args) { switch (args[0]) { + case "screenshot": + return mockScreenshot(); + case "WantAgent": + return mockWantAgent(); + case "wallpaper": + return mockWallpaper(); + case "systemTimer": + return mockSystemTimer(); + case "systemTime": + return mockSystemTime(); + case "reminderAgent": + return mockReminderAgent(); + case "account.osAccount": + return mockOsAccount(); + case "multimodalInput.inputMonitor": + return mockInputMonitor(); + case "geolocation": + return mockOhosGeolocation(); + case "account.appAccount": + return mockAppAccount(); + case "window": + return mockWindow(); + case "telephony.call": + return mockCall(); + case "telephony.data": + return mockData(); + case "telephony.observer": + return mockObserver(); + case "telephony.radio": + return mockRadio(); + case "telephony.sim": + return mockSim(); + case "telephony.sms": + return mockSMS(); + case "pasteboard": + return mockPasteBoard(); + case "request": + return mockRequest(); + case "screenLock": + return mockScreenLock(); + case "nfc.cardEmulation": + return mockNfcCardEmulation(); + case "nfc.controller": + return mockController(); + case "nfc.tag": + return mockTag(); + case "network": + return mockNetwork(); + case "net.connection": + return mockConnection(); + case "net.http": + return mockHttp(); + case "net.socket": + return mockSocket(); + case "net.webSocket": + return mockWebSocket(); + case "inputmethodengine": + return mockInputMethodEngine(); + case "inputmethod": + return mockInputMethod(); + case "security.huks": + return mockHuks(); + case "display": + return mockDisplay(); + case "distributedHardware.deviceManager": + return mockDeviceManager(); + case "deviceInfo": + return mockDeviceInfo(); + case "data.storage": + return mockDataStorage(); + case "contact": + return mockContact(); + case "cipher": + return mockCipher(); + case "bytrace": + return mockBytrace(); + case "brightness": + return mockBrightness(); + case "bluetooth": + return mockBluetooth(); + case "batteryInfo": + return mockOhosBatteryinfo(); case "systemParameter": return mockSystemParameter(); - case "application.Ability": + case "11.Ability": return mockAbility(); case "application.FormExtension": return mockFormExtension(); @@ -157,8 +276,6 @@ export function mockRequireNapiFun() { return mockwebgl2(); case "process": return mockProcess(); - case "bytrace": - return mockBytrace(); case "url": return mockUrl(); case "hiAppEvent": @@ -232,7 +349,7 @@ export function mockRequireNapiFun() { case "WorkSchedulerExtensionAbility": return mockWorkSchedulerExtensionAbility(); case "userIAM.userAuth": - return mockUserAuth(); + return mockUserAuth(); case "util.ArrayList": return mockArrayList(); case "util.Deque": @@ -262,7 +379,7 @@ export function mockRequireNapiFun() { case "util.Vector": return mockVector(); case "multimedia.mediaLibrary": - return mockMultimediaMediaLibrary(); + return mockMultimediaMediaLibrary(); case "multimedia.media": return mockMultimediaMedia(); case "multimedia.image": diff --git a/runtime/main/extend/systemplugin/napi/WorkSchedulerExtensionAbility.js b/runtime/main/extend/systemplugin/napi/ohos_WorkSchedulerExtensionAbility.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/WorkSchedulerExtensionAbility.js rename to runtime/main/extend/systemplugin/napi/ohos_WorkSchedulerExtensionAbility.js diff --git a/runtime/main/extend/systemplugin/napi/abilityAccessCtrl.js b/runtime/main/extend/systemplugin/napi/ohos_abilityAccessCtrl.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/abilityAccessCtrl.js rename to runtime/main/extend/systemplugin/napi/ohos_abilityAccessCtrl.js diff --git a/runtime/main/extend/systemplugin/ohos/appAccount.js b/runtime/main/extend/systemplugin/napi/ohos_account_appAccount.js similarity index 86% rename from runtime/main/extend/systemplugin/ohos/appAccount.js rename to runtime/main/extend/systemplugin/napi/ohos_account_appAccount.js index c82a7f78..0b1e8231 100644 --- a/runtime/main/extend/systemplugin/ohos/appAccount.js +++ b/runtime/main/extend/systemplugin/napi/ohos_account_appAccount.js @@ -1,438 +1,437 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { paramMock } from "../utils" - -export function mockAppAccount() { - const appAccountInfoMock = { - owner: "[PC Preview] unknown owner", - name: "[PC Preview] unknown name" - }; - const OAuthTokenInfoMock = { - authType: "[PC preview] unknown authType", - token: "[PC preview] unknown token" - }; - const AuthenticatorInfoMock = { - owner: "[PC preview] unknown owner", - iconId: "[PC preview] unknown iconId", - labelId: "[PC preview] unknown labelId", - }; - - const appAccountManagerMock = { - addAccount: function (...args) { - console.warn("AppAccountManager.addAccount interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - addAccountImplicitly: function (...args) { - console.warn("AppAccountManager.addAccountImplicitly interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock); - } - }, - deleteAccount: function (...args) { - console.warn("AppAccountManager.deleteAccount interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - disableAppAccess: function (...args) { - console.warn("AppAccountManager.disableAppAccess interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - enableAppAccess: function (...args) { - console.warn("AppAccountManager.enableAppAccess interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - checkAppAccountSyncEnable: function (...args) { - console.warn("AppAccountManager.checkAppAccountSyncEnable interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - setAccountCredential: function (...args) { - console.warn("AppAccountManager.setAccountCredential interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - setAccountExtraInfo: function (...args) { - console.warn("AppAccountManager.setAccountExtraInfo interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - setAppAccountSyncEnable: function (...args) { - console.warn("AppAccountManager.setAppAccountSyncEnable interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - setAssociatedData: function (...args) { - console.warn("AppAccountManager.setAssociatedData interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getAllAccessibleAccounts: function (...args) { - console.warn("AppAccountManager.getAllAccessibleAccounts interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - var appAccountInfoArrayMock = new Array(); - appAccountInfoArrayMock.push(appAccountInfoMock); - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, appAccountInfoArrayMock); - } else { - return new Promise((resolve, reject) => { - resolve(appAccountInfoArrayMock); - }) - } - }, - getAllAccounts: function (...args) { - console.warn("AppAccountManager.getAllAccounts interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - var appAccountInfoArrayMock = new Array(); - appAccountInfoArrayMock.push(appAccountInfoMock); - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, appAccountInfoArrayMock); - } else { - return new Promise((resolve, reject) => { - resolve(appAccountInfoArrayMock); - }) - } - }, - getAccountCredential: function (...args) { - console.warn("AppAccountManager.getAccountCredential interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getAccountExtraInfo: function (...args) { - console.warn("AppAccountManager.getAccountExtraInfo interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getAssociatedData: function (...args) { - console.warn("AppAccountManager.getAssociatedData interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - on: function (...args) { - console.warn("AppAccountManager.on interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - var appAccountInfoArrayMock = new Array(); - appAccountInfoArrayMock.push(appAccountInfoMock); - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, appAccountInfoArrayMock); - } else { - return new Promise((resolve, reject) => { - resolve(appAccountInfoArrayMock); - }) - } - }, - off: function (...args) { - console.warn("AppAccountManager.off interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - var appAccountInfoArrayMock = new Array(); - appAccountInfoArrayMock.push(appAccountInfoMock); - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, appAccountInfoArrayMock); - } else { - return new Promise((resolve, reject) => { - resolve(appAccountInfoArrayMock); - }) - } - }, - authenticate: function (...args) { - console.warn("AppAccountManager.authenticate interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock); - } - }, - getOAuthToken: function (...args) { - console.warn("AppAccountManager.getOAuthToken interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock) - }) - } - }, - setOAuthToken: function (...args) { - console.warn("AppAccountManager.setOAuthToken interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve() - }) - } - }, - deleteOAuthToken: function (...args) { - console.warn("AppAccountManager.deleteOAuthToken interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve() - }) - } - }, - setOAuthTokenVisibility: function (...args) { - console.warn("AppAccountManager.setOAuthTokenVisibility interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve() - }) - } - }, - checkOAuthTokenVisibility: function (...args) { - console.warn("AppAccountManager.checkOAuthTokenVisibility interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve() - }) - } - }, - getAllOAuthTokens: function (...args) { - console.warn("AppAccountManager.getAllOAuthTokens interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, new Array(OAuthTokenInfoMock)); - } else { - return new Promise((resolve, reject) => { - resolve(new Array(OAuthTokenInfoMock)) - }) - } - }, - getOAuthList: function (...args) { - console.warn("AppAccountManager.getOAuthList interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, new Array(paramMock.paramStringMock)); - } else { - return new Promise((resolve, reject) => { - resolve(new Array(paramMock.paramStringMock)) - }) - } - }, - getAuthenticatorCallback: function (...args) { - console.warn("AppAccountManager.getAuthenticatorCallback interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock); - } else { - return new Promise((resolve, reject) => { - resolve(AuthenticatorCallbackMock) - }) - } - }, - getAuthenticatorInfo: function (...args) { - console.warn("AppAccountManager.getAuthenticatorInfo interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorInfoMock); - } else { - return new Promise((resolve, reject) => { - resolve(AuthenticatorInfoMock) - }) - } - } - }; - const AuthenticatorCallbackMock = { - onResult: function (...args) { - console.warn("AuthenticatorCallback.onResult interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - }, - onRequestRedirected: function (...args) { - console.warn("AuthenticatorCallback.onRequestRedirected interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - } - }; - const AuthenticatorClass = class Authenticator { - constructor() { - console.warn("appAccount.Authenticator constructor interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - this.addAccountImplicitly = function (...args) { - console.warn("Authenticator.addAccountImplicitly interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock); - } - }; - this.authenticate = function (...args) { - console.warn("Authenticator.authenticate interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock); - } - }; - } - }; - const ConstantsMock = { - ACTION_ADD_ACCOUNT_IMPLICITLY: '[PC preview] unknow string', - ACTION_AUTHENTICATE: '[PC preview] unknow string', - KEY_NAME: '[PC preview] unknow string', - KEY_OWNER: '[PC preview] unknow string', - KEY_TOKEN: '[PC preview] unknow string', - KEY_ACTION: '[PC preview] unknow string', - KEY_AUTH_TYPE: '[PC preview] unknow string', - KEY_SESSION_ID: '[PC preview] unknow string', - KEY_CALLER_PID: '[PC preview] unknow string', - KEY_CALLER_UID: '[PC preview] unknow string', - KEY_CALLER_BUNDLE_NAME: '[PC preview] unknow string' - }; - const ResultCodeMock = { - SUCCESS: '[PC preview] unknow resultCode', - ERROR_ACCOUNT_NOT_EXIST: '[PC preview] unknow resultCode', - ERROR_APP_ACCOUNT_SERVICE_EXCEPTION: '[PC preview] unknow resultCode', - ERROR_INVALID_PASSWORD: '[PC preview] unknow resultCode', - ERROR_INVALID_REQUEST: '[PC preview] unknow resultCode', - ERROR_INVALID_RESPONSE: '[PC preview] unknow resultCode', - ERROR_NETWORK_EXCEPTION: '[PC preview] unknow resultCode', - ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST: '[PC preview] unknow resultCode', - ERROR_OAUTH_CANCELED: '[PC preview] unknow resultCode', - ERROR_OAUTH_LIST_TOO_LARGE: '[PC preview] unknow resultCode', - ERROR_OAUTH_SERVICE_BUSY: '[PC preview] unknow resultCode', - ERROR_OAUTH_SERVICE_EXCEPTION: '[PC preview] unknow resultCode', - ERROR_OAUTH_SESSION_NOT_EXIST: '[PC preview] unknow resultCode', - ERROR_OAUTH_TIMEOUT: '[PC preview] unknow resultCode', - ERROR_OAUTH_TOKEN_NOT_EXIST: '[PC preview] unknow resultCode', - ERROR_OAUTH_TOKEN_TOO_MANY: '[PC preview] unknow resultCode', - ERROR_OAUTH_UNSUPPORT_ACTION: '[PC preview] unknow resultCode', - ERROR_OAUTH_UNSUPPORT_AUTH_TYPE: '[PC preview] unknow resultCode', - ERROR_PERMISSION_DENIED: '[PC preview] unknow resultCode' - }; - - global.ohosplugin.account = global.ohosplugin.account || {}; - global.ohosplugin.account.appAccount = { - createAppAccountManager: function (...args) { - console.warn("appAccount.createAppAccountManager interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - return appAccountManagerMock; - }, - AuthenticatorCallback:AuthenticatorCallbackMock, - Authenticator:AuthenticatorClass, - Constants:ConstantsMock, - ResultCode:ResultCodeMock, - } +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockAppAccount() { + const appAccountInfoMock = { + owner: "[PC Preview] unknown owner", + name: "[PC Preview] unknown name" + }; + const OAuthTokenInfoMock = { + authType: "[PC preview] unknown authType", + token: "[PC preview] unknown token" + }; + const AuthenticatorInfoMock = { + owner: "[PC preview] unknown owner", + iconId: "[PC preview] unknown iconId", + labelId: "[PC preview] unknown labelId", + }; + + const appAccountManagerMock = { + addAccount: function (...args) { + console.warn("AppAccountManager.addAccount interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + addAccountImplicitly: function (...args) { + console.warn("AppAccountManager.addAccountImplicitly interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock); + } + }, + deleteAccount: function (...args) { + console.warn("AppAccountManager.deleteAccount interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + disableAppAccess: function (...args) { + console.warn("AppAccountManager.disableAppAccess interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + enableAppAccess: function (...args) { + console.warn("AppAccountManager.enableAppAccess interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + checkAppAccountSyncEnable: function (...args) { + console.warn("AppAccountManager.checkAppAccountSyncEnable interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + setAccountCredential: function (...args) { + console.warn("AppAccountManager.setAccountCredential interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + setAccountExtraInfo: function (...args) { + console.warn("AppAccountManager.setAccountExtraInfo interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + setAppAccountSyncEnable: function (...args) { + console.warn("AppAccountManager.setAppAccountSyncEnable interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + setAssociatedData: function (...args) { + console.warn("AppAccountManager.setAssociatedData interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getAllAccessibleAccounts: function (...args) { + console.warn("AppAccountManager.getAllAccessibleAccounts interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + var appAccountInfoArrayMock = new Array(); + appAccountInfoArrayMock.push(appAccountInfoMock); + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, appAccountInfoArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(appAccountInfoArrayMock); + }) + } + }, + getAllAccounts: function (...args) { + console.warn("AppAccountManager.getAllAccounts interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + var appAccountInfoArrayMock = new Array(); + appAccountInfoArrayMock.push(appAccountInfoMock); + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, appAccountInfoArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(appAccountInfoArrayMock); + }) + } + }, + getAccountCredential: function (...args) { + console.warn("AppAccountManager.getAccountCredential interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getAccountExtraInfo: function (...args) { + console.warn("AppAccountManager.getAccountExtraInfo interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getAssociatedData: function (...args) { + console.warn("AppAccountManager.getAssociatedData interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + on: function (...args) { + console.warn("AppAccountManager.on interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + var appAccountInfoArrayMock = new Array(); + appAccountInfoArrayMock.push(appAccountInfoMock); + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, appAccountInfoArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(appAccountInfoArrayMock); + }) + } + }, + off: function (...args) { + console.warn("AppAccountManager.off interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + var appAccountInfoArrayMock = new Array(); + appAccountInfoArrayMock.push(appAccountInfoMock); + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, appAccountInfoArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(appAccountInfoArrayMock); + }) + } + }, + authenticate: function (...args) { + console.warn("AppAccountManager.authenticate interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock); + } + }, + getOAuthToken: function (...args) { + console.warn("AppAccountManager.getOAuthToken interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock) + }) + } + }, + setOAuthToken: function (...args) { + console.warn("AppAccountManager.setOAuthToken interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve() + }) + } + }, + deleteOAuthToken: function (...args) { + console.warn("AppAccountManager.deleteOAuthToken interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve() + }) + } + }, + setOAuthTokenVisibility: function (...args) { + console.warn("AppAccountManager.setOAuthTokenVisibility interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve() + }) + } + }, + checkOAuthTokenVisibility: function (...args) { + console.warn("AppAccountManager.checkOAuthTokenVisibility interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve() + }) + } + }, + getAllOAuthTokens: function (...args) { + console.warn("AppAccountManager.getAllOAuthTokens interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, new Array(OAuthTokenInfoMock)); + } else { + return new Promise((resolve, reject) => { + resolve(new Array(OAuthTokenInfoMock)) + }) + } + }, + getOAuthList: function (...args) { + console.warn("AppAccountManager.getOAuthList interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, new Array(paramMock.paramStringMock)); + } else { + return new Promise((resolve, reject) => { + resolve(new Array(paramMock.paramStringMock)) + }) + } + }, + getAuthenticatorCallback: function (...args) { + console.warn("AppAccountManager.getAuthenticatorCallback interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock); + } else { + return new Promise((resolve, reject) => { + resolve(AuthenticatorCallbackMock) + }) + } + }, + getAuthenticatorInfo: function (...args) { + console.warn("AppAccountManager.getAuthenticatorInfo interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorInfoMock); + } else { + return new Promise((resolve, reject) => { + resolve(AuthenticatorInfoMock) + }) + } + } + }; + const AuthenticatorCallbackMock = { + onResult: function (...args) { + console.warn("AuthenticatorCallback.onResult interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + }, + onRequestRedirected: function (...args) { + console.warn("AuthenticatorCallback.onRequestRedirected interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + } + }; + const AuthenticatorClass = class Authenticator { + constructor() { + console.warn("appAccount.Authenticator constructor interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + this.addAccountImplicitly = function (...args) { + console.warn("Authenticator.addAccountImplicitly interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock); + } + }; + this.authenticate = function (...args) { + console.warn("Authenticator.authenticate interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock); + } + }; + } + }; + const ConstantsMock = { + ACTION_ADD_ACCOUNT_IMPLICITLY: '[PC preview] unknow string', + ACTION_AUTHENTICATE: '[PC preview] unknow string', + KEY_NAME: '[PC preview] unknow string', + KEY_OWNER: '[PC preview] unknow string', + KEY_TOKEN: '[PC preview] unknow string', + KEY_ACTION: '[PC preview] unknow string', + KEY_AUTH_TYPE: '[PC preview] unknow string', + KEY_SESSION_ID: '[PC preview] unknow string', + KEY_CALLER_PID: '[PC preview] unknow string', + KEY_CALLER_UID: '[PC preview] unknow string', + KEY_CALLER_BUNDLE_NAME: '[PC preview] unknow string' + }; + const ResultCodeMock = { + SUCCESS: '[PC preview] unknow resultCode', + ERROR_ACCOUNT_NOT_EXIST: '[PC preview] unknow resultCode', + ERROR_APP_ACCOUNT_SERVICE_EXCEPTION: '[PC preview] unknow resultCode', + ERROR_INVALID_PASSWORD: '[PC preview] unknow resultCode', + ERROR_INVALID_REQUEST: '[PC preview] unknow resultCode', + ERROR_INVALID_RESPONSE: '[PC preview] unknow resultCode', + ERROR_NETWORK_EXCEPTION: '[PC preview] unknow resultCode', + ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST: '[PC preview] unknow resultCode', + ERROR_OAUTH_CANCELED: '[PC preview] unknow resultCode', + ERROR_OAUTH_LIST_TOO_LARGE: '[PC preview] unknow resultCode', + ERROR_OAUTH_SERVICE_BUSY: '[PC preview] unknow resultCode', + ERROR_OAUTH_SERVICE_EXCEPTION: '[PC preview] unknow resultCode', + ERROR_OAUTH_SESSION_NOT_EXIST: '[PC preview] unknow resultCode', + ERROR_OAUTH_TIMEOUT: '[PC preview] unknow resultCode', + ERROR_OAUTH_TOKEN_NOT_EXIST: '[PC preview] unknow resultCode', + ERROR_OAUTH_TOKEN_TOO_MANY: '[PC preview] unknow resultCode', + ERROR_OAUTH_UNSUPPORT_ACTION: '[PC preview] unknow resultCode', + ERROR_OAUTH_UNSUPPORT_AUTH_TYPE: '[PC preview] unknow resultCode', + ERROR_PERMISSION_DENIED: '[PC preview] unknow resultCode' + }; + const appAccount = { + createAppAccountManager: function (...args) { + console.warn("appAccount.createAppAccountManager interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + return appAccountManagerMock; + }, + AuthenticatorCallback: AuthenticatorCallbackMock, + Authenticator: AuthenticatorClass, + Constants: ConstantsMock, + ResultCode: ResultCodeMock, + } + return appAccount } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/distributedAccount.js b/runtime/main/extend/systemplugin/napi/ohos_account_distributedAccount.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/distributedAccount.js rename to runtime/main/extend/systemplugin/napi/ohos_account_distributedAccount.js diff --git a/runtime/main/extend/systemplugin/ohos/osAccount.js b/runtime/main/extend/systemplugin/napi/ohos_account_osAccount.js similarity index 97% rename from runtime/main/extend/systemplugin/ohos/osAccount.js rename to runtime/main/extend/systemplugin/napi/ohos_account_osAccount.js index 5813a5ba..54fe7c5d 100644 --- a/runtime/main/extend/systemplugin/ohos/osAccount.js +++ b/runtime/main/extend/systemplugin/napi/ohos_account_osAccount.js @@ -1,394 +1,394 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { paramMock } from "../utils" - -export function mockOsAccount() { - const osAccountInfoMock = { - localId: "[PC Preview] unknown id", - localName: "[PC Preview] unknown name", - type: "[PC Preview] unknown type", - constraints: "[PC Preview] unknown constraints", - distributedInfo: "[PC Preview] unknown distributedInfo" - }; - const osAccountTypeMock = "[PC Preview] unknown type"; - const accountManagerMock = { - activateOsAccount: function (...args) { - console.warn("AccountManager.activateOsAccount interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - isMultiOsAccountEnable: function (...args) { - console.warn("AccountManager.isMultiOsAccountEnable interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - isOsAccountActived: function (...args) { - console.warn("AccountManager.isOsAccountActived interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - isOsAccountConstraintEnable: function (...args) { - console.warn("AccountManager.isOsAccountConstraintEnable interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - isTestOsAccount: function (...args) { - console.warn("AccountManager.isTestOsAccount interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - isOsAccountVerified: function (...args) { - console.warn("AccountManager.isOsAccountVerified interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - removeOsAccount: function (...args) { - console.warn("AccountManager.removeOsAccount interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - setOsAccountConstraints: function (...args) { - console.warn("AccountManager.setOsAccountConstraints interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - setOsAccountName: function (...args) { - console.warn("AccountManager.setOsAccountName interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getCreatedOsAccountsCount: function (...args) { - console.warn("AccountManager.getCreatedOsAccountsCount interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - getOsAccountLocalIdFromProcess: function (...args) { - console.warn("AccountManager.getOsAccountLocalIdFromProcess interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - getOsAccountLocalIdFromUid: function (...args) { - console.warn("AccountManager.getOsAccountLocalIdFromUid interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - getOsAccountLocalIdFromDomain: function (...args) { - console.warn("AccountManager.getOsAccountLocalIdFromDomain interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - queryMaxOsAccountNumber: function (...args) { - console.warn("AccountManager.queryMaxOsAccountNumber interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - getOsAccountAllConstraints: function (...args) { - console.warn("AccountManager.getOsAccountAllConstraints interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - queryAllCreatedOsAccounts: function (...args) { - console.warn("AccountManager.queryAllCreatedOsAccounts interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - var osAccountInfoArrayMock = new Array(); - osAccountInfoArrayMock.push(osAccountInfoMock); - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, osAccountInfoArrayMock); - } else { - return new Promise((resolve, reject) => { - resolve(osAccountInfoArrayMock); - }) - } - }, - queryActivatedOsAccountIds: function (...args) { - console.warn("AccountManager.queryActivatedOsAccountIds interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - var osAccountIdsArrayMock = new Array(); - osAccountIdsArrayMock.push(osAccountInfoMock); - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, osAccountIdsArrayMock); - } else { - return new Promise((resolve, reject) => { - resolve(osAccountIdsArrayMock); - }) - } - }, - createOsAccount: function (...args) { - console.warn("AccountManager.createOsAccount interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, osAccountInfoMock); - } else { - return new Promise((resolve, reject) => { - resolve(osAccountInfoMock); - }) - } - }, - createOsAccountForDomain: function (...args) { - console.warn("AccountManager.createOsAccountForDomain interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, osAccountInfoMock); - } else { - return new Promise((resolve, reject) => { - resolve(osAccountInfoMock); - }) - } - }, - queryCurrentOsAccount: function (...args) { - console.warn("AccountManager.queryCurrentOsAccount interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, osAccountInfoMock); - } else { - return new Promise((resolve, reject) => { - resolve(osAccountInfoMock); - }) - } - }, - queryOsAccountById: function (...args) { - console.warn("AccountManager.queryOsAccountById interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, osAccountInfoMock); - } else { - return new Promise((resolve, reject) => { - resolve(osAccountInfoMock); - }) - } - }, - getOsAccountTypeFromProcess: function (...args) { - console.warn("AccountManager.getOsAccountTypeFromProcess interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, osAccountTypeMock); - } else { - return new Promise((resolve, reject) => { - resolve(osAccountTypeMock); - }) - } - }, - getDistributedVirtualDeviceId: function (...args) { - console.warn("AccountManager.getDistributedVirtualDeviceId interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getOsAccountProfilePhoto: function (...args) { - console.warn("AccountManager.getOsAccountProfilePhoto interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - setOsAccountProfilePhoto: function (...args) { - console.warn("AccountManager.setOsAccountProfilePhoto interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getOsAccountLocalIdBySerialNumber: function (...args) { - console.warn("AccountManager.getOsAccountLocalIdBySerialNumber interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getSerialNumberByOsAccountLocalId: function (...args) { - console.warn("AccountManager.getSerialNumberByOsAccountLocalId interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - on: function (...args) { - console.warn("AccountManager.on interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - off: function (...args) { - console.warn("AccountManager.off interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - const len = args.length - if (len > 0 && typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - } - }; - global.ohosplugin.account = global.ohosplugin.account || {}; - global.ohosplugin.account.osAccount = { - getAccountManager: function (...args) { - console.warn("osAccount.getAccountManager interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - return accountManagerMock; - }, - OsAccountType: { - ADMIN: "[PC Preview] unknown ADMIN", - NORMAL: "[PC Preview] unknown NORMAL", - GUEST: "[PC Preview] unknown GUEST" - } - }; +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockOsAccount() { + const osAccountInfoMock = { + localId: "[PC Preview] unknown id", + localName: "[PC Preview] unknown name", + type: "[PC Preview] unknown type", + constraints: "[PC Preview] unknown constraints", + distributedInfo: "[PC Preview] unknown distributedInfo" + }; + const osAccountTypeMock = "[PC Preview] unknown type"; + const accountManagerMock = { + activateOsAccount: function (...args) { + console.warn("AccountManager.activateOsAccount interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + isMultiOsAccountEnable: function (...args) { + console.warn("AccountManager.isMultiOsAccountEnable interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + isOsAccountActived: function (...args) { + console.warn("AccountManager.isOsAccountActived interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + isOsAccountConstraintEnable: function (...args) { + console.warn("AccountManager.isOsAccountConstraintEnable interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + isTestOsAccount: function (...args) { + console.warn("AccountManager.isTestOsAccount interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + isOsAccountVerified: function (...args) { + console.warn("AccountManager.isOsAccountVerified interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + removeOsAccount: function (...args) { + console.warn("AccountManager.removeOsAccount interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + setOsAccountConstraints: function (...args) { + console.warn("AccountManager.setOsAccountConstraints interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + setOsAccountName: function (...args) { + console.warn("AccountManager.setOsAccountName interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getCreatedOsAccountsCount: function (...args) { + console.warn("AccountManager.getCreatedOsAccountsCount interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getOsAccountLocalIdFromProcess: function (...args) { + console.warn("AccountManager.getOsAccountLocalIdFromProcess interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getOsAccountLocalIdFromUid: function (...args) { + console.warn("AccountManager.getOsAccountLocalIdFromUid interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getOsAccountLocalIdFromDomain: function (...args) { + console.warn("AccountManager.getOsAccountLocalIdFromDomain interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + queryMaxOsAccountNumber: function (...args) { + console.warn("AccountManager.queryMaxOsAccountNumber interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getOsAccountAllConstraints: function (...args) { + console.warn("AccountManager.getOsAccountAllConstraints interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + queryAllCreatedOsAccounts: function (...args) { + console.warn("AccountManager.queryAllCreatedOsAccounts interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + var osAccountInfoArrayMock = new Array(); + osAccountInfoArrayMock.push(osAccountInfoMock); + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, osAccountInfoArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(osAccountInfoArrayMock); + }) + } + }, + queryActivatedOsAccountIds: function (...args) { + console.warn("AccountManager.queryActivatedOsAccountIds interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + var osAccountIdsArrayMock = new Array(); + osAccountIdsArrayMock.push(osAccountInfoMock); + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, osAccountIdsArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(osAccountIdsArrayMock); + }) + } + }, + createOsAccount: function (...args) { + console.warn("AccountManager.createOsAccount interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, osAccountInfoMock); + } else { + return new Promise((resolve, reject) => { + resolve(osAccountInfoMock); + }) + } + }, + createOsAccountForDomain: function (...args) { + console.warn("AccountManager.createOsAccountForDomain interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, osAccountInfoMock); + } else { + return new Promise((resolve, reject) => { + resolve(osAccountInfoMock); + }) + } + }, + queryCurrentOsAccount: function (...args) { + console.warn("AccountManager.queryCurrentOsAccount interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, osAccountInfoMock); + } else { + return new Promise((resolve, reject) => { + resolve(osAccountInfoMock); + }) + } + }, + queryOsAccountById: function (...args) { + console.warn("AccountManager.queryOsAccountById interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, osAccountInfoMock); + } else { + return new Promise((resolve, reject) => { + resolve(osAccountInfoMock); + }) + } + }, + getOsAccountTypeFromProcess: function (...args) { + console.warn("AccountManager.getOsAccountTypeFromProcess interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, osAccountTypeMock); + } else { + return new Promise((resolve, reject) => { + resolve(osAccountTypeMock); + }) + } + }, + getDistributedVirtualDeviceId: function (...args) { + console.warn("AccountManager.getDistributedVirtualDeviceId interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getOsAccountProfilePhoto: function (...args) { + console.warn("AccountManager.getOsAccountProfilePhoto interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + setOsAccountProfilePhoto: function (...args) { + console.warn("AccountManager.setOsAccountProfilePhoto interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getOsAccountLocalIdBySerialNumber: function (...args) { + console.warn("AccountManager.getOsAccountLocalIdBySerialNumber interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getSerialNumberByOsAccountLocalId: function (...args) { + console.warn("AccountManager.getSerialNumberByOsAccountLocalId interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + on: function (...args) { + console.warn("AccountManager.on interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + off: function (...args) { + console.warn("AccountManager.off interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + } + }; + const osAccount = { + getAccountManager: function (...args) { + console.warn("osAccount.getAccountManager interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + return accountManagerMock; + }, + OsAccountType: { + ADMIN: "[PC Preview] unknown ADMIN", + NORMAL: "[PC Preview] unknown NORMAL", + GUEST: "[PC Preview] unknown GUEST" + } + } + return osAccount } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/applicationAbility.js b/runtime/main/extend/systemplugin/napi/ohos_application_Ability.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/applicationAbility.js rename to runtime/main/extend/systemplugin/napi/ohos_application_Ability.js diff --git a/runtime/main/extend/systemplugin/napi/applicationAbilityStage.js b/runtime/main/extend/systemplugin/napi/ohos_application_AbilityStage.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/applicationAbilityStage.js rename to runtime/main/extend/systemplugin/napi/ohos_application_AbilityStage.js diff --git a/runtime/main/extend/systemplugin/napi/applicationDataShareExtensionAbility.js b/runtime/main/extend/systemplugin/napi/ohos_application_DataShareExtensionAbility.js similarity index 96% rename from runtime/main/extend/systemplugin/napi/applicationDataShareExtensionAbility.js rename to runtime/main/extend/systemplugin/napi/ohos_application_DataShareExtensionAbility.js index 2479e54d..29b5ea62 100644 --- a/runtime/main/extend/systemplugin/napi/applicationDataShareExtensionAbility.js +++ b/runtime/main/extend/systemplugin/napi/ohos_application_DataShareExtensionAbility.js @@ -15,7 +15,7 @@ import { paramMock } from "../utils" import { ExtensionContextClass } from "./application/abilityContext" -import { ResultSetMock } from "./dataShare" +import { ResultSetMock } from "./ohos_data_dataShare" export function mockDataShareExtensionAbility() { const DataShareExtensionAbilityClass = class DataShareExtensionAbility { diff --git a/runtime/main/extend/systemplugin/napi/applicationFormExtension.js b/runtime/main/extend/systemplugin/napi/ohos_application_FormExtension.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/applicationFormExtension.js rename to runtime/main/extend/systemplugin/napi/ohos_application_FormExtension.js diff --git a/runtime/main/extend/systemplugin/napi/applicationServiceExtAbility.js b/runtime/main/extend/systemplugin/napi/ohos_application_ServiceExtAbility.js similarity index 96% rename from runtime/main/extend/systemplugin/napi/applicationServiceExtAbility.js rename to runtime/main/extend/systemplugin/napi/ohos_application_ServiceExtAbility.js index 957f2a7f..d6677bfd 100644 --- a/runtime/main/extend/systemplugin/napi/applicationServiceExtAbility.js +++ b/runtime/main/extend/systemplugin/napi/ohos_application_ServiceExtAbility.js @@ -14,7 +14,7 @@ */ import { paramMock } from "../utils" -import { RemoteObjectClass } from "./applicationServiceExtensionAbility" +import { RemoteObjectClass } from "./ohos_application_ServiceExtensionAbility" const ApplicationInfoMock = { name: '[PC preview] unknow name', @@ -118,7 +118,7 @@ export function mockServiceExtAbility() { this.currentHapModuleInfo = HapModuleInfoMock; } } - const ServiceExtAbilityContextClass = class ServiceExtAbilityContext extends ExtAbilityContextClass{ + const ServiceExtAbilityContextClass = class ServiceExtAbilityContext extends ExtAbilityContextClass { constructor() { super(); console.warn('ServiceExtAbilityContext.constructor interface mocked in the Previewer. How this interface works on' + @@ -203,7 +203,7 @@ export function mockServiceExtAbility() { this.onConnect = function (...args) { console.warn("ServiceExtAbility.onConnect interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") - return new RemoteObjectClass(); + return new RemoteObjectClass(); }; this.onDisconnect = function (...args) { console.warn("ServiceExtAbility.onDisconnect interface mocked in the Previewer. How this interface works on the Previewer" + diff --git a/runtime/main/extend/systemplugin/napi/applicationServiceExtensionAbility.js b/runtime/main/extend/systemplugin/napi/ohos_application_ServiceExtensionAbility.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/applicationServiceExtensionAbility.js rename to runtime/main/extend/systemplugin/napi/ohos_application_ServiceExtensionAbility.js diff --git a/runtime/main/extend/systemplugin/napi/applicationAbilityManager.js b/runtime/main/extend/systemplugin/napi/ohos_application_abilityManager.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/applicationAbilityManager.js rename to runtime/main/extend/systemplugin/napi/ohos_application_abilityManager.js diff --git a/runtime/main/extend/systemplugin/napi/applicationAppManager.js b/runtime/main/extend/systemplugin/napi/ohos_application_appManager.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/applicationAppManager.js rename to runtime/main/extend/systemplugin/napi/ohos_application_appManager.js diff --git a/runtime/main/extend/systemplugin/napi/applicationFormBindingData.js b/runtime/main/extend/systemplugin/napi/ohos_application_formBindingData.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/applicationFormBindingData.js rename to runtime/main/extend/systemplugin/napi/ohos_application_formBindingData.js diff --git a/runtime/main/extend/systemplugin/napi/applicationMissionManager.js b/runtime/main/extend/systemplugin/napi/ohos_application_missionManager.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/applicationMissionManager.js rename to runtime/main/extend/systemplugin/napi/ohos_application_missionManager.js diff --git a/runtime/main/extend/systemplugin/napi/applicationUriPermissionManager.js b/runtime/main/extend/systemplugin/napi/ohos_application_uriPermissionManager.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/applicationUriPermissionManager.js rename to runtime/main/extend/systemplugin/napi/ohos_application_uriPermissionManager.js diff --git a/runtime/main/extend/systemplugin/napi/backgroundTaskManager.js b/runtime/main/extend/systemplugin/napi/ohos_backgroundTaskManager.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/backgroundTaskManager.js rename to runtime/main/extend/systemplugin/napi/ohos_backgroundTaskManager.js diff --git a/runtime/main/extend/systemplugin/batteryinfo.js b/runtime/main/extend/systemplugin/napi/ohos_batteryInfo.js similarity index 95% rename from runtime/main/extend/systemplugin/batteryinfo.js rename to runtime/main/extend/systemplugin/napi/ohos_batteryInfo.js index 83647baa..fa2d3348 100644 --- a/runtime/main/extend/systemplugin/batteryinfo.js +++ b/runtime/main/extend/systemplugin/napi/ohos_batteryInfo.js @@ -1,50 +1,51 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export function mockOhosBatteryinfo() { - const BatteryPluggedType = { - NONE: '[PC preview] unknow NONE', - AC: '[PC preview] unknow AC', - USB: '[PC preview] unknow USB', - WIRELESS: '[PC preview] unknow WIRELESS' - } - const BatteryChargeState = { - NONE: '[PC preview] unknow NONE', - ENABLE: '[PC preview] unknow ENABLE', - DISABLE: '[PC preview] unknow DISABLE', - FULL: '[PC preview] unknow FULL' - } - const BatteryHealthState = { - UNKNOWN: '[PC preview] unknow UNKNOWN', - GOOD: '[PC preview] unknow GOOD', - OVERHEAT: '[PC preview] unknow OVERHEAT', - OVERVOLTAGE: '[PC preview] unknow OVERVOLTAGE', - COLD: '[PC preview] unknow COLD', - DEAD: '[PC preview] unknow DEAD' - } - global.systemplugin.batteryInfo = { - BatteryPluggedType, - BatteryChargeState, - BatteryHealthState, - batterySOC: "[PC Preview] unknow batterySOC", - chargingStatus: "[PC Preview] unknow chargingStatus", - healthStatus: "[PC Preview] unknow healthStatus", - pluggedType: "[PC Preview] unknow pluggedType", - voltage: "[PC Preview] unknow voltage", - technology: "[PC Preview] unknow technology", - batteryTemperature: "[PC Preview] unknow batteryTemperature", - isBatteryPresent: "[PC Preview] unknow isBatteryPresent" - } -} +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function mockOhosBatteryinfo() { + const BatteryPluggedType = { + NONE: '[PC preview] unknow NONE', + AC: '[PC preview] unknow AC', + USB: '[PC preview] unknow USB', + WIRELESS: '[PC preview] unknow WIRELESS' + } + const BatteryChargeState = { + NONE: '[PC preview] unknow NONE', + ENABLE: '[PC preview] unknow ENABLE', + DISABLE: '[PC preview] unknow DISABLE', + FULL: '[PC preview] unknow FULL' + } + const BatteryHealthState = { + UNKNOWN: '[PC preview] unknow UNKNOWN', + GOOD: '[PC preview] unknow GOOD', + OVERHEAT: '[PC preview] unknow OVERHEAT', + OVERVOLTAGE: '[PC preview] unknow OVERVOLTAGE', + COLD: '[PC preview] unknow COLD', + DEAD: '[PC preview] unknow DEAD' + } + const batteryInfo = { + BatteryPluggedType, + BatteryChargeState, + BatteryHealthState, + batterySOC: "[PC Preview] unknow batterySOC", + chargingStatus: "[PC Preview] unknow chargingStatus", + healthStatus: "[PC Preview] unknow healthStatus", + pluggedType: "[PC Preview] unknow pluggedType", + voltage: "[PC Preview] unknow voltage", + technology: "[PC Preview] unknow technology", + batteryTemperature: "[PC Preview] unknow batteryTemperature", + isBatteryPresent: "[PC Preview] unknow isBatteryPresent" + } + return batteryInfo +} diff --git a/runtime/main/extend/systemplugin/napi/batteryStatistics.js b/runtime/main/extend/systemplugin/napi/ohos_batteryStatistics.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/batteryStatistics.js rename to runtime/main/extend/systemplugin/napi/ohos_batteryStatistics.js diff --git a/runtime/main/extend/systemplugin/bluetooth.js b/runtime/main/extend/systemplugin/napi/ohos_bluetooth.js similarity index 94% rename from runtime/main/extend/systemplugin/bluetooth.js rename to runtime/main/extend/systemplugin/napi/ohos_bluetooth.js index 47d15ac3..a958fb25 100644 --- a/runtime/main/extend/systemplugin/bluetooth.js +++ b/runtime/main/extend/systemplugin/napi/ohos_bluetooth.js @@ -13,10 +13,10 @@ * limitations under the License. */ -import { hasComplete } from "./utils" +import { hasComplete } from "../utils" export function mockBluetooth() { - global.systemplugin.bluetooth = { + const bluetooth = { startBLEScan: function (...args) { console.warn("bluetooth.startBLEScan interface mocked in the Previewer. How this interface works on the" + " Previewer may be different from that on a real device.") @@ -56,4 +56,5 @@ export function mockBluetooth() { delete this.unsubscribeBLE } } + return bluetooth } diff --git a/runtime/main/extend/systemplugin/brightness.js b/runtime/main/extend/systemplugin/napi/ohos_brightness.js similarity index 94% rename from runtime/main/extend/systemplugin/brightness.js rename to runtime/main/extend/systemplugin/napi/ohos_brightness.js index 55fe8622..f2aaea3b 100644 --- a/runtime/main/extend/systemplugin/brightness.js +++ b/runtime/main/extend/systemplugin/napi/ohos_brightness.js @@ -13,10 +13,10 @@ * limitations under the License. */ -import { hasComplete } from "./utils" +import { hasComplete } from "../utils" export function mockBrightness() { - global.systemplugin.brightness = { + const brightness = { argsV: { value: 80 }, @@ -58,4 +58,5 @@ export function mockBrightness() { hasComplete(args[0].complete) } } + return brightness } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/bundle.js b/runtime/main/extend/systemplugin/napi/ohos_bundle.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/bundle.js rename to runtime/main/extend/systemplugin/napi/ohos_bundle.js diff --git a/runtime/main/extend/systemplugin/ohos/bundleState.js b/runtime/main/extend/systemplugin/napi/ohos_bundleState.js similarity index 96% rename from runtime/main/extend/systemplugin/ohos/bundleState.js rename to runtime/main/extend/systemplugin/napi/ohos_bundleState.js index bfe6c652..df70c3b3 100644 --- a/runtime/main/extend/systemplugin/ohos/bundleState.js +++ b/runtime/main/extend/systemplugin/napi/ohos_bundleState.js @@ -51,7 +51,7 @@ export function mockBundleState() { BY_MONTHLY: 3, BY_ANNUALLY: 4 } - global.ohosplugin.bundleState = { + const bundleState = { isIdleState: function (...args) { console.warn("bundleState.isIdleState interface mocked in the Previewer. How this interface works on the" + " Previewer may be different from that on a real device."); @@ -125,4 +125,5 @@ export function mockBundleState() { } } } + return bundleState } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/innerBundleManager.js b/runtime/main/extend/systemplugin/napi/ohos_bundle_innerBundleManager.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/innerBundleManager.js rename to runtime/main/extend/systemplugin/napi/ohos_bundle_innerBundleManager.js diff --git a/runtime/main/extend/systemplugin/napi/bytrace.js b/runtime/main/extend/systemplugin/napi/ohos_bytrace.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/bytrace.js rename to runtime/main/extend/systemplugin/napi/ohos_bytrace.js diff --git a/runtime/main/extend/systemplugin/napi/commonEvent.js b/runtime/main/extend/systemplugin/napi/ohos_commonEvent.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/commonEvent.js rename to runtime/main/extend/systemplugin/napi/ohos_commonEvent.js diff --git a/runtime/main/extend/systemplugin/napi/configPolicy.js b/runtime/main/extend/systemplugin/napi/ohos_configPolicy.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/configPolicy.js rename to runtime/main/extend/systemplugin/napi/ohos_configPolicy.js diff --git a/runtime/main/extend/systemplugin/contact.js b/runtime/main/extend/systemplugin/napi/ohos_contact.js similarity index 97% rename from runtime/main/extend/systemplugin/contact.js rename to runtime/main/extend/systemplugin/napi/ohos_contact.js index 77276a0e..8b1706bd 100644 --- a/runtime/main/extend/systemplugin/contact.js +++ b/runtime/main/extend/systemplugin/napi/ohos_contact.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import { paramMock } from "./utils" +import { paramMock } from "../utils" export function mockContact() { const ContactClass = class Contact { @@ -251,7 +251,7 @@ export function mockContact() { this.website = "[PC Preview] unknow website"; } } - global.systemplugin.contact = { + const contact = { Contact: ContactClass, ContactAttributes: ContactAttributesClass, Email: EmailClass, @@ -452,4 +452,5 @@ export function mockContact() { } } } + return contact } diff --git a/runtime/main/extend/systemplugin/napi/convertxml.js b/runtime/main/extend/systemplugin/napi/ohos_convertxml.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/convertxml.js rename to runtime/main/extend/systemplugin/napi/ohos_convertxml.js diff --git a/runtime/main/extend/systemplugin/data.js b/runtime/main/extend/systemplugin/napi/ohos_data_Storage.js similarity index 94% rename from runtime/main/extend/systemplugin/data.js rename to runtime/main/extend/systemplugin/napi/ohos_data_Storage.js index 25ea906d..23aa2fc2 100644 --- a/runtime/main/extend/systemplugin/data.js +++ b/runtime/main/extend/systemplugin/napi/ohos_data_Storage.js @@ -13,13 +13,60 @@ * limitations under the License. */ -import { paramMock } from "./utils" +import { paramMock } from "../utils" export function mockDataStorage() { - global.systemplugin.data = {} - const paramValueTypeMock = '[PC Preview] unknow ValueType' - const storageObserverMock = { - key: "[PC preview] unknow key" + const storage = { + storageMock, + getStorageSync: function () { + console.warn("data.storage.getStorageSync interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return storageMock + }, + getStorage: function (...args) { + console.warn("data.storage.getStorage interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, storageMock) + } else { + return new Promise((resolve) => { + resolve(storageMock) + }) + } + }, + deleteStorageSync: function () { + console.warn("data.storage.deleteStorageSync interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + }, + deleteStorage: function (...args) { + console.warn("data.storage.deleteStorage interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve() + }) + } + }, + removeStorageFromCacheSync: function () { + console.warn("data.storage.removeStorageFromCacheSync interface mocked in the Previewer. How this interface" + + " works on the Previewer may be different from that on a real device.") + }, + removeStorageFromCache: function (...args) { + console.warn("data.storage.removeStorageFromCache interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve() + }) + } + } } const storageMock = { getSync: function () { @@ -133,55 +180,5 @@ export function mockDataStorage() { args[len - 1].call(this, storageObserverMock) } } - global.systemplugin.data.storage = { - getStorageSync: function () { - console.warn("data.storage.getStorageSync interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return storageMock - }, - getStorage: function (...args) { - console.warn("data.storage.getStorage interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, storageMock) - } else { - return new Promise((resolve) => { - resolve(storageMock) - }) - } - }, - deleteStorageSync: function () { - console.warn("data.storage.deleteStorageSync interface mocked in the Previewer. How this interface works on" + - " the Previewer may be different from that on a real device.") - }, - deleteStorage: function (...args) { - console.warn("data.storage.deleteStorage interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve) => { - resolve() - }) - } - }, - removeStorageFromCacheSync: function () { - console.warn("data.storage.removeStorageFromCacheSync interface mocked in the Previewer. How this interface" + - " works on the Previewer may be different from that on a real device.") - }, - removeStorageFromCache: function (...args) { - console.warn("data.storage.removeStorageFromCache interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve) => { - resolve() - }) - } - } - } + return storage } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/dataAbility.js b/runtime/main/extend/systemplugin/napi/ohos_data_dataAbility.js similarity index 99% rename from runtime/main/extend/systemplugin/napi/dataAbility.js rename to runtime/main/extend/systemplugin/napi/ohos_data_dataAbility.js index 16e8547d..68466761 100644 --- a/runtime/main/extend/systemplugin/napi/dataAbility.js +++ b/runtime/main/extend/systemplugin/napi/ohos_data_dataAbility.js @@ -14,7 +14,7 @@ */ import { paramMock } from '../utils'; -import { RdbPredicatesClass } from './rdb' +import { RdbPredicatesClass } from './ohos_data_rdb' export function mockDataAbility() { const DataAbilityPredicatesClass = class DataAbilityPredicates { diff --git a/runtime/main/extend/systemplugin/napi/dataShare.js b/runtime/main/extend/systemplugin/napi/ohos_data_dataShare.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/dataShare.js rename to runtime/main/extend/systemplugin/napi/ohos_data_dataShare.js diff --git a/runtime/main/extend/systemplugin/napi/distributedData.js b/runtime/main/extend/systemplugin/napi/ohos_data_distributedData.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/distributedData.js rename to runtime/main/extend/systemplugin/napi/ohos_data_distributedData.js diff --git a/runtime/main/extend/systemplugin/napi/ohos_data_distributedDataObject.js b/runtime/main/extend/systemplugin/napi/ohos_data_distributedDataObject.js new file mode 100644 index 00000000..c529f43d --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_data_distributedDataObject.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockDistributedObject() { + const DistributedObject = { + setSessionId: function (...args) { + console.warn("DistributedObject.setSessionId interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + }, + on: function (...args) { + console.warn("DistributedObject.on interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + }, + off: function (...args) { + console.warn("DistributedObject.off interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + } + }; + const distributedObjectMock = { + createDistributedObject: function (...args) { + console.warn("distributedObject.createDistributedObject interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device."); + return DistributedObject; + }, + genSessionId: function (...args) { + console.warn("distributedObject.genSessionId interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device."); + return 'just test'; + } + }; + return distributedObjectMock; +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/rdb.js b/runtime/main/extend/systemplugin/napi/ohos_data_rdb.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/rdb.js rename to runtime/main/extend/systemplugin/napi/ohos_data_rdb.js diff --git a/runtime/main/extend/systemplugin/deviceInfo.js b/runtime/main/extend/systemplugin/napi/ohos_deviceInfo.js similarity index 70% rename from runtime/main/extend/systemplugin/deviceInfo.js rename to runtime/main/extend/systemplugin/napi/ohos_deviceInfo.js index 1196229c..71c08776 100644 --- a/runtime/main/extend/systemplugin/deviceInfo.js +++ b/runtime/main/extend/systemplugin/napi/ohos_deviceInfo.js @@ -1,20 +1,20 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +* Copyright (c) 2021 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ export function mockDeviceInfo() { - global.systemplugin.deviceInfo = { + const deviceInfo = { deviceType: '[PC preview] unknow type', manufacture: '[PC preview] unknow manufacture', brand: '[PC preview] unknow brand', @@ -46,4 +46,5 @@ export function mockDeviceInfo() { buildTime: '[PC preview] unknow build time', buildRootHash: '[PC preview] unknow build root hash' } + return deviceInfo } diff --git a/runtime/main/extend/systemplugin/display.js b/runtime/main/extend/systemplugin/napi/ohos_display.js similarity index 95% rename from runtime/main/extend/systemplugin/display.js rename to runtime/main/extend/systemplugin/napi/ohos_display.js index 720635a4..9ef6e171 100644 --- a/runtime/main/extend/systemplugin/display.js +++ b/runtime/main/extend/systemplugin/napi/ohos_display.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import { paramMock } from "./utils" +import { paramMock } from "../utils" export function mockDisplay() { const displayMock = { @@ -46,7 +46,7 @@ export function mockDisplay() { rotation: '[PC preview] unknow rotation', name: '[PC preview] unknow name' }] - global.systemplugin.display = { + const display = { getDefaultDisplay: function (...args) { console.warn("display.getDefaultDisplay interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") @@ -84,4 +84,5 @@ export function mockDisplay() { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) }, } + return display } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/deviceManager.js b/runtime/main/extend/systemplugin/napi/ohos_distributedHardware_deviceManager.js similarity index 94% rename from runtime/main/extend/systemplugin/deviceManager.js rename to runtime/main/extend/systemplugin/napi/ohos_distributedHardware_deviceManager.js index d6ba4f22..5b2df6cb 100644 --- a/runtime/main/extend/systemplugin/deviceManager.js +++ b/runtime/main/extend/systemplugin/napi/ohos_distributedHardware_deviceManager.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import { paramMock } from "./utils" +import { paramMock } from "../utils" export function mockDeviceManager() { const deviceInfoMock = { @@ -130,8 +130,8 @@ export function mockDeviceManager() { " be different from that on a real device.") } } - global.systemplugin.distributedHardware = global.systemplugin.distributedHardware || {}; - global.systemplugin.distributedHardware.deviceManager = { + const deviceManager = { + deviceManagerMock, createDeviceManager: function (...args) { console.warn("distributedHardware.deviceManager.createDeviceManager interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") @@ -141,4 +141,5 @@ export function mockDeviceManager() { } } } + return deviceManager } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/document.js b/runtime/main/extend/systemplugin/napi/ohos_document.js similarity index 94% rename from runtime/main/extend/systemplugin/document.js rename to runtime/main/extend/systemplugin/napi/ohos_document.js index 15d8710c..4d1504c6 100644 --- a/runtime/main/extend/systemplugin/document.js +++ b/runtime/main/extend/systemplugin/napi/ohos_document.js @@ -13,10 +13,10 @@ * limitations under the License. */ -import { paramMock } from "./utils" +import { paramMock } from "../utils" export function mockDocument() { - global.systemplugin.document = { + const document = { create: function (...args) { console.warn("document.create interface mocked in the Previewer. How this interface works on the Previewer may" + " be different from that on a real device.") @@ -54,4 +54,5 @@ export function mockDocument() { } } } + return document } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/environment.js b/runtime/main/extend/systemplugin/napi/ohos_environment.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/environment.js rename to runtime/main/extend/systemplugin/napi/ohos_environment.js diff --git a/runtime/main/extend/systemplugin/napi/emitter.js b/runtime/main/extend/systemplugin/napi/ohos_events_emitter.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/emitter.js rename to runtime/main/extend/systemplugin/napi/ohos_events_emitter.js diff --git a/runtime/main/extend/systemplugin/napi/filemanager.js b/runtime/main/extend/systemplugin/napi/ohos_fileManager.js similarity index 97% rename from runtime/main/extend/systemplugin/napi/filemanager.js rename to runtime/main/extend/systemplugin/napi/ohos_fileManager.js index c7ed4b92..f06e905c 100644 --- a/runtime/main/extend/systemplugin/napi/filemanager.js +++ b/runtime/main/extend/systemplugin/napi/ohos_fileManager.js @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { paramMock } from "../utils" - -export function mockFileManager() { - const filemanager = { - getRoot: function (...args) { - console.warn("filemanager.getRoot interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock) - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramArrayMock); - }) - } - }, - listFile: function (...args) { - console.warn("filemanager.listFile interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock) - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramArrayMock); - }) - } - }, - createFile: function (...args) { - console.warn("filemanager.createFile interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - } - return filemanager; -} +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockFileManager() { + const filemanager = { + getRoot: function (...args) { + console.warn("filemanager.getRoot interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }) + } + }, + listFile: function (...args) { + console.warn("filemanager.listFile interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }) + } + }, + createFile: function (...args) { + console.warn("filemanager.createFile interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + } + return filemanager; +} diff --git a/runtime/main/extend/systemplugin/napi/fileio.js b/runtime/main/extend/systemplugin/napi/ohos_fileio.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/fileio.js rename to runtime/main/extend/systemplugin/napi/ohos_fileio.js diff --git a/runtime/main/extend/systemplugin/ohos/geolocation.js b/runtime/main/extend/systemplugin/napi/ohos_geolocation.js similarity index 97% rename from runtime/main/extend/systemplugin/ohos/geolocation.js rename to runtime/main/extend/systemplugin/napi/ohos_geolocation.js index e7f92f5e..c234ce77 100644 --- a/runtime/main/extend/systemplugin/ohos/geolocation.js +++ b/runtime/main/extend/systemplugin/napi/ohos_geolocation.js @@ -48,7 +48,7 @@ export function mockOhosGeolocation() { descriptions: '[PC preview] unknow descriptions', descriptionsSize: '[PC preview] unknow descriptionsSize', } - global.ohosplugin.geolocation = { + const geolocation = { on: function (...args) { console.warn("geolocation.on interface mocked in the Previewer. How this interface works on the" + " Previewer may be different from that on a real device."); @@ -182,4 +182,5 @@ export function mockOhosGeolocation() { } }, } + return geolocation } diff --git a/runtime/main/extend/systemplugin/napi/hiAppEvent.js b/runtime/main/extend/systemplugin/napi/ohos_hiAppEvent.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/hiAppEvent.js rename to runtime/main/extend/systemplugin/napi/ohos_hiAppEvent.js diff --git a/runtime/main/extend/systemplugin/napi/hilog.js b/runtime/main/extend/systemplugin/napi/ohos_hilog.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/hilog.js rename to runtime/main/extend/systemplugin/napi/ohos_hilog.js diff --git a/runtime/main/extend/systemplugin/napi/i18n.js b/runtime/main/extend/systemplugin/napi/ohos_i18n.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/i18n.js rename to runtime/main/extend/systemplugin/napi/ohos_i18n.js diff --git a/runtime/main/extend/systemplugin/inputMethod.js b/runtime/main/extend/systemplugin/napi/ohos_inputmethod.js similarity index 96% rename from runtime/main/extend/systemplugin/inputMethod.js rename to runtime/main/extend/systemplugin/napi/ohos_inputmethod.js index 1cbdb277..ca1a920b 100644 --- a/runtime/main/extend/systemplugin/inputMethod.js +++ b/runtime/main/extend/systemplugin/napi/ohos_inputmethod.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import { paramMock } from "./utils" +import { paramMock } from "../utils" export function mockInputMethod() { const KeyboardType = { @@ -136,7 +136,7 @@ export function mockInputMethod() { } }, } - global.systemplugin.inputMethod = { + const inputMethod = { MAX_TYPE_MUN: 128, getInputMethodController: function () { console.warn("inputmethod.getInputMethodController interface mocked in the Previewer. How this interface works" + @@ -149,4 +149,5 @@ export function mockInputMethod() { return InputMethodSettingMock; } } + return inputMethod } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/inputMethodEngine.js b/runtime/main/extend/systemplugin/napi/ohos_inputmethodengine.js similarity index 96% rename from runtime/main/extend/systemplugin/inputMethodEngine.js rename to runtime/main/extend/systemplugin/napi/ohos_inputmethodengine.js index 0d9f5272..57abbf87 100644 --- a/runtime/main/extend/systemplugin/inputMethodEngine.js +++ b/runtime/main/extend/systemplugin/napi/ohos_inputmethodengine.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import { paramMock } from "./utils" +import { paramMock } from "../utils" const NOTIFY = "[PC Preview] unknow" const Properties = [ @@ -403,7 +403,7 @@ export function mockInputMethodEngine() { } }, } - global.systemplugin.inputMethodEngine = { + const inputMethodEngine = { getInputMethodEngine: function () { console.warn("inputMethodEngine.getInputMethodEngine interface mocked in the Previewer. How this interface works" + " on the Previewer may be different from that on a real device.") @@ -417,6 +417,6 @@ export function mockInputMethodEngine() { } for (let Property of Properties) { - global.systemplugin.inputMethodEngine[Property] = NOTIFY + " " + Property + inputMethodEngine[Property] = NOTIFY + " " + Property } } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/intl.js b/runtime/main/extend/systemplugin/napi/ohos_intl.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/intl.js rename to runtime/main/extend/systemplugin/napi/ohos_intl.js diff --git a/runtime/main/extend/systemplugin/napi/mediaquery.js b/runtime/main/extend/systemplugin/napi/ohos_mediaquery.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/mediaquery.js rename to runtime/main/extend/systemplugin/napi/ohos_mediaquery.js diff --git a/runtime/main/extend/systemplugin/napi/multimediaAudio.js b/runtime/main/extend/systemplugin/napi/ohos_multimedia_audio.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/multimediaAudio.js rename to runtime/main/extend/systemplugin/napi/ohos_multimedia_audio.js diff --git a/runtime/main/extend/systemplugin/napi/multimediaCamera.js b/runtime/main/extend/systemplugin/napi/ohos_multimedia_camera.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/multimediaCamera.js rename to runtime/main/extend/systemplugin/napi/ohos_multimedia_camera.js diff --git a/runtime/main/extend/systemplugin/napi/multimediaImage.js b/runtime/main/extend/systemplugin/napi/ohos_multimedia_image.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/multimediaImage.js rename to runtime/main/extend/systemplugin/napi/ohos_multimedia_image.js diff --git a/runtime/main/extend/systemplugin/napi/multimediaMedia.js b/runtime/main/extend/systemplugin/napi/ohos_multimedia_media.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/multimediaMedia.js rename to runtime/main/extend/systemplugin/napi/ohos_multimedia_media.js diff --git a/runtime/main/extend/systemplugin/napi/multimediaMediaLibrary.js b/runtime/main/extend/systemplugin/napi/ohos_multimedia_mediaLibrary.js similarity index 81% rename from runtime/main/extend/systemplugin/napi/multimediaMediaLibrary.js rename to runtime/main/extend/systemplugin/napi/ohos_multimedia_mediaLibrary.js index 109d9aaf..945af1dd 100644 --- a/runtime/main/extend/systemplugin/napi/multimediaMediaLibrary.js +++ b/runtime/main/extend/systemplugin/napi/ohos_multimedia_mediaLibrary.js @@ -14,7 +14,7 @@ */ import { paramMock } from "../utils" -import { PixelMapMock } from "./multimediaImage" +import { PixelMapMock } from "./ohos_multimedia_image" export function mockMultimediaMediaLibrary() { const mockFileAsset = { @@ -39,9 +39,9 @@ export function mockMultimediaMediaLibrary() { albumId: "[PC Preview] unknow albumId", albumUri: "[PC Preview] unknow albumUri", albumName: "[PC Preview] unknow albumName", - isDirectory: function(...args) { + isDirectory: function (...args) { console.warn("FileAsset.isDirectory interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) @@ -51,9 +51,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - commitModify: function(...args) { + commitModify: function (...args) { console.warn("FileAsset.commitModify interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -63,9 +63,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - open: function(...args) { + open: function (...args) { console.warn("FileAsset.open interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) @@ -75,9 +75,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - close: function(...args) { + close: function (...args) { console.warn("FileAsset.close interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -87,9 +87,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - getThumbnail: function(...args) { + getThumbnail: function (...args) { console.warn("FileAsset.getThumbnail interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, mockImagePixelMap) @@ -99,9 +99,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - favorite: function(...args) { + favorite: function (...args) { console.warn("FileAsset.favorite interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -111,9 +111,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - isFavorite: function(...args) { + isFavorite: function (...args) { console.warn("FileAsset.isFavorite interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) @@ -123,9 +123,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - trash: function(...args) { + trash: function (...args) { console.warn("FileAsset.trash interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) @@ -135,9 +135,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - isTrash: function(...args) { + isTrash: function (...args) { console.warn("FileAsset.isTrash interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) @@ -150,23 +150,23 @@ export function mockMultimediaMediaLibrary() { }; const mockFetchFileResult = { - getCount: function(...args) { + getCount: function (...args) { console.warn("FetchFileResult.getCount interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") return paramMock.paramNumberMock }, - isAfterLast: function(...args) { + isAfterLast: function (...args) { console.warn("FetchFileResult.isAfterLast interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") return paramMock.paramBooleanMock }, - close: function(...args) { + close: function (...args) { console.warn("FetchFileResult.close interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") }, - getFirstObject: function(...args) { + getFirstObject: function (...args) { console.warn("FetchFileResult.getFirstObject interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, mockFileAsset) @@ -176,9 +176,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - getNextObject: function(...args) { + getNextObject: function (...args) { console.warn("FetchFileResult.getNextObject interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, mockFileAsset) @@ -188,9 +188,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - getLastObject: function(...args) { + getLastObject: function (...args) { console.warn("FetchFileResult.getLastObject interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, mockFileAsset) @@ -200,9 +200,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - getPositionObject: function(...args) { + getPositionObject: function (...args) { console.warn("FetchFileResult.getPositionObject interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, mockFileAsset) @@ -212,9 +212,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - getAllObject: function(...args) { + getAllObject: function (...args) { console.warn("FetchFileResult.getPositionObject interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, [mockFileAsset]) @@ -243,9 +243,9 @@ export function mockMultimediaMediaLibrary() { count: "[PC Preview] unknow count", relativePath: "[PC Preview] unknow relativePath", coverUri: "[PC Preview] unknow coverUri", - commitModify: function(...args) { + commitModify: function (...args) { console.warn("Album.commitModify interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -255,9 +255,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - getFileAssets: function(...args) { + getFileAssets: function (...args) { console.warn("Album.getFileAssets interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (len > 0 && typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, mockFetchFileResult); @@ -270,9 +270,9 @@ export function mockMultimediaMediaLibrary() { }; const mockMediaLibrary = { - getPublicDirectory: function(...args) { + getPublicDirectory: function (...args) { console.warn("MediaLibrary.getPublicDirectory interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); @@ -282,9 +282,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - getFileAssets: function(...args) { + getFileAssets: function (...args) { console.warn("MediaLibrary.getFileAssets interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, mockFetchFileResult); @@ -294,17 +294,17 @@ export function mockMultimediaMediaLibrary() { }) } }, - on: function(...args) { + on: function (...args) { console.warn("MediaLibrary.on interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") }, - off: function(...args) { + off: function (...args) { console.warn("MediaLibrary.off interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") }, - createAsset: function(...args) { + createAsset: function (...args) { console.warn("MediaLibrary.createAsset interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, mockFileAsset); @@ -314,9 +314,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - deleteAsset: function(...args) { + deleteAsset: function (...args) { console.warn("MediaLibrary.deleteAsset interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -326,9 +326,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - getAlbums: function(...args) { + getAlbums: function (...args) { console.warn("MediaLibrary.getAlbums interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, [mockAlbum]); @@ -338,9 +338,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - storeMediaAsset: function(...args) { + storeMediaAsset: function (...args) { console.warn("MediaLibrary.storeMediaAsset interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); @@ -350,9 +350,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - startImagePreview: function(...args) { + startImagePreview: function (...args) { console.warn("MediaLibrary.startImagePreview interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -362,9 +362,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - startMediaSelect: function(...args) { + startMediaSelect: function (...args) { console.warn("MediaLibrary.startMediaSelect interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paramStringMock]); @@ -374,9 +374,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - getActivePeers: function(...args) { + getActivePeers: function (...args) { console.warn("MediaLibrary.getActivePeers interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, [mockPeerInfo]); @@ -386,9 +386,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - getAllPeers: function(...args) { + getAllPeers: function (...args) { console.warn("MediaLibrary.getAllPeers interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, [mockPeerInfo]); @@ -398,9 +398,9 @@ export function mockMultimediaMediaLibrary() { }) } }, - release: function(...args) { + release: function (...args) { console.warn("MediaLibrary.startImagePreview interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") + " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock); @@ -457,9 +457,9 @@ export function mockMultimediaMediaLibrary() { TYPE_CAR: 5, TYPE_TV: 6 }, - getMediaLibrary: function(...args) { + getMediaLibrary: function (...args) { console.warn("mediaLibrary.getMediaLibrary interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") + " be different from that on a real device.") return mockMediaLibrary; } }; diff --git a/runtime/main/extend/systemplugin/napi/inputDevice.js b/runtime/main/extend/systemplugin/napi/ohos_multimodalInput_inputDevice.js similarity index 86% rename from runtime/main/extend/systemplugin/napi/inputDevice.js rename to runtime/main/extend/systemplugin/napi/ohos_multimodalInput_inputDevice.js index 1874aa5c..8c5d09d1 100644 --- a/runtime/main/extend/systemplugin/napi/inputDevice.js +++ b/runtime/main/extend/systemplugin/napi/ohos_multimodalInput_inputDevice.js @@ -20,26 +20,17 @@ export function mockInputDevice() { source: '[PC preview] unknow source', axis: '[PC preview] unknow axis', max: '[PC preview] unknow max', - min: '[PC preview] unknow min', - fuzz: '[PC preview] unknow fuzz', - flat: '[PC preview] unknow flat', - resolution: '[PC preview] unknow resolution', + min: '[PC preview] unknow min' } const InputDeviceData = { id: '[PC preview] unknow id', name: '[PC preview] unknow name', sources: ['[PC preview] unknow sources'], - axisRanges: [AxisRange], - bus: '[PC preview] unknow bus', - product: '[PC preview] unknow product', - vendor: '[PC preview] unknow vendor', - version: '[PC preview] unknow version', - phys: '[PC preview] unknow phys', - uniq: '[PC preview] unknow uniq', + axisRanges: [AxisRange] } const EventType = ['changed'] - const DeviceIds = [0, 1, 2, 3, 4] + const DeviceIds = [0, 1, 2, 3, 4, 5, 6, 7] const inputDevice = { on: function (...args) { console.warn("inputDevice.on interface mocked in the Previewer. How this interface works on the" + @@ -139,8 +130,8 @@ export function mockInputDevice() { args[1].call(this, InputDeviceData); } }, - supportKeys: function(...args) { - console.warn("inputDevice.supportKeys interface mocked in the Previewer." + + getKeystrokeAbility: function(...args) { + console.warn("inputDevice.getKeystrokeAbility interface mocked in the Previewer." + "How this interface works on the" + " Previewer may be different from that on a real device."); const len = args.length; if (len < 2 || len > 3) { @@ -158,7 +149,11 @@ export function mockInputDevice() { if (len === 2) { var KeystrokeAbilityArr = []; for (var i = 0; i < args[1].length; ++i) { - KeystrokeAbilityArr.unshift('[PC preview] unknow boolean'); + var KeystrokeAbility = { + keyCode: args[1][i], + isSupport: '[PC preview] unknow isSupport', + } + KeystrokeAbilityArr[i] = KeystrokeAbility; } return new Promise((resolve, reject) => { resolve(KeystrokeAbilityArr); @@ -170,7 +165,11 @@ export function mockInputDevice() { } var KeystrokeAbilityArr = []; for (var i = 0; i < args[1].length; ++i) { - KeystrokeAbilityArr.unshift('[PC preview] unknow boolean'); + var KeystrokeAbility = { + keyCode: args[1][i], + isSupport: '[PC preview] unknow isSupport', + } + KeystrokeAbilityArr[i] = KeystrokeAbility; } args[2].call(this, KeystrokeAbilityArr); } diff --git a/runtime/main/extend/systemplugin/napi/ohos_multimodalInput_inputMonitor.js b/runtime/main/extend/systemplugin/napi/ohos_multimodalInput_inputMonitor.js new file mode 100644 index 00000000..ff969d42 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_multimodalInput_inputMonitor.js @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function mockInputMonitor() { + const touches = [{ + force: 1.67, + globalX: 122, + globalY: 3654, + localX: 0, + localY: 0, + size: 2.03 + }]; + const changedTouches = [{ + force: 1.67, + globalX: 122, + globalY: 3654, + localX: 0, + localY: 0, + size: 2.03 + }]; + const pressedButtons = [10, 11, 12, 13, 14]; + const inputMonitor = { + on: function (...args) { + console.warn('multimodalInput.inputMonitor.on interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + clearInterval(this.offInputMonitor); + delete this.offInputMonitor; + this.offInputMonitor = setInterval(() => { + const len = args.length; + if (len !== 2 || typeof args[0] !== 'string' || typeof args[len - 1] !== 'function') { + console.warn('multimodalInput.inputMonitor.on param invalid.'); + return; + } + if (args[0] !== 'touch' && args[0] !== 'mouse') { + console.warn('multimodalInput.inputMonitor.on first param should be touch or mouse.'); + return; + } + const value = {}; + value.type = 'up'; + value.timestamp = 318878; + value.deviceId = 0; + value.touches = touches; + value.changedTouches = changedTouches; + const mouse = {}; + mouse.type = 'move'; + mouse.pressedButtons = pressedButtons; + mouse.displayId = 20; + mouse.targetWindowId = 21; + mouse.agentWindowId = 22; + mouse.localX = 450; + mouse.localY = 736; + mouse.globalX = 450; + mouse.globalY = 784; + mouse.timestamp = 55670246; + mouse.axisVerticalValue = 15; + mouse.axisHorizontalValue = 20; + if (args[0] === 'touch') { + console.warn('multimodalInput.inputMonitor.on touch callback.'); + args[len - 1].call(this, value); + } else if (args[0] === 'mouse') { + console.warn('multimodalInput.inputMonitor.on mouse callback.'); + args[len - 1].call(this, mouse); + } + }, 1000); + }, + + off: function (...args) { + console.warn('multimodalInput.inputMonitor.off interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + clearInterval(this.offInputMonitor); + delete this.offInputMonitor; + } + } + return inputMonitor +} + diff --git a/runtime/main/extend/systemplugin/napi/ohos_net_connection.js b/runtime/main/extend/systemplugin/napi/ohos_net_connection.js new file mode 100644 index 00000000..a0ed0ba5 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_net_connection.js @@ -0,0 +1,387 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockConnection() { + const NetAddress = "[PC Preview] unknow NetAddress" + const NetHandle = { + netId: "[PC Preview] unknow netId", + bindSocket: function () { + console.warn("NetHandle.bindSocket interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + openConnection: function () { + console.warn("NetHandle.openConnection interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, HttpRequest); + } else { + return new Promise((resolve, reject) => { + resolve(HttpRequest); + }) + } + }, + getAddressesByName: function () { + console.warn("NetHandle.getAddressesByName interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, NetAddress); + } else { + return new Promise((resolve, reject) => { + resolve(NetAddress); + }) + } + }, + getAddressByName: function () { + console.warn("NetHandle.getAddressByName interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, NetAddress); + } else { + return new Promise((resolve, reject) => { + resolve(NetAddress); + }) + } + }, + } + const NetBearType = "[PC Preview] unknow NetBearType" + const NetCapabilities = { + bearerTypes: function () { + console.warn("NetCapabilities.bearerTypes interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + var netBearTypeArray = new Array(); + netBearTypeArray.push(NetBearType); + return netBearTypeArray; + } + } + const NetCap = "[PC Preview] unknow NetCap" + const ConnectionProperties = { + interfaceName: "[PC Preview] unknow interfaceName", + isUsePrivateDns: "[PC Preview] unknow isUsePrivateDns", + privateDnsServerName: "[PC Preview] unknow privateDnsServerName", + domains: "[PC Preview] unknow domains", + httpProxy: "[PC Preview] unknow httpProxy", + linkAddresses: function () { + console.warn("ConnectionProperties.linkAddresses interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + var LinkAddress = new Array(); + LinkAddress.push(NetBearType); + return LinkAddress; + }, + dnses: function () { + console.warn("ConnectionProperties.dnses interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + var NetAddress = new Array(); + NetAddress.push(NetBearType); + return NetAddress; + }, + routes: function () { + console.warn("ConnectionProperties.routes interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + var RouteInfo = new Array(); + RouteInfo.push(NetBearType); + return RouteInfo; + }, + mtu: "[PC Preview] unknow mtu" + } + const HttpProxy = { + host: "[PC Preview] unknow host", + port: "[PC Preview] unknow port", + parsedExclusionList: "[PC Preview] unknow parsedExclusionList" + } + const blocked = "[PC Preview] unknow blocked" + const BackgroundPolicy = "[PC Preview] unknow BackgroundPolicy" + const connection = { + on: function (...args) { + console.warn("net.connection.on interface mocked in the Previewer. How this interface works on the Previewer may " + + "be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] === 'netAvailable') { + args[len - 1].call(this, paramMock.businessErrorMock, NetHandle); + } else if (args[0] === 'netBlockStatusChange') { + args[len - 1].call(this, paramMock.businessErrorMock, { NetHandle, blocked }); + } else if (args[0] === 'netCapabilitiesChange') { + args[len - 1].call(this, { NetHandle, NetCap }); + } else if (args[0] === 'netConnectionPropertiesChange') { + args[len - 1].call(this, { NetHandle, ConnectionProperties }); + } else if (args[0] === 'netLosing') { + args[len - 1].call(this, { + NetHandle, + maxMsToLive: "[PC Preview] unknow maxMsToLive" + }); + } else if (args[0] === 'netLost') { + args[len - 1].call(this, paramMock.businessErrorMock, NetHandle); + } else if (args[0] === 'netUnavailable') { + args[len - 1].call(this, paramMock.businessErrorMock); + } + } + }, + off: function (...args) { + console.warn("net.connection.off interface mocked in the Previewer. How this interface works on the Previewer may " + + "be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] === 'netAvailable') { + args[len - 1].call(this, paramMock.businessErrorMock, NetHandle); + } else if (args[0] === 'netBlockStatusChange') { + args[len - 1].call(this, { NetHandle, blocked }); + } else if (args[0] === 'netCapabilitiesChange') { + args[len - 1].call(this, { NetHandle, NetCap }); + } else if (args[0] === 'netConnectionPropertiesChange') { + args[len - 1].call(this, { NetHandle, ConnectionProperties }); + } else if (args[0] === 'netLosing') { + args[len - 1].call(this, { + NetHandle, + maxMsToLive: "[PC Preview] unknow maxMsToLive" + }); + } else if (args[0] === 'netLost') { + args[len - 1].call(this, paramMock.businessErrorMock, NetHandle); + } else if (args[0] === 'netUnavailable') { + args[len - 1].call(this, paramMock.businessErrorMock); + } + } + }, + addNetStatusCallback: function (...args) { + console.warn("net.connection.addNetStatusCallback interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + removeNetStatusCallback: function (...args) { + console.warn("net.connection.removeNetStatusCallback interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getAppNet: function (...args) { + console.warn("net.connection.getAppNet interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, NetHandle); + } else { + return new Promise((resolve, reject) => { + resolve(NetHandle); + }) + } + }, + setAppNet: function (...args) { + console.warn("net.connection.setAppNet interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getDefaultNet: function (...args) { + console.warn("net.connection.getDefaultNet interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, NetHandle); + } else { + return new Promise((resolve, reject) => { + resolve(NetHandle); + }) + } + }, + getAllNets: function (...args) { + console.warn("net.connection.getAllNets interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, NetHandle); + } else { + return new Promise((resolve, reject) => { + resolve(NetHandle); + }) + } + }, + getDefaultHttpProxy: function (...args) { + console.warn("net.connection.getDefaultHttpProxy interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, HttpProxy); + } else { + return new Promise((resolve, reject) => { + resolve(HttpProxy); + }) + } + }, + getConnectionProperties: function (...args) { + console.warn("net.connection.getConnectionProperties interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ConnectionProperties); + } else { + return new Promise((resolve, reject) => { + resolve(ConnectionProperties); + }) + } + }, + getNetCapabilities: function (...args) { + console.warn("net.connection.getNetCapabilities interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, NetCapabilities); + } else { + return new Promise((resolve, reject) => { + resolve(NetCapabilities); + }) + } + }, + getBackgroundPolicy: function (...args) { + console.warn("net.connection.getBackgroundPolicy interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, BackgroundPolicy); + } else { + return new Promise((resolve, reject) => { + resolve(BackgroundPolicy); + }) + } + }, + isDefaultNetMetered: function (...args) { + console.warn("net.connection.isDefaultNetMetered interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + hasDefaultNet: function (...args) { + console.warn("net.connection.hasDefaultNet interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + enableAirplaneMode: function (...args) { + console.warn("net.connection.enableAirplaneMode interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + disableAirplaneMode: function (...args) { + console.warn("net.connection.disableAirplaneMode interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + enableDistributedCellularData: function (...args) { + console.warn("net.connection.enableDistributedCellularData interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + disableDistributedCellularData: function (...args) { + console.warn("net.connection.disableDistributedCellularData interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + reportNetConnected: function (...args) { + console.warn("net.connection.reportNetConnected interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + reportNetDisconnected: function (...args) { + console.warn("net.connection.reportNetDisconnected interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + } + return connection +} diff --git a/runtime/main/extend/systemplugin/napi/ohos_net_http.js b/runtime/main/extend/systemplugin/napi/ohos_net_http.js new file mode 100644 index 00000000..18c21004 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_net_http.js @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockHttp() { + const HttpResponseCacheOptions = { + filePath: "[PC Preview] unknow filePath", + fileChildPath: "[PC Preview] unknow fileChildPath", + cacheSize: "[PC Preview] unknow cacheSize" + } + const HttpResponseCache = { + close: function (...args) { + console.warn("net.HttpResponseCache.close interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + delete: function (...args) { + console.warn("net.HttpResponseCache.delete interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + flush: function (...args) { + console.warn("net.HttpResponseCache.flush interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + } + } + const HttpResponseMock = { + result: "[PC Preview] unknow result", + responseCode: "[PC Preview] unknow responseCode", + header: "[PC Preview] unknow header" + } + const HttpRequestMock = { + request: function (...args) { + console.warn("HttpRequest.request interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, HttpResponseMock); + } else { + return new Promise((resolve, reject) => { + resolve(HttpResponseMock); + }) + } + }, + destroy: function () { + console.warn("HttpRequest.destroy interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + on: function (...args) { + console.warn("HttpRequest.on interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock); + } + }, + off: function (...args) { + console.warn("HttpRequest.off interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock); + } + } + } + const http = { + createHttp: function () { + console.warn("net.http.createHttp interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return HttpRequestMock; + }, + getInstalledHttpResponseCache: function (...args) { + console.warn("net.http.getInstalledHttpResponseCache interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, HttpResponseCache); + } else { + return new Promise((resolve, reject) => { + resolve(HttpResponseCache); + }) + } + }, + createHttpResponseCache: function (...args) { + console.warn("net.http.createHttpResponseCache interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, HttpResponseCacheOptions); + } else { + return new Promise((resolve, reject) => { + resolve(HttpResponseCache); + }) + } + } + } + return http +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_net_socket.js b/runtime/main/extend/systemplugin/napi/ohos_net_socket.js new file mode 100644 index 00000000..446d1d78 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_net_socket.js @@ -0,0 +1,265 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockSocket() { + const SocketStateBase = { + isBound: "[PC Preview] unknow isBound", + isClose: "[PC Preview] unknow isClose", + isConnected: "[PC Preview] unknow isConnected" + } + const SocketRemoteInfo = { + address: "[PC Preview] unknow address", + family: "[PC Preview] unknow family", + port: "[PC Preview] unknow port", + size: "[PC Preview] unknow size" + } + const NetAddress = { + address: "[PC Preview] unknow saddressize", + family: "[PC Preview] unknow family", + port: "[PC Preview] unknow port " + } + const UDPSocket = { + bind: function (...args) { + console.warn("UDPSocket.bind interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + send: function (...args) { + console.warn("UDPSocket.send interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + close: function (...args) { + console.warn("UDPSocket.close interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getState: function (...args) { + console.warn("UDPSocket.getState interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, SocketStateBase) + } else { + return new Promise((resolve, reject) => { + resolve(SocketStateBase); + }) + } + }, + setExtraOptions: function (...args) { + console.warn("UDPSocket.setExtraOptions interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + on: function (...args) { + console.warn("UDPSocket.on interface mocked in the Previewer. How this interface works on the Previewer may " + + "be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] === 'message') { + args[len - 1].call(this, { + message: "[PC Preview] unknow message", + remoteInfo: SocketRemoteInfo + }); + } else if (args[0] === 'listening') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else if (args[0] === 'error') { + args[len - 1].call(this, paramMock.businessErrorMock); + } + } + }, + off: function (...args) { + console.warn("UDPSocket.off interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] === 'message') { + args[len - 1].call(this, { + message: "[PC Preview] unknow message", + remoteInfo: SocketRemoteInfo + }); + } else if (args[0] === 'listening') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else if (args[0] === 'error') { + args[len - 1].call(this, paramMock.businessErrorMock); + } + } + } + } + + const TCPSocket = { + bind: function (...args) { + console.warn("TcpSocket.bind interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + connect: function (...args) { + console.warn("TcpSocket.connect interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + send: function (...args) { + console.warn("TcpSocket.send interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + close: function (...args) { + console.warn("TcpSocket.close interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getRemoteAddress: function (...args) { + console.warn("TcpSocket.getRemoteAddress interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, NetAddress) + } else { + return new Promise((resolve, reject) => { + resolve(NetAddress); + }) + } + }, + getState: function (...args) { + console.warn("TcpSocket.getState interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, SocketStateBase) + } else { + return new Promise((resolve, reject) => { + resolve(SocketStateBase); + }) + } + }, + setExtraOptions: function (...args) { + console.warn("TcpSocket.setExtraOptions interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + on: function (...args) { + console.warn("TcpSocket.on interface mocked in the Previewer. How this interface works on the Previewer may " + + "be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] === 'message') { + args[len - 1].call(this, { + message: "[PC Preview] unknow message", + remoteInfo: SocketRemoteInfo + }); + } else if (args[0] === 'listening') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else if (args[0] === 'error') { + args[len - 1].call(this, paramMock.businessErrorMock); + } + } + }, + off: function (...args) { + console.warn("TcpSocket.off interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] === 'message') { + args[len - 1].call(this, { + message: "[PC Preview] unknow message", + remoteInfo: SocketRemoteInfo + }); + } else if (args[0] === 'listening') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else if (args[0] === 'error') { + args[len - 1].call(this, paramMock.businessErrorMock); + } + } + } + } + const socket = { + constructUDPSocketInstance: function () { + console.warn("net.socket.constructUDPSocketInstance interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return UDPSocket; + }, + constructTCPSocketInstance: function () { + console.warn("net.socket.constructTCPSocketInstance interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return TCPSocket; + } + } + return socket +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_net_webSocket.js b/runtime/main/extend/systemplugin/napi/ohos_net_webSocket.js new file mode 100644 index 00000000..ec457c36 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_net_webSocket.js @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockWebSocket() { + global.systemplugin.net = {} + const WebSocketMock = { + connect: function (...args) { + console.warn("WebSocket.connect interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + send: function (...args) { + console.warn("WebSocket.send interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + close: function (...args) { + console.warn("WebSocket.close interface mocked in the Previewer. How this interface works on the Previewer " + + "may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + on: function (...args) { + console.warn("WebSocket.on interface mocked in the Previewer. How this interface works on the Previewer may " + + "be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] === 'open') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock); + } else if (args[0] === 'message') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else if (args[0] === 'close') { + args[len - 1].call(this, paramMock.businessErrorMock, { + code: "[PC Preview] unknow code", + reason: "[PC Preview] unknow reason" + }); + } else if (args[0] === 'error') { + args[len - 1].call(this, paramMock.businessErrorMock); + } + } + }, + off: function (...args) { + console.warn("WebSocket.off interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] === 'open') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock); + } else if (args[0] === 'message') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else if (args[0] === 'close') { + args[len - 1].call(this, paramMock.businessErrorMock, { + code: "[PC Preview] unknow code", + reason: "[PC Preview] unknow reason" + }); + } else if (args[0] === 'error') { + args[len - 1].call(this, paramMock.businessErrorMock); + } + } + } + } + const webSocket = { + createWebSocket: function () { + console.warn("net.webSocket.createWebSocket interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebSocketMock; + } + } + return webSocket +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/network.js b/runtime/main/extend/systemplugin/napi/ohos_network.js similarity index 95% rename from runtime/main/extend/systemplugin/network.js rename to runtime/main/extend/systemplugin/napi/ohos_network.js index ca4815f4..e1933456 100644 --- a/runtime/main/extend/systemplugin/network.js +++ b/runtime/main/extend/systemplugin/napi/ohos_network.js @@ -18,7 +18,7 @@ export function mockNetwork() { metered: true, type: "5g" } - global.systemplugin.network = { + const network = { getType: function (...args) { console.warn("network.getType interface mocked in the Previewer. How this interface works on the Previewer may" + " be different from that on a real device.") @@ -41,4 +41,5 @@ export function mockNetwork() { delete this.unsubscribeNetwork } } + return network } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/nfc.js b/runtime/main/extend/systemplugin/napi/ohos_nfc_cardEmulation.js similarity index 86% rename from runtime/main/extend/systemplugin/nfc.js rename to runtime/main/extend/systemplugin/napi/ohos_nfc_cardEmulation.js index 9b776dee..7df508a2 100644 --- a/runtime/main/extend/systemplugin/nfc.js +++ b/runtime/main/extend/systemplugin/napi/ohos_nfc_cardEmulation.js @@ -13,15 +13,14 @@ * limitations under the License. */ -import { paramMock } from "./utils" +import { paramMock } from "../utils" export function mockNfcCardEmulation() { - global.systemplugin.nfc = {} - global.systemplugin.nfc.cardEmulation = { + const cardEmulation = { isSupported: function (...args) { console.warn("nfc.cardEmulation.isSupported interface mocked in the Previewer. How this interface works on the" + " Previewer may be different from that on a real device.") return paramMock.paramBooleanMock; } } -} +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_nfc_controller.js b/runtime/main/extend/systemplugin/napi/ohos_nfc_controller.js new file mode 100644 index 00000000..466f4650 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_nfc_controller.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockController() { + const controller = { + isNfcAvailable: function (...args) { + console.warn("nfc.controller.isNfcAvailable interface mocked in the Previewer." + + "How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + isNfcOpen: function (...args) { + console.warn("nfc.controller.isNfcOpen interface mocked in the Previewer." + + "How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + on: function (...args) { + console.warn("nfc.controller.on interface mocked in the Previewer." + + "How this interface works on the Previewer may be different from that on a real device.") + }, + off: function (...args) { + console.warn("nfc.controller.off interface mocked in the Previewer." + + "How this interface works on the Previewer may be different from that on a real device.") + }, + getNfcState: function (...args) { + console.warn("nfc.controller.getNfcState interface mocked in the Previewer." + + "How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + } + return controller +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/ohos/nfc.js b/runtime/main/extend/systemplugin/napi/ohos_nfc_tag.js similarity index 86% rename from runtime/main/extend/systemplugin/ohos/nfc.js rename to runtime/main/extend/systemplugin/napi/ohos_nfc_tag.js index 32da1a99..37a8050b 100644 --- a/runtime/main/extend/systemplugin/ohos/nfc.js +++ b/runtime/main/extend/systemplugin/napi/ohos_nfc_tag.js @@ -15,11 +15,7 @@ import { paramMock } from "../utils" -export function mockOhosNfc() { - global.ohosplugin.nfc = {} - const TagInfoMock = { - supportedProfiles: "[PC preview] unknown supportedProfiles", - } +export function mockTag() { const NfcATagMock = { getTagInfo: function (...args) { console.warn("NfcATag.getTagInfo interface mocked in the Previewer." + @@ -252,39 +248,7 @@ export function mockOhosNfc() { return paramMock.paramNumberMock }, } - global.ohosplugin.nfc.cardEmulation = { - isSupported: function (...args) { - console.warn("nfc.cardEmulation.isSupported interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock; - } - } - global.ohosplugin.nfc.controller = { - isNfcAvailable: function (...args) { - console.warn("nfc.controller.isNfcAvailable interface mocked in the Previewer." + - "How this interface works on the Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - isNfcOpen: function (...args) { - console.warn("nfc.controller.isNfcOpen interface mocked in the Previewer." + - "How this interface works on the Previewer may be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - on: function (...args) { - console.warn("nfc.controller.on interface mocked in the Previewer." + - "How this interface works on the Previewer may be different from that on a real device.") - }, - off: function (...args) { - console.warn("nfc.controller.off interface mocked in the Previewer." + - "How this interface works on the Previewer may be different from that on a real device.") - }, - getNfcState: function (...args) { - console.warn("nfc.controller.getNfcState interface mocked in the Previewer." + - "How this interface works on the Previewer may be different from that on a real device.") - return paramMock.paramNumberMock; - }, - } - global.ohosplugin.nfc.tag = { + const tag = { getNfcATag: function (...args) { console.warn("nfc.tag.getNfcATag interface mocked in the Previewer. How this interface works on the" + " Previewer may be different from that on a real device.") @@ -306,4 +270,5 @@ export function mockOhosNfc() { return NfcVTagMock; }, } -} + return tag +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/notification.js b/runtime/main/extend/systemplugin/napi/ohos_notification.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/notification.js rename to runtime/main/extend/systemplugin/napi/ohos_notification.js diff --git a/runtime/main/extend/systemplugin/pasteboard.js b/runtime/main/extend/systemplugin/napi/ohos_pasteboard.js similarity index 94% rename from runtime/main/extend/systemplugin/pasteboard.js rename to runtime/main/extend/systemplugin/napi/ohos_pasteboard.js index c0a9943d..efedd4d0 100644 --- a/runtime/main/extend/systemplugin/pasteboard.js +++ b/runtime/main/extend/systemplugin/napi/ohos_pasteboard.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import { paramMock } from "./utils" +import { paramMock } from "../utils" export function mockPasteBoard() { const PasteDataMock = { @@ -49,7 +49,7 @@ export function mockPasteBoard() { } } } - global.systemplugin.pasteboard = { + const pasteboard = { createPlainTextData: function () { console.warn("pasteboard.createPlainTextData interface mocked in the Previewer. How this interface works on" + " the Previewer may be different from that on a real device.") @@ -61,4 +61,5 @@ export function mockPasteBoard() { return SystemPasteboardMock; } } + return pasteboard } diff --git a/runtime/main/extend/systemplugin/napi/power.js b/runtime/main/extend/systemplugin/napi/ohos_power.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/power.js rename to runtime/main/extend/systemplugin/napi/ohos_power.js diff --git a/runtime/main/extend/systemplugin/napi/process.js b/runtime/main/extend/systemplugin/napi/ohos_process.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/process.js rename to runtime/main/extend/systemplugin/napi/ohos_process.js diff --git a/runtime/main/extend/systemplugin/ohos/reminderAgent.js b/runtime/main/extend/systemplugin/napi/ohos_reminderAgent.js similarity index 96% rename from runtime/main/extend/systemplugin/ohos/reminderAgent.js rename to runtime/main/extend/systemplugin/napi/ohos_reminderAgent.js index 8ab41d15..8e69469b 100644 --- a/runtime/main/extend/systemplugin/ohos/reminderAgent.js +++ b/runtime/main/extend/systemplugin/napi/ohos_reminderAgent.js @@ -49,7 +49,7 @@ export function mockReminderAgent() { const reminderReqs = [ reminderReq ] - global.ohosplugin.reminderAgent = { + const reminderAgent = { publishReminder: function (...args) { console.warn("reminderAgent.publishReminder interface mocked in the Previewer." + "How this interface works on the Previewer may be different from that on a real device.") @@ -123,4 +123,5 @@ export function mockReminderAgent() { } } } + return reminderAgent } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/request.js b/runtime/main/extend/systemplugin/napi/ohos_request.js similarity index 93% rename from runtime/main/extend/systemplugin/request.js rename to runtime/main/extend/systemplugin/napi/ohos_request.js index 92f5f3b7..f82bdcc6 100644 --- a/runtime/main/extend/systemplugin/request.js +++ b/runtime/main/extend/systemplugin/napi/ohos_request.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import { hasComplete } from "./utils" +import { hasComplete } from "../utils" export function mockRequest() { const uploadResponseMock = { @@ -27,7 +27,7 @@ export function mockRequest() { const onDownloadCompleteMock = { uri: "[PC Preview]: unknow uri" } - global.systemplugin.request = { + const request = { upload: function (...args) { console.warn("system.request.upload interface mocked in the Previewer. How this interface works on the" + " Previewer may be different from that on a real device.") @@ -47,4 +47,5 @@ export function mockRequest() { hasComplete(args[0].complete) } } + return request } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_resourceManager.js b/runtime/main/extend/systemplugin/napi/ohos_resourceManager.js new file mode 100644 index 00000000..2369acb0 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_resourceManager.js @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function mockResourceManager() { + function Configuration(direction, locale) { + this.direction = direction; + this.locale = locale; + } + + function DeviceCapability(screenDensity, deviceType) { + this.screenDensity = screenDensity; + this.deviceType = deviceType; + } + + function ResourceManager(mgrId, module) { + var resMgrId = mgrId; + var resourcemgrModuleGroup = module; + + this.getString = getString; + async function getString(resId, callback) { + var data = "mock string"; + console.warn("ResourceManager.getString interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + if (typeof callback === 'function') { + callback.call(this, null, data); + } else { + return new Promise((resolve) => { + resolve(data); + }) + } + } + + this.getStringArray = getStringArray; + async function getStringArray(resId, callback) { + var data = ["mock string1", "mock string2"]; + console.warn("ResourceManager.getStringArray interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + if (typeof callback === 'function') { + callback.call(this, null, data); + } else { + return new Promise((resolve) => { + resolve(data); + }) + } + } + + this.getMedia = getMedia; + async function getMedia(resId, callback) { + var data = "mock media data"; + console.warn("ResourceManager.getMedia interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + if (typeof callback === 'function') { + callback.call(this, 1, data); + } else { + return new Promise((resolve, reject) => { + reject(data); + }) + } + } + + this.getMediaBase64 = getMediaBase64; + async function getMediaBase64(resId, callback) { + var data = "mock media data"; + console.warn("ResourceManager.getMediaBase64 interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + if (typeof callback === 'function') { + callback.call(this, 1, data); + } else { + return new Promise((resolve, reject) => { + reject(data); + }) + } + } + + this.getPluralString = getPluralString; + async function getPluralString(resId, num, callback) { + var data = "mock plural string"; + console.warn("ResourceManager.getPluralString interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + if (typeof callback === 'function') { + callback.call(this, null, data); + } else { + return new Promise((resolve) => { + resolve(data); + }) + } + } + + this.getConfiguration = getConfiguration; + async function getConfiguration(callback) { + var data = { "direction": 0, "locale": "zh_CN" }; + console.warn("ResourceManager.getConfiguration interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + if (typeof callback === 'function') { + callback.call(this, null, data); + } else { + return new Promise((resolve) => { + resolve(data); + }) + } + } + + this.getDeviceCapability = getDeviceCapability; + async function getDeviceCapability(callback) { + var data = { "deviceType": 0, "screenDensity": 480 }; + console.warn("ResourceManager.getDeviceCapability interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + if (typeof callback === 'function') { + callback.call(this, null, data); + } else { + return new Promise((resolve) => { + resolve(data); + }) + } + } + + this.release = release; + async function release(callback) { + console.warn("ResourceManager.release interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + } + + this.getRawFile = getRawFile; + async function getRawFile(path, callback) { + var data = "mock raw file"; + console.warn("ResourceManager.getRawFile interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + if (typeof callback === 'function') { + callback.call(this, null, data); + } else { + return new Promise((resolve) => { + resolve(data); + }) + } + } + + this.getRawFileDescriptor = getRawFileDescriptor; + async function getRawFileDescriptor(path, callback) { + var data = "mock raw file descriptor"; + console.warn("ResourceManager.getRawFileDescriptor interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + if (typeof callback === 'function') { + callback.call(this, null, data); + } else { + return new Promise((resolve) => { + resolve(data); + }) + } + } + + this.closeRawFileDescriptor = closeRawFileDescriptor; + async function closeRawFileDescriptor(path, callback) { + var data = "mock close raw file descriptor"; + console.warn("ResourceManager.closeRawFileDescriptor interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + if (typeof callback === 'function') { + callback.call(this, null, data); + } else { + return new Promise((resolve) => { + resolve(data); + }) + } + } + } + + var resourceManager = { + getResourceManager: async function getResourceManager(optBundleName, optCallback) { + let bundleName = ''; + let callback; + if (typeof optCallback == 'function') { + bundleName = optBundleName ? optBundleName : ''; + callback = optCallback; + } else if (typeof optBundleName == 'function') { + callback = optBundleName; + } else { + bundleName = optBundleName ? optBundleName : ''; + } + let data = new ResourceManager(1, null); + console.warn("ResourceManager.getResourceManager interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + if (typeof callback === 'function') { + callback.call(this, 1, data); + } else { + return new Promise((resolve) => { + resolve(data); + }) + } + } + }; + + const resourceManager = { + getResourceManager: resourceManager.getResourceManager + } + return resourceManager +} diff --git a/runtime/main/extend/systemplugin/napi/rpc.js b/runtime/main/extend/systemplugin/napi/ohos_rpc.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/rpc.js rename to runtime/main/extend/systemplugin/napi/ohos_rpc.js diff --git a/runtime/main/extend/systemplugin/napi/runninglock.js b/runtime/main/extend/systemplugin/napi/ohos_runninglock.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/runninglock.js rename to runtime/main/extend/systemplugin/napi/ohos_runninglock.js diff --git a/runtime/main/extend/systemplugin/screenLock.js b/runtime/main/extend/systemplugin/napi/ohos_screenLock.js similarity index 94% rename from runtime/main/extend/systemplugin/screenLock.js rename to runtime/main/extend/systemplugin/napi/ohos_screenLock.js index ffaf61fe..893f232c 100644 --- a/runtime/main/extend/systemplugin/screenLock.js +++ b/runtime/main/extend/systemplugin/napi/ohos_screenLock.js @@ -13,10 +13,10 @@ * limitations under the License. */ -import { paramMock } from "./utils" +import { paramMock } from "../utils" export function mockScreenLock() { - global.systemplugin.screenLock = { + const screenLock = { isScreenLocked: function (...args) { console.warn("screenLock.isScreenLocked interface mocked in the Previewer. How this interface works on the" + " Previewer may be different from that on a real device.") @@ -54,4 +54,5 @@ export function mockScreenLock() { } } } + return screenLock } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/screenshot.js b/runtime/main/extend/systemplugin/napi/ohos_screenshot.js similarity index 86% rename from runtime/main/extend/systemplugin/screenshot.js rename to runtime/main/extend/systemplugin/napi/ohos_screenshot.js index 9226f2af..67478007 100644 --- a/runtime/main/extend/systemplugin/screenshot.js +++ b/runtime/main/extend/systemplugin/napi/ohos_screenshot.js @@ -13,31 +13,31 @@ * limitations under the License. */ -import { paramMock } from "./utils" +import { paramMock } from "../utils" export function mockScreenshot() { - const RectMock = { + const RectMock = { left: '[PC preview] unknow Rect.left', top: '[PC preview] unknow Rect.top', width: '[PC preview] unknow Rect.width', height: '[PC preview] unknow Rect.height' } - const SizeMock = { + const SizeMock = { width: '[PC preview] unknow Size.width', height: '[PC preview] unknow Size.height', } - const ScreenshotOptionsMock= { + const ScreenshotOptionsMock = { screenRect: RectMock, imageSize: SizeMock, rotation: '[PC preview] unknow Size.width', - displayId: '[PC preview] unknow Size.width', + displayId: '[PC preview] unknow Size.width', } const screenshotMock = { ImageSource: '[PC preview] unknow ImageSource' } - global.systemplugin.screenshot = { + const screenshot = { save: function (...args) { console.warn("screenshot.save interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") @@ -51,4 +51,5 @@ export function mockScreenshot() { } } } + return screenshot } diff --git a/runtime/main/extend/systemplugin/huks.js b/runtime/main/extend/systemplugin/napi/ohos_security_huks.js similarity index 96% rename from runtime/main/extend/systemplugin/huks.js rename to runtime/main/extend/systemplugin/napi/ohos_security_huks.js index 2545267b..99e99f38 100644 --- a/runtime/main/extend/systemplugin/huks.js +++ b/runtime/main/extend/systemplugin/napi/ohos_security_huks.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import { paramMock } from "./utils" +import { paramMock } from "../utils" export function mockHuks() { @@ -36,7 +36,7 @@ export function mockHuks() { properties: [HuksParamMock], certChains: [paramMock.paramStringMock], } - global.systemplugin.huks = { + const huks = { generateKey: function (...args) { console.warn("huks.generateKey interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") @@ -438,4 +438,5 @@ export function mockHuks() { HUKS_TAG_ASYMMETRIC_PRIVATE_KEY_DATA: 20003, }, } + return huks } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/securitylabel.js b/runtime/main/extend/systemplugin/napi/ohos_securitylabel.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/securitylabel.js rename to runtime/main/extend/systemplugin/napi/ohos_securitylabel.js diff --git a/runtime/main/extend/systemplugin/napi/sensor.js b/runtime/main/extend/systemplugin/napi/ohos_sensor.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/sensor.js rename to runtime/main/extend/systemplugin/napi/ohos_sensor.js diff --git a/runtime/main/extend/systemplugin/napi/settings.js b/runtime/main/extend/systemplugin/napi/ohos_settings.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/settings.js rename to runtime/main/extend/systemplugin/napi/ohos_settings.js diff --git a/runtime/main/extend/systemplugin/napi/statfs.js b/runtime/main/extend/systemplugin/napi/ohos_statfs.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/statfs.js rename to runtime/main/extend/systemplugin/napi/ohos_statfs.js diff --git a/runtime/main/extend/systemplugin/napi/storageStatistics.js b/runtime/main/extend/systemplugin/napi/ohos_storageStatistics.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/storageStatistics.js rename to runtime/main/extend/systemplugin/napi/ohos_storageStatistics.js diff --git a/runtime/main/extend/systemplugin/ohos/systemTime.js b/runtime/main/extend/systemplugin/napi/ohos_systemTime.js similarity index 96% rename from runtime/main/extend/systemplugin/ohos/systemTime.js rename to runtime/main/extend/systemplugin/napi/ohos_systemTime.js index 08ded396..4ed40e69 100644 --- a/runtime/main/extend/systemplugin/ohos/systemTime.js +++ b/runtime/main/extend/systemplugin/napi/ohos_systemTime.js @@ -16,7 +16,7 @@ import { paramMock } from "../utils" export function mockSystemTime() { - global.ohosplugin.systemTime = { + const systemTime = { setTime: function (...args) { console.warn('systemTime.setTime interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.'); @@ -149,5 +149,6 @@ export function mockSystemTime() { }); } }, - }; + } + return systemTime } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/ohos/systemTimer.js b/runtime/main/extend/systemplugin/napi/ohos_systemTimer.js similarity index 96% rename from runtime/main/extend/systemplugin/ohos/systemTimer.js rename to runtime/main/extend/systemplugin/napi/ohos_systemTimer.js index addd4d91..ce16e5a0 100644 --- a/runtime/main/extend/systemplugin/ohos/systemTimer.js +++ b/runtime/main/extend/systemplugin/napi/ohos_systemTimer.js @@ -16,7 +16,7 @@ import { paramMock } from "../utils" export function mockSystemTimer() { - global.ohosplugin.systemTimer = { + const systemTimer = { TIMER_TYPE_REALTIME: '[PC preview] unknow TIMER_TYPE_REALTIME', TIMER_TYPE_WAKEUP: '[PC preview] unknow TIMER_TYPE_WAKEUP', TIMER_TYPE_EXACT: '[PC preview] unknow TIMER_TYPE_EXACT', @@ -70,4 +70,5 @@ export function mockSystemTimer() { } } } + return systemTimer } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/systemParameter.js b/runtime/main/extend/systemplugin/napi/ohos_systemparameter.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/systemParameter.js rename to runtime/main/extend/systemplugin/napi/ohos_systemparameter.js diff --git a/runtime/main/extend/systemplugin/napi/ohos_telephony_call.js b/runtime/main/extend/systemplugin/napi/ohos_telephony_call.js new file mode 100644 index 00000000..64ef7ab0 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_telephony_call.js @@ -0,0 +1,561 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockCall() { + const CallWaitingStatus = "[PC Preview] unknow CallWaitingStatus"; + const RestrictionStatus = "[PC Preview] unknow RestrictionStatus"; + const CallAttributeOptions = { + accountNumber: "[PC Preview] unknow accountNumber", + speakerphoneOn: "[PC Preview] unknow speakerphoneOn", + accountId: "[PC Preview] unknow accountId", + videoState: "[PC Preview] unknow videoState", + startTime: "[PC Preview] unknow startTime", + isEcc: "[PC Preview] unknow isEcc", + callType: "[PC Preview] unknow callType", + callId: "[PC Preview] unknow callId", + callState: "[PC Preview] unknow callState", + conferenceState: "[PC Preview] unknow conferenceState" + } + const CallTransferResult = { + status: "[PC Preview] unknow status", + number: "[PC Preview] unknow number", + } + const call = { + dial: function (...args) { + console.warn("telephony.call.dial interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + makeCall: function (...args) { + console.warn("telephony.call.makeCall interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + hasCall: function (...args) { + console.warn("telephony.call.hasCall interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + getCallState: function (...args) { + console.warn("telephony.call.getCallState interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, CallState); + } else { + return new Promise((resolve, reject) => { + resolve(CallState); + }) + } + }, + displayCallScreen: function (...args) { + console.warn("telephony.call.displayCallScreen interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + muteRinger: function (...args) { + console.warn("telephony.call.muteRinger interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + hasVoiceCapability: function () { + console.warn("telephony.call.hasVoiceCapability interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + isVideoCallingEnabled: function (...args) { + console.warn("telephony.call.isVideoCallingEnabled interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + inputDialerSpecialCode: function (...args) { + console.warn("telephony.call.inputDialerSpecialCode interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + isHacEnabled: function (...args) { + console.warn("telephony.call.isHacEnabled interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + isEmergencyPhoneNumber: function (...args) { + console.warn("telephony.call.isEmergencyPhoneNumber interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + formatPhoneNumber: function (...args) { + console.warn("telephony.call.formatPhoneNumber interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + formatPhoneNumberToE164: function (...args) { + console.warn("telephony.call.formatPhoneNumberToE164 interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + comparePhoneNumbers: function (...args) { + console.warn("telephony.call.comparePhoneNumbers interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + getCallerIndex: function (...args) { + console.warn("telephony.call.getCallerIndex interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getCountryCodeFromDbNumber: function (...args) { + console.warn("telephony.call.getCountryCodeFromDbNumber interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getIntlPrefixAndCountryCodeLen: function (...args) { + console.warn("telephony.call.getIntlPrefixAndCountryCodeLen interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + answer: function (...args) { + console.warn("telephony.call.answer interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + hangup: function (...args) { + console.warn("telephony.call.hangup interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + reject: function (...args) { + console.warn("telephony.call.reject interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + holdCall: function (...args) { + console.warn("telephony.call.holdCall interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + unHoldCall: function (...args) { + console.warn("telephony.call.unHoldCall interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + switchCall: function (...args) { + console.warn("telephony.call.switchCall interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + combineConference: function (...args) { + console.warn("telephony.call.combineConference interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getMainCallId: function (...args) { + console.warn("telephony.call.getMainCallId interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getSubCallIdList: function (...args) { + console.warn("telephony.call.getSubCallIdList interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }) + } + }, + getCallIdListForConference: function (...args) { + console.warn("telephony.call.getCallIdListForConference interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }) + } + }, + getCallWaitingStatus: function (...args) { + console.warn("telephony.call.getCallWaitingStatus interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, CallWaitingStatus); + } else { + return new Promise((resolve, reject) => { + resolve(CallWaitingStatus); + }) + } + }, + setCallWaiting: function (...args) { + console.warn("telephony.call.setCallWaiting interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + startDTMF: function (...args) { + console.warn("telephony.call.startDTMF interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + stopDTMF: function (...args) { + console.warn("telephony.call.stopDTMF interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + isInEmergencyCall: function (...args) { + console.warn("telephony.call.isInEmergencyCall interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + on: function (...args) { + console.warn("telephony.call.on interface mocked in the Previewer. How this interface works on the Previewer may " + + "be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] == 'callDetailsChange') { + args[len - 1].call(this, CallAttributeOptions); + } else if (args[0] == 'callEventChange') { + args[len - 1].call(this, paramMock.paramObjectMock); + } + } + }, + off: function (...args) { + console.warn("telephony.call.off interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] == 'callDetailsChange') { + args[len - 1].call(this, CallAttributeOptions); + } else if (args[0] == 'callEventChange') { + args[len - 1].call(this, paramMock.paramObjectMock); + } + } + }, + isNewCallAllowed: function (...args) { + console.warn("telephony.call.isNewCallAllowed interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + separateConference: function (...args) { + console.warn("telephony.call.separateConference interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getCallRestrictionStatus: function (...args) { + console.warn("telephony.call.getCallRestrictionStatus interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, RestrictionStatus); + } else { + return new Promise((resolve, reject) => { + resolve(RestrictionStatus); + }) + } + }, + setCallRestriction: function (...args) { + console.warn("telephony.call.setCallRestriction interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + setCallTransfer: function (...args) { + console.warn("telephony.call.setCallTransfer interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getCallTransferInfo: function (...args) { + console.warn("telephony.call.getCallTransferInfo interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, CallTransferResult); + } else { + return new Promise((resolve, reject) => { + resolve(CallTransferResult); + }) + } + }, + setCallTransferInfo: function (...args) { + console.warn("telephony.call.setCallTransferInfo interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + isRinging: function (...args) { + console.warn("telephony.call.isRinging interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + setMuted: function (...args) { + console.warn("telephony.call.setMuted interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + setAudioDevice: function (...args) { + console.warn("telephony.call.setAudioDevice interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + } + } + return call +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_telephony_data.js b/runtime/main/extend/systemplugin/napi/ohos_telephony_data.js new file mode 100644 index 00000000..b6af9c3d --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_telephony_data.js @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockData() { + const data = { + getDefaultCellularDataSlotId: function (...args) { + console.warn("telephony.data.getDefaultCellularDataSlotId interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + setDefaultCellularDataSlotId: function (...args) { + console.warn("telephony.data.setDefaultCellularDataSlotId interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getCellularDataFlowType: function (...args) { + console.warn("telephony.data.getCellularDataFlowType interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getCellularDataState: function (...args) { + console.warn("telephony.data.getCellularDataState interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + isCellularDataEnabled: function (...args) { + console.warn("telephony.data.isCellularDataEnabled interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + enableCellularData: function (...args) { + console.warn("telephony.data.enableCellularData interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + disableCellularData: function (...args) { + console.warn("telephony.data.disableCellularData interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + isCellularDataRoamingEnabled: function (...args) { + console.warn("telephony.data.isCellularDataRoamingEnabled interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + enableCellularDataRoaming: function (...args) { + console.warn("telephony.data.enableCellularDataRoaming interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + disableCellularDataRoaming: function (...args) { + console.warn("telephony.data.disableCellularDataRoaming interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + } + } + return data +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_telephony_observer.js b/runtime/main/extend/systemplugin/napi/ohos_telephony_observer.js new file mode 100644 index 00000000..bba534f2 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_telephony_observer.js @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockObserver() { + const SimStateData = { + type: "[PC Preview] unknow type", + state: "[PC Preview] unknow state", + } + const observer = { + on: function (...args) { + console.warn("telephony.observer.on interface mocked in the Previewer. How this interface works on the Previewer may " + + "be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] === 'networkStateChange') { + args[len - 1].call(this, NetworkState); + } else if (args[0] === 'signalInfoChange') { + args[len - 1].call(this, [SignalInformation]); + } else if (args[0] === 'cellInfoChange') { + args[len - 1].call(this, [CellInformation]); + } else if (args[0] === 'cellularDataConnectionStateChange') { + args[len - 1].call(this, paramMock.businessErrorMock, { + state: "[PC Preview] unknow state", + network: "[PC Preview] unknow network" + }); + } else if (args[0] === 'cellularDataFlowChange') { + args[len - 1].call(this, DataFlowType); + } else if (args[0] === 'callStateChange') { + args[len - 1].call(this, paramMock.businessErrorMock, { + state: "[PC Preview] unknow state", + number: "[PC Preview] unknow number" + }); + } else if (args[0] === 'cfuIndicatorChange' || 'voiceMailMsgIndicatorChange') { + args[len - 1].call(this, paramMock.paramBooleanMock); + } else if (args[0] === 'simStateChange') { + args[len - 1].call(this, SimStateData); + } + } + }, + off: function (...args) { + console.warn("telephony.observer.off interface mocked in the Previewer. How this interface works on the Previewer may " + + "be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] === 'networkStateChange') { + args[len - 1].call(this, NetworkState); + } else if (args[0] === 'signalInfoChange') { + args[len - 1].call(this, [SignalInformation]); + } else if (args[0] === 'cellInfoChange') { + args[len - 1].call(this, [CellInformation]); + } else if (args[0] === 'cellularDataConnectionStateChange') { + args[len - 1].call(this, paramMock.businessErrorMock, { + state: "[PC Preview] unknow state", + network: "[PC Preview] unknow network" + }); + } else if (args[0] === 'cellularDataFlowChange') { + args[len - 1].call(this, DataFlowType); + } else if (args[0] === 'callStateChange') { + args[len - 1].call(this, paramMock.businessErrorMock, { + state: "[PC Preview] unknow state", + number: "[PC Preview] unknow number" + }); + } else if (args[0] === 'cfuIndicatorChange' || 'voiceMailMsgIndicatorChange') { + args[len - 1].call(this, paramMock.paramBooleanMock); + } else if (args[0] === 'simStateChange') { + args[len - 1].call(this, SimStateData); + } + } + }, + once: function (...args) { + console.warn("telephony.observer.once interface mocked in the Previewer. How this interface works on the Previewer may " + + "be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] === 'networkStateChange') { + args[len - 1].call(this, NetworkState); + } else if (args[0] === 'signalInfoChange') { + args[len - 1].call(this, [SignalInformation]); + } else if (args[0] === 'cellInfoChange') { + args[len - 1].call(this, [CellInformation]); + } else if (args[0] === 'cellularDataConnectionStateChange') { + args[len - 1].call(this, paramMock.businessErrorMock, { + state: "[PC Preview] unknow state", + network: "[PC Preview] unknow network" + }); + } else if (args[0] === 'cellularDataFlowChange') { + args[len - 1].call(this, DataFlowType); + } else if (args[0] === 'callStateChange') { + args[len - 1].call(this, paramMock.businessErrorMock, { + state: "[PC Preview] unknow state", + number: "[PC Preview] unknow number" + }); + } else if (args[0] === 'cfuIndicatorChange' || 'voiceMailMsgIndicatorChange') { + args[len - 1].call(this, paramMock.paramBooleanMock); + } else if (args[0] === 'simStateChange') { + args[len - 1].call(this, SimStateData); + } + } + } + } + return observer +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_telephony_radio.js b/runtime/main/extend/systemplugin/napi/ohos_telephony_radio.js new file mode 100644 index 00000000..9922ed01 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_telephony_radio.js @@ -0,0 +1,320 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +const NetworkState = { + longOperatorName: "[PC Preview] unknow longOperatorName", + shortOperatorName: "[PC Preview] unknow shortOperatorName", + plmnNumeric: "[PC Preview] unknow plmnNumeric", + isRoaming: "[PC Preview] unknow isRoaming", + regState: "[PC Preview] unknow regState", + nsaState: "[PC Preview] unknow nsaState", + isCaActive: "[PC Preview] unknow isCaActive", + isEmergency: "[PC Preview] unknow isEmergency", +} +const SignalInformation = { + signalType: "[PC Preview] unknow signalType", + signalLevel: "[PC Preview] unknow signalLevel" +} +const DataFlowType = "[PC Preview] unknow DataFlowType" +const DataConnectState = "[PC Preview] unknow DataConnectState" +const CellInformation = { + networkType: "[PC Preview] unknow networkType", + isCamped: "[PC Preview] unknow isCamped", + timeStamp: "[PC Preview] unknow timeStamp", + signalInformation: "[PC Preview] unknow signalInformation", + data: "[PC Preview] unknow unkown data" +} +export function mockRadio() { + const NetworkSearchResult = { + isNetworkSearchSuccess: "[PC Preview] unknow isNetworkSearchSuccess", + networkSearchResult: [{ + operatorName: "[PC Preview] unknow operatorName", + operatorNumeric: "[PC Preview] unknow operatorNumeric", + state: "[PC Preview] unknow state", + radioTech: "[PC Preview] unknow radioTech" + }] + } + const PreferredNetworkMode = "[PC Preview] unknow PreferredNetworkMode" + const NrOptionMode = "[PC Preview] unknow NrOptionMode" + const NetworkSelectionMode = "[PC Preview] unknow unkown NetworkSelectionMode" + const radio = { + getRadioTech: function (...args) { + console.warn("telephony.radio.getRadioTech interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, { + psRadioTech: "[PC Preview] unknow psRadioTech", + csRadioTech: "[PC Preview] unknow csRadioTech" + }); + } else { + return new Promise((resolve, reject) => { + resolve({ + psRadioTech: "[PC Preview] unknow psRadioTech", + csRadioTech: "[PC Preview] unknow csRadioTech" + }); + }) + } + }, + getNetworkState: function (...args) { + console.warn("telephony.radio.getNetworkState interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, NetworkState); + } else { + return new Promise((resolve, reject) => { + resolve(NetworkState); + }) + } + }, + sendUpdateCellLocationRequest: function (...args) { + console.warn("telephony.radio.sendUpdateCellLocationRequest interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getCellInformation: function (...args) { + console.warn("telephony.radio.getCellInformation interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [CellInformation]); + } else { + return new Promise((resolve, reject) => { + resolve([CellInformation]); + }) + } + }, + getNetworkSelectionMode: function (...args) { + console.warn("telephony.radio.getNetworkSelectionMode interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, NetworkSelectionMode); + } else { + return new Promise((resolve, reject) => { + resolve(NetworkSelectionMode); + }) + } + }, + setNetworkSelectionMode: function (...args) { + console.warn("telephony.radio.setNetworkSelectionMode interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getNetworkSearchInformation: function (...args) { + console.warn("telephony.radio.getNetworkSearchInformation interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, NetworkSearchResult); + } else { + return new Promise((resolve, reject) => { + resolve(NetworkSearchResult); + }) + } + }, + getISOCountryCodeForNetwork: function (...args) { + console.warn("telephony.radio.getISOCountryCodeForNetwork interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getNrOptionMode: function (...args) { + console.warn("telephony.radio.getNrOptionMode interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, NrOptionMode); + } else { + return new Promise((resolve, reject) => { + resolve(NrOptionMode); + }) + } + }, + getIMEI: function (...args) { + console.warn("telephony.radio.getIMEI interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getMEID: function (...args) { + console.warn("telephony.radio.getMEID interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getUniqueDeviceId: function (...args) { + console.warn("telephony.radio.getUniqueDeviceId interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getPrimarySlotId: function (...args) { + console.warn("telephony.radio.getPrimarySlotId interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getSignalInformation: function (...args) { + console.warn("telephony.radio.getSignalInformation interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [SignalInformation]); + } else { + return new Promise((resolve, reject) => { + resolve([SignalInformation]); + }) + } + }, + isNrSupported: function () { + console.warn("telephony.radio.isNrSupported interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + isRadioOn: function (...args) { + console.warn("telephony.radio.isRadioOn interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + turnOnRadio: function (...args) { + console.warn("telephony.radio.turnOnRadio interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + turnOffRadio: function (...args) { + console.warn("telephony.radio.turnOffRadio interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getOperatorName: function (...args) { + console.warn("telephony.radio.getOperatorName interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + setPreferredNetwork: function (...args) { + console.warn("telephony.radio.setPreferredNetwork interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getPreferredNetwork: function (...args) { + console.warn("telephony.radio.getPreferredNetwork interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, PreferredNetworkMode); + } else { + return new Promise((resolve, reject) => { + resolve(PreferredNetworkMode); + }) + } + }, + getIMEISV: function (...args) { + console.warn("telephony.radio.getIMEISV interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + } + } + return radio +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_telephony_sim.js b/runtime/main/extend/systemplugin/napi/ohos_telephony_sim.js new file mode 100644 index 00000000..7325cee3 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_telephony_sim.js @@ -0,0 +1,521 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockSim() { + const IccAccountInfo = { + simId: "[PC Preview] unknow simId", + slotIndex: "[PC Preview] unknow slotIndex", + isEsim: "[PC Preview] unknow isEsim", + isActive: "[PC Preview] unknow isActive", + iccId: "[PC Preview] unknow iccId", + showName: "[PC Preview] unknow showName", + showNumber: "[PC Preview] unknow showNumber" + } + const OperatorConfigMock = { + field: "[PC Preview] unknow field", + value: "[PC Preview] unknow value" + } + const LockStatusResponse = { + result: "[PC Preview] unknow result", + remain: "[PC Preview] unknow remain" + } + const DiallingNumbersInfo = { + efid: "[PC Preview] unknow efid", + recordNumber: "[PC Preview] unknow recordNumber", + alphaTag: "[PC Preview] unknow alphaTag", + number: "[PC Preview] unknow number", + emails: "[PC Preview] unknow emails" + } + const CardType = "[PC Preview] unknow CardType"; + const SimState = "[PC Preview] unknow SimState"; + const sim = { + isSimActive: function (...args) { + console.warn("telephony.sim.isSimActive interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + getDefaultVoiceSlotId: function (...args) { + console.warn("telephony.sim.getDefaultVoiceSlotId interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + hasOperatorPrivileges: function (...args) { + console.warn("telephony.sim.hasOperatorPrivileges interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + getISOCountryCodeForSim: function (...args) { + console.warn("telephony.sim.getISOCountryCodeForSim interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getSimOperatorNumeric: function (...args) { + console.warn("telephony.sim.getSimOperatorNumeric interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getSimSpn: function (...args) { + console.warn("telephony.sim.getSimSpn interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getSimState: function (...args) { + console.warn("telephony.sim.getSimState interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, SimState); + } else { + return new Promise((resolve, reject) => { + resolve(SimState); + }) + } + }, + getCardType: function (...args) { + console.warn("telephony.sim.getCardType interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, CardType); + } else { + return new Promise((resolve, reject) => { + resolve(CardType); + }) + } + }, + getSimIccId: function (...args) { + console.warn("telephony.sim.getSimIccId interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getVoiceMailIdentifier: function (...args) { + console.warn("telephony.sim.getVoiceMailIdentifier interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getVoiceMailNumber: function (...args) { + console.warn("telephony.sim.getVoiceMailNumber interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getVoiceMailCount: function (...args) { + console.warn("telephony.sim.getVoiceMailCount interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getSimTelephoneNumber: function (...args) { + console.warn("telephony.sim.getSimTelephoneNumber interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getSimGid1: function (...args) { + console.warn("telephony.sim.getSimGid1 interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getSimTeleNumberIdentifier: function (...args) { + console.warn("telephony.sim.getSimTeleNumberIdentifier interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getLine1NumberFromImpu: function (...args) { + console.warn("telephony.sim.getLine1NumberFromImpu interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getMaxSimCount: function () { + console.warn("telephony.sim.getMaxSimCount interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + return paramMock.paramNumberMock; + }, + getIMSI: function (...args) { + console.warn("telephony.sim.getIMSI interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + hasSimCard: function (...args) { + console.warn("telephony.sim.hasSimCard interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + getSimAccountInfo: function (...args) { + console.warn("telephony.sim.getSimAccountInfo interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, IccAccountInfo); + } else { + return new Promise((resolve, reject) => { + resolve(IccAccountInfo); + }) + } + }, + getActiveSimAccountInfoList: function (...args) { + console.warn("telephony.sim.getActiveSimAccountInfoList interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [IccAccountInfo]); + } else { + return new Promise((resolve, reject) => { + resolve([IccAccountInfo]); + }) + } + }, + setDefaultVoiceSlotId: function (...args) { + console.warn("telephony.sim.setDefaultVoiceSlotId interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + activateSim: function (...args) { + console.warn("telephony.sim.activateSim interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + deactivateSim: function (...args) { + console.warn("telephony.sim.deactivateSim interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + setShowName: function (...args) { + console.warn("telephony.sim.setShowName interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getShowName: function (...args) { + console.warn("telephony.sim.getShowName interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + setShowNumber: function (...args) { + console.warn("telephony.sim.setShowNumber interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getShowNumber: function (...args) { + console.warn("telephony.sim.getShowNumber interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getOperatorConfigs: function (...args) { + console.warn("telephony.sim.getOperatorConfigs interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [OperatorConfigMock]); + } else { + return new Promise((resolve, reject) => { + resolve([OperatorConfigMock]); + }) + } + }, + unlockPin: function (...args) { + console.warn("telephony.sim.unlockPin interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, LockStatusResponse); + } else { + return new Promise((resolve, reject) => { + resolve(LockStatusResponse); + }) + } + }, + unlockPuk: function (...args) { + console.warn("telephony.sim.unlockPuk interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, LockStatusResponse); + } else { + return new Promise((resolve, reject) => { + resolve(LockStatusResponse); + }) + } + }, + alterPin: function (...args) { + console.warn("telephony.sim.alterPin interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, LockStatusResponse); + } else { + return new Promise((resolve, reject) => { + resolve(LockStatusResponse); + }) + } + }, + setLockState: function (...args) { + console.warn("telephony.sim.setLockState interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, LockStatusResponse); + } else { + return new Promise((resolve, reject) => { + resolve(LockStatusResponse); + }) + } + }, + unlockPin2: function (...args) { + console.warn("telephony.sim.unlockPin2 interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, LockStatusResponse); + } else { + return new Promise((resolve, reject) => { + resolve(LockStatusResponse); + }) + } + }, + unlockPuk2: function (...args) { + console.warn("telephony.sim.unlockPuk2 interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, LockStatusResponse); + } else { + return new Promise((resolve, reject) => { + resolve(LockStatusResponse); + }) + } + }, + alterPin2: function (...args) { + console.warn("telephony.sim.alterPin2 interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, LockStatusResponse); + } else { + return new Promise((resolve, reject) => { + resolve(LockStatusResponse); + }) + } + }, + queryIccDiallingNumbers: function (...args) { + console.warn("telephony.sim.queryIccDiallingNumbers interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [DiallingNumbersInfo]); + } else { + return new Promise((resolve, reject) => { + resolve([DiallingNumbersInfo]); + }) + } + }, + addIccDiallingNumbers: function (...args) { + console.warn("telephony.sim.addIccDiallingNumbers interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + delIccDiallingNumbers: function (...args) { + console.warn("telephony.sim.delIccDiallingNumbers interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + updateIccDiallingNumbers: function (...args) { + console.warn("telephony.sim.updateIccDiallingNumbers interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + } + } + return sim +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_telephony_sms.js b/runtime/main/extend/systemplugin/napi/ohos_telephony_sms.js new file mode 100644 index 00000000..1d890b48 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_telephony_sms.js @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockSMS() { + const SimShortMessage = { + shortMessage: "[PC Preview] unknow shortMessage", + simMessageStatus: "[PC Preview] unknow simMessageStatus", + indexOnSim: "[PC Preview] unknow indexOnSim" + } + const ShortMessage = { + visibleMessageBody: "[PC Preview] unknow visibleMessageBody", + visibleRawAddress: "[PC Preview] unknow visibleRawAddress", + messageClass: "[PC Preview] unknow messageClass", + protocolId: "[PC Preview] unknow protocolId", + scAddress: "[PC Preview] unknow scAddress", + scTimestamp: "[PC Preview] unknow scTimestamp", + isReplaceMessage: "[PC Preview] unknow isReplaceMessage", + hasReplyPath: "[PC Preview] unknow hasReplyPath", + pdu: ["[PC Preview] unknow pdu"], + status: "[PC Preview] unknow status", + isSmsStatusReportMessage: "[PC Preview] unknow isSmsStatusReportMessage", + emailAddress: "[PC Preview] unknow emailAddress", + emailMessageBody: "[PC Preview] unknow emailMessageBody", + userRawData: ["[PC Preview] unknow userRawData"], + isEmailMessage: "[PC Preview] unknow isEmailMessage", + } + const sms = { + splitMessage: function (...args) { + console.warn("telephony.sms.splitMessage interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paramStringMock]); + } else { + return new Promise((resolve, reject) => { + resolve([paramMock.paramStringMock]); + }) + } + }, + createMessage: function (...args) { + console.warn("telephony.sms.createMessage interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ShortMessage); + } else { + return new Promise((resolve, reject) => { + resolve(ShortMessage); + }) + } + }, + sendMessage: function (...args) { + console.warn("telephony.sms.sendMessage interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + }, + setDefaultSmsSlotId: function (...args) { + console.warn("telephony.sms.setDefaultSmsSlotId interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getDefaultSmsSlotId: function (...args) { + console.warn("telephony.sms.getDefaultSmsSlotId interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + setSmscAddr: function (...args) { + console.warn("telephony.sms.setSmscAddr interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getSmscAddr: function (...args) { + console.warn("telephony.sms.getSmscAddr interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + hasSmsCapability: function () { + console.warn("telephony.sms.hasSmsCapability interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + addSimMessage: function (...args) { + console.warn("telephony.sms.addSimMessage interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + delSimMessage: function (...args) { + console.warn("telephony.sms.delSimMessage interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + updateSimMessage: function (...args) { + console.warn("telephony.sms.updateSimMessage interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getAllSimMessages: function (...args) { + console.warn("telephony.sms.getAllSimMessages interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [SimShortMessage]); + } else { + return new Promise((resolve, reject) => { + resolve([SimShortMessage]); + }) + } + }, + setCBConfig: function (...args) { + console.warn("telephony.sms.setCBConfig interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + } + } + return sms +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/thermal.js b/runtime/main/extend/systemplugin/napi/ohos_thermal.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/thermal.js rename to runtime/main/extend/systemplugin/napi/ohos_thermal.js diff --git a/runtime/main/extend/systemplugin/napi/update.js b/runtime/main/extend/systemplugin/napi/ohos_update.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/update.js rename to runtime/main/extend/systemplugin/napi/ohos_update.js diff --git a/runtime/main/extend/systemplugin/napi/uri.js b/runtime/main/extend/systemplugin/napi/ohos_uri.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/uri.js rename to runtime/main/extend/systemplugin/napi/ohos_uri.js diff --git a/runtime/main/extend/systemplugin/napi/url.js b/runtime/main/extend/systemplugin/napi/ohos_url.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/url.js rename to runtime/main/extend/systemplugin/napi/ohos_url.js diff --git a/runtime/main/extend/systemplugin/napi/usb.js b/runtime/main/extend/systemplugin/napi/ohos_usb.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/usb.js rename to runtime/main/extend/systemplugin/napi/ohos_usb.js diff --git a/runtime/main/extend/systemplugin/napi/userAuth.js b/runtime/main/extend/systemplugin/napi/ohos_userIAM_userAuth.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/userAuth.js rename to runtime/main/extend/systemplugin/napi/ohos_userIAM_userAuth.js diff --git a/runtime/main/extend/systemplugin/napi/util.js b/runtime/main/extend/systemplugin/napi/ohos_util.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/util.js rename to runtime/main/extend/systemplugin/napi/ohos_util.js diff --git a/runtime/main/extend/systemplugin/napi/arraylist.js b/runtime/main/extend/systemplugin/napi/ohos_util_Arraylist.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/arraylist.js rename to runtime/main/extend/systemplugin/napi/ohos_util_Arraylist.js diff --git a/runtime/main/extend/systemplugin/napi/deque.js b/runtime/main/extend/systemplugin/napi/ohos_util_Deque.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/deque.js rename to runtime/main/extend/systemplugin/napi/ohos_util_Deque.js diff --git a/runtime/main/extend/systemplugin/napi/hashmap.js b/runtime/main/extend/systemplugin/napi/ohos_util_HashMap.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/hashmap.js rename to runtime/main/extend/systemplugin/napi/ohos_util_HashMap.js diff --git a/runtime/main/extend/systemplugin/napi/hashset.js b/runtime/main/extend/systemplugin/napi/ohos_util_HashSet.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/hashset.js rename to runtime/main/extend/systemplugin/napi/ohos_util_HashSet.js diff --git a/runtime/main/extend/systemplugin/napi/lightweightmap.js b/runtime/main/extend/systemplugin/napi/ohos_util_LightWeightMap.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/lightweightmap.js rename to runtime/main/extend/systemplugin/napi/ohos_util_LightWeightMap.js diff --git a/runtime/main/extend/systemplugin/napi/lightweightset.js b/runtime/main/extend/systemplugin/napi/ohos_util_LightWeightSet.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/lightweightset.js rename to runtime/main/extend/systemplugin/napi/ohos_util_LightWeightSet.js diff --git a/runtime/main/extend/systemplugin/napi/linkedlist.js b/runtime/main/extend/systemplugin/napi/ohos_util_LinkedList.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/linkedlist.js rename to runtime/main/extend/systemplugin/napi/ohos_util_LinkedList.js diff --git a/runtime/main/extend/systemplugin/napi/list.js b/runtime/main/extend/systemplugin/napi/ohos_util_List.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/list.js rename to runtime/main/extend/systemplugin/napi/ohos_util_List.js diff --git a/runtime/main/extend/systemplugin/napi/plainarray.js b/runtime/main/extend/systemplugin/napi/ohos_util_PlainArray.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/plainarray.js rename to runtime/main/extend/systemplugin/napi/ohos_util_PlainArray.js diff --git a/runtime/main/extend/systemplugin/napi/queue.js b/runtime/main/extend/systemplugin/napi/ohos_util_Queue.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/queue.js rename to runtime/main/extend/systemplugin/napi/ohos_util_Queue.js diff --git a/runtime/main/extend/systemplugin/napi/stack.js b/runtime/main/extend/systemplugin/napi/ohos_util_Stack.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/stack.js rename to runtime/main/extend/systemplugin/napi/ohos_util_Stack.js diff --git a/runtime/main/extend/systemplugin/napi/treemap.js b/runtime/main/extend/systemplugin/napi/ohos_util_TreeMap.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/treemap.js rename to runtime/main/extend/systemplugin/napi/ohos_util_TreeMap.js diff --git a/runtime/main/extend/systemplugin/napi/treeset.js b/runtime/main/extend/systemplugin/napi/ohos_util_TreeSet.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/treeset.js rename to runtime/main/extend/systemplugin/napi/ohos_util_TreeSet.js diff --git a/runtime/main/extend/systemplugin/napi/vector.js b/runtime/main/extend/systemplugin/napi/ohos_util_Vector.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/vector.js rename to runtime/main/extend/systemplugin/napi/ohos_util_Vector.js diff --git a/runtime/main/extend/systemplugin/napi/vibrator.js b/runtime/main/extend/systemplugin/napi/ohos_vibrator.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/vibrator.js rename to runtime/main/extend/systemplugin/napi/ohos_vibrator.js diff --git a/runtime/main/extend/systemplugin/napi/volumeManager.js b/runtime/main/extend/systemplugin/napi/ohos_volumeManager.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/volumeManager.js rename to runtime/main/extend/systemplugin/napi/ohos_volumeManager.js diff --git a/runtime/main/extend/systemplugin/ohos/wallpaper.js b/runtime/main/extend/systemplugin/napi/ohos_wallpaper.js similarity index 94% rename from runtime/main/extend/systemplugin/ohos/wallpaper.js rename to runtime/main/extend/systemplugin/napi/ohos_wallpaper.js index a291597a..3a8e0a14 100644 --- a/runtime/main/extend/systemplugin/ohos/wallpaper.js +++ b/runtime/main/extend/systemplugin/napi/ohos_wallpaper.js @@ -17,7 +17,7 @@ import { paramMock } from "../utils" import { PixelMapMock } from "../multimedia" export function mockWallpaper() { - global.ohosplugin.wallpaper = { + const wallpaper = { WallpaperType: { WALLPAPER_SYSTEM: '[PC preview] unknow WALLPAPER_SYSTEM', WALLPAPER_LOCKSCREEN: '[PC preview] unknow WALLPAPER_LOCKSCREEN' @@ -152,7 +152,7 @@ export function mockWallpaper() { if (args[0] == 'colorChange') { let colors = new Array(); colors.push(RgbaColorMock); - args[len - 1].call(this, colors, global.ohosplugin.wallpaper.WallpaperType.WALLPAPER_SYSTEM); + args[len - 1].call(this, colors, wallpaper.WallpaperType.WALLPAPER_SYSTEM); } } }, @@ -164,7 +164,7 @@ export function mockWallpaper() { if (args[0] == 'colorChange') { let colors = new Array(); colors.push(RgbaColorMock); - args[len - 1].call(this, colors, global.ohosplugin.wallpaper.WallpaperType.WALLPAPER_SYSTEM); + args[len - 1].call(this, colors, wallpaper.WallpaperType.WALLPAPER_SYSTEM); } } } @@ -175,4 +175,5 @@ export function mockWallpaper() { blue: '[PC preview] unknow blue', alpha: '[PC preview] unknow alpha' } + return wallpaper } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/ohos/wantAgent.js b/runtime/main/extend/systemplugin/napi/ohos_wantAgent.js similarity index 96% rename from runtime/main/extend/systemplugin/ohos/wantAgent.js rename to runtime/main/extend/systemplugin/napi/ohos_wantAgent.js index e3a9b6d0..25072ba4 100644 --- a/runtime/main/extend/systemplugin/ohos/wantAgent.js +++ b/runtime/main/extend/systemplugin/napi/ohos_wantAgent.js @@ -35,7 +35,7 @@ export function mockWantAgent() { extraInfo: '[PC preview] unknow extraInfo', } const WantAgentMock = {} - global.ohosplugin.wantAgent = { + const wantAgent = { OperationType: { UNKNOWN_TYPE: 0, START_ABILITY: 1, @@ -136,5 +136,5 @@ export function mockWantAgent() { } }, } - + return wantAgent } diff --git a/runtime/main/extend/systemplugin/napi/wifi.js b/runtime/main/extend/systemplugin/napi/ohos_wifi.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/wifi.js rename to runtime/main/extend/systemplugin/napi/ohos_wifi.js diff --git a/runtime/main/extend/systemplugin/window.js b/runtime/main/extend/systemplugin/napi/ohos_window.js similarity index 94% rename from runtime/main/extend/systemplugin/window.js rename to runtime/main/extend/systemplugin/napi/ohos_window.js index 7a9446f1..830c6544 100644 --- a/runtime/main/extend/systemplugin/window.js +++ b/runtime/main/extend/systemplugin/napi/ohos_window.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import { paramMock } from "./utils" +import { paramMock } from "../utils" export const windowPropertiesMock = { windowRect: '[PC preview] unknow windowRect', @@ -381,7 +381,7 @@ export function mockWindow() { primaryBounds: RectMock, secondaryBounds: RectMock, } - global.systemplugin.window = { + const window = { getTopWindow: function (...args) { console.warn("window.getTopWindow interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") @@ -466,18 +466,6 @@ export function mockWindow() { }) } }, - ToggleShownStateForAllAppWindows: function (...args) { - console.warn("window.ToggleShownStateForAllAppWindows interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve, reject) => { - resolve() - }) - } - }, AvoidAreaType: { TYPE_SYSTEM: 0, TYPE_CUTOUT: 1, @@ -498,4 +486,5 @@ export function mockWindow() { WIDE_GAMUT: 1 }, } + return window } diff --git a/runtime/main/extend/systemplugin/napi/workScheduler.js b/runtime/main/extend/systemplugin/napi/ohos_workScheduler.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/workScheduler.js rename to runtime/main/extend/systemplugin/napi/ohos_workScheduler.js diff --git a/runtime/main/extend/systemplugin/napi/worker.js b/runtime/main/extend/systemplugin/napi/ohos_worker.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/worker.js rename to runtime/main/extend/systemplugin/napi/ohos_worker.js diff --git a/runtime/main/extend/systemplugin/napi/xml.js b/runtime/main/extend/systemplugin/napi/ohos_xml.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/xml.js rename to runtime/main/extend/systemplugin/napi/ohos_xml.js diff --git a/runtime/main/extend/systemplugin/napi/zlib.js b/runtime/main/extend/systemplugin/napi/ohos_zlib.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/zlib.js rename to runtime/main/extend/systemplugin/napi/ohos_zlib.js diff --git a/runtime/main/extend/systemplugin/cipher.js b/runtime/main/extend/systemplugin/napi/system_cipher.js similarity index 92% rename from runtime/main/extend/systemplugin/cipher.js rename to runtime/main/extend/systemplugin/napi/system_cipher.js index 6af56eb3..f335b561 100644 --- a/runtime/main/extend/systemplugin/cipher.js +++ b/runtime/main/extend/systemplugin/napi/system_cipher.js @@ -13,10 +13,10 @@ * limitations under the License. */ -import { hasComplete } from "./utils" +import { hasComplete } from "../utils" export function mockCipher() { - global.systemplugin.cipher = { + const cipher = { rsa: function (...args) { console.warn("cipher.rsa interface mocked in the Previewer. How this interface works on the Previewer may be" + " different from that on a real device.") @@ -32,4 +32,5 @@ export function mockCipher() { hasComplete(args[0].complete) } } + return cipher } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/file.js b/runtime/main/extend/systemplugin/napi/system_file.js similarity index 96% rename from runtime/main/extend/systemplugin/file.js rename to runtime/main/extend/systemplugin/napi/system_file.js index d49592a5..a89f98cc 100644 --- a/runtime/main/extend/systemplugin/file.js +++ b/runtime/main/extend/systemplugin/napi/system_file.js @@ -13,10 +13,10 @@ * limitations under the License. */ -import { hasComplete } from "./utils" +import { hasComplete } from "../utils" export function mockFile() { - global.systemplugin.file = { + const file = { move: function (...args) { console.warn("file.move interface mocked in the Previewer. How this interface works on the Previewer may be" + " different from that on a real device.") @@ -107,4 +107,5 @@ export function mockFile() { hasComplete(args[0].complete) } } + return file } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/storage.js b/runtime/main/extend/systemplugin/napi/system_storage.js similarity index 100% rename from runtime/main/extend/systemplugin/napi/storage.js rename to runtime/main/extend/systemplugin/napi/system_storage.js diff --git a/runtime/main/extend/systemplugin/resourceManager.js b/runtime/main/extend/systemplugin/resourceManager.js deleted file mode 100644 index d6614b94..00000000 --- a/runtime/main/extend/systemplugin/resourceManager.js +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export function mockResourceManager() { -function Configuration(direction, locale) { - this.direction = direction; - this.locale = locale; -} - -function DeviceCapability(screenDensity, deviceType) { - this.screenDensity = screenDensity; - this.deviceType = deviceType; -} - -function ResourceManager(mgrId, module) { - var resMgrId = mgrId; - var resourcemgrModuleGroup = module; - - this.getString = getString; - async function getString(resId, callback) { - var data = "mock string"; - console.warn("ResourceManager.getString interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - if (typeof callback === 'function') { - callback.call(this, null, data); - } else { - return new Promise((resolve) => { - resolve(data); - }) - } - } - - this.getStringArray = getStringArray; - async function getStringArray(resId, callback) { - var data = [ "mock string1", "mock string2"]; - console.warn("ResourceManager.getStringArray interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - if (typeof callback === 'function') { - callback.call(this, null, data); - } else { - return new Promise((resolve) => { - resolve(data); - }) - } - } - - this.getMedia = getMedia; - async function getMedia(resId, callback) { - var data = "mock media data"; - console.warn("ResourceManager.getMedia interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - if (typeof callback === 'function') { - callback.call(this, 1, data); - } else { - return new Promise((resolve, reject) => { - reject(data); - }) - } - } - - this.getMediaBase64 = getMediaBase64; - async function getMediaBase64(resId, callback) { - var data = "mock media data"; - console.warn("ResourceManager.getMediaBase64 interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - if (typeof callback === 'function') { - callback.call(this, 1, data); - } else { - return new Promise((resolve, reject) => { - reject(data); - }) - } - } - - this.getPluralString = getPluralString; - async function getPluralString(resId, num, callback) { - var data = "mock plural string"; - console.warn("ResourceManager.getPluralString interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - if (typeof callback === 'function') { - callback.call(this, null, data); - } else { - return new Promise((resolve) => { - resolve(data); - }) - } - } - - this.getConfiguration = getConfiguration; - async function getConfiguration(callback) { - var data = {"direction" : 0, "locale" : "zh_CN"}; - console.warn("ResourceManager.getConfiguration interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - if (typeof callback === 'function') { - callback.call(this, null, data); - } else { - return new Promise((resolve) => { - resolve(data); - }) - } - } - - this.getDeviceCapability = getDeviceCapability; - async function getDeviceCapability(callback) { - var data = {"deviceType" : 0, "screenDensity" : 480 }; - console.warn("ResourceManager.getDeviceCapability interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - if (typeof callback === 'function') { - callback.call(this, null, data); - } else { - return new Promise((resolve) => { - resolve(data); - }) - } - } - - this.release = release; - async function release(callback) { - console.warn("ResourceManager.release interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - } - - this.getRawFile = getRawFile; - async function getRawFile(path, callback) { - var data = "mock raw file"; - console.warn("ResourceManager.getRawFile interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - if (typeof callback === 'function') { - callback.call(this, null, data); - } else { - return new Promise((resolve) => { - resolve(data); - }) - } - } - - this.getRawFileDescriptor = getRawFileDescriptor; - async function getRawFileDescriptor(path, callback) { - var data = "mock raw file descriptor"; - console.warn("ResourceManager.getRawFileDescriptor interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - if (typeof callback === 'function') { - callback.call(this, null, data); - } else { - return new Promise((resolve) => { - resolve(data); - }) - } - } - - this.closeRawFileDescriptor = closeRawFileDescriptor; - async function closeRawFileDescriptor(path, callback) { - var data = "mock close raw file descriptor"; - console.warn("ResourceManager.closeRawFileDescriptor interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - if (typeof callback === 'function') { - callback.call(this, null, data); - } else { - return new Promise((resolve) => { - resolve(data); - }) - } - } -} - -var resourceManager = { - getResourceManager: async function getResourceManager(optBundleName, optCallback) { - let bundleName = ''; - let callback; - if (typeof optCallback == 'function') { - bundleName = optBundleName ? optBundleName : ''; - callback = optCallback; - } else if (typeof optBundleName == 'function') { - callback = optBundleName; - } else { - bundleName = optBundleName ? optBundleName : ''; - } - let data = new ResourceManager(1, null); - console.warn("ResourceManager.getResourceManager interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - if (typeof callback === 'function') { - callback.call(this, 1, data); - } else { - return new Promise((resolve) => { - resolve(data); - }) - } - } -}; - -global.systemplugin.resourceManager = { - getResourceManager: resourceManager.getResourceManager -}; -} diff --git a/runtime/main/extend/systemplugin/telephony.js b/runtime/main/extend/systemplugin/telephony.js deleted file mode 100644 index e8993071..00000000 --- a/runtime/main/extend/systemplugin/telephony.js +++ /dev/null @@ -1,1756 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { paramMock } from "./utils" - -const CallState = "[PC Preview] unknow CallState"; -export function mockCall() { - const CallWaitingStatus = "[PC Preview] unknow CallWaitingStatus"; - const RestrictionStatus = "[PC Preview] unknow RestrictionStatus"; - const CallAttributeOptions = { - accountNumber: "[PC Preview] unknow accountNumber", - speakerphoneOn: "[PC Preview] unknow speakerphoneOn", - accountId: "[PC Preview] unknow accountId", - videoState: "[PC Preview] unknow videoState", - startTime: "[PC Preview] unknow startTime", - isEcc: "[PC Preview] unknow isEcc", - callType: "[PC Preview] unknow callType", - callId: "[PC Preview] unknow callId", - callState: "[PC Preview] unknow callState", - conferenceState: "[PC Preview] unknow conferenceState" - } - const CallTransferResult = { - status: "[PC Preview] unknow status", - number: "[PC Preview] unknow number", - } - global.systemplugin.telephony = global.systemplugin.telephony || {} - global.systemplugin.telephony.call = { - dial: function (...args) { - console.warn("telephony.call.dial interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - makeCall: function (...args) { - console.warn("telephony.call.makeCall interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - hasCall: function (...args) { - console.warn("telephony.call.hasCall interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - getCallState: function (...args) { - console.warn("telephony.call.getCallState interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, CallState); - } else { - return new Promise((resolve, reject) => { - resolve(CallState); - }) - } - }, - displayCallScreen: function (...args) { - console.warn("telephony.call.displayCallScreen interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - muteRinger: function (...args) { - console.warn("telephony.call.muteRinger interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - hasVoiceCapability: function () { - console.warn("telephony.call.hasVoiceCapability interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - isVideoCallingEnabled: function (...args) { - console.warn("telephony.call.isVideoCallingEnabled interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - inputDialerSpecialCode: function (...args) { - console.warn("telephony.call.inputDialerSpecialCode interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - isHacEnabled: function (...args) { - console.warn("telephony.call.isHacEnabled interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - isEmergencyPhoneNumber: function (...args) { - console.warn("telephony.call.isEmergencyPhoneNumber interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - formatPhoneNumber: function (...args) { - console.warn("telephony.call.formatPhoneNumber interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - formatPhoneNumberToE164: function (...args) { - console.warn("telephony.call.formatPhoneNumberToE164 interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - comparePhoneNumbers: function (...args) { - console.warn("telephony.call.comparePhoneNumbers interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - getCallerIndex: function (...args) { - console.warn("telephony.call.getCallerIndex interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - getCountryCodeFromDbNumber: function (...args) { - console.warn("telephony.call.getCountryCodeFromDbNumber interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getIntlPrefixAndCountryCodeLen: function (...args) { - console.warn("telephony.call.getIntlPrefixAndCountryCodeLen interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - answer: function (...args) { - console.warn("telephony.call.answer interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - hangup: function (...args) { - console.warn("telephony.call.hangup interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - reject: function (...args) { - console.warn("telephony.call.reject interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - holdCall: function (...args) { - console.warn("telephony.call.holdCall interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - unHoldCall: function (...args) { - console.warn("telephony.call.unHoldCall interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - switchCall: function (...args) { - console.warn("telephony.call.switchCall interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - combineConference: function (...args) { - console.warn("telephony.call.combineConference interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getMainCallId: function (...args) { - console.warn("telephony.call.getMainCallId interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - getSubCallIdList: function (...args) { - console.warn("telephony.call.getSubCallIdList interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramArrayMock); - }) - } - }, - getCallIdListForConference: function (...args) { - console.warn("telephony.call.getCallIdListForConference interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramArrayMock); - }) - } - }, - getCallWaitingStatus: function (...args) { - console.warn("telephony.call.getCallWaitingStatus interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, CallWaitingStatus); - } else { - return new Promise((resolve, reject) => { - resolve(CallWaitingStatus); - }) - } - }, - setCallWaiting: function (...args) { - console.warn("telephony.call.setCallWaiting interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - startDTMF: function (...args) { - console.warn("telephony.call.startDTMF interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - stopDTMF: function (...args) { - console.warn("telephony.call.stopDTMF interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - isInEmergencyCall: function (...args) { - console.warn("telephony.call.isInEmergencyCall interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - on: function (...args) { - console.warn("telephony.call.on interface mocked in the Previewer. How this interface works on the Previewer may " + - "be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - if (args[0] == 'callDetailsChange') { - args[len - 1].call(this, CallAttributeOptions); - } else if (args[0] == 'callEventChange') { - args[len - 1].call(this, paramMock.paramObjectMock); - } - } - }, - off: function (...args) { - console.warn("telephony.call.off interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - if (args[0] == 'callDetailsChange') { - args[len - 1].call(this, CallAttributeOptions); - } else if (args[0] == 'callEventChange') { - args[len - 1].call(this, paramMock.paramObjectMock); - } - } - }, - isNewCallAllowed: function (...args) { - console.warn("telephony.call.isNewCallAllowed interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - separateConference: function (...args) { - console.warn("telephony.call.separateConference interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getCallRestrictionStatus: function (...args) { - console.warn("telephony.call.getCallRestrictionStatus interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, RestrictionStatus); - } else { - return new Promise((resolve, reject) => { - resolve(RestrictionStatus); - }) - } - }, - setCallRestriction: function (...args) { - console.warn("telephony.call.setCallRestriction interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - setCallTransfer: function (...args) { - console.warn("telephony.call.setCallTransfer interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getCallTransferInfo: function (...args) { - console.warn("telephony.call.getCallTransferInfo interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, CallTransferResult); - } else { - return new Promise((resolve, reject) => { - resolve(CallTransferResult); - }) - } - }, - setCallTransferInfo: function (...args) { - console.warn("telephony.call.setCallTransferInfo interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - isRinging: function (...args) { - console.warn("telephony.call.isRinging interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - setMuted: function (...args) { - console.warn("telephony.call.setMuted interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - setAudioDevice: function (...args) { - console.warn("telephony.call.setAudioDevice interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - } - } -} -export function mockData() { - global.systemplugin.telephony.data = { - getDefaultCellularDataSlotId: function (...args) { - console.warn("telephony.data.getDefaultCellularDataSlotId interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - setDefaultCellularDataSlotId: function (...args) { - console.warn("telephony.data.setDefaultCellularDataSlotId interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getCellularDataFlowType: function (...args) { - console.warn("telephony.data.getCellularDataFlowType interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - getCellularDataState: function (...args) { - console.warn("telephony.data.getCellularDataState interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - isCellularDataEnabled: function (...args) { - console.warn("telephony.data.isCellularDataEnabled interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - enableCellularData: function (...args) { - console.warn("telephony.data.enableCellularData interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - disableCellularData: function (...args) { - console.warn("telephony.data.disableCellularData interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - isCellularDataRoamingEnabled: function (...args) { - console.warn("telephony.data.isCellularDataRoamingEnabled interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - enableCellularDataRoaming: function (...args) { - console.warn("telephony.data.enableCellularDataRoaming interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - disableCellularDataRoaming: function (...args) { - console.warn("telephony.data.disableCellularDataRoaming interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - } - } -} -const NetworkState = { - longOperatorName: "[PC Preview] unknow longOperatorName", - shortOperatorName: "[PC Preview] unknow shortOperatorName", - plmnNumeric: "[PC Preview] unknow plmnNumeric", - isRoaming: "[PC Preview] unknow isRoaming", - regState: "[PC Preview] unknow regState", - nsaState: "[PC Preview] unknow nsaState", - isCaActive: "[PC Preview] unknow isCaActive", - isEmergency: "[PC Preview] unknow isEmergency", -} -const SignalInformation = { - signalType: "[PC Preview] unknow signalType", - signalLevel: "[PC Preview] unknow signalLevel" -} -const DataFlowType = "[PC Preview] unknow DataFlowType" -const DataConnectState = "[PC Preview] unknow DataConnectState" -const CellInformation = { - networkType: "[PC Preview] unknow networkType", - isCamped: "[PC Preview] unknow isCamped", - timeStamp: "[PC Preview] unknow timeStamp", - signalInformation: "[PC Preview] unknow signalInformation", - data: "[PC Preview] unknow unkown data" -} -export function mockRadio() { - const NetworkSearchResult = { - isNetworkSearchSuccess: "[PC Preview] unknow isNetworkSearchSuccess", - networkSearchResult: [{ - operatorName: "[PC Preview] unknow operatorName", - operatorNumeric: "[PC Preview] unknow operatorNumeric", - state: "[PC Preview] unknow state", - radioTech: "[PC Preview] unknow radioTech" - }] - } - const PreferredNetworkMode = "[PC Preview] unknow PreferredNetworkMode" - const NrOptionMode = "[PC Preview] unknow NrOptionMode" - const NetworkSelectionMode = "[PC Preview] unknow unkown NetworkSelectionMode" - global.systemplugin.telephony.radio = { - getRadioTech: function (...args) { - console.warn("telephony.radio.getRadioTech interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, { - psRadioTech: "[PC Preview] unknow psRadioTech", - csRadioTech: "[PC Preview] unknow csRadioTech" - }); - } else { - return new Promise((resolve, reject) => { - resolve({ - psRadioTech: "[PC Preview] unknow psRadioTech", - csRadioTech: "[PC Preview] unknow csRadioTech" - }); - }) - } - }, - getNetworkState: function (...args) { - console.warn("telephony.radio.getNetworkState interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, NetworkState); - } else { - return new Promise((resolve, reject) => { - resolve(NetworkState); - }) - } - }, - sendUpdateCellLocationRequest: function (...args) { - console.warn("telephony.radio.sendUpdateCellLocationRequest interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getCellInformation: function (...args) { - console.warn("telephony.radio.getCellInformation interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, [CellInformation]); - } else { - return new Promise((resolve, reject) => { - resolve([CellInformation]); - }) - } - }, - getNetworkSelectionMode: function (...args) { - console.warn("telephony.radio.getNetworkSelectionMode interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, NetworkSelectionMode); - } else { - return new Promise((resolve, reject) => { - resolve(NetworkSelectionMode); - }) - } - }, - setNetworkSelectionMode: function (...args) { - console.warn("telephony.radio.setNetworkSelectionMode interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getNetworkSearchInformation: function (...args) { - console.warn("telephony.radio.getNetworkSearchInformation interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, NetworkSearchResult); - } else { - return new Promise((resolve, reject) => { - resolve(NetworkSearchResult); - }) - } - }, - getISOCountryCodeForNetwork: function (...args) { - console.warn("telephony.radio.getISOCountryCodeForNetwork interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getNrOptionMode: function (...args) { - console.warn("telephony.radio.getNrOptionMode interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, NrOptionMode); - } else { - return new Promise((resolve, reject) => { - resolve(NrOptionMode); - }) - } - }, - getIMEI: function (...args) { - console.warn("telephony.radio.getIMEI interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getMEID: function (...args) { - console.warn("telephony.radio.getMEID interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getUniqueDeviceId: function (...args) { - console.warn("telephony.radio.getUniqueDeviceId interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getPrimarySlotId: function (...args) { - console.warn("telephony.radio.getPrimarySlotId interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - getSignalInformation: function (...args) { - console.warn("telephony.radio.getSignalInformation interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, [SignalInformation]); - } else { - return new Promise((resolve, reject) => { - resolve([SignalInformation]); - }) - } - }, - isNrSupported: function () { - console.warn("telephony.radio.isNrSupported interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - isRadioOn: function (...args) { - console.warn("telephony.radio.isRadioOn interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - turnOnRadio: function (...args) { - console.warn("telephony.radio.turnOnRadio interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - turnOffRadio: function (...args) { - console.warn("telephony.radio.turnOffRadio interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getOperatorName: function (...args) { - console.warn("telephony.radio.getOperatorName interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - setPreferredNetwork: function (...args) { - console.warn("telephony.radio.setPreferredNetwork interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getPreferredNetwork: function (...args) { - console.warn("telephony.radio.getPreferredNetwork interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, PreferredNetworkMode); - } else { - return new Promise((resolve, reject) => { - resolve(PreferredNetworkMode); - }) - } - }, - getIMEISV: function (...args) { - console.warn("telephony.radio.getIMEISV interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - } - } -} -export function mockSim() { - const IccAccountInfo = { - simId: "[PC Preview] unknow simId", - slotIndex: "[PC Preview] unknow slotIndex", - isEsim: "[PC Preview] unknow isEsim", - isActive: "[PC Preview] unknow isActive", - iccId: "[PC Preview] unknow iccId", - showName: "[PC Preview] unknow showName", - showNumber: "[PC Preview] unknow showNumber" - } - const OperatorConfigMock = { - field: "[PC Preview] unknow field", - value: "[PC Preview] unknow value" - } - const LockStatusResponse = { - result: "[PC Preview] unknow result", - remain: "[PC Preview] unknow remain" - } - const DiallingNumbersInfo = { - efid: "[PC Preview] unknow efid", - recordNumber: "[PC Preview] unknow recordNumber", - alphaTag: "[PC Preview] unknow alphaTag", - number: "[PC Preview] unknow number", - emails: "[PC Preview] unknow emails" - } - const CardType = "[PC Preview] unknow CardType"; - const SimState = "[PC Preview] unknow SimState"; - global.systemplugin.telephony.sim = { - isSimActive: function (...args) { - console.warn("telephony.sim.isSimActive interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - getDefaultVoiceSlotId: function (...args) { - console.warn("telephony.sim.getDefaultVoiceSlotId interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - hasOperatorPrivileges: function (...args) { - console.warn("telephony.sim.hasOperatorPrivileges interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - getISOCountryCodeForSim: function (...args) { - console.warn("telephony.sim.getISOCountryCodeForSim interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getSimOperatorNumeric: function (...args) { - console.warn("telephony.sim.getSimOperatorNumeric interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getSimSpn: function (...args) { - console.warn("telephony.sim.getSimSpn interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getSimState: function (...args) { - console.warn("telephony.sim.getSimState interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, SimState); - } else { - return new Promise((resolve, reject) => { - resolve(SimState); - }) - } - }, - getCardType: function (...args) { - console.warn("telephony.sim.getCardType interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, CardType); - } else { - return new Promise((resolve, reject) => { - resolve(CardType); - }) - } - }, - getSimIccId: function (...args) { - console.warn("telephony.sim.getSimIccId interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getVoiceMailIdentifier: function (...args) { - console.warn("telephony.sim.getVoiceMailIdentifier interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getVoiceMailNumber: function (...args) { - console.warn("telephony.sim.getVoiceMailNumber interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getVoiceMailCount: function (...args) { - console.warn("telephony.sim.getVoiceMailCount interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - getSimTelephoneNumber: function (...args) { - console.warn("telephony.sim.getSimTelephoneNumber interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getSimGid1: function (...args) { - console.warn("telephony.sim.getSimGid1 interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getSimTeleNumberIdentifier: function (...args) { - console.warn("telephony.sim.getSimTeleNumberIdentifier interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getLine1NumberFromImpu: function (...args) { - console.warn("telephony.sim.getLine1NumberFromImpu interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getMaxSimCount: function () { - console.warn("telephony.sim.getMaxSimCount interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - return paramMock.paramNumberMock; - }, - getIMSI: function (...args) { - console.warn("telephony.sim.getIMSI interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - hasSimCard: function (...args) { - console.warn("telephony.sim.hasSimCard interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - getSimAccountInfo: function (...args) { - console.warn("telephony.sim.getSimAccountInfo interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, IccAccountInfo); - } else { - return new Promise((resolve, reject) => { - resolve(IccAccountInfo); - }) - } - }, - getActiveSimAccountInfoList: function (...args) { - console.warn("telephony.sim.getActiveSimAccountInfoList interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, [IccAccountInfo]); - } else { - return new Promise((resolve, reject) => { - resolve([IccAccountInfo]); - }) - } - }, - setDefaultVoiceSlotId: function (...args) { - console.warn("telephony.sim.setDefaultVoiceSlotId interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - activateSim: function (...args) { - console.warn("telephony.sim.activateSim interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - deactivateSim: function (...args) { - console.warn("telephony.sim.deactivateSim interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - setShowName: function (...args) { - console.warn("telephony.sim.setShowName interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getShowName: function (...args) { - console.warn("telephony.sim.getShowName interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - setShowNumber: function (...args) { - console.warn("telephony.sim.setShowNumber interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getShowNumber: function (...args) { - console.warn("telephony.sim.getShowNumber interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - getOperatorConfigs: function (...args) { - console.warn("telephony.sim.getOperatorConfigs interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, [OperatorConfigMock]); - } else { - return new Promise((resolve, reject) => { - resolve([OperatorConfigMock]); - }) - } - }, - unlockPin: function (...args) { - console.warn("telephony.sim.unlockPin interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, LockStatusResponse); - } else { - return new Promise((resolve, reject) => { - resolve(LockStatusResponse); - }) - } - }, - unlockPuk: function (...args) { - console.warn("telephony.sim.unlockPuk interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, LockStatusResponse); - } else { - return new Promise((resolve, reject) => { - resolve(LockStatusResponse); - }) - } - }, - alterPin: function (...args) { - console.warn("telephony.sim.alterPin interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, LockStatusResponse); - } else { - return new Promise((resolve, reject) => { - resolve(LockStatusResponse); - }) - } - }, - setLockState: function (...args) { - console.warn("telephony.sim.setLockState interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, LockStatusResponse); - } else { - return new Promise((resolve, reject) => { - resolve(LockStatusResponse); - }) - } - }, - unlockPin2: function (...args) { - console.warn("telephony.sim.unlockPin2 interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, LockStatusResponse); - } else { - return new Promise((resolve, reject) => { - resolve(LockStatusResponse); - }) - } - }, - unlockPuk2: function (...args) { - console.warn("telephony.sim.unlockPuk2 interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, LockStatusResponse); - } else { - return new Promise((resolve, reject) => { - resolve(LockStatusResponse); - }) - } - }, - alterPin2: function (...args) { - console.warn("telephony.sim.alterPin2 interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, LockStatusResponse); - } else { - return new Promise((resolve, reject) => { - resolve(LockStatusResponse); - }) - } - }, - queryIccDiallingNumbers: function (...args) { - console.warn("telephony.sim.queryIccDiallingNumbers interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, [DiallingNumbersInfo]); - } else { - return new Promise((resolve, reject) => { - resolve([DiallingNumbersInfo]); - }) - } - }, - addIccDiallingNumbers: function (...args) { - console.warn("telephony.sim.addIccDiallingNumbers interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - delIccDiallingNumbers: function (...args) { - console.warn("telephony.sim.delIccDiallingNumbers interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - updateIccDiallingNumbers: function (...args) { - console.warn("telephony.sim.updateIccDiallingNumbers interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - } - } -} -export function mockSMS() { - const SimShortMessage = { - shortMessage: "[PC Preview] unknow shortMessage", - simMessageStatus: "[PC Preview] unknow simMessageStatus", - indexOnSim: "[PC Preview] unknow indexOnSim" - } - const ShortMessage = { - visibleMessageBody: "[PC Preview] unknow visibleMessageBody", - visibleRawAddress: "[PC Preview] unknow visibleRawAddress", - messageClass: "[PC Preview] unknow messageClass", - protocolId: "[PC Preview] unknow protocolId", - scAddress: "[PC Preview] unknow scAddress", - scTimestamp: "[PC Preview] unknow scTimestamp", - isReplaceMessage: "[PC Preview] unknow isReplaceMessage", - hasReplyPath: "[PC Preview] unknow hasReplyPath", - pdu: ["[PC Preview] unknow pdu"], - status: "[PC Preview] unknow status", - isSmsStatusReportMessage: "[PC Preview] unknow isSmsStatusReportMessage", - emailAddress: "[PC Preview] unknow emailAddress", - emailMessageBody: "[PC Preview] unknow emailMessageBody", - userRawData: ["[PC Preview] unknow userRawData"], - isEmailMessage: "[PC Preview] unknow isEmailMessage", - } - global.systemplugin.telephony.sms = { - splitMessage: function (...args) { - console.warn("telephony.sms.splitMessage interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paramStringMock]); - } else { - return new Promise((resolve, reject) => { - resolve([paramMock.paramStringMock]); - }) - } - }, - createMessage: function (...args) { - console.warn("telephony.sms.createMessage interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, ShortMessage); - } else { - return new Promise((resolve, reject) => { - resolve(ShortMessage); - }) - } - }, - sendMessage: function (...args) { - console.warn("telephony.sms.sendMessage interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - }, - setDefaultSmsSlotId: function (...args) { - console.warn("telephony.sms.setDefaultSmsSlotId interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getDefaultSmsSlotId: function (...args) { - console.warn("telephony.sms.getDefaultSmsSlotId interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }) - } - }, - setSmscAddr: function (...args) { - console.warn("telephony.sms.setSmscAddr interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getSmscAddr: function (...args) { - console.warn("telephony.sms.getSmscAddr interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramStringMock); - }) - } - }, - hasSmsCapability: function () { - console.warn("telephony.sms.hasSmsCapability interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - return paramMock.paramBooleanMock; - }, - addSimMessage: function (...args) { - console.warn("telephony.sms.addSimMessage interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - delSimMessage: function (...args) { - console.warn("telephony.sms.delSimMessage interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - updateSimMessage: function (...args) { - console.warn("telephony.sms.updateSimMessage interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - getAllSimMessages: function (...args) { - console.warn("telephony.sms.getAllSimMessages interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, [SimShortMessage]); - } else { - return new Promise((resolve, reject) => { - resolve([SimShortMessage]); - }) - } - }, - setCBConfig: function (...args) { - console.warn("telephony.sms.setCBConfig interface mocked in the Previewer. How this interface works on the Previewer may" + - " be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - } - } -} -export function mockObserver() { - const SimStateData = { - type: "[PC Preview] unknow type", - state: "[PC Preview] unknow state", - } - global.systemplugin.telephony.observer = { - on: function (...args) { - console.warn("telephony.observer.on interface mocked in the Previewer. How this interface works on the Previewer may " + - "be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - if (args[0] === 'networkStateChange') { - args[len - 1].call(this, NetworkState); - } else if (args[0] === 'signalInfoChange') { - args[len - 1].call(this, [SignalInformation]); - } else if (args[0] === 'cellInfoChange') { - args[len - 1].call(this, [CellInformation]); - } else if (args[0] === 'cellularDataConnectionStateChange') { - args[len - 1].call(this, paramMock.businessErrorMock, { - state: "[PC Preview] unknow state", - network: "[PC Preview] unknow network" - }); - } else if (args[0] === 'cellularDataFlowChange') { - args[len - 1].call(this, DataFlowType); - } else if (args[0] === 'callStateChange') { - args[len - 1].call(this, paramMock.businessErrorMock, { - state: "[PC Preview] unknow state", - number: "[PC Preview] unknow number" - }); - } else if (args[0] === 'cfuIndicatorChange' || 'voiceMailMsgIndicatorChange') { - args[len - 1].call(this, paramMock.paramBooleanMock); - } else if (args[0] === 'simStateChange') { - args[len - 1].call(this, SimStateData); - } - } - }, - off: function (...args) { - console.warn("telephony.observer.off interface mocked in the Previewer. How this interface works on the Previewer may " + - "be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - if (args[0] === 'networkStateChange') { - args[len - 1].call(this, NetworkState); - } else if (args[0] === 'signalInfoChange') { - args[len - 1].call(this, [SignalInformation]); - } else if (args[0] === 'cellInfoChange') { - args[len - 1].call(this, [CellInformation]); - } else if (args[0] === 'cellularDataConnectionStateChange') { - args[len - 1].call(this, paramMock.businessErrorMock, { - state: "[PC Preview] unknow state", - network: "[PC Preview] unknow network" - }); - } else if (args[0] === 'cellularDataFlowChange') { - args[len - 1].call(this, DataFlowType); - } else if (args[0] === 'callStateChange') { - args[len - 1].call(this, paramMock.businessErrorMock, { - state: "[PC Preview] unknow state", - number: "[PC Preview] unknow number" - }); - } else if (args[0] === 'cfuIndicatorChange' || 'voiceMailMsgIndicatorChange') { - args[len - 1].call(this, paramMock.paramBooleanMock); - } else if (args[0] === 'simStateChange') { - args[len - 1].call(this, SimStateData); - } - } - }, - once: function (...args) { - console.warn("telephony.observer.once interface mocked in the Previewer. How this interface works on the Previewer may " + - "be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - if (args[0] === 'networkStateChange') { - args[len - 1].call(this, NetworkState); - } else if (args[0] === 'signalInfoChange') { - args[len - 1].call(this, [SignalInformation]); - } else if (args[0] === 'cellInfoChange') { - args[len - 1].call(this, [CellInformation]); - } else if (args[0] === 'cellularDataConnectionStateChange') { - args[len - 1].call(this, paramMock.businessErrorMock, { - state: "[PC Preview] unknow state", - network: "[PC Preview] unknow network" - }); - } else if (args[0] === 'cellularDataFlowChange') { - args[len - 1].call(this, DataFlowType); - } else if (args[0] === 'callStateChange') { - args[len - 1].call(this, paramMock.businessErrorMock, { - state: "[PC Preview] unknow state", - number: "[PC Preview] unknow number" - }); - } else if (args[0] === 'cfuIndicatorChange' || 'voiceMailMsgIndicatorChange') { - args[len - 1].call(this, paramMock.paramBooleanMock); - } else if (args[0] === 'simStateChange') { - args[len - 1].call(this, SimStateData); - } - } - } - } -} \ No newline at end of file