HealthStats

open class HealthStats
kotlin.Any
   ↳ android.os.health.HealthStats

A HealthStats object contains system health data about an application.

Data Types
Each of the keys references data in one of five data types:

A measurement metric contains a sinlge long value. That value may be a count, a time, or some other type of value. The unit for a measurement (COUNT, MS, etc) will always be in the name of the constant for the key to retrieve it. For example, the UidHealthStats.MEASUREMENT_WIFI_TX_MS value is the number of milliseconds (ms) that were spent transmitting on wifi by an application. The UidHealthStats.MEASUREMENT_MOBILE_RX_PACKETS measurement is the number of packets received on behalf of an application. The UidHealthStats.MEASUREMENT_TOUCH_USER_ACTIVITY_COUNT measurement is the number of times the user touched the screen, causing the screen to stay awake.

A timer metric contains an int count and a long time, measured in milliseconds. Timers track how many times a resource was used, and the total duration for that usage. For example, the android.os.health.UidHealthStats#TIMER_FLASHLIGHT timer tracks how many times the application turned on the flashlight, and for how many milliseconds total it kept it on.

A measurement map metric is a mapping of java.lang.String names to java.lang.Long values. The names typically are application provided names. For example, the PackageHealthStats.MEASUREMENTS_WAKEUP_ALARMS_COUNT measurement map is a mapping of the tag provided to the android.app.AlarmManager when the alarm is scheduled.

A timer map metric is a mapping of java.lang.String names to android.os.health.TimerStat objects. The names are typically application provided names. For example, the UidHealthStats.TIMERS_WAKELOCKS_PARTIAL is a mapping of tag provided to the android.os.PowerManager when the wakelock is created to the number of times and for how long each wakelock was active.

Lastly, a health stats metric is a mapping of java.lang.String names to a recursive android.os.health.HealthStats object containing more detailed information. For example, the UidHealthStats.STATS_PACKAGES metric is a mapping of the package names for each of the APKs sharing a uid to the information recorded for that apk. The returned HealthStats objects will each be associated with a different set of constants. For the HealthStats returned for UidHealthStats.STATS_PACKAGES, the keys come from the android.os.health.PackageHealthStats class.

The keys that are available are subject to change, depending on what a particular device or software version is capable of recording. Applications must handle the absence of data without crashing.
Requires API level 24 (Android 7.0, Nougat)

Summary

Public methods
open MutableMap<String!, TimerStat!>!
getTimers(key: Int)

Get the TimerStat map for the given key.

open Int

Get the number of measurement values in this object.

open Boolean

Return whether this object contains a measurement for the supplied key.

open Int

Get the key for the measurement map at the given index.

open Int

Get the number of HealthStat map values in this object.

open Int

Get the number of timer values in this object.

open Boolean
hasStats(key: Int)

Return whether this object contains a HealthStats map for the supplied key.

open Boolean
hasTimer(key: Int)

Return whether this object contains a TimerStat for the supplied key.

open Int

Get the key for the timer map at the given index.

open MutableMap<String!, HealthStats!>!
getStats(key: Int)

Get the HealthStats map for the given key.

open TimerStat!
getTimer(key: Int)

Return a TimerStat object for the given key.

open Int

Get the key for the measurement at the given index.

open Long

Get the measurement for the given key.

open Int

Get the key for the timer at the given index.

open Int

Get the key for the timer at the given index.

open String!

Get a name representing the contents of this object.

open Boolean
hasTimers(key: Int)

Return whether this object contains a timers map for the supplied key.

open Long

Get the time for the timer for the given key, in milliseconds.

open Int

Get the number of timer map values in this object.

open Int

Get the number of measurement map values in this object.

open MutableMap<String!, Long!>!

Get the measurements map for the given key.

open Int

Get the count for the timer for the given key.

open Boolean

Return whether this object contains a measurements map for the supplied key.

Public methods

getTimers

added in API level 24
open fun getTimers(key: Int): MutableMap<String!, TimerStat!>!

Get the TimerStat map for the given key.
Requires API level 24 (Android 7.0, Nougat)

Exceptions
IndexOutOfBoundsException When the key is not present in this object.

See Also

getMeasurementKeyCount

added in API level 24
open fun getMeasurementKeyCount(): Int

Get the number of measurement values in this object. Can be used to iterate through the available measurements.
Requires API level 24 (Android 7.0, Nougat)

hasMeasurement

added in API level 24
open fun hasMeasurement(key: Int): Boolean

Return whether this object contains a measurement for the supplied key.
Requires API level 24 (Android 7.0, Nougat)

getMeasurementsKeyAt

added in API level 24
open fun getMeasurementsKeyAt(index: Int): Int

Get the key for the measurement map at the given index. Index must be between 0 and the result of getMeasurementsKeyCount().
Requires API level 24 (Android 7.0, Nougat)

getStatsKeyCount

added in API level 24
open fun getStatsKeyCount(): Int

Get the number of HealthStat map values in this object. Can be used to iterate through the available measurements.
Requires API level 24 (Android 7.0, Nougat)

getTimerKeyCount

added in API level 24
open fun getTimerKeyCount(): Int

Get the number of timer values in this object. Can be used to iterate through the available timers.
Requires API level 24 (Android 7.0, Nougat)

See Also

hasStats

added in API level 24
open fun hasStats(key: Int): Boolean

Return whether this object contains a HealthStats map for the supplied key.
Requires API level 24 (Android 7.0, Nougat)

hasTimer

added in API level 24
open fun hasTimer(key: Int): Boolean

Return whether this object contains a TimerStat for the supplied key.
Requires API level 24 (Android 7.0, Nougat)

getTimersKeyAt

added in API level 24
open fun getTimersKeyAt(index: Int): Int

Get the key for the timer map at the given index. Index must be between 0 and the result of getTimersKeyCount().
Requires API level 24 (Android 7.0, Nougat)

getStats

added in API level 24
open fun getStats(key: Int): MutableMap<String!, HealthStats!>!

Get the HealthStats map for the given key.
Requires API level 24 (Android 7.0, Nougat)

Exceptions
IndexOutOfBoundsException When the key is not present in this object.

See Also

getTimer

added in API level 24
open fun getTimer(key: Int): TimerStat!

Return a TimerStat object for the given key. This will allocate a new TimerStat object, which may be wasteful. Instead, use #getTimerCount and #getTimerTime.
Requires API level 24 (Android 7.0, Nougat)

Exceptions
IndexOutOfBoundsException When the key is not present in this object.

See Also

getMeasurementKeyAt

added in API level 24
open fun getMeasurementKeyAt(index: Int): Int

Get the key for the measurement at the given index. Index must be between 0 and the result of getMeasurementKeyCount().
Requires API level 24 (Android 7.0, Nougat)

getMeasurement

added in API level 24
open fun getMeasurement(key: Int): Long

Get the measurement for the given key.
Requires API level 24 (Android 7.0, Nougat)

Exceptions
IndexOutOfBoundsException When the key is not present in this object.

See Also

getTimerKeyAt

added in API level 24
open fun getTimerKeyAt(index: Int): Int

Get the key for the timer at the given index. Index must be between 0 and the result of getTimerKeyCount().
Requires API level 24 (Android 7.0, Nougat)

getStatsKeyAt

added in API level 24
open fun getStatsKeyAt(index: Int): Int

Get the key for the timer at the given index. Index must be between 0 and the result of getStatsKeyCount().
Requires API level 24 (Android 7.0, Nougat)

getDataType

added in API level 24
open fun getDataType(): String!

Get a name representing the contents of this object.
Requires API level 24 (Android 7.0, Nougat)

hasTimers

added in API level 24
open fun hasTimers(key: Int): Boolean

Return whether this object contains a timers map for the supplied key.
Requires API level 24 (Android 7.0, Nougat)

getTimerTime

added in API level 24
open fun getTimerTime(key: Int): Long

Get the time for the timer for the given key, in milliseconds.
Requires API level 24 (Android 7.0, Nougat)

Exceptions
IndexOutOfBoundsException When the key is not present in this object.

See Also

getTimersKeyCount

added in API level 24
open fun getTimersKeyCount(): Int

Get the number of timer map values in this object. Can be used to iterate through the available timer maps.
Requires API level 24 (Android 7.0, Nougat)

See Also

getMeasurementsKeyCount

added in API level 24
open fun getMeasurementsKeyCount(): Int

Get the number of measurement map values in this object. Can be used to iterate through the available measurement maps.
Requires API level 24 (Android 7.0, Nougat)

getMeasurements

added in API level 24
open fun getMeasurements(key: Int): MutableMap<String!, Long!>!

Get the measurements map for the given key.
Requires API level 24 (Android 7.0, Nougat)

Exceptions
IndexOutOfBoundsException When the key is not present in this object.

See Also

getTimerCount

added in API level 24
open fun getTimerCount(key: Int): Int

Get the count for the timer for the given key.
Requires API level 24 (Android 7.0, Nougat)

Exceptions
IndexOutOfBoundsException When the key is not present in this object.

See Also

hasMeasurements

added in API level 24
open fun hasMeasurements(key: Int): Boolean

Return whether this object contains a measurements map for the supplied key.
Requires API level 24 (Android 7.0, Nougat)