Services

The Wear Kernel implements the services of the Wear Services library. An application gets each service from KernelServiceProvider.

Kernel Services

Service

Role

ComponentService

Registers the activities, the watchfaces, and the complication data sources of the application. Returns the components of all the applications. Sets and returns the navigator.

DeviceService

Returns the battery level (in %), the charging state, the device name, and the Bluetooth address of the device (format 00:1A:7D:DA:71:13).

HealthService

Returns the steps and the calories (in kcal) of the current day, the heart rate (in bpm), the blood oxygen saturation (in %), and the duration of each sleep stage (awake, light, deep, REM, in minutes).

TimeService

Returns the current time (in milliseconds since the Java Epoch), the time zone ID, and the offset from UTC (in seconds, with daylight saving time). Notifies the registered TimeConfigurationListener instances when the date, the time, or the time zone changes.

FontService

Returns the system fonts as MicroVG vector fonts: regular, light, semi bold, bold italic, and monospace.

ResourceService

Returns the absolute resource path of an image of the application, from its path in the application.

ExternalResourceService

Creates, decodes, and deletes external resources (see External Resources).

External Resources

An external resource is a resource stored outside the application binary, for example on the file system. External resources are often created at build time, such as the fonts and the images stored on the file system. An application can also create external resources at runtime, with the ExternalResourceService. The path of an external resource starts with / and is relative to the directory of the application.

To create an external resource at runtime:

  1. Call createExternalResource() with the path and the size of the data. To store an image in a format that the display uses directly, call createExternalImage() with one of the formats RGB565, ARGB4444, or A8. The Kernel converts the image when it stores it.

  2. Write the data with Writer.write().

  3. Call Writer.commit(). The resource is then available to the application. Writer.close() without commit() discards the data.

getExternalResourcePath() returns the path to load an external resource. deleteExternalResource() deletes a resource.

Health Services

Note

The Health Services are a preview. Their API can change in the next releases.

The Health Services give the applications the health data of the user: live values, day reports, sleep reports, and workouts. The health stack of the device sends the sensor data to the Kernel through the Event Queue. The Kernel stores the data and computes the reports. The applications read the data when they need it: the services do not notify them.

The Health Services replace the current HealthService with a new version, and add four services:

Service

Role

HealthService

Returns the current heart rate, steps, and calories with getCurrentData(). Returns the samples of one metric (heart rate, steps, or calories) for the last minutes. Returns the report of the current day and of the last days: heart rate (average, resting, minimum, maximum), time in each heart rate zone, steps, and active and passive calories.

SleepService

Returns the report of the last night and the reports of the last days. A sleep report gives the start and end time, the total sleep duration, the duration of each stage (awake, light, deep, REM), a sleep score from 0 to 100, the number of awakenings, and the list of sleep phases.

LiveActivityService

Starts a workout of an activity type, pauses it, resumes it, and adds laps. Stops the workout, and saves or discards it. Returns the live data of the workout: heart rate and heart rate zone (1 to 5), steps, calories, distance (in meters), and pace (in seconds per kilometer).

CompletedActivityService

Returns the reports of the completed workouts: the last one, the last n ones, or the ones of the last days.

UserService

Returns and sets the user profile: age, gender, height, weight, heart rate values (maximum, resting, basal), the five heart rate zones, body fat, VO2 max, stride length, and the daily goals for steps, calories, and sleep.

A workout report (ActivityReport) gives the activity type, the start and end time, the active duration without the pauses, the distance, the elevation change, the pace and heart rate (average and maximum), the time in each heart rate zone, the calories, the start location, the laps, and the samples of each metric during the workout.

The activity type is one of 85 types, such as RUN, TRAIL_RUN, ROAD_BIKE, POOL_SWIM, OPEN_WATER_SWIM, HIKE, STRENGTH, or YOGA. Laps are available for the activity types that support them.

On the Simulator, the Mock simulates the health data, from its UI or from CSV scenario files.