Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can my app access admin level privileges on non-rooted device?

Tags:

java

android

root

Android requires super user for deleting, modifying or reading anything in the root directory except system which is read only.

However, I have noticed that even without a rooted device, some applications are able to take advantage of these processes. For example, Norton is able to do device wipes on non-rooted phones. Is there a way to grant my application similar access?

like image 644
PS3Modder Avatar asked Sep 17 '14 20:09

PS3Modder


People also ask

How do I bypass administrator on Android?

Go to your phone's settings and then click on “Security.” You'll see “Device Administration” as a security category. Click on it to see a list of apps that have been given administrator privileges. Click the app you want to remove and confirm that you want to deactivate administrator privileges.

What is activate device administrator app?

The device admin app enforces the desired policies. Here's how it works: A system administrator writes a device admin app that enforces remote/local device security policies. These policies could be hard-coded into the app, or the app could dynamically fetch policies from a third-party server.


1 Answers

An application with Administrator Rights can use the Device Administration API. This API offers the ability to wipe the device.

Using this, it doesn't need any super-user permissions, it only needs device administrator rights.

To summarize how to use the Device Administration API:

  1. You need a resource file declaring policies needed by your app
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-policies>
    <wipe-data />
  </uses-policies>
</device-admin>
  1. You need to implement a DeviceAdminReceiver to react to various administration event your app is interested in. (an empty implementation can be enough if you are only interested in wipe-device) (more details on how to setup this receiver: here)

  2. You need the BIND_DEVICE_ADMIN permission

  3. At some point (probably at start up) your app must trigger ACTION_ADD_DEVICE_ADMIN to ask to the user to grant "Device Administration Rights" to your app. (once those rights are granted, there is no reason to ask them again. The user always have the ability to un-grant those rights from the Settings app)

  4. When your setup is correct (and if the user grant Device Admin rights to your app), you can invoke the DevicePolicyManager:

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

Note that an app with device administrator rights cannot be un-installed. The user needs to manually remove those rights (with the Settings app) before being able to un-install it.

like image 58
ben75 Avatar answered Oct 10 '22 17:10

ben75