How to make my application the owner of the device?

APIs Device APIs and the Android 5.0 review mention something about the device owner’s application . How to configure the application as the owner of the device?

Edit: Are there any other ways besides rooting, and NFC, if available, please share.

+36
android device-admin
Jan 17 '14 at 10:18
source share
3 answers

Actually there is a method other than NFC, and rooting to install the application as the device owner’s application. You can use the dpm command line tool from adb shell .

Using:

 usage: dpm [subcommand] [options] usage: dpm set-device-owner <COMPONENT> usage: dpm set-profile-owner <COMPONENT> <USER_ID> dpm set-device-owner: Sets the given component as active admin, and its package as device owner. dpm set-profile-owner: Sets the given component as active admin and profile owner for an existing user. 

UPDATE: The dpm utility dpm really simple. Its purpose is to create a new file called device_owner.xml under /data/system/device_owner.xml , which refers to Device / Profile owner applications.

The Android platform then reads this file to check which application is considered as the device owner or the application for the profile owner.

On the root device , you can actually create this file yourself , but since the dpm tool does this, you better use it (DRY principle):

For example , using the Runtime.exec() command:

 Runtime.getRuntime().exec("dpm set-device-owner com.foo.deviceowner/.DeviceAdminRcvr"); 

Also note that this tool only works if the user does not have an account (make sure that the account is not set in Settings> Accounts) before using it.

Source and additional information in the Android Shell Command Shell Tool: Device Policy Manager

+37
Jan 12 '15 at 19:28
source share

If you use root on your device, you can follow this method to become the owner of the device.

First create a device_owner.xml file with the following contents:

 <?xml version="1.0" encoding="utf-8" standalone="yes" ?> <device-owner package="your.owner.app.package.id" name="Your app name" /> 

Now follow these steps

  • adb push device_owner.xml /sdcard/

  • adb shell

  • su

  • cp /sdcard/device_owner.xml /data/system/

  • cd /data/system/

  • chown system:system device_owner.xml

  • reboot

Note. Before rebooting the device, make sure that you have installed the application that you are trying to make the owner of the device. If you do not, you will get boot animation for an infinite amount of time.

+7
Nov 10 '14 at 8:26
source share

I just tried it, and the dpm command requires root privileges on real devices (for example, Samsung T550), otherwise a SecurityException will fail. adb shell provides only root for Android emulators. So you have to start the device first.

-one
May 14 '16 at 15:58
source share



All Articles