How to use Android-L preview Task Locking?
Asked Answered
Y

2

9

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.

Yaelyager answered 14/10, 2014 at 10:36 Comment(3)
You might get better answers if you ask this question on the Android Stackexchange..Postmark
What is the problem you got?Proprietary
I've asked a related question on Android Stackexchange, about how we will enable this on production Android-L devices: android.stackexchange.com/questions/85013/…Schwartz
C
6

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
Camber answered 15/10, 2014 at 4:10 Comment(3)
Thanks! 8. chown system:system seems to have made the difference, working now :)Yaelyager
There is a way to do this in versions less than 21 ?Gelya
@Menna-AllahSami No Task Locking (now called screen pinning) requires Lollipop. There are ways to try and do something similar but none of them work as well imo.Yaelyager
V
2

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

Vinson answered 14/10, 2014 at 11:35 Comment(3)
Calling 'startLockTask' without pushing the file does not seem to have any effect.Yaelyager
@Yaelyager without pushing device_owner.xml u wont be able to go in kiosk modeCamber
@Vinson without pushing device_owner.xml how can u use startLockTask() in Android L???Camber

© 2022 - 2024 — McMap. All rights reserved.