Control


public final class Control
extends Object implements Parcelable

java.lang.Object
   ↳ android.service.controls.Control


Represents a physical object that can be represented by a ControlTemplate and whose properties may be modified through a ControlAction. The information is provided by a ControlsProviderService and represents static information (not current status) about the device.

Each control needs a unique (per provider) identifier that is persistent across reboots of the system.

Each Control will have a name, a subtitle and will optionally belong to a structure and zone. Some of these values are defined by the user and/or the ControlsProviderService and will be used to display the control as well as group them for management.

Each object will have an associated DeviceTypes. This will determine the icons and colors used to display it.

An Intent linking to the provider Activity that expands on this Control and allows for further actions should be provided.

Summary

Nested classes

class Control.StatefulBuilder

Builder class for Control that contains state information. 

class Control.StatelessBuilder

Builder class for Control

Constants

int STATUS_DISABLED

The Control is currently disabled.

int STATUS_ERROR

Used to indicate that there was a temporary error while loading the device state.

int STATUS_NOT_FOUND

The device corresponding to the Control cannot be found or was removed.

int STATUS_OK

Used to indicate that the state of the device was successfully retrieved.

int STATUS_UNKNOWN

Reserved for use with the StatelessBuilder, and while loading.

Inherited constants

Fields

public static final Creator<Control> CREATOR

Public methods

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

PendingIntent getAppIntent()
String getControlId()
ControlTemplate getControlTemplate()
ColorStateList getCustomColor()

Optional color to be shown with the Control.

Icon getCustomIcon()

Optional icon to be shown with the Control.

int getDeviceType()
int getStatus()
CharSequence getStatusText()
CharSequence getStructure()

Optional top-level group to help define the Control's location, visible to the user.

CharSequence getSubtitle()
CharSequence getTitle()
CharSequence getZone()

Optional group name to help define the Control's location within a structure, visible to the user.

boolean isAuthRequired()
void writeToParcel(Parcel dest, int flags)

Flatten this object in to a Parcel.

Inherited methods

Constants

STATUS_DISABLED

Added in API level 30
public static final int STATUS_DISABLED

The Control is currently disabled. A default error message will be displayed in place of any custom text that was set through StatefulBuilder.setStatusText.

Constant Value: 4 (0x00000004)

STATUS_ERROR

Added in API level 30
public static final int STATUS_ERROR

Used to indicate that there was a temporary error while loading the device state. A default error message will be displayed in place of any custom text that was set through StatefulBuilder.setStatusText.

Constant Value: 3 (0x00000003)

STATUS_NOT_FOUND

Added in API level 30
public static final int STATUS_NOT_FOUND

The device corresponding to the Control cannot be found or was removed. The user will be alerted and directed to the application to resolve.

Constant Value: 2 (0x00000002)

STATUS_OK

Added in API level 30
public static final int STATUS_OK

Used to indicate that the state of the device was successfully retrieved. This includes all scenarios where the device may have a warning for the user, such as "Lock jammed", or "Vacuum stuck". Any information for the user should be set through StatefulBuilder.setStatusText.

Constant Value: 1 (0x00000001)

STATUS_UNKNOWN

Added in API level 30
public static final int STATUS_UNKNOWN

Reserved for use with the StatelessBuilder, and while loading. When state is requested via ControlsProviderService.createPublisherFor, use other status codes to indicate the proper device state.

Constant Value: 0 (0x00000000)

Fields

CREATOR

Added in API level 30
public static final Creator<Control> CREATOR

Public methods

describeContents

Added in API level 30
public int describeContents ()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(android.os.Parcel, int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or CONTENTS_FILE_DESCRIPTOR

getAppIntent

Added in API level 30
public PendingIntent getAppIntent ()

Returns
PendingIntent a PendingIntent linking to an Activity for the Control This value cannot be null.

getControlId

Added in API level 30
public String getControlId ()

Returns
String the identifier for the Control This value cannot be null.

getControlTemplate

Added in API level 30
public ControlTemplate getControlTemplate ()

Returns
ControlTemplate instance of ControlTemplate, that defines how the Control will behave and what interactions are available to the user This value cannot be null.

getCustomColor

Added in API level 30
public ColorStateList getCustomColor ()

Optional color to be shown with the Control. It is highly recommended to let the system default the color unless the default is not suitable for the application.

Returns
ColorStateList background color to use This value may be null.

getCustomIcon

Added in API level 30
public Icon getCustomIcon ()

Optional icon to be shown with the Control. It is highly recommended to let the system default the icon unless the default icon is not suitable.

Returns
Icon icon to show This value may be null.

getDeviceType

Added in API level 30
public int getDeviceType ()

Returns
int type of device represented by this Control, used to determine the default icon and color Value is DeviceTypes.TYPE_GENERIC_ON_OFF, DeviceTypes.TYPE_GENERIC_START_STOP, DeviceTypes.TYPE_GENERIC_OPEN_CLOSE, DeviceTypes.TYPE_GENERIC_LOCK_UNLOCK, DeviceTypes.TYPE_GENERIC_ARM_DISARM, DeviceTypes.TYPE_GENERIC_TEMP_SETTING, DeviceTypes.TYPE_GENERIC_VIEWSTREAM, DeviceTypes.TYPE_UNKNOWN, DeviceTypes.TYPE_AC_HEATER, DeviceTypes.TYPE_AC_UNIT, DeviceTypes.TYPE_AIR_FRESHENER, DeviceTypes.TYPE_AIR_PURIFIER, DeviceTypes.TYPE_COFFEE_MAKER, DeviceTypes.TYPE_DEHUMIDIFIER, DeviceTypes.TYPE_DISPLAY, DeviceTypes.TYPE_FAN, DeviceTypes.TYPE_HOOD, DeviceTypes.TYPE_HUMIDIFIER, DeviceTypes.TYPE_KETTLE, DeviceTypes.TYPE_LIGHT, DeviceTypes.TYPE_MICROWAVE, DeviceTypes.TYPE_OUTLET, DeviceTypes.TYPE_RADIATOR, DeviceTypes.TYPE_REMOTE_CONTROL, DeviceTypes.TYPE_SET_TOP, DeviceTypes.TYPE_STANDMIXER, DeviceTypes.TYPE_STYLER, DeviceTypes.TYPE_SWITCH, DeviceTypes.TYPE_TV, DeviceTypes.TYPE_WATER_HEATER, DeviceTypes.TYPE_DISHWASHER, DeviceTypes.TYPE_DRYER, DeviceTypes.TYPE_MOP, DeviceTypes.TYPE_MOWER, DeviceTypes.TYPE_MULTICOOKER, DeviceTypes.TYPE_SHOWER, DeviceTypes.TYPE_SPRINKLER, DeviceTypes.TYPE_WASHER, DeviceTypes.TYPE_VACUUM, DeviceTypes.TYPE_AWNING, DeviceTypes.TYPE_BLINDS, DeviceTypes.TYPE_CLOSET, DeviceTypes.TYPE_CURTAIN, DeviceTypes.TYPE_DOOR, DeviceTypes.TYPE_DRAWER, DeviceTypes.TYPE_GARAGE, DeviceTypes.TYPE_GATE, DeviceTypes.TYPE_PERGOLA, DeviceTypes.TYPE_SHUTTER, DeviceTypes.TYPE_WINDOW, DeviceTypes.TYPE_VALVE, DeviceTypes.TYPE_LOCK, DeviceTypes.TYPE_SECURITY_SYSTEM, DeviceTypes.TYPE_HEATER, DeviceTypes.TYPE_REFRIGERATOR, DeviceTypes.TYPE_THERMOSTAT, DeviceTypes.TYPE_CAMERA, DeviceTypes.TYPE_DOORBELL, or DeviceTypes.TYPE_ROUTINE

getStatus

Added in API level 30
public int getStatus ()

Returns
int status of the Control, used to convey information about the attempt to fetch the current state Value is STATUS_UNKNOWN, STATUS_OK, STATUS_NOT_FOUND, STATUS_ERROR, or STATUS_DISABLED

getStatusText

Added in API level 30
public CharSequence getStatusText ()

Returns
CharSequence user-facing text description of the Control's status, describing its current state This value cannot be null.

getStructure

Added in API level 30
public CharSequence getStructure ()

Optional top-level group to help define the Control's location, visible to the user. If not present, the application name will be used as the top-level group. A structure contains zones which contains controls.

Returns
CharSequence name of the structure containing the control This value may be null.

getSubtitle

Added in API level 30
public CharSequence getSubtitle ()

Returns
CharSequence additional information about the Control, to appear underneath the title This value cannot be null.

getTitle

Added in API level 30
public CharSequence getTitle ()

Returns
CharSequence the user facing name of the Control This value cannot be null.

getZone

Added in API level 30
public CharSequence getZone ()

Optional group name to help define the Control's location within a structure, visible to the user. A structure contains zones which contains controls.

Returns
CharSequence name of the zone containing the control This value may be null.

isAuthRequired

Added in API level 33
public boolean isAuthRequired ()

Returns
boolean true if the control can not be interacted with until the device is unlocked

writeToParcel

Added in API level 30
public void writeToParcel (Parcel dest, 
                int flags)

Flatten this object in to a Parcel.

Parameters
dest Parcel: This value cannot be null.

flags int: Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES