How to remove set-device-owner in Android DPM?
Asked Answered
C

6

21

I have made an app device owner using ADB, by following this link : How to make my app a device owner?

but now, I'm not able to revert this.

In the device administration Tab, this option is disabled. Not able to change the value of this app.

Certainty answered 6/3, 2018 at 10:12 Comment(0)
P
41

By specifying the android:testOnly="true" attribute in the AndroidManifest.xml it will be possible to uninstall the app or remove admin with:

adb shell dpm remove-active-admin package.name/MyDeviceAdminReceiver

But on a production device, this attribute should not be included and the app will be a non-test admin. From that point, it will not be possible to remove it or uninstall the application without wipe/factory reset.

Thankfully, updates can be done when the app is signed with the same key and when the version code is equal or greater:

adb install -r path/to/kiosk.apk

If you would like to get rid of admin and application on a production device programatically you have to reinstall it with a few new changes. Firstly you can wipe data programmatically if you have permission <wipe-data \> in device_admin_receiver.xml with:

devicePolicyManager.wipeData(DevicePolicyManager.WIPE_RESET_PROTECTION_DATA)

If you don’t have this permission new version should not start LockTask and remove its package from default Home app list with:

devicePolicyManager.clearPackagePersistentPreferredActivities(adminComponentName, packageName)

You could then manually go to Settings to perform a wipe/factory reset.

Information found on https://snow.dog/blog/kiosk-mode-android

Puissant answered 13/11, 2018 at 22:33 Comment(1)
Attempt to remove non-test adminDithyrambic
G
15

You can unset it programmatically. You need to call this function in your device owner application

DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);

dpm.clearDeviceOwnerApp(context.getPackageName());

For more information see

Update: This method is deprecated in API level 26

Gombach answered 14/5, 2018 at 7:22 Comment(2)
This method was deprecated in API level 26. Android DocsScup
I can't restart app because, quote "app is already running", I can't stop it or reinstallBases
L
7

you can use the following ADB shell command to remove device owner

adb shell dpm remove-active-admin ComponentInfo{}

Disables an active admin, the admin must have declared android:testOnly in the application in its manifest. This will also remove device and profile owners

Laurilaurianne answered 22/5, 2018 at 6:30 Comment(2)
This works as long as the active admin app does not have android:testOnly="false" in its AndroidManifest.xml. Otherwise, Android (at least 6.0) gets cranky and refuses to do what is asked of it.Juba
fyi: adb shell dpm remove-active-admin only available from Android 7Impignorate
I
2

fyi: adb shell dpm remove-active-admin only available from Android 7

Impignorate answered 7/4, 2020 at 21:50 Comment(1)
Okay so what you actually mean is that ""The above command from sjDroid is usable in Android 7+ only AND the developer must have declared android:testOnly in the application""Sigma
I
1

The only way out is to flash or factory reset the device.

Inevitable answered 13/3, 2018 at 10:16 Comment(1)
The above link is for removing device administrator and not device owner. Device administrator cannot be removed if device owner is active. Please get your facts right before downvoting an answerInevitable
S
1

This is crazy. I have been able to remove Device Admin (uninstall or disable) on my S7 and S5 forever. I don't understand why I cannot disable/remove a Package Disabler app as is malfunctioning on my S10 w/ OS 11.

Surely there is a way to remove it via ADB? I added it via ADB.

I wish people would write complete instructions WITH warnings that you will not be able to remove it after install without factory reset! (all my apps + data lost!)

Hmm... Please provide a solution for stock non-root users :D Thanks!

Sigma answered 7/2, 2022 at 6:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.