Disable DeviceAdmin from shell?

Shatazone picture Shatazone · Dec 17, 2012 · Viewed 12.2k times · Source

I'm trying to uninstall an application from shell, however this application is running as a device administrator and thus shell> adb uninstall com.example.test did not work.

How can I disable a device admin from shell?

Answer

CJBS picture CJBS · Mar 17, 2015

Typically, administrative access is revoked via the Device Administrators screen, then the app is uninstalled. In the subsequent examples, I'll assume airdroid (com.sand.airdroid), has been configured as a device administrator, and is to be uninstalled. So to tailor this example, replace instances of com.sand.airdroid with your own app name.

The clean method

To access Device Administrators, navigate: SettingsSecurityDevice Administrators. Then, uncheck the application to un-set administrative access for.

It's also possible to open up this activity using the shell:

adb shell am start -S "com.android.settings/.Settings\$DeviceAdminSettingsActivity"

Once this is done, the activity can be uninstalled normally:

adb uninstall com.sand.airdroid

The brute-force method (requires root)

A brute-force method does exist. It involves searching for all files in the /system and /data filesystems, and deleting each found item. Disclaimer: Use with care (test on an emulator first).

adb shell

# Switch to root
su -

# Search for all installed files using the fully-qualified app name
find /system /data -name \*com.sand.airdroid\* 

...a list of files (including directories) appears -- for each file, cause it to be deleted by prefixing it with a rm -f:

rm -r /data/media/0/Android/data/com.sand.airdroid
rm -r /data/data/com.sand.airdroid
rm -r /data/app-lib/com.sand.airdroid-1
rm -r /data/app/com.sand.airdroid-1.apk
rm -r /data/dalvik-cache/data@[email protected]@classes.dex

# Run the find command again to ensure nothing was missed
find /system /data -name \*com.sand.airdroid\* 

# exit root
exit
# exit Android shell
exit

To allow Android to clean up its files, reboot the device.

adb reboot

Once the device has restarted, the application can be uninstalled with the uninstall command to finalize clean-up.

adb uninstall com.sand.airdroid