diff --git a/packages/connectivity_plus/connectivity_plus/OAT.xml b/packages/connectivity_plus/connectivity_plus/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..921de7086caf44239a6f03c7c981eb9b37468f88 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/OAT.xml @@ -0,0 +1,159 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/.gitignore b/packages/connectivity_plus/connectivity_plus/example/ohos/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6f7b4f89c49a6abadc383d9665d3b4c171d466bc --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/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/packages/connectivity_plus/connectivity_plus/example/ohos/AppScope/app.json5 b/packages/connectivity_plus/connectivity_plus/example/ohos/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7978bcb2bc7b85f1cc12452da0b258dcce650413 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "app": { + "bundleName": "io.flutter.plugins.example", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/AppScope/resources/base/element/string.json b/packages/connectivity_plus/connectivity_plus/example/ohos/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..810f4a362c1d177309eec4f2efe5cac2f4558c28 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "example" + } + ] +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/AppScope/resources/base/media/app_icon.png b/packages/connectivity_plus/connectivity_plus/example/ohos/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packages/connectivity_plus/connectivity_plus/example/ohos/AppScope/resources/base/media/app_icon.png differ diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/build-profile.json5 b/packages/connectivity_plus/connectivity_plus/example/ohos/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..17544ec09a2c79b44a6356736e53b8c84f4c8c6e --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/build-profile.json5 @@ -0,0 +1,42 @@ +/* + * 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.0(12)", + "runtimeOS": "HarmonyOS" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/dependencies/hvigor-3.2.1-s.tgz b/packages/connectivity_plus/connectivity_plus/example/ohos/dependencies/hvigor-3.2.1-s.tgz new file mode 100644 index 0000000000000000000000000000000000000000..192fd1cc134a755f681480b2d1d0fd0200e0b987 Binary files /dev/null and b/packages/connectivity_plus/connectivity_plus/example/ohos/dependencies/hvigor-3.2.1-s.tgz differ diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/dependencies/hvigor-ohos-arkui-x-plugin-2.3.0-s.tgz b/packages/connectivity_plus/connectivity_plus/example/ohos/dependencies/hvigor-ohos-arkui-x-plugin-2.3.0-s.tgz new file mode 100644 index 0000000000000000000000000000000000000000..f68ba481042f63665474b9cc85557cd4e67b765d Binary files /dev/null and b/packages/connectivity_plus/connectivity_plus/example/ohos/dependencies/hvigor-ohos-arkui-x-plugin-2.3.0-s.tgz differ diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/dependencies/hvigor-ohos-plugin-3.2.1-s.tgz b/packages/connectivity_plus/connectivity_plus/example/ohos/dependencies/hvigor-ohos-plugin-3.2.1-s.tgz new file mode 100644 index 0000000000000000000000000000000000000000..7c2f096f190c1d951ddec98e4b161ffa11664d75 Binary files /dev/null and b/packages/connectivity_plus/connectivity_plus/example/ohos/dependencies/hvigor-ohos-plugin-3.2.1-s.tgz differ diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/dta/icudtl.dat b/packages/connectivity_plus/connectivity_plus/example/ohos/dta/icudtl.dat new file mode 100644 index 0000000000000000000000000000000000000000..d1f10917ab52e3ebd251abd7f5377d7196b80d67 Binary files /dev/null and b/packages/connectivity_plus/connectivity_plus/example/ohos/dta/icudtl.dat differ diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/.gitignore b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..2795a1c5b1fe53659dd1b71d90ba0592eaf7e043 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/.gitignore @@ -0,0 +1,7 @@ + +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/build-profile.json5 b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6040f38ef69528b0c9dd95b5e9f6c6f6f9b5d368 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/build-profile.json5 @@ -0,0 +1,29 @@ +/* + * 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. + */ + +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "HarmonyOS" + }, + { + "name": "ohosTest", + } + ] +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/hvigorfile.ts b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..10851b6ad1be3b3d774202742dab0f576adb8945 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/hvigorfile.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/libs/arm64-v8a/libc++_shared.so b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/libs/arm64-v8a/libc++_shared.so new file mode 100644 index 0000000000000000000000000000000000000000..831c9353702073d45889352a4dafb93103d67d20 Binary files /dev/null and b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/libs/arm64-v8a/libc++_shared.so differ diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/oh-package.json5 b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1c3655f76f43216bceaeda5876f43c16c1bb51f2 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/oh-package.json5 @@ -0,0 +1,27 @@ +/* + * 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "integration_test": "file:../har/integration_test.har", + "connectivity_plus": "file:../har/connectivity_plus.har" + } +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..02ceff9857af87b6c78cb2b238ba413ae21bf967 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,25 @@ +/* + * 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 { FlutterAbility } from '@ohos/flutter_ohos' +import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant'; +import FlutterEngine from '@ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterEngine'; + +export default class EntryAbility extends FlutterAbility { + configureFlutterEngine(flutterEngine: FlutterEngine) { + super.configureFlutterEngine(flutterEngine) + GeneratedPluginRegistrant.registerWith(flutterEngine) + } +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/ets/pages/Index.ets b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..66761f21c9e3bc5001970f7c9705c2beb4669910 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,39 @@ +/* + * 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 { 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 + } +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets new file mode 100644 index 0000000000000000000000000000000000000000..b2cbd2fc1a22865f172583439799766c9dbf69bd --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets @@ -0,0 +1,43 @@ +/* + * 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 { FlutterEngine, Log } from '@ohos/flutter_ohos'; +import ConnectivityPlugin from 'connectivity_plus'; +import IntegrationTestPlugin from 'integration_test'; + +/** + * Generated file. Do not edit. + * This file is generated by the Flutter tool based on the + * plugins that support the Ohos platform. + */ + +const TAG = "GeneratedPluginRegistrant"; + +export class GeneratedPluginRegistrant { + + static registerWith(flutterEngine: FlutterEngine) { + try { + flutterEngine.getPlugins()?.add(new ConnectivityPlugin()); + flutterEngine.getPlugins()?.add(new IntegrationTestPlugin()); + } catch (e) { + Log.e( + TAG, + "Tried to register plugins with FlutterEngine (" + + flutterEngine + + ") failed."); + Log.e(TAG, "Received exception while registering", e); + } + } +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/module.json5 b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..59bd60539a5455f0a008d966fcef96d5d5197308 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/module.json5 @@ -0,0 +1,53 @@ +/* + * 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. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + {"name" : "ohos.permission.INTERNET"}, + ] + } +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/base/element/color.json b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/base/element/string.json b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/base/media/icon.png b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/base/media/icon.png differ diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/base/profile/main_pages.json b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/en_US/element/string.json b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/zh_CN/element/string.json b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..597ecf95e61d7e30367c22fe2f8638008361b044 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/ets/test/Ability.test.ets b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6d28a17dc5b32efd9788a1376bcab0f3d35a4cac --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * 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 hilog from '@ohos.hilog'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // 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(() => { + // 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(() => { + // 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(() => { + // 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, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + 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); + }); + }) +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/ets/test/List.test.ets b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..89fda7fabb26fa81a6a78352029686019175b6f8 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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 abilityTest from './Ability.test' + +export default function testsuite() { + abilityTest() +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..86ee102c17577bbab5ab8f38b5703f5b8e996c69 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -0,0 +1,65 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import hilog from '@ohos.hilog'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; +import window from '@ohos.window'; +import Want from '@ohos.app.ability.Want'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; + +export default class TestAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); + let abilityDelegator: object + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + let abilityDelegatorArguments: object + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..f6dc7258db0a523fa0513227f058bcd77f8278d2 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -0,0 +1,49 @@ +/* + * 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 hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..a0e22ac7c5a0aac444cb2d15776087b40f5aa59d --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,64 @@ +/* + * 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 hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/module.json5 b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2af56a01c55fe8013cb6fe4c84aa3db731d7fe8d --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/module.json5 @@ -0,0 +1,51 @@ +/* + * 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/resources/base/element/color.json b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/resources/base/element/string.json b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/resources/base/media/icon.png b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..b7e7343cacb32ce982a45e76daad86e435e054fe --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "testability/pages/Index" + ] +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/hvigor/hvigor-config.json5 b/packages/connectivity_plus/connectivity_plus/example/ohos/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..81a7de6b734379d96e7a72ac23079b32d977ef01 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/hvigor/hvigor-config.json5 @@ -0,0 +1,23 @@ +/* + * 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. + */ + +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "properties": { + "ohos.nativeResolver": false + } +} diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/hvigorfile.ts b/packages/connectivity_plus/connectivity_plus/example/ohos/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ad508b65548d8e71746fac70baf7405a14f31631 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/hvigorfile.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + +// 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'; diff --git a/packages/connectivity_plus/connectivity_plus/example/ohos/oh-package.json5 b/packages/connectivity_plus/connectivity_plus/example/ohos/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1b28adce6a7958d2e6d4a958385d5059ed5939b6 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/example/ohos/oh-package.json5 @@ -0,0 +1,36 @@ +/* + * 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. + */ + +{ + "modelVersion": "5.0.0", + "name": "apptemplate", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "@ohos/flutter_ohos": "file:./har/flutter.har" + }, + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "overrides": { + "@ohos/flutter_ohos": "file:./har/flutter.har", + "integration_test": "file:./har/integration_test.har", + "connectivity_plus": "file:./har/connectivity_plus.har", + "@ohos/flutter_module": "file:./entry" + } +} diff --git a/packages/connectivity_plus/connectivity_plus/example/pubspec.yaml b/packages/connectivity_plus/connectivity_plus/example/pubspec.yaml index 6ae05c65d14ea049abdc080603d39140e29690fa..63ba9e449bddeb3f1b28d64aa310276d546b5c5d 100644 --- a/packages/connectivity_plus/connectivity_plus/example/pubspec.yaml +++ b/packages/connectivity_plus/connectivity_plus/example/pubspec.yaml @@ -7,7 +7,8 @@ environment: dependencies: flutter: sdk: flutter - connectivity_plus: ^6.1.0 + connectivity_plus: + path: ../ dev_dependencies: flutter_driver: @@ -17,7 +18,7 @@ dev_dependencies: integration_test: sdk: flutter test: ^1.16.4 - flutter_lints: ^5.0.0 + flutter_lints: ^4.0.0 flutter: uses-material-design: true diff --git a/packages/connectivity_plus/connectivity_plus/ohos/.gitignore b/packages/connectivity_plus/connectivity_plus/ohos/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6f7b4f89c49a6abadc383d9665d3b4c171d466bc --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/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/packages/connectivity_plus/connectivity_plus/ohos/build-profile.json5 b/packages/connectivity_plus/connectivity_plus/ohos/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d1e2d2ba471ac6c13ecc059ce99f328237ee5e01 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/ohos/build-profile.json5 @@ -0,0 +1,27 @@ +/* + * 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. + */ +{ + "apiType": "stageMode", + "buildOption": { + }, + "targets": [ + { + "name": "default" + }, + { + "name": "connectivity_plus", + } + ] +} diff --git a/packages/connectivity_plus/connectivity_plus/ohos/hvigorfile.ts b/packages/connectivity_plus/connectivity_plus/ohos/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e81ac5f3195e7bd6a48fbd3bc15d9edd77627fd9 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/ohos/hvigorfile.ts @@ -0,0 +1,15 @@ +/* + * 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 { harTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/packages/connectivity_plus/connectivity_plus/ohos/index.ets b/packages/connectivity_plus/connectivity_plus/ohos/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..c38cdbc9485e4663ea67d3dc3320f24f77b86d46 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/ohos/index.ets @@ -0,0 +1,16 @@ +/* + * 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 ConnectivityPlugin from './src/main/ets/dev/fluttercommunity/plus/connectivity/ConnectivityPlugin'; +export default ConnectivityPlugin; diff --git a/packages/connectivity_plus/connectivity_plus/ohos/oh-package.json5 b/packages/connectivity_plus/connectivity_plus/ohos/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e95ddb42c644cd1f294b3aab17872f9fb72d33bb --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/ohos/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ +{ + "name": "connectivity_plus", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": { + "@ohos/flutter_ohos": "file:./libs/flutter_embedding.har" + } +} diff --git a/packages/connectivity_plus/connectivity_plus/ohos/src/main/ets/dev/fluttercommunity/plus/connectivity/Connectivity.ets b/packages/connectivity_plus/connectivity_plus/ohos/src/main/ets/dev/fluttercommunity/plus/connectivity/Connectivity.ets new file mode 100644 index 0000000000000000000000000000000000000000..e440c4d8001c3576b6cc7a8abe0d53ae2954e21d --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/ohos/src/main/ets/dev/fluttercommunity/plus/connectivity/Connectivity.ets @@ -0,0 +1,71 @@ +/* + * 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 connection from '@ohos.net.connection' +import { ArrayList } from '@kit.ArkTS'; + +const TAG = "Connectivity"; + +export class Connectivity { + public static CONNECTIVITY_NONE = "none"; + private static CONNECTIVITY_WIFI = "wifi"; + private static CONNECTIVITY_MOBILE = "mobile"; + private static CONNECTIVITY_ETHERNET = "ethernet"; + private static CONNECTIVITY_BLUETOOTH = "bluetooth"; + private static CONNECTIVITY_VPN = "vpn"; + public static netConnection = connection.createNetConnection(); + + constructor() { + + } + + async getNetworkType(): Promise> { + //通过异步方式获取网络信息 + const netHandle = await connection.getDefaultNet(); + if (netHandle.netId == 0) { + const types: ArrayList = new ArrayList(); + types.add(Connectivity.CONNECTIVITY_NONE); + return types; + } + const capabilities = await connection.getNetCapabilities(netHandle); + return this.hasTransport(capabilities.bearerTypes); + } + + hasTransport(capabilities: Array): ArrayList { + const types: ArrayList = new ArrayList(); + //若数组为空返回CONNECTIVITY_NONE + if (capabilities.length == 0) { + types.add(Connectivity.CONNECTIVITY_NONE); + return types; + } + if (capabilities.includes(connection.NetBearType.BEARER_WIFI)) { + types.add(Connectivity.CONNECTIVITY_WIFI); + return types; + } + if (capabilities.includes(connection.NetBearType.BEARER_ETHERNET)) { + types.add(Connectivity.CONNECTIVITY_ETHERNET); + return types; + } + if (capabilities.includes(connection.NetBearType.BEARER_CELLULAR)) { + types.add(Connectivity.CONNECTIVITY_MOBILE); + return types; + } + types.add(Connectivity.CONNECTIVITY_NONE); + return types; + } +} + + + diff --git a/packages/connectivity_plus/connectivity_plus/ohos/src/main/ets/dev/fluttercommunity/plus/connectivity/ConnectivityBroadcastReceiver.ets b/packages/connectivity_plus/connectivity_plus/ohos/src/main/ets/dev/fluttercommunity/plus/connectivity/ConnectivityBroadcastReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..801b6e5c4d70dc04061950fd899bdc5fab4d1074 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/ohos/src/main/ets/dev/fluttercommunity/plus/connectivity/ConnectivityBroadcastReceiver.ets @@ -0,0 +1,87 @@ +/* + * 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 { StreamHandler, EventSink } from '@ohos/flutter_ohos/src/main/ets/plugin/common/EventChannel'; +import { Connectivity } from './Connectivity'; +import { ArrayList } from '@kit.ArkTS'; + +//创建tag +const TAG = "ConnectivityBroadcastReceiver"; + +//创建类 +export class ConnectivityBroadcastReceiver implements StreamHandler { + private connectivity: Connectivity; + private context: Context; + private events: EventSink | null = null; + + constructor(context: Context, connectivity: Connectivity) { + this.context = context; + this.connectivity = connectivity; + } + + onListen(args: Object, events: EventSink): void { + this.events = events; + + Connectivity.netConnection.register(async (error) => { + this.sendEvent(await this.connectivity.getNetworkType()) + }) + + //订阅网络可用事件。 + Connectivity.netConnection.on('netAvailable', async (data) => { + this.sendEvent(await this.connectivity.getNetworkType()) + }) + + //订阅网络能力变化事件。 + Connectivity.netConnection.on('netCapabilitiesChange', async (data) => { + this.sendEvent(await this.connectivity.getNetworkType()) + }) + + //订阅网络连接信息变化事件 + Connectivity.netConnection.on('netConnectionPropertiesChange', async (data) => { + this.sendEvent(await this.connectivity.getNetworkType()) + }) + + //订阅网络订阅网络丢失事件。 + Connectivity.netConnection.on('netLost', (data) => { + const types: ArrayList = new ArrayList(); + types.add(Connectivity.CONNECTIVITY_NONE); + this.sendEvent(types) + }) + + //订阅网络不可用事件。 + Connectivity.netConnection.on('netUnavailable', (data) => { + const types: ArrayList = new ArrayList(); + types.add(Connectivity.CONNECTIVITY_NONE); + this.sendEvent(types) + }) + + } + + onCancel(args?: Object): void { + Connectivity.netConnection.unregister((error) => { + }) + } + + private sendEvent(networkType: ArrayList): Promise { + if (this.events != null && networkType != null) { + this.events.success(networkType); + } + return new Promise((reject) => { + reject(); + }) + } +} + + diff --git a/packages/connectivity_plus/connectivity_plus/ohos/src/main/ets/dev/fluttercommunity/plus/connectivity/ConnectivityMethodChannelHandler.ets b/packages/connectivity_plus/connectivity_plus/ohos/src/main/ets/dev/fluttercommunity/plus/connectivity/ConnectivityMethodChannelHandler.ets new file mode 100644 index 0000000000000000000000000000000000000000..268878c7e4e58293942d76e091e329891e486618 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/ohos/src/main/ets/dev/fluttercommunity/plus/connectivity/ConnectivityMethodChannelHandler.ets @@ -0,0 +1,49 @@ +/* + * 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 MethodCall from '@ohos/flutter_ohos/src/main/ets/plugin/common/MethodCall'; +import { MethodCallHandler, MethodResult } from '@ohos/flutter_ohos/src/main/ets/plugin/common/MethodChannel'; +import { Connectivity } from './Connectivity'; +import Log from '@ohos/flutter_ohos/src/main/ets/util/Log'; +import { ArrayList } from '@kit.ArkTS'; + + +const TAG: string = "ConnectivityMethodChannelHandler"; + +export default class ConnectivityMethodChannelHandler implements MethodCallHandler { + private connectivity: Connectivity; + + constructor(connectivity: Connectivity) { + this.connectivity = connectivity; + } + + + onMethodCall(call: MethodCall, result: MethodResult): void { + Log.d(TAG, 'onMethodCall step in') + switch (call.method) { + case "check": + this.handleCheckResult(result); + break; + default: + result.notImplemented(); + break; + } + } + + async handleCheckResult(result: MethodResult): Promise { + const networkType: ArrayList = await this.connectivity.getNetworkType() + result.success(networkType) + } +} + diff --git a/packages/connectivity_plus/connectivity_plus/ohos/src/main/ets/dev/fluttercommunity/plus/connectivity/ConnectivityPlugin.ets b/packages/connectivity_plus/connectivity_plus/ohos/src/main/ets/dev/fluttercommunity/plus/connectivity/ConnectivityPlugin.ets new file mode 100644 index 0000000000000000000000000000000000000000..b74e3c95d166e5c7a5e67d173151acbd4bb53733 --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/ohos/src/main/ets/dev/fluttercommunity/plus/connectivity/ConnectivityPlugin.ets @@ -0,0 +1,63 @@ +/* + * 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 { + FlutterPlugin, + FlutterPluginBinding +} from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin'; +import MethodChannel from '@ohos/flutter_ohos/src/main/ets/plugin/common/MethodChannel'; +import EventChannel from '@ohos/flutter_ohos/src/main/ets/plugin/common/EventChannel'; +import { ConnectivityBroadcastReceiver } from './ConnectivityBroadcastReceiver'; +import { Connectivity } from './Connectivity'; +import ConnectivityMethodChannelHandler from './ConnectivityMethodChannelHandler'; +import Log from '@ohos/flutter_ohos/src/main/ets/util/Log'; +import StandardMethodCodec from '@ohos/flutter_ohos/src/main/ets/plugin/common/StandardMethodCodec'; + +const TAG: string = "ConnectivityPlugin"; + +export default class ConnectivityPlugin implements FlutterPlugin { + private methodChannel: MethodChannel | null = null; + private eventChannel: EventChannel | null = null; + private receiver: ConnectivityBroadcastReceiver | null = null; + private pluginBing: FlutterPluginBinding | null = null; + + getUniqueClassName(): string { + return "ConnectivityPlugin"; + } + + onAttachedToEngine(binding: FlutterPluginBinding): void { + Log.d(TAG, 'onAttachedToEngine connectivity plugin') + + this.methodChannel = new MethodChannel(binding.getBinaryMessenger(), "dev.fluttercommunity.plus/connectivity", StandardMethodCodec.INSTANCE); + this.eventChannel = new EventChannel(binding.getBinaryMessenger(), "dev.fluttercommunity.plus/connectivity_status", StandardMethodCodec.INSTANCE); + + let connectivity = new Connectivity(); + let methodChannelHandler = new ConnectivityMethodChannelHandler(connectivity); + this.receiver = new ConnectivityBroadcastReceiver(binding.getApplicationContext(), connectivity); + this.methodChannel.setMethodCallHandler(methodChannelHandler); + this.eventChannel.setStreamHandler(this.receiver); + this.pluginBing = binding; + } + + onDetachedFromEngine(binding: FlutterPluginBinding): void { + Log.d(TAG, 'onDetachedFromEngine connectivity plugin') + this.methodChannel?.setMethodCallHandler(null); + this.eventChannel?.setStreamHandler(null); + this.receiver?.onCancel(); + this.methodChannel = null; + this.eventChannel = null; + this.receiver = null; + this.pluginBing = null; + } +} diff --git a/packages/connectivity_plus/connectivity_plus/ohos/src/main/module.json5 b/packages/connectivity_plus/connectivity_plus/ohos/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..50a219aafc1f588001cfee0581a458d402341d1b --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/ohos/src/main/module.json5 @@ -0,0 +1,32 @@ +/* + * 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. + */ + +{ + "module": { + "name": "connectivity_plus", + "type": "har", + "deviceTypes": [ + "default", + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + }, + { + "name": "ohos.permission.GET_NETWORK_INFO" + } + ] + } +} diff --git a/packages/connectivity_plus/connectivity_plus/ohos/src/main/resources/base/element/string.json b/packages/connectivity_plus/connectivity_plus/ohos/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1e76de0c66777cfe83568615c5c2e68c61d23fed --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/ohos/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "page_show", + "value": "page from npm package" + } + ] +} diff --git a/packages/connectivity_plus/connectivity_plus/ohos/src/main/resources/en_US/element/string.json b/packages/connectivity_plus/connectivity_plus/ohos/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1e76de0c66777cfe83568615c5c2e68c61d23fed --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/ohos/src/main/resources/en_US/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "page_show", + "value": "page from npm package" + } + ] +} diff --git a/packages/connectivity_plus/connectivity_plus/ohos/src/main/resources/zh_CN/element/string.json b/packages/connectivity_plus/connectivity_plus/ohos/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1e76de0c66777cfe83568615c5c2e68c61d23fed --- /dev/null +++ b/packages/connectivity_plus/connectivity_plus/ohos/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "page_show", + "value": "page from npm package" + } + ] +} diff --git a/packages/connectivity_plus/connectivity_plus/pubspec.yaml b/packages/connectivity_plus/connectivity_plus/pubspec.yaml index 519298097478bd7d290402d2666c73e2f9d01d8e..68692d94f42e0e96db3e6ec849022c492534afc6 100644 --- a/packages/connectivity_plus/connectivity_plus/pubspec.yaml +++ b/packages/connectivity_plus/connectivity_plus/pubspec.yaml @@ -34,6 +34,9 @@ flutter: fileName: src/connectivity_plus_web.dart windows: pluginClass: ConnectivityPlusWindowsPlugin + ohos: + package: dev.fluttercommunity.plus.connectivity + pluginClass: ConnectivityPlugin dependencies: flutter: