diff --git a/BUILD.gn b/BUILD.gn index 6872069f..acdb132c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -17,6 +17,8 @@ import("//foundation/ace/ace_engine/ace_config.gni") prebuilt_js_path = get_label_info(":gen_jsf_c", "target_out_dir") + "/dist/strip.native.min.js" +prebuilt_js_api_mock_path = get_label_info(":gen_jsf_c", "target_out_dir") + + "/dist/jsMockSystemPlugin.js" #snapshot_path = # get_label_info(":gen_snapshot", "target_out_dir") + "/strip.native.min.js" @@ -158,7 +160,10 @@ action("gen_snapshot") { "tsconfig.json", "tslint.json", ] - outputs = [ prebuilt_js_path ] + outputs = [ + prebuilt_js_path, + prebuilt_js_api_mock_path, + ] } jsfc_path = get_label_info(":jsf", "target_out_dir") + "/src/jsf.c" diff --git a/runtime/main/app/index.ts b/runtime/main/app/index.ts index bdc572cb..a6349bf2 100644 --- a/runtime/main/app/index.ts +++ b/runtime/main/app/index.ts @@ -91,6 +91,7 @@ export function appCreate(page: Page, options: Options, data: object, services: return; } if (options.pcPreview && options.pcPreview === 'enable') { + global.pcPreview = true; mockSystemPlugin(); } const packageName: string = page.packageName; diff --git a/runtime/main/extend/systemplugin/ability.js b/runtime/main/extend/systemplugin/ability.js index 7c777344..b01393e5 100644 --- a/runtime/main/extend/systemplugin/ability.js +++ b/runtime/main/extend/systemplugin/ability.js @@ -1,4 +1,5 @@ import { paramMock } from "./utils" +import { windowMock } from "./window" export function mockAbilityFeatureAbility() { global.systemplugin.ability = {} @@ -13,10 +14,76 @@ export function mockAbilityFeatureAbility() { parameters: "[PC Preview] unknow parameters", entities: "[PC Preview] unknow entities" } + const getFileTypesArrayMock = [ + paramMock.paramStringMock + ] const AbilityResultMock = { resultCode: "[PC Preview] unknow resultCode", want: WantMock } + const ResultSetMock = { + columnNames: "[PC Preview] unknow columnNames", + columnCount: "[PC Preview] unknow columnCount", + rowCount: "[PC Preview] unknow rowCount", + rowIndex: "[PC Preview] unknow rowIndex", + isEnded: "[PC Preview] unknow isEnded", + isStarted: "[PC Preview] unknow isStarted", + isClose: "[PC Preview] unknow isClose", + getColumnIndex: function (...args) { + console.warn("ResultSet.getColumnIndex interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + goTo: function (...args) { + console.warn("ResultSet.goTo interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + goToRow: function (...args) { + console.warn("ResultSet.goToRow interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + goToFirstRow: function (...args) { + console.warn("ResultSet.goToFirstRow interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + goToNextRow: function (...args) { + console.warn("ResultSet.goToNextRow interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + getBlob: function (...args) { + console.warn("ResultSet.getBlob interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramArrayMock; + }, + getString: function (...args) { + console.warn("ResultSet.getString interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramStringMock; + }, + getLong: function (...args) { + console.warn("ResultSet.getLong interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + getDouble: function (...args) { + console.warn("ResultSet.getDouble interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + isColumnNull: function (...args) { + console.warn("ResultSet.isColumnNull interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + close: function () { + console.warn("ResultSet.isColumnNull interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + } + } const DataAbilityHelperMock = { openFile: function (...args) { console.warn("DataAbilityHelper.openFile interface mocked in the Previewer. How this interface works on the Previewer" + @@ -25,7 +92,7 @@ export function mockAbilityFeatureAbility() { if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) } else { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { resolve(paramMock.paramNumberMock); }) } @@ -53,48 +120,546 @@ export function mockAbilityFeatureAbility() { if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock) } else { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { resolve(paramMock.paramObjectMock); }) } - } - } - const ContextMock = { - getCacheDir: function (...args) { - console.warn("Context.getCacheDir interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + }, + getType: function (...args) { + console.warn("DataAbilityHelper.getType interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { - resolve("[PC Preview] unknow string") + resolve(paramMock.paramStringMock); + }) + } + }, + getFileTypes: function (...args) { + console.warn("DataAbilityHelper.getFileTypes interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, getFileTypesArrayMock) + } else { + return new Promise((resolve) => { + resolve(getFileTypesArrayMock); + }) + } + }, + normalizeUri: function (...args) { + console.warn("DataAbilityHelper.normalizeUri interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramStringMock); + }) + } + }, + denormalizeUri: function (...args) { + console.warn("DataAbilityHelper.denormalizeUri interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramStringMock); + }) + } + }, + notifyChange: function (...args) { + console.warn("DataAbilityHelper.notifyChange interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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(); + }) + } + }, + insert: function (...args) { + console.warn("DataAbilityHelper.insert interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + batchInsert: function (...args) { + console.warn("DataAbilityHelper.batchInsert interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + delete: function (...args) { + console.warn("DataAbilityHelper.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, paramMock.paramNumberMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + update: function (...args) { + console.warn("DataAbilityHelper.update interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + query: function (...args) { + console.warn("DataAbilityHelper.query interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ResultSetMock) + } else { + return new Promise((resolve) => { + resolve(ResultSetMock); + }) + } + } + } + const PermissionRequestResultMock = { + requestCode: "[PC Preview] unknow requestCode", + permissions: ["[PC Preview] unknow permission", "[PC Preview] unknow permission"], + authResults: ["[PC Preview] unknow authResult", "[PC Preview] unknow authResult"] + } + const ModuleInfoMock = { + moduleName: "[PC Preview] unknow moduleName", + moduleSourceDir: "[PC Preview] unknow moduleSourceDir" + } + const CustomizeDataMock = { + name: "[PC Preview] unknow name", + value: "[PC Preview] unknow values" + } + 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 moduleSourceDir", "[PC Preview] unknow moduleSourceDir"], + permissions: ["[PC Preview] unknow permission", "[PC Preview] unknow permission"], + moduleInfo: [ModuleInfoMock], + entryDir: "[PC Preview] unknow entryDir", + customizeData:new Map([["[PC Preview] unknow customizeDataKey", CustomizeDataMock]]) + } + 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", + iconId: "[PC Preview] unknow iconId", + moduleName: "[PC Preview] unknow moduleName", + 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: "[PC Preview] unknow type", + subType: "[PC Preview] unknow subType", + orientation: "[PC Preview] unknow orientation", + launchMode: "[PC Preview] unknow launchMode", + permissions: ["[PC Preview] unknow permission", "[PC Preview] unknow permission"], + deviceTypes: ["[PC Preview] unknow deviceType", "[PC Preview] unknow deviceType"], + deviceCapabilities: ["[PC Preview] unknow 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", + customizeData: new Map([["[PC Preview] unknow customizeDataKey", CustomizeDataMock]]) + } + const ProcessInfoMock = { + pid: "[PC Preview] unknow pid", + processName: "[PC Preview] unknow processName" + } + const HapModuleInfoMock = { + name: "[PC Preview] unknow name", + description: "[PC Preview] unknow description", + descriptionId: "[PC Preview] unknow descriptionId", + icon: "[PC Preview] unknow icon", + label: "[PC Preview] unknow label", + labelId: "[PC Preview] unknow labelId", + iconId: "[PC Preview] unknow iconId", + backgroundImg: "[PC Preview] unknow backgroundImg", + supportedModes: "[PC Preview] unknow supportedModes", + reqCapabilities: ["[PC Preview] unknow reqCapabilities", "[PC Preview] unknow reqCapabilities"], + deviceTypes: ["[PC Preview] unknow deviceTypes", "[PC Preview] unknow deviceTypes"], + abilityInfo: [AbilityInfoMock], + moduleName: "[PC Preview] unknow moduleName", + mainAbilityName: "[PC Preview] unknow mainAbilityName", + installationFree: "[PC Preview] unknow installationFree", + } + const ElementNameMock = { + deviceId: "[PC Preview] unknow deviceId", + bundleName: "[PC Preview] unknow bundleName", + abilityName: "[PC Preview] unknow abilityName", + uri: "[PC Preview] unknow uri", + shortName: "[PC Preview] unknow shortName", + } + const AppVersionInfoMock = { + appName: "[PC Preview] unknow appName", + versionCode: "[PC Preview] unknow versionCode", + versionName: "[PC Preview] unknow versionName" + } + const ContextMock = { + getCacheDir: function (...args) { + console.warn("Context.getCacheDir interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramStringMock) }) } }, getFilesDir: function (...args) { console.warn("Context.getFilesDir interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") + " may be 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) => { - resolve("[PC Preview] unknow string") + resolve(paramMock.paramStringMock) }) } }, getExternalCacheDir: function (...args) { console.warn("Context.getExternalCacheDir 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) } else { return new Promise((resolve) => { - resolve("[PC Preview] unknow string") + resolve(paramMock.paramStringMock) }) } + }, + getOrCreateLocalDir: function (...args) { + console.warn("Context.getOrCreateLocalDir interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramStringMock) + }) + } + }, + getOrCreateDistributedDir: function (...args) { + console.warn("Context.getOrCreateDistributedDir interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramStringMock) + }) + } + }, + verifyPermission: function (...args) { + console.warn("Context.verifyPermission interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramNumberMock) + }) + } + }, + compelVerifyPermission: function (...args) { + console.warn("Context.compelVerifyPermission interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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() + }) + } + }, + authUriAccessPermission: function (...args) { + console.warn("Context.authUriAccessPermission interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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() + }) + } + }, + unauthUriAccessPermission: function (...args) { + console.warn("Context.unauthUriAccessPermission interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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() + }) + } + }, + requestPermissionsFromUser: function (...args) { + console.warn("Context.requestPermissionsFromUser interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, PermissionRequestResultMock) + } else { + return new Promise((resolve) => { + resolve(PermissionRequestResultMock) + }) + } + }, + getApplicationInfo: function (...args) { + console.warn("Context.getApplicationInfo interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ApplicationInfoMock) + } else { + return new Promise((resolve) => { + resolve(ApplicationInfoMock) + }) + } + }, + getBundleName: function (...args) { + console.warn("Context.getBundleName interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramStringMock) + }) + } + }, + getDisplayOrientation: function (...args) { + console.warn("Context.getDisplayOrientation interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramNumberMock) + }) + } + }, + setDisplayOrientation: function (...args) { + console.warn("Context.setDisplayOrientation interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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() + }) + } + }, + setShowOnLockScreen: function (...args) { + console.warn("Context.setShowOnLockScreen interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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() + }) + } + }, + setWakeUpScreen: function (...args) { + console.warn("Context.setWakeUpScreen interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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() + }) + } + }, + getProcessInfo: function (...args) { + console.warn("Context.getProcessInfo interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ProcessInfoMock) + } else { + return new Promise((resolve) => { + resolve(ProcessInfoMock) + }) + } + }, + getAppType: function (...args) { + console.warn("Context.getAppType interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramStringMock) + }) + } + }, + getElementName: function (...args) { + console.warn("Context.getElementName interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ElementNameMock) + } else { + return new Promise((resolve) => { + resolve(ElementNameMock) + }) + } + }, + getHapModuleInfo: function (...args) { + console.warn("Context.getHapModuleInfo interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, HapModuleInfoMock) + } else { + return new Promise((resolve) => { + resolve(HapModuleInfoMock) + }) + } + }, + getProcessName: function (...args) { + console.warn("Context.getProcessName interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramStringMock) + }) + } + }, + getCallingBundle: function (...args) { + console.warn("Context.getCallingBundle interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramStringMock) + }) + } + }, + printDrawnCompleted: function (...args) { + console.warn("Context.printDrawnCompleted interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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() + }) + } + }, + isUpdatingConfigurations: function (...args) { + console.warn("Context.isUpdatingConfigurations interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramBooleanMock) + }) + } + }, + getAppVersionInfo: function (...args) { + console.warn("Context.getAppVersionInfo interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AppVersionInfoMock) + } else { + return new Promise((resolve) => { + resolve(AppVersionInfoMock) + }) + } + }, + getAbilityInfo: function (...args) { + console.warn("Context.getAbilityInfo interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AbilityInfoMock) + } else { + return new Promise((resolve) => { + resolve(AbilityInfoMock) + }) + } + }, + getApplicationContext: function () { + console.warn("Context.getApplicationContext interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + return ContextMock; } } global.systemplugin.ability.featureAbility = { @@ -110,6 +675,30 @@ export function mockAbilityFeatureAbility() { }) } }, + startAssistAbility: function (...args) { + console.warn("ability.featureAbility.startAssistAbility mocked in the Previewer. How this interface works on the Previewer may be" + + " different from that on a real device.") + }, + stopAssistAbility: function (...args) { + console.warn("ability.featureAbility.stopAssistAbility interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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() + }) + } + }, + addAssistCallback: function (...args) { + console.warn("ability.featureAbility.addAssistCallback interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, global.systemplugin.ability.abilityAgent) + } + }, startAbility: function (...args) { console.warn("ability.featureAbility.startAbility interface mocked in the Previewer. How this interface works" + " on the Previewer may be different from that on a real device.") @@ -167,6 +756,54 @@ export function mockAbilityFeatureAbility() { console.warn("ability.featureAbility.getContext interface mocked in the Previewer. How this interface works on" + " the Previewer may be different from that on a real device.") return ContextMock; + }, + getAbilityMissionId: function (...args) { + console.warn("ability.featureAbility.getAbilityMissionId interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + setSwipeToDismiss: function (...args) { + console.warn("ability.featureAbility.setSwipeToDismiss interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }) + } + }, + hasWindowFocus: function (...args) { + console.warn("ability.featureAbility.hasWindowFocus interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + getWindow: function (...args) { + console.warn("ability.featureAbility.getWindow interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, windowMock) + } else { + return new Promise((resolve) => { + resolve(windowMock); + }) + } } } } @@ -183,6 +820,30 @@ export function mockAbilityParticleAbility() { resolve(paramMock.paramNumberMock) }) } + }, + startBackgroundRunning: function (...args) { + console.warn("ability.particleAbility.startBackgroundRunning interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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() + }) + } + }, + cancelBackgroundRunning: function (...args) { + console.warn("ability.particleAbility.cancelBackgroundRunning interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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() + }) + } } } } @@ -208,9 +869,29 @@ export function mockAbilityFormManager() { customizeDatas: "[PC Preview] unknow customizeDatas", jsonObject: "[PC Preview] unknow jsonObject" } + const WantMock = { + deviceId: "[PC Preview] unknow deviceId", + bundleName: "[PC Preview] unknow bundleName", + abilityName: "[PC Preview] unknow abilityName", + uri: "[PC Preview] unknow uri", + type: "[PC Preview] unknow type", + flag: "[PC Preview] unknow flag", + action: "[PC Preview] unknow action", + parameters: "[PC Preview] unknow parameters", + entities: "[PC Preview] unknow entities" + } + const FormStateMock = { + UNKNOWN : '-1', + DEFAULT : '0', + READY : '1' + } const FormInfoArrayMock = [ FormInfoMock ] + const AcquireFormStateMock = { + FormStateMock, + WantMock + } global.systemplugin.ability.formManager = { requestForm: function (...args) { console.warn("ability.formManager.requestForm interface mocked in the Previewer. How this interface works" + @@ -308,8 +989,8 @@ export function mockAbilityFormManager() { }) } }, - getFormsInfoByApp: function (...args) { - console.warn("ability.formManager.getFormsInfoByApp interface mocked in the Previewer. How this interface works" + + getFormsInfo: function (...args) { + console.warn("ability.formManager.getFormsInfo interface mocked in the Previewer. How this interface works" + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { @@ -320,17 +1001,233 @@ export function mockAbilityFormManager() { }) } }, - getFormsInfoByModule: function (...args) { - console.warn("ability.formManager.getFormsInfoByModule interface mocked in the Previewer. How this interface works" + + isSystemReady: function (...args) { + console.warn("ability.formManager.isSystemReady interface mocked in the Previewer. How this interface works" + " on the Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, FormInfoArrayMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) } else { return new Promise((resolve) => { - resolve(FormInfoArrayMock) + resolve(paramMock.paramBooleanMock) + }) + } + }, + castTempForm: function (...args) { + console.warn("ability.formManager.castTempForm interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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() + }) + } + }, + deleteInvalidForms: function (...args) { + console.warn("ability.formManager.deleteInvalidForms interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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) => { + resolve(paramMock.paramNumberMock) + }) + } + }, + acquireFormState: function (...args) { + console.warn("ability.formManager.acquireFormState interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AcquireFormStateMock) + } else { + return new Promise((resolve) => { + resolve(AcquireFormStateMock) + }) + } + }, + on: function (...args) { + console.warn("ability.formManager.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) + } + }, + off: function (...args) { + console.warn("ability.formManager.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) + } + } + } +} +export function mockAbilityContinuationRegisterManager() { + const ContinuationResultMock = { + id: "[PC Preview] unknow id", + type: "[PC Preview] unknow type" + } + global.systemplugin.ability.continuationRegisterManager = { + on: function (...args) { + console.warn("ability.ContinuationRegisterManager.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 (args[0] === 'deviceConnect') { + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ContinuationResultMock) + } + } else { + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) + } + } + }, + off: function (...args) { + console.warn("ability.ContinuationRegisterManager.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 (args[0] === 'deviceConnect') { + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ContinuationResultMock) + } + } else { + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) + } + } + }, + register: function (...args) { + console.warn("ability.ContinuationRegisterManager.register interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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) => { + resolve(paramMock.paramNumberMock) + }) + } + }, + unregister: function (...args) { + console.warn("ability.ContinuationRegisterManager.unregister interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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() + }) + } + }, + updateConnectStatus: function (...args) { + console.warn("ability.ContinuationRegisterManager.updateConnectStatus interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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) => { + resolve(paramMock.paramNumberMock) + }) + } + }, + showDeviceList: function (...args) { + console.warn("ability.ContinuationRegisterManager.showDeviceList interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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) => { + resolve(paramMock.paramNumberMock) + }) + } + }, + disconnect: function (...args) { + console.warn("ability.ContinuationRegisterManager.disconnect interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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() }) } } } -} \ No newline at end of file +} +export function mockAbilityDataUriUtils() { + global.systemplugin.ability.dataUriUtils = { + getId: function (...args) { + console.warn("ability.dataUriUtils.getId interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + attachId: function (...args) { + console.warn("ability.dataUriUtils.attachId interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return paramMock.paramStringMock + }, + deleteId: function (...args) { + console.warn("ability.dataUriUtils.deleteId interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return paramMock.paramStringMock + }, + updateId: function (...args) { + console.warn("ability.dataUriUtils.updateId interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return paramMock.paramStringMock + } + } +} +export function mockAbilityAbilityAgent() { + global.systemplugin.ability.abilityAgent = { + on: function (...args) { + console.warn("ability.abilityAgent.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) + } + }, + off: function (...args) { + console.warn("ability.abilityAgent.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) + } + }, + postMessage: function (...args) { + console.warn("ability.abilityAgent.postMessage interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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() + }) + } + } + } +} +export function mockAbilityFormBindingData() { + const FormBindingDataMock = { + data: "[PC Preview] unknow data" + } + global.systemplugin.ability.formBindingData = { + createFormBindingData: function (...args) { + console.warn("ability.formBindingData.createFormBindingData interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return FormBindingDataMock; + } + } +} diff --git a/runtime/main/extend/systemplugin/batteryinfo.js b/runtime/main/extend/systemplugin/batteryinfo.js index 905de290..3f92182b 100644 --- a/runtime/main/extend/systemplugin/batteryinfo.js +++ b/runtime/main/extend/systemplugin/batteryinfo.js @@ -1,12 +1,35 @@ -export function mockOhosBatteryinfo() { - global.systemplugin.batteryInfo = { - 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" - } -} +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" + } +} diff --git a/runtime/main/extend/systemplugin/contact.js b/runtime/main/extend/systemplugin/contact.js new file mode 100644 index 00000000..603f63e5 --- /dev/null +++ b/runtime/main/extend/systemplugin/contact.js @@ -0,0 +1,216 @@ +import { paramMock } from "./utils" + +export function mockContact () { + const contactMock = { + contactAttributes:"[PC Preview] unknow contactAttributes", + id:"[PC Preview] unknow id", + key:"[PC Preview] unknow key", + emails:"[PC Preview] unknow emails", + events:"[PC Preview] unknow events", + groups:"[PC Preview] unknow groups", + imAddresses:"[PC Preview] unknow imAddresses", + phoneNumbers:"[PC Preview] unknow phoneNumbers", + portrait:"[PC Preview] unknow portrait", + postalAddresses:"[PC Preview] unknow postalAddresses", + relations:"[PC Preview] unknow relations", + sipAddresses:"[PC Preview] unknow sipAddresses", + websites:"[PC Preview] unknow websites", + name:"[PC Preview] unknow name", + nickName:"[PC Preview] unknow nickName", + note:"[PC Preview] unknow note", + organization:"[PC Preview] unknow organization", + } + const holderMock = { + holderId:"[PC Preview] unknow holderId", + bundleName:"[PC Preview] unknow bundleName", + displayName:"[PC Preview] unknow displayName", + } + const groupMock = { + groupId:"[PC Preview] unknow groupId", + title:"[PC Preview] unknow title" + } + global.systemplugin.contact = { + addContact: function (...args) { + console.warn("contact.addContact interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramNumberMock) + }); + } + }, + selectContact: function (...args) { + console.warn("contact.selectContact interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + var array = new Array(); + array.push(contactMock); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, array) + } else { + return new Promise((resolve) => { + resolve(array) + }); + } + }, + deleteContact: function (...args) { + console.warn("contact.deleteContact interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }); + } + }, + queryContact: function (...args) { + console.warn("contact.queryContact interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, contactMock) + } else { + return new Promise((resolve) => { + resolve(contactMock) + }); + } + }, + queryContacts: function (...args) { + console.warn("contact.queryContacts interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + var array = new Array(); + array.push(contactMock); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, array) + } else { + return new Promise((resolve) => { + resolve(array) + }); + } + }, + queryContactsByEmail: function (...args) { + console.warn("contact.queryContactsByEmail interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + var array = new Array(); + array.push(contactMock); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, array) + } else { + return new Promise((resolve) => { + resolve(array) + }); + } + }, + queryContactsByPhoneNumber: function (...args) { + console.warn("contact.queryContactsByPhoneNumber interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + var array = new Array(); + array.push(contactMock); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, array) + } else { + return new Promise((resolve) => { + resolve(array) + }); + } + }, + queryGroups: function (...args) { + console.warn("contact.queryGroups interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + var array = new Array(); + array.push(groupMock); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, array) + } else { + return new Promise((resolve) => { + resolve(array) + }); + } + }, + queryHolders: function (...args) { + console.warn("contact.queryHolders interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + var array = new Array(); + array.push(holderMock); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, array) + } else { + return new Promise((resolve) => { + resolve(array) + }); + } + }, + queryKey: function (...args) { + console.warn("contact.queryKey interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramStringMock) + }); + } + }, + queryMyCard: function (...args) { + console.warn("contact.queryMyCard interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + var array = new Array(); + array.push(contactMock); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, array) + } else { + return new Promise((resolve) => { + resolve(array) + }); + } + }, + updateContact: function (...args) { + console.warn("contact.updateContact interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }); + } + }, + isLocalContact: function (...args) { + console.warn("contact.isLocalContact interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramBooleanMock) + }); + } + }, + isMyCard: function (...args) { + console.warn("contact.isMyCard interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramBooleanMock) + }); + } + } + } +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/distributedSchedule.js b/runtime/main/extend/systemplugin/distributedSchedule.js index d1aad493..68d4aff9 100644 --- a/runtime/main/extend/systemplugin/distributedSchedule.js +++ b/runtime/main/extend/systemplugin/distributedSchedule.js @@ -42,6 +42,19 @@ export function mockDistributedSchedule() { resolve(paramMock.paramStringMock) }) } + }, + queryRemoteAbilityByWant: function (...args) { + console.warn("distributedSchedule.queryRemoteAbilityByWant interface mocked in the Previewer. " + + "How this interface works on the Previewer" + + " may be 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) => { + resolve(paramMock.paramArrayMock) + }) + } } } -} +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/index.js b/runtime/main/extend/systemplugin/index.js index 70780198..8c7b4bdd 100644 --- a/runtime/main/extend/systemplugin/index.js +++ b/runtime/main/extend/systemplugin/index.js @@ -3,13 +3,19 @@ import regeneratorRuntime from 'babel-runtime/regenerator' import { mockAbilityFeatureAbility, mockAbilityParticleAbility, - mockAbilityFormManager + mockAbilityFormManager, + mockAbilityContinuationRegisterManager, + mockAbilityDataUriUtils, + mockAbilityAbilityAgent, + mockAbilityFormBindingData } from './ability' +import {mockAppAbilityManager} from './ohos/app' +import { mockBackgroundTaskManager } from './ohos/backgroundTaskManager' import { mockBattery } from './battery' import { mockBrightness } from './brightness' import { mockBluetooth } from './bluetooth' -import { mockCall } from './telephony' +import { mockCall, mockData, mockRadio, mockSim, mockSMS } from './telephony' import { mockCipher } from './cipher' import { mockDataStorage } from './data' import { mockDeviceInfo } from './deviceInfo' @@ -29,6 +35,8 @@ import { import { mockNetwork } from './network' import { mockNfcCardEmulation } from './nfc' import { mockNotification } from './notification' +import { mockOhosNotification } from './ohos/notification' +import { mockCommonEvent } from './ohos/commonEvent' import { mockOhosBatteryinfo } from './batteryinfo' import { mockOhosRequest } from './ohos/request' @@ -36,14 +44,17 @@ import { mockPasteBoard } from './pasteboard' 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' import { mockSystemPackage } from './systemPackage' import { mockUserauth } from './userIAM' import { mockVibrator } from './vibrator' -import { mockWebSocket, mockHttp } from './net' +import { mockWebSocket, mockHttp, mockMdns, mockSocket } from './net' import { mockWifi } from './wifi' import { mockWindow } from './window' @@ -52,6 +63,10 @@ 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 {mockSettings} from "./settings" export function mockSystemPlugin() { global.regeneratorRuntime = regeneratorRuntime @@ -60,6 +75,8 @@ export function mockSystemPlugin() { global.ohosplugin = {} mockNotification() + mockOhosNotification() + mockCommonEvent() mockFetch() mockRequest() mockStorage() @@ -85,20 +102,38 @@ export function mockSystemPlugin() { mockMultimediaMedia() mockMultimediaMedialibrary() mockCall() + mockData() + mockRadio() + mockSim() + mockSMS() mockWebSocket() mockHttp() + mockMdns() + mockSocket() mockDeviceInfo() mockWifi() + mockResourceManager() mockNfcCardEmulation() mockDataStorage() mockWindow() mockAbilityFeatureAbility() + mockAbilityContinuationRegisterManager() mockReminderAgent() mockRequireNapiFun() + mockAbilityDataUriUtils() mockAccessibility() mockAbilityParticleAbility() mockAbilityFormManager() + mockAbilityAbilityAgent() + mockAbilityFormBindingData() mockAI() mockDisplay() mockDeviceManager() + mockScreenshot() + mockBackgroundTaskManager() + mockStorageInfoManager() + mockContact() + mockScreenLock() + mockSettings() + mockAppAbilityManager() } diff --git a/runtime/main/extend/systemplugin/multimedia.js b/runtime/main/extend/systemplugin/multimedia.js index a682dc35..1164371e 100644 --- a/runtime/main/extend/systemplugin/multimedia.js +++ b/runtime/main/extend/systemplugin/multimedia.js @@ -1,237 +1,545 @@ -import { paramMock } from "./utils" - -export function mockMultimediaImage() { - global.systemplugin.multimedia = {} - const sizeMock = { - height: "[PC Preview] unknow height", - width: "[PC Preview] unknow width" - } - const imageInfoMock = { - size: sizeMock, - pixelFortmat: "[PC Preview] unknow pixelFortmat", - colorSpace: "[PC Preview] unknow colorSpace", - alphaType: "[PC Preview] unknow alphaType" - } - const imageSourceMock = { - getImageInfo: function (...args) { - console.warn("ImageSource.getImageInfo interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, imageInfoMock); - } else { - return new Promise((resolve, reject) => { - resolve(imageInfoMock); - }) - } - }, - release: function (...args) { - console.warn("ImageSource.release interface mocked in the Previewer. How this interface works on the Previewer" + - " may be 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(); - }) - } - }, - supportedFormats: "[PC Preview] unknow supportedFormats" - } - const imagePackerMock = { - packing: function (...args) { - console.warn("ImagePacker.packing interface mocked in the Previewer. How this interface works on the Previewer" + - " may be 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); - }) - } - }, - release: function (...args) { - console.warn("ImagePacker.release interface mocked in the Previewer. How this interface works on the Previewer" + - " may be 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(); - }) - } - }, - supportedFormats: "[PC Preview] unknow supportedFormats" - } - global.systemplugin.multimedia.image = { - createImageSource: function () { - console.warn("multimedia.image.createImageSource interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") - return imageSourceMock; - }, - createImagePacker: function () { - console.warn("multimedia.image.createImagePacker interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") - return imagePackerMock; - } - } -} - -export function mockMultimediaMedia() { - const audioPlayerMock = { - play: function () { - console.warn("AudioPlayer.play interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return - }, - pause: function () { - console.warn("AudioPlayer.pause interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return - }, - stop: function () { - console.warn("AudioPlayer.stop interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return - }, - seek: function (...args) { - console.warn("AudioPlayer.seek interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return - }, - setVolume: function (...args) { - console.warn("AudioPlayer.setVolume interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - return - }, - release: function () { - console.warn("AudioPlayer.release interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return - }, - src: "[PC Preview] unknow src", - loop: "[PC Preview] unknow loop", - currentTime: "[PC Preview] unknow currentTime", - duration: "[PC Preview] unknow duration", - state: "[PC Preview] unknow state", - on: function (...args) { - console.warn("AudioPlayer.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] == 'error') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else if (args[0] == 'timeUpdate') { - args[len - 1].call(this, paramMock.paramNumberMock); - } else { - args[len - 1].call(this); - } - } - } - } - const audioRecorderMock = { - prepare: function () { - console.warn("AudioRecorder.prepare interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - }, - start: function () { - console.warn("AudioRecorder.start interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }, - pause: function () { - console.warn("AudioRecorder.pause interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }, - resume: function () { - console.warn("AudioRecorder.resume interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - }, - stop: function () { - console.warn("AudioRecorder.stop interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }, - release: function () { - console.warn("AudioRecorder.release interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - }, - reset: function () { - console.warn("AudioRecorder.reset 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("AudioRecorder.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] == 'error') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - args[len - 1].call(this); - } - } - } - } - global.systemplugin.multimedia.media = { - createAudioPlayer: function () { - console.warn("multimedia.media.createAudioPlayer interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") - return audioPlayerMock; - }, - createAudioRecorder: function () { - console.warn("multimedia.media.createAudioRecorder interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") - return audioRecorderMock; - } - } -} - -export function mockMultimediaMedialibrary() { - const MediaLibraryMock = { - 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.") - 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); - }) - } - }, - 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.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock); - } else { - return new Promise((resolve, reject) => { - resolve(); - }) - } - }, - 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.") - 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); - }) - } - } - } - global.systemplugin.multimedia.mediaLibrary = { - getMediaLibrary: function () { - console.warn("multimedia.mediaLibrary.getMediaLibrary interface mocked in the Previewer. How this interface" + - " works on the Previewer may be different from that on a real device.") - return MediaLibraryMock; - } - } -} \ No newline at end of file +import { paramMock } from "./utils" + +const sizeMock = { + height: "[PC Preview] unknow height", + width: "[PC Preview] unknow width" +} +const imageInfoMock = { + size: sizeMock, + pixelFortmat: "[PC Preview] unknow pixelFortmat", + colorSpace: "[PC Preview] unknow colorSpace", + alphaType: "[PC Preview] unknow alphaType" +} +export const PixelMapMock = { + isEditable: "[PC Preview]: unknow isEditable", + readPixelsToBuffer: function (...args) { + console.warn("PixelMap.readPixelsToBuffer interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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(); + }) + } + }, + readPixels: function (...args) { + console.warn("PixelMap.readPixels interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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(); + }) + } + }, + writePixels: function (...args) { + console.warn("PixelMap.writePixels interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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(); + }) + } + }, + writeBufferToPixels: function (...args) { + console.warn("PixelMap.writeBufferToPixels interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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(); + }) + } + }, + getImageInfo: function (...args) { + console.warn("PixelMap.getImageInfo interface mocked 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, imageInfoMock); + } else { + return new Promise((resolve, reject) => { + resolve(imageInfoMock); + }) + } + }, + getBytesNumberPerRow: function (...args) { + console.warn("PixelMap.getBytesNumberPerRow interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramNumberMock + }, + getPixelBytesNumber: function (...args) { + console.warn("PixelMap.getPixelBytesNumber interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramNumberMock + }, + release: function (...args) { + console.warn("PixelMap.release interface mocked 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(); + }) + } + } +} + +export function mockMultimediaImage() { + global.systemplugin.multimedia = {} + const imageSourceMock = { + getImageInfo: function (...args) { + console.warn("ImageSource.getImageInfo interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, imageInfoMock); + } else { + return new Promise((resolve, reject) => { + resolve(imageInfoMock); + }) + } + }, + release: function (...args) { + console.warn("ImageSource.release interface mocked 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(); + }) + } + }, + createPixelMap: function (...args) { + console.warn("ImageSource.createPixelMap interface mocked 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, PixelMapMock); + } else { + return new Promise((resolve, reject) => { + resolve(PixelMapMock); + }) + } + }, + getImageProperty: function (...args) { + console.warn("ImageSource.getImageProperty interface mocked 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); + }) + } + }, + supportedFormats: "[PC Preview] unknow supportedFormats" + } + const imagePackerMock = { + packing: function (...args) { + console.warn("ImagePacker.packing interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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); + }) + } + }, + release: function (...args) { + console.warn("ImagePacker.release interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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(); + }) + } + }, + supportedFormats: "[PC Preview] unknow supportedFormats" + } + const PixelMapFormatMock = { + UNKNOWN: "[PC Preview]: unknow UNKNOWN", + RGB_565: "[PC Preview]: unknow RGB_565", + RGBA_8888: "[PC Preview]: unknow RGBA_8888", + } + const PropertyKeyMock = { + BITS_PER_SAMPLE: "[PC Preview]: unknow BITS_PER_SAMPLE", + ORIENTATION: "[PC Preview]: unknow ORIENTATION", + IMAGE_LENGTH: "[PC Preview]: unknow IMAGE_LENGTH", + GPS_LATITUDE: "[PC Preview]: unknow GPS_LATITUDE", + GPS_LONGITUDE: "[PC Preview]: unknow GPS_LONGITUDE", + GPS_LATITUDE_REF: "[PC Preview]: unknow GPS_LATITUDE_REF", + GPS_LONGITUDE_REF: "[PC Preview]: unknow GPS_LONGITUDE_REF" + } + + global.systemplugin.multimedia.image = { + PixelMapFormat: PixelMapFormatMock, + PropertyKey: PropertyKeyMock, + createImageSource: function () { + console.warn("multimedia.image.createImageSource interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return imageSourceMock; + }, + createImagePacker: function () { + console.warn("multimedia.image.createImagePacker interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return imagePackerMock; + } + } +} + +export function mockMultimediaMedia() { + const audioPlayerMock = { + play: function () { + console.warn("AudioPlayer.play interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return + }, + pause: function () { + console.warn("AudioPlayer.pause interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return + }, + stop: function () { + console.warn("AudioPlayer.stop interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return + }, + seek: function (...args) { + console.warn("AudioPlayer.seek interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return + }, + setVolume: function (...args) { + console.warn("AudioPlayer.setVolume interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return + }, + release: function () { + console.warn("AudioPlayer.release interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return + }, + src: "[PC Preview] unknow src", + loop: "[PC Preview] unknow loop", + currentTime: "[PC Preview] unknow currentTime", + duration: "[PC Preview] unknow duration", + state: "[PC Preview] unknow state", + on: function (...args) { + console.warn("AudioPlayer.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] == 'error') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else if (args[0] == 'timeUpdate') { + args[len - 1].call(this, paramMock.paramNumberMock); + } else { + args[len - 1].call(this); + } + } + } + } + const audioRecorderMock = { + prepare: function () { + console.warn("AudioRecorder.prepare interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + start: function () { + console.warn("AudioRecorder.start interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + pause: function () { + console.warn("AudioRecorder.pause interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + resume: function () { + console.warn("AudioRecorder.resume interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + stop: function () { + console.warn("AudioRecorder.stop interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + release: function () { + console.warn("AudioRecorder.release interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + reset: function () { + console.warn("AudioRecorder.reset 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("AudioRecorder.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] == 'error') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + args[len - 1].call(this); + } + } + } + } + global.systemplugin.multimedia.media = { + createAudioPlayer: function () { + console.warn("multimedia.media.createAudioPlayer interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return audioPlayerMock; + }, + createAudioRecorder: function () { + console.warn("multimedia.media.createAudioRecorder interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return audioRecorderMock; + } + } +} + +export function mockMultimediaMedialibrary() { + const FileAssetMock = { + id: "[PC Preview] unknow id", + uri: "[PC Preview] unknow uri", + thumbnailUri: "[PC Preview] unknow thumbnailUri", + mimeType: "[PC Preview] unknow mimeType", + mediaType: "[PC Preview] unknow mediaType", + displayName: "[PC Preview] unknow displayName", + title: "[PC Preview] unknow title", + size: "[PC Preview] unknow size", + albumId: "[PC Preview] unknow albumId", + albumName: "[PC Preview] unknow albumName", + dateAdded: "[PC Preview] unknow dateAdded", + dateModified: "[PC Preview] unknow dateMidified", + dateTaken: "[PC Preview] unknow dateTaken", + orientation: "[PC Preview] unknow orientation", + width: "[PC Preview] unknow width", + height: "[PC Preview] unknow height", + extendedValues: "[PC Preview] unknow extendedValues", + } + const MediaLibraryMock = { + 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.") + 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); + }) + } + }, + 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.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + 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.") + 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); + }) + } + }, + 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.") + const len = args.length + var isCallBack = typeof args[len - 1] === 'function' + return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FetchFileResultMock) + : new Promise((resolve, reject) => { + resolve(FetchFileResultMock); + }) + }, + 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.") + const len = args.length + var albumsMock = new Array(AlbumMock) + var isCallBack = typeof args[len - 1] === 'function' + return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, albumsMock) + : new Promise((resolve, reject) => { + resolve(albumsMock); + }) + }, + 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.") + return + }, + 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.") + return + } + } + const FetchFileResultMock = { + 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.") + return paramMock.paramNumberMock + }, + 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.") + return paramMock.paramBooleanMock + }, + 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.") + return + }, + 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.") + const len = args.length + var isCallBack = typeof args[len - 1] === 'function' + return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FileAssetMock) + : new Promise((resolve, reject) => { + resolve(FileAssetMock); + }) + }, + 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.") + const len = args.length + var isCallBack = typeof args[len - 1] === 'function' + return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FileAssetMock) + : new Promise((resolve, reject) => { + resolve(FileAssetMock); + }) + }, + 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.") + const len = args.length + var isCallBack = typeof args[len - 1] === 'function' + return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FileAssetMock) + : new Promise((resolve, reject) => { + resolve(FileAssetMock); + }) + }, + 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.") + const len = args.length + var isCallBack = typeof args[len - 1] === 'function' + return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FileAssetMock) + : new Promise((resolve, reject) => { + resolve(FileAssetMock); + }) + }, + getAllObject: function (...args) { + console.warn("FetchFileResult.getAllObject interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + var fileAssets = new Array(FileAssetMock) + var isCallBack = typeof args[len - 1] === 'function' + return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, fileAssets) + : new Promise((resolve, reject) => { + resolve(fileAssets); + }) + } + } + const AlbumMock = { + albumId: "[PC Preview] unknow albumId", + albumName: "[PC Preview] unknow albumName", + path: "[PC Preview] unknow path", + dateModified: "[PC Preview] unknow dateModified", + 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.") + const len = args.length + var isCallBack = typeof args[len - 1] === 'function' + return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FetchFileResultMock) + : new Promise((resolve, reject) => { + resolve(FetchFileResultMock); + }) + } + } + const AVMetadataHelperMock = { + setSource: function (...args) { + console.warn("AVMetadataHelper.setSource interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + var isCallBack = typeof args[len - 1] === 'function' + return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock) + : new Promise((resolve, reject) => { + resolve(); + }) + }, + fetchVideoPixelMapByTime: function (...args) { + console.warn("AVMetadataHelper.fetchVideoPixelMapByTime interface mocked in the Previewer. How this interface" + + " works on the Previewer may be different from that on a real device.") + const len = args.length + var isCallBack = typeof args[len - 1] === 'function' + return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock) + : new Promise((resolve, reject) => { + resolve(paramMock.paramObjectMock); + }) + }, + resolveMetadata: function (...args) { + console.warn("AVMetadataHelper.resolveMetadata interface mocked in the Previewer. How this interface" + + " works on the Previewer may be different from that on a real device.") + const len = args.length + var isCallBack = typeof args[len - 1] === 'function' + return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) + : new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + }, + release: function (...args) { + console.warn("AVMetadataHelper.release interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + var isCallBack = typeof args[len - 1] === 'function' + return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock) + : new Promise((resolve, reject) => { + resolve(); + }) + } + } + global.systemplugin.multimedia.mediaLibrary = { + getMediaLibrary: function () { + console.warn("multimedia.mediaLibrary.getMediaLibrary interface mocked in the Previewer. How this interface" + + " works on the Previewer may be different from that on a real device.") + return MediaLibraryMock; + }, + createAVMetadataHelper: function () { + console.warn("multimedia.mediaLibrary.createAVMetadataHelper interface mocked in the Previewer. How this" + + " interface works on the Previewer may be different from that on a real device.") + return AVMetadataHelperMock; + } + } +} diff --git a/runtime/main/extend/systemplugin/napi/bytrace.js b/runtime/main/extend/systemplugin/napi/bytrace.js new file mode 100644 index 00000000..87ee405b --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/bytrace.js @@ -0,0 +1,19 @@ +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/napi/hiAppEvent.js b/runtime/main/extend/systemplugin/napi/hiAppEvent.js new file mode 100644 index 00000000..ab212de2 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/hiAppEvent.js @@ -0,0 +1,47 @@ +import { paramMock } from "../utils" + +function buildMockInfo(interfaceName) { + return interfaceName + " interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device." +} + +export function mockHiAppEvent() { + const EventTypeMock = { + FAULT: paramMock.paramNumberMock, + STATISTIC: paramMock.paramNumberMock, + SECURITY: paramMock.paramNumberMock, + BEHAVIOR: paramMock.paramNumberMock + } + const EventMock = { + USER_LOGIN: paramMock.paramStringMock, + USER_LOGOUT: paramMock.paramStringMock, + DISTRIBUTED_SERVICE_START: paramMock.paramStringMock + } + const ParamMock = { + USER_ID: paramMock.paramStringMock, + DISTRIBUTED_SERVICE_NAME: paramMock.paramStringMock, + DISTRIBUTED_SERVICE_INSTANCE_ID: paramMock.paramStringMock + } + + const hiAppEvent = { + EventType: EventTypeMock, + Event: EventMock, + Param: ParamMock, + write: function (...args) { + console.warn(buildMockInfo("hiAppEvent.write")) + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve() + }) + } + }, + configure: function (...args) { + console.warn(buildMockInfo("hiAppEvent.configure")); + return paramMock.paramBooleanMock + } + } + return hiAppEvent +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/hilog.js b/runtime/main/extend/systemplugin/napi/hilog.js new file mode 100644 index 00000000..7c3a9abe --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/hilog.js @@ -0,0 +1,32 @@ +import { paramMock } from "../utils" + +export function mockHilog() { + const hilog = { + debug: function (...args) { + console.warn("hilog.debug interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + info: function (...args) { + console.warn("hilog.info interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + warn: function (...args) { + console.warn("hilog.warn interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + error: function (...args) { + console.warn("hilog.error interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + fatal: function (...args) { + console.warn("hilog.fatal interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + isLoggable: function (...args) { + console.warn("hilog.isLoggable 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 hilog; +} diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index dd66cbb1..736ac2e1 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -4,6 +4,15 @@ import { mockWorker } from './worker' import { mockUtil } from './util' import { mockPower } from './power' import { mockRunningLock } from './runningLock' +import { mockRpc } from './rpc' +import { mockBytrace } from './bytrace' +import { mockwebgl } from './webgl' +import { mockwebgl2 } from './webgl2' +import { mockProcess } from './process' +import { mockUrl } from './url' +import { mockMediaQuery } from './mediaquery' +import { mockHiAppEvent } from './hiAppEvent' +import { mockHilog } from './hilog' export function mockRequireNapiFun() { global.requireNapi = function (...args) { @@ -20,6 +29,24 @@ export function mockRequireNapiFun() { return mockPower(); case "runningLock": return mockRunningLock(); + case "rpc": + return mockRpc(); + case "webgl": + return mockwebgl(); + case "webgl2": + return mockwebgl2(); + case "process": + return mockProcess(); + case "bytrace": + return mockBytrace(); + case "url": + return mockUrl(); + case "mediaquery": + return mockMediaQuery(); + case "hiAppEvent": + return mockHiAppEvent(); + case "hilog": + return mockHilog(); } } } diff --git a/runtime/main/extend/systemplugin/napi/mediaquery.js b/runtime/main/extend/systemplugin/napi/mediaquery.js new file mode 100644 index 00000000..4ca7ad48 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/mediaquery.js @@ -0,0 +1,25 @@ +export function mockMediaQuery() { + const mediaquery = { + matchMediaSync: function (...args) { + console.warn("mediaquery.matchMediaSync interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + var listener = { + on: function (...args) { + console.warn("listener.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("listener.off interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + }, + matches:false, + media:String + }; + if (args.length === 1 && typeof args[0] === 'string') { + listener.media = args[0]; + } + return listener; + } + } + return mediaquery +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/process.js b/runtime/main/extend/systemplugin/napi/process.js new file mode 100644 index 00000000..e0ad70db --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/process.js @@ -0,0 +1,93 @@ +import { paramMock } from "../utils" + +export function mockProcess() { + const result = { + runCmd: function(...args) { + console.warn("process.runCmd interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return ChildProcessMock; + }, + abort: function(...args) { + console.warn("process.abort 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("process.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("process.off interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + exit: function(...args) { + console.warn("process.exit interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + cwd: function(...args) { + console.warn("process.cwd interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramStringMock; + }, + chdir: function(...args) { + console.warn("process.chdir interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + uptime: function(...args) { + console.warn("process.uptime interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + kill: function(...args) { + console.warn("process.kill interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + getEgid: '[PC preview] unknow getEgid', + getEuid: '[PC preview] unknow getEuid', + getGid: '[PC preview] unknow getGid', + getUid: '[PC preview] unknow getUid', + getGroups: '[PC preview] unknow getGroups', + getPid: '[PC preview] unknow getPid', + getPpid: '[PC preview] unknow getPpid', + + } + const ChildProcessMock = { + pid: '[PC preview] unknow pid', + ppid: '[PC preview] unknow ppid', + exitCode: '[PC preview] unknow exitCode', + killed: '[PC preview] unknow killed', + wait: function(...args) { + console.warn("ChildProcess.wait interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + }, + getOutput: function(...args) { + console.warn("ChildProcess.getOutput interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const arr = new Uint8Array() + return new Promise((resolve, reject) => { + resolve(arr); + }) + }, + getErrorOutput: function(...args) { + console.warn("ChildProcess.getErrorOutput interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const arr = new Uint8Array() + return new Promise((resolve, reject) => { + resolve(arr); + }) + }, + close: function (...args) { + console.warn("ChildProcess.close interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + kill: function (...args) { + console.warn("ChildProcess.kill interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + } + } + return result; +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/rpc.js b/runtime/main/extend/systemplugin/napi/rpc.js new file mode 100644 index 00000000..284d57f8 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/rpc.js @@ -0,0 +1,424 @@ +import { paramMock } from "../utils" + +export function mockRpc() { + const MessageParcel = { + reclaim: function () { + console.warn("rpc.reclaim interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + writeRemoteObject: function (...args) { + console.warn("rpc.writeRemoteObject interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + readRemoteObject: function () { + console.warn("rpc.readRemoteObject interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return IRemoteObject + }, + writeInterfaceToken: function (...args) { + console.warn("rpc.writeInterfaceToken interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + readInterfaceToken: function () { + console.warn("rpc.readInterfaceToken interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramStringMock + }, + getSize: function () { + console.warn("rpc.getSize interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + getCapacity: function () { + console.warn("rpc.getCapacity interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + setSize: function (...args) { + console.warn("rpc.setSize interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + setCapacity: function (...args) { + console.warn("rpc.setCapacity interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + getWritableBytes: function () { + console.warn("rpc.getWritableBytes interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + getReadableBytes: function () { + console.warn("rpc.getReadableBytes interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + getReadPosition: function () { + console.warn("rpc.getReadPosition interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + getWritePosition: function () { + console.warn("rpc.getWritePosition interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + rewindRead: function (...args) { + console.warn("rpc.rewindRead interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + rewindWrite: function (...args) { + console.warn("rpc.rewindWrite interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeByte: function (...args) { + console.warn("rpc.writeByte interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeShort: function (...args) { + console.warn("rpc.writeShort interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeInt: function (...args) { + console.warn("rpc.writeInt interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeLong: function (...args) { + console.warn("rpc.writeLong interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeFloat: function (...args) { + console.warn("rpc.writeFloat interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeDouble: function (...args) { + console.warn("rpc.writeDouble interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeBoolean: function (...args) { + console.warn("rpc.writeBoolean interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeChar: function (...args) { + console.warn("rpc.writeChar interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeString: function (...args) { + console.warn("rpc.writeString interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeSequenceable: function (...args) { + console.warn("rpc.writeSequenceable interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeByteArray: function (...args) { + console.warn("rpc.writeByteArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeShortArray: function (...args) { + console.warn("rpc.writeShortArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeIntArray: function (...args) { + console.warn("rpc.writeIntArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeLongArray: function (...args) { + console.warn("rpc.writeLongArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeFloatArray: function (...args) { + console.warn("rpc.writeFloatArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeDoubleArray: function (...args) { + console.warn("rpc.writeDoubleArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeBooleanArray: function (...args) { + console.warn("rpc.writeBooleanArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeCharArray: function (...args) { + console.warn("rpc.writeCharArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeStringArray: function (...args) { + console.warn("rpc.writeStringArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + writeSequenceableArray: function (...args) { + console.warn("rpc.writeSequenceableArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + readByte: function () { + console.warn("rpc.readByte interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + readShort: function () { + console.warn("rpc.readShort interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + readInt: function () { + console.warn("rpc.readInt interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + readLong: function () { + console.warn("rpc.readLong interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + readFloat: function () { + console.warn("rpc.readFloat interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + readDouble: function () { + console.warn("rpc.readDouble interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + readBoolean: function () { + console.warn("rpc.readBoolean interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + readChar: function () { + console.warn("rpc.readChar interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + readString: function () { + console.warn("rpc.readString interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramStringMock + }, + readSequenceable: function (...args) { + console.warn("rpc.readSequenceable interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + readByteArray: function () { + console.warn("rpc.readByteArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramArrayMock; + }, + readShortArray: function () { + console.warn("rpc.readShortArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramArrayMock; + }, + readIntArray: function () { + console.warn("rpc.readIntArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramArrayMock; + }, + readLongArray: function () { + console.warn("rpc.readLongArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramArrayMock; + }, + readFloatArray: function () { + console.warn("rpc.readFloatArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramArrayMock; + }, + readDoubleArray: function () { + console.warn("rpc.readDoubleArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramArrayMock; + }, + readBooleanArray: function () { + console.warn("rpc.readBooleanArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramArrayMock; + }, + readCharArray: function () { + console.warn("rpc.readCharArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramArrayMock; + }, + readStringArray: function () { + console.warn("rpc.readStringArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramArrayMock; + } + }; + const IRemoteObject = { + queryLocalInterface: function (...args) { + console.warn("rpc.queryLocalInterface interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return IRemoteBroker + }, + sendRequest: function (...args) { + console.warn("rpc.sendRequest interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + addDeathRecipient: function (...args) { + console.warn("rpc.addDeathRecipient interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + removeDeathRecipient: function (...args) { + console.warn("rpc.removeDeathRecipient interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + getInterfaceDescriptor: function () { + console.warn("rpc.getInterfaceDescriptor interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramStringMock + }, + isObjectDead: function () { + console.warn("rpc.isObjectDead interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + } + }; + const IRemoteBroker = { + asObject: function () { + console.warn("rpc.asObject interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return IRemoteObject + } + }; + const RemoteProxy = { + queryLocalInterface: function (...args) { + console.warn("rpc.queryLocalInterface interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return IRemoteObject + }, + addDeathRecipient: function (...args) { + console.warn("rpc.addDeathRecipient interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + removeDeathRecipient: function (...args) { + console.warn("rpc.removeDeathRecipient interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + getInterfaceDescriptor: function () { + console.warn("rpc.getInterfaceDescriptor interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramStringMock + }, + sendRequest: function (...args) { + console.warn("rpc.sendRequest interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + isObjectDead: function () { + console.warn("rpc.isObjectDead interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + } + }; + const rpc = { + MessageParcel: { + create: function () { + console.warn("rpc.create interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return MessageParcel + } + }, + MessageOption: { + flags: '[PC preview] unknow flags', + waitTime: '[PC preview] unknow waitTime' + }, + RemoteProxy: RemoteProxy, + IPCSkeleton: { + getContextObject: function () { + console.warn("rpc.getContextObject interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return IRemoteObject + }, + getCallingPid: function () { + console.warn("rpc.getCallingPid interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + getCallingUid: function () { + console.warn("rpc.getCallingUid interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + getCallingDeviceID: function () { + console.warn("rpc.getCallingDeviceID interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramStringMock + }, + getLocalDeviceID: function () { + console.warn("rpc.getLocalDeviceID interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramStringMock + }, + getLocalAbility: function () { + console.warn("rpc.getLocalAbility interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return RemoteProxy + }, + isLocalCalling: function () { + console.warn("rpc.isLocalCalling interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + flushCommands: function (...args) { + console.warn("rpc.flushCommands interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + resetCallingIdentity: function () { + console.warn("rpc.resetCallingIdentity interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramStringMock + }, + setCallingIdentity: function (...args) { + console.warn("rpc.setCallingIdentity interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + } + }, + RemoteObject: { + onRemoteRequest: function (...args) { + console.warn("rpc.onRemoteRequest interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + attachLocalInterface: function (...args) { + console.warn("rpc.attachLocalInterface interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + } + } + } + return rpc +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/runningLock.js b/runtime/main/extend/systemplugin/napi/runningLock.js index e7c886d5..6494a1ec 100644 --- a/runtime/main/extend/systemplugin/napi/runningLock.js +++ b/runtime/main/extend/systemplugin/napi/runningLock.js @@ -16,7 +16,12 @@ export function mockRunningLock() { " may be different from that on a real device.") } }; + const RunningLockType = { + BACKGROUND : '[PC Preview] unknow BACKGROUND', + PROXIMITY_SCREEN_CONTROL : '[PC Preview] unknow PROXIMITY_SCREEN_CONTROL' + }; const runningLock = { + RunningLockType, isRunningLockTypeSupported: function (...args) { console.warn("runningLock.isRunningLockTypeSupported interface mocked in the Previewer. How this interface works on the" + " Previewer may be different from that on a real device.") @@ -43,4 +48,4 @@ export function mockRunningLock() { } } return runningLock -} \ No newline at end of file +} diff --git a/runtime/main/extend/systemplugin/napi/url.js b/runtime/main/extend/systemplugin/napi/url.js new file mode 100644 index 00000000..0a1e8e56 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/url.js @@ -0,0 +1,104 @@ +import { paramMock } from "../utils" + +export function mockUrl() { + const result = { + URLSearchParams: function(...args) { + console.warn("url.URLSearchParams interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return URLSearchParamsMock; + }, + URL: function(...args) { + console.warn("url.URL interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return URLMock; + } + } + const URLSearchParamsMock = { + append: function(...args) { + console.warn("URLSearchParams.append interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + delete: function(...args) { + console.warn("URLSearchParams.delete interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + getAll: function(...args) { + console.warn("URLSearchParams.getAll interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + var arrStr = new Array() + return arrStr; + }, + entries: function(...args) { + console.warn("URLSearchParams.entries interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramObjectMock; + }, + forEach: function(...args) { + console.warn("URLSearchParams.forEach interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + get: function(...args) { + console.warn("URLSearchParams.get interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramStringMock; + }, + has: function(...args) { + console.warn("URLSearchParams.has interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + set: function(...args) { + console.warn("URLSearchParams.set interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + sort: function(...args) { + console.warn("URLSearchParams.sort interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + keys: function(...args) { + console.warn("URLSearchParams.keys interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramObjectMock; + }, + values: function(...args) { + console.warn("URLSearchParams.values interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramObjectMock; + }, + [Symbol.iterator]: function(...args) { + console.warn("URLSearchParams.[Symbol.iterator] interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramObjectMock; + }, + toString: function(...args) { + console.warn("URLSearchParams.toString interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramStringMock; + } + } + const URLMock = { + toString: function(...args) { + console.warn("URLSearchParams.toString interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramStringMock; + }, + toJSON: function(...args) { + console.warn("URLSearchParams.toJSON interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramStringMock; + }, + hash: '[PC preview] unknow hash', + host: '[PC preview] unknow host', + hostname: '[PC preview] unknow hostname', + href: '[PC preview] unknow href', + origin: '[PC preview] unknow origin', + password: '[PC preview] unknow password', + pathname: '[PC preview] unknow pathname', + port: '[PC preview] unknow port', + protocol: '[PC preview] unknow protocol', + search: '[PC preview] unknow search', + searchParams: URLSearchParamsMock, + username: '[PC preview] unknow username', + } + return result; +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/util.js b/runtime/main/extend/systemplugin/napi/util.js index 85f8d34f..28d1ec17 100644 --- a/runtime/main/extend/systemplugin/napi/util.js +++ b/runtime/main/extend/systemplugin/napi/util.js @@ -2,6 +2,25 @@ import { paramMock } from "../utils" export function mockUtil() { const result = { + printf: function(...args) { + console.warn("util.printf interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramStringMock; + }, + getErrorString: function(...args) { + console.warn("util.getErrorString interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramStringMock; + }, + callbackWrapper: function(...args) { + console.warn("util.callbackWrapper interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }, + promiseWrapper: function(...args) { + console.warn("util.promiseWrapper interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramObjectMock; + }, TextDecoder: function(...args) { console.warn("util.TextDecoder interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") @@ -28,7 +47,8 @@ export function mockUtil() { encode: function(...args) { console.warn("TextEncoder.encode interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") - return paramMock.paramArrayMock; + const arr = new Uint8Array() + return arr; }, encodeInto: function(...args) { console.warn("TextEncoder.encodeInto interface mocked in the Previewer. How this interface works on the Previewer" + diff --git a/runtime/main/extend/systemplugin/napi/webgl.js b/runtime/main/extend/systemplugin/napi/webgl.js new file mode 100644 index 00000000..f7fab3f4 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/webgl.js @@ -0,0 +1,739 @@ +import { paramMock } from "../utils" + +export function mockwebgl() { + + const WebGLContextAttributes ={ + brightness: '[PC preview] unknow brightness', + alpha: '[PC preview] unknow alpha', + depth: '[PC preview] unknow depth', + stencil: '[PC preview] unknow stencil', + antialias: '[PC preview] unknow antialias', + premultipliedAlpha: '[PC preview] unknow premultipliedAlpha', + preserveDrawingBuffer: '[PC preview] unknow preserveDrawingBuffer', + powerPreference: '[PC preview] unknow powerPreference', + failIfMajorPerformanceCaveat: '[PC preview] unknow failIfMajorPerformanceCaveat', + desynchronized: '[PC preview] unknow desynchronized' + } + + const float32ArrayWith2val = [ + paramMock.paramNumberMock,paramMock.paramNumberMock + ] + + const float32ArrayWith4val = [ + paramMock.paramNumberMock,paramMock.paramNumberMock,paramMock.paramNumberMock,paramMock.paramNumberMock + ] + const int32ArrayWith2ele = [ + paramMock.paramNumberMock,paramMock.paramNumberMock + ] + const int32ArrayWith4ele = [ + paramMock.paramNumberMock,paramMock.paramNumberMock,paramMock.paramNumberMock,paramMock.paramNumberMock + ] + + const WebGLShaderArray = [ + WebGLShader,WebGLShader,WebGLShader + ] + const WebGLBuffer = { + } + const WebGLFramebuffer = { + } + const WebGLProgram = { + } + const WebGLRenderbuffer = { + } + const WebGLShader = { + } + const WebGLTexture = { + } + const WebGLUniformLocation = { + } + const WebGLActiveInfo = { + size: '[PC preview] unknow size', + type: '[PC preview] unknow type', + name: '[PC preview] unknow name' + } + const WebGLShaderPrecisionFormat = { + rangeMin: '[PC preview] unknow rangeMin', + rangeMax: '[PC preview] unknow rangeMax', + precision: '[PC preview] unknow precision' + } + const webglmock = { + paramDoubleMock: '[PC Preview] unknow double', + paramAnyMock: '[PC Preview] unknow any', + stringArray: '[PC preview] unknow stringArray', + uint32Array: '[PC preview] unknow uint32Array', + glBooleanArray: '[PC preview] unknow glBooleanArray', + WebGLShaderArray: '[PC preview] unknow WebGLShaderArray', + + getContextAttributes: function (...args) { + console.warn("webgl.getContextAttributes interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLContextAttributes + }, + isContextLost: function (...args) { + console.warn("webgl.isContextLost interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock + }, + getSupportedExtensions: function (...args) { + console.warn("webgl.getSupportedExtensions interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return stringarray + }, + getExtension: function (...args) { + console.warn("webgl.getExtension interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramAnyMock + }, + activeTexture: function (...args) { + console.warn("webgl.activeTexture interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + attachShader: function (...args) { + console.warn("webgl.attachShader interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + bindAttribLocation: function (...args) { + console.warn("webgl.bindAttribLocation interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + bindBuffer: function (...args) { + console.warn("webgl.bindBuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + bindFramebuffer: function (...args) { + console.warn("webgl.bindFramebuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + bindRenderbuffer: function (...args) { + console.warn("webgl.bindRenderbuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + bindTexture: function (...args) { + console.warn("webgl.bindTexture interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + blendColor: function (...args) { + console.warn("webgl.blendColor interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + blendEquation: function (...args) { + console.warn("webgl.blendEquation interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + blendEquationSeparate: function (...args) { + console.warn("webgl.blendEquationSeparate interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + blendFunc: function (...args) { + console.warn("webgl.blendFunc interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + blendFuncSeparate: function (...args) { + console.warn("webgl.blendFuncSeparate interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + checkFramebufferStatus: function (...args) { + console.warn("webgl.checkFramebufferStatus interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + clear: function (...args) { + console.warn("webgl.clear interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + clearColor: function (...args) { + console.warn("webgl.clearColor interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + clearDepth: function (...args) { + console.warn("webgl.clearDepth interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + clearStencil: function (...args) { + console.warn("webgl.clearStencil interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + colorMask: function (...args) { + console.warn("webgl.colorMask interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + compileShader: function (...args) { + console.warn("webgl.compileShader interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + copyTexImage2D: function (...args) { + console.warn("webgl.copyTexImage2D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + copyTexSubImage2D: function (...args) { + console.warn("webgl.copyTexSubImage2D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + createBuffer: function (...args) { + console.warn("webgl.createBuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLBuffer; + }, + createFramebuffer: function (...args) { + console.warn("webgl.createFramebuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLFramebuffer; + }, + createProgram: function (...args) { + console.warn("webgl.createProgram interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLProgram; + }, + createRenderbuffer: function (...args) { + console.warn("webgl.createRenderbuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLRenderbuffer; + }, + createShader: function (...args) { + console.warn("webgl.createShader interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLShader; + }, + + createTexture: function (...args) { + console.warn("webgl.createTexture interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLTexture; + }, + cullFace: function (...args) { + console.warn("webgl.cullFace interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + deleteBuffer: function (...args) { + console.warn("webgl.deleteBuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + deleteFramebuffer: function (...args) { + console.warn("webgl.deleteFramebuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + deleteProgram: function (...args) { + console.warn("webgl.deleteProgram interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + deleteRenderbuffer: function (...args) { + console.warn("webgl.deleteRenderbuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + deleteShader: function (...args) { + console.warn("webgl.deleteRenderbuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + deleteTexture: function (...args) { + console.warn("webgl.deleteRenderbuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + depthFunc: function (...args) { + console.warn("webgl.deleteRenderbuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + depthMask: function (...args) { + console.warn("webgl.deleteRenderbuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + depthRange: function (...args) { + console.warn("webgl.depthRange interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + detachShader: function (...args) { + console.warn("webgl.detachShader interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + disable: function (...args) { + console.warn("webgl.disable interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + disableVertexAttribArray: function (...args) { + console.warn("webgl.disableVertexAttribArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + drawArrays: function (...args) { + console.warn("webgl.drawArrays interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + drawElements: function (...args) { + console.warn("webgl.drawElements interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + enable: function (...args) { + console.warn("webgl.enable interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + enableVertexAttribArray: function (...args) { + console.warn("webgl.enableVertexAttribArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + finish: function (...args) { + console.warn("webgl.finish interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + flush: function (...args) { + console.warn("webgl.flush interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + framebufferRenderbuffer: function (...args) { + console.warn("webgl.framebufferRenderbuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + framebufferTexture2D: function (...args) { + console.warn("webgl.framebufferTexture2D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + frontFace: function (...args) { + console.warn("webgl.frontFace interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + generateMipmap: function (...args) { + console.warn("webgl.generateMipmap interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + getActiveAttrib: function (...args) { + console.warn("webgl.getActiveAttrib interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLActiveInfo; + }, + + getActiveUniform: function (...args) { + console.warn("webgl.getActiveAttrib interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLActiveInfo; + }, + getAttachedShaders: function (...args) { + console.warn("webgl.getActiveAttrib interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLShaderArray; + }, + getAttribLocation: function (...args) { + console.warn("webgl.getActiveAttrib interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + getBufferParameter: function (...args) { + console.warn("webgl.getActiveAttrib interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + getParameter: function (...args) { + console.warn("webgl.getActiveAttrib interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + if (args[0] == 0x0B73 || args[0] == 0x0B21 || + args[0] == 0x8038 || args[0] == 0x2A00 || + args[0] == 0x80AA) { + return paramMock.paramNumberMock;; + } else if (args[0] == 0x8069 || args[0] == 0x8514) { + return WebGLTexture; + } else if (args[0] == 0x1F01 || args[0] == 0x8B8C || + args[0] == 0x1F00 || args[0] == 0x1F02) { + return stringArray; + } else if (args[0] == 0x8894 || args[0] == 0x8895) { + return WebGLBuffer; + } else if (args[0] == 0x8CA6) { + return WebGLFramebuffer; + } else if (args[0] == 0x8B8D) { + return WebGLProgram; + } else if (args[0] == 0x8CA7) { + return WebGLRenderbuffer; + } else if (args[0] == 0x846E || args[0] == 0x846D || + args[0] == 0x0B70) { + return float32ArrayWith2val; + } else if (args[0] == 0x0C22 || args[0] == 0x8005) { + return float32ArrayWith4val; + } else if (args[0] == 0x86A3) { + return uint32Array; + } else if (args[0] == 0x0D3A) { + return int32ArrayWith2ele; + } else if (args[0] == 0x0C10) { + return int32ArrayWith4ele; + } else if (args[0] == 0x0BE2 || args[0] == 0x0B44 || args[0] == 0x0B71 || + args[0] == 0x0B72 || args[0] == 0x0BD0 || args[0] == 0x8037 || + args[0] == 0x809E || args[0] == 0x80A0 || + args[0] == 0x80AB || args[0] == 0x0C11 || args[0] == 0x0B90 || + args[0] == 0x9240 || + args[0] == 0x9241) { + return paramMock.paramBooleanMock; + } else if (args[0] == 0x0C23) { + return glBooleanArray; + } else { + return paramMock.paramNumberMock;; + } + }, + getError: function (...args) { + console.warn("webgl.getError interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + getFramebufferAttachmentParameter: function (...args) { + console.warn("webgl.getFramebufferAttachmentParameter interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + if (args[2] == 0x8CD0 || + args[2] == 0x8CD2 || + args[2] == 0x8CD3 || + args[2] == 0x8215 || + args[2] == 0x8214 || + args[2] == 0x8210 || + args[2] == 0x8211 || + args[2] == 0x8216 || + args[2] == 0x8213 || + args[2] == 0x8212 || + args[2] == 0x8217 || + args[2] == 0x8CD4) { + return paramMock.paramNumberMock; + } else if (args[2] == 0x8CD1) { + return paramMock.paramObjectMock; + } + }, + getProgramParameter: function (...args) { + console.warn("webgl.getProgramParameter interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + if (args[1] == 0x8B80 || args[1] == 0x8B82 || args[1] == 0x8B83) { + return paramMock.paramBooleanMock; + } else { + return paramMock.paramNumberMock; + } + }, + getProgramInfoLog: function (...args) { + console.warn("webgl.getProgramInfoLog interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramStringMock; + }, + getRenderbufferParameter: function (...args) { + console.warn("webgl.getRenderbufferParameter interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + + getShaderParameter: function (...args) { + console.warn("webgl.getShaderParameter interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + if (args[1] == 0x8B4F) { + return paramMock.paramNumberMock; + } else { + return paramMock.paramBooleanMock; + } + }, + getShaderPrecisionFormat: function (...args) { + console.warn("webgl.getShaderPrecisionFormat interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLShaderPrecisionFormat; + }, + getShaderInfoLog: function (...args) { + console.warn("webgl.getShaderInfoLog interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramStringMock; + }, + getShaderSource: function (...args) { + console.warn("webgl.getShaderSource interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramStringMock; + }, + getTexParameter: function (...args) { + console.warn("webgl.getTexParameter interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + if (args[1] == 0x84FE) { + return paramMock.paramDoubleMock; + } else { + return paramMock.paramNumberMock; + } + }, + + getUniform: function (...args) { + console.warn("webgl.getUniform interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramAnyMock; + }, + getUniformLocation: function (...args) { + console.warn("webgl.getUniformLocation interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLUniformLocation; + }, + getVertexAttrib: function (...args) { + console.warn("webgl.getVertexAttrib interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + getVertexAttribOffset: function (...args) { + console.warn("webgl.getVertexAttribOffset interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + hint: function (...args) { + console.warn("webgl.hint interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + isBuffer: function (...args) { + console.warn("webgl.isBuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + isEnabled: function (...args) { + console.warn("webgl.isEnabled interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + isFramebuffer: function (...args) { + console.warn("webgl.isFramebuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + isProgram: function (...args) { + console.warn("webgl.isProgram interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + isRenderbuffer: function (...args) { + console.warn("webgl.isRenderbuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + isShader: function (...args) { + console.warn("webgl.isShader interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + isTexture: function (...args) { + console.warn("webgl.isTexture interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + lineWidth: function (...args) { + console.warn("webgl.lineWidth interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + linkProgram: function (...args) { + console.warn("webgl.linkProgram interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + pixelStorei: function (...args) { + console.warn("webgl.pixelStorei interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + polygonOffset: function (...args) { + console.warn("webgl.polygonOffset interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + renderbufferStorage: function (...args) { + console.warn("webgl.renderbufferStorage interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + sampleCoverage: function (...args) { + console.warn("webgl.sampleCoverage interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + scissor: function (...args) { + console.warn("webgl.scissor interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + shaderSource: function (...args) { + console.warn("webgl.shaderSource interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + stencilFunc: function (...args) { + console.warn("webgl.stencilFunc interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + stencilFuncSeparate: function (...args) { + console.warn("webgl.stencilFuncSeparate interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + stencilMask: function (...args) { + console.warn("webgl.stencilMask interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + stencilMaskSeparate: function (...args) { + console.warn("webgl.stencilMaskSeparate interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + stencilOp: function (...args) { + console.warn("webgl.stencilOp interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + stencilOpSeparate: function (...args) { + console.warn("webgl.stencilOpSeparate interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + texParameterf: function (...args) { + console.warn("webgl.texParameterf interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + texParameteri: function (...args) { + console.warn("webgl.texParameteri interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform1f: function (...args) { + console.warn("webgl.uniform1f interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform2f: function (...args) { + console.warn("webgl.uniform2f interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + uniform3f: function (...args) { + console.warn("webgl.uniform3f interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform4f: function (...args) { + console.warn("webgl.uniform4f interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform1i: function (...args) { + console.warn("webgl.uniform1i interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform2i: function (...args) { + console.warn("webgl.uniform2i interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform3i: function (...args) { + console.warn("webgl.uniform3i interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + uniform4i: function (...args) { + console.warn("webgl.uniform4i interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + useProgram: function (...args) { + console.warn("webgl.useProgram interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + validateProgram: function (...args) { + console.warn("webgl.validateProgram interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + vertexAttrib1f: function (...args) { + console.warn("webgl.vertexAttrib1f interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + vertexAttrib2f: function (...args) { + console.warn("webgl.vertexAttrib2f interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + vertexAttrib3f: function (...args) { + console.warn("webgl.vertexAttrib3f interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + vertexAttrib4f: function (...args) { + console.warn("webgl.vertexAttrib4f interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + vertexAttrib1fv: function (...args) { + console.warn("webgl.vertexAttrib1fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + vertexAttrib2fv: function (...args) { + console.warn("webgl.vertexAttrib2fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + vertexAttrib3fv: function (...args) { + console.warn("webgl.vertexAttrib3fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + vertexAttrib4fv: function (...args) { + console.warn("webgl.vertexAttrib4fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + vertexAttribPointer: function (...args) { + console.warn("webgl.vertexAttribPointer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + viewport: function (...args) { + console.warn("webgl.vertexAttrib3fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + bufferData: function (...args) { + console.warn("webgl.bufferData interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + bufferSubData: function (...args) { + console.warn("webgl.bufferSubData interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + compressedTexImage2D: function (...args) { + console.warn("webgl.compressedTexImage2D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + compressedTexSubImage2D: function (...args) { + console.warn("webgl.compressedTexSubImage2D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + readPixels: function (...args) { + console.warn("webgl.readPixels interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + texImage2D: function (...args) { + console.warn("webgl.texImage2D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + texSubImage2D: function (...args) { + console.warn("webgl.texSubImage2D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform1fv: function (...args) { + console.warn("webgl.uniform1fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform2fv: function (...args) { + console.warn("webgl.uniform2fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform3fv: function (...args) { + console.warn("webgl.uniform3fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + uniform4fv: function (...args) { + console.warn("webgl.uniform4fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform1iv: function (...args) { + console.warn("webgl.uniform1iv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform2iv: function (...args) { + console.warn("webgl.uniform2iv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform3iv: function (...args) { + console.warn("webgl.uniform3iv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform4iv: function (...args) { + console.warn("webgl.uniform4iv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + uniformMatrix2fv: function (...args) { + console.warn("webgl.uniformMatrix2fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniformMatrix3fv: function (...args) { + console.warn("webgl.uniformMatrix3fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniformMatrix4fv: function (...args) { + console.warn("webgl.uniformMatrix4fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + } + } + return webglmock +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/webgl2.js b/runtime/main/extend/systemplugin/napi/webgl2.js new file mode 100644 index 00000000..657a8e92 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/webgl2.js @@ -0,0 +1,507 @@ +import { paramMock } from "../utils" + +export function mockwebgl2() { + const WebGLQuery = { + } + const WebGLSampler = { + } + const WebGLSync = { + } + const WebGLTransformFeedback = { + } + const WebGLVertexArrayObject = { + } + + const webgl2Mock = { + paramDoubleMock: '[PC Preview] unknow double', + paramAnyMock: '[PC Preview] unknow any', + stringArray: '[PC preview] unknow stringArray', + uint32Array: '[PC preview] unknow uint32Array', + glBooleanArray: '[PC preview] unknow glBooleanArray', + int32Array: '[PC preview] unknow int32Array', + uintArray: '[PC preview] unknow uintArray', + + copyBufferSubData: function (...args) { + console.warn("webgl.copyBufferSubData interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + getBufferSubData: function (...args) { + console.warn("webgl.getBufferSubData interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + blitFramebuffer: function (...args) { + console.warn("webgl.blitFramebuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + framebufferTextureLayer: function (...args) { + console.warn("webgl.framebufferTextureLayer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + invalidateFramebuffer: function (...args) { + console.warn("webgl.invalidateFramebuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + invalidateSubFramebuffer: function (...args) { + console.warn("webgl.invalidateFramebuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + readBuffer: function (...args) { + console.warn("webgl.readBuffer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + getInternalformatParameter: function (...args) { + console.warn("webgl.getInternalformatParameter interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + if (pname == GL_SAMPLES) { + return int32Array + } + }, + renderbufferStorageMultisample: function (...args) { + console.warn("webgl.renderbufferStorageMultisample interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + texStorage2D: function (...args) { + console.warn("webgl.texStorage2D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + texStorage3D: function (...args) { + console.warn("webgl.texStorage3D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + texImage3D: function (...args) { + console.warn("webgl.texImage3D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + texSubImage3D: function (...args) { + console.warn("webgl.texSubImage3D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + copyTexSubImage3D: function (...args) { + console.warn("webgl.copyTexSubImage3D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + compressedTexImage3D: function (...args) { + console.warn("webgl.compressedTexImage3D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + compressedTexSubImage3D: function (...args) { + console.warn("webgl.compressedTexSubImage3D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + getFragDataLocation: function (...args) { + console.warn("webgl.getFragDataLocation interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + uniform1ui: function (...args) { + console.warn("webgl.uniform1ui interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform2ui: function (...args) { + console.warn("webgl.uniform2ui interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform3ui: function (...args) { + console.warn("webgl.uniform3ui interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + uniform4ui: function (...args) { + console.warn("webgl.uniform4ui interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform1uiv: function (...args) { + console.warn("webgl.uniform1uiv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform2uiv: function (...args) { + console.warn("webgl.uniform2uiv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform3uiv: function (...args) { + console.warn("webgl.uniform3uiv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform4uiv: function (...args) { + console.warn("webgl.uniform4uiv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + uniformMatrix3x2fv: function (...args) { + console.warn("webgl.uniformMatrix3x2fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniformMatrix4x2fv: function (...args) { + console.warn("webgl.uniformMatrix4x2fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniformMatrix2x3fv: function (...args) { + console.warn("webgl.uniformMatrix2x3fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniformMatrix4x3fv: function (...args) { + console.warn("webgl.uniformMatrix4x3fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniformMatrix2x4fv: function (...args) { + console.warn("webgl.uniformMatrix2x4fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + uniformMatrix3x4fv: function (...args) { + console.warn("webgl.uniformMatrix3x4fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + vertexAttribI4i: function (...args) { + console.warn("webgl.vertexAttribI4i interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + vertexAttribI4iv: function (...args) { + console.warn("webgl.vertexAttribI4iv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + vertexAttribI4ui: function (...args) { + console.warn("webgl.vertexAttribI4ui interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + vertexAttribI4uiv: function (...args) { + console.warn("webgl.vertexAttribI4uiv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + vertexAttribIPointer: function (...args) { + console.warn("webgl.vertexAttribIPointer interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + vertexAttribDivisor: function (...args) { + console.warn("webgl.vertexAttribDivisor interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + drawArraysInstanced: function (...args) { + console.warn("webgl.drawArraysInstanced interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + drawElementsInstanced: function (...args) { + console.warn("webgl.drawElementsInstanced interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + drawRangeElements: function (...args) { + console.warn("webgl.drawRangeElements interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + drawBuffers: function (...args) { + console.warn("webgl.drawBuffers interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + clearBufferfv: function (...args) { + console.warn("webgl.clearBufferfv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + clearBufferiv: function (...args) { + console.warn("webgl.clearBufferiv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + clearBufferuiv: function (...args) { + console.warn("webgl.clearBufferuiv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + clearBufferfi: function (...args) { + console.warn("webgl.clearBufferfi interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + createQuery: function (...args) { + console.warn("webgl.createQuery interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLQuery; + }, + deleteQuery: function (...args) { + console.warn("webgl.deleteQuery interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + isQuery: function (...args) { + console.warn("webgl.isQuery interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + beginQuery: function (...args) { + console.warn("webgl.beginQuery interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + endQuery: function (...args) { + console.warn("webgl.endQuery interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + getQuery: function (...args) { + console.warn("webgl2.getQuery interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLQuery; + }, + getQueryParameter: function (...args) { + console.warn("webgl2.getQueryParameter interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + if (args[1] == GL_QUERY_RESULT) { + return paramMock.paramNumberMock; + } else if (args[1] == GL_QUERY_RESULT_AVAILABLE) { + return paramMock.paramBooleanMock; + } + }, + createSampler: function (...args) { + console.warn("webgl2.createSampler interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLSampler; + }, + deleteSampler: function (...args) { + console.warn("webgl2.deleteSampler interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + isSampler: function (...args) { + console.warn("webgl2.isSampler interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + + bindSampler: function (...args) { + console.warn("webgl2.bindSampler interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + samplerParameteri: function (...args) { + console.warn("webgl2.samplerParameteri interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + samplerParameterf: function (...args) { + console.warn("webgl2.samplerParameterf interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + getSamplerParameter: function (...args) { + console.warn("webgl2.getSamplerParameter interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + if (args[1] == GL_TEXTURE_MAX_LOD || pName == GL_TEXTURE_MIN_LOD) { + return paramDoubleMock; + } else { + return paramMock.paramNumberMock; + } + }, + fenceSync: function (...args) { + console.warn("webgl2.fenceSync interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLSync; + }, + + isSync: function (...args) { + console.warn("webgl2.isSync interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + deleteSync: function (...args) { + console.warn("webgl2.deleteSync interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + clientWaitSync: function (...args) { + console.warn("webgl2.clientWaitSync interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + waitSync: function (...args) { + console.warn("webgl2.waitSync interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + getSyncParameter: function (...args) { + console.warn("webgl2.getSyncParameter interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramAnyMock; + }, + + createTransformFeedback: function (...args) { + console.warn("webgl2.createTransformFeedback interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLTransformFeedback; + }, + deleteTransformFeedback: function (...args) { + console.warn("webgl2.deleteTransformFeedback interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + isTransformFeedback: function (...args) { + console.warn("webgl2.isTransformFeedback interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + bindTransformFeedback: function (...args) { + console.warn("webgl2.bindTransformFeedback interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + beginTransformFeedback: function (...args) { + console.warn("webgl2.beginTransformFeedback interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + endTransformFeedback: function (...args) { + console.warn("webgl2.endTransformFeedback interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + transformFeedbackVaryings: function (...args) { + console.warn("webgl2.transformFeedbackVaryings interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + getTransformFeedbackVarying: function (...args) { + console.warn("webgl2.getTransformFeedbackVarying interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLActiveInfo; + }, + pauseTransformFeedback: function (...args) { + console.warn("webgl2.pauseTransformFeedback interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + resumeTransformFeedback: function (...args) { + console.warn("webgl2.resumeTransformFeedback interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + bindBufferBase: function (...args) { + console.warn("webgl2.bindBufferBase interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + bindBufferRange: function (...args) { + console.warn("webgl2.bindBufferRange interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + getIndexedParameter: function (...args) { + console.warn("webgl2.getIndexedParameter interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramAnyMock; + }, + getUniformIndices: function (...args) { + console.warn("webgl2.getUniformIndices interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return uintArray; + }, + getActiveUniforms: function (...args) { + console.warn("webgl2.getActiveUniforms interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramAnyMock; + }, + + getUniformBlockIndex: function (...args) { + console.warn("webgl2.getUniformBlockIndex interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramNumberMock; + }, + getActiveUniformBlockParameter: function (...args) { + console.warn("webgl2.getActiveUniformBlockParameter interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramAnyMock; + }, + getActiveUniformBlockName: function (...args) { + console.warn("webgl2.getActiveUniformBlockName interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramStringMock; + }, + uniformBlockBinding: function (...args) { + console.warn("webgl2.uniformBlockBinding interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + createVertexArray: function (...args) { + console.warn("webgl2.createVertexArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return WebGLVertexArrayObject; + }, + + deleteVertexArray: function (...args) { + console.warn("webgl2.deleteVertexArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + isVertexArray: function (...args) { + console.warn("webgl2.isVertexArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + return paramMock.paramBooleanMock; + }, + bindVertexArray: function (...args) { + console.warn("webgl2.bindVertexArray interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + bufferData: function (...args) { + console.warn("webgl2.bufferData interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + bufferSubData: function (...args) { + console.warn("webgl2.bufferSubData interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + texImage2D: function (...args) { + + console.warn("webgl2.texImage2D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + texSubImage2D: function (...args) { + console.warn("webgl2.texSubImage2D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + compressedTexImage2D: function (...args) { + console.warn("webgl2.compressedTexImage2D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + compressedTexSubImage2D: function (...args) { + console.warn("webgl2.compressedTexSubImage2D interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform1fv: function (...args) { + console.warn("webgl2.uniform1fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform2fv: function (...args) { + console.warn("webgl2.uniform2fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform3fv: function (...args) { + console.warn("webgl2.uniform3fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform4fv: function (...args) { + console.warn("webgl2.uniform4fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + uniform1iv: function (...args) { + console.warn("webgl2.uniform1iv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform2iv: function (...args) { + console.warn("webgl2.uniform2iv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform3iv: function (...args) { + console.warn("webgl2.uniform3iv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniform4iv: function (...args) { + console.warn("webgl2.uniform4iv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniformMatrix2fv: function (...args) { + console.warn("webgl2.uniformMatrix2fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + + uniformMatrix3fv: function (...args) { + console.warn("webgl2.uniformMatrix3fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + uniformMatrix4fv: function (...args) { + console.warn("webgl2.uniformMatrix4fv interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + readPixels: function (...args) { + console.warn("webgl2.readPixels interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + } + } + return webgl2Mock; + +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/net.js b/runtime/main/extend/systemplugin/net.js index dee2f37f..925fadc0 100644 --- a/runtime/main/extend/systemplugin/net.js +++ b/runtime/main/extend/systemplugin/net.js @@ -1,137 +1,499 @@ -import { paramMock } from "./utils" +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); - }) + 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); + } + } } - }, - 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, { - 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, { - code: "[PC Preview] unknow code", - reason: "[PC Preview] unknow reason" - }); - } else if (args[0] == 'error') { - args[len - 1].call(this, paramMock.businessErrorMock); - } - } - } } global.systemplugin.net.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; - } + 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; + } } } export function mockHttp() { - 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); - }) + 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); + } + } + } + global.systemplugin.net.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; + } + } +} + +export function mockMdns() { + const localServiceInfoMock = { + serviceType: "[PC Preview] unknow serviceType", + serviceName: "[PC Preview] unknow serviceName", + host: "[PC Preview] unknow host", + port: "[PC Preview] unknow port" + } + global.systemplugin.net.mdns = { + on: function (...args) { + console.warn("net.mdns.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] === 'serviceAdd') { + args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); + } else if (args[0] === 'serviceRemove') { + args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); + } else if (args[0] === 'serviceStart') { + args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); + } else if (args[0] === 'serviceStop') { + args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); + } else if (args[0] === 'serviceFound') { + args[len - 1].call(this, localServiceInfoMock); + } else if (args[0] === 'serviceLost') { + args[len - 1].call(this, localServiceInfoMock); + } else if (args[0] === 'serviceResolve') { + args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); + } else if (args[0] === 'serviceLost') { + args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); + } else if (args[0] === 'error') { + args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); + } else { + args[len - 1].call(this); + } + } + }, + off: function (...args) { + console.warn("net.mdns.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 (args[0] === 'serviceAdd') { + args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); + } else if (args[0] === 'serviceRemove') { + args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); + } else if (args[0] === 'serviceStart') { + args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); + } else if (args[0] === 'serviceStop') { + args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); + } else if (args[0] === 'serviceFound') { + args[len - 1].call(this, localServiceInfoMock); + } else if (args[0] === 'serviceLost') { + args[len - 1].call(this, localServiceInfoMock); + } else if (args[0] === 'serviceResolve') { + args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); + } else if (args[0] === 'serviceLost') { + args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); + } else if (args[0] === 'error') { + args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0}); + } else { + args[len - 1].call(this); + } + }, + addLocalService: function (...args) { + console.warn("net.mdns.addLocalService interface mocked in the Previewer. How this interface works on the Previewer may" + + " be 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(); + }) + } + }, + removeLocalService: function (...args) { + console.warn("net.mdns.removeLocalService interface mocked in the Previewer. How this interface works on the Previewer may" + + " be 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(); + }) + } + }, + startSearchingMDNS: function (...args) { + console.warn("net.mdns.startSearchingMDNS interface mocked in the Previewer. How this interface works on the Previewer may" + + " be 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(); + }) + } + }, + stopSearchingMDNS: function (...args) { + console.warn("net.mdns.stopSearchingMDNS interface mocked in the Previewer. How this interface works on the Previewer may" + + " be 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 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); + } + } } - }, - 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); + } + + 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); + } + } } - }, - 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); + } + global.systemplugin.net.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; } } } - global.systemplugin.net.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; - } - } -} \ No newline at end of file + diff --git a/runtime/main/extend/systemplugin/ohos/app.js b/runtime/main/extend/systemplugin/ohos/app.js new file mode 100644 index 00000000..611fb6f7 --- /dev/null +++ b/runtime/main/extend/systemplugin/ohos/app.js @@ -0,0 +1,287 @@ +import {paramMock} from "../utils" +import {PixelMapMock} from "../multimedia" + +export function mockAppAbilityManager() { + global.ohosplugin.app = {} + const ActiveProcessInfoMock = { + pid: "[PC Preview] unknow pid", + uid: "[PC Preview] unknow uid", + processName: "[PC Preview] unknow processName", + bundleNames: ["[PC Preview] unknow bundleNames", "[PC Preview] unknow bundleNames"] + } + const ElementNameMock = { + deviceId: "[PC Preview] unknow deviceId", + bundleName: "[PC Preview] unknow bundleName", + abilityName: "[PC Preview] unknow abilityName", + uri: "[PC Preview] unknow uri", + shortName: "[PC Preview] unknow shortName", + } + const AbilityMissionInfoMock = { + missionId: "[PC Preview] unknow missionId", + bottomAbility: { + abilityName: ElementNameMock.abilityName, + bundleName: ElementNameMock.bundleName, + deviceId: ElementNameMock.deviceId + }, + topAbility: { + abilityName: ElementNameMock.abilityName, + bundleName: ElementNameMock.bundleName, + deviceId: ElementNameMock.deviceId + }, + windowMode: "[PC Preview] unknow windowMode" + } + + const ActiveServiceAbilityInfoMock = { + pid: "[PC Preview] unknow pid", + uid: "[PC Preview] unknow uid", + processName: "[PC Preview] unknow processName", + serviceAbility: { + abilityName: ElementNameMock.abilityName, + bundleName: ElementNameMock.bundleName, + deviceId: ElementNameMock.deviceId + } + } + + const ProcessErrorInfoMock = { + errStatus: "[PC Preview] unknow errStatus", + processName: "[PC Preview] unknow processName", + pid: "[PC Preview] unknow pid", + uid: "[PC Preview] unknow uid", + abilityName: "[PC Preview] unknow abilityName", + errMsg: "[PC Preview] unknow errMsg", + backTrace: "[PC Preview] unknow backTrace" + } + const SystemMemoryAttrMock = { + availSysMem: "[PC Preview] unknow availSysMem", + totalSysMem: "[PC Preview] unknow totalSysMem", + threshold: "[PC Preview] unknow threshold", + isSysInlowMem: "[PC Preview] unknow isSysInlowMem" + } + const MissionSnapshotMock = { + topAbility: { + abilityName: ElementNameMock.abilityName, + bundleName: ElementNameMock.bundleName, + deviceId: ElementNameMock.deviceId + }, + snapshot: PixelMapMock + } + const MemoryMapInfoMock = { + vmPss: "[PC Preview] unknow vmPss", + vmPrivateDirty: "[PC Preview] unknow vmPrivateDirty", + vmSharedDirty: "[PC Preview] unknow vmSharedDirty", + nativePss: "[PC Preview] unknow nativePss", + nativePrivateDirty: "[PC Preview] unknow nativePrivateDirty", + nativeSharedDirty: "[PC Preview] unknow nativeSharedDirty", + otherPss: "[PC Preview] unknow otherPss", + otherPrivateDirty: "[PC Preview] unknow otherPrivateDirty", + otherSharedDirty: "[PC Preview] unknow otherSharedDirty" + } + + global.ohosplugin.app.abilityManager = { + getCurrentUserId: function (...args) { + console.warn("app.abilityManager.getCurrentUserId interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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) => { + resolve(paramMock.paramNumberMock) + }) + } + }, + getActiveProcessInfos: function (...args) { + console.warn("app.abilityManager.getActiveProcessInfos interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [ActiveProcessInfoMock]) + } else { + return new Promise((resolve) => { + resolve([ActiveProcessInfoMock]) + }) + } + }, + getActiveAbilityMissionInfos: function (...args) { + console.warn("app.abilityManager.getActiveAbilityMissionInfos interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [AbilityMissionInfoMock]) + } else { + return new Promise((resolve) => { + resolve([AbilityMissionInfoMock]) + }) + } + }, + getPreviousAbilityMissionInfos: function (...args) { + console.warn("app.abilityManager.getPreviousAbilityMissionInfos interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [AbilityMissionInfoMock]) + } else { + return new Promise((resolve) => { + resolve([AbilityMissionInfoMock]) + }) + } + }, + deleteMissions: function (...args) { + console.warn("app.abilityManager.deleteMissions interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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() + }) + } + }, + isUserATestUser: function (...args) { + console.warn("app.abilityManager.isUserATestUser interface mocked in the Previewer. How this interface works on" + + " the Previewer may be 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) => { + resolve(paramMock.paramBooleanMock) + }) + } + }, + getActiveServiceAbilityInfos: function (...args) { + console.warn("app.abilityManager.getActiveServiceAbilityInfos interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [ActiveServiceAbilityInfoMock]) + } else { + return new Promise((resolve) => { + resolve([ActiveServiceAbilityInfoMock]) + }) + } + }, + getHomeScreenIconDenseness: function (...args) { + console.warn("app.abilityManager.getHomeScreenIconDenseness interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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) => { + resolve(paramMock.paramNumberMock) + }) + } + }, + getHomeScreenIconSize: function (...args) { + console.warn("app.abilityManager.getHomeScreenIconSize interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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) => { + resolve(paramMock.paramNumberMock) + }) + } + }, + isMultiWindowAllowed: function (...args) { + console.warn("app.abilityManager.isMultiWindowAllowed interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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) => { + resolve(paramMock.paramBooleanMock) + }) + } + }, + moveMissionToFirstSplitScreen: function (...args) { + console.warn("app.abilityManager.moveMissionToFirstSplitScreen interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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() + }) + } + }, + isRamConstrainedDevice: function (...args) { + console.warn("app.abilityManager.isRamConstrainedDevice interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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) => { + resolve(paramMock.paramBooleanMock) + }) + } + }, + getAppMemorySize: function (...args) { + console.warn("app.abilityManager.getAppMemorySize interface mocked in the Previewer. How this interface works" + + " on the Previewer may be 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) => { + resolve(paramMock.paramNumberMock) + }) + } + }, + getProcessMemoryMapInfos: function (...args) { + console.warn("app.abilityManager.getProcessMemoryMapInfos interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [MemoryMapInfoMock]) + } else { + return new Promise((resolve) => { + resolve([MemoryMapInfoMock]) + }) + } + }, + + getSystemMemoryAttr: function (...args) { + console.warn("app.abilityManager.getSystemMemoryAttr interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, SystemMemoryAttrMock) + } else { + return new Promise((resolve) => { + resolve(SystemMemoryAttrMock) + }) + } + }, + getProcessErrorInfos: function (...args) { + console.warn("app.abilityManager.getProcessErrorInfos interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [ProcessErrorInfoMock]) + } else { + return new Promise((resolve) => { + resolve([ProcessErrorInfoMock]) + }) + } + }, + getAbilityMissionSnapshot: function (...args) { + console.warn("app.abilityManager.getAbilityMissionSnapshot interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, MissionSnapshotMock) + } else { + return new Promise((resolve) => { + resolve(MissionSnapshotMock) + }) + } + } + } +} diff --git a/runtime/main/extend/systemplugin/ohos/backgroundTaskManager.js b/runtime/main/extend/systemplugin/ohos/backgroundTaskManager.js new file mode 100644 index 00000000..ac34645f --- /dev/null +++ b/runtime/main/extend/systemplugin/ohos/backgroundTaskManager.js @@ -0,0 +1,35 @@ +import { paramMock } from "../utils" + +export function mockBackgroundTaskManager () { + const DelaySuspendInfoMock = { + requestId : '[PC preview] unknown requestId', + actualDelayTime: '[PC preview] unknown actualDelayTime', + } + global.ohosplugin.backgroundTaskManager = { + requestSuspendDelay: function (...args) { + console.warn("backgroundTaskManager.requestSuspendDelay interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + return DelaySuspendInfoMock; + } + }, + cancelSuspendDelay: function (...args) { + console.warn("backgroundTaskManager.cancelSuspendDelay interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + getRemainingDelayTime: function (...args) { + console.warn("backgroundTaskManager.getRemainingDelayTime interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, DelaySuspendInfoMock.actualDelayTime) + } else { + return new Promise((resolve) => { + resolve(DelaySuspendInfoMock.actualDelayTime) + }); + } + } + } +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/ohos/commonEvent.js b/runtime/main/extend/systemplugin/ohos/commonEvent.js new file mode 100644 index 00000000..ed5c9139 --- /dev/null +++ b/runtime/main/extend/systemplugin/ohos/commonEvent.js @@ -0,0 +1,189 @@ +import {paramMock} from "../utils" + +export function mockCommonEvent() { + const CommonEventSubscriberMock = { + getCode: function (...args) { + console.warn("CommonEventSubscriber.getCode interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramNumberMock); + }); + } + }, + setCode: function (...args) { + console.warn("CommonEventSubscriber.setCode interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + getData: function (...args) { + console.warn("CommonEventSubscriber.getData interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramStringMock); + }); + } + }, + setData: function (...args) { + console.warn("CommonEventSubscriber.setData interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + setCodeAndData: function (...args) { + console.warn("CommonEventSubscriber.setCodeAndData interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + isOrderedCommonEvent: function (...args) { + console.warn("CommonEventSubscriber.isOrderedCommonEvent interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramBooleanMock); + }); + } + }, + isStickyCommonEvent: function (...args) { + console.warn("CommonEventSubscriber.isStickyCommonEvent interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramBooleanMock); + }); + } + }, + abortCommonEvent: function (...args) { + console.warn("CommonEventSubscriber.abortCommonEvent interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + clearAbortCommonEvent: function (...args) { + console.warn("CommonEventSubscriber.clearAbortCommonEvent interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + getAbortCommonEvent: function (...args) { + console.warn("CommonEventSubscriber.getAbortCommonEvent interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramBooleanMock); + }); + } + }, + getSubscribeInfo: function (...args) { + console.warn("CommonEventSubscriber.getSubscribeInfo interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, CommonEventSubscribeInfoMock); + } else { + return new Promise((resolve) => { + resolve(CommonEventSubscribeInfoMock); + }); + } + } + } + const CommonEventDataMock = { + event: '[PC preview] unknow event', + bundleName: '[PC preview] unknow bundleName', + code: '[PC preview] unknow code', + data: '[PC preview] unknow data', + } + const CommonEventSubscribeInfoMock = { + events: '[PC preview] unknow events', + publisherPermission: '[PC preview] unknow publisherPermission', + publisherDeviceId: '[PC preview] unknow publisherDeviceId', + userId: '[PC preview] unknow userId', + priority: '[PC preview] unknow priority', + } + global.ohosplugin.commonEvent = { + publish: function (...args) { + console.warn("commonEvent.publish interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } + }, + createSubscriber: function (...args) { + console.warn("commonEvent.createSubscriber interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, CommonEventSubscriberMock); + } else { + return new Promise((resolve) => { + resolve(CommonEventSubscriberMock); + }); + } + }, + subscribe: function (...args) { + console.warn("commonEvent.subscribe interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, CommonEventDataMock); + } + }, + unsubscribe: function (...args) { + console.warn("commonEvent.subscribe interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } + }, + } + +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/ohos/notification.js b/runtime/main/extend/systemplugin/ohos/notification.js new file mode 100644 index 00000000..cc25e4d1 --- /dev/null +++ b/runtime/main/extend/systemplugin/ohos/notification.js @@ -0,0 +1,324 @@ +import {paramMock} from "../utils" + +export function mockOhosNotification() { + const NotificationSlotMock = { + type: '[PC preview] unknow type', + level: '[PC preview] unknow level', + desc: '[PC preview] unknow desc', + badgeFlag: '[PC preview] unknow badgeFlag', + bypassDnd: '[PC preview] unknow bypassDnd', + lockscreenVisibility: '[PC preview] unknow lockscreenVisibility', + vibrationEnabled: '[PC preview] unknow vibrationEnabled', + sound: '[PC preview] unknow sound', + lightEnabled: '[PC preview] unknow lightEnabled', + lightColor: '[PC preview] unknow lightColor', + vibrationValues: '[PC preview] unknow vibrationValues' + } + const NotificationRequestMock = { + content: '[PC preview] unknow content', + id: '[PC preview] unknow id', + slotType: '[PC preview] unknow slotType', + isOngoing: '[PC preview] unknow isOngoing', + isUnremovable: '[PC preview] unknow isUnremovable', + deliveryTime: '[PC preview] unknow deliveryTime', + tapDismissed: '[PC preview] unknow tapDismissed', + autoDeletedTime: '[PC preview] unknow autoDeletedTime', + wantAgent: '[PC preview] unknow wantAgent', + extraInfo: '[PC preview] unknow extraInfo', + color: '[PC preview] unknow color', + colorEnabled: '[PC preview] unknow colorEnabled', + isAlertOnce: '[PC preview] unknow isAlertOnce', + isStopwatch: '[PC preview] unknow isStopwatch', + isCountDown: '[PC preview] unknow isCountDown', + isFloatingIcon: '[PC preview] unknow isFloatingIcon', + label: '[PC preview] unknow label', + badgeIconStyle: '[PC preview] unknow badgeIconStyle', + showDeliveryTime: '[PC preview] unknow showDeliveryTime', + actionButtons: '[PC preview] unknow actionButtons', + creatorBundleName: '[PC preview] unknow creatorBundleName', + creatorUid: '[PC preview] unknow creatorUid', + creatorPid: '[PC preview] unknow creatorPid', + classification: '[PC preview] unknow classification', + hashCode: '[PC preview] unknow hashCode', + } + global.ohosplugin.notification = { + publish: function (...args) { + console.warn("notification.publish interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + cancel: function (...args) { + console.warn("notification.cancel interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + cancelAll: function (...args) { + console.warn("notification.cancelAll interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + addSlot: function (...args) { + console.warn("notification.addSlot interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + addSlots: function (...args) { + console.warn("notification.addSlots interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + getSlot: function (...args) { + console.warn("notification.getSlot interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, NotificationSlotMock); + } else { + return new Promise((resolve) => { + resolve(NotificationSlotMock); + }); + } + }, + getSlots: function (...args) { + console.warn("notification.getSlots interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [NotificationSlotMock]); + } else { + return new Promise((resolve) => { + resolve([NotificationSlotMock]); + }); + } + }, + removeSlot: function (...args) { + console.warn("notification.removeSlot interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + removeAllSlots: function (...args) { + console.warn("notification.removeAllSlots interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + subscribe: function (...args) { + console.warn("notification.subscribe interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + unsubscribe: function (...args) { + console.warn("notification.unsubscribe interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + enableNotification: function (...args) { + console.warn("notification.enableNotification interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + isNotificationEnabled: function (...args) { + console.warn("notification.isNotificationEnabled interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramBooleanMock); + }); + } + }, + displayBadge: function (...args) { + console.warn("notification.displayBadge interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + isBadgeDisplayed: function (...args) { + console.warn("notification.isBadgeDisplayed interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramBooleanMock); + }); + } + }, + setSlotByBundle: function (...args) { + console.warn("notification.setSlotByBundle interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + getSlotsByBundle: function (...args) { + console.warn("notification.getSlotsByBundle interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [NotificationSlotMock]); + } else { + return new Promise((resolve) => { + resolve([NotificationSlotMock]); + }); + } + }, + getSlotNumByBundle: function (...args) { + console.warn("notification.getSlotNumByBundle interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramStringMock); + }); + } + }, + remove: function (...args) { + console.warn("notification.remove interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + removeAll: function (...args) { + console.warn("notification.removeAll interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }); + } + }, + getAllActiveNotifications: function (...args) { + console.warn("notification.getAllActiveNotifications interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [NotificationRequestMock]); + } else { + return new Promise((resolve) => { + resolve([NotificationRequestMock]); + }); + } + }, + getActiveNotificationCount: function (...args) { + console.warn("notification.getActiveNotificationCount interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramNumberMock); + }); + } + }, + getActiveNotifications: function (...args) { + console.warn("notification.getActiveNotifications interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [NotificationRequestMock]); + } else { + return new Promise((resolve) => { + resolve([NotificationRequestMock]); + }); + } + }, + } +} + + diff --git a/runtime/main/extend/systemplugin/ohos/storageInfoManager.js b/runtime/main/extend/systemplugin/ohos/storageInfoManager.js new file mode 100644 index 00000000..6394e334 --- /dev/null +++ b/runtime/main/extend/systemplugin/ohos/storageInfoManager.js @@ -0,0 +1,63 @@ +import { paramMock } from "../utils" + +export function mockStorageInfoManager () { + const infoMock = { + storageInfo: { + appSize: 472897, + cacheSize: 483, + dataSize: 32543 + }, + totalSize: 12800000, + freeSize: 23700000, + } + global.ohosplugin.storageInfoManager = { + queryInfoByPackageName: function (...args) { + console.warn("storageInfoManager.queryInfoByPackageName interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, infoMock.storageInfo); + } else { + return new Promise((resolve) => { + resolve(infoMock.storageInfo); + }) + } + }, + getTotalSize: function (...args) { + console.warn("storageInfoManager.getTotalSize interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, infoMock.totalSize); + } else { + return new Promise((resolve) => { + resolve(infoMock.totalSize); + }) + } + }, + getFreeSize: function (...args) { + console.warn("storageInfoManager.getFreeSize interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, infoMock.freeSize); + } else { + return new Promise((resolve) => { + resolve(infoMock.freeSize); + }) + } + }, + queryInfoByUid: function (...args) { + console.warn("storageInfoManager.queryInfoByUid interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, infoMock.storageInfo); + } else { + return new Promise((resolve) => { + resolve(infoMock.storageInfo); + }) + } + }, + } +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/resourceManager.js b/runtime/main/extend/systemplugin/resourceManager.js new file mode 100644 index 00000000..8c1a1b31 --- /dev/null +++ b/runtime/main/extend/systemplugin/resourceManager.js @@ -0,0 +1,202 @@ +/* + * 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.getJsonConfig = getJsonConfig; + async function getJsonConfig(resId, callback) { + var data = {"data" : { "name": "mock string1"} }; + console.warn("ResourceManager.getJsonConfig 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.getJsonConfig interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + } +} + +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); + }) + } + }, + getAResourceManager: async function getAResourceManager(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.getAResourceManager 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, + getAResourceManager: resourceManager.getAResourceManager +}; +}; diff --git a/runtime/main/extend/systemplugin/screenLock.js b/runtime/main/extend/systemplugin/screenLock.js new file mode 100644 index 00000000..ce383a8c --- /dev/null +++ b/runtime/main/extend/systemplugin/screenLock.js @@ -0,0 +1,42 @@ +import { paramMock } from "./utils" + +export function mockScreenLock () { + global.systemplugin.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.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramBooleanMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + isSecureMode: function (...args) { + console.warn("screenLock.isSecureMode interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + unlockScreen: function (...args) { + console.warn("screenLock.unlockScreen interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }) + } + } + } +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/screenshot.js b/runtime/main/extend/systemplugin/screenshot.js new file mode 100644 index 00000000..8bcc32f5 --- /dev/null +++ b/runtime/main/extend/systemplugin/screenshot.js @@ -0,0 +1,22 @@ +import { paramMock } from "./utils" + +export function mockScreenshot() { + const screenshotMock = { + ImageSource: '[PC preview] unknow ImageSource' + } + + global.systemplugin.window.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.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, screenshotMock) + } else { + return new Promise((resolve, reject) => { + resolve(screenshotMock) + }) + } + } + } +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/settings.js b/runtime/main/extend/systemplugin/settings.js new file mode 100644 index 00000000..a1e008d1 --- /dev/null +++ b/runtime/main/extend/systemplugin/settings.js @@ -0,0 +1,69 @@ +import { paramMock } from "./utils" + +export function mockSettings () { + const mockInfo = { + URI : "[PC Preview] unknow string" + } + global.systemplugin.settings = { + getURI: function (...args) { + console.warn("settings.getURI interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, mockInfo) + } else { + return new Promise((resolve) => { + resolve(mockInfo); + }) + } + }, + getValue: function (...args) { + console.warn("settings.getValue interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramStringMock); + }) + } + }, + setValue: function (...args) { + console.warn("settings.setValue interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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(); + }) + } + }, + enableAirplaneMode: function (...args) { + console.warn("settings.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) => { + resolve(); + }) + } + }, + canShowFloating: function (...args) { + console.warn("settings.canShowFloating interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + } +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/telephony.js b/runtime/main/extend/systemplugin/telephony.js index f5726781..95f9c208 100644 --- a/runtime/main/extend/systemplugin/telephony.js +++ b/runtime/main/extend/systemplugin/telephony.js @@ -1,19 +1,1633 @@ -import { paramMock } from "./utils" +import {paramMock} from "./utils" export function mockCall() { - 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); - }) - } + 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 TransferNumberInfo = { + status: "[PC Preview] unknow status", + number: "[PC Preview] unknow number", + } + const CallState = "[PC Preview] unknow CallState"; + 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(); + }) + } + }, + getCallTransferNumber: function (...args) { + console.warn("telephony.call.getCallTransferNumber interface mocked in the Previewer. How this interface works on the Previewer may" + + " be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, TransferNumberInfo); + } else { + return new Promise((resolve, reject) => { + resolve(TransferNumberInfo); + }) + } + }, + 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(); + }) + } + } + } +} + +export function mockRadio() { + 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 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 SignalInformation = { + signalType: "[PC Preview] unknow signalType", + signalLevel:"[PC Preview] unknow signalLevel" + } + const NrOptionMode ="[PC Preview] unknow NrOptionMode" + 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" + } + 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); + }) + } + } + } +} + +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", + } + 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.") + return; + }, + 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(); + }) + } + } } - } } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/utils.js b/runtime/main/extend/systemplugin/utils.js index 8b84fe74..1d652d8b 100644 --- a/runtime/main/extend/systemplugin/utils.js +++ b/runtime/main/extend/systemplugin/utils.js @@ -10,12 +10,7 @@ export function getRandomArbitrary(min, max) { } export const paramMock = { - businessErrorMock: { - code: '[PC Preview]: unknow code', - name: '[PC Preview]: unknow name', - message: '[PC Preview]: unknow message', - stack: '[PC Preview]: unknow stack' - }, + businessErrorMock: null, paramNumberMock: "[PC Preview] unknow number", paramStringMock: "[PC Preview] unknow string", paramBooleanMock: "[PC Preview] unknow boolean", diff --git a/runtime/main/extend/systemplugin/window.js b/runtime/main/extend/systemplugin/window.js index 7e460ef2..8c807426 100644 --- a/runtime/main/extend/systemplugin/window.js +++ b/runtime/main/extend/systemplugin/window.js @@ -1,295 +1,323 @@ import { paramMock } from "./utils" +const windowPropertiesMock = { + windowRect:'[PC preview] unknow windowRect', + type:'[PC preview] unknow type', + brightness: '[PC preview] unknow brightness', + isTransparent: '[PC preview] unknow isTransparent', + isFullScreen: '[PC preview] unknow isFullScreen', + isKeepScreenOn: '[PC preview] unknow isKeepScreenOn', + dimBehindValue: '[PC preview] unknow dimBehindValue', + isLayoutFullScreen: '[PC preview] unknow isLayoutFullScreen', + focusable: '[PC preview] unknow focusable', + touchable: '[PC preview] unknow touchable', + isPrivacyMode: '[PC preview] unknow isPrivacyMode', + isRoundCorner: '[PC preview] unknow isRoundCorner' +} +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 AvoidAreaMock = { + leftRect: RectMock, + topRect: RectMock, + rightRect: RectMock, + bottomRect: RectMock +} +export const windowMock = { + setBrightness: function (...args) { + console.warn("Window.setBrightness interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + setBackgroundColor: function (...args) { + console.warn("Window.setBackgroundColor interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + setTransparent: function (...args) { + console.warn("Window.setTransparent interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + setFullScreen: function (...args) { + console.warn("Window.setFullScreen interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + setKeepScreenOn: function (...args) { + console.warn("Window.setKeepScreenOn interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + setDimBehind: function (...args) { + console.warn("Window.setDimBehind interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + setLayoutFullScreen: function (...args) { + console.warn("Window.setLayoutFullScreen interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + setFocusable: function (...args) { + console.warn("Window.setFocusable interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + setTouchable: function (...args) { + console.warn("Window.setTouchable interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + setPrivacyMode: function (...args) { + console.warn("Window.setPrivacyMode interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + setSystemBarEnable: function (...args) { + console.warn("Window.setSystemBarEnable interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + setSystemBarProperties: function (...args) { + console.warn("Window.setSystemBarProperties interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + getProperties: function (...args) { + console.warn("Window.getProperties interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, windowPropertiesMock) + } else { + return new Promise((resolve) => { + resolve(windowPropertiesMock) + }) + } + }, + getAvoidArea: function (...args) { + console.warn("Window.getAvoidArea interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, AvoidAreaMock) + } else { + return new Promise((resolve) => { + resolve(AvoidAreaMock) + }) + } + }, + moveTo: function (...args) { + console.warn("Window.moveTo interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + resetSize: function (...args) { + console.warn("Window.resetSize interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve() + }) + } + }, + hide: function (...args) { + console.warn("Window.hide interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + show: function (...args) { + console.warn("Window.show interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + isShowing: function (...args) { + console.warn("Window.isShowing interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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) => { + resolve(paramMock.paramBooleanMock) + }) + } + }, + destroy: function (...args) { + console.warn("Window.destroy interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + setOutsideTouchable: function (...args) { + console.warn("Window.setOutsideTouchable interface mocked in the Previewer. How this interface works on the" + + " Previewer may be 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() + }) + } + }, + on: function (...args) { + console.warn("Window.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 + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + }, + off: function (...args) { + console.warn("Window.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 + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + }, +} export function mockWindow() { - const windowPropertiesMock = { - brightness: '[PC preview] unknow brightness', - isFullScreen: '[PC preview] unknow isFullScreen', - isKeepScreenOn: '[PC preview] unknow isKeepScreenOn', - isPrivacyMode: '[PC preview] unknow isPrivacyMode', - touchable: '[PC preview] unknow touchable', - focusable: '[PC preview] unknow focusable', - isLayoutFullScreen: '[PC preview] unknow isLayoutFullScreen', - isDimBehind: '[PC preview] unknow isDimBehind', - isTransparent: '[PC preview] unknow isTransparent', - isRoundCorner: '[PC preview] unknow isRoundCorner' + const SizeMock = { + width: '[PC preview] unknow width', + height: '[PC preview] unknow height' } - const AvoidAreaMock = { - left: '[PC preview] unknow Rect.left Rect.top Rect.right Rect.bottom', - top: '[PC preview] unknow Rect.left Rect.top Rect.right Rect.bottom', - right: '[PC preview] unknow Rect.left Rect.top Rect.right Rect.bottom', - bottom: '[PC preview] unknow Rect.left Rect.top Rect.right Rect.bottom' - - } - const windowMock = { - setBrightness: function (...args) { - console.warn("Window.setBrightness interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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() - }) - } - }, - setBackgroundColor: function (...args) { - console.warn("Window.setBackgroundColor interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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() - }) - } - }, - setFullScreen: function (...args) { - console.warn("Window.setFullScreen interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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() - }) - } - }, - setKeepScreenOn: function (...args) { - console.warn("Window.setKeepScreenOn interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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() - }) - } - }, - setSystemBarProperties: function (...args) { - console.warn("Window.setSystemBarProperties interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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() - }) - } - }, - getProperties: function (...args) { - console.warn("Window.getProperties interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, windowPropertiesMock) - } else { - return new Promise((resolve) => { - resolve(windowPropertiesMock) - }) - } - }, - on: function (...args) { - console.warn("Window.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 - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) - }, - off: function (...args) { - console.warn("Window.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 - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) - }, - setSystemBarEnable: function (...args) { - console.warn("Window.setSystemBarEnable interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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() - }) - } - }, - setTransparent: function (...args) { - console.warn("Window.setTransparent interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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() - }) - } - }, - 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() - }) - } - }, - setPrivacyMode: function (...args) { - console.warn("Window.setPrivacyMode interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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() - }) - } - }, - setTouchable: function (...args) { - console.warn("Window.setTouchable interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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() - }) - } - }, - setFocusable: function (...args) { - console.warn("Window.setFocusable interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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() - }) - } - }, - setLayoutFullScreen: function (...args) { - console.warn("Window.setLayoutFullScreen interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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() - }) - } - }, - getAvoidArea: function (...args) { - console.warn("Window.getAvoidArea interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, AvoidAreaMock) - } else { - return new Promise((resolve) => { - resolve(AvoidAreaMock) - }) - } - }, - setDimBehind: function (...args) { - console.warn("Window.setDimBehind interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve) => { - resolve() - }) - } - }, - hide: function (...args) { - console.warn("Window.hide interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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() - }) - } - }, - show: function (...args) { - console.warn("Window.show interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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() - }) - } - }, - isShowing: function (...args) { - console.warn("Window.isShowing interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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) => { - resolve(paramMock.paramBooleanMock) - }) - } - }, - destroy: function (...args) { - console.warn("Window.destroy interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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() - }) - } - }, - setOutsideTouchable: function (...args) { - console.warn("Window.setOutsideTouchable interface mocked in the Previewer. How this interface works on the" + - " Previewer may be 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 getSplitScreenBoundsMock = { + splitMode: '[PC preview] unknow splitMode', + primaryBounds: RectMock, + secondaryBounds: RectMock, } global.systemplugin.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.") + " may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock, windowMock) @@ -301,7 +329,7 @@ export function mockWindow() { }, create: function (...args) { console.warn("Window.create 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, windowMock) @@ -313,7 +341,7 @@ export function mockWindow() { }, find: function (...args) { console.warn("Window.find 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, windowMock) @@ -323,5 +351,53 @@ export function mockWindow() { }) } }, + getWindowMode: function (...args) { + console.warn("Window.getWindowMode interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) + }) + } + }, + getSplitScreenBounds: function (...args) { + console.warn("window.getSplitScreenBounds interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, getSplitScreenBoundsMock) + } else { + return new Promise((resolve, reject) => { + resolve(getSplitScreenBoundsMock) + }) + } + }, + isFloatingAbilityWindowVisible: function (...args) { + console.warn("window.isFloatingAbilityWindowVisible interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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) + }) + } + }, + setSplitBarVisibility: function (...args) { + console.warn("window.setSplitBarVisibility interface mocked in the Previewer. How this interface works on the Previewer" + + " may be 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() + }) + } + } } } \ No newline at end of file diff --git a/runtime/main/model/compiler.ts b/runtime/main/model/compiler.ts index 1e0c653c..de2db03c 100644 --- a/runtime/main/model/compiler.ts +++ b/runtime/main/model/compiler.ts @@ -449,12 +449,13 @@ function compileNativeComponent(vm: Vm, template: TemplateInterface, dest: FragB vm.mediaStatus.width = e.width; vm.mediaStatus.height = e.height; vm.mediaStatus.resolution = e.resolution; - vm.mediaStatus['device-type'] = e.deviceType; - vm.mediaStatus['aspect-ratio'] = e.aspectRatio; - vm.mediaStatus['device-width'] = e.deviceWidth; - vm.mediaStatus['device-height'] = e.deviceHeight; - vm.mediaStatus['round-screen'] = e.roundScreen; - vm.mediaStatus['dark-mode'] = e.darkMode; + vm.mediaStatus['device-type'] = e['device-type']; + vm.mediaStatus['aspect-ratio'] = e['aspect-ratio']; + vm.mediaStatus['device-width'] = e['device-width']; + vm.mediaStatus['device-height'] = e['device-height']; + vm.mediaStatus['round-screen'] = e['round-screen']; + vm.mediaStatus['dark-mode'] = e['dark-mode']; + vm.mediaStatus['api-version'] = e['api-version']; const css = vm.vmOptions && vm.vmOptions.style || {}; const mqArr = css['@MEDIA']; if (!mqArr) { diff --git a/runtime/vdom/Element.ts b/runtime/vdom/Element.ts index f36c673c..23fc9ab4 100644 --- a/runtime/vdom/Element.ts +++ b/runtime/vdom/Element.ts @@ -29,6 +29,9 @@ import { TaskCenter } from '../main/manage/event/TaskCenter'; import { FragBlockInterface } from '../main/model/compiler'; import Vm from '../main/model'; import { CSS_INHERITANCE } from '../main/app/bundle'; +import {interceptCallback} from "../main/manage/event/callbackIntercept"; +import {mockwebgl} from "../main/extend/systemplugin/napi/webgl"; +import {mockwebgl2} from "../main/extend/systemplugin/napi/webgl2"; /** * Element is a basic class to describe a tree node in vdom. @@ -57,6 +60,32 @@ class Element extends Node { super(); const NativeElementClass = NativeElementClassFactory.nativeElementClassMap.get(type); if (NativeElementClass && !isExtended) { + if (global.pcPreview && type === 'canvas') { + Object.defineProperty(NativeElementClass.prototype, 'getContext', { + configurable: true, + enumerable: true, + get: function moduleGetter() { + return (...args: any) => { + const taskCenter = this.getTaskCenter(this.docId); + if (taskCenter) { + // support aceapp callback style + args = interceptCallback(args); + if (args[0] === 'webgl') { + return mockwebgl(); + } else if (args[0] === 'webgl2') { + return mockwebgl2(); + } + const ret = taskCenter.send('component', { + ref: this.ref, + component: type, + method: 'getContext' + }, args); + return ret; + } + }; + } + }); + } return new NativeElementClass(props); }