Problem Statement:
Enrolling devices to DO Mode is time taking process which involves factory reset.
To overcome this difficulty we can make use of adb commands, configure the app as Device Owner in just few mins without worrying about factory resetting the device .
Prerequiste:
1.Enable adb & install adb tools on PC you can find the steps in this link :
https://developer.android.com/studio/command-line/adb#Enabling
https://www.xda-developers.com/install-adb-windows-macos-linux/
3.Install apk that need to be set as Device Owner.
https://play.google.com/store/apps/details?id=com.afwsamples.testdpc
https://www.apkmirror.com/apk/sample-developer/test-dpc/
3.Remove all accounts configured on the device without that Android OS will not allow to configure device owner.
Process to set application as DO using adb:
We will be using TestDPC application for this you can find link for it in prerequistes.
I hope at this point all pre-requistes are taken care & TestDPC is installed on the device.
Open command prompt or terminal & enter below command to set TestDPC as device
adb shell dpm set-device-owner com.afwsamples.testdpc/.DeviceAdminReceiver
We can even set it as profile owner & remove them as Device Owner or Profile Owner using below command.
adb shell dpm set-profile-owner com.afwsamples.testdpc/.DeviceAdminReceiver
adb shell dpm remove-active-admin com.afwsamples.testdpc/.DeviceAdminReceiver –
Note: Remove Device owner command will require application be in testOnly mode.It is used only while developing application.
https://developer.android.com/guide/topics/manifest/application-element#testOnly