Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Android-L preview Task Locking?

Has anyone got task locking working in Android L? Could they share some details on how it works? I have seen the instructions below, but struggling to understand this.

At the moment I have made an App that I would like to run in kiosk mode. I have looked at making it a launcher App or using Surelock but the new task locking looks like it will be the best option in future.

I need to create a userdebug build of Android L? I have not built Android from source before, I started looking at making a build but I don't think the source for Android-L is available yet?

To set up a device owner, follow these steps:

Attach a device running an Android userdebug build to your development machine.
Install your device owner app.
Create a device_owner.xml file and save it to the /data/system directory on the device.

$ adb root
$ adb shell stop
$ rm /tmp/device_owner.xml
$ echo "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>">> /tmp/device_owner.xml
$ echo "<device-owner package=\"<your_device_owner_package>\"name=\"*<your_organization_name>\" />" >> /tmp/device_owner.xml
$ adb push /tmp/device_owner.xml /data/system/device_owner.xml
$ adb reboot

https://developer.android.com/preview/api-overview.html

Edit: More info

I tried rooting my device (Nexus 7) running the Android-L preview. I then put a device_owner.xml with my package name in data/system/. But it still does not work, islockTaskPermited() return false, and calling startLockTask() does nothing.

like image 399
tagy22 Avatar asked Oct 14 '14 10:10

tagy22


2 Answers

Taking Below Snip from Task Locking API

enter image description here

It is clear that startLockTask() api will be hv effect if device_owner.xml is present .

How do i check if my app is device owner ?

When you app is device owner , you app is Device Administrator option will be checked and checkbox will be gray out hence will not allow u to untick the checkbox.

enter image description here

You need to give system right while pushing device_owner.xml

Follow below steps :

  1. Create device_owner.xml [make sure the app will be present before u push device_owner.xml ]
  2. Navigate to path in terminal where device_owner is present
  3. adb push device_owner.xml /sdcard/
  4. adb shell
  5. su
  6. cp /sdcard/device_owner.xml /data/system/
  7. cd /data/system/
  8. chown system:system device_owner.xml
  9. reboot
like image 132
KOTIOS Avatar answered Oct 13 '22 16:10

KOTIOS


Make a file device_owner.xml using below content, replace appropriate package name

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<device-owner package="com.your.packagename" name="Yourname" />

adb push device_owner.xml /data/system/device_owner.xml Reboot device.

from com.your.packagename app call

startLockTask(); 

from your activity

Even if you do not have userdebug, you can test it by calling startLockTask, without pushing any file

like image 35
nandeesh Avatar answered Oct 13 '22 18:10

nandeesh