diff --git a/runtime/main/extend/systemplugin/accessibility.js b/runtime/main/extend/systemplugin/accessibility.js index 0efba532..cb2bbe10 100644 --- a/runtime/main/extend/systemplugin/accessibility.js +++ b/runtime/main/extend/systemplugin/accessibility.js @@ -16,74 +16,6 @@ import { paramMock } from './utils'; export function mockAccessibility() { - const AbilitySubTypeMock = { - UNSPECIFIED: 0, - CA: 1 - }; - - const DisplayOrientationMock = { - UNSPECIFIED: 1, - LANDSCAPE: 2, - PORTRAIT: 3, - FOLLOWRECENT: 4 - }; - const LaunchModeMock = { - SINGLETON: 0, - STANDARD: 1 - }; - - const ApplicationInfoMock = { - name: '[PC Preview] unknow name', - description: '[PC Preview] unknow description', - descriptionId: '[PC Preview] unknow descriptionId', - systemApp: '[PC Preview] unknow systemApp', - enabled: '[PC Preview] unknow enabled', - label: '[PC Preview] unknow label', - labelId: '[PC Preview] unknow labelId', - icon: '[PC Preview] unknow icon', - iconId: '[PC Preview] unknow iconId', - process: '[PC Preview] unknow process', - supportedModes: '[PC Preview] unknow supportedModes', - moduleSourceDirs: '[PC Preview] unknow moduleSourceDirs', - permissions: '[PC Preview] unknow permissions', - permissions: '[PC Preview] unknow permissions', - flags: '[PC Preview] unknow flags', - entryDir: '[PC Preview] unknow entryDir' - }; - - const AbilityInfoMock = { - bundleName: '[PC Preview] unknow bundleName', - name: '[PC Preview] unknow name', - label: '[PC Preview] unknow label', - description: '[PC Preview] unknow description', - icon: '[PC Preview] unknow icon', - labelId: '[PC Preview] unknow labelId', - descriptionId: '[PC Preview] unknow descriptionId', - moduleName: '[PC Preview] unknow moduleName', - iconId: '[PC Preview] unknow iconId', - process: '[PC Preview] unknow process', - targetAbility: '[PC Preview] unknow targetAbility', - backgroundModes: '[PC Preview] unknow backgroundModes', - isVisible: '[PC Preview] unknow isVisible', - formEnabled: '[PC Preview] unknow formEnabled', - type: AbilityTypeMock, - subType: AbilitySubTypeMock, - orientation: DisplayOrientationMock, - launchMode: LaunchModeMock, - permissions: '[PC Preview] unknow permissions', - deviceTypes: '[PC Preview] unknow deviceTypes', - deviceCapabilities: '[PC Preview] unknow deviceCapabilities', - readPermission: '[PC Preview] unknow readPermission', - writePermission: '[PC Preview] unknow writePermission', - applicationInfo: ApplicationInfoMock, - formEntity: '[PC Preview] unknow formEntity', - minFormHeight: '[PC Preview] unknow minFormHeight', - defaultFormHeight: '[PC Preview] unknow defaultFormHeight', - minFormWidth: '[PC Preview] unknow minFormWidth', - defaultFormWidth: '[PC Preview] unknow defaultFormWidth', - uri: '[PC Preview] unknow uri' - }; - const AbilityTypeMock = { audible: 'audible', generic: 'generic', @@ -106,13 +38,30 @@ export function mockAccessibility() { id: '[PC Preview] unknow id', name: '[PC Preview] unknow name', bundleName: '[PC Preview] unknow bundleName', - abilityInfo: AbilityInfoMock, abilityTypes: [AbilityTypeMock], capabilities: [CapabilityMock], description: '[PC Preview] unknow description', eventTypes: [EventTypeMock] }; + const CaptionsFontEdgeTypeMock = '[PC Preview] unknow CaptionsFontEdgeType'; + + const CaptionsFontFamilyMock = '[PC Preview] unknow CaptionsFontFamily'; + + const CaptionStyleMock = { + fontFamily: [CaptionsFontFamilyMock], + fontScale: '[PC Preview] unknow fontScale', + fontColor: '[PC Preview] unknow fontColor', + fontEdgeType: [CaptionsFontEdgeTypeMock], + backgroundColor: '[PC Preview] unknow backgroundColor', + windowColor: '[PC Preview] unknow windowColor' + }; + + const CaptionsManagerMock = { + enabled: '[PC Preview] unknow enabled', + style: [CaptionStyleMock] + }; + const WindowUpdateTypeMock = '[PC Preview] unknow WindowUpdateType'; const ActionMock = '[PC Preview] unknow Action'; @@ -207,6 +156,18 @@ export function mockAccessibility() { resolve(); }); } + }, + getCaptionsManager: function (...args) { + console.warn('accessibility.getCaptionsManager interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [CaptionsManagerMock]); + } else { + return new Promise((resolve, reject) => { + resolve([CaptionsManagerMock]); + }); + } } }; } diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 7f7d9150..36ca2394 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -60,7 +60,9 @@ import { mockEnvironment } from "./environment" import { mockSettings } from './settings' import { mockAbilityAccessCtrl } from './abilityAccessCtrl' import { mockConfigPolicy } from './configPolicy' +import { mockUpdate } from './update' import { mockBackgroundTaskManager } from './backgroundTaskManager' +import { mockSecurityLabel } from './securitylabel' export function mockRequireNapiFun() { global.requireNapi = function (...args) { @@ -159,8 +161,12 @@ export function mockRequireNapiFun() { return mockAbilityAccessCtrl(); case "configPolicy": return mockConfigPolicy(); + case "update": + return mockUpdate(); case "backgroundTaskManager": return mockBackgroundTaskManager(); + case "securitylabel": + return mockSecurityLabel(); default: return global.requireNapiPreview(...args); } diff --git a/runtime/main/extend/systemplugin/napi/securitylabel.js b/runtime/main/extend/systemplugin/napi/securitylabel.js new file mode 100644 index 00000000..cfe0c6ee --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/securitylabel.js @@ -0,0 +1,46 @@ +/* + * 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 mockSecurityLabel() { + const securitylabel = { + setSecurityLabel: function (...args) { + console.warn("securitylabel.setSecurityLabel interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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); + }) + } + }, + getSecurityLabel: function (...args) { + console.warn("securitylabel.getSecurityLabel interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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 securitylabel; +} diff --git a/runtime/main/extend/systemplugin/napi/update.js b/runtime/main/extend/systemplugin/napi/update.js new file mode 100644 index 00000000..f3efb101 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/update.js @@ -0,0 +1,227 @@ +/* + * 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 mockUpdate() { + const updater = { + checkNewVersion: function (...args) { + console.warn("Updater.checkNewVersion interface mocked 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, NewVersionInfo); + } else { + return new Promise((resolve, reject) => { + resolve(NewVersionInfo); + }) + } + }, + download: function (...args) { + console.warn("Updater.download interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + upgrade: function (...args) { + console.warn("Updater.upgrade interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + getNewVersionInfo: function (...args) { + console.warn("Updater.getNewVersionInfo interface mocked 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, NewVersionInfo); + } else { + return new Promise((resolve, reject) => { + resolve(NewVersionInfo); + }) + } + }, + getUpdatePolicy: function (...args) { + console.warn("Updater.getUpdatePolicy interface mocked 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, UpdatePolicy); + } else { + return new Promise((resolve, reject) => { + resolve(UpdatePolicy); + }) + } + }, + setUpdatePolicy: function (...args) { + console.warn("Updater.setUpdatePolicy interface mocked 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); + }) + } + }, + applyNewVersion: function (...args) { + console.warn("Updater.applyNewVersion interface mocked 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); + }) + } + }, + rebootAndCleanCache: function (...args) { + console.warn("Updater.rebootAndCleanCache interface mocked 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); + }) + } + }, + verifyUpdatePackage: function (...args) { + console.warn("Updater.verifyUpdatePackage 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("Updater.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, Progress); + } + }, + off: function (...args) { + console.warn("Updater.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, Progress); + } + }, + cancel: function (...args) { + console.warn("Updater.cancel interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + } + const update = { + PackageTypes, + NewVersionStatus, + UpdateState, + InstallMode, + getUpdater: function (...args) { + console.warn("update.getUpdater interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return updater; + }, + getUpdaterForOther: function (...args) { + console.warn("update.getUpdaterForOther interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return updater; + }, + getUpdaterFromOther: function (...args) { + console.warn("update.getUpdaterFromOther interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return updater; + } + } + return update; +} + +const PackageTypes = { + PACKAGE_TYPE_NORMAL: 1, + PACKAGE_TYPE_BASE: 2, + PACKAGE_TYPE_CUST: 3, + PACKAGE_TYPE_PRELOAD: 4, + PACKAGE_TYPE_COTA: 5, + PACKAGE_TYPE_VERSION: 6, + PACKAGE_TYPE_PATCH: 7, +} + +const CheckResult = { + versionName: "[PC Preview] unknow versionName", + versionCode: "[PC Preview] unknow versionCode", + size: "[PC Preview] unknow size", + verifyInfo: "[PC Preview] unknow verifyInfo", + packageType: PackageTypes.PACKAGE_TYPE_NORMAL, + descriptionId: "[PC Preview] unknow descriptionId", +} + +const DescriptionInfo = { + descriptionId: "[PC Preview] unknow descriptionId", + content: "[PC Preview] unknow content", +} + +const NewVersionStatus = { + VERSION_STATUS_ERR: -1, + VERSION_STATUS_NEW: 0, + VERSION_STATUS_NONE: 1, + VERSION_STATUS_BUSY: 2, +} + +const NewVersionInfo = { + status: NewVersionStatus.VERSION_STATUS_NEW, + errMsg: "[PC Preview] unknow errMsg", + checkResults: [CheckResult], + descriptionInfo: [DescriptionInfo] +} + +const UpdateState = { + UPDATE_STATE_INIT: 0, + UPDATE_STATE_CHECK_VERSION_ON: 10, + UPDATE_STATE_CHECK_VERSION_FAIL: 11, + UPDATE_STATE_CHECK_VERSION_SUCCESS: 12, + UPDATE_STATE_DOWNLOAD_ON: 20, + UPDATE_STATE_DOWNLOAD_PAUSE: 21, + UPDATE_STATE_DOWNLOAD_CANCEL: 22, + UPDATE_STATE_DOWNLOAD_FAIL: 23, + UPDATE_STATE_DOWNLOAD_SUCCESS: 24, + UPDATE_STATE_VERIFY_ON: 30, + UPDATE_STATE_VERIFY_FAIL: 31, + UPDATE_STATE_VERIFY_SUCCESS: 32, + UPDATE_STATE_PACKAGE_TRANS_ON: 70, + UPDATE_STATE_PACKAGE_TRANS_FAIL: 71, + UPDATE_STATE_PACKAGE_TRANS_SUCCESS: 72, + UPDATE_STATE_INSTALL_ON: 80, + UPDATE_STATE_INSTALL_FAIL: 81, + UPDATE_STATE_INSTALL_SUCCESS: 82, + UPDATE_STATE_UPDATE_ON: 90, + UPDATE_STATE_UPDATE_FAIL: 91, + UPDATE_STATE_UPDATE_SUCCESS: 92 +} + +const Progress = { + percent: "[PC Preview] unknow percent", + status: UpdateState.UPDATE_STATE_INIT, + endReason: "[PC Preview] unknow endReason" +} + +const InstallMode = { + INSTALL_MODE_NORMAL: "[PC Preview] unknow INSTALL_MODE_NORMAL", + INSTALL_MODE_NIGHT: "[PC Preview] unknow INSTALL_MODE_NIGHT", + INSTALL_MODE_AUTO: "[PC Preview] unknow INSTALL_MODE_AUTO" +} + +const UpdatePolicy = { + autoDownload: "[PC Preview] unknow autoDownload", + installMode: InstallMode.INSTALL_MODE_NORMAL, + autoUpgradeInterval: [0] +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/wifi.js b/runtime/main/extend/systemplugin/napi/wifi.js old mode 100755 new mode 100644 index 707e9106..6f38f121 --- a/runtime/main/extend/systemplugin/napi/wifi.js +++ b/runtime/main/extend/systemplugin/napi/wifi.js @@ -76,6 +76,32 @@ export function mockWifi() { ipAddress: '[PC preview] unknow ipAddress', } + const p2pLinkedInfoMock = { + connectState: '[PC preview] unknow connectState', + isGroupOwner: '[PC preview] unknow isGroupOwner', + groupOwnerAddr: '[PC preview] unknow groupOwnerAddr', + } + + const WifiP2pDeviceMock = { + deviceName: '[PC preview] unknow deviceName', + deviceAddress: '[PC preview] unknow deviceAddress', + primaryDeviceType: '[PC preview] unknow primaryDeviceType', + deviceStatus: '[PC preview] unknow deviceStatus', + groupCapabilitys: '[PC preview] unknow groupCapabilitys', + } + + const p2pGroupInfoMock = { + isP2pGo: '[PC preview] unknow connectState', + ownerInfo: WifiP2pDeviceMock, + passphrase: '[PC preview] unknow passphrase', + interface: '[PC preview] unknow interface', + groupName: '[PC preview] unknow groupName', + networkId: '[PC preview] unknow networkId', + frequency: '[PC preview] unknow frequency', + clientDevices: [WifiP2pDeviceMock], + goIpAddress: '[PC preview] unknow goIpAddress', + } + const wifi = { enableWifi: function (...args) { console.warn("wifi.enableWifi interface mocked in the Previewer. How this interface works on the Previewer" + @@ -128,8 +154,8 @@ export function mockWifi() { }, connectToNetwork: function (...args) { - console.warn("wifi.connectToNetwork interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + console.warn("wifi.connectToNetwork interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") return paramMock.paramBooleanMock; }, @@ -287,6 +313,93 @@ export function mockWifi() { console.warn("wifi.off interface mocked in the Previewer." + " How this interface works on the Previewer may be different from that on a real device.") }, + + getP2pLinkedInfo: function (...args) { + console.warn("wifi.getP2pLinkedInfo interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, p2pLinkedInfoMock) + } else { + return new Promise((resolve) => { + resolve(p2pLinkedInfoMock) + }) + } + }, + + getCurrentGroup: function (...args) { + console.warn("wifi.getCurrentGroup interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, p2pGroupInfoMock) + } else { + return new Promise((resolve) => { + resolve(p2pGroupInfoMock) + }) + } + }, + + getP2pDevices: function (...args) { + console.warn("wifi.getP2pDevices interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [WifiP2pDeviceMock]) + } else { + return new Promise((resolve) => { + resolve([WifiP2pDeviceMock]) + }) + } + }, + + createGroup: function (...args) { + console.warn("wifi.createGroup interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + removeGroup: function (...args) { + console.warn("wifi.removeGroup interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + p2pConnect: function (...args) { + console.warn("wifi.p2pConnect interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + p2pCancelConnect: function (...args) { + console.warn("wifi.p2pCancelConnect interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + startDiscoverDevices: function (...args) { + console.warn("wifi.startDiscoverDevices interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + stopDiscoverDevices: function (...args) { + console.warn("wifi.stopDiscoverDevices interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + deletePersistentGroup: function (...args) { + console.warn("wifi.deletePersistentGroup interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + setDeviceName: function (...args) { + console.warn("wifi.setDeviceName interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, } return wifi; } diff --git a/runtime/main/extend/systemplugin/window.js b/runtime/main/extend/systemplugin/window.js index 0cb9ea6a..ffdfad8e 100644 --- a/runtime/main/extend/systemplugin/window.js +++ b/runtime/main/extend/systemplugin/window.js @@ -234,6 +234,18 @@ export const windowMock = { }) } }, + setWindowType: function (...args) { + console.warn("Window.setWindowType interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, loadContent: function (...args) { console.warn("Window.loadContent interface mocked in the Previewer. How this interface works on the" + " Previewer may be different from that on a real device.") @@ -423,5 +435,15 @@ export function mockWindow() { TYPE_CUTOUT: 1, TYPE_SYSTEM_GESTURE: 2 }, + WindowType: { + TYPE_APP: 0, + TYPE_SYSTEM_ALERT: 1, + TYPE_INPUT_METHOD: 2, + TYPE_STATUS_BAR: 3, + TYPE_PANEL: 4, + TYPE_KEYGUARD: 5, + TYPE_VOLUME_OVERLAY: 6, + TYPE_NAVIGATION_BAR: 7 + }, } -} \ No newline at end of file +} diff --git a/runtime/preparation/init.ts b/runtime/preparation/init.ts index 2b40106f..28dc07f6 100644 --- a/runtime/preparation/init.ts +++ b/runtime/preparation/init.ts @@ -151,7 +151,7 @@ const ComponentsInfo: components[] = [ 'type': 'image-animator' }, { - 'methods': ['showError', 'delete', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'getInspector', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], + 'methods': ['showError', 'insert', 'delete', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'getInspector', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'input' }, {