diff --git a/runtime/main/extend/systemplugin/napi/ohos_sensor.js b/runtime/main/extend/systemplugin/napi/ohos_sensor.js index 46cac30a69d3971b7f543278831d486f31dfb0c6..e364fe13c250c5bcda66c4f369b74dd713e387f0 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_sensor.js +++ b/runtime/main/extend/systemplugin/napi/ohos_sensor.js @@ -168,7 +168,10 @@ export function mockSensor() { firmwareVersion: '[PC preview] unknown firmwareVersion', hardwareVersion: '[PC preview] unknown hardwareVersion', sensorTypeId: '[PC preview] unknown sensorTypeId', + SensorId: '[PC preview] unknown sensorId', maxRange: '[PC preview] unknown maxRange', + minSamplePeriod: '[PC preview] unknown minSamplePeriod', + maxSamplePeriod: '[PC preview] unknown maxSamplePeriod', precision: '[PC preview] unknown precision', power: '[PC preview] unknown power' } @@ -197,9 +200,33 @@ export function mockSensor() { SENSOR_TYPE_ID_WEAR_DETECTION: 280, SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED: 281 } + const SensorId = { + ACCELEROMETER: 1, + GYROSCOPE: 2, + AMBIENT_LIGHT: 5, + MAGNETIC_FIELD: 6, + BAROMETER: 8, + HALL: 10, + PROXIMITY: 12, + HUMIDITY: 13, + ORIENTATION: 256, + GRAVITY: 257, + LINEAR_ACCELERATION: 258, + ROTATION_VECTOR: 259, + AMBIENT_TEMPERATURE: 260, + MAGNETIC_FIELD_UNCALIBRATED: 261, + GYROSCOPE_UNCALIBRATED: 263, + SIGNIFICANT_MOTION: 264, + PEDOMETER_DETECTION: 265, + PEDOMETER: 266, + HEART_RATE: 278, + WEAR_DETECTION: 280, + ACCELEROMETER_UNCALIBRATED: 281 + } const sensor = { Sensor, SensorType, + SensorId, on: function (...args) { console.warn('sensor.on interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.') @@ -313,6 +340,18 @@ export function mockSensor() { }); } }, + getGeomagneticInfo: function (...args) { + console.warn('sensor.getGeomagneticInfo interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.') + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, GeomagneticResponse); + } else { + return new Promise((resolve, reject) => { + resolve(GeomagneticResponse); + }); + } + }, getAltitude: function (...args) { console.warn('sensor.getAltitude interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.') @@ -325,6 +364,18 @@ export function mockSensor() { }); } }, + getDeviceAltitude: function (...args) { + console.warn('sensor.getDeviceAltitude interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be 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); + }); + } + }, getGeomagneticDip: function (...args) { console.warn('sensor.getGeomagneticDip interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.') @@ -337,6 +388,18 @@ export function mockSensor() { }); } }, + getInclination: function (...args) { + console.warn('sensor.getInclination interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be 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); + }); + } + }, getAngleModify: function (...args) { console.warn('sensor.getAngleModifiy interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.') @@ -349,6 +412,18 @@ export function mockSensor() { }); } }, + getAngleVariation: function (...args) { + console.warn('sensor.getAngleVariation interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be 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.paraNumberMock]); + } else { + return new Promise((resolve, reject) => { + resolve([paramMock.paraNumberMock]); + }); + } + }, createRotationMatrix: function (...args) { console.warn('sensor.createRotationMatrix interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.') @@ -369,6 +444,27 @@ export function mockSensor() { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.RotationMatrixResponse); } + }, + getRotationMatrix: function (...args) { + console.warn('sensor.getRotationMatrix interface mocked 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 == 1) { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }); + } else if (len == 2) { + if (typeof args[len - 1] == 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(RotationMatrixResponse); + }); + } + } else if (len == 3) { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.RotationMatrixResponse); + } + }, transformCoordinateSystem: function (...args) { console.warn('sensor.transformCoordinateSystem interface mocked in the Previewer. How this interface works on the' @@ -382,6 +478,18 @@ export function mockSensor() { }); } }, + transformRotationMatrix: function (...args) { + console.warn('sensor.transformRotationMatrix interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be 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.paraNumberMock]); + } else { + return new Promise((resolve, reject) => { + resolve([paramMock.paraNumberMock]); + }); + } + }, createQuaternion: function (...args) { console.warn('sensor.createQuaternion interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.') @@ -394,6 +502,18 @@ export function mockSensor() { }); } }, + getQuaternion: function (...args) { + console.warn('sensor.getQuaternion interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be 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.paraNumberMock]); + } else { + return new Promise((resolve, reject) => { + resolve([paramMock.paraNumberMock]); + }); + } + }, getDirection: function (...args) { console.warn('sensor.getDirection interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.') @@ -406,6 +526,18 @@ export function mockSensor() { }); } }, + getOrientation: function (...args) { + console.warn('sensor.getOrientation interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be 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.paraNumberMock]); + } else { + return new Promise((resolve, reject) => { + resolve([paramMock.paraNumberMock]); + }); + } + }, getSingleSensor: function (...args) { console.warn('sensor.getSingleSensor interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.')