From 20849b23c78c5dde1d2ba1025a62bebbc6594026 Mon Sep 17 00:00:00 2001 From: sunlian Date: Thu, 14 Nov 2024 10:46:02 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=99=E6=80=81=E4=BF=A1=E6=81=AF=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunlian --- .../main/ets/entryability/EntryAbility.ets | 1 + .../src/main/ets/models/TestItemData.ets | 33 ++ OHBM/entry/src/main/ets/pages/BasicInfo.ets | 453 ++++++++++++++++++ OHBM/entry/src/main/ets/pages/Index.ets | 153 +++++- OHBM/entry/src/main/ets/pages/Performance.ets | 39 ++ .../src/main/ets/views/BasicInfoItem.ets | 58 +++ .../entry/src/main/ets/views/TestGridItem.ets | 58 +++ OHBM/entry/src/main/module.json5 | 46 ++ .../resources/base/profile/main_pages.json | 4 +- scenario/MusicPlayerOnline/AppScope/app.json5 | 4 +- .../src/main/ets/manager/PlayerManager.ets | 40 +- 11 files changed, 868 insertions(+), 21 deletions(-) create mode 100644 OHBM/entry/src/main/ets/models/TestItemData.ets create mode 100644 OHBM/entry/src/main/ets/pages/BasicInfo.ets create mode 100644 OHBM/entry/src/main/ets/pages/Performance.ets create mode 100644 OHBM/entry/src/main/ets/views/BasicInfoItem.ets create mode 100644 OHBM/entry/src/main/ets/views/TestGridItem.ets diff --git a/OHBM/entry/src/main/ets/entryability/EntryAbility.ets b/OHBM/entry/src/main/ets/entryability/EntryAbility.ets index 796015d5..8500b1e0 100644 --- a/OHBM/entry/src/main/ets/entryability/EntryAbility.ets +++ b/OHBM/entry/src/main/ets/entryability/EntryAbility.ets @@ -20,6 +20,7 @@ import { window } from '@kit.ArkUI'; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + AppStorage.setOrCreate('APPContext', this.context); } onDestroy(): void { diff --git a/OHBM/entry/src/main/ets/models/TestItemData.ets b/OHBM/entry/src/main/ets/models/TestItemData.ets new file mode 100644 index 00000000..cdbbd6de --- /dev/null +++ b/OHBM/entry/src/main/ets/models/TestItemData.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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. + */ +/** + * List item data entity. + */ + +type OnItemClick = () => void; + +export default class TestItemData { + onItemClick: OnItemClick; + title: string; + img: Resource; + subTitle: string; + + constructor(title: string, img: Resource, subTitle: string, onItemClick: OnItemClick) { + this.title = title; + this.img = img; + this.subTitle = subTitle; + this.onItemClick = onItemClick; + } +} \ No newline at end of file diff --git a/OHBM/entry/src/main/ets/pages/BasicInfo.ets b/OHBM/entry/src/main/ets/pages/BasicInfo.ets new file mode 100644 index 00000000..80bf79ec --- /dev/null +++ b/OHBM/entry/src/main/ets/pages/BasicInfo.ets @@ -0,0 +1,453 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { deviceInfo } from '@kit.BasicServicesKit'; +import { batteryInfo } from '@kit.BasicServicesKit'; +import { sensor } from '@kit.SensorServiceKit'; +import { camera } from '@kit.CameraKit'; +import { common } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +class Item { + name: string = '' + value: string = '' + + constructor(name: string, value: string) { + this.name = name; + this.value = value; + } +} + +@Entry +@Component +struct BasicInfo { + @State deviceInfoArray: Item[] = [] + @State batteryInfoArray: Item[] = [] + @State sensorInfoArray: Item[] = [] + @State cameraInfoArray: Item[] = [] + + aboutToAppear(): void { + this.getDeviceInfo(); + this.getCameraInfo(); + this.getBatteryInfo(); + this.getSensorInfo(); + } + + build() { + Column() { + Text('验机') + .fontSize(32) + .width('100%') + .textAlign(TextAlign.Center) + .margin(16) + Scroll() { + Column() { + Text('设备信息') + .fontSize(24) + .width('100%') + .backgroundColor('#CCCCCC') + .padding(12) + List() { + ForEach(this.deviceInfoArray, (item: Item) => { + ListItem() { + Row() { + Text(item.name) + .fontSize(18) + Text(item.value) + .fontSize(18) + } + .margin({ top: 4, bottom: 4 }) + .justifyContent(FlexAlign.SpaceBetween) + .width('100%') + } + }) + } + .divider({ strokeWidth: 1, color: '#CCCCCC' }) + .width('90%') + + Text('相机') + .fontSize(24) + .width('100%') + .backgroundColor('#CCCCCC') + .padding(12) + List() { + ForEach(this.cameraInfoArray, (item: Item) => { + ListItem() { + Row() { + Text(item.name) + .fontSize(18) + Text(item.value) + .fontSize(18) + } + .margin({ top: 4, bottom: 4 }) + .justifyContent(FlexAlign.SpaceBetween) + .width('100%') + } + }) + } + .divider({ strokeWidth: 1, color: '#CCCCCC' }) + .width('90%') + + Text('电量信息') + .fontSize(24) + .width('100%') + .backgroundColor('#CCCCCC') + .padding(12) + List() { + ForEach(this.batteryInfoArray, (item: Item) => { + ListItem() { + Row() { + Text(item.name) + .fontSize(18) + Text(item.value) + .fontSize(18) + } + .margin({ top: 4, bottom: 4 }) + .justifyContent(FlexAlign.SpaceBetween) + .width('100%') + } + }) + } + .divider({ strokeWidth: 1, color: '#CCCCCC' }) + .width('90%') + + Text('传感器') + .fontSize(24) + .width('100%') + .backgroundColor('#CCCCCC') + .padding(12) + List() { + ForEach(this.sensorInfoArray, (item: Item) => { + ListItem() { + Row() { + Text(item.name) + .fontSize(18) + Text(item.value) + .fontSize(18) + } + .margin({ top: 4, bottom: 4 }) + .justifyContent(FlexAlign.SpaceBetween) + .width('100%') + } + }) + } + .divider({ strokeWidth: 1, color: '#CCCCCC' }) + .width('90%') + } + } + .scrollBar(BarState.Off) + .height('100%') + }.margin({ bottom: 48 }) + } + + getDeviceInfo() { + this.deviceInfoArray = []; + this.deviceInfoArray.push(new Item('deviceType', deviceInfo.deviceType)); + this.deviceInfoArray.push(new Item('manufacture', deviceInfo.manufacture)); + this.deviceInfoArray.push(new Item('brand', deviceInfo.brand)); + this.deviceInfoArray.push(new Item('marketName', deviceInfo.marketName)); + this.deviceInfoArray.push(new Item('productSeries', deviceInfo.productSeries)); + this.deviceInfoArray.push(new Item('productModel', deviceInfo.productModel)); + this.deviceInfoArray.push(new Item('softwareModel', deviceInfo.softwareModel)); + this.deviceInfoArray.push(new Item('hardwareModel', deviceInfo.hardwareModel)); + this.deviceInfoArray.push(new Item('serial', deviceInfo.serial)); + this.deviceInfoArray.push(new Item('bootloaderVersion', deviceInfo.bootloaderVersion)); + this.deviceInfoArray.push(new Item('abiList', deviceInfo.abiList)); + this.deviceInfoArray.push(new Item('securityPatchTag', deviceInfo.securityPatchTag)); + this.deviceInfoArray.push(new Item('displayVersion', deviceInfo.displayVersion)); + this.deviceInfoArray.push(new Item('incrementalVersion', deviceInfo.incrementalVersion)); + this.deviceInfoArray.push(new Item('osReleaseType', deviceInfo.osReleaseType)); + this.deviceInfoArray.push(new Item('osFullName', deviceInfo.osFullName)); + this.deviceInfoArray.push(new Item('majorVersion', deviceInfo.majorVersion.toString())); + this.deviceInfoArray.push(new Item('seniorVersion', deviceInfo.seniorVersion.toString())); + this.deviceInfoArray.push(new Item('featureVersion', deviceInfo.featureVersion.toString())); + this.deviceInfoArray.push(new Item('buildVersion', deviceInfo.buildVersion.toString())); + this.deviceInfoArray.push(new Item('sdkApiVersion', deviceInfo.sdkApiVersion.toString())); + this.deviceInfoArray.push(new Item('firstApiVersion', deviceInfo.firstApiVersion.toString())); + this.deviceInfoArray.push(new Item('buildUser', deviceInfo.buildUser)); + this.deviceInfoArray.push(new Item('buildHost', deviceInfo.buildHost)); + this.deviceInfoArray.push(new Item('buildTime', deviceInfo.buildTime)); + this.deviceInfoArray.push(new Item('buildRootHash', deviceInfo.buildRootHash)); + this.deviceInfoArray.push(new Item('udid', deviceInfo.udid)); + this.deviceInfoArray.push(new Item('distributionOSName', deviceInfo.distributionOSName)); + this.deviceInfoArray.push(new Item('distributionOSVersion', deviceInfo.distributionOSVersion)); + this.deviceInfoArray.push(new Item('distributionOSApiVersion', deviceInfo.distributionOSApiVersion.toString())); + this.deviceInfoArray.push(new Item('distributionOSReleaseType', deviceInfo.distributionOSReleaseType)); + this.deviceInfoArray.push(new Item('ODID', deviceInfo.ODID)); + } + + getCameraInfo() { + let cameraManager = this.getCameraManager(); + let cameras: Array = []; + try { + if (cameraManager !== undefined) { + cameras = cameraManager.getSupportedCameras(); + for (let index = 0; index < cameras.length; index++) { + let element = cameras[index]; + this.cameraInfoArray.push(new Item('ID', element.cameraId)); + this.cameraInfoArray.push(new Item('位置', + `${element.cameraPosition}(0-相机位置未指定,1-后置相机,2-前置相机)`)); + this.cameraInfoArray.push(new Item('类型', + `${element.cameraType}(0-相机类型未指定,1-广角相机,2-超广角相机,3-长焦相机,4-带景深信息的相机)`)); + this.cameraInfoArray.push(new Item('连接类型', + `${element.connectionType}(0-内置相机,1-USB连接的相机,2-远程连接的相机)`)); + this.cameraInfoArray.push(new Item('方向', element.cameraOrientation.toString())); + let modes = this.getSupportedSceneModes(cameraManager, element); + this.cameraInfoArray.push(new Item('modes', `${modes}(1-普通拍照模式,2-普通录像模式,12-安全相机模式)`)); + for (let index = 0; index < modes.length; index++) { + let mode = modes[index]; + let cameraOutputCapability: camera.CameraOutputCapability = + cameraManager.getSupportedOutputCapability(element, mode); + for (let index = 0; index < cameraOutputCapability.previewProfiles.length; index++) { + let previewProfile = cameraOutputCapability.previewProfiles[index]; + this.cameraInfoArray.push(new Item(`mode[${mode}]previewProfiles format:`, + `${previewProfile.format}(3-RGBA_888格式的图片,1003-YUV_420_SP格式的图片,2000-JPEG格式的图片,2001-YCBCR_P010格式的图片,2002-YCRCB_P010格式的图片)`)); + this.cameraInfoArray.push(new Item(`mode[${mode}]previewProfiles size:`, + `${previewProfile.size.width}x${previewProfile.size.height}`)); + } + for (let index = 0; index < cameraOutputCapability.photoProfiles.length; index++) { + let photoProfiles = cameraOutputCapability.photoProfiles[index]; + this.cameraInfoArray.push(new Item(`mode[${mode}]photoProfiles format:`, + photoProfiles.format.toString())); + this.cameraInfoArray.push(new Item(`mode[${mode}]photoProfiles size:`, + `${photoProfiles.size.width}x${photoProfiles.size.height}`)); + } + for (let index = 0; index < cameraOutputCapability.videoProfiles.length; index++) { + let videoProfiles = cameraOutputCapability.videoProfiles[index]; + this.cameraInfoArray.push(new Item(`mode[${mode}]videoProfiles frameRateRange:`, + `${videoProfiles.frameRateRange.min}-${videoProfiles.frameRateRange.max}`)); + this.cameraInfoArray.push(new Item(`mode[${mode}]videoProfiles format:`, + videoProfiles.format.toString())); + this.cameraInfoArray.push(new Item(`mode[${mode}]videoProfiles size:`, + `${videoProfiles.size.width}x${videoProfiles.size.height}`)); + } + for (let index = 0; index < cameraOutputCapability.supportedMetadataObjectTypes.length; index++) { + let supportedMetadataObjectTypes = cameraOutputCapability.supportedMetadataObjectTypes[index]; + this.cameraInfoArray.push(new Item(`mode[${mode}]supportedMetadataObjectTypes:`, + supportedMetadataObjectTypes.toString())); + } + } + } + } + } catch (error) { + let err = error as BusinessError; + console.error(`The getSupportedCameras call failed. error code: ${err.code}`); + } + } + + getSupportedSceneModes(cameraManager: camera.CameraManager, camera: camera.CameraDevice): Array { + let modes: Array = []; + try { + modes = cameraManager.getSupportedSceneModes(camera); + } catch (error) { + let err = error as BusinessError; + console.error(`The getSupportedSceneModes call failed. error code: ${err.code}`); + } + return modes; + } + + getCameraManager(): camera.CameraManager | undefined { + let cameraManager: camera.CameraManager | undefined = undefined; + try { + cameraManager = camera.getCameraManager(AppStorage.get('APPContext') as common.UIAbilityContext); + } catch (error) { + let err = error as BusinessError; + console.error(`The getCameraManager call failed. error code: ${err.code}`); + } + return cameraManager; + } + + getBatteryInfo() { + this.batteryInfoArray = [] + this.batteryInfoArray.push(new Item('batterySOC', batteryInfo.batterySOC.toString())); + this.batteryInfoArray.push(new Item('chargingStatus', batteryInfo.chargingStatus.toString())); + this.batteryInfoArray.push(new Item('healthStatus', batteryInfo.healthStatus.toString())); + this.batteryInfoArray.push(new Item('pluggedType', batteryInfo.pluggedType.toString())); + this.batteryInfoArray.push(new Item('voltage', batteryInfo.voltage.toString())); + this.batteryInfoArray.push(new Item('technology', batteryInfo.technology.toString())); + this.batteryInfoArray.push(new Item('batteryTemperature', batteryInfo.batteryTemperature.toString())); + this.batteryInfoArray.push(new Item('isBatteryPresent', batteryInfo.isBatteryPresent.toString())); + this.batteryInfoArray.push(new Item('batteryCapacityLevel', batteryInfo.batteryCapacityLevel.toString())); + this.batteryInfoArray.push(new Item('nowCurrent', batteryInfo.nowCurrent.toString())); + } + + getSensorInfo() { + this.sensorInfoArray = [] + try { + sensor.once(sensor.SensorId.ACCELEROMETER, (data: sensor.AccelerometerResponse) => { + this.sensorInfoArray.push(new Item('加速度传感器', `x:${data.x},y:${data.y},z:${data.z}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('加速度传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.AMBIENT_LIGHT, (data: sensor.LightResponse) => { + console.info('Succeeded in invoking once. the ambient light intensity: ' + data.intensity); + this.sensorInfoArray.push(new Item('光传感器', `intensity:${data.intensity}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('光传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.AMBIENT_TEMPERATURE, (data: sensor.AmbientTemperatureResponse) => { + this.sensorInfoArray.push(new Item('温度传感器', `temperature:${data.temperature}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('温度传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.BAROMETER, (data: sensor.BarometerResponse) => { + this.sensorInfoArray.push(new Item('气压传感器', `pressure:${data.pressure}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('气压传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.GRAVITY, (data: sensor.GravityResponse) => { + this.sensorInfoArray.push(new Item('重力传感器', `x:${data.x},y:${data.y},z:${data.z}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('重力传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.GYROSCOPE, (data: sensor.GyroscopeResponse) => { + this.sensorInfoArray.push(new Item('陀螺仪传感器', `x:${data.x},y:${data.y},z:${data.z}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('陀螺仪传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.HALL, (data: sensor.HallResponse) => { + this.sensorInfoArray.push(new Item('霍尔传感器', `status:${data.status}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('霍尔传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.HEART_RATE, (data: sensor.HeartRateResponse) => { + this.sensorInfoArray.push(new Item('心率传感器', `heartRate:${data.heartRate}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('心率传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.HUMIDITY, (data: sensor.HumidityResponse) => { + console.info('Succeeded in invoking once. Humidity: ' + data.humidity); + this.sensorInfoArray.push(new Item('湿度传感器', `heartRate:${data.humidity}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('湿度传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.LINEAR_ACCELEROMETER, (data: sensor.LinearAccelerometerResponse) => { + this.sensorInfoArray.push(new Item('线性加速度传感器', `x:${data.x},y:${data.y},z:${data.z}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('线性加速度传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.MAGNETIC_FIELD, (data: sensor.MagneticFieldResponse) => { + this.sensorInfoArray.push(new Item('磁场传感器', `x:${data.x},y:${data.y},z:${data.z}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('磁场传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.ORIENTATION, (data: sensor.OrientationResponse) => { + this.sensorInfoArray.push(new Item('方向传感器', `beta:${data.beta},gamma:${data.gamma},alpha:${data.alpha}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('方向传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.PEDOMETER, (data: sensor.PedometerResponse) => { + this.sensorInfoArray.push(new Item('计步器传感器', `steps:${data.steps}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('计步器传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.PEDOMETER_DETECTION, (data: sensor.PedometerDetectionResponse) => { + this.sensorInfoArray.push(new Item('计步检测器传感器', `scalar:${data.scalar}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('计步检测器传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.PROXIMITY, (data: sensor.ProximityResponse) => { + this.sensorInfoArray.push(new Item('接近光传感器', `distance:${data.distance}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('接近光传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.ROTATION_VECTOR, (data: sensor.RotationVectorResponse) => { + this.sensorInfoArray.push(new Item('旋转矢量传感器', `x:${data.x},y:${data.y},z:${data.z},w:${data.w}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('旋转矢量传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.SIGNIFICANT_MOTION, (data: sensor.SignificantMotionResponse) => { + this.sensorInfoArray.push(new Item('大幅动作检测传感器', `scalar:${data.scalar}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('大幅动作检测传感器', `ERROR:${e.code}`)); + } + try { + sensor.once(sensor.SensorId.WEAR_DETECTION, (data: sensor.WearDetectionResponse) => { + this.sensorInfoArray.push(new Item('佩戴检测传感器', `value:${data.value}`)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); + this.sensorInfoArray.push(new Item('佩戴检测传感器', `ERROR:${e.code}`)); + } + } +} \ No newline at end of file diff --git a/OHBM/entry/src/main/ets/pages/Index.ets b/OHBM/entry/src/main/ets/pages/Index.ets index 61860feb..2a2ab2e4 100644 --- a/OHBM/entry/src/main/ets/pages/Index.ets +++ b/OHBM/entry/src/main/ets/pages/Index.ets @@ -12,22 +12,157 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import TestItemData from '../models/TestItemData'; +import TestGridItem from '../views/TestGridItem'; +import router from '@ohos.router'; +import { BusinessError } from '@ohos.base'; @Entry @Component struct Index { @State message: string = '开鸿测评(OpenHarmony Benchmarks)'; + @State items: TestItemData[] = []; - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } + aboutToAppear(): void { + this.items.push(new TestItemData('验机', $r('app.media.app_icon'), '待测试', () => { + try { + router.pushUrl({ + url: 'pages/BasicInfo', + }) + } catch (err) { + console.error(`pushUrl failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`); + } + })) + this.items.push(new TestItemData('性能评分', $r('app.media.app_icon'), '待测试', () => { + try { + router.pushUrl({ + url: 'pages/Performance', }) + } catch (err) { + console.error(`pushUrl failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`); + } + })) + this.items.push(new TestItemData('压力', $r('app.media.app_icon'), '待测试', () => { + })) + this.items.push(new TestItemData('网络', $r('app.media.app_icon'), '待测试', () => { + })) + this.items.push(new TestItemData('屏幕', $r('app.media.app_icon'), '待测试', () => { + })) + this.items.push(new TestItemData('电池', $r('app.media.app_icon'), '待测试', () => { + })) + + } + + build() { + Column() { + Row() { + Text('开鸿测评v0.0.1') + .fontSize(16) + .fontColor(Color.White) + .margin(8) + Image($r('app.media.app_icon')) + .height(36) + .margin(8) + } + .backgroundColor('#3333FF') + .width('100%') + .justifyContent(FlexAlign.SpaceBetween) + + Scroll() { + Column() { + RelativeContainer() { + Text('开始测评') + .fontSize(42) + .fontColor(Color.White) + .borderRadius(42) + .padding(16) + .backgroundColor('#11FFFFFF') + .alignSelf(ItemAlign.Center) + .alignRules({ + bottom: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + Row() { + Text('电池温度:28.5℃') + .fontSize(16) + .fontColor(Color.White) + .margin(8) + Text('CPU温度:31.5℃') + .fontSize(16) + .fontColor(Color.White) + .margin(8) + Blank() + Text('查看详情 >') + .fontSize(16) + .fontColor(Color.White) + .margin(8) + } + .width('100%') + .backgroundBlurStyle(BlurStyle.COMPONENT_THIN) + .alignRules({ + bottom: { anchor: '__container__', align: VerticalAlign.Bottom }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + } + .width('100%') + .height('40%') + .backgroundColor('#3333FF') + + Column() { + Grid() { + ForEach(this.items, (item: TestItemData) => { + GridItem() { + TestGridItem({ item }) + } + .height(120) + .width(120) + }) + } + .columnsTemplate('1fr 1fr 1fr') + .columnsGap(10) + .rowsGap(10) + .margin({ bottom: 16 }) + .padding({ top: 16 }) + .backgroundColor(Color.White) + .width('100%') + .height(272) + } + .width('100%') + .backgroundColor('#66CCCCCC') + + Column() { + List({ space: 10 }) { + ListItem() { + Text('其他测试1') + } + .height(48) + + ListItem() { + Text('其他测试2') + } + .height(48) + + ListItem() { + Text('其他测试3') + } + .height(48) + + ListItem() { + Text('其他测试4') + } + .height(48) + + ListItem() { + Text('其他测试5') + } + .height(48) + } + .divider({ strokeWidth: 1, color: '#CCCCCC' }) + .margin(16) + + } + } + }.scrollBar(BarState.Off) } .height('100%') .width('100%') diff --git a/OHBM/entry/src/main/ets/pages/Performance.ets b/OHBM/entry/src/main/ets/pages/Performance.ets new file mode 100644 index 00000000..6308b21a --- /dev/null +++ b/OHBM/entry/src/main/ets/pages/Performance.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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. + */ + + +@Entry +@Component +struct Performance { + + build() { + Column() { + Scroll() { + Column() { + Column() { + Text('性能评分') + } + + Column() { + } + .margin({ bottom: 80 }) + } + .constraintSize({ minHeight: '100%' }) + } + .height('100%') + .padding({ left: 12, right: 12 }) + } + } +} \ No newline at end of file diff --git a/OHBM/entry/src/main/ets/views/BasicInfoItem.ets b/OHBM/entry/src/main/ets/views/BasicInfoItem.ets new file mode 100644 index 00000000..0f4bccf6 --- /dev/null +++ b/OHBM/entry/src/main/ets/views/BasicInfoItem.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import ItemData from '../models/TestItemData'; + +/** + * List item information component. + */ +@Component +export default struct BasicInfoItem { + item: ItemData = new ItemData('', $r('app.media.app_icon'), '', () => { + }); + + aboutToAppear() { + } + + build() { + Column() { + Column() { + } + .borderRadius(12) + .backgroundImage(this.item.img) + .backgroundImageSize(ImageSize.Cover) + .shadow({ radius: 1, color: Color.Gray }) + .width(64) + .height(64) + .justifyContent(FlexAlign.SpaceBetween) + + Text(this.item.title) + .fontSize(20) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.MARQUEE }) + .width(120) + .textAlign(TextAlign.Center) + .margin({ top: 4 }) + Text(this.item.subTitle) + .fontSize(16) + .margin(4) + .fontColor(Color.Gray) + } + .alignItems(HorizontalAlign.Center) + .onClick(() => { + this.item.onItemClick(); + }) + } +} \ No newline at end of file diff --git a/OHBM/entry/src/main/ets/views/TestGridItem.ets b/OHBM/entry/src/main/ets/views/TestGridItem.ets new file mode 100644 index 00000000..11df4cd3 --- /dev/null +++ b/OHBM/entry/src/main/ets/views/TestGridItem.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import ItemData from '../models/TestItemData'; + +/** + * List item information component. + */ +@Component +export default struct TestGridItem { + item: ItemData = new ItemData('', $r('app.media.app_icon'), '', () => { + }); + + aboutToAppear() { + } + + build() { + Column() { + Column() { + } + .borderRadius(12) + .backgroundImage(this.item.img) + .backgroundImageSize(ImageSize.Cover) + .shadow({ radius: 1, color: Color.Gray }) + .width(64) + .height(64) + .justifyContent(FlexAlign.SpaceBetween) + + Text(this.item.title) + .fontSize(20) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.MARQUEE }) + .width(120) + .textAlign(TextAlign.Center) + .margin({ top: 4 }) + Text(this.item.subTitle) + .fontSize(16) + .margin(4) + .fontColor(Color.Gray) + } + .alignItems(HorizontalAlign.Center) + .onClick(() => { + this.item.onItemClick(); + }) + } +} \ No newline at end of file diff --git a/OHBM/entry/src/main/module.json5 b/OHBM/entry/src/main/module.json5 index f9d8ebc2..18c8d1e2 100644 --- a/OHBM/entry/src/main/module.json5 +++ b/OHBM/entry/src/main/module.json5 @@ -62,6 +62,52 @@ } ], } + ], + "requestPermissions": [ + { + "name": "ohos.permission.ACCELEROMETER", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility", + "EntryFormAbility" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.READ_HEALTH_DATA", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility", + "EntryFormAbility" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.ACTIVITY_MOTION", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility", + "EntryFormAbility" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.GYROSCOPE", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility", + "EntryFormAbility" + ], + "when": "inuse" + } + } ] } } \ No newline at end of file diff --git a/OHBM/entry/src/main/resources/base/profile/main_pages.json b/OHBM/entry/src/main/resources/base/profile/main_pages.json index 1898d94f..959aca2c 100644 --- a/OHBM/entry/src/main/resources/base/profile/main_pages.json +++ b/OHBM/entry/src/main/resources/base/profile/main_pages.json @@ -1,5 +1,7 @@ { "src": [ - "pages/Index" + "pages/Index", + "pages/BasicInfo", + "pages/Performance" ] } diff --git a/scenario/MusicPlayerOnline/AppScope/app.json5 b/scenario/MusicPlayerOnline/AppScope/app.json5 index ebae582d..d6077844 100644 --- a/scenario/MusicPlayerOnline/AppScope/app.json5 +++ b/scenario/MusicPlayerOnline/AppScope/app.json5 @@ -17,8 +17,8 @@ "app": { "bundleName": "com.example.musicPlayerOnline", "vendor": "example", - "versionCode": 1000002, - "versionName": "1.0.2", + "versionCode": 1000003, + "versionName": "1.0.3", "icon": "$media:app_icon", "label": "$string:app_name" } diff --git a/scenario/MusicPlayerOnline/entry/src/main/ets/manager/PlayerManager.ets b/scenario/MusicPlayerOnline/entry/src/main/ets/manager/PlayerManager.ets index f0c01f66..6e207df9 100644 --- a/scenario/MusicPlayerOnline/entry/src/main/ets/manager/PlayerManager.ets +++ b/scenario/MusicPlayerOnline/entry/src/main/ets/manager/PlayerManager.ets @@ -14,14 +14,11 @@ */ import media from '@ohos.multimedia.media'; -import { BusinessError } from '@ohos.base'; import AudioData from '../model/AudioData'; import Logger from '../utils/Logger'; import emitter from '@ohos.events.emitter'; import AppConstants from '../constants/AppConstants'; import { PLAY_MODE } from '../constants/PlayMode'; -import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; -import wantAgent, { WantAgent } from '@ohos.app.ability.wantAgent'; import common from '@ohos.app.ability.common'; import HttpManager from './HttpManager'; import PlayListData from '../model/PlayListData'; @@ -31,12 +28,17 @@ import formBindingData from '@ohos.app.form.formBindingData'; import CommonUtils from '../utils/CommonUtils'; import prompt from '@ohos.promptAction'; import { audio } from '@kit.AudioKit'; +import { backgroundTaskManager } from '@kit.BackgroundTasksKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { wantAgent, WantAgent } from '@kit.AbilityKit'; +import { avSession } from '@kit.AVSessionKit'; export default class PlayerManager { private tag: string = 'PlayerManager'; private formId: string = ''; private isSeek: boolean = false; private avPlayer: media.AVPlayer | undefined = undefined; + private avSession: avSession.AVSession | undefined = undefined; private list: AudioData[] = []; private explorePlaylistItem: PlayListData = new PlayListData('', $r('app.media.icon'), '', [], ''); private favourList: AudioData[] = []; @@ -54,7 +56,6 @@ export default class PlayerManager { }; constructor() { - this.startContinuousTask(); } initialPlayList() { @@ -164,7 +165,7 @@ export default class PlayerManager { Logger.info(this.tag, 'PlayerManager state released called.'); break; default: - Logger.info(this.tag, 'PlayerManager state unknown called.'); + Logger.info(this.tag, 'PlayerManager state unknown called.'); if (this.avPlayer !== undefined) { try { this.avPlayer.release(); @@ -236,7 +237,9 @@ export default class PlayerManager { */ play(item: AudioData): void { Logger.info(this.tag, 'Play finish:' + this.listPosition.toString()); - this.getItem().isPlaying = false; + if (this.getItem() !== undefined) { + this.getItem().isPlaying = false; + } let index = -1 if (item === undefined || item.id === '') { return @@ -430,6 +433,8 @@ export default class PlayerManager { if (this.avPlayer === undefined) { this.avPlayer = await media.createAVPlayer(); this.setAVPlayerCallback(this.avPlayer); + this.startContinuousTask(); + this.createAVSession(AppStorage.get('APPContext') as common.UIAbilityContext); } else { await this.avPlayer.reset(); } @@ -589,10 +594,11 @@ export default class PlayerManager { //设置后台任务 startContinuousTask() { + Logger.info(this.tag, "1111"); let wantAgentInfo: wantAgent.WantAgentInfo = { wants: [ { - bundleName: "com.example.avplayer", + bundleName: "com.example.musicPlayerOnline", abilityName: "EntryAbility" } ], @@ -602,10 +608,13 @@ export default class PlayerManager { }; try { + Logger.info(this.tag, "2222"); wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => { try { + let list: Array = ["dataTransfer","audioPlayback"]; + Logger.info(this.tag, "3333"); backgroundTaskManager.startBackgroundRunning(AppStorage.get('APPContext') as common.UIAbilityContext, - backgroundTaskManager.BackgroundMode.AUDIO_PLAYBACK, wantAgentObj).then(() => { + list, wantAgentObj).then(() => { Logger.info(this.tag, "PlayerManager Operation startBackgroundRunning succeeded"); }).catch((error: BusinessError) => { Logger.error(this.tag, @@ -636,6 +645,18 @@ export default class PlayerManager { `PlayerManager Operation stopBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); } } + createAVSession(context: common.UIAbilityContext): void { + Logger.debug(this.tag, 'createAVSession begin'); + avSession.createAVSession(context, 'online_player', 'audio').then((data) => { + Logger.debug(this.tag, 'createAVSession succeed'); + this.avSession = data; + }); + }; + + destroyAVSession(): void { + Logger.debug(this.tag, 'destroyAVSession begin'); + this.avSession?.destroy(); + }; //退出app async exitAPP() { @@ -643,8 +664,9 @@ export default class PlayerManager { if (this.avPlayer !== undefined) { await this.avPlayer.release(); this.avPlayer = undefined; + this.stopContinuousTask(); + this.destroyAVSession(); } - this.stopContinuousTask(); (AppStorage.get('APPContext') as common.UIAbilityContext).terminateSelf() .then(() => { -- Gitee