title: Remove Device Owner Android
body: <p>I'm quite new in Java and Android dev coming from a more c++ background. I've created a Kiosk/COSU app using <a href="https://stackoverflow.com/questions/40960648/android-studio-kiosk-mode-single-purpose-devices-lock-task-mode">this question </a> as guidance. I set the app as device admin using </p>
  
  <pre><code>adb shell dpm set-device-owner ...../.AppAdminReceiver
  </code></pre>
  
  <p>I'd like to disable the active device owner without factory resetting the device. I've tried programatically using questions like <a href="https://stackoverflow.com/questions/48990479/disable-a-device-owner-app-from-android-terminal">this</a>
  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 <code>android:testOnly="true"</code> to the AndroidManifest.xml and then using <code>adb shell dpm remove-active-admin ...../.AppAdminReceiver</code> as seen <a href="https://stackoverflow.com/questions/48990479/disable-a-device-owner-app-from-android-terminal">here</a> but I get the error </p>
  
  <p><code>java.lang.SecurityException: Attempt to remove non-test admin ComponentInfo{....AppAdminReceiver} 0</code>. </p>
  
  <p>The method described in the previous link seems to be deprecated in Android Oreo which is the OS I'm building my app for.</p>
  
  <p>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.</p>