HealthProbe
Collects health data from Apple Health or Google Health Connect.
Created by the HealthSamplingPackage for the HealthSamplingPackage.HEALTH measure and configured by a HealthSamplingConfiguration. Each time it is resumed, it fetches the configured health data types back to the last time data was collected and emits one HealthData measurement per data point. Use it with a trigger that runs regularly, such as a PeriodicTrigger, or from a HealthAppTask that the user starts.
Key points:
- On initialize, it removes types not supported on this platform and adds the rest to the HealthServiceManager.
- It collects nothing if permissions are missing, the type list is empty, or the start time is after the end time.
- It pauses itself 20 seconds after a collection.
- Errors from the
healthplugin are logged and the resume fails.
- Inheritance
-
- Object
- AbstractExecutor<
Measure> - Probe
- HealthProbe
Constructors
HealthProbe
Properties
deviceManager
The device that this probes uses to collect data.
samplingConfiguration
The sampling configuration for this probe.
Configuration is obtained in the following order:
- from the Measure.overrideSamplingConfiguration
- from the DeviceConfiguration.defaultSamplingConfiguration of the deployment
- from the DeviceConfiguration.dataTypeSamplingSchemes of the static device configuration
- from the SamplingPackage.samplingSchemes of the sampling packages
Returns null in case no configuration is found.
See also the section on Sampling schemes and configurations in the CARP Core Framework. In addition to CARP Core, CARP Mobile Sensing also supports sampling schemes in the sampling packages, which are used as the 4th possible configuration in the list above.
stream
A stream that only carries collection errors.
Measurements are emitted on measurements, not on this stream.
Methods
hasPermissions
Whether permission is granted to read the health data types in the samplingConfiguration.
See HealthServiceManager.hasHealthPermissions for the iOS caveat.
onInitialize
Callback when this executor is initialized. Returns true if successfully initialized, false otherwise.
Note that this is a non-async method and should hence be 'light-weight' and not block execution for a long duration.
onResume
Callback when this executor is resumed. Returns true if successfully resumed, false otherwise.
requestPermissions
Requests permission to read the health data types in the samplingConfiguration, if not already granted.
Note that this shows the permission dialog to the user, asking for access to the health data. If the user denies access, this method returns false.
Note that on Android, if the user denies access to the health data types TWICE, then the permissions are permanently denied and the app cannot ask anymore. In this case, this method cannot be used to request permissions. Instead, the user must manually go to the settings of the phone and enable the permissions.
validateHealthDataTypes
Removes the health data types in samplingConfiguration that are not supported on the current platform (iOS or Android).
Logs a warning for each removed type. Called when the probe is initialized.