Added in API level 24

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 single 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.

Summary

Public methods
open String!

Get a name representing the contents of this object.

open Long

Get the measurement for the given key.

open Int

Get the key for the measurement at the given index.

open Int

Get the number of measurement values in this object.

open MutableMap<String!, Long!>!

Get the measurements map for the given key.

open Int

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

open Int

Get the number of measurement map values in this object.

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

Get the HealthStats map for the given key.

open Int

Get the key for the timer at the given index.

open Int

Get the number of HealthStat map values in this object.

open TimerStat!
getTimer(key: Int)

Return a TimerStat object for the given key.

open Int

Get the count for the timer for the given key.

open Int

Get the key for the timer at the given index.

open Int

Get the number of timer values in this object.

open Long

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

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

Get the TimerStat map for the given key.

open Int

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

open Int

Get the number of timer map values in this object.

open Boolean

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

open Boolean

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

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 Boolean
hasTimers(key: Int)

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

Public methods

getMeasurement

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

Get the measurement for the given key.

Exceptions
java.lang.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().

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.

getMeasurements

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

Get the measurements map for the given key.

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

See Also

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().

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.

getStats

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

Get the HealthStats map for the given key.

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

See Also

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().

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.

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.

Exceptions
java.lang.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.

Exceptions
java.lang.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().

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.

See Also

getTimerTime

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

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

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

See Also

getTimers

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

Get the TimerStat map for the given key.

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

See Also

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().

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.

See Also

hasMeasurement

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

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

hasMeasurements

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

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

hasStats

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

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

hasTimer

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

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

hasTimers

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

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