diff --git a/OAT.xml b/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..fbe5ead8b418802d515b610a3ae04ef64b165ec2 --- /dev/null +++ b/OAT.xml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/permission_handler_ohos/.gitignore b/permission_handler_ohos/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..00a1a002a161880e5a95028c030d8cfecc432daa --- /dev/null +++ b/permission_handler_ohos/.gitignore @@ -0,0 +1,47 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release + +**.har +GeneratedPluginRegistrant.* diff --git a/permission_handler_ohos/AUTHORS b/permission_handler_ohos/AUTHORS new file mode 100644 index 0000000000000000000000000000000000000000..7918633418172b41ecf22d5fdac2b876610771b6 --- /dev/null +++ b/permission_handler_ohos/AUTHORS @@ -0,0 +1,20 @@ +# 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. + +# Below is a list of people and organizations that have contributed +# to the Flutter project. Names should be added to the list like so: +# +# Name/Organization + +Baseflow +Maurits van Beusekom \ No newline at end of file diff --git a/permission_handler_ohos/CHANGELOG.md b/permission_handler_ohos/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..f0ddb4607cf68b8f5fc88eaf9a15b0ea7f58c806 --- /dev/null +++ b/permission_handler_ohos/CHANGELOG.md @@ -0,0 +1,2 @@ +##1.0.0 +new ohos version. \ No newline at end of file diff --git a/permission_handler_ohos/README.md b/permission_handler_ohos/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ba655784e821b9d67533c7d51da0e2855fcfb22f --- /dev/null +++ b/permission_handler_ohos/README.md @@ -0,0 +1,15 @@ +## ohos权限配置参考 + +### [声明权限](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/declare-permissions.md) + +应用在申请权限时,需要在项目的配置文件中,逐个声明需要的权限,否则应用将无法获取授权。 + +--- +### [权限列表](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md) +#### 对所有应用开放 +在申请目标权限前,建议开发者先阅读申请应用权限,对权限的工作流程有基本了解后,再结合列表中权限字段的具体说明,判断应用能否申请目标权限,提高开发效率。 + +--- +### 注意事项 + + 申请权限需要在ohos/entry/src/main/module.json5中声明 diff --git a/permission_handler_ohos/example/README.md b/permission_handler_ohos/example/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/permission_handler_ohos/example/lib/main.dart b/permission_handler_ohos/example/lib/main.dart new file mode 100644 index 0000000000000000000000000000000000000000..c77451cde514f7fc7c62c90a6d1775ec349e7664 --- /dev/null +++ b/permission_handler_ohos/example/lib/main.dart @@ -0,0 +1,164 @@ +/* +* 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 'package:baseflow_plugin_template/baseflow_plugin_template.dart'; +import 'package:flutter/material.dart'; +import 'package:permission_handler_platform_interface/permission_handler_platform_interface.dart'; + +void main() { + runApp(BaseflowPluginExample( + pluginName: 'Permission Handler', + githubURL: 'https://github.com/Baseflow/flutter-permission-handler', + pubDevURL: 'https://pub.dev/packages/permission_handler', + pages: [PermissionHandlerWidget.createPage()])); +} + +///Defines the main theme color +final MaterialColor themeMaterialColor = + BaseflowPluginExample.createMaterialColor( + const Color.fromRGBO(48, 49, 60, 1)); + +/// A Flutter application demonstrating the functionality of this plugin +class PermissionHandlerWidget extends StatefulWidget { + /// Creates a [PermissionHandlerWidget]. + const PermissionHandlerWidget({ + super.key, + }); + + /// Create a page containing the functionality of this plugin + static ExamplePage createPage() { + return ExamplePage( + Icons.location_on, (context) => const PermissionHandlerWidget()); + } + + @override + _PermissionHandlerWidgetState createState() => + _PermissionHandlerWidgetState(); +} + +class _PermissionHandlerWidgetState extends State { + @override + Widget build(BuildContext context) { + return Center( + child: ListView( + children: Permission.values + .where((permission) { + return permission != Permission.unknown && + permission != Permission.mediaLibrary && + permission != Permission.photosAddOnly && + permission != Permission.reminders && + permission != Permission.bluetooth && + permission != Permission.appTrackingTransparency && + permission != Permission.criticalAlerts && + permission != Permission.assistant && + permission != Permission.backgroundRefresh; + }) + .map((permission) => PermissionWidget(permission)) + .toList()), + ); + } +} + +/// Permission widget containing information about the passed [Permission] +class PermissionWidget extends StatefulWidget { + /// Constructs a [PermissionWidget] for the supplied [Permission] + const PermissionWidget( + this._permission, { + super.key, + }); + + final Permission _permission; + + @override + _PermissionState createState() => _PermissionState(); +} + +class _PermissionState extends State { + _PermissionState(); + + final PermissionHandlerPlatform _permissionHandler = + PermissionHandlerPlatform.instance; + PermissionStatus _permissionStatus = PermissionStatus.denied; + + @override + void initState() { + super.initState(); + + _listenForPermissionStatus(); + } + + void _listenForPermissionStatus() async { + final status = + await _permissionHandler.checkPermissionStatus(widget._permission); + setState(() => _permissionStatus = status); + } + + Color getPermissionColor() { + switch (_permissionStatus) { + case PermissionStatus.denied: + return Colors.red; + case PermissionStatus.granted: + return Colors.green; + case PermissionStatus.limited: + return Colors.orange; + default: + return Colors.grey; + } + } + + @override + Widget build(BuildContext context) { + return ListTile( + title: Text( + widget._permission.toString(), + style: Theme.of(context).textTheme.bodyLarge, + ), + subtitle: Text( + _permissionStatus.toString(), + style: TextStyle(color: getPermissionColor()), + ), + trailing: (widget._permission is PermissionWithService) + ? IconButton( + icon: const Icon( + Icons.info, + color: Colors.white, + ), + onPressed: () { + checkServiceStatus( + context, widget._permission as PermissionWithService); + }) + : null, + onTap: () { + requestPermission(widget._permission); + }, + ); + } + + void checkServiceStatus( + BuildContext context, PermissionWithService permission) async { + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text( + (await _permissionHandler.checkServiceStatus(permission)).toString()), + )); + } + + Future requestPermission(Permission permission) async { + final status = await _permissionHandler.requestPermissions([permission]); + + setState(() { + _permissionStatus = status[permission] ?? PermissionStatus.denied; + }); + } +} diff --git a/permission_handler_ohos/example/ohos/.gitignore b/permission_handler_ohos/example/ohos/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6f7b4f89c49a6abadc383d9665d3b4c171d466bc --- /dev/null +++ b/permission_handler_ohos/example/ohos/.gitignore @@ -0,0 +1,17 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test + +/entry/libs/arm64-v8a/libflutter.so +/entry/src/main/resources/rawfile/flutter_assets +**.har +**/oh-package-lock.json5 +BuildProfile.ets diff --git a/permission_handler_ohos/example/ohos/AppScope/app.json5 b/permission_handler_ohos/example/ohos/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ae9857b32e7ef19e3b51fc621b626e4a122ef90d --- /dev/null +++ b/permission_handler_ohos/example/ohos/AppScope/app.json5 @@ -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. +*/ + +{ + "app": { + "bundleName": "com.ohos.permissionhandler.example", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/permission_handler_ohos/example/ohos/AppScope/resources/base/element/string.json b/permission_handler_ohos/example/ohos/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..810f4a362c1d177309eec4f2efe5cac2f4558c28 --- /dev/null +++ b/permission_handler_ohos/example/ohos/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "example" + } + ] +} diff --git a/permission_handler_ohos/example/ohos/AppScope/resources/base/media/app_icon.png b/permission_handler_ohos/example/ohos/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/permission_handler_ohos/example/ohos/AppScope/resources/base/media/app_icon.png differ diff --git a/permission_handler_ohos/example/ohos/build-profile.json5 b/permission_handler_ohos/example/ohos/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d209fee432db4515940449ca8f4516144ae32cf6 --- /dev/null +++ b/permission_handler_ohos/example/ohos/build-profile.json5 @@ -0,0 +1,35 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.0(12)", + "runtimeOS": "HarmonyOS" + } + ], + "buildModeSet": [ + { + "name": "debug" + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/permission_handler_ohos/example/ohos/dta/icudtl.dat b/permission_handler_ohos/example/ohos/dta/icudtl.dat new file mode 100644 index 0000000000000000000000000000000000000000..d1f10917ab52e3ebd251abd7f5377d7196b80d67 Binary files /dev/null and b/permission_handler_ohos/example/ohos/dta/icudtl.dat differ diff --git a/permission_handler_ohos/example/ohos/entry/.gitignore b/permission_handler_ohos/example/ohos/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6f7b4f89c49a6abadc383d9665d3b4c171d466bc --- /dev/null +++ b/permission_handler_ohos/example/ohos/entry/.gitignore @@ -0,0 +1,17 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test + +/entry/libs/arm64-v8a/libflutter.so +/entry/src/main/resources/rawfile/flutter_assets +**.har +**/oh-package-lock.json5 +BuildProfile.ets diff --git a/permission_handler_ohos/example/ohos/entry/build-profile.json5 b/permission_handler_ohos/example/ohos/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a2de5564711c7ec9a8781208e89652a1f570c4a2 --- /dev/null +++ b/permission_handler_ohos/example/ohos/entry/build-profile.json5 @@ -0,0 +1,31 @@ +/* +* 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": { + "napiLibFilterOption": { + "enableOverride": true + } + }, + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/permission_handler_ohos/example/ohos/entry/hvigorfile.ts b/permission_handler_ohos/example/ohos/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..894fc15c6b793f085e6c8506e43d719af658e8ff --- /dev/null +++ b/permission_handler_ohos/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/permission_handler_ohos/example/ohos/entry/oh-package.json5 b/permission_handler_ohos/example/ohos/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..543646d1020268669ef041fdd8e6fd3b396dbf95 --- /dev/null +++ b/permission_handler_ohos/example/ohos/entry/oh-package.json5 @@ -0,0 +1,13 @@ +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": { + "@ohos/flutter_ohos": "file:../har/flutter.har", + "permission_handler_ohos": "file:../har/permission_handler_ohos.har" + } +} \ No newline at end of file diff --git a/permission_handler_ohos/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets b/permission_handler_ohos/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..d367ac7db8560a85845b66e484508ce108be3766 --- /dev/null +++ b/permission_handler_ohos/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,24 @@ +/* +* 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, FlutterEngine } from '@ohos/flutter_ohos' +import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant'; + +export default class EntryAbility extends FlutterAbility { + configureFlutterEngine(flutterEngine: FlutterEngine) { + super.configureFlutterEngine(flutterEngine) + GeneratedPluginRegistrant.registerWith(flutterEngine); + } +} diff --git a/permission_handler_ohos/example/ohos/entry/src/main/ets/pages/Index.ets b/permission_handler_ohos/example/ohos/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1125f9fdd95f4310a182c1c9e3680f37f73686c9 --- /dev/null +++ b/permission_handler_ohos/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/permission_handler_ohos/example/ohos/entry/src/main/module.json5 b/permission_handler_ohos/example/ohos/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d4dad8478b08397a6254b34c0d1bce746897db42 --- /dev/null +++ b/permission_handler_ohos/example/ohos/entry/src/main/module.json5 @@ -0,0 +1,213 @@ +/* +* 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.DISCOVER_BLUETOOTH", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + }, + { + "name": "ohos.permission.USE_BLUETOOTH", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + }, + { + "name": "ohos.permission.ACTIVITY_MOTION", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + }, + { + "name": "ohos.permission.LOCATION", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + }, + { + "name": "ohos.permission.CAMERA", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + }, + { + "name": "ohos.permission.APPROXIMATELY_LOCATION", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + }, + { + "name": "ohos.permission.LOCATION_IN_BACKGROUND", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + }, + { + "name": "ohos.permission.READ_CALENDAR", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + }, + { + "name": "ohos.permission.WRITE_CALENDAR", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + }, + { + "name": "ohos.permission.READ_CONTACTS", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + }, + { + "name": "ohos.permission.WRITE_CONTACTS", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + }, + { + "name": "ohos.permission.ACCESS_BLUETOOTH", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + }, + { + "name": "ohos.permission.MEDIA_LOCATION", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + }, + { + "name": "ohos.permission.MICROPHONE", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + }, + { + "name": "ohos.permission.ACCESS_NOTIFICATION_POLICY", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + }, + { + "name": "ohos.permission.READ_MEDIA", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:module_desc" + } + ] + } +} \ No newline at end of file diff --git a/permission_handler_ohos/example/ohos/entry/src/main/resources/base/element/color.json b/permission_handler_ohos/example/ohos/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/permission_handler_ohos/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/permission_handler_ohos/example/ohos/entry/src/main/resources/base/element/string.json b/permission_handler_ohos/example/ohos/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/permission_handler_ohos/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": "label" + } + ] +} \ No newline at end of file diff --git a/permission_handler_ohos/example/ohos/entry/src/main/resources/base/media/icon.png b/permission_handler_ohos/example/ohos/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/permission_handler_ohos/example/ohos/entry/src/main/resources/base/media/icon.png differ diff --git a/permission_handler_ohos/example/ohos/entry/src/main/resources/base/profile/main_pages.json b/permission_handler_ohos/example/ohos/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/permission_handler_ohos/example/ohos/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/permission_handler_ohos/example/ohos/entry/src/main/resources/en_US/element/string.json b/permission_handler_ohos/example/ohos/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/permission_handler_ohos/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": "label" + } + ] +} \ No newline at end of file diff --git a/permission_handler_ohos/example/ohos/entry/src/main/resources/zh_CN/element/string.json b/permission_handler_ohos/example/ohos/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..597ecf95e61d7e30367c22fe2f8638008361b044 --- /dev/null +++ b/permission_handler_ohos/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": "label" + } + ] +} \ No newline at end of file diff --git a/permission_handler_ohos/example/ohos/entry/src/test/List.test.ets b/permission_handler_ohos/example/ohos/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0db841ed9cff9fdea904b802e68d01f1d9b2b36a --- /dev/null +++ b/permission_handler_ohos/example/ohos/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* +* 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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest() +} \ No newline at end of file diff --git a/permission_handler_ohos/example/ohos/entry/src/test/LocalUnit.test.ets b/permission_handler_ohos/example/ohos/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f3517276bcfc5453175c8f9b532d32b71e7d0e76 --- /dev/null +++ b/permission_handler_ohos/example/ohos/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* +* 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', function () { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(function () { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(function () { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(function () { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(function () { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, function () { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/permission_handler_ohos/example/ohos/hvigor/hvigor-config.json5 b/permission_handler_ohos/example/ohos/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f9138d9c2333822e5e95613c65cf6f2ca0c79654 --- /dev/null +++ b/permission_handler_ohos/example/ohos/hvigor/hvigor-config.json5 @@ -0,0 +1,23 @@ +/* +* 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. +*/ + +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "properties": { + "ohos.nativeResolver": false, + } +} \ No newline at end of file diff --git a/permission_handler_ohos/example/ohos/hvigorfile.ts b/permission_handler_ohos/example/ohos/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..5a172b770e3b15f67c12152d00f38f2084d3915b --- /dev/null +++ b/permission_handler_ohos/example/ohos/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 { appTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file diff --git a/permission_handler_ohos/example/ohos/oh-package.json5 b/permission_handler_ohos/example/ohos/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..950211f86fc59a26721bd65197712333929faa15 --- /dev/null +++ b/permission_handler_ohos/example/ohos/oh-package.json5 @@ -0,0 +1,20 @@ +{ + "modelVersion": "5.0.0", + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "example", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": { + "@ohos/flutter_ohos": "file:./har/flutter.har" + }, + "overrides": { + "@ohos/flutter_ohos": "file:./har/flutter.har", + "permission_handler_ohos": "file:./har/permission_handler_ohos.har", + "@ohos/flutter_module": "file:./entry" + } +} \ No newline at end of file diff --git a/permission_handler_ohos/example/pubspec.yaml b/permission_handler_ohos/example/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..38df7c1a8341c6ceb17aa6882cecc6b1809423e7 --- /dev/null +++ b/permission_handler_ohos/example/pubspec.yaml @@ -0,0 +1,44 @@ +# 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. + +name: permission_handler_ohos_example +description: Demonstrates how to use the permission_handler_ohos plugin. + +environment: + sdk: '>=2.19.6 <4.0.0' + +dependencies: + baseflow_plugin_template: ^2.1.2 + flutter: + sdk: flutter + +dev_dependencies: + flutter_test: + sdk: flutter + + permission_handler_ohos: + # When depending on this package from a real application you should use: + # permission_handler_ohos: ^x.y.z + # See https://dart.dev/tools/pub/dependencies#version-constraints + # The example app is bundled with the plugin so we use a path dependency on + # the parent directory to use the current plugin's version. + path: ../ + + url_launcher: ^6.0.12 + +flutter: + uses-material-design: true + + assets: + - res/images/baseflow_logo_def_light-02.png + - res/images/poweredByBaseflowLogoLight@3x.png diff --git a/permission_handler_ohos/example/res/images/baseflow_logo_def_light-02.png b/permission_handler_ohos/example/res/images/baseflow_logo_def_light-02.png new file mode 100644 index 0000000000000000000000000000000000000000..85f071f275a6572658078b2e05b773cf5e006907 Binary files /dev/null and b/permission_handler_ohos/example/res/images/baseflow_logo_def_light-02.png differ diff --git a/permission_handler_ohos/example/res/images/poweredByBaseflowLogoLight.png b/permission_handler_ohos/example/res/images/poweredByBaseflowLogoLight.png new file mode 100644 index 0000000000000000000000000000000000000000..6b9f1aae184f57e6b8306ad54adeff9bf35b7e8e Binary files /dev/null and b/permission_handler_ohos/example/res/images/poweredByBaseflowLogoLight.png differ diff --git a/permission_handler_ohos/example/res/images/poweredByBaseflowLogoLight@2x.png b/permission_handler_ohos/example/res/images/poweredByBaseflowLogoLight@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..66901d9eaf642b4d16e7b5f8e2be9b3d3d912371 Binary files /dev/null and b/permission_handler_ohos/example/res/images/poweredByBaseflowLogoLight@2x.png differ diff --git a/permission_handler_ohos/example/res/images/poweredByBaseflowLogoLight@3x.png b/permission_handler_ohos/example/res/images/poweredByBaseflowLogoLight@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..36fbdff3812d2ab9da6593693dcd3f619b303326 Binary files /dev/null and b/permission_handler_ohos/example/res/images/poweredByBaseflowLogoLight@3x.png differ diff --git a/permission_handler_ohos/ohos/.gitignore b/permission_handler_ohos/ohos/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6f7b4f89c49a6abadc383d9665d3b4c171d466bc --- /dev/null +++ b/permission_handler_ohos/ohos/.gitignore @@ -0,0 +1,17 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test + +/entry/libs/arm64-v8a/libflutter.so +/entry/src/main/resources/rawfile/flutter_assets +**.har +**/oh-package-lock.json5 +BuildProfile.ets diff --git a/permission_handler_ohos/ohos/build-profile.json5 b/permission_handler_ohos/ohos/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c6a1887696bb3b9e8904ba51758a5516168d2e53 --- /dev/null +++ b/permission_handler_ohos/ohos/build-profile.json5 @@ -0,0 +1,26 @@ +/* +* 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" + } + ] +} \ No newline at end of file diff --git a/permission_handler_ohos/ohos/hvigorfile.ts b/permission_handler_ohos/ohos/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..5384423c6ef108fd39dd8d7d2cd0489769f720a3 --- /dev/null +++ b/permission_handler_ohos/ohos/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 { harTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/permission_handler_ohos/ohos/index.ets b/permission_handler_ohos/ohos/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07b1ab6c8d91d68321b0a06622a79754d8462a98 --- /dev/null +++ b/permission_handler_ohos/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 PermissionHandlerPlugin from './src/main/ets/com/baseflow/permissionhandler/PermissionHandlerPlugin'; +export default PermissionHandlerPlugin; diff --git a/permission_handler_ohos/ohos/oh-package.json5 b/permission_handler_ohos/ohos/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..aa5c408b0b88d1c673c2a0c592c67238730807c2 --- /dev/null +++ b/permission_handler_ohos/ohos/oh-package.json5 @@ -0,0 +1,27 @@ +/* +* 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. +*/ + +{ + "name": "permission_handler_ohos", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "index.ets", + "author": "", + "license": "", + "dependencies": { + "@ohos/flutter_ohos": "file:./har/flutter.har" + } +} + diff --git a/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/AppSettingManager.ets b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/AppSettingManager.ets new file mode 100644 index 0000000000000000000000000000000000000000..8a7c9dc032b7a59ce8b51f0a1f82e663071e345a --- /dev/null +++ b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/AppSettingManager.ets @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import bundleManager from '@ohos.bundle.bundleManager'; +import Log from '@ohos/flutter_ohos/src/main/ets/util/Log'; +import { ErrorCallback } from './ErrorCallback'; +import PermissionConstants from './PermissionConstants'; +import Want from '@ohos.app.ability.Want'; + +export class AppSettingManager { + openAppSettings(ability: UIAbility | null, successCallback: OpenAppSettingsSuccessCallback, errorCallback: ErrorCallback): void { + if(ability == null) { + Log.d(PermissionConstants.LOG_TAG, "Context cannot be null."); + errorCallback?.onError("PermissionHandler.AppSettingsManager", "Android context cannot be null."); + return; + } + bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION).then((bundleInfo) => { + if (bundleInfo == null) { + successCallback.onSuccess(false); + return; + } + let want: Want = { + abilityName: 'com.huawei.hmos.settings.MainAbility', + bundleName: 'com.huawei.hmos.settings', + uri: 'application_info_entry', + parameters: { + pushParams : bundleInfo.name + } + }; + try { + ability.context.startAbility(want).then(() => { + successCallback.onSuccess(true); + }); + } catch (error) { + Log.i(PermissionConstants.LOG_TAG, "start ability exception"); + successCallback?.onSuccess(false); + } + }); + } +} + +export interface OpenAppSettingsSuccessCallback { + onSuccess(appSettingsOpenedSuccessfully : boolean): void; +} \ No newline at end of file diff --git a/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/ErrorCallback.ets b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/ErrorCallback.ets new file mode 100644 index 0000000000000000000000000000000000000000..53fdf790eecdd1c385ea19e2223d41d0c94bc7c6 --- /dev/null +++ b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/ErrorCallback.ets @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2024 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 interface ErrorCallback { + onError(errorCode: string, errorDescription: string):void; +} \ No newline at end of file diff --git a/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/MethodCallHandlerImpl.ets b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/MethodCallHandlerImpl.ets new file mode 100644 index 0000000000000000000000000000000000000000..39dfeab66bb67b813206b226883d193a2acb03f0 --- /dev/null +++ b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/MethodCallHandlerImpl.ets @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { MethodCallHandler, MethodResult } from '@ohos/flutter_ohos/src/main/ets/plugin/common/MethodChannel'; +import common from '@ohos.app.ability.common'; +import MethodCall from '@ohos/flutter_ohos/src/main/ets/plugin/common/MethodCall'; +import { AppSettingManager } from './AppSettingManager'; +import { PermissionManager } from './PermissionManager'; +import { ServiceManager } from './ServiceManager'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import ArrayList from '@ohos.util.ArrayList'; + +export class MethodCallHandlerImpl implements MethodCallHandler { + private applicationContext: common.Context; + private permissionManager: PermissionManager; + private appSettingManager: AppSettingManager; + private serviceManager: ServiceManager; + private ability: UIAbility | null = null; + + public constructor(applicationContext: common.Context, appSettingManager: AppSettingManager, + permissionManager: PermissionManager, serviceManager: ServiceManager) { + this.applicationContext = applicationContext; + this.appSettingManager = appSettingManager; + this.permissionManager = permissionManager; + this.serviceManager = serviceManager; + } + + public setAbility(ability: UIAbility | null): void { + this.ability = ability; + } + + onMethodCall(call: MethodCall, result: MethodResult): void { + switch (call.method) { + case 'checkServiceStatus': + let permission: number = call.args; + this.serviceManager.checkServiceStatus(permission, this.applicationContext, { + onSuccess: (serviceStatus: number) => { + result.success(serviceStatus); + } + } as ESObject, { + onError: (errorCode: string, errorDescription: string) => { + result.error(errorCode, errorDescription, null); + } + } as ESObject); + break + case 'checkPermissionStatus': + let checkedPermission: number = call.args; + this.permissionManager.checkPermissionStatus(checkedPermission, this.applicationContext, { + onSuccess : (permissionStatus: number) => { + result.success(permissionStatus); + } + } as ESObject); + break; + case 'requestPermissions': + let permissions: ArrayList = call.args; + this.permissionManager.requestPermissions(permissions, this.ability as UIAbility, { + onSuccess : (results: Map) => { + result.success(results); + } + } as ESObject, { + onError: (errorCode: string, errorDescription: string) => { + result.error(errorCode, errorDescription, null); + } + } as ESObject); + break; + case 'shouldShowRequestPermissionRationale': + let showShowPermission: number = call.args; + this.permissionManager.shouldShowRequestPermissionRationale(showShowPermission, { + onSuccess : (isShow: boolean) => { + result.success(isShow); + } + } as ESObject, { + onError: (errorCode: string, errorDescription: string) => { + result.error(errorCode, errorDescription, null); + } + } as ESObject); + break; + case 'openAppSettings': + this.appSettingManager.openAppSettings(this.ability, { + onSuccess: (isSuccess: boolean) => { + result.success(isSuccess) + } + } as ESObject, { + onError: (errorCode: string, errorDescription: string) => { + result.error(errorCode, errorDescription, null); + } + } as ESObject); + break; + default: + result.notImplemented(); + break; + } + } +} diff --git a/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/PermissionConstants.ets b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/PermissionConstants.ets new file mode 100644 index 0000000000000000000000000000000000000000..d79a42fedc1e0039d068489898518d1c3d33f318 --- /dev/null +++ b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/PermissionConstants.ets @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2024 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 default class PermissionConstants { + static LOG_TAG: string = 'permission_handler'; + static PERMISSION_CODE: number = 24; + static PERMISSION_CODE_IGNORE_BATTERY_OPTIMIZATIONS: number = 209; + static PERMISSION_CODE_MANAGE_EXTERNAL_STORAGE: number = 210; + static PERMISSION_CODE_SYSTEM_ALERT_WINDOW: number = 211; + static PERMISSION_CODE_REQUEST_INSTALL_PACKAGES: number = 212; + static PERMISSION_CODE_ACCESS_NOTIFICATION_POLICY: number = 213; + static PERMISSION_CODE_SCHEDULE_EXACT_ALARM = 214; + + //PERMISSION_GROUP + // Deprecated in favor of PERMISSION_GROUP_CALENDAR_WRITE_ONLY and + // PERMISSION_GROUP_CALENDAR_FULL_ACCESS. + static PERMISSION_GROUP_CALENDAR: number = 0; + static PERMISSION_GROUP_CAMERA: number = 1; + static PERMISSION_GROUP_CONTACTS: number = 2; + static PERMISSION_GROUP_LOCATION: number = 3; + static PERMISSION_GROUP_LOCATION_ALWAYS: number = 4; + static PERMISSION_GROUP_LOCATION_WHEN_IN_USE: number = 5; + static PERMISSION_GROUP_MEDIA_LIBRARY: number = 6; + static PERMISSION_GROUP_MICROPHONE: number = 7; + static PERMISSION_GROUP_PHONE: number = 8; + static PERMISSION_GROUP_PHOTOS: number = 9; + static PERMISSION_GROUP_PHOTOS_ADD_ONLY: number = 10; + static PERMISSION_GROUP_REMINDERS: number = 11; + static PERMISSION_GROUP_SENSORS: number = 12; + static PERMISSION_GROUP_SMS: number = 13; + static PERMISSION_GROUP_SPEECH: number = 14; + static PERMISSION_GROUP_STORAGE: number = 15; + static PERMISSION_GROUP_IGNORE_BATTERY_OPTIMIZATIONS: number = 16; + static PERMISSION_GROUP_NOTIFICATION: number = 17; + static PERMISSION_GROUP_ACCESS_MEDIA_LOCATION: number = 18; + static PERMISSION_GROUP_ACTIVITY_RECOGNITION: number = 19; + static PERMISSION_GROUP_UNKNOWN: number = 20; + static PERMISSION_GROUP_BLUETOOTH: number = 21; + static PERMISSION_GROUP_MANAGE_EXTERNAL_STORAGE: number = 22; + static PERMISSION_GROUP_SYSTEM_ALERT_WINDOW: number = 23; + static PERMISSION_GROUP_REQUEST_INSTALL_PACKAGES: number = 24; + static PERMISSION_GROUP_APP_TRACK_TRANSPARENCY: number = 25; + static PERMISSION_GROUP_CRITICAL_ALERTS: number = 26; + static PERMISSION_GROUP_ACCESS_NOTIFICATION_POLICY: number = 27; + static PERMISSION_GROUP_BLUETOOTH_SCAN: number = 28; + static PERMISSION_GROUP_BLUETOOTH_ADVERTISE: number = 29; + static PERMISSION_GROUP_BLUETOOTH_CONNECT: number = 30; + static PERMISSION_GROUP_NEARBY_WIFI_DEVICES: number = 31; + static PERMISSION_GROUP_VIDEOS: number = 32; + static PERMISSION_GROUP_AUDIO: number = 33; + static PERMISSION_GROUP_SCHEDULE_EXACT_ALARM: number = 34; + static PERMISSION_GROUP_SENSORS_ALWAYS: number = 35; + static PERMISSION_GROUP_CALENDAR_WRITE_ONLY = 36; + static PERMISSION_GROUP_CALENDAR_FULL_ACCESS = 37; + static PERMISSION_GROUP_ASSISTANT = 38; + static PERMISSION_GROUP_BACKGROUND_REFRESH = 39; + + //PERMISSION_STATUS + static PERMISSION_STATUS_DENIED: number = 0; + static PERMISSION_STATUS_GRANTED: number = 1; + static PERMISSION_STATUS_RESTRICTED: number = 2; + static PERMISSION_STATUS_LIMITED: number = 3; + static PERMISSION_STATUS_NEVER_ASK_AGAIN: number = 4; + + //SERVICE_STATUS + static SERVICE_STATUS_DISABLED: number = 0; + static SERVICE_STATUS_ENABLED: number = 1; + static SERVICE_STATUS_NOT_APPLICABLE: number = 2; +} \ No newline at end of file diff --git a/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/PermissionHandlerPlugin.ets b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/PermissionHandlerPlugin.ets new file mode 100644 index 0000000000000000000000000000000000000000..1697ddd9900fdfc1f7ae880a1412e290ef3d5598 --- /dev/null +++ b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/PermissionHandlerPlugin.ets @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import AbilityAware from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/ability/AbilityAware'; +import { AbilityPluginBinding } from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/ability/AbilityPluginBinding'; +import { FlutterPlugin, FlutterPluginBinding } from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin'; +import Log from '@ohos/flutter_ohos/src/main/ets/util/Log'; +import { BinaryMessenger } from '@ohos/flutter_ohos/src/main/ets/plugin/common/BinaryMessenger'; +import MethodChannel from '@ohos/flutter_ohos/src/main/ets/plugin/common/MethodChannel'; +import StandardMethodCodec from '@ohos/flutter_ohos/src/main/ets/plugin/common/StandardMethodCodec'; +import { AppSettingManager } from './AppSettingManager'; +import { MethodCallHandlerImpl } from './MethodCallHandlerImpl'; +import { PermissionManager } from './PermissionManager'; +import { ServiceManager } from './ServiceManager'; + + +const TAG: string = 'PermissionHandlerPlugin'; + +/** + * Platform implementation of the permission_handler Flutter plugin. + * + *

Instantiate this in an add to app scenario to gracefully handle ability and context changes. + * See {@code com.example.permissionhandlerexample.MainAbility} for an example. + * + */ +export default class PermissionHandlerPlugin implements FlutterPlugin, AbilityAware { + private permissionManager: PermissionManager; + private methodChannel: MethodChannel | null = null; + private methodCallHandler: MethodCallHandlerImpl | null = null; + private pluginBinding: AbilityPluginBinding | null = null; + + constructor() { + this.permissionManager = new PermissionManager(); + } + + onAttachedToAbility(binding: AbilityPluginBinding): void { + this.pluginBinding = binding; + this.startListeningToAbility(this.pluginBinding.getAbility()); + } + + onDetachedFromAbility(): void { + this.stopListeningToAbility(); + } + + getUniqueClassName(): string { + return TAG; + } + + onAttachedToEngine(binding: FlutterPluginBinding): void { + Log.i(TAG, 'onAttachedToEngine'); + this.startListening(binding?.getApplicationContext(), binding?.getBinaryMessenger()); + } + + onDetachedFromEngine(binding: FlutterPluginBinding): void { + this.stopListening(); + } + + private startListening(context: common.Context, message: BinaryMessenger): void { + this.methodChannel = new MethodChannel(message, 'flutter.baseflow.com/permissions/methods', StandardMethodCodec.INSTANCE); + this.methodCallHandler = new MethodCallHandlerImpl(context, new AppSettingManager(), + this.permissionManager, new ServiceManager()); + this.methodChannel.setMethodCallHandler(this.methodCallHandler); + } + + private stopListening(): void { + this.methodChannel?.setMethodCallHandler(null); + this.methodChannel = null; + this.methodCallHandler = null; + } + + private startListeningToAbility(ability: UIAbility): void { + if (this.methodCallHandler != null) { + this.methodCallHandler.setAbility(ability); + } + } + + private stopListeningToAbility(): void { + if (this.methodCallHandler != null) { + this.methodCallHandler.setAbility(null); + } + } +} \ No newline at end of file diff --git a/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/PermissionManager.ets b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/PermissionManager.ets new file mode 100644 index 0000000000000000000000000000000000000000..970b8cf6935cee49471de62e2e19d878547b9da0 --- /dev/null +++ b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/PermissionManager.ets @@ -0,0 +1,320 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import PermissionConstants from './PermissionConstants'; +import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'; +import bundleManager from '@ohos.bundle.bundleManager'; +import PermissionUtils from './PermissionUtils'; +import Log from '@ohos/flutter_ohos/src/main/ets/util/Log'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import ArrayList from '@ohos.util.ArrayList'; +import { ErrorCallback } from './ErrorCallback'; +import { BusinessError, Callback } from '@ohos.base'; +import { notificationManager } from '@kit.NotificationKit'; + +export class PermissionManager { + private tokenId: number | null = null; + + private atManager: abilityAccessCtrl.AtManager; + + private ongoing: boolean = false; + + private ability: UIAbility | null = null; + + private successCallback: RequestPermissionsSuccessCallback | null = null; + + private requestResults:Map | null = null; + + constructor() { + this.atManager = abilityAccessCtrl.createAtManager(); + } + + /** + * 检测权限状态 + * + * @param permission 权限 + * @param context 上下文 + * @param successCallback 回调结果 + */ + public checkPermissionStatus(permission: number, context: common.Context, + successCallback: CheckPermissionSuccessCallback): void { + this.determinePermissionStatus(permission, successCallback); + } + + private determinePermissionStatus(permission: number, successCallback: CheckPermissionSuccessCallback): void { + if (permission == PermissionConstants.PERMISSION_GROUP_NOTIFICATION) { + let enabled = notificationManager.isNotificationEnabledSync(); + if (enabled) { + successCallback.onSuccess(PermissionConstants.PERMISSION_STATUS_GRANTED); + } else { + successCallback.onSuccess(PermissionConstants.PERMISSION_STATUS_DENIED); + } + return; + } + if (permission == PermissionConstants.PERMISSION_GROUP_BLUETOOTH) { + this.checkBluetoothPermissionStatus(successCallback); + return; + } + PermissionUtils.getManifestNames(permission, (names: ArrayList) => { + if (names == null || names == undefined) { + Log.d(PermissionConstants.LOG_TAG, "No specific permissions needed for: " + permission); + successCallback.onSuccess(PermissionConstants.PERMISSION_STATUS_GRANTED); + return; + } + if (names.length == 0) { + Log.d(PermissionConstants.LOG_TAG, "No permissions found in manifest for: " + names + permission); + if (permission == PermissionConstants.PERMISSION_GROUP_IGNORE_BATTERY_OPTIMIZATIONS) { + successCallback.onSuccess(PermissionConstants.PERMISSION_STATUS_DENIED); + return; + } + if (permission == PermissionConstants.PERMISSION_GROUP_MANAGE_EXTERNAL_STORAGE) { + successCallback.onSuccess(PermissionConstants.PERMISSION_STATUS_GRANTED); + return; + } + successCallback.onSuccess(PermissionConstants.PERMISSION_STATUS_DENIED); + return; + } + for (let name of names) { + if (permission == PermissionConstants.PERMISSION_GROUP_IGNORE_BATTERY_OPTIMIZATIONS) { + successCallback.onSuccess(PermissionConstants.PERMISSION_STATUS_DENIED); + return; + } + if (permission == PermissionConstants.PERMISSION_GROUP_MANAGE_EXTERNAL_STORAGE) { + successCallback.onSuccess(PermissionConstants.PERMISSION_STATUS_GRANTED); + return; + } + if (permission == PermissionConstants.PERMISSION_GROUP_SYSTEM_ALERT_WINDOW) { + successCallback.onSuccess(PermissionConstants.PERMISSION_STATUS_GRANTED); + return; + } + if (permission == PermissionConstants.PERMISSION_GROUP_REQUEST_INSTALL_PACKAGES) { + successCallback.onSuccess(PermissionConstants.PERMISSION_STATUS_GRANTED); + return; + } + if (this.tokenId == null || this.tokenId == undefined) { + let bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION) + this.tokenId = bundleInfo.appInfo.accessTokenId; + } + let status: abilityAccessCtrl.GrantStatus = this.atManager.verifyAccessTokenSync(this.tokenId, name as Permissions); + if (status != abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) { + successCallback.onSuccess(PermissionConstants.PERMISSION_STATUS_DENIED); + return; + } + } + successCallback.onSuccess(PermissionConstants.PERMISSION_STATUS_GRANTED); + }); + } + + requestPermissions(permissions: ArrayList, ability: UIAbility, + successCallback: RequestPermissionsSuccessCallback, errorCallback: ErrorCallback ): void { + if (this.ongoing) { + errorCallback.onError( "PermissionHandler.PermissionManager", + "A request for permissions is already running, please wait for it to finish before doing another request (note that you can request multiple permissions at the same time)."); + return; + } + if (ability == null) { + Log.d(PermissionConstants.LOG_TAG, "Unable to detect current Activity."); + errorCallback.onError( + "PermissionHandler.PermissionManager", + "Unable to detect current Ohos Activity."); + return; + } + this.successCallback = successCallback; + this.ability = ability; + this.requestResults = new Map(); + this.getPermissionToRequest(permissions, (permissionsToRequest: ESObject) => { + if (permissionsToRequest?.length > 0) { + try { + this.atManager.requestPermissionsFromUser(ability.context, permissionsToRequest.convertToArray(), (error, result) => { + this.ongoing = false; + let grant: Array = result.authResults; + let permissionNames: Array = result.permissions; + // Calendar permissions are split between WRITE and READ in Android, and split between WRITE + // and FULL ACCESS in the plugin. We need special logic for this translation. + let calendarWriteIndex: number = permissionNames.indexOf('ohos.permission.WRITE_CALENDAR'); + // WRITE -> WRITE. + if (calendarWriteIndex >= 0) { + let authResult: number = grant[calendarWriteIndex]; + let writeStatus: number = PermissionUtils.toPermissionStatus(authResult); + this.requestResults?.set(PermissionConstants.PERMISSION_GROUP_CALENDAR_WRITE_ONLY, writeStatus); + + // WRITE + READ -> FULL ACCESS. + let calendarReadIndex: number = permissionNames.indexOf('ohos.permission.READ_CALENDAR'); + if (calendarReadIndex >= 0) { + let readGrantResult: number = grant[calendarReadIndex]; + let readStatus: number = PermissionUtils.toPermissionStatus(readGrantResult); + let fullAccessStatus = PermissionUtils.strictestStatusFromTwo(writeStatus, readStatus); + this.requestResults?.set(PermissionConstants.PERMISSION_GROUP_CALENDAR_FULL_ACCESS, fullAccessStatus); + // Support deprecated CALENDAR permission. + this.requestResults?.set(PermissionConstants.PERMISSION_GROUP_CALENDAR, fullAccessStatus); + } + } + + for (let i = 0; i < permissionNames.length; i++) { + let permissionName: string = permissionNames[i]; + let authResult: number = grant[i]; + let permission: number = PermissionUtils.parseOhosName(permissionName); + // WRITE_CALENDAR and READ_CALENDAR permission results have already been handled. + if ((permissionName == 'ohos.permission.WRITE_CALENDAR') || (permissionName == 'ohos.permission.READ_CALENDAR')) { + continue; + } + if (permission == PermissionConstants.PERMISSION_GROUP_UNKNOWN) + continue; + if (permission == PermissionConstants.PERMISSION_GROUP_NOTIFICATION) { + notificationManager.requestEnableNotification(this.ability?.context).then(() => { + let enabled = notificationManager.isNotificationEnabledSync(); + if (enabled) { + this.requestResults?.set(PermissionConstants.PERMISSION_GROUP_NOTIFICATION, PermissionConstants.PERMISSION_STATUS_GRANTED); + } else { + this.requestResults?.set(PermissionConstants.PERMISSION_GROUP_NOTIFICATION, PermissionConstants.PERMISSION_STATUS_DENIED); + } + this.successCallback?.onSuccess(this.requestResults as Map); + }).catch((err: BusinessError) => { + this.requestResults?.set(PermissionConstants.PERMISSION_GROUP_NOTIFICATION, PermissionConstants.PERMISSION_STATUS_DENIED); + this.successCallback?.onSuccess(this.requestResults as Map); + }); + return; + } else if (permission == PermissionConstants.PERMISSION_GROUP_MICROPHONE) { + this.requestResults?.set(PermissionConstants.PERMISSION_GROUP_MICROPHONE, PermissionUtils.toPermissionStatus(authResult)); + this.requestResults?.set(PermissionConstants.PERMISSION_GROUP_SPEECH, PermissionUtils.toPermissionStatus(authResult)); + } else if (permission == PermissionConstants.PERMISSION_GROUP_LOCATION_ALWAYS) { + this.requestResults?.set(PermissionConstants.PERMISSION_GROUP_LOCATION_ALWAYS, PermissionUtils.toPermissionStatus(authResult)); + } else if (permission == PermissionConstants.PERMISSION_GROUP_LOCATION) { + + if (permissionName == 'ohos.permission.APPROXIMATELY_LOCATION') { + this.requestResults?.set(PermissionConstants.PERMISSION_GROUP_LOCATION_WHEN_IN_USE, PermissionUtils.toPermissionStatus(authResult)); + } + if (permissionName == 'ohos.permission.LOCATION') { + this.requestResults?.set(PermissionConstants.PERMISSION_GROUP_LOCATION, PermissionUtils.toPermissionStatus(authResult)); + } + + } else { + this.requestResults?.set(permission, PermissionUtils.toPermissionStatus(authResult)); + } + PermissionUtils.updatePermissionShouldShowStatus(permission); + } + this.successCallback?.onSuccess(this.requestResults as Map); + }); + } catch (error) { + this.ongoing = false; + this.successCallback?.onSuccess(this.requestResults as Map); + } + } else { + this.ongoing = false; + this.successCallback?.onSuccess(this.requestResults as Map); + } + }); + } + + private getPermissionToRequest(permissions: ArrayList, callback: Callback>): void { + let permissionsToRequest: ArrayList = new ArrayList(); + let size: number = permissions.length; + for (let permission of permissions) { + this.determinePermissionStatus(permission, { + onSuccess : (permissionStatus:ESObject) => { + if (permissionStatus == PermissionConstants.PERMISSION_STATUS_GRANTED) { + if (!this.requestResults?.has(permission)) { + this.requestResults?.set(permission, PermissionConstants.PERMISSION_STATUS_GRANTED); + } + size -= 1; + if (size == 0) { + callback(permissionsToRequest); + } + return; + } + PermissionUtils.getManifestNames(permission, (names:ArrayList) => { + if (names == null || names.length == 0) { + if (this.requestResults && !this.requestResults.has(permission)) { + if (permission == PermissionConstants.PERMISSION_GROUP_IGNORE_BATTERY_OPTIMIZATIONS) { + this.requestResults.set(permission, PermissionConstants.PERMISSION_STATUS_DENIED); + } + if (permission == PermissionConstants.PERMISSION_GROUP_MANAGE_EXTERNAL_STORAGE) { + this.requestResults.set(permission, PermissionConstants.PERMISSION_STATUS_GRANTED); + } + if (permission == PermissionConstants.PERMISSION_GROUP_SYSTEM_ALERT_WINDOW) { + this.requestResults.set(permission, PermissionConstants.PERMISSION_STATUS_GRANTED); + } + } + size -= 1; + if (size == 0) { + callback(permissionsToRequest); + } + return; + } + if (permission == PermissionConstants.PERMISSION_GROUP_IGNORE_BATTERY_OPTIMIZATIONS) { + // don't support + } else if (permission == PermissionConstants.PERMISSION_GROUP_MANAGE_EXTERNAL_STORAGE) { + // don't support + } else if (permission == PermissionConstants.PERMISSION_GROUP_SYSTEM_ALERT_WINDOW) { + // don't support + } else { + for (let name of names) { + permissionsToRequest.add(name); + } + } + size -= 1; + if (size == 0) { + callback(permissionsToRequest); + } + }); + } + } as ESObject); + } + } + + private checkBluetoothPermissionStatus(successCallback: CheckPermissionSuccessCallback): void { + PermissionUtils.getManifestNames(PermissionConstants.PERMISSION_GROUP_BLUETOOTH, (permissions: ESObject) => { + let missingInManifest: boolean = permissions == null || permissions.isEmpty(); + if (missingInManifest) { + Log.d(PermissionConstants.LOG_TAG, "Bluetooth permission missing in manifest"); + successCallback.onSuccess(PermissionConstants.PERMISSION_STATUS_DENIED); + } else { + successCallback.onSuccess(PermissionConstants.PERMISSION_STATUS_GRANTED); + } + }); + } + + private checkPermission(successCallback: CheckPermissionSuccessCallback, permissionName: Permissions): void { + if (this.tokenId == null || this.tokenId == undefined) { + bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION) + .then((bundleInfo)=> { + this.tokenId = bundleInfo.appInfo.accessTokenId; + successCallback.onSuccess(this.atManager.verifyAccessTokenSync(this.tokenId, permissionName)); + }); + } else { + successCallback.onSuccess(this.atManager.verifyAccessTokenSync(this.tokenId, permissionName)); + } + } + + shouldShowRequestPermissionRationale(permission: number, + callback: ShouldShowRequestPermissionRationaleSuccessCallback, errorCallback: ErrorCallback): void { + callback?.onSuccess(false); + } +} + +export interface CheckPermissionSuccessCallback { + onSuccess(permissionStatus: number): void; +} + +export interface RequestPermissionsSuccessCallback { + onSuccess(results: Map ) : void; +} + +export interface ShouldShowRequestPermissionRationaleSuccessCallback { + onSuccess(shouldShowRequestPermissionRationale: boolean): void; +} + diff --git a/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/PermissionUtils.ets b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/PermissionUtils.ets new file mode 100644 index 0000000000000000000000000000000000000000..a4a77612e5bc974f0514d3dc34438230d140ed45 --- /dev/null +++ b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/PermissionUtils.ets @@ -0,0 +1,346 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import bundleManager from '@ohos.bundle.bundleManager'; +import ArrayList from '@ohos.util.ArrayList'; +import { Callback } from '@ohos.base'; +import Log from '@ohos/flutter_ohos/src/main/ets/util/Log'; +import PermissionConstants from './PermissionConstants'; +import { PermissionRequestResult } from '@kit.AbilityKit'; + +const TAG: string = 'PermissionUtils'; + +export default class PermissionUtils { + static parseOhosName(permission: String): number { + switch (permission) { + case 'ohos.permission.WRITE_CALENDAR': + return PermissionConstants.PERMISSION_GROUP_CALENDAR_WRITE_ONLY; + case 'ohos.permission.WRITE_CALENDAR': + case 'ohos.permission.READ_CALENDAR': + return PermissionConstants.PERMISSION_GROUP_CALENDAR_FULL_ACCESS; + case 'ohos.permission.READ_CALENDAR': + case 'ohos.permission.WRITE_CALENDAR': + return PermissionConstants.PERMISSION_GROUP_CALENDAR; + case 'ohos.permission.CAMERA': + return PermissionConstants.PERMISSION_GROUP_CAMERA; + case 'ohos.permission.READ_CONTACTS': + case 'ohos.permission.WRITE_CONTACTS': + // case 'ohos.permission.GET_LOCAL_ACCOUNTS': + return PermissionConstants.PERMISSION_GROUP_CONTACTS; + case 'ohos.permission.LOCATION_IN_BACKGROUND': + return PermissionConstants.PERMISSION_GROUP_LOCATION_ALWAYS; + case 'ohos.permission.LOCATION': + case 'ohos.permission.APPROXIMATELY_LOCATION': + return PermissionConstants.PERMISSION_GROUP_LOCATION; + case 'ohos.permission.MICROPHONE': + return PermissionConstants.PERMISSION_GROUP_MICROPHONE; + case 'ohos.permission.SET_TELEPHONY_STATE': + case 'ohos.permission.GET_TELEPHONY_STATE': + case 'ohos.permission.PLACE_CALL': + case 'ohos.permission.ANSWER_CALL': + case 'ohos.permission.READ_CALL_LOG': + case 'ohos.permission.WRITE_CALL_LOG': + case 'ohos.permission.CONNECT_CELLULAR_CALL_SERVICE': + case 'ohos.permission.MANAGE_VOICEMAIL': + return PermissionConstants.PERMISSION_GROUP_PHONE; + case 'ohos.permission.READ_HEALTH_DATA': + return PermissionConstants.PERMISSION_GROUP_SENSORS; + case 'ohos.permission.RECEIVE_SMS': + case 'ohos.permission.RECEIVE_WAP_MESSAGES': + case 'ohos.permission.RECEIVE_MMS': + return PermissionConstants.PERMISSION_GROUP_SMS; + case 'ohos.permission.READ_EXTERNAL_STORAGE': + case 'ohos.permission.WRITE_EXTERNAL_STORAGE': + return PermissionConstants.PERMISSION_GROUP_STORAGE; + case 'ohos.permission.MEDIA_LOCATION': + return PermissionConstants.PERMISSION_GROUP_ACCESS_MEDIA_LOCATION; + case 'ohos.permission.ACTIVITY_MOTION': + return PermissionConstants.PERMISSION_GROUP_ACTIVITY_RECOGNITION; + case 'ohos.permission.MANAGE_EXTERNAL_STORAGE': + return PermissionConstants.PERMISSION_GROUP_MANAGE_EXTERNAL_STORAGE; + case 'ohos.permission.SYSTEM_ALERT_WINDOW': + return PermissionConstants.PERMISSION_GROUP_SYSTEM_ALERT_WINDOW; + case 'ohos.permission.INSTALL_BUNDLE': + return PermissionConstants.PERMISSION_GROUP_REQUEST_INSTALL_PACKAGES; + case 'ohos.permission.ACCESS_NOTIFICATION_POLICY': + return PermissionConstants.PERMISSION_GROUP_ACCESS_NOTIFICATION_POLICY; + case 'ohos.permission.USE_BLUETOOTH': + return PermissionConstants.PERMISSION_GROUP_BLUETOOTH_SCAN; + case 'ohos.permission.DISCOVER_BLUETOOTH': + return PermissionConstants.PERMISSION_GROUP_BLUETOOTH_ADVERTISE; + case 'ohos.permission.MANAGE_BLUETOOTH': + case 'ohos.permission.ACCESS_BLUETOOTH': + return PermissionConstants.PERMISSION_GROUP_BLUETOOTH_CONNECT; + case 'ohos.permission.NOTIFICATION_CONTROLLER': + return PermissionConstants.PERMISSION_GROUP_NOTIFICATION; + case 'ohos.permission.GET_WIFI_INFO': + case 'ohos.permission.SET_WIFI_INFO': + return PermissionConstants.PERMISSION_GROUP_NEARBY_WIFI_DEVICES; + case 'ohos.permission.READ_MEDIA': + return PermissionConstants.PERMISSION_GROUP_AUDIO; + case 'ohos.permission.READ_IMAGEVIDEO': + case 'ohos.permission.WRITE_IMAGEVIDEO': + return PermissionConstants.PERMISSION_GROUP_PHOTOS; + case 'ohos.permission.SCHEDULE_EXACT_ALARM': + return PermissionConstants.PERMISSION_GROUP_SCHEDULE_EXACT_ALARM; + default: + return PermissionConstants.PERMISSION_GROUP_UNKNOWN; + } + } + + static hasPermissionInManifest(confirmedPermission: ArrayList, permission: string, callback: Callback): void { + try { + if (confirmedPermission != null) { + for (let confirmed of confirmedPermission) { + if (confirmed == permission) { + callback(true); + return; + } + } + } + bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION) + .then((bundleInfo) => { + for (let requestedPermission of bundleInfo.reqPermissionDetails) { + if (requestedPermission?.name == permission) { + callback(true); + return; + } + } + callback(false); + }) + } catch (e) { + Log.i(TAG, 'hasPermissionInManifest exception : ' + e); + callback(false); + } + } + + static getRequestPermission(permissions: ArrayList, callback: Callback>): void { + let permissionNames: ArrayList = new ArrayList(); + try { + bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION) + .then((bundleInfo) => { + for (let requestedPermission of bundleInfo.reqPermissionDetails) { + if (permissions.has(requestedPermission.name)) { + permissionNames.add(requestedPermission.name); + } + } + // 不用经过getBundleInfo校验直接返回进行授权因此直接使用permissions + callback(permissionNames); + }) + } catch (e) { + Log.i(TAG, 'getRequestPermission exception : ' + e); + } + } + + static getManifestNames(permission: number, callback: ESObject): void { + let permissionNames: ArrayList = new ArrayList(); + switch (permission) { + case PermissionConstants.PERMISSION_GROUP_CALENDAR_WRITE_ONLY: + let calendarNamesWriteOnly: ArrayList = new ArrayList(); + calendarNamesWriteOnly.add('ohos.permission.WRITE_CALENDAR'); + PermissionUtils.getRequestPermission(calendarNamesWriteOnly, callback); + break; + case PermissionConstants.PERMISSION_GROUP_CALENDAR_FULL_ACCESS: + case PermissionConstants.PERMISSION_GROUP_CALENDAR: + let calendarNames: ArrayList = new ArrayList(); + calendarNames.add('ohos.permission.READ_CALENDAR'); + calendarNames.add('ohos.permission.WRITE_CALENDAR'); + PermissionUtils.getRequestPermission(calendarNames, callback); + break; + case PermissionConstants.PERMISSION_GROUP_CAMERA: + PermissionUtils.hasPermissionInManifest(permissionNames, 'ohos.permission.CAMERA', (camera) => { + if (camera) { + permissionNames.add('ohos.permission.CAMERA'); + } + callback(permissionNames); + }); + break; + case PermissionConstants.PERMISSION_GROUP_CONTACTS: + let contracts: ArrayList = new ArrayList(); + contracts.add('ohos.permission.READ_CONTACTS'); + contracts.add('ohos.permission.WRITE_CONTACTS'); + // contracts.add('ohos.permission.GET_LOCAL_ACCOUNTS'); + callback(contracts); + break; + case PermissionConstants.PERMISSION_GROUP_LOCATION_ALWAYS: + let location: ArrayList = new ArrayList(); + location.add('ohos.permission.LOCATION_IN_BACKGROUND'); + PermissionUtils.getRequestPermission(location, callback); + break; + case PermissionConstants.PERMISSION_GROUP_LOCATION_WHEN_IN_USE: + case PermissionConstants.PERMISSION_GROUP_LOCATION: + let locationGroup: ArrayList = new ArrayList(); + locationGroup.add('ohos.permission.LOCATION'); + locationGroup.add('ohos.permission.APPROXIMATELY_LOCATION'); + PermissionUtils.getRequestPermission(locationGroup, callback); + break; + case PermissionConstants.PERMISSION_GROUP_SPEECH: + case PermissionConstants.PERMISSION_GROUP_MICROPHONE: + let microphone: ArrayList = new ArrayList(); + microphone.add('ohos.permission.MICROPHONE'); + PermissionUtils.getRequestPermission(microphone, callback); + break; + case PermissionConstants.PERMISSION_GROUP_PHONE: + let phone: ArrayList = new ArrayList(); + phone.add('ohos.permission.SET_TELEPHONY_STATE'); + phone.add('ohos.permission.GET_TELEPHONY_STATE'); + phone.add('ohos.permission.PLACE_CALL'); + phone.add('ohos.permission.ANSWER_CALL'); + phone.add('ohos.permission.READ_CALL_LOG'); + phone.add('ohos.permission.WRITE_CALL_LOG'); + // phone.add('ohos.permission.CONNECT_CELLULAR_CALL_SERVICE'); + phone.add('ohos.permission.MANAGE_VOICEMAIL'); + callback(phone); + break; + case PermissionConstants.PERMISSION_GROUP_SENSORS: + case PermissionConstants.PERMISSION_GROUP_SENSORS_ALWAYS: + let sensor: ArrayList = new ArrayList(); + sensor.add('ohos.permission.READ_HEALTH_DATA'); + callback(sensor); + break; + case PermissionConstants.PERMISSION_GROUP_SMS: + let sms: ArrayList = new ArrayList(); + sms.add('ohos.permission.RECEIVE_SMS'); + sms.add('ohos.permission.RECEIVE_WAP_MESSAGES'); + sms.add('ohos.permission.RECEIVE_MMS'); + callback(sms); + break; + case PermissionConstants.PERMISSION_GROUP_STORAGE: + callback(permissionNames); + break; + case PermissionConstants.PERMISSION_GROUP_IGNORE_BATTERY_OPTIMIZATIONS: + callback(permissionNames); + break; + case PermissionConstants.PERMISSION_GROUP_ACCESS_MEDIA_LOCATION: + let mediaLocation: ArrayList = new ArrayList(); + mediaLocation.add('ohos.permission.MEDIA_LOCATION'); + PermissionUtils.getRequestPermission(mediaLocation, callback); + break; + case PermissionConstants.PERMISSION_GROUP_ACTIVITY_RECOGNITION: + let motion: ArrayList = new ArrayList(); + motion.add('ohos.permission.ACTIVITY_MOTION'); + callback(motion); + break; + case PermissionConstants.PERMISSION_GROUP_BLUETOOTH: + let bluetooth: ArrayList = new ArrayList(); + bluetooth.add('ohos.permission.ACCESS_BLUETOOTH'); + PermissionUtils.getRequestPermission(bluetooth, callback); + break; + case PermissionConstants.PERMISSION_GROUP_MANAGE_EXTERNAL_STORAGE: + callback(permissionNames); + break; + case PermissionConstants.PERMISSION_GROUP_SYSTEM_ALERT_WINDOW: + callback(permissionNames); + break; + case PermissionConstants.PERMISSION_GROUP_REQUEST_INSTALL_PACKAGES: + let installBundle: ArrayList = new ArrayList(); + installBundle.add('ohos.permission.INSTALL_BUNDLE'); + callback(installBundle); + break; + case PermissionConstants.PERMISSION_GROUP_ACCESS_NOTIFICATION_POLICY: + let policy: ArrayList = new ArrayList(); + policy.add('ohos.permission.ACCESS_NOTIFICATION_POLICY'); + callback(policy); + break; + case PermissionConstants.PERMISSION_GROUP_BLUETOOTH_SCAN: + let bluetoothScan: ArrayList = new ArrayList(); + bluetoothScan.add('ohos.permission.USE_BLUETOOTH'); + callback(bluetoothScan); + break; + case PermissionConstants.PERMISSION_GROUP_BLUETOOTH_ADVERTISE: + let bluetoothDiscover: ArrayList = new ArrayList(); + bluetoothDiscover.add('ohos.permission.DISCOVER_BLUETOOTH'); + callback(bluetoothDiscover); + break; + case PermissionConstants.PERMISSION_GROUP_BLUETOOTH_CONNECT: + let bluetoothConnect: ArrayList = new ArrayList(); + bluetoothConnect.add('ohos.permission.MANAGE_BLUETOOTH'); + bluetoothConnect.add('ohos.permission.ACCESS_BLUETOOTH'); + callback(bluetoothConnect); + break; + case PermissionConstants.PERMISSION_GROUP_NOTIFICATION: + let postNotification: ArrayList = new ArrayList(); + postNotification.add('ohos.permission.NOTIFICATION_CONTROLLER'); + callback(postNotification); + break; + case PermissionConstants.PERMISSION_GROUP_NEARBY_WIFI_DEVICES: + callback(permissionNames); + break; + case PermissionConstants.PERMISSION_GROUP_PHOTOS: + case PermissionConstants.PERMISSION_GROUP_VIDEOS: + let photosVideos: ArrayList = new ArrayList(); + photosVideos.add('ohos.permission.READ_IMAGEVIDEO'); + photosVideos.add('ohos.permission.WRITE_IMAGEVIDEO'); + PermissionUtils.getRequestPermission(photosVideos, callback); + break; + case PermissionConstants.PERMISSION_GROUP_AUDIO: + let media: ArrayList = new ArrayList(); + media.add('ohos.permission.READ_MEDIA'); + PermissionUtils.getRequestPermission(media, callback); + break; + case PermissionConstants.PERMISSION_GROUP_SCHEDULE_EXACT_ALARM: + let exactAlarm: ArrayList = new ArrayList(); + exactAlarm.add('ohos.permission.SCHEDULE_EXACT_ALARM'); + callback(permissionNames); + break; + case PermissionConstants.PERMISSION_GROUP_MEDIA_LIBRARY: + case PermissionConstants.PERMISSION_GROUP_REMINDERS: + case PermissionConstants.PERMISSION_GROUP_UNKNOWN: + callback(null); + break; + default: + callback(permissionNames); + break; + } + } + + static toPermissionStatus(authResult: number): number { + if (authResult == -1 || authResult == 2) { + return PermissionConstants.PERMISSION_STATUS_DENIED; + } + return PermissionConstants.PERMISSION_STATUS_GRANTED; + } + + static updatePermissionShouldShowStatus(permission: number): void { + } + + static strictestStatus(statuses: Set): number { + if (statuses.has(PermissionConstants.PERMISSION_STATUS_NEVER_ASK_AGAIN)) { + return PermissionConstants.PERMISSION_STATUS_NEVER_ASK_AGAIN; + } + if (statuses.has(PermissionConstants.PERMISSION_STATUS_RESTRICTED)) { + return PermissionConstants.PERMISSION_STATUS_RESTRICTED; + } + if (statuses.has(PermissionConstants.PERMISSION_STATUS_DENIED)) { + return PermissionConstants.PERMISSION_STATUS_DENIED; + } + if (statuses.has(PermissionConstants.PERMISSION_STATUS_LIMITED)) { + return PermissionConstants.PERMISSION_STATUS_LIMITED; + } + return PermissionConstants.PERMISSION_STATUS_GRANTED; + } + + static strictestStatusFromTwo(statusA?: PermissionConstants, statusB?: PermissionConstants): number { + const statuses = new Set(); + if (statusA !== undefined) { + statuses.add(statusA); + } + if (statusB !== undefined) { + statuses.add(statusB); + } + return PermissionUtils.strictestStatus(statuses); + } +} \ No newline at end of file diff --git a/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/ServiceManager.ets b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/ServiceManager.ets new file mode 100644 index 0000000000000000000000000000000000000000..9983699871cf5755195fdfcf878931483be2d20c --- /dev/null +++ b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/ServiceManager.ets @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import { ErrorCallback } from './ErrorCallback'; +import PermissionConstants from './PermissionConstants'; +import locationManager from '@ohos.geoLocationManager'; +import bluetoothManager from '@ohos.bluetoothManager'; +import sim from '@ohos.telephony.sim'; + +export class ServiceManager { + checkServiceStatus(permission: number, context: common.Context, + successCallback: SuccessCallback, errorCallback: ErrorCallback): void { + if (permission == PermissionConstants.PERMISSION_GROUP_LOCATION || + permission == PermissionConstants.PERMISSION_GROUP_LOCATION_ALWAYS || + permission == PermissionConstants.PERMISSION_GROUP_LOCATION_WHEN_IN_USE) { + successCallback.onSuccess(this.isLocationServiceEnable() + ? PermissionConstants.SERVICE_STATUS_ENABLED : PermissionConstants.SERVICE_STATUS_DISABLED); + return; + } + if (permission == PermissionConstants.PERMISSION_GROUP_BLUETOOTH) { + successCallback.onSuccess(this.isBluetoothServiceEnable() + ? PermissionConstants.SERVICE_STATUS_ENABLED : PermissionConstants.SERVICE_STATUS_DISABLED); + return; + } + if (permission == PermissionConstants.PERMISSION_GROUP_PHONE) { + try { + sim.getSimState(0).then((state) => { + if (state == sim.SimState.SIM_STATE_READY) { + successCallback.onSuccess(PermissionConstants.SERVICE_STATUS_ENABLED); + return; + } + sim.getSimState(1).then((stateSimTwo) => { + if (stateSimTwo == sim.SimState.SIM_STATE_READY) { + successCallback.onSuccess(PermissionConstants.SERVICE_STATUS_ENABLED); + return; + } + successCallback.onSuccess(PermissionConstants.SERVICE_STATUS_DISABLED); + }); + }); + } catch (error) { + successCallback.onSuccess(PermissionConstants.SERVICE_STATUS_DISABLED); + } + return; + } + if (permission == PermissionConstants.PERMISSION_GROUP_IGNORE_BATTERY_OPTIMIZATIONS) { + successCallback.onSuccess(PermissionConstants.SERVICE_STATUS_DISABLED); + return; + } + successCallback.onSuccess(PermissionConstants.SERVICE_STATUS_NOT_APPLICABLE); + } + + private isLocationServiceEnable(): boolean { + try { + return locationManager.isLocationEnabled(); + } catch (error) { + return false; + } + } + + private isBluetoothServiceEnable(): boolean { + try { + return bluetoothManager.getState() == bluetoothManager.BluetoothState.STATE_ON; + } catch (error) { + return false; + } + } +} + +export interface SuccessCallback { + onSuccess(serviceStatus: number): void; +} \ No newline at end of file diff --git a/permission_handler_ohos/ohos/src/main/module.json5 b/permission_handler_ohos/ohos/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fe2c21ee331547585cd9f5daf83ad9eb4f78ccf7 --- /dev/null +++ b/permission_handler_ohos/ohos/src/main/module.json5 @@ -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. +*/ + +{ + "module": { + "name": "permission_handler_ohos", + "type": "har", + "deviceTypes": [ + "phone", + "tablet" + ], + } +} \ No newline at end of file diff --git a/permission_handler_ohos/ohos/src/main/resources/base/element/color.json b/permission_handler_ohos/ohos/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/permission_handler_ohos/ohos/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/permission_handler_ohos/ohos/src/main/resources/base/element/string.json b/permission_handler_ohos/ohos/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..873ab82052a1996280005200b7dc1883c0c123f3 --- /dev/null +++ b/permission_handler_ohos/ohos/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "PermissionhandlerAbility_desc", + "value": "description" + }, + { + "name": "PermissionhandlerAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/permission_handler_ohos/ohos/src/main/resources/base/media/icon.png b/permission_handler_ohos/ohos/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/permission_handler_ohos/ohos/src/main/resources/base/media/icon.png differ diff --git a/permission_handler_ohos/ohos/src/main/resources/base/profile/main_pages.json b/permission_handler_ohos/ohos/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/permission_handler_ohos/ohos/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/permission_handler_ohos/ohos/src/main/resources/en_US/element/string.json b/permission_handler_ohos/ohos/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..873ab82052a1996280005200b7dc1883c0c123f3 --- /dev/null +++ b/permission_handler_ohos/ohos/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "PermissionhandlerAbility_desc", + "value": "description" + }, + { + "name": "PermissionhandlerAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/permission_handler_ohos/ohos/src/main/resources/zh_CN/element/string.json b/permission_handler_ohos/ohos/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..602d4f1d86041f786b089100db594b118df4aa8c --- /dev/null +++ b/permission_handler_ohos/ohos/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "PermissionhandlerAbility_desc", + "value": "description" + }, + { + "name": "PermissionhandlerAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/permission_handler_ohos/ohos/src/test/List.test.ets b/permission_handler_ohos/ohos/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0db841ed9cff9fdea904b802e68d01f1d9b2b36a --- /dev/null +++ b/permission_handler_ohos/ohos/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* +* 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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest() +} \ No newline at end of file diff --git a/permission_handler_ohos/ohos/src/test/LocalUnit.test.ets b/permission_handler_ohos/ohos/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f3517276bcfc5453175c8f9b532d32b71e7d0e76 --- /dev/null +++ b/permission_handler_ohos/ohos/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* +* 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', function () { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(function () { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(function () { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(function () { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(function () { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, function () { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/permission_handler_ohos/pubspec.yaml b/permission_handler_ohos/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..df485b4c7ba24138de18479388b165e952ea84d8 --- /dev/null +++ b/permission_handler_ohos/pubspec.yaml @@ -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. + +name: permission_handler_ohos +description: Permission plugin for Flutter. This plugin provides the Ohos API to request and check permissions. +homepage: https://gitee.com/openharmony-sig/flutter_permission_handler +version: 10.3.2 + +environment: + sdk: ">=2.15.0 <4.0.0" + flutter: ">=2.8.0" + +flutter: + plugin: + implements: permission_handler + platforms: + ohos: + package: com.baseflow.permissionhandler + pluginClass: PermissionHandlerPlugin + +dependencies: + flutter: + sdk: flutter + permission_handler_platform_interface: ^4.2.0 + +dev_dependencies: + flutter_lints: ^1.0.4 + plugin_platform_interface: ^2.0.0