Setting the device owner in an AOSP build for Android 9 (Pie)


I was recently trying to provision my Video Kiosk App as the device owner in an AOSP build for the Odroid N2 developer board.

While there were some clues on the Internet there really was not a working solution.  In fact there were some old, purported, solutions that were simply wrong.

So how do you do it?

First create your device_policies.xml and device_owner_2.xml files.  Here are the ones I’m using. They were created by entering the command:

adb shell dpm set-device-owner com.burningthumb.premiervideokiosk/.AdminReceiver

device_policies.xml

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<policies setup-complete="true">
<admin name="com.burningthumb.premiervideokiosk/com.burningthumb.premiervideokiosk.AdminReceiver">
<policies flags="0" />
<strong-auth-unlock-timeout value="0" />
</admin>
</policies>

device_owner_2.xml

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<policies setup-complete="true">
<admin name="com.burningthumb.premiervideokiosk/com.burningthumb.premiervideokiosk.AdminReceiver">
<policies flags="0" />
<strong-auth-unlock-timeout value="0" />
</admin>
</policies>
odroidn2:/system # cat device_owner_2.xml
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<root>
<device-owner package="com.burningthumb.premiervideokiosk" name="" component="com.burningthumb.premiervideokiosk/com.burningthumb.premiervideokiosk.AdminReceiver" userRestrictionsMigrated="true" />
<device-owner-context userId="0" />
</root>

Then use the AOSP build system to copy those files to the /system directory of the AOSP build (they eventually need to be put in the /data/system directory but the AOSP build system seems, so far as I can tell, unable to copy files directly into /data/system directory).

To accomplish this, I put those files in the directory odroid-n2/device/hardkernel and added these lines just prior to the last line of the odroid-n2/device/hardkernel/odroidn2.mk file:

# Set device ownership for the kiosk mode app
PRODUCT_COPY_FILES += device/hardkernel/$(PRODUCT_DIR)/device_owner_2.xml:/system/device_owner_2.xml
PRODUCT_COPY_FILES += device/hardkernel/$(PRODUCT_DIR)/device_policies.xml:/system/device_policies.xml

Finally I used the init.rc to copy the files to /data/system by adding these lines to the on post-fs-data section of the init.ordoidn2.system.rc file in that odroid-n2/device/hardkernel directory:

# set the device owner to Video Kiosk
copy /system/device_owner_2.xml /data/system/device_owner_2.xml
chmod 0600 /data/system/device_owner_2.xml
chown system system /data/system/device_owner_2.xml
copy /system/device_policies.xml /data/system/device_policies.xml
chmod 0600 /data/system/device_policies.xml
chown system system /data/system/device_policies.xml

So there you have it, a working solution, so far as I can tell, for provisioning your App as a device owner on Android 9 (Pie) using the Odroid N2 developer board.

Leave a comment