ComplicationDataSourceService


public abstract class ComplicationDataSourceService extends Service


Class for sources of complication data.

A complication data source service must implement onComplicationRequest to respond to requests for updates from the complication system.

Manifest requirements:

  • The manifest declaration of this service must include an intent filter for android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST.

  • A ComplicationDataSourceService must include a meta-data tag with android.support.wearable.complications.SUPPORTED_TYPES in its manifest entry.

The value of android.support.wearable.complications.SUPPORTED_TYPES should be a comma separated list of types supported by the data source, from this table:

Androidx class Tag name
GoalProgressComplicationData GOAL_PROGRESS
LongTextComplicationData LONG_TEXT
MonochromaticImageComplicationData ICON
PhotoImageComplicationData LARGE_IMAGE
RangedValueComplicationData RANGED_TEXT
ShortTextComplicationData SHORT_TEXT
SmallImageComplicationData SMALL_IMAGE
WeightedElementsComplicationData WEIGHTED_ELEMENTS

The order in which types are listed has no significance. In the case where a watch face supports multiple types in a single complication slot, the watch face will determine which types it prefers.

For example, a complication data source that supports the RANGED_VALUE, SHORT_TEXT, and ICON types would include the following in its manifest entry:

<meta-data
android:name="android.support.wearable.complications.SUPPORTED_TYPES"
android:value="RANGED_VALUE,SHORT_TEXT,ICON" />

From android T onwards, it is recommended for ComplicationDataSourceServices to be direct boot aware because the system is able to fetch complications before the lock screen has been removed. To do this add android:directBootAware="true" to your service tag.

  • A provider can choose to trust one or more watch faces by including the following in its manifest entry:

<meta-data
android:name="android.support.wearable.complications.SAFE_WATCH_FACES"
android:value="com.pkg1/com.trusted.wf1,com.pkg2/com.trusted.wf2" />

The listed watch faces will not need com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA in order to receive complications from this provider. Also the provider may choose to serve different types to safe watch faces by including the following in its manifest:

<meta-data
android:name="androidx.wear.watchface.complications.datasource.SAFE_WATCH_FACE_SUPPORTED_TYPES"
android:value="ICON" />

In addition the provider can learn if a request is for a safe watchface by examining ComplicationRequest.isForSafeWatchFace. Note SAFE_WATCH_FACE_SUPPORTED_TYPES and isForSafeWatchFace are gated behind the privileged permission com.google.wear.permission.GET_IS_FOR_SAFE_WATCH_FACE.

  • A ComplicationDataSourceService should include a meta-data tag with android.support.wearable.complications.UPDATE_PERIOD_SECONDS in its manifest entry. The value of this tag is the number of seconds the complication data source would like to elapse between update requests.

Note that update requests are not guaranteed to be sent with this frequency. For complications with frequent updates they can also register a separate meta-data tag with androidx.wear.watchface.complications.data.source.IMMEDIATE_UPDATE_PERIOD_MILLISECONDS in their manifest which supports sampling at up to 1Hz when the watch face is visible and non-ambient, however this also requires the application to have the privileged permission com.google.android.wearable.permission.USE_IMMEDIATE_COMPLICATION_UPDATE.

If a complication data source never needs to receive update requests beyond the one sent when a complication is activated, the value of this tag should be 0.

For example, a complication data source that would like to update at most every hour should include the following in its manifest entry:

<meta-data
android:name="android.support.wearable.complications.UPDATE_PERIOD_SECONDS"
android:value="3600" />
  • A ComplicationDataSourceService can include a meta-data tag with android.support.wearable.complications.PROVIDER_CONFIG_ACTION its manifest entry to cause a configuration activity to be shown when the complication data source is selected.

The configuration activity must reside in the same package as the complication data source, and must register an intent filter for the action specified here, including android.support.wearable.complications.category.PROVIDER_CONFIG as well as Intent.CATEGORY_DEFAULT as categories.

Note back up and restore of any configuration data is left to the complication data source, see METADATA_KEY_CONFIG_RESTORE_SUPPORTED for more details.

The complication id being configured will be included in the intent that starts the config activity using the extra key android.support.wearable.complications.EXTRA_CONFIG_COMPLICATION_ID.

The complication type that will be requested from the complication data source will also be included, using the extra key android.support.wearable.complications.EXTRA_CONFIG_COMPLICATION_TYPE.

The complication data source's ComponentName will also be included in the intent that starts the config activity, using the extra key android.support.wearable.complications.EXTRA_CONFIG_PROVIDER_COMPONENT.

The config activity must call Activity.setResult with either Activity.RESULT_OK or Activity.RESULT_CANCELED before it is finished, to tell the system whether or not the complication data source should be set on the given complication.

It is possible to provide additional meta-data tag androidx.watchface.complications.datasource.DEFAULT_CONFIG_SUPPORTED in the service set to "true" to let the system know that the data source is able to provide complication data before it is configured.

  • The manifest entry for the service should also include an android:icon attribute. The icon provided there should be a single-color white icon that represents the complication data source. This icon will be shown in the complication data source chooser interface, and may also be included in ComplicationProviderInfo given to watch faces for display in their configuration activities.

  • The manifest entry should also include android:permission="com.google.android.wearable.permission.BIND_COMPLICATION_PROVIDER" to ensure that only the system can bind to it.

Multiple complication data sources in the same APK are supported but in android R there's a soft limit of 100 data sources per APK. Above that the companion watchface editor won't support this complication data source app.

There's no need to call setDataSource for any the ComplicationData Builders because the system will append this value on your behalf.

Summary

Nested types

Callback for onComplicationRequest where only one of onComplicationData or onComplicationDataTimeline should be called.

Constants

static final @NonNull String

The intent action used to send update requests to the data source.

static final @NonNull String

Category for complication data source config activities.

static final @NonNull String

Extra used to supply the complication id to a complication data source configuration activity.

static final @NonNull String

Extra used to supply the complication type to a complication data source configuration activity.

static final @NonNull String

Extra used to supply the complication data source component to a complication data source configuration activity.

static final @NonNull String

Metadata key used to declare that the complication data source service supports backup and restore (B&R) of complication configuration data.

static final @NonNull String

Metadata key used to declare an action for a configuration activity for a complication data source.

static final @NonNull String

Metadata key.

static final @NonNull String

Metadata key used to request elevated frequency of onComplicationRequests when the watch face is visible and non-ambient.

static final @NonNull String

Metadata key used to declare a list of watch faces that may receive data from a complication data source before they are granted the RECEIVE_COMPLICATION_DATA permission.

static final @NonNull String

Metadata key used to declare supported complication types for safe watch faces.

static final @NonNull String

Metadata key used to declare supported complication types.

static final @NonNull String

Metadata key used to declare the requested frequency of update requests.

Public constructors

Public methods

abstract ComplicationData

A request for representative preview data for the complication, for use in the editor UI.

final IBinder
void
@MainThread
onComplicationActivated(
    int complicationInstanceId,
    @NonNull ComplicationType type
)

Called when a complication is activated.

void
@MainThread
onComplicationDeactivated(int complicationInstanceId)

Called when a complication is deactivated.

abstract void

Called when a complication data update is requested for the given complication id.

void

If a metadata key with METADATA_KEY_IMMEDIATE_UPDATE_PERIOD_MILLISECONDS is present in the manifest, and the provider has privileged permission com.google.android.wearable.permission.USE_IMMEDIATE_COMPLICATION_UPDATE, then onStartImmediateComplicationRequests will be called when the watch face is visible and non-ambient.

void
@MainThread
onStopImmediateComplicationRequests(int complicationInstanceId)

If a metadata key with METADATA_KEY_IMMEDIATE_UPDATE_PERIOD_MILLISECONDS is present in the manifest, and the provider has privileged permission com.google.android.wearable.permission.USE_IMMEDIATE_COMPLICATION_UPDATE, then onStartImmediateComplicationRequests will be called when the watch face ceases to be visible and non-ambient.

Inherited methods

From android.content.ComponentCallbacks
From android.content.ComponentCallbacks2
void
onTrimMemory(int level)
From android.content.Context
boolean
bindIsolatedService(
    @NonNull Intent service,
    @NonNull Context.BindServiceFlags flags,
    @NonNull String instanceName,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
boolean
bindIsolatedService(
    @NonNull Intent service,
    int flags,
    @NonNull String instanceName,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
boolean
bindService(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    @NonNull Context.BindServiceFlags flags
)
boolean
bindService(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    int flags
)
boolean
bindService(
    @NonNull Intent service,
    @NonNull Context.BindServiceFlags flags,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
boolean
bindService(
    @NonNull Intent service,
    int flags,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
boolean
bindServiceAsUser(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    @NonNull Context.BindServiceFlags flags,
    @NonNull UserHandle user
)
boolean
bindServiceAsUser(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    int flags,
    @NonNull UserHandle user
)
int
int
@NonNull int[]
checkCallingOrSelfUriPermissions(
    @NonNull List<@NonNull Uri> uris,
    int modeFlags
)
int
int
checkCallingUriPermission(@NonNull Uri uri, int modeFlags)
@NonNull int[]
int
checkContentUriPermissionFull(
    @NonNull Uri uri,
    int pid,
    int uid,
    int modeFlags
)
int
checkPermission(@NonNull String permission, int pid, int uid)
int
int
checkUriPermission(@NonNull Uri uri, int pid, int uid, int modeFlags)
int
checkUriPermission(
    @Nullable Uri uri,
    @Nullable String readPermission,
    @Nullable String writePermission,
    int pid,
    int uid,
    int modeFlags
)
@NonNull int[]
checkUriPermissions(
    @NonNull List<@NonNull Uri> uris,
    int pid,
    int uid,
    int modeFlags
)
void

This method is deprecated. Deprecated in Java

@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
createDeviceContext(int deviceId)
@NonNull Context
@NonNull Context
@NonNull Context
createPackageContext(@NonNull String packageName, int flags)
@NonNull Context
createWindowContext(int type, @Nullable Bundle options)
@NonNull Context
createWindowContext(
    @NonNull Display display,
    int type,
    @Nullable Bundle options
)
@NonNull String[]
boolean
boolean
boolean
void
enforceCallingOrSelfPermission(
    @NonNull String permission,
    @Nullable String message
)
void
enforceCallingOrSelfUriPermission(
    @NonNull Uri uri,
    int modeFlags,
    @NonNull String message
)
void
enforceCallingPermission(
    @NonNull String permission,
    @Nullable String message
)
void
enforceCallingUriPermission(
    @NonNull Uri uri,
    int modeFlags,
    @NonNull String message
)
void
enforcePermission(
    @NonNull String permission,
    int pid,
    int uid,
    @Nullable String message
)
void
enforceUriPermission(
    @NonNull Uri uri,
    int pid,
    int uid,
    int modeFlags,
    @NonNull String message
)
void
enforceUriPermission(
    @Nullable Uri uri,
    @Nullable String readPermission,
    @Nullable String writePermission,
    int pid,
    int uid,
    int modeFlags,
    @Nullable String message
)
@NonNull String[]
final int
getColor(int id)
final @NonNull ColorStateList
@NonNull File
@NonNull File
getDir(@NonNull String name, int mode)
final @Nullable Drawable
getDrawable(int id)
@Nullable File
@NonNull File[]
@NonNull File
@NonNull SharedPreferences
getSharedPreferences(@NonNull String name, int mode)
final @NonNull String
getString(int resId)
final @NonNull String
getString(int resId, @NonNull Object... formatArgs)
@NonNull Object
final @NonNull T
<T extends Object> getSystemService(@NonNull Class<@NonNull T> serviceClass)
String
final @NonNull CharSequence
getText(int resId)
void
grantUriPermission(
    @NonNull String toPackage,
    @NonNull Uri uri,
    int modeFlags
)
boolean
moveDatabaseFrom(@NonNull Context sourceContext, @NonNull String name)
boolean
moveSharedPreferencesFrom(
    @NonNull Context sourceContext,
    @NonNull String name
)
final @NonNull TypedArray
final @NonNull TypedArray
obtainStyledAttributes(int resid, @NonNull int[] attrs)
final @NonNull TypedArray
final @NonNull TypedArray
obtainStyledAttributes(
    @Nullable AttributeSet set,
    @NonNull int[] attrs,
    int defStyleAttr,
    int defStyleRes
)
@NonNull FileInputStream
@NonNull FileOutputStream
openFileOutput(@NonNull String name, int mode)
@NonNull SQLiteDatabase
openOrCreateDatabase(
    @NonNull String name,
    int mode,
    @NonNull SQLiteDatabase.CursorFactory factory
)
@NonNull SQLiteDatabase
openOrCreateDatabase(
    @NonNull String name,
    int mode,
    @NonNull SQLiteDatabase.CursorFactory factory,
    @Nullable DatabaseErrorHandler errorHandler
)
@NonNull Drawable

This method is deprecated. Deprecated in Java

void
void
registerDeviceIdChangeListener(
    @NonNull Executor executor,
    @NonNull IntConsumer listener
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver receiver,
    @NonNull IntentFilter filter
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver receiver,
    @NonNull IntentFilter filter,
    int flags
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver receiver,
    @NonNull IntentFilter filter,
    @Nullable String broadcastPermission,
    @Nullable Handler scheduler
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver receiver,
    @NonNull IntentFilter filter,
    @Nullable String broadcastPermission,
    @Nullable Handler scheduler,
    int flags
)
void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
void
void
revokeUriPermission(@NonNull Uri uri, int modeFlags)
void
revokeUriPermission(
    @NonNull String targetPackage,
    @NonNull Uri uri,
    int modeFlags
)
void
void
sendBroadcast(@NonNull Intent intent, @Nullable String receiverPermission)
void
sendBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission,
    @Nullable Bundle options
)
void
void
sendBroadcastAsUser(
    @NonNull Intent intent,
    @NonNull UserHandle user,
    String receiverPermission
)
void
sendBroadcastWithMultiplePermissions(
    @NonNull Intent intent,
    @NonNull String[] receiverPermissions
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission,
    @Nullable Bundle options
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission,
    @Nullable Bundle options,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission,
    @Nullable String receiverAppOp,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)
void
sendOrderedBroadcastAsUser(
    @NonNull Intent intent,
    @NonNull UserHandle user,
    @Nullable String receiverPermission,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)
void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
sendStickyOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)

This method is deprecated. Deprecated in Java

void
sendStickyOrderedBroadcastAsUser(
    @NonNull Intent intent,
    @NonNull UserHandle user,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)

This method is deprecated. Deprecated in Java

void
setTheme(int resid)
void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
startActivities(@NonNull Intent[] intents)
void
startActivities(@NonNull Intent[] intents, @Nullable Bundle options)
void
void
@Nullable ComponentName
boolean
startInstrumentation(
    @NonNull ComponentName className,
    @Nullable String profileFile,
    @Nullable Bundle arguments
)
void
startIntentSender(
    @NonNull IntentSender intent,
    @Nullable Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags
)
void
startIntentSender(
    @NonNull IntentSender intent,
    @Nullable Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags,
    @Nullable Bundle options
)
@Nullable ComponentName
boolean
void
void
void
void
void
updateServiceGroup(
    @NonNull ServiceConnection conn,
    int group,
    int importance
)
From android.content.ContextWrapper
void
@NonNull Context
@NonNull ApplicationInfo
@NonNull AssetManager
@NonNull AttributionSource
@Nullable String
@NonNull Context
@NonNull File
@NonNull ClassLoader
@NonNull File
@NonNull ContentResolver
@NonNull File
int
@Nullable Display
@Nullable File
@NonNull File[]
@NonNull File[]
@NonNull File
@NonNull Executor
@NonNull Looper
@NonNull File
@NonNull File
@NonNull File[]
@NonNull String
@NonNull String
@NonNull PackageManager
@NonNull String
@NonNull String
@Nullable ContextParams
@NonNull Resources
@NonNull Resources.Theme
@NonNull Drawable

This method is deprecated. Deprecated in Java

int

This method is deprecated. Deprecated in Java

int

This method is deprecated. Deprecated in Java

boolean
boolean
boolean
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    int initialCode,
    @Nullable String receiverPermission,
    @Nullable String receiverAppOp,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    @Nullable String initialData,
    @Nullable Bundle initialExtras,
    @Nullable Bundle options
)
From android.app.Service
void
dump(
    @NonNull FileDescriptor fd,
    @NonNull PrintWriter writer,
    @NonNull String[] args
)
final @NonNull Application
final int
void
void
void
void
onStart(@NonNull Intent intent, int startId)

This method is deprecated. Deprecated in Java

int
onStartCommand(@NonNull Intent intent, int flags, int startId)
void
void
onTimeout(int startId)
void
onTimeout(int startId, int fgsType)
boolean
final void
startForeground(int id, @NonNull Notification notification)
final void
startForeground(
    int id,
    @NonNull Notification notification,
    int foregroundServiceType
)
final void
stopForeground(int notificationBehavior)
final void
stopForeground(boolean removeNotification)

This method is deprecated. Deprecated in Java

final void
final void
stopSelf(int startId)
final boolean
stopSelfResult(int startId)

Constants

ACTION_COMPLICATION_UPDATE_REQUEST

public static final @NonNull String ACTION_COMPLICATION_UPDATE_REQUEST

The intent action used to send update requests to the data source. ComplicationDataSourceService must declare an intent filter for this action in the manifest.

CATEGORY_DATA_SOURCE_CONFIG

public static final @NonNull String CATEGORY_DATA_SOURCE_CONFIG

Category for complication data source config activities. The configuration activity for a complication complication data source must specify this category in its intent filter.

EXTRA_CONFIG_COMPLICATION_ID

public static final @NonNull String EXTRA_CONFIG_COMPLICATION_ID

Extra used to supply the complication id to a complication data source configuration activity.

EXTRA_CONFIG_COMPLICATION_TYPE

public static final @NonNull String EXTRA_CONFIG_COMPLICATION_TYPE

Extra used to supply the complication type to a complication data source configuration activity.

EXTRA_CONFIG_DATA_SOURCE_COMPONENT

public static final @NonNull String EXTRA_CONFIG_DATA_SOURCE_COMPONENT

Extra used to supply the complication data source component to a complication data source configuration activity.

METADATA_KEY_CONFIG_RESTORE_SUPPORTED

@RequiresApi(value = 34)
public static final @NonNull String METADATA_KEY_CONFIG_RESTORE_SUPPORTED

Metadata key used to declare that the complication data source service supports backup and restore (B&R) of complication configuration data. The system is responsible for backup and restore of the assignment of complications to watch faces, but responsibility for backup and restore for any complication data source configuration data is left to the data source.

If this flag is set to false, then the system will restore any complications using this provider in the "not configured" state, i.e. the complication will show a + sign with a tap action leading to the complication data source's configuration action as defined by METADATA_KEY_DATA_SOURCE_CONFIG_ACTION, instead of real data.

This is a boolean value, defaulting to true, which means apps are opted in by default but can explicitly opt out by setting this meta-data tag to false.

The value is ignored (equivalent to false) if the app does not enable Android B&R ( https://developer.android.com/guide/topics/data/backup). This value is also ignored prior to Android U.

METADATA_KEY_DATA_SOURCE_CONFIG_ACTION

public static final @NonNull String METADATA_KEY_DATA_SOURCE_CONFIG_ACTION

Metadata key used to declare an action for a configuration activity for a complication data source.

A ComplicationDataSourceService can include a meta-data tag with this name in its manifest entry to cause a configuration activity to be shown when the complication data source is selected.

The configuration activity must reside in the same package as the complication data source, and must register an intent filter for the action specified here, including CATEGORY_DATA_SOURCE_CONFIG as well as Intent.CATEGORY_DEFAULT as categories.

The complication id being configured will be included in the intent that starts the config activity using the extra key EXTRA_CONFIG_COMPLICATION_ID.

The complication type that will be requested from the complication data source will also be included, using the extra key EXTRA_CONFIG_COMPLICATION_TYPE.

The complication data source's ComponentName will also be included in the intent that starts the config activity, using the extra key EXTRA_CONFIG_DATA_SOURCE_COMPONENT.

The config activity must call Activity.setResult with either Activity.RESULT_OK or Activity.RESULT_CANCELED before it is finished, to tell the system whether or not the complication data source should be set on the given complication.

METADATA_KEY_DATA_SOURCE_DEFAULT_CONFIG_SUPPORTED

public static final @NonNull String METADATA_KEY_DATA_SOURCE_DEFAULT_CONFIG_SUPPORTED

Metadata key. Setting to "true" indicates to the system that this complication data source with a PROVIDER_CONFIG_ACTION metadata tag is able to provide complication data before it is configured. See METADATA_KEY_DATA_SOURCE_CONFIG_ACTION.

METADATA_KEY_IMMEDIATE_UPDATE_PERIOD_MILLISECONDS

public static final @NonNull String METADATA_KEY_IMMEDIATE_UPDATE_PERIOD_MILLISECONDS

Metadata key used to request elevated frequency of onComplicationRequests when the watch face is visible and non-ambient.

To do this ComplicationDataSourceService should include a meta-data tag with this name in its manifest entry. The value of this tag is the number of milliseconds the complication data source would like to elapse between onComplicationRequests requests when the watch face is visible and non-ambient.

Note in addition to this meta-data, the data source must also request the privileged permission com.google.android.wearable.permission.USE_IMMEDIATE_COMPLICATION_UPDATE.

Note that update requests are not guaranteed to be sent with this frequency and a lower limit exists (initially 1 second).

METADATA_KEY_SAFE_WATCH_FACES

public static final @NonNull String METADATA_KEY_SAFE_WATCH_FACES

Metadata key used to declare a list of watch faces that may receive data from a complication data source before they are granted the RECEIVE_COMPLICATION_DATA permission. This allows the listed watch faces to set the complication data source as a default and have the complication populate when the watch face is first seen.

Only trusted watch faces that will set this complication data source as a default should be included in this list.

Note that if a watch face is in the same app package as the complication data source, it does not need to be added to this list.

The value of this tag should be a comma separated list of watch faces or packages. An entry can be a flattened component, as if ComponentName.flattenToString had been called, to declare a specific watch face as safe. An entry can also be a package name, as if ComponentName.getPackageName had been called, in which case any watch face under the app with that package name will be considered safe for this complication data source.

From Android T, if this provider has the privileged permission com.google.wear.permission.GET_IS_FOR_SAFE_WATCH_FACE, then ComplicationRequest.isForSafeWatchFace will be populated.

METADATA_KEY_SAFE_WATCH_FACE_SUPPORTED_TYPES

public static final @NonNull String METADATA_KEY_SAFE_WATCH_FACE_SUPPORTED_TYPES

Metadata key used to declare supported complication types for safe watch faces.

Gated behind the privileged permission `com.google.wear.permission.GET_IS_FOR_SAFE_WATCH_FACE', this overrides the METADATA_KEY_SUPPORTED_TYPES list for 'safe' watch faces. I.e. watch faces in the METADATA_KEY_SAFE_WATCH_FACES metadata list.

This means for example trusted watch faces could receive ComplicationType.SHORT_TEXT and untrusted ones ComplicationType.MONOCHROMATIC_IMAGE.

METADATA_KEY_SUPPORTED_TYPES

public static final @NonNull String METADATA_KEY_SUPPORTED_TYPES

Metadata key used to declare supported complication types.

A ComplicationDataSourceService must include a meta-data tag with this name in its manifest entry. The value of this tag should be a comma separated list of types supported by the complication data source. Types should be given as named as per the type fields in the ComplicationData, but omitting the "TYPE_" prefix, e.g. SHORT_TEXT, LONG_TEXT, RANGED_VALUE.

The order of types in METADATA_KEY_SUPPORTED_TYPES has no significance. During complication data source selection, each item in the complication slot's supported types is checked against entries in the data source's METADATA_KEY_SUPPORTED_TYPES and the first matching entry from the slot's support types (if any) is chosen. If there are no matches then this data source is not eligible to be selected in that slot.

For example, a complication data source that supports the RANGED_VALUE, SHORT_TEXT, and ICON type would include the following in its manifest entry:

<meta-data
android:name="android.support.wearable.complications.SUPPORTED_TYPES"
android:value="RANGED_VALUE,SHORT_TEXT,ICON" />

METADATA_KEY_UPDATE_PERIOD_SECONDS

public static final @NonNull String METADATA_KEY_UPDATE_PERIOD_SECONDS

Metadata key used to declare the requested frequency of update requests.

A ComplicationDataSourceService should include a meta-data tag with this name in its manifest entry. The value of this tag is the number of seconds the complication data source would like to elapse between update requests.

Note that update requests are not guaranteed to be sent with this frequency.

If a complication data source never needs to receive update requests beyond the one sent when a complication is activated, the value of this tag should be 0.

For example, a complication data source that would like to update every ten minutes should include the following in its manifest entry:

<meta-data
android:name="android.support.wearable.complications.UPDATE_PERIOD_SECONDS"
android:value="600" />

Public constructors

ComplicationDataSourceService

Added in 1.0.0
public ComplicationDataSourceService()

Public methods

getPreviewData

Added in 1.0.0
public abstract ComplicationData getPreviewData(@NonNull ComplicationType type)

A request for representative preview data for the complication, for use in the editor UI. Preview data is assumed to be static per type. E.g. for a complication that displays the date and time of an event, rather than returning the real time it should return a fixed date and time such as 10:10 Aug 1st. This data may be cached by the system and the result should be constant based on the current locale.

This will be called on a background thread.

Parameters
@NonNull ComplicationType type

The type of complication preview data requested.

Returns
ComplicationData

Preview data for the given complication type.

onBind

Added in 1.0.0
public final IBinder onBind(@NonNull Intent intent)

onComplicationActivated

Added in 1.0.0
@MainThread
public void onComplicationActivated(
    int complicationInstanceId,
    @NonNull ComplicationType type
)

Called when a complication is activated.

This occurs when the watch face calls setActiveComplications, or when this data source is chosen for a complication which is already active.

This will usually be followed by a call to onComplicationRequest.

This will be called on the main thread.

Parameters
int complicationInstanceId

The system's ID for the complication. Note this ID is distinct from the complication slot used by the watch face itself.

@NonNull ComplicationType type

The ComplicationType of the activated slot.

onComplicationDeactivated

Added in 1.0.0
@MainThread
public void onComplicationDeactivated(int complicationInstanceId)

Called when a complication is deactivated.

This occurs when the current watch face changes, or when the watch face calls setActiveComplications and does not include the given complication (usually because the watch face has stopped displaying it).

This will be called on the main thread.

Parameters
int complicationInstanceId

The system's ID for the complication. Note this ID is distinct from the complication slot used by the watch face itself.

onComplicationRequest

Added in 1.0.0
@MainThread
public abstract void onComplicationRequest(
    @NonNull ComplicationRequest request,
    @NonNull ComplicationDataSourceService.ComplicationRequestListener listener
)

Called when a complication data update is requested for the given complication id.

In response to this request the result callback should be called with the data to be displayed. If the request can not be fulfilled or no update is needed then null should be passed to the callback.

The callback doesn't have be called within onComplicationRequest but it should be called soon after. If this does not occur within around 20 seconds (exact timeout length subject to change), then the system will unbind from this service which may cause your eventual update to not be received. However if ComplicationRequest.immediateResponseRequired is true then provider should try to deliver the response in under 100 milliseconds, if false the deadline is 20 seconds. ComplicationRequest.immediateResponseRequired will only ever be true if METADATA_KEY_IMMEDIATE_UPDATE_PERIOD_MILLISECONDS is present in the manifest, and the provider has the privileged permission com.google.android.wearable.permission.USE_IMMEDIATE_COMPLICATION_UPDATE, and the complication is visible and non-ambient.

Parameters
@NonNull ComplicationRequest request

The details about the complication that has been requested.

@NonNull ComplicationDataSourceService.ComplicationRequestListener listener

The callback to pass the result to the system.

onStartImmediateComplicationRequests

Added in 1.1.0
@MainThread
public void onStartImmediateComplicationRequests(int complicationInstanceId)

If a metadata key with METADATA_KEY_IMMEDIATE_UPDATE_PERIOD_MILLISECONDS is present in the manifest, and the provider has privileged permission com.google.android.wearable.permission.USE_IMMEDIATE_COMPLICATION_UPDATE, then onStartImmediateComplicationRequests will be called when the watch face is visible and non-ambient. A series of onComplicationRequests will follow where ComplicationRequest.immediateResponseRequired is true, ending with a call to onStopImmediateComplicationRequests.

Parameters
int complicationInstanceId

The system's ID for the complication. Note this ID is distinct from the complication slot used by the watch face itself.

onStopImmediateComplicationRequests

Added in 1.1.0
@MainThread
public void onStopImmediateComplicationRequests(int complicationInstanceId)

If a metadata key with METADATA_KEY_IMMEDIATE_UPDATE_PERIOD_MILLISECONDS is present in the manifest, and the provider has privileged permission com.google.android.wearable.permission.USE_IMMEDIATE_COMPLICATION_UPDATE, then onStartImmediateComplicationRequests will be called when the watch face ceases to be visible and non-ambient. No subsequent calls to onComplicationRequest where ComplicationRequest.immediateResponseRequired is true will be made unless the complication becomes visible and non-ambient again.

Parameters
int complicationInstanceId

The system's ID for the complication. Note this ID is distinct from the complication slot used by the watch face itself.