Skip to main content
Version: 17 Jan 2024

Android Lock Task CLI Tool

If you need to enable a kiosk-style functionality on the Magic Leap 2 headset for displaying demos to multiple users, it's possible to do so via the Android Lock Task Mode. You can achieve this natively through JNI using the Android documentation, or alternatively, use the command line tool built into the Magic Leap 2 OS which is documented below.

Magic Leap 2 Lock Task Mode CLI

Communicating with this service is done via intents with extras.

Below are some common usecases:

To launch apps and add them to the lock task whitelist:

adb shell am start-service -n com.magicleap.locktaskservice/.LockTaskService -e \
"com.magicleap.locktaskservice.EXTRA_ADD_AND_LAUNCH" "your.package.name"

To remove a package from the task whitelist:

adb shell am start-service -n com.magicleap.locktaskservice/.LockTaskService -e \
"com.magicleap.locktaskservice.EXTRA_REMOVE_PACKAGE" "your.package.name"

To remove all packages (effectively ending lock task mode) from the task whitelist (the 'value', 0 below, is ignored):

adb shell am start-service -n com.magicleap.locktaskservice/.LockTaskService -e \
"com.magicleap.locktaskservice.EXTRA_REMOVE_ALL_PACKAGES" 0
note

Other activities cannot be started while lock task mode is enabled.

Undoing setup

Choose one of the following to remove the admin receiver:

  1. Assuming the AndroidManifest.xml had testOnly=true at the time set-device-owner was called:
adb shell dpm remove-active-admin com.magicleap.locktaskservice/.LockTaskAdminReceiver
  1. Wipe user data:
adb reboot bootloader && fastboot erase userdata && fastboot reboot

Extras

For debugging to dump some state to logcat:

public static final String EXTRA_DUMP_STATE = "com.magicleap.locktaskservice.EXTRA_DUMP_STATE";

This command emoves all lock service tasks and undoes the lock task policies this service set. This is the first checked Extra; all other Extras are ignored if this extra is present. This extra's 'value' is ignored.

public static final String EXTRA_REMOVE_ALL_PACKAGES =
"com.magicleap.locktaskservice.EXTRA_REMOVE_ALL_PACKAGES";

The value of this extra specifies which package to remove from lock task mode.

This Extra is checked after EXTRA_REMOVE_ALL_PACKAGES.

note

Individual components cannot be removed - all components for a specific package will be removed.

public static final String EXTRA_REMOVE_PACKAGE =
"com.magicleap.locktaskservice.EXTRA_REMOVE_PACKAGE";

The value specifies which component or package to add and launch in lock task mode. This is the last Extra checked.

Recall a component is: the.package.name/a.package.name.TheClassName

Or (if the TheClassName is in the same package): the.package.name/.TheClassName

If it is determined that the string is not a component, it is assumed it is the package and uses the default intent.

public static final String EXTRA_ADD_AND_LAUNCH =
"com.magicleap.locktaskservice.EXTRA_ADD_AND_LAUNCH";