How to remove set-device-owner in Android DPM?

2019-01-27 08:02发布

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.

4条回答
倾城 Initia
2楼-- · 2019-01-27 08:30

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 be deleted so that the app will become a non-test admin. From that point, it will not be possible to remove it or uninstall the application without wipe/factory reset. It’s also important to remember that if you build an app from the Android Studio, it will be signed with a default key from Android and the application will become a non-test admin. After some time, if you would like to add some new features you will realize that it’s not possible to install a new version. Thankfully, updates can be done when the app is signed with the same key when version code is equal or greater with:

adb install -r path/to/kiosk.apk

If you would like to get rid of admin and application on the production device 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:

mDevicePolicyManager.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 apps list with:

mDevicePolicyManager.clearPackagePersistentPreferredActivities(mAdminComponentName, packageName)

Then you could manually go to Settings to perform wipe/factory reset.

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

查看更多
Deceive 欺骗
3楼-- · 2019-01-27 08:38

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

查看更多
别忘想泡老子
4楼-- · 2019-01-27 08:39

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

查看更多
疯言疯语
5楼-- · 2019-01-27 08:46

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

查看更多
登录 后发表回答