5

I'm quite new in Java and Android dev coming from a more c++ background. I've created a Kiosk/COSU app using this question as guidance. I set the app as device admin using

adb shell dpm set-device-owner ...../.AppAdminReceiver

I'd like to disable the active device owner without factory resetting the device. I've tried programatically using questions like this and a few others but it doesn't seem to work. The code executes but the app is still the device owner. I've also tried adding android:testOnly="true" to the AndroidManifest.xml and then using adb shell dpm remove-active-admin ...../.AppAdminReceiver as seen here but I get the error

java.lang.SecurityException: Attempt to remove non-test admin ComponentInfo{....AppAdminReceiver} 0.

The method described in the previous link seems to be deprecated in Android Oreo which is the OS I'm building my app for.

How can I remove the device owner in Oreo? I don't mind if it's done via adb or programmatically, as long as I don't need to factory reset the device.

user931018
  • 643
  • 1
  • 10
  • 24
  • Device owner and device admin are two different things. AFAIK device owner can be set only on factory reset device. Device admin can be taken down in settings. If you want to take down device admin, you need to factory reset your phone. Unless the phone is rooted (I think) – Krzysztof Kubicki Aug 02 '18 at 05:45
  • I apologise if I was ambiguous with regards to it being device owner and device admin. The command I used as stated in my question seems to indicate that the app was set as Device Owner. However, I was able to execute this command via the Android Studio terminal using adb instead of being set on Factory Reset. Is there anything else I can try to remove the app as Device Owner? I've also updated my question to use device owner instead of admin. – user931018 Aug 02 '18 at 07:29
  • have you tried this? https://stackoverflow.com/questions/49128293/how-to-remove-set-device-owner-in-android-dpm – Krzysztof Kubicki Aug 02 '18 at 08:11
  • @KrzysztofKubicki Yes I have. As stated above, it executes but it doesn't seem to trigger anything. Seems this was deprecated in API 26. – user931018 Aug 02 '18 at 08:25

2 Answers2

4

I have found following ways to activate a device owner

  1. QR code provisioning
  2. "adb shell dpm set-device-owner" command
  3. NFC provisioning

Once you have activated the device owner, you won't be able to deactivate it from settings.

There are two ways to remove a device owner

  1. Factory reset
  2. The second can only be done from the device owner application code, it is as follows

    DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    devicePolicyManager.clearDeviceOwnerApp(this.getPackageName());
    

I have created a hidden option in the application to run this.

**Please note that if you want to add this code and run the application to remove owner privileges, the application should be signed with the same key.

Milind Gaikwad
  • 175
  • 1
  • 7
0

You can do it in settings. Just open settings and type "admin" in the search box. Then select "Device admin apps", click on your app and "Deactivate this device admin app"

Alternative way to that page might be Apps & Notifications -> Scroll down and select Advanced -> Special app access -> Device admin apps

Siim Puniste
  • 210
  • 2
  • 11