ModeManager

public final class ModeManager
extends Object

java.lang.Object
   ↳ com.google.wear.modes.ModeManager


Provides a means to query and update the state of modes and features on Wear.

An instance of this class can be obtained directly via the Wear SDK by invoking the following API:

com.google.wear.Sdk.getWearManager(context, ModeManager.class);

This class provides methods returning objects to control the mode or feature under consideration particularly interacting with its configured and active value where:

  • Active value: This refers to the value of the state of the mode or feature as reflected on the device.
  • Configured value: This refers to the default value of the state of the mode or feature.

Only the configured value of a mode or feature can be set directly. The active value, on the other hand, cannot be set directly and is determined by the current operating context of the system and depends on either the configuration of this mode / feature or the configurations of others. If the configured value of a mode or feature does not play a role in determining its active value, it's state is said to be overridden. There are a variety of reasons as to why the state of a mode or feature might be overridden.

As an example, let's consider the interaction of just two states: Battery Saver Mode and Always on Display and that battery saver mode overrides the state of ambient mode. If ambient mode is enabled, and we also enable battery saver mode, ambient mode will be disabled. Here the configured value for ambient mode will still be true but the active value will be false, i.e. ambient mode is overridden. Even if the configured value for always on display is updated, it would remain disabled. Only when battery saver mode is disabled, i.e. the override on ambient mode is uplifted, the enablement status of ambient mode will be updated to its configured value.

Following is the list of supported modes and features:

Following is the list of reasons why the state of a mode or feature is overridden:

Summary

Constants

int MODE_SUPPORT_STATUS_NOT_SUPPORTED

The mode is not supported for the current user on this device.

int MODE_SUPPORT_STATUS_SUPPORTED

The mode is actively supported for the current user on this device.

int MODE_SUPPORT_STATUS_UNKNOWN

The support status cannot be determined at this time.

Fields

public static final long FLAG_OVERRIDDEN_BY_BATTERY_SAVER_MODE

Flag to check if the state of a mode or feature is being overridden by Battery Saver Mode.

public static final long FLAG_OVERRIDDEN_BY_BEDTIME_MODE

Flag to check if the state of a mode or feature is being overridden by Bedtime Mode.

public static final long FLAG_OVERRIDDEN_BY_DOWNTIME_MODE

Flag to check if the state of a mode or feature is being overridden by Downtime Mode.

public static final long FLAG_OVERRIDDEN_BY_SCHOOL_MODE

Flag to check if the state of a mode or feature is being overridden by School Mode.

public static final long FLAG_OVERRIDDEN_BY_SCREEN_READER

Flag to check if the state of a mode or feature is being overridden by screen reader

public static final long FLAG_OVERRIDDEN_BY_THEATER_MODE

Flag to check if the state of a mode or feature is being overridden by Theater Mode.

public static final long FLAG_OVERRIDDEN_BY_UNKNOWN_REASON

Flag to check if the state of a mode or feature is being overridden but the reason is unknown

Public methods

void addModeSupportStatusListener(Executor executor, BiConsumer<Class<?>, Integer> listener)

Adds a listener to receive updates on mode support status.

AmbientMode getAmbientMode()

Gets the instance of AmbientMode to control Ambient Mode.

BatterySaverMode getBatterySaverMode()

Gets the instance of BatterySaverMode to control Battery Saver Mode.

BedtimeMode getBedtimeMode()

Gets the instance of BedtimeMode to control Bedtime Mode.

DoNotDisturbMode getDoNotDisturbMode()

Gets the instance of DoNotDisturbMode to control Do Not Disturb Mode.

DowntimeMode getDowntimeMode()

Gets the instance of DowntimeMode to control Downtime Mode or null if unavailable.

int getModeSupportStatus(Class<?> clazz)

Gets the current support status for a given mode.

SchoolMode getSchoolMode()

Gets the instance of SchoolMode to control School Mode or null if unavailable.

TheaterMode getTheaterMode()

Gets the instance of TheaterMode to control Theater Mode.

TiltToWake getTiltToWake()

Gets the instance of TiltToWake to control Tilt To Wake.

TouchLockMode getTouchLockMode()

Gets the instance of TouchLockMode to control Touch Lock Mode or null if unavailable.

void removeModeSupportStatusListener(BiConsumer<Class<?>, Integer> listener)

Removes a previously added mode support status listener.

Inherited methods

Constants

MODE_SUPPORT_STATUS_NOT_SUPPORTED

Added in API level 37
public static final int MODE_SUPPORT_STATUS_NOT_SUPPORTED

The mode is not supported for the current user on this device.

Constant Value: 3 (0x00000003)

MODE_SUPPORT_STATUS_SUPPORTED

Added in API level 37
public static final int MODE_SUPPORT_STATUS_SUPPORTED

The mode is actively supported for the current user on this device.

Constant Value: 2 (0x00000002)

MODE_SUPPORT_STATUS_UNKNOWN

Added in API level 37
public static final int MODE_SUPPORT_STATUS_UNKNOWN

The support status cannot be determined at this time.

Constant Value: 1 (0x00000001)

Fields

FLAG_OVERRIDDEN_BY_BATTERY_SAVER_MODE

Added in version 33.2
public static final long FLAG_OVERRIDDEN_BY_BATTERY_SAVER_MODE

Flag to check if the state of a mode or feature is being overridden by Battery Saver Mode. This requires the permission to read the state of Battery Saver Mode (i.e. READ_BATTERY_SAVER)

FLAG_OVERRIDDEN_BY_BEDTIME_MODE

Added in version 33.2
public static final long FLAG_OVERRIDDEN_BY_BEDTIME_MODE

Flag to check if the state of a mode or feature is being overridden by Bedtime Mode. This requires the permission to read the state of Bedtime Mode (i.e. READ_FOCUS_MODES)

FLAG_OVERRIDDEN_BY_DOWNTIME_MODE

Added in version 36.1
public static final long FLAG_OVERRIDDEN_BY_DOWNTIME_MODE

Flag to check if the state of a mode or feature is being overridden by Downtime Mode. This requires the permission to read the state of Downtime Mode (i.e. READ_FOCUS_MODES)

FLAG_OVERRIDDEN_BY_SCHOOL_MODE

Added in version 33.3
public static final long FLAG_OVERRIDDEN_BY_SCHOOL_MODE

Flag to check if the state of a mode or feature is being overridden by School Mode. This requires the permission to read the state of School Mode (i.e. READ_FOCUS_MODES)

FLAG_OVERRIDDEN_BY_SCREEN_READER

Added in version 33.2
public static final long FLAG_OVERRIDDEN_BY_SCREEN_READER

Flag to check if the state of a mode or feature is being overridden by screen reader

FLAG_OVERRIDDEN_BY_THEATER_MODE

Added in version 33.2
public static final long FLAG_OVERRIDDEN_BY_THEATER_MODE

Flag to check if the state of a mode or feature is being overridden by Theater Mode. This requires the permission to read the state of Theater Mode (i.e. READ_FOCUS_MODES)

FLAG_OVERRIDDEN_BY_UNKNOWN_REASON

Added in version 33.2
public static final long FLAG_OVERRIDDEN_BY_UNKNOWN_REASON

Flag to check if the state of a mode or feature is being overridden but the reason is unknown

Public methods

addModeSupportStatusListener

Added in API level 37
public void addModeSupportStatusListener (Executor executor, 
                BiConsumer<Class<?>, Integer> listener)

Adds a listener to receive updates on mode support status.

The availability of optional modes can change at runtime. This listener mechanism allows applications to react to such changes. The listener will be immediately invoked with the current status for all supported modes upon registration.

The caller must hold the appropriate permission for any mode it wishes to receive updates for. The listener will only receive events for modes where the caller holds the required permission.

Parameters
executor Executor: The executor on which to invoke the listener.

listener BiConsumer: A BiConsumer that will receive the Class and its new integer status.

Throws
SecurityException if the caller does not have the required permissions.

getAmbientMode

Added in version 33.2
public AmbientMode getAmbientMode ()

Gets the instance of AmbientMode to control Ambient Mode.
Requires com.google.wear.services.Permissions.READ_DISPLAY_CONFIG

Returns
AmbientMode AmbientMode to control Ambient Mode

Throws
SecurityException if the caller does not have the permission to read Ambient Mode state

getBatterySaverMode

Added in version 33.2
public BatterySaverMode getBatterySaverMode ()

Gets the instance of BatterySaverMode to control Battery Saver Mode.
Requires com.google.wear.services.Permissions.READ_BATTERY_SAVER

Returns
BatterySaverMode BatterySaverMode to control Battery Saver Mode

Throws
SecurityException if the caller does not have the permission to read Battery Saver Mode state

getBedtimeMode

Added in version 33.2
public BedtimeMode getBedtimeMode ()

Gets the instance of BedtimeMode to control Bedtime Mode.
Requires com.google.wear.services.Permissions.READ_FOCUS_MODES

Returns
BedtimeMode BedtimeMode to control Bedtime Mode

Throws
SecurityException if the caller does not have the permission to read Bedtime Mode state

getDoNotDisturbMode

Added in version 33.2
public DoNotDisturbMode getDoNotDisturbMode ()

Gets the instance of DoNotDisturbMode to control Do Not Disturb Mode.
Requires com.google.wear.services.Permissions.READ_FOCUS_MODES

Returns
DoNotDisturbMode DoNotDisturbMode to control Do Not Disturb Mode

Throws
SecurityException if the caller does not have the permission to read Do Not Disturb Mode state

getDowntimeMode

Added in version 36.1
public DowntimeMode getDowntimeMode ()

Gets the instance of DowntimeMode to control Downtime Mode or null if unavailable.
Requires com.google.wear.services.Permissions.READ_FOCUS_MODES

Returns
DowntimeMode DowntimeMode to control Downtime Mode or null if Downtime Mode is not supported

Throws
SecurityException if the caller does not have the permission to read Downtime Mode state

getModeSupportStatus

Added in API level 37
public int getModeSupportStatus (Class<?> clazz)

Gets the current support status for a given mode.

Some modes are optional and may not be supported on all devices. This method, along with addModeSupportStatusListener(Executor, BiConsumer), is the recommended way to check for support, especially for modes like SchoolMode and DowntimeMode whose availability can change at runtime.

This method returns the status at the time of calling. To react to changes in the support status (e.g., after device provisioning or when supervision is enabled), applications should use addModeSupportStatusListener(Executor, BiConsumer).

The caller must hold the appropriate permission for the specific mode being queried. If the permission is not held, the status will be returned as MODE_SUPPORT_STATUS_UNKNOWN.

Parameters
clazz Class: The class representing the mode to query (e.g., SchoolMode.class).

Returns
int The current ModeSupportStatus for the given mode. This will be one of:
  • MODE_SUPPORT_STATUS_SUPPORTED: The mode is available and can be used on the device for the current user.
  • MODE_SUPPORT_STATUS_NOT_SUPPORTED: The mode is not available on this device. This can be due to hardware/software configuration or because a necessary condition is not met (e.g., device supervision is not enabled for a supervised mode).
  • MODE_SUPPORT_STATUS_UNKNOWN: The support status could not be determined at this time. This can occur if the device has not completed its initial setup (OOBE), or if the calling app lacks the necessary permission to query the mode's status.
.
Value is one of the following:

getSchoolMode

Added in version 33.3
public SchoolMode getSchoolMode ()

Gets the instance of SchoolMode to control School Mode or null if unavailable.
Requires com.google.wear.services.Permissions.READ_FOCUS_MODES

Returns
SchoolMode SchoolMode to control School Mode or null if School Mode is not supported

Throws
SecurityException if the caller does not have the permission to read School Mode state

getTheaterMode

Added in version 33.2
public TheaterMode getTheaterMode ()

Gets the instance of TheaterMode to control Theater Mode.
Requires com.google.wear.services.Permissions.READ_FOCUS_MODES

Returns
TheaterMode TheaterMode to control Theater Mode

Throws
SecurityException if the caller does not have the permission to read Theater Mode state

getTiltToWake

Added in version 33.2
public TiltToWake getTiltToWake ()

Gets the instance of TiltToWake to control Tilt To Wake.
Requires com.google.wear.services.Permissions.READ_GESTURES_CONFIG

Returns
TiltToWake TiltToWake to control Tilt To Wake

Throws
SecurityException if the caller does not have the permission to read Tilt To Wake state

getTouchLockMode

Added in version 33.2
public TouchLockMode getTouchLockMode ()

Gets the instance of TouchLockMode to control Touch Lock Mode or null if unavailable.
Requires com.google.wear.services.Permissions.READ_TOUCH_LOCK

Returns
TouchLockMode TouchLockMode to control Touch Lock Mode

Throws
SecurityException if the caller does not have the permission to read Touch Lock Mode state

removeModeSupportStatusListener

Added in API level 37
public void removeModeSupportStatusListener (BiConsumer<Class<?>, Integer> listener)

Removes a previously added mode support status listener.

If the listener is not currently registered, this method does nothing.

This method does not require any permissions to be held by the caller.

Parameters
listener BiConsumer: The listener to remove.