diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/.gitignore b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/AppScope/app.json5 b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..44a103546ed7a948fc9275fc104c0e7a11c3fc1a --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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": "com.example.bluetoothswitch", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/AppScope/resources/base/element/string.json b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..526bd0898a87b9c0bad898c489b3dd5b6510bd52 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "BluetoothSwitch" + } + ] +} diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/AppScope/resources/base/media/app_icon.png differ diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/README.md b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/README.md new file mode 100644 index 0000000000000000000000000000000000000000..89ff8197d3f6ca39f2f09e7606295dc610edbba6 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/README.md @@ -0,0 +1,77 @@ +# 蓝牙设置开发指导 + +### 介绍 + +蓝牙设置主要提供了开启蓝牙、关闭蓝牙、获取蓝牙状态的方法,帮助开发者实现基本蓝牙功能。 + + +### 场景介绍 + +主要场景有: + +1. 开启、关闭蓝牙 + +### 接口说明 + +完整的 JS API 说明以及实例代码请参考:[access接口](https://gitcode.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/reference/apis-connectivity-kit/js-apis-bluetooth-access.md) + +具体接口说明如下表。 + +| 接口名 | 功能描述 | +| ----------------------------------- | --------------------------- | +| enableBluetooth() | 开启蓝牙。 | +| disableBluetooth() | 关闭蓝牙。 | +| getState() | 获取蓝牙开关状态。 | +| on(type: 'stateChange') | 订阅蓝牙设备开关状态事件。| +| off(type: 'stateChange') | 取消订阅蓝牙设备开关状态事件。 | + +### 主要场景开发步骤 + +#### 开启、关闭蓝牙 + +1. import需要的access模块。 +2. 需要SystemCapability.Communication.Bluetooth.Core系统能力。 +3. 开启蓝牙。 +4. 关闭蓝牙。 +5. 错误码请参见[蓝牙服务子系统错误码](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/reference/apis-connectivity-kit/errorcode-bluetoothManager.md). + + + +### 工程目录 +``` +entry/src/main/ets/ +|---entryability +| |---EntryAbility.ets +|---entrybackupability +| |---EntryBackupAbility.ets +|---pages +| |---Index.ets // 应用主页面 +``` + +### 相关权限 + +需要开启蓝牙权限。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.57。 + +3.本示例需要使用DevEco Studio NEXT Developer Preview2 (Build Version: 5.0.5.306, built on December 12, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/build-profile.json5 b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9564dd6e516e700526b07623afcbb15c7efd9e27 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/build-profile.json5 @@ -0,0 +1,43 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/code-linter.json5 b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..77b31b517a3e5c2f34c3ae1bf44083c0c06cbd6d --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/code-linter.json5 @@ -0,0 +1,20 @@ +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/.gitignore b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/build-profile.json5 b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4e956928b47b71f85916d920e894e1272a61d125 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/hvigorfile.ts b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/hvigorfile.ts @@ -0,0 +1,6 @@ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/obfuscation-rules.txt b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/oh-package.json5 b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..dbacc308e4f7758a11b72c6a2af812b2471a0e8a --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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": {} +} + diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..3c895983f321415c175d04d87596f7064d058722 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 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 { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + 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.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..29feaca7669174be5c2b0e2366529ee94ab7e726 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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 '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..9f88c321e535dcb0e2600d421382ac09f48f1486 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2025 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 { access } from '@kit.ConnectivityKit'; + +@Entry +@Component +struct SetBluetooth { + @State state: string = 'bluetooth switch'; + build() { + Column({space:12}){ + Text('state: ' + this.state).id('state') + Button('open bluetooth') + .onClick(() => { + // 开启蓝牙 + access.enableBluetooth(); + access.on('stateChange', (data) => { + let btStateMessage = ''; + switch (data) { + case 0: + btStateMessage += 'STATE_OFF'; + break; + case 1: + btStateMessage += 'STATE_TURNING_ON'; + break; + case 2: + btStateMessage += 'STATE_ON'; + break; + case 3: + btStateMessage += 'STATE_TURNING_OFF'; + break; + case 4: + btStateMessage += 'STATE_BLE_TURNING_ON'; + break; + case 5: + btStateMessage += 'STATE_BLE_ON'; + break; + case 6: + btStateMessage += 'STATE_BLE_TURNING_OFF'; + break; + default: + btStateMessage += 'unknown status'; + break; + } + if (btStateMessage == 'STATE_ON') { + access.off('stateChange'); + } + console.info('bluetooth statues: ' + btStateMessage); + }); + }) + + Button('close bluetooth') + .onClick(() => { + // 关闭蓝牙 + access.disableBluetooth(); + access.on('stateChange', (data) => { + let btStateMessage = ''; + switch (data) { + case 0: + btStateMessage += 'STATE_OFF'; + break; + case 1: + btStateMessage += 'STATE_TURNING_ON'; + break; + case 2: + btStateMessage += 'STATE_ON'; + break; + case 3: + btStateMessage += 'STATE_TURNING_OFF'; + break; + case 4: + btStateMessage += 'STATE_BLE_TURNING_ON'; + break; + case 5: + btStateMessage += 'STATE_BLE_ON'; + break; + case 6: + btStateMessage += 'STATE_BLE_TURNING_OFF'; + break; + default: + btStateMessage += 'unknown status'; + break; + } + if (btStateMessage == 'STATE_OFF') { + access.off('stateChange'); + } + }); + }) + }.width('100%') + } +} diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/module.json5 b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d7b54bacee01e85ba62003ad57bc51136edf0887 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/module.json5 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2025 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", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.ACCESS_BLUETOOTH", + "reason": "$string:ACCESS_BLUETOOTH", + "usedScene": { + "when": "always" + } + }], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/element/color.json b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/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/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/element/string.json b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8aa7303c14c55ef37e50e0e4bd26eb742e311631 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "BluetoothSwitch" + }, + { + "name": "ACCESS_BLUETOOTH", + "value": "user" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/media/background.png b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/mock/mock-config.json5 b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a99e1d70a555e9935e93519642bb8d05bcb5a149 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ + +{ +} \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..8630f0493ae875a1eb88b53bbaf9de8a2c7c359f --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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 '@kit.PerformanceAnalysisKit'; +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); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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(); +} \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/ohosTest/module.json5 b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..eb3fe2e51f3c1d44c87272b49bc5b1df36dd2472 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/test/List.test.ets b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // 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. + 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/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/hvigor/hvigor-config.json5 b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3511c6358c656ebda11ff67ebc9dc6454caeaa69 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/hvigorfile.ts b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/hvigorfile.ts @@ -0,0 +1,6 @@ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/oh-package.json5 b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b794cc97660170c8387dce079423043d77c04ae3 --- /dev/null +++ b/code/DocsSample/ConnectivityKit/Bluetooth/BluetoothSwitch/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "modelVersion": "5.0.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +}