Use synthetic data with Health Services

Use synthetic data providers to simulate sensor data from Health Services and test your app as though an exercise were really happening. You can use one of the preconfigured exercise profiles or configure a custom one using flags.

There are two options available for generating simulated data:

  • You can use synthetic data providers, which offer extensive options for data generation. This method uses adb commands and is described on this page.

    To use synthetic data providers on an emulator, you must enable developer options.

  • You can also use the emulator extended controls in Android Studio. Access the emulator's extended controls panel using the overflow menu in the button bar. From the extended controls, you can load Keyhole Markup Language (KML) or GPS Exchange Format (GPX) files to simulate location. You can also specify the behavior of the heart rate sensor.

Enable synthetic data providers

Complete the following steps to enable synthetic data providers.

  1. Enable developer options.
  2. Issue the following adb command to enable synthetic providers:

    adb shell am broadcast \
    -a "whs.USE_SYNTHETIC_PROVIDERS" \
    com.google.android.wearable.healthservices
    

Once synthetic providers are enabled, issue commands described on this page to control the behavior of the "synthetic user."

Disable synthetic data providers

To switch back to using real sensors, run the following command:

adb shell am broadcast \
-a "whs.USE_SENSOR_PROVIDERS" \
com.google.android.wearable.healthservices

Synthetic exercises

Health Services supports the following exercise types:

  • Walking: whs.synthetic.user.START_WALKING
  • Running: whs.synthetic.user.START_RUNNING
  • Hiking: whs.synthetic.user.START_HIKING
  • Swimming: whs.synthetic.user.START_SWIMMING
  • Running on a treadmill: whs.synthetic.user.START_RUNNING_TREADMILL

The exercises generate realistic synthetic data for the following data types:

  • Heart rate
  • Step count per minute
  • GPS location, using a single default route
  • Duration of the activity
  • Elevation and floors

In addition, the following states can be generated:

  • Sleep state—asleep or awake
  • Fall detection

Start

To start simulating an exercise, issue the appropriate broadcast to com.google.android.wearable.healthservices:

# start the "walking" synthetic exercise
$ adb shell am broadcast \
-a "whs.synthetic.user.START_WALKING" \
com.google.android.wearable.healthservices

Each activity has presets for the supported metrics:

Activity Heart rate Average speed Elevation change Use location
Walking 120 bpm 1.4 m/sec 20.0 m/min true
Running 170 bpm 2.3 m/sec 20.0 m/min true
Hiking 150 bpm 1.3 m/sec 20.0 m/min true
Swimming 150 bpm 1.6 m/sec 0.0 m/min true
Running on treadmill 160 bpm 2.3 m/sec 20.0 m/min false

Stop

To stop the synthetic activity, use the following command:

adb shell am broadcast \
-a "whs.synthetic.user.STOP_EXERCISE" \
com.google.android.wearable.healthservices

Custom

For more precise control over what metrics are generated, start a custom exercise activity using the action string whs.synthetic.user.START_EXERCISE. Provide any combination of the following flags:

  • --ei exercise_options_duration_secs <int>: duration of the exercise in seconds. Default: 0.
  • --ei exercise_options_heart_rate <int>: heart rate in beats per minute. Average: 70.
  • --ef exercise_options_average_speed <float>: average speed in meters per second. Also affects steps per minute, or cadence. Default: 0.
  • --ez exercise_options_use_location <boolean>: whether to emit location data during the exercise, using a default route. Default: false.
  • --ef exercise_options_max_elevation_rate <float>: maximum possible elevation change rate in meters per minute. Default: 0.

For example, set exercise options in the following way:

adb shell am broadcast \
-a "whs.synthetic.user.START_EXERCISE" \
--ei exercise_options_heart_rate 90 \
--ef exercise_options_average_speed 1.2 \
--ez exercise_options_use_location true \
com.google.android.wearable.healthservices

You can also change the data types that are available, whether or not the real or emulated hardware supports a particular data type. For example, you can enable or disable absolute elevation, as shown in the following snippet:

# enable synthetic mode and enable absolute elevation
$ adb shell am broadcast \
-a "whs.CONFIGURE_SYNTHETIC_DEVICE" \
--ez absolute_elevation true \
com.google.android.wearable.healthservices

# enable synthetic mode and disable absolute elevation
$ adb shell am broadcast \
-a "whs.CONFIGURE_SYNTHETIC_DEVICE" \
--ez absolute_elevation false \
com.google.android.wearable.healthservices

Other states and events

Sleep state

You can also trigger sleep states for the synthetic user. Two states are supported: asleep and awake.

To enter the asleep state, run this command:

adb shell am broadcast \
-a "whs.synthetic.user.START_SLEEPING" \
com.google.android.wearable.healthservices

To enter the awake state, run this command:

adb shell am broadcast \
-a "whs.synthetic.user.STOP_SLEEPING" \
com.google.android.wearable.healthservices

Fall detection

To simulate a fall, run this command:

adb shell am broadcast \
-a "whs.synthetic.user.FALL_OVER" \
com.google.android.wearable.healthservices

It can take up to a minute for health services to deliver the fall event.