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:
- Bedtime Mode -
BedtimeMode - Ambient Mode -
AmbientMode - Tilt To Wake -
TiltToWake - Do Not Disturb Mode -
DoNotDisturbMode - Touch Lock Mode -
TouchLockMode - Theater Mode -
TheaterMode - Battery Saver Mode -
BatterySaverMode - School Mode -
SchoolMode - Downtime Mode -
DowntimeMode
Following is the list of reasons why the state of a mode or feature is overridden:
- Unknown reason -
ModeManager.FLAG_OVERRIDDEN_BY_UNKNOWN_REASON - Bedtime Mode -
ModeManager.FLAG_OVERRIDDEN_BY_BEDTIME_MODE - Theater Mode -
ModeManager.FLAG_OVERRIDDEN_BY_THEATER_MODE - Screen reader -
ModeManager.FLAG_OVERRIDDEN_BY_SCREEN_READER - Battery Saver Mode -
ModeManager.FLAG_OVERRIDDEN_BY_BATTERY_SAVER_MODE - School Mode -
ModeManager.FLAG_OVERRIDDEN_BY_SCHOOL_MODE - Downtime Mode -
ModeManager.FLAG_OVERRIDDEN_BY_DOWNTIME_MODE
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 |
BatterySaverMode
|
getBatterySaverMode()
Gets the instance of |
BedtimeMode
|
getBedtimeMode()
Gets the instance of |
DoNotDisturbMode
|
getDoNotDisturbMode()
Gets the instance of |
DowntimeMode
|
getDowntimeMode()
Gets the instance of |
int
|
getModeSupportStatus(Class<?> clazz)
Gets the current support status for a given mode. |
SchoolMode
|
getSchoolMode()
Gets the instance of |
TheaterMode
|
getTheaterMode()
Gets the instance of |
TiltToWake
|
getTiltToWake()
Gets the instance of |
TouchLockMode
|
getTouchLockMode()
Gets the instance of |
void
|
removeModeSupportStatusListener(BiConsumer<Class<?>, Integer> listener)
Removes a previously added mode support status listener. |
Inherited methods | |
|---|---|
Constants
MODE_SUPPORT_STATUS_NOT_SUPPORTED
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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:
Value is one of the following: |
getSchoolMode
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
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
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
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
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. |