I would like to make a profile in Tasker to enable device administrator privilegies to "Android Device Manager" when a text message is received. This way I could keep Device Manager disabled, while I can re-enable it remotely (by a text message for example) in case I lost my phone.

Is there any way to do that using Tasker?


Not sure why would you want to do that but you're gonna need root access for sure if you want to enable Android Device Manager as Device administrator in background.

I tried combinations of intent broadcasts to avoid device reboot but with no success, so note that my method requires a reboot.

All the enabled Device administrators are noted in the file /data/system/device_policies.xml. Simply add or remove an app's entries from it, reboot the device and that app would get enabled/disabled as Device administrator.

Any app which shows up under Settings → Security → Device administrator has a receiver meant specifically to meet the requirements of using the Device Administration API and requires the permission BIND_DEVICE_ADMIN. You can check the receiver's name in the Manifest of the app. It is this receiver which is mentioned in the device_policies.xml file.

The simplest way to get the app's device admin receiver's name and the flag is to enable the app as Device administrator, look for the app's entries under device_policies.xml file and then revoke the Device administrator privilege .

For Android Device Manager (ADM; managed by Google Play Services), the entries are:

<admin name="com.google.android.gms/com.google.android.gms.mdm.receivers.MdmDeviceAdminReceiver">
<policies flags="28" />

Now, let's make a task to add those entries in the said XML file whenever needed.

Note: First, Busybox is required for the task, but you can do away its need and use Tasker's inbuilt functionality for sorting if you look closely at the action I proposed to enable ADM. Second, my solution is tested on Android 5.0.2 and 5.1.1 but it should work on other Android releases as well with little tinkering.

  1. Create a task named "Enable ADM".
  2. Create the following actions in that task:

    1. Code → Run Shell,

      • Command:

        if [ "$(grep -o '</policies>' /data/system/device_policies.xml)" != "</policies>" ]; then sed -i 's/<policies setup-complete="true" \/>/<policies setup-complete="true" \/>\n<admin name="com.google.android.gms\/com.google.android.gms.mdm.receivers.MdmDeviceAdminReceiver">\n<policies flags="28" \/>\n<\/admin>\n<\/policies>/g' /data/system/device_policies.xml; fi; if [ "$(grep -o 'com.google.android.gms/' /data/system/device_policies.xml)" != "com.google.android.gms/" ]; then sed -i 's/<\/policies>/<admin name="com.google.android.gms\/com.google.android.gms.mdm.receivers.MdmDeviceAdminReceiver">\n<policies flags="28" \/>\n<\/admin>\n<\/policies>/g' /data/system/device_policies.xml; fi

        The command may look a bit incomprehensible at first, but it's plain and simple in reality . The whole command consists of two simple conditions and actions. The first if condition is checking whether </policies> string is available in the file or not. If any app is enabled as Device administrator then the app's receiver and flag would show up between <policies setup-complete="true"> and </profiles>. If none of the apps is enabled then </policies> would not show up so we can easily append ADM's entries into the file.

        The second if condition is checking whether ADM is already enabled or not. If not, then add the entries to enable it.

      • Check Use Root

    2. Code → Run Shell,

      • Command: setprop ctl.restart zygote

        This would soft-reboot the device.

      • Check Use Root

    3. Instead of soft-reboot, you can opt for normal reboot from System → Reboot → Type: Normal
  3. Create an event profile from Event → Phone → Received Text and set,

    • Type: SMS
    • Sender: Choose a number or leave it blank
    • Content: Specify what should be in the text to trigger the task such as "Yo boy!". Alternatively, you can avoid this stage and leave everything pretty much global but use an action or more in a task for more complexity as well as flexibility.
  4. Assign the task to the profile.

That's it. You can test your profile now. It should work flawlessly. If it doesn't, then I'm not at fault! Keep troubleshooting since you know the concept now.

| improve this answer | |

I have yet to see a plugin or 3rd app that will allow you to do this.

It is still possible to have tasker enable device administrator privileges to "Android Device Manager." The issue becomes in the absence of a plugin you'd most likely have to enable Android Device Manager through a series of simulated tap and swipes. Since a security measure this method isn't at all practical as the person could potentially see what going on.

I would honestly suggest investing in Cerberus. It can hide itself and respond to test messages and commands which can be sent from the web. You can find many stories on reddit about how this app has allowed people to recover their phones.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.