| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 06-Mar-2025 | - | 36 | 33 | ||
| entry/ | 06-Mar-2025 | - | 3,260 | 3,052 | ||
| hvigor/ | 06-Mar-2025 | - | 23 | 22 | ||
| screenshots/device/ | 06-Mar-2025 | - | ||||
| .gitignore | D | 06-Mar-2025 | 119 | 11 | 11 | |
| DMSample测试用例报告.md | D | 06-Mar-2025 | 2.9 KiB | 14 | 12 | |
| README.md | D | 06-Mar-2025 | 852 | 22 | 10 | |
| README_zh.md | D | 06-Mar-2025 | 4.7 KiB | 84 | 59 | |
| build-profile.json5 | D | 06-Mar-2025 | 1.1 KiB | 43 | 42 | |
| hvigorfile.ts | D | 06-Mar-2025 | 159 | 2 | 1 | |
| hvigorw | D | 06-Mar-2025 | 2 KiB | 62 | 28 | |
| hvigorw.bat | D | 06-Mar-2025 | 2 KiB | 73 | 56 | |
| oh-package.json5 | D | 06-Mar-2025 | 824 | 27 | 25 | |
| ohosTest.md | D | 06-Mar-2025 | 1.1 KiB | 10 | 9 |
README.md
1# DeviceManager 2 3 4 5### Introduction 6 7This sample shows the use of the **DeviceManager** API in eTS, including obtaining the trusted device list, scanning for devices, authenticating devices, and subscribing to device status changes. 8 9### Usage 10 111. The sample app automatically obtains the trusted devices and displays them in the **online** state on the device list. It also scans for devices and displays the discovered devices in the **discover** state on the device list. 12 132. Touch a device in the **discover** state to trigger authentication. After the authentication is complete, the page is automatically refreshed. 14 153. Subscribe to device status changes. When the device status changes, the page is automatically refreshed. 16 17### Constraints 18 191. This sample requires a networking test. 20 212. This sample can only be run on standard-system devices. 22
README_zh.md
1# 设备管理 2 3### 介绍 4 5本示例主要展示了设备管理相关的功能,使用[@ohos.distributedHardware.deviceManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-distributedservice-kit/js-apis-device-manager-sys.md) 6等接口,实现了包括获取本机设备信息,获取授信设备列表,根据过滤条件扫描设备,设备认证,设备状态订阅,导入凭据,控制设备是否允许被发现等功能。 7 8### 效果预览 9 10|主页|选择过滤条件|发现与可信设备列表|取消认证| 11|--------------------------------|--------------------------------|--------------------------------|--------------------------------| 12||| 13 14使用说明 151. 进入应用会自动获取本机设备信息,并且注册设备状态监听,在有设备上下线的时候,刷新可信设备列表 162. 在主界面,可以点击允许被发现开关控制本机是否允许被发现; 173. 在主界面,可以点击刷新,刷新可信设备列表,点击已认证,解除认证关系; 184. 在主界面,可以点击过滤条件,选择对应的过滤条件,在发现设备时进行过滤; 195. 在主界面,可以点击发现,发现周边的设备,并点击发现的设备,进行PIN码认证; 20 21### 工程目录 22 23``` 24entry/src/main/ets/ 25|---common 26| |---Constant.ets // 弹窗工具 27| |---Logger.ets // 日志工具 28|---entryability 29|---model 30| |---RemoteDeviceModel.ets // 主要封装了DeviceManager库相关的接口,实现相关的功能 31|---pages 32| |---index.ets // 首页 33| |---FilterOption.ets // 过滤条件页面 34| |---ListDeviceView.ets // 列表设备组件 35``` 36 37### 具体实现 38 39获取本机设备信息,获取授信设备列表,根据过滤条件扫描设备,设备认证,设备状态订阅,控制设备是否允许被发现等功能,接口封装在RemoteDeviceModel,源码参考:[RemoteDeviceModel.ts](entry/src/main/ets/model/RemoteDeviceModel.ets) 40 41 * 使用RemoteDeviceModel.createDeviceManager()来获取DeviceManager对象; 42 * 获取本机设备信息:调用RemoteDeviceModel.getLocalDeviceInfo()来获取本机设备信息; 43 * 注册设备状态监听:调用RemoteDeviceModel.registerDeviceStateListener(),来注册设备状态监听; 44 * 获取可信设备列表:调用RemoteDeviceModel.getTrustedDeviceList()来获取可信设备列表; 45 * 发布设备:调用RemoteDeviceModel.setIsSupportRange()设置是否上报距离,然后调用deviceManager.publishDeviceDiscovery()发布设备; 46 * 停止发布设备:调用RemoteDeviceModel.unAuthenticateDevice()停止发布; 47 * 发现和停止发现设备:调用RemoteDeviceModel.startDeviceDiscovery()发现设备,调用RemoteDeviceModel.stopDeviceDiscovery()停止发现设备; 48 * 认证和取消认证设备:调用RemoteDeviceModel.authenticateDevice()认证,调用RemoteDeviceModel.unAuthenticateDevice()取消认证设备; 49 50### 相关概念 51 52设备管理:用于获取可信设备和本地设备的相关信息。在调用DeviceManager的方法前,需要先通过createDeviceManager构建一个DeviceManager实例。 53 54### 相关权限 55 56允许系统应用获取分布式设备的认证组网能力:ohos.permission.ACCESS_SERVICE_DM。 57 58### 约束与限制 59 601.本示例需要组网测试。 61 622.本示例仅支持标准系统上运行,支持设备:RK3568。 63 643.本示例为Stage模型,支持API10版本SDK,SDK版本号(API Version 10 Release),镜像版本号(4.0 Release)。 65 664.本示例需要使用DevEco Studio 版本号(4.0 Release)及以上版本才可编译运行。 67 685.本示例需要使用@ohos.distributedHardware.deviceManager系统权限的系统接口。使用Full SDK时需要手动从镜像站点获取,并在DevEco Studio中替换,具体操作可参考[替换指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/faqs/full-sdk-switch-guide.md) 69。 70 716.本示例涉及系统接口,需要配置系统应用签名,可以参考[特殊权限配置方法](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/hapsigntool-overview.md),把配置文件中的“app-feature”字段信息改为“hos_system_app”。 72 73### 下载 74 75如需单独下载本工程,执行如下命令: 76 77``` 78git init 79git config core.sparsecheckout true 80echo code/SystemFeature/DistributedAppDev/DistributedAuthentication > .git/info/sparse-checkout 81git remote add origin https://gitee.com/openharmony/applications_app_samples.git 82git pull origin master 83``` 84