Disable DeviceAdmin from shell?
Asked Answered
R

3

9

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?

Rainer answered 17/12, 2012 at 9:30 Comment(0)
I
18

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
Ivon answered 17/3, 2015 at 7:19 Comment(4)
I was looking for a solution that doesn't require root, reboot nor user inputRainer
Thanks! this worked, second method once the phone is rooted or a nexusReiners
Needed to add single quotes like here android.stackexchange.com/questions/45601/… adb shell am start -S "'com.android.settings/.Settings\$DeviceAdminSettingsActivity'"Snowdrift
Thanks this works with a slight modification: I also modify /data/system/device_policies.xmlBootblack
G
16

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.

Galleywest answered 12/8, 2018 at 11:18 Comment(4)
And then you can call 'uninstall' command to uninstall once the app is in disabled state. This is the real non-root solution.Aras
Installed a malware and this worked in removing it. After the disable-user command, I proceeded to run 'adb uninstall package-name'Barbarian
Any way of enabling device admin again after? I needed to do this on a bugged development device and now I cannot allow the app to be device admin even after reinstall.Clientele
This worked on my Android 9 device, thanks a lot!Gauze
T
2

You can not uninstall app directly if it is set as Admin. First you have to disable the admin mode and 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
Tubulure answered 29/4, 2019 at 7:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.