diff --git a/packages/device_info_plus/device_info_plus/example/lib/main.dart b/packages/device_info_plus/device_info_plus/example/lib/main.dart index 58f4888b3fa6bc616d1055e4895010279cfdcfbe..f9547e39681f461fcbf85d5646cba1ee2e5a33e2 100644 --- a/packages/device_info_plus/device_info_plus/example/lib/main.dart +++ b/packages/device_info_plus/device_info_plus/example/lib/main.dart @@ -8,6 +8,7 @@ import 'dart:async'; import 'dart:developer' as developer; import 'package:device_info_plus/device_info_plus.dart'; +import 'package:device_info_plus/device_info_plus_ohos.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -29,6 +30,8 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { static final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin(); + static final DeviceInfoOhosPlugin deviceInfoOhosPlugin = + DeviceInfoOhosPlugin(); Map _deviceData = {}; @override @@ -44,21 +47,33 @@ class _MyAppState extends State { if (kIsWeb) { deviceData = _readWebBrowserInfo(await deviceInfoPlugin.webBrowserInfo); } else { - deviceData = switch (defaultTargetPlatform) { - TargetPlatform.android => - _readAndroidBuildData(await deviceInfoPlugin.androidInfo), - TargetPlatform.iOS => - _readIosDeviceInfo(await deviceInfoPlugin.iosInfo), - TargetPlatform.linux => - _readLinuxDeviceInfo(await deviceInfoPlugin.linuxInfo), - TargetPlatform.windows => - _readWindowsDeviceInfo(await deviceInfoPlugin.windowsInfo), - TargetPlatform.macOS => - _readMacOsDeviceInfo(await deviceInfoPlugin.macOsInfo), - TargetPlatform.fuchsia => { - 'Error:': 'Fuchsia platform isn\'t supported' - }, - }; + switch (defaultTargetPlatform) { + case TargetPlatform.android: + deviceData = + _readAndroidBuildData(await deviceInfoPlugin.androidInfo); + break; + case TargetPlatform.iOS: + deviceData = _readIosDeviceInfo(await deviceInfoPlugin.iosInfo); + break; + case TargetPlatform.linux: + deviceData = _readLinuxDeviceInfo(await deviceInfoPlugin.linuxInfo); + break; + case TargetPlatform.windows: + deviceData = + _readWindowsDeviceInfo(await deviceInfoPlugin.windowsInfo); + break; + case TargetPlatform.macOS: + deviceData = _readMacOsDeviceInfo(await deviceInfoPlugin.macOsInfo); + break; + case TargetPlatform.ohos: + deviceData = (await deviceInfoOhosPlugin.ohosDeviceInfo).data; + break; + default: + deviceData = { + 'Error:': '$defaultTargetPlatform isn\'t supported' + }; + } + ; } } on PlatformException { deviceData = { @@ -252,14 +267,25 @@ class _MyAppState extends State { ); } - String _getAppBarTitle() => kIsWeb - ? 'Web Browser info' - : switch (defaultTargetPlatform) { - TargetPlatform.android => 'Android Device Info', - TargetPlatform.iOS => 'iOS Device Info', - TargetPlatform.linux => 'Linux Device Info', - TargetPlatform.windows => 'Windows Device Info', - TargetPlatform.macOS => 'MacOS Device Info', - TargetPlatform.fuchsia => 'Fuchsia Device Info', - }; + String _getAppBarTitle() { + if (kIsWeb) { + return 'Web Browser info'; + } + switch (defaultTargetPlatform) { + case TargetPlatform.android: + return 'Android Device Info'; + case TargetPlatform.ohos: + return 'Ohos Device Info'; + case TargetPlatform.iOS: + return 'iOS Device Info'; + case TargetPlatform.linux: + return 'Linux Device Info'; + case TargetPlatform.windows: + return 'Windows Device Info'; + case TargetPlatform.macOS: + return 'MacOS Device Info'; + case TargetPlatform.fuchsia: + return 'Fuchsia Device Info'; + } + } } diff --git a/packages/device_info_plus/device_info_plus/example/ohos/.gitignore b/packages/device_info_plus/device_info_plus/example/ohos/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..940b8265564d187f21566b25654fb8608808c6a4 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/.gitignore @@ -0,0 +1,18 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +entry/libs/arm64-v8a/libapp.so +entry/libs/arm64-v8a/libflutter.so +entry/libs/arm64-v8a/libvmservice_snapshot.so +entry/src/main/resources/rawfile/flutter_assets/ +har/*.har +oh-package-lock.json5 +dta \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/example/ohos/AppScope/app.json5 b/packages/device_info_plus/device_info_plus/example/ohos/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ae914f3a4ce1a746022f492993d5607a5f36e799 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "dev.fluttercommunity.plus.device_info_plus_example", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/example/ohos/AppScope/resources/base/element/string.json b/packages/device_info_plus/device_info_plus/example/ohos/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..73507ba637568fe7552b9e14f34e19e6a326d6ba --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "device_info_plus_example" + } + ] +} diff --git a/packages/device_info_plus/device_info_plus/example/ohos/AppScope/resources/base/media/app_icon.png b/packages/device_info_plus/device_info_plus/example/ohos/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packages/device_info_plus/device_info_plus/example/ohos/AppScope/resources/base/media/app_icon.png differ diff --git a/packages/device_info_plus/device_info_plus/example/ohos/build-profile.json5 b/packages/device_info_plus/device_info_plus/example/ohos/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1d12140d202702d7c73d64f1b291fe5c45a660ce --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/build-profile.json5 @@ -0,0 +1,27 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.0(12)", + "runtimeOS": "HarmonyOS" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/example/ohos/entry/.gitignore b/packages/device_info_plus/device_info_plus/example/ohos/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e9921c3125aab9d5307bea9523af7e3b0443436f --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/entry/.gitignore @@ -0,0 +1,9 @@ + +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test +/har +/libs \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/example/ohos/entry/build-profile.json5 b/packages/device_info_plus/device_info_plus/example/ohos/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..633d360fbc91a3186a23b66ab71b27e5618944cb --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/entry/build-profile.json5 @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 Hunan OpenValley 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. +*/ + +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "HarmonyOS" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/example/ohos/entry/hvigorfile.ts b/packages/device_info_plus/device_info_plus/example/ohos/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..894fc15c6b793f085e6c8506e43d719af658e8ff --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/entry/hvigorfile.ts @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 Hunan OpenValley 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. +*/ + +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/packages/device_info_plus/device_info_plus/example/ohos/entry/oh-package.json5 b/packages/device_info_plus/device_info_plus/example/ohos/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..078610f17b4a9d75c48dc65508a230e5a4a552fb --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/entry/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + } +} \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..a00049282e93c69f1b3dcd987538024f47e40ace --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 Hunan OpenValley 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 { FlutterAbility } from '@ohos/flutter_ohos' +import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant'; +import FlutterEngine from '@ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterEngine'; + +export default class EntryAbility extends FlutterAbility { + configureFlutterEngine(flutterEngine: FlutterEngine) { + super.configureFlutterEngine(flutterEngine) + GeneratedPluginRegistrant.registerWith(flutterEngine) + } +} diff --git a/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/ets/pages/Index.ets b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1125f9fdd95f4310a182c1c9e3680f37f73686c9 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2023 Hunan OpenValley 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 common from '@ohos.app.ability.common'; +import { FlutterPage } from '@ohos/flutter_ohos' + +let storage = LocalStorage.getShared() +const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS' + +@Entry(storage) +@Component +struct Index { + private context = getContext(this) as common.UIAbilityContext + @LocalStorageLink('viewId') viewId: string = ""; + + build() { + Column() { + FlutterPage({ viewId: this.viewId }) + } + } + + onBackPress(): boolean { + this.context.eventHub.emit(EVENT_BACK_PRESS) + return true + } +} \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40b63144bda90dd0523f86d9bb220bfe9f1d2da --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets @@ -0,0 +1,28 @@ +import { FlutterEngine, Log } from '@ohos/flutter_ohos'; +import DeviceInfoPlusPlugin from 'device_info_plus'; +import IntegrationTestPlugin from 'integration_test'; + +/** + * Generated file. Do not edit. + * This file is generated by the Flutter tool based on the + * plugins that support the Ohos platform. + */ + +const TAG = "GeneratedPluginRegistrant"; + +export class GeneratedPluginRegistrant { + + static registerWith(flutterEngine: FlutterEngine) { + try { + flutterEngine.getPlugins()?.add(new DeviceInfoPlusPlugin()); + flutterEngine.getPlugins()?.add(new IntegrationTestPlugin()); + } catch (e) { + Log.e( + TAG, + "Tried to register plugins with FlutterEngine (" + + flutterEngine + + ") failed."); + Log.e(TAG, "Received exception while registering", e); + } + } +} diff --git a/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/module.json5 b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7bbf78b18f39991b1404061c7437538c7d532bb7 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/module.json5 @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2023 Hunan OpenValley 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. +*/ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + {"name" : "ohos.permission.INTERNET"}, + ] + } +} \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/base/element/color.json b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/base/element/string.json b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..66fc0909c6ab805eb5ec24708bca885d3df679c4 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "device_info_plus_example" + } + ] +} \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/base/media/icon.png b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/base/media/icon.png differ diff --git a/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/base/profile/main_pages.json b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/en_US/element/string.json b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..66fc0909c6ab805eb5ec24708bca885d3df679c4 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "device_info_plus_example" + } + ] +} \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/zh_CN/element/string.json b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5b5875feb9dcb193be8463d12ff3c86908e2aa23 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "device_info_plus_example" + } + ] +} \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/example/ohos/hvigor/hvigor-config.json5 b/packages/device_info_plus/device_info_plus/example/ohos/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ab31acd375a4380517091174c19f41226513fd11 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/hvigor/hvigor-config.json5 @@ -0,0 +1,24 @@ +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "default", /* Define the build analyze mode. Value: [ "default" | "verbose" | false ]. Default: "default" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 4096 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process */ + }, + "properties": { + "ohos.nativeResolver": false + } +} \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/example/ohos/hvigorfile.ts b/packages/device_info_plus/device_info_plus/example/ohos/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..8f2d2aafe6d6a3a71a9944ebd0c91fbc308ac9d1 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/hvigorfile.ts @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 Hunan OpenValley 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 { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/example/ohos/oh-package.json5 b/packages/device_info_plus/device_info_plus/example/ohos/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8f72a6f6c86d7c91b97dd324494dda410ec79c80 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/example/ohos/oh-package.json5 @@ -0,0 +1,18 @@ +{ + "modelVersion": "5.0.0", + "name": "apptemplate", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "@ohos/flutter_ohos": "file:./har/flutter.har" + }, + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "overrides": { + "@ohos/flutter_ohos": "file:./har/flutter.har" + } +} \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/example/pubspec.yaml b/packages/device_info_plus/device_info_plus/example/pubspec.yaml index f43b38eb18a8c4603141987854fdf1409f85952c..de010a1b9b34ce149226b836d2e25a79ad027260 100644 --- a/packages/device_info_plus/device_info_plus/example/pubspec.yaml +++ b/packages/device_info_plus/device_info_plus/example/pubspec.yaml @@ -4,7 +4,9 @@ description: Demonstrates how to use the device_info_plus plugin. dependencies: flutter: sdk: flutter - device_info_plus: ^11.1.0 + device_info_plus: + path: ../ + cupertino_icons: ^1.0.2 dev_dependencies: flutter_driver: @@ -13,7 +15,7 @@ dev_dependencies: sdk: flutter integration_test: sdk: flutter - flutter_lints: ^5.0.0 + flutter_lints: ^2.0.0 flutter: uses-material-design: true diff --git a/packages/device_info_plus/device_info_plus/lib/device_info_plus_ohos.dart b/packages/device_info_plus/device_info_plus/lib/device_info_plus_ohos.dart new file mode 100644 index 0000000000000000000000000000000000000000..fb244212ec7ca33f672474e9bd8fed8e609c149a --- /dev/null +++ b/packages/device_info_plus/device_info_plus/lib/device_info_plus_ohos.dart @@ -0,0 +1,30 @@ +import 'package:device_info_plus/src/ohos_device_info.dart'; +import 'package:device_info_plus_platform_interface/device_info_plus_platform_interface.dart'; +import 'package:device_info_plus_platform_interface/method_channel/method_channel_device_info.dart'; + +export 'src/ohos_device_info.dart'; + +class DeviceInfoOhosPlugin { + DeviceInfoOhosPlugin(); + static MethodChannelDeviceInfo get _platform { + return DeviceInfoPlatform.instance as MethodChannelDeviceInfo; + } + + /// This information does not change from call to call. Cache it. + OhosDeviceInfo? _cachedOhosDeviceInfo; + + /// Information derived from `@ohos.deviceInfo`. + /// + /// https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-device-info-0000001428061996-V3 + Future get ohosDeviceInfo async => _cachedOhosDeviceInfo ??= + OhosDeviceInfo.fromMap((await _platform.deviceInfo()).data); + + /// Requires permission: ohos.permission.sec.ACCESS_UDID (System permission, only open to system apps). + /// Device serial number. + /// Device Udid. + Future get ohosAccessUDIDInfo async => + OhosAccessUDIDInfo.fromMap( + // ignore: invalid_use_of_visible_for_testing_member + (await _platform.channel.invokeMethod('getAccessUDIDInfo')) + .cast()); +} diff --git a/packages/device_info_plus/device_info_plus/lib/src/ohos_device_info.dart b/packages/device_info_plus/device_info_plus/lib/src/ohos_device_info.dart new file mode 100644 index 0000000000000000000000000000000000000000..04beaa384b68fe79e8bbd5946fa3ae160830a635 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/lib/src/ohos_device_info.dart @@ -0,0 +1,309 @@ +import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; + +/// Information derived from `@ohos.deviceInfo`. +/// +/// https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-device-info-0000001428061996-V3 + +class OhosDeviceInfo extends BaseDeviceInfo { + OhosDeviceInfo._({ + required Map data, + required this.deviceType, + required this.manufacture, + required this.brand, + required this.marketName, + required this.productSeries, + required this.productModel, + required this.softwareModel, + required this.hardwareModel, + // required this.hardwareProfile, + // required this.serial, + required this.bootloaderVersion, + required this.abiList, + required this.securityPatchTag, + required this.displayVersion, + required this.incrementalVersion, + required this.osReleaseType, + required this.osFullName, + required this.majorVersion, + required this.seniorVersion, + required this.featureVersion, + required this.buildVersion, + required this.sdkApiVersion, + required this.firstApiVersion, + required this.versionId, + required this.buildType, + required this.buildUser, + required this.buildHost, + required this.buildTime, + required this.buildRootHash, + // required this.udid, + required this.distributionOSName, + required this.distributionOSVersion, + required this.distributionOSApiVersion, + required this.distributionOSReleaseType, + required this.isPhysicalDevice, + }) : super(data); + + factory OhosDeviceInfo.fromMap(Map map) { + return OhosDeviceInfo._( + data: map, + deviceType: map['deviceType'] ?? '', + manufacture: map['manufacture'] ?? '', + brand: map['brand'] ?? '', + marketName: map['marketName'] ?? '', + productSeries: map['productSeries'] ?? '', + productModel: map['productModel'] ?? '', + softwareModel: map['softwareModel'] ?? '', + hardwareModel: map['hardwareModel'] ?? '', + // hardwareProfile: map['hardwareProfile'] ?? '', + // serial: map['serial'] ?? '', + bootloaderVersion: map['bootloaderVersion'] ?? '', + abiList: map['abiList'] ?? '', + securityPatchTag: map['securityPatchTag'] ?? '', + displayVersion: map['displayVersion'] ?? '', + incrementalVersion: map['incrementalVersion'] ?? '', + osReleaseType: map['osReleaseType'] ?? '', + osFullName: map['osFullName'] ?? '', + majorVersion: map['majorVersion'] ?? 0, + seniorVersion: map['seniorVersion'] ?? 0, + featureVersion: map['featureVersion'] ?? 0, + buildVersion: map['buildVersion'] ?? 0, + sdkApiVersion: map['sdkApiVersion'] ?? 0, + firstApiVersion: map['firstApiVersion'] ?? 0, + versionId: map['versionId'] ?? '', + buildType: map['buildType'] ?? '', + buildUser: map['buildUser'] ?? '', + buildHost: map['buildHost'] ?? '', + buildTime: map['buildTime'] ?? '', + buildRootHash: map['buildRootHash'] ?? '', + // udid: map['udid'] ?? '', + distributionOSName: map['distributionOSName'] ?? '', + distributionOSVersion: map['distributionOSVersion'] ?? '', + distributionOSApiVersion: map['distributionOSApiVersion'] ?? 0, + distributionOSReleaseType: map['distributionOSReleaseType'] ?? '', + isPhysicalDevice: map['isPhysicalDevice'] == true, + ); + } + + /// Device type. + /// 设备类型。 + final String deviceType; + + /// Device manufacturer name. + /// 设备厂家名称。 + final String manufacture; + + /// Device brand name. + /// 设备品牌名称。 + final String brand; + + /// External product series. + /// 外部产品系列。 + final String marketName; + + /// Product series. + /// 产品系列。 + final String productSeries; + + /// Product model. + /// 认证型号。 + final String productModel; + + /// Software model. + /// 内部软件子型号。 + final String softwareModel; + + /// Hardware model. + /// 硬件版本号。 + final String hardwareModel; + + /// Hardware profile. + /// 硬件Profile。 + // @Deprecated('since api 9') + // final String hardwareProfile; + + /// Requires permission: ohos.permission.sec.ACCESS_UDID (System permission, only open to system apps). + /// Device serial number. + /// 设备序列号。 + // final String serial; + + /// Bootloader version number. + /// Bootloader版本号。 + final String bootloaderVersion; + + /// Application binary interface (Abi) list. + /// 应用二进制接口(Abi)列表。 + final String abiList; + + /// Security patch level. + /// 安全补丁级别。 + final String securityPatchTag; + + /// Product version. + /// 产品版本。 + final String displayVersion; + + /// Incremental version. + /// 差异版本号。 + final String incrementalVersion; + + /// OS release type. + /// 系统的发布类型,取值为: + /// - Canary:面向特定开发者发布的早期预览版本,不承诺API稳定性。 + /// - Beta:面向开发者公开发布的Beta版本,不承诺API稳定性。 + /// - Release:面向开发者公开发布的正式版本,承诺API稳定性。 + final String osReleaseType; + + /// OS version. + /// 系统版本。 + final String osFullName; + + /// Major version number, increases with updates to the overall architecture. + /// Major版本号,随主版本更新增加。 + final int majorVersion; + + /// Senior version number, increases with updates to the partial architecture or major features. + /// Senior版本号,随局部架构、重大特性增加。 + final int seniorVersion; + + /// Feature version number, increases with planned new features. + /// Feature版本号,标识规划的新特性版本。 + final int featureVersion; + + /// Build version number, increases with each new development build. + /// Build版本号,标识编译构建的版本号。 + final int buildVersion; + + /// SDK API version number. + /// 系统软件API版本。 + final int sdkApiVersion; + + /// First API version number. + /// 首个版本系统软件API版本。 + final int firstApiVersion; + + /// Version ID. + /// 版本ID。 + final String versionId; + + /// Build type. + /// 构建类型。 + final String buildType; + + /// Build user. + /// 构建用户。 + final String buildUser; + + /// Build host. + /// 构建主机。 + final String buildHost; + + /// Build time. + /// 构建时间。 + final String buildTime; + + /// Build version hash. + /// 构建版本Hash。 + final String buildRootHash; + + /// Requires permission: ohos.permission.sec.ACCESS_UDID (System permission, only open to system apps). + /// Device Udid. + /// 设备Udid。 + // final String udid; + + /// Distribution OS name. + /// 发行版系统名称。 + final String distributionOSName; + + /// Distribution OS version. + /// 发行版系统版本号。 + final String distributionOSVersion; + + /// Distribution OS API version. + /// 发行版系统API版本号。 + final int distributionOSApiVersion; + + /// Distribution OS release type. + /// 发行版系统类型。 + final String distributionOSReleaseType; + + /// `false` if the application is running in an emulator, `true` otherwise. + final bool isPhysicalDevice; + + Map toJson() { + return { + 'deviceType': deviceType, + 'manufacture': manufacture, + 'brand': brand, + 'marketName': marketName, + 'productSeries': productSeries, + 'productModel': productModel, + 'softwareModel': softwareModel, + 'hardwareModel': hardwareModel, + // 'hardwareProfile': hardwareProfile, + // serial': serial, + 'bootloaderVersion': bootloaderVersion, + 'abiList': abiList, + 'securityPatchTag': securityPatchTag, + 'displayVersion': displayVersion, + 'incrementalVersion': incrementalVersion, + 'osReleaseType': osReleaseType, + 'osFullName': osFullName, + 'majorVersion': majorVersion, + 'seniorVersion': seniorVersion, + 'featureVersion': featureVersion, + 'buildVersion': buildVersion, + 'sdkApiVersion': sdkApiVersion, + 'firstApiVersion': firstApiVersion, + 'versionId': versionId, + 'buildType': buildType, + 'buildUser': buildUser, + 'buildHost': buildHost, + 'buildTime': buildTime, + 'buildRootHash': buildRootHash, + // 'udid': udid, + 'distributionOSName': distributionOSName, + 'distributionOSVersion': distributionOSVersion, + 'distributionOSApiVersion': distributionOSApiVersion, + 'distributionOSReleaseType': distributionOSReleaseType, + 'isPhysicalDevice': isPhysicalDevice, + }; + } +} + +/// Information derived from `@ohos.deviceInfo`. +/// +/// https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-device-info-0000001428061996-V3 + +class OhosAccessUDIDInfo extends BaseDeviceInfo { + OhosAccessUDIDInfo._({ + required Map data, + required this.serial, + required this.udid, + }) : super(data); + + factory OhosAccessUDIDInfo.fromMap(Map map) { + return OhosAccessUDIDInfo._( + data: map, + serial: map['serial'] ?? '', + udid: map['udid'] ?? '', + ); + } + + /// Requires permission: ohos.permission.sec.ACCESS_UDID (System permission, only open to system apps). + /// Device serial number. + /// 设备序列号。 + final String serial; + + /// Requires permission: ohos.permission.sec.ACCESS_UDID (System permission, only open to system apps). + /// Device Udid. + /// 设备Udid。 + final String udid; + + Map toJson() { + return { + 'serial': serial, + 'udid': udid, + }; + } +} diff --git a/packages/device_info_plus/device_info_plus/ohos/.gitignore b/packages/device_info_plus/device_info_plus/ohos/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..c0f9ca4c47ca2d6aea523c5e0cf3331566bbf88a --- /dev/null +++ b/packages/device_info_plus/device_info_plus/ohos/.gitignore @@ -0,0 +1,9 @@ +/node_modules +/oh_modules +/.preview +/.idea +/build +/.cxx +/.test +/BuildProfile.ets +/oh-package-lock.json5 diff --git a/packages/device_info_plus/device_info_plus/ohos/build-profile.json5 b/packages/device_info_plus/device_info_plus/ohos/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..79961f96a6fe0507354b7952a378c3be2ae4bfab --- /dev/null +++ b/packages/device_info_plus/device_info_plus/ohos/build-profile.json5 @@ -0,0 +1,10 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "targets": [ + { + "name": "default" + } + ] +} diff --git a/packages/device_info_plus/device_info_plus/ohos/hvigorfile.ts b/packages/device_info_plus/device_info_plus/ohos/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..47e6e1f81d365872f101585f5dbf816bcad65864 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/ohos/hvigorfile.ts @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { harTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/ohos/index.ets b/packages/device_info_plus/device_info_plus/ohos/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..d1866906cef7fde05693a3c14665a303b81b8376 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/ohos/index.ets @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 Hunan OpenValley 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 DeviceInfoPlusPlugin from './src/main/ets/components/plugin/DeviceInfoPlusOhosPlugin'; +export default DeviceInfoPlusPlugin; diff --git a/packages/device_info_plus/device_info_plus/ohos/oh-package.json5 b/packages/device_info_plus/device_info_plus/ohos/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6ee47cc8f2bf35a1e143969e3f70e11a41260511 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/ohos/oh-package.json5 @@ -0,0 +1,11 @@ +{ + "name": "device_info_plus", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": { + "@ohos/flutter_ohos": "file:./har/flutter.har" + } +} diff --git a/packages/device_info_plus/device_info_plus/ohos/src/main/ets/components/plugin/DeviceInfoPlusOhosPlugin.ets b/packages/device_info_plus/device_info_plus/ohos/src/main/ets/components/plugin/DeviceInfoPlusOhosPlugin.ets new file mode 100644 index 0000000000000000000000000000000000000000..9d8b8fe9eca3b2edfab74a61d7b39f48f9f0d85e --- /dev/null +++ b/packages/device_info_plus/device_info_plus/ohos/src/main/ets/components/plugin/DeviceInfoPlusOhosPlugin.ets @@ -0,0 +1,92 @@ +import { + FlutterPlugin, + FlutterPluginBinding +} from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin'; +import MethodChannel, { + MethodCallHandler, + MethodResult +} from '@ohos/flutter_ohos/src/main/ets/plugin/common/MethodChannel'; +import MethodCall from '@ohos/flutter_ohos/src/main/ets/plugin/common/MethodCall'; +import deviceInfo from '@ohos.deviceInfo'; +import HashMap from '@ohos.util.HashMap'; + +/** DeviceInfoPlusPlugin **/ +export default class DeviceInfoPlusPlugin implements FlutterPlugin, MethodCallHandler { + private channel: MethodChannel | null = null; + + constructor() { + } + + getUniqueClassName(): string { + return "DeviceInfoPlusPlugin" + } + + onAttachedToEngine(binding: FlutterPluginBinding): void { + this.channel = new MethodChannel(binding.getBinaryMessenger(), "dev.fluttercommunity.plus/device_info"); + this.channel.setMethodCallHandler(this) + } + + onDetachedFromEngine(binding: FlutterPluginBinding): void { + if (this.channel != null) { + this.channel.setMethodCallHandler(null) + } + } + + onMethodCall(call: MethodCall, result: MethodResult): void { + if (call.method == "getDeviceInfo") { + let infoMap: HashMap = new HashMap(); + infoMap.set('deviceType', deviceInfo.deviceType); + infoMap.set('manufacture', deviceInfo.manufacture); + infoMap.set('brand', deviceInfo.brand); + infoMap.set('marketName', deviceInfo.marketName); + infoMap.set('productSeries', deviceInfo.productSeries); + infoMap.set('productModel', deviceInfo.productModel); + infoMap.set('softwareModel', deviceInfo.softwareModel); + infoMap.set('hardwareModel', deviceInfo.hardwareModel); + // deprecated + // infoMap.set('hardwareProfile', deviceInfo.hardwareProfile); + // infoMap.set('serial', deviceInfo.serial); + // infoMap.set('serial', ''); + infoMap.set('bootloaderVersion', deviceInfo.bootloaderVersion); + infoMap.set('abiList', deviceInfo.abiList); + infoMap.set('securityPatchTag', deviceInfo.securityPatchTag); + infoMap.set('displayVersion', deviceInfo.displayVersion); + infoMap.set('incrementalVersion', deviceInfo.incrementalVersion); + infoMap.set('osReleaseType', deviceInfo.osReleaseType); + infoMap.set('osFullName', deviceInfo.osFullName); + infoMap.set('majorVersion', deviceInfo.majorVersion); + infoMap.set('seniorVersion', deviceInfo.seniorVersion); + infoMap.set('featureVersion', deviceInfo.featureVersion); + infoMap.set('buildVersion', deviceInfo.buildVersion); + infoMap.set('sdkApiVersion', deviceInfo.sdkApiVersion); + infoMap.set('firstApiVersion', deviceInfo.firstApiVersion); + infoMap.set('versionId', deviceInfo.versionId); + infoMap.set('buildType', deviceInfo.buildType); + infoMap.set('buildUser', deviceInfo.buildUser); + infoMap.set('buildHost', deviceInfo.buildHost); + infoMap.set('buildTime', deviceInfo.buildTime); + infoMap.set('buildRootHash', deviceInfo.buildRootHash); + // infoMap.set('udid', deviceInfo.udid); + // infoMap.set('udid', ''); + infoMap.set('distributionOSName', deviceInfo.distributionOSName); + infoMap.set('distributionOSVersion', deviceInfo.distributionOSVersion); + infoMap.set('distributionOSApiVersion', deviceInfo.distributionOSApiVersion); + infoMap.set('distributionOSReleaseType', deviceInfo.distributionOSReleaseType); + infoMap.set('isPhysicalDevice', !this.isEmulator(infoMap)); + result.success(infoMap) + } + else if (call.method == "getAccessUDIDInfo") { + let infoMap: HashMap = new HashMap(); + infoMap.set('serial', deviceInfo.serial); + infoMap.set('udid', deviceInfo.udid); + result.success(infoMap) + } + else { + result.notImplemented() + } + } + + isEmulator(infoMap: HashMap): Boolean { + return infoMap.hasValue('emulator') || deviceInfo.versionId.includes('emulator') || deviceInfo.displayVersion.includes('emulator'); + } +} \ No newline at end of file diff --git a/packages/device_info_plus/device_info_plus/ohos/src/main/module.json5 b/packages/device_info_plus/device_info_plus/ohos/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..700af06cb2e4b9a58586191deadc3929f8ff71ed --- /dev/null +++ b/packages/device_info_plus/device_info_plus/ohos/src/main/module.json5 @@ -0,0 +1,10 @@ +{ + "module": { + "name": "device_info_plus", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/packages/device_info_plus/device_info_plus/pubspec.yaml b/packages/device_info_plus/device_info_plus/pubspec.yaml index e09e032f5475c0f0cd92a0a86dad9a665f81c8ae..25d10deec86e6a34a2f191b177a109fa7887a8e3 100644 --- a/packages/device_info_plus/device_info_plus/pubspec.yaml +++ b/packages/device_info_plus/device_info_plus/pubspec.yaml @@ -27,7 +27,8 @@ flutter: pluginClass: DeviceInfoPlusMacosPlugin windows: dartPluginClass: DeviceInfoPlusWindowsPlugin - + ohos: + pluginClass: DeviceInfoPlusPlugin dependencies: device_info_plus_platform_interface: ^7.0.1 ffi: ^2.0.1