How can my permissions at the application access level on untethered devices?

Android requires the superuser to delete, modify, or read anything in the root directory, except for a system that is only being read.

However, I noticed that even without an embedded device, some applications can take advantage of these processes. For example, Norton can wipe devices on non-root phones. Is there a way to give my application the same access?

+5
source share
1 answer

An application with administrator privileges can use the device administration API. This API offers the ability to erase a device.

Using this, he does not need superuser permissions, he only needs the administrator rights of the device .

To summarize the use of the device administration API :

  • You need a resource file that announces the policies your application needs.
<device-admin xmlns:android="http://schemas.android.com/apk/res/android"> <uses-policies> <wipe-data /> </uses-policies> </device-admin> 
  1. You need to implement DeviceAdminReceiver in order to respond to various administration events in which your application is interested (an empty implementation may be sufficient if you are only interested in a wipe device) (more about how to configure this receiver: here )

  2. You need permission BIND_DEVICE_ADMIN

  3. At some point (possibly at startup), your application should call ACTION_ADD_DEVICE_ADMIN to ask the user to provide “Device Control Rights” to your application. (once these rights are granted, there is no reason to ask them again. The user always has the opportunity to revoke these rights in the Settings application).

  4. When your installation is correct (and if the user provides device administrator privileges for your application), you can call DevicePolicyManager:

 DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); devicePolicyManager.wipeData(0); 

Please note that an application with device administrator rights cannot be disabled. The user must manually remove these rights (using the Settings application) before he can install it.

+10
source

Source: https://habr.com/ru/post/1202811/


All Articles