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 |
getMeasurement(key: Int) Get the measurement for the given key. |
open Int |
getMeasurementKeyAt(index: 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!>! |
getMeasurements(key: Int) Get the measurements map for the given key. |
open Int |
getMeasurementsKeyAt(index: 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!>! |
Get the HealthStats map for the given key. |
open Int |
getStatsKeyAt(index: 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! |
Return a TimerStat object for the given key. |
open Int |
getTimerCount(key: Int) Get the count for the timer for the given key. |
open Int |
getTimerKeyAt(index: Int) Get the key for the timer at the given index. |
open Int |
Get the number of timer values in this object. |
open Long |
getTimerTime(key: Int) Get the time for the timer for the given key, in milliseconds. |
open MutableMap<String!, TimerStat!>! |
Get the TimerStat map for the given key. |
open Int |
getTimersKeyAt(index: 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 |
hasMeasurement(key: Int) Return whether this object contains a measurement for the supplied key. |
open Boolean |
hasMeasurements(key: Int) Return whether this object contains a measurements map for the supplied key. |
open Boolean |
Return whether this object contains a HealthStats map for the supplied key. |
open Boolean |
Return whether this object contains a TimerStat for the supplied key. |
open Boolean |
Return whether this object contains a timers map for the supplied key. |
Public methods
getDataType
open fun getDataType(): String!
Get a name representing the contents of this object.
getMeasurement
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
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()
.
See Also
getMeasurementKeyCount
open fun getMeasurementKeyCount(): Int
Get the number of measurement values in this object. Can be used to iterate through the available measurements.
See Also
getMeasurements
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
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()
.
See Also
getMeasurementsKeyCount
open fun getMeasurementsKeyCount(): Int
Get the number of measurement map values in this object. Can be used to iterate through the available measurement maps.
See Also
getStats
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
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()
.
See Also
getStatsKeyCount
open fun getStatsKeyCount(): Int
Get the number of HealthStat map values in this object. Can be used to iterate through the available measurements.
See Also
getTimer
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
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
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()
.
See Also
getTimerKeyCount
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
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
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
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()
.
See Also
getTimersKeyCount
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
open fun hasMeasurement(key: Int): Boolean
Return whether this object contains a measurement for the supplied key.
hasMeasurements
open fun hasMeasurements(key: Int): Boolean
Return whether this object contains a measurements map for the supplied key.
hasStats
open fun hasStats(key: Int): Boolean
Return whether this object contains a HealthStats map for the supplied key.
hasTimer
open fun hasTimer(key: Int): Boolean
Return whether this object contains a TimerStat for the supplied key.
hasTimers
open fun hasTimers(key: Int): Boolean
Return whether this object contains a timers map for the supplied key.