--- tags: Android BSP Development, MyJob --- # How to Set DeviceOwner For App with adb (Using testDPC Example) ## Where to download ### Locate MH5108_FixDeviceOwnerIssue directory ![](https://i.imgur.com/J4o31tF.png) * The adb command locate in adb folder. Copy **adb** to **/usr/local/bin** * The TestDPC apk loacte in TestDPC folder. ## How to use ### 1. Install TestDPC Apk `$ adb install TestDPC_6102.apk` ### 2. Set DeviceOwner permission for testDPC It will set the given component as active admin, and its package as device owner. `$ adb shell dpm set-device-owner com.afwsamples.testdpc/.DeviceAdminReceiver` > The **dpm** utility is to create a new file called **device_owner.xml** under **/data/system/device_owner.xml** that references the *Device/Profile owner* apps > ### 3. How to check if an Android app already is a Device Owner There are two method that can check if the app is DeviceOwner #### a. Using adb command to check device_owner.xml (*Need root permission*) ``` kevinlee@kevinlee-Protech-ubuntu:~$ adb shell cat /data/system/device_owner_2.xml <?xml version='1.0' encoding='utf-8' standalone='yes' ?> <root> <device-owner package="com.afwsamples.testdpc" name="" component="com.afwsamples.testdpc/com.afwsamples.testdpc.DeviceAdminReceiver" userRestrictionsMigrated="true" /> <device-owner-context userId="0" /> </root> ``` #### b. Via Android platform Settings -> Security -> Deviceadministrators ![](https://i.imgur.com/GRHilb8.png) ![](https://i.imgur.com/vobiFmR.png) A DeviceOwner app will not be uninstall and the button "*Deactivate this device administrator*" will be highlight. >Note. >If showing the below picture, it is not correct to set DeviceOwner for app. ![](https://i.imgur.com/ReA3HT9.png)