How to enable task locking in Android 5.0 production devices This StackOverflow question explores how to enable a device owner app, and thus kiosk mode, in the Android L developer preview. As the method requires a userdebug build of Android, rooting the device, and copying an XML file into the root filesystem, it doesn't seem suitable for mass deployment of a single function Android device inside a company.

How are device owner apps going to be installed on production Android L devices?
(Edit: Updated after some more testing)

Check the latest documentation.

This feature seems to be called Screen pinning now, and the App does not have to be the device owner. If the device owner is not set the user will be prompted to accept. But there are issues with this for kiosk use, mentioned below.


  There are two ways to activate screen pinning:
  
  Manually: Users can enable screen pinning in Settings > Security >
  Screen Pinning, and select the tasks they want to pin by touching the
  green pin icon in the recents screen. Programmatically: To activate
  screen pinning programmatically, call startLockTask() from your app.
  If the requesting app is not a device owner, the user is prompted for
  confirmation. A device owner app can call the setLockTaskPackages()
  method to enable apps to be pinnable without the user confirmation
  step.


If you activate screen pinning programatically (non device owner App) or on the device using the pin in the recents you get the following behaviour:

A dialog appears asking the user if they want to enable screen pinning and if they want to require a password to exit. If they press yes the status bar and notifications disappear, back, home and recents buttons do NOT disappear. Tapping on home or recents makes a toast appear inform the user how to exit screen pinning.

The user can then hold down back and recents to exit screen pinning. If the user selected to require a password, they will get kicked straight to the lock screen. This behaviour means it is not suitable for a kiosk imo. As it is too easy for kiosk users to end up looking at the lock screen.

To get a proper kiosk mode we need to set the device owner. Google's documentation says you need to do this with NFC:


  To deploy and activate a device owner, you must perform an NFC data
  transfer from a programming app to the device while the device is in
  its unprovisioned state.


Using NFC to do this seems a bit complex (what if a device does not have NFC?). I have not investigated this yet so if anyone can provide info how you go about setting the device owner by NFC? Which now becomes the main point of your question. (i.e. setting the device owner on a non rooted device)

But to confirm the behaviour is as expected if you root a device you can set the device owner as per Google's previous instructions (adding a device_owner.xml) as I mentioned here

Now you can properly lock the App, no dialog appears for the user to accept, when enabled the recents and home button disappear and the user cannot leave the App unless your App unlocks itself. A proper kiosk mode. I have tested this on a Nexus 7 2013 with the latest Lollipop build.

The following snippet turns on the lock:

mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
mDeviceAdminSample = new ComponentName(this, DeviceAdminSample.class);

if (mDPM.isDeviceOwnerApp(this.getPackageName())) {
    Log.d(TAG, "isDeviceOwnerApp: YES");
    String[] packages = {this.getPackageName()};
    mDPM.setLockTaskPackages(mDeviceAdminSample, packages);
} else {
    Log.d(TAG, "isDeviceOwnerApp: NO");
}

if (mDPM.isLockTaskPermitted(this.getPackageName())) {
    Log.d(TAG, "isLockTaskPermitted: ALLOWED");
    startLockTask();
} else {
    Log.d(TAG, "isLockTaskPermitted: NOT ALLOWED");
}