StatefulWatchFaceRuntimeService


abstract class StatefulWatchFaceRuntimeService<Extra : Any?> : WatchFaceService


WatchFaceRuntimeService is required to be stateless as multiple can be created in parallel. StatefulWatchFaceRuntimeService allows for metadata to be associated with watch faces on a per instance basis. This state is created by createExtra and is passed into other methods.

Note because a WatchFaceRuntimeService loads it's resources from another package, it will need the following permission:

    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />

Currently Wear OS only supports the runtime for the Android Watch Face Format (see https://developer.android.com/training/wearables/wff for more details).

Note only one watch face definition per resource only watch face package is supported.

Summary

Public constructors

Protected functions

final ComplicationSlotsManager
createComplicationSlotsManager(
    currentUserStyleRepository: CurrentUserStyleRepository
)

If the WatchFaceService's manifest doesn't define a androidx.wear.watchface.XmlSchemaAndComplicationSlotsDefinition meta data tag then override this factory method to create a non-empty ComplicationSlotsManager.

abstract ComplicationSlotsManager
@WorkerThread
createComplicationSlotsManager(
    currentUserStyleRepository: CurrentUserStyleRepository,
    resourceOnlyWatchFacePackageName: String,
    extra: Extra
)

If the WatchFaceService's manifest doesn't define a androidx.wear.watchface.XmlSchemaAndComplicationSlotsDefinition meta data tag then override this factory method to create a non-empty ComplicationSlotsManager.

abstract Extra

Constructs the user defined Extra object which is passed as a parameter to the other methods.

final UserStyleFlavors
createUserStyleFlavors(
    currentUserStyleRepository: CurrentUserStyleRepository,
    complicationSlotsManager: ComplicationSlotsManager
)

If the WatchFaceService's manifest doesn't define a androidx.wear.watchface.XmlSchemaAndComplicationSlotsDefinition meta data tag then override this factory method to create non-empty UserStyleFlavors.

abstract UserStyleFlavors
@WorkerThread
createUserStyleFlavors(
    currentUserStyleRepository: CurrentUserStyleRepository,
    complicationSlotsManager: ComplicationSlotsManager,
    resourceOnlyWatchFacePackageName: String,
    extra: Extra
)

If the WatchFaceService's manifest doesn't define an androidx.wear.watchface.XmlSchemaAndComplicationSlotsDefinition meta data tag then override this factory method to create non-empty UserStyleFlavors.

final UserStyleSchema

If the WatchFaceService's manifest doesn't define an androidx.wear.watchface.XmlSchemaAndComplicationSlotsDefinition meta data tag then override this factory method to create a non-empty UserStyleSchema.

abstract UserStyleSchema
@WorkerThread
createUserStyleSchema(
    resourceOnlyWatchFacePackageName: String,
    extra: Extra
)

If the WatchFaceService's manifest doesn't define an androidx.wear.watchface.XmlSchemaAndComplicationSlotsDefinition meta data tag then override this factory method to create a non-empty UserStyleSchema.

final suspend WatchFace
createWatchFace(
    surfaceHolder: SurfaceHolder,
    watchState: WatchState,
    complicationSlotsManager: ComplicationSlotsManager,
    currentUserStyleRepository: CurrentUserStyleRepository
)

Override this factory method to create your WatchFaceImpl.

abstract suspend WatchFace
@WorkerThread
createWatchFace(
    surfaceHolder: SurfaceHolder,
    watchState: WatchState,
    complicationSlotsManager: ComplicationSlotsManager,
    currentUserStyleRepository: CurrentUserStyleRepository,
    resourceOnlyWatchFacePackageName: String,
    extra: Extra
)

Override this factory method to create your WatchFaceImpl.

Inherited functions

From android.content.Context
From android.content.ContextWrapper
open Boolean
bindIsolatedService(
    p0: Intent,
    p1: Int,
    p2: String,
    p3: Executor,
    p4: ServiceConnection
)
open Boolean
bindService(
    p0: Intent,
    p1: ServiceConnection,
    p2: Context.BindServiceFlags
)
open Boolean
open Boolean
bindService(
    p0: Intent,
    p1: Context.BindServiceFlags,
    p2: Executor,
    p3: ServiceConnection
)
open Boolean
bindService(p0: Intent, p1: Int, p2: Executor, p3: ServiceConnection)
open Boolean
bindServiceAsUser(
    p0: Intent,
    p1: ServiceConnection,
    p2: Context.BindServiceFlags,
    p3: UserHandle
)
open Boolean
open Int
open Int
open IntArray
open Int
open Int
open IntArray
open Int
checkPermission(p0: String, p1: Int, p2: Int)
open Int
open Int
checkUriPermission(p0: Uri, p1: Int, p2: Int, p3: Int)
open Int
checkUriPermission(p0: Uri?, p1: String?, p2: String?, p3: Int, p4: Int, p5: Int)
open IntArray
checkUriPermissions(p0: MutableList<Uri>, p1: Int, p2: Int, p3: Int)
open Unit

This function is deprecated. Deprecated in Java

open Context
open Context
open Context
open Context
open Context
open Context
open Context
open Context
open Context
open Context
createWindowContext(p0: Display, p1: Int, p2: Bundle?)
open Array<String>
open Boolean
open Boolean
open Boolean
open Unit
open Unit
open Unit
open Unit
open Unit
enforcePermission(p0: String, p1: Int, p2: Int, p3: String?)
open Unit
enforceUriPermission(p0: Uri, p1: Int, p2: Int, p3: Int, p4: String)
open Unit
enforceUriPermission(
    p0: Uri?,
    p1: String?,
    p2: String?,
    p3: Int,
    p4: Int,
    p5: Int,
    p6: String?
)
open Array<String>
open Context
open ApplicationInfo
open AssetManager
open AttributionSource
open String?
open Context
open File
open ClassLoader
open File
open ContentResolver
open File
open File
open Int
open File
getDir(p0: String, p1: Int)
open Display?
open File?
open Array<File>
open File?
open Array<File>
open Array<File>
open File
open File
open Executor
open Looper
open File
open File
open Array<File>
open String
open String
open PackageManager
open String
open String
open ContextParams?
open Resources
open SharedPreferences
open Any
open String?
open Resources.Theme
open Drawable

This function is deprecated. Deprecated in Java

open Int

This function is deprecated. Deprecated in Java

open Int

This function is deprecated. Deprecated in Java

open Unit
grantUriPermission(p0: String, p1: Uri, p2: Int)
open Boolean
open Boolean
open Boolean
open Boolean
open Boolean
open FileInputStream
open FileOutputStream
open SQLiteDatabase
open SQLiteDatabase
openOrCreateDatabase(
    p0: String,
    p1: Int,
    p2: SQLiteDatabase.CursorFactory,
    p3: DatabaseErrorHandler?
)
open Drawable

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Intent?
open Intent?
open Intent?
registerReceiver(
    p0: BroadcastReceiver?,
    p1: IntentFilter,
    p2: String?,
    p3: Handler?
)
open Intent?
registerReceiver(
    p0: BroadcastReceiver?,
    p1: IntentFilter,
    p2: String?,
    p3: Handler?,
    p4: Int
)
open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Unit
revokeUriPermission(p0: String, p1: Uri, p2: Int)
open Unit
open Unit
open Unit
sendBroadcast(p0: Intent, p1: String?, p2: Bundle?)
open Unit
open Unit
open Unit
open Unit
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: String?,
    p2: BroadcastReceiver?,
    p3: Handler?,
    p4: Int,
    p5: String?,
    p6: Bundle?
)
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: String?,
    p2: Bundle?,
    p3: BroadcastReceiver?,
    p4: Handler?,
    p5: Int,
    p6: String?,
    p7: Bundle?
)
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: String?,
    p2: String?,
    p3: BroadcastReceiver?,
    p4: Handler?,
    p5: Int,
    p6: String?,
    p7: Bundle?
)
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: Int,
    p2: String?,
    p3: String?,
    p4: BroadcastReceiver?,
    p5: Handler?,
    p6: String?,
    p7: Bundle?,
    p8: Bundle?
)
open Unit
sendOrderedBroadcastAsUser(
    p0: Intent,
    p1: UserHandle,
    p2: String?,
    p3: BroadcastReceiver?,
    p4: Handler?,
    p5: Int,
    p6: String?,
    p7: Bundle?
)
open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit
sendStickyOrderedBroadcast(
    p0: Intent,
    p1: BroadcastReceiver?,
    p2: Handler?,
    p3: Int,
    p4: String?,
    p5: Bundle?
)

This function is deprecated. Deprecated in Java

open Unit
sendStickyOrderedBroadcastAsUser(
    p0: Intent,
    p1: UserHandle,
    p2: BroadcastReceiver?,
    p3: Handler?,
    p4: Int,
    p5: String?,
    p6: Bundle?
)

This function is deprecated. Deprecated in Java

open Unit
open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Unit
open Unit
open ComponentName?
open Boolean
open Unit
startIntentSender(p0: IntentSender, p1: Intent?, p2: Int, p3: Int, p4: Int)
open Unit
startIntentSender(
    p0: IntentSender,
    p1: Intent?,
    p2: Int,
    p3: Int,
    p4: Int,
    p5: Bundle?
)
open ComponentName?
open Boolean
open Unit
open Unit
open Unit
open Unit
open Unit
From android.app.Service
open Unit
Application
Int
open Unit
open Unit
open Unit
onStart(p0: Intent, p1: Int)

This function is deprecated. Deprecated in Java

open Int
onStartCommand(p0: Intent, p1: Int, p2: Int)
open Unit
open Unit
open Unit
open Boolean
Unit
Unit
startForeground(p0: Int, p1: Notification, p2: Int)
Unit

This function is deprecated. Deprecated in Java

Unit
Unit
Unit
Boolean
From android.service.wallpaper.WallpaperService
final IBinder?
open Unit
open Unit
From androidx.wear.watchface.WatchFaceService
open Unit
@UiThread
dump(fd: FileDescriptor, writer: PrintWriter, args: Array<String>)
Handler

Returns the lazily constructed background thread Handler.

open ComplicationSlotInflationFactory?

This function is deprecated. Use the version with currentUserStyleRepository argument instead

open ComplicationSlotInflationFactory

Used when inflating ComplicationSlots from XML (i.e the manifest contains androidx.wear.watchface.XmlSchemaAndComplicationSlotsDefinition metadata) to provide a ComplicationSlotInflationFactory which provides the CanvasComplicationFactory and where necessary edge complication ComplicationTapFilters needed for inflating ComplicationSlots.

Handler

Returns the ui thread Handler.

open Unit
final WallpaperService.Engine

Creates an interactive engine for WallpaperService.

Public constructors

StatefulWatchFaceRuntimeService

<Extra : Any?> StatefulWatchFaceRuntimeService()

Protected functions

createComplicationSlotsManager

Added in 1.3.0-alpha04
protected final fun createComplicationSlotsManager(
    currentUserStyleRepository: CurrentUserStyleRepository
): ComplicationSlotsManager

If the WatchFaceService's manifest doesn't define a androidx.wear.watchface.XmlSchemaAndComplicationSlotsDefinition meta data tag then override this factory method to create a non-empty ComplicationSlotsManager. This manager will be passed to createUserStyleFlavors and createWatchFace. This will be called from a background thread but the ComplicationSlotsManager should be accessed exclusively from the UiThread afterwards.

Parameters
currentUserStyleRepository: CurrentUserStyleRepository

The CurrentUserStyleRepository constructed using the UserStyleSchema returned by createUserStyleSchema.

createComplicationSlotsManager

Added in 1.3.0-alpha04
@WorkerThread
protected abstract fun createComplicationSlotsManager(
    currentUserStyleRepository: CurrentUserStyleRepository,
    resourceOnlyWatchFacePackageName: String,
    extra: Extra
): ComplicationSlotsManager

If the WatchFaceService's manifest doesn't define a androidx.wear.watchface.XmlSchemaAndComplicationSlotsDefinition meta data tag then override this factory method to create a non-empty ComplicationSlotsManager. This manager will be passed to createUserStyleFlavors and createWatchFace. This will be called from a background thread but the ComplicationSlotsManager should be accessed exclusively from the UiThread afterwards.

Parameters
currentUserStyleRepository: CurrentUserStyleRepository

The CurrentUserStyleRepository constructed using the UserStyleSchema returned by createUserStyleSchema.

resourceOnlyWatchFacePackageName: String

The android package from which the watch face definition should be loaded.

extra: Extra

The object returned by createExtra.

createExtra

Added in 1.3.0-alpha04
protected abstract fun createExtra(): Extra

Constructs the user defined Extra object which is passed as a parameter to the other methods.

createUserStyleFlavors

Added in 1.3.0-alpha04
protected final fun createUserStyleFlavors(
    currentUserStyleRepository: CurrentUserStyleRepository,
    complicationSlotsManager: ComplicationSlotsManager
): UserStyleFlavors

If the WatchFaceService's manifest doesn't define a androidx.wear.watchface.XmlSchemaAndComplicationSlotsDefinition meta data tag then override this factory method to create non-empty UserStyleFlavors. This is called on a background thread. The system reads the flavors once and changes may be ignored until the APK is updated. Metadata tag "androidx.wear.watchface.FLAVORS_SUPPORTED" should be added to let the system know the service supports flavors.

Parameters
currentUserStyleRepository: CurrentUserStyleRepository

The CurrentUserStyleRepository constructed using the UserStyleSchema returned by createUserStyleSchema.

complicationSlotsManager: ComplicationSlotsManager

The ComplicationSlotsManager returned by createComplicationSlotsManager

Returns
UserStyleFlavors

The UserStyleFlavors, which is exposed to the system.

createUserStyleFlavors

Added in 1.3.0-alpha04
@WorkerThread
protected abstract fun createUserStyleFlavors(
    currentUserStyleRepository: CurrentUserStyleRepository,
    complicationSlotsManager: ComplicationSlotsManager,
    resourceOnlyWatchFacePackageName: String,
    extra: Extra
): UserStyleFlavors

If the WatchFaceService's manifest doesn't define an androidx.wear.watchface.XmlSchemaAndComplicationSlotsDefinition meta data tag then override this factory method to create non-empty UserStyleFlavors. This is called on a background thread. The system reads the flavors once and changes may be ignored until the APK is updated. Metadata tag "androidx.wear.watchface.FLAVORS_SUPPORTED" should be added to let the system know the service supports flavors.

Parameters
currentUserStyleRepository: CurrentUserStyleRepository

The CurrentUserStyleRepository constructed using the UserStyleSchema returned by createUserStyleSchema.

complicationSlotsManager: ComplicationSlotsManager

The ComplicationSlotsManager returned by createComplicationSlotsManager

resourceOnlyWatchFacePackageName: String

The android package from which the watch face definition should be loaded.

extra: Extra

The object returned by createExtra.

Returns
UserStyleFlavors

The UserStyleFlavors, which is exposed to the system.

createUserStyleSchema

Added in 1.3.0-alpha04
protected final fun createUserStyleSchema(): UserStyleSchema

If the WatchFaceService's manifest doesn't define an androidx.wear.watchface.XmlSchemaAndComplicationSlotsDefinition meta data tag then override this factory method to create a non-empty UserStyleSchema. A CurrentUserStyleRepository constructed with this schema will be passed to createComplicationSlotsManager, createUserStyleFlavors and createWatchFace. This is called on a background thread.

createUserStyleSchema

Added in 1.3.0-alpha04
@WorkerThread
protected abstract fun createUserStyleSchema(
    resourceOnlyWatchFacePackageName: String,
    extra: Extra
): UserStyleSchema

If the WatchFaceService's manifest doesn't define an androidx.wear.watchface.XmlSchemaAndComplicationSlotsDefinition meta data tag then override this factory method to create a non-empty UserStyleSchema. A CurrentUserStyleRepository constructed with this schema will be passed to createComplicationSlotsManager, createUserStyleFlavors and createWatchFace. This is called on a background thread.

Parameters
resourceOnlyWatchFacePackageName: String

The android package from which the watch face definition should be loaded.

extra: Extra

The object returned by createExtra.

createWatchFace

protected final suspend fun createWatchFace(
    surfaceHolder: SurfaceHolder,
    watchState: WatchState,
    complicationSlotsManager: ComplicationSlotsManager,
    currentUserStyleRepository: CurrentUserStyleRepository
): WatchFace

Override this factory method to create your WatchFaceImpl. This method will be called by the library on a background thread, if possible any expensive initialization should be done asynchronously. The WatchFace and its Renderer should be accessed exclusively from the UiThread afterwards. There is a memory barrier between construction and rendering so no special threading primitives are required.

Warning the system will likely time out waiting for watch face initialization if it takes longer than MAX_CREATE_WATCHFACE_TIME_MILLIS milliseconds.

Parameters
surfaceHolder: SurfaceHolder

The SurfaceHolder to pass to the Renderer's constructor.

watchState: WatchState

The WatchState for the watch face.

complicationSlotsManager: ComplicationSlotsManager

The ComplicationSlotsManager returned by createComplicationSlotsManager.

currentUserStyleRepository: CurrentUserStyleRepository

The CurrentUserStyleRepository constructed using the UserStyleSchema returned by createUserStyleSchema.

Returns
WatchFace

A WatchFace whose Renderer uses the provided surfaceHolder.

createWatchFace

@WorkerThread
protected abstract suspend fun createWatchFace(
    surfaceHolder: SurfaceHolder,
    watchState: WatchState,
    complicationSlotsManager: ComplicationSlotsManager,
    currentUserStyleRepository: CurrentUserStyleRepository,
    resourceOnlyWatchFacePackageName: String,
    extra: Extra
): WatchFace

Override this factory method to create your WatchFaceImpl. This method will be called by the library on a background thread, if possible any expensive initialization should be done asynchronously. The WatchFace and its Renderer should be accessed exclusively from the UiThread afterwards. There is a memory barrier between construction and rendering so no special threading primitives are required.

Warning the system will likely time out waiting for watch face initialization if it takes longer than WatchFaceService.MAX_CREATE_WATCHFACE_TIME_MILLIS milliseconds.

Parameters
surfaceHolder: SurfaceHolder

The SurfaceHolder to pass to the Renderer's constructor.

watchState: WatchState

The WatchState for the watch face.

complicationSlotsManager: ComplicationSlotsManager

The ComplicationSlotsManager returned by createComplicationSlotsManager.

currentUserStyleRepository: CurrentUserStyleRepository

The CurrentUserStyleRepository constructed using the UserStyleSchema returned by createUserStyleSchema.

resourceOnlyWatchFacePackageName: String

The android package from which the watch face definition should be loaded.

extra: Extra

The object returned by createExtra.

Returns
WatchFace

A WatchFace whose Renderer uses the provided surfaceHolder.