# Dedicated devices

Glass is typically configured to be used as a dedicated device with a small number of
applications that make up an enterprise solution. The following guide demonstrates how to set
up Glass as a dedicated device.

> [!IMPORTANT]
> For more information, see [dedicated devices overview](https://developer.android.com/work/dpc/dedicated-devices) and [dedicated devices cookbook](https://developer.android.com/work/dpc/dedicated-devices/cookbook).

## Provisioning

[Low-touch provisioning](https://developers.google.com/glass-enterprise/guides/provisioning-and-configuration)
on Glass Enterprise Edition 2 installs and configures an admin application that's
downloaded from the metadata provided in a QR code. This application can take advantage of the
[DevicePolicyManager](https://developer.android.com/reference/android/app/admin/DevicePolicyManager)
API, which is the preferred method to manage the device's configuration.

## Replace launcher

To set up a dedicated device, you must replace the launcher application. This ensures that the
dedicated application is launched automatically after the device reboots. The following content
outlines the tasks involved in preparing an application and setting it as the launcher:

- [Activity intent filter](https://developers.google.com/glass-enterprise/guides/dedicated-devices#activity-intent-filter)
- [Set a new launcher](https://developers.google.com/glass-enterprise/guides/dedicated-devices#set-a-new-launcher)

### Activity intent filter

- You need to add the following categories to the main activity in your application's manifest:

```
<intent-filter>
  <action android:name="android.intent.action.MAIN"/>
  <category android:name="android.intent.category.LAUNCHER"/>

  <category android:name="android.intent.category.HOME"/>
  <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
```

### Set a new launcher

- To set a new launcher, call [addPersistentPreferredActivity()](https://developer.android.com/reference/android/app/admin/DevicePolicyManager#addPersistentPreferredActivity(android.content.ComponentName,%20android.content.IntentFilter,%20android.content.ComponentName)) from the admin application. This only works if the device has already been provisioned. For non-provisioned devices, select a new launcher from the UI on the device.

#### Add persistent preferred activity

- This method allows you to set a given `componentName` as the device's launcher, without interacting with the device.

### Kotlin

```kotlin
val filter = IntentFilter(Intent.ACTION_MAIN)
filter.addCategory(Intent.CATEGORY_HOME)
filter.addCategory(Intent.CATEGORY_DEFAULT)

val componentName = ComponentName(PACKAGE_NAME, CLASS_NAME)
val devicePolicyManager: DevicePolicyManager =
    context.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val adminName = getComponentName(context)
devicePolicyManager.addPersistentPreferredActivity(adminName, filter, componentName)
```

### Java

```java
final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
filter.addCategory(Intent.CATEGORY_HOME);
filter.addCategory(Intent.CATEGORY_DEFAULT);

final ComponentName componentName = new ComponentName(PACKAGE_NAME, CLASS_NAME);
DevicePolicyManager devicePolicyManager =
    (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
final adminName = getComponentName(context);
devicePolicyManager.addPersistentPreferredActivity(adminName, filter, componentName);
```
**Note:** Reboot the device to apply the changes.

#### Use UI on the device

- Use one of the following methods to show a launcher selection dialog on the screen:

##### Using swipe up touch gesture in settings

- Swipe backwards on the home screen to show a settings summary screen. Then, tap to enter the settings screen. Swipe up to show the dialog.

##### Using intent in the application

### Kotlin

```kotlin
val intent = Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
```

### Java

```java
final Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
```

##### Using adb command

- `adb shell am start -a android.intent.action.MAIN -c android.intent.category.HOME`
- Swipe forward and backward on the touchpad to select your preferred application and tap to confirm. Use the same method to select the "Always" button.

## Lock task mode

- Lock task mode allows you to create a list of packages that are permitted to run on the device.

> [!IMPORTANT]
> For more information, see [lock task mode overview](https://developer.android.com/work/dpc/dedicated-devices/lock-task-mode).

### Set permitted packages

- The following snippet shows you how to set the list of packages:

### Kotlin

```kotlin
private val KIOSK_PACKAGE = "com.example.kiosk"
private val PLAYER_PACKAGE = "com.example.player"
private val APP_PACKAGES = arrayOf(KIOSK_PACKAGE, PLAYER_PACKAGE)

val devicePolicyManager: DevicePolicyManager =
  context.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val adminName = getComponentName(context)
devicePolicyManager.setLockTaskPackages(adminName, APP_PACKAGES)
```

### Java

```java
private static final String KIOSK_PACKAGE = "com.example.kiosk";
private static final String PLAYER_PACKAGE = "com.example.player";
private static final String[] APP_PACKAGES = {KIOSK_PACKAGE, PLAYER_PACKAGE};

final DevicePolicyManager devicePolicyManager =
    (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
final ComponentName adminName = getComponentName(context);
devicePolicyManager.setLockTaskPackages(adminName, APP_PACKAGES);
```
**Note:** If you want to allow users to control the [settings](https://developers.google.com/glass-enterprise/guides/application-integration#settings) on Glass be sure to add the `com.google.android.glass.settings` package to the list. **Note:** If the application's package isn't on the lock task packages list, [screen pinning](https://support.google.com/android/answer/9455138) is launched instead.

### Start lock task mode

- Lock task mode can be started by the application's activity. The following snippet shows how you can do this:

### Kotlin

```kotlin
override fun onResume() {
    super.onResume()
    activity.startLockTask()
}
```

### Java

```java
@Override
public void onResume() {
  super.onResume();
  getActivity().startLockTask();
}
```