Disable DeviceAdmin from shell?

15,568

Solution 1

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

Solution 2

adb shell pm disable-user (package name) will deactivate DeviceAdmin and disable the app. It will not be activated even if you enable the app again.

Solution 3

You can not uninstall app directly if it is set as Admin .first you have to disable the admin mode then you will be able to uninstall app. to remove active admin first you run this command

adb shell dpm remove-active-admin com.kiosk.example/com.kiosk.example.MyDeviceAdminReceiver 

(com.kiosk.example) is package name replace it with your own and MyDeviceAdminReceiver is receiver name. when this command give success then you can uninstall app. or run this command to uninstall

adb uninstall com.kiosk.example.

Share:
15,568
Shatazone
Author by

Shatazone

Updated on July 27, 2022

Comments

  • Shatazone
    Shatazone over 1 year

    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?