Class ShadowUsageStatsManager
UsageStatsManager.- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic final classApp usage limit observer registered viaUsageStatsManager.registerAppUsageLimitObserver(int, String[], Duration, Duration, PendingIntent).static classApp usage observer registered viaUsageStatsManager.registerAppUsageObserver(int, String[], long, TimeUnit, PendingIntent).static classBuilder for constructingUsageEvents.Eventobjects.static classUsage session observer registered viaUsageStatsManager.registerUsageSessionObserver(int, String[], Duration, Duration, PendingIntent, PendingIntent).static classBuilder for constructingUsageStatsobjects.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected static final Map<Integer, ShadowUsageStatsManager.UsageSessionObserver> 
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddBroadcastResponseStats(Object statsObject) voidaddEvent(UsageEvents.Event event) Adds an event to be returned byUsageStatsManager.queryEvents(long, long).voidDeprecated.voidaddUsageStats(int intervalType, UsageStats stats) Adds an aggregatedUsageStatsobject, to be returned byqueryUsageStats(int, long, long).protected voidclearBroadcastResponseStats(String packageName, long id) protected intReturns the current app's standby bucket that is set bysetCurrentAppStandbyBucket.intgetAppStandbyBucket(String packageName) Returns the current standby bucket of the specified app that is set bysetAppStandbyBucket.com.google.common.collect.ImmutableList<ShadowUsageStatsManager.AppUsageLimitObserver> Returns theShadowUsageStatsManager.AppUsageLimitObservers currently registered inUsageStatsManager.Returns theShadowUsageStatsManager.AppUsageObservers currently registered inUsageStatsManager.Returns theShadowUsageStatsManager.UsageSessionObservers currently registered inUsageStatsManager.protected intprotected List<?> queryBroadcastResponseStats(String packageName, long id) protected UsageEventsqueryEvents(long beginTime, long endTime) protected UsageEventsqueryEvents(Object queryObject) protected UsageEventsqueryEventsForSelf(long beginTime, long endTime) protected List<UsageStats> queryUsageStats(int intervalType, long beginTime, long endTime) Returns aggregated UsageStats added by callingaddUsageStats(int, android.app.usage.UsageStats).protected voidregisterAppUsageLimitObserver(int observerId, String[] observedEntities, Duration timeLimit, Duration timeUsed, PendingIntent callbackIntent) Registers an app usage limit observer that receives a callback oncallbackIntentwhen the sum of usages of apps and tokens inobservedEntitiesexceedstimeLimit - timeUsed.protected voidregisterAppUsageObserver(int observerId, String[] packages, long timeLimit, TimeUnit timeUnit, PendingIntent callbackIntent) protected voidregisterUsageSessionObserver(int observerId, String[] packages, Duration sessionStepDuration, Duration thresholdTimeDuration, PendingIntent sessionStepTriggeredIntent, PendingIntent sessionEndedIntent) static voidreset()voidsetAppStandbyBucket(String packageName, int bucket) Sets the standby bucket of the specified app.voidsetAppStandbyBuckets(Map<String, Integer> appBuckets) voidsetCurrentAppStandbyBucket(int bucket) Sets the current app's standby bucketvoidsetUsageSource(int usageSource) Sets what app usage observers will consider the source of usage for an activity.voidsimulateTimeChange(long offsetToAddInMillis) Simulates the operations done by the framework when there is a time change.voidtriggerRegisteredAppUsageLimitObserver(int observerId, Duration timeUsed) Triggers a currently registeredShadowUsageStatsManager.AppUsageLimitObserverwithobserverId.voidtriggerRegisteredAppUsageObserver(int observerId, long timeUsedInMillis) Triggers a currently registeredShadowUsageStatsManager.AppUsageObserverwithobserverId.voidtriggerRegisteredSessionEndedObserver(int observerId) Triggers a currently registeredShadowUsageStatsManager.UsageSessionObserverwithobserverId.voidtriggerRegisteredSessionStepObserver(int observerId, long timeUsedInMillis) Triggers a currently registeredShadowUsageStatsManager.UsageSessionObserverwithobserverId.protected voidunregisterAppUsageLimitObserver(int observerId) Unregisters the app usage limit observer specified byobserverId.protected voidunregisterAppUsageObserver(int observerId) protected voidunregisterUsageSessionObserver(int observerId) 
- 
Field Details- 
usageSessionObserversByIdprotected static final Map<Integer,ShadowUsageStatsManager.UsageSessionObserver> usageSessionObserversById
 
- 
- 
Constructor Details- 
ShadowUsageStatsManagerpublic ShadowUsageStatsManager()
 
- 
- 
Method Details- 
queryEvents
- 
queryEvents
- 
queryEventsForSelf
- 
addEventDeprecated.UseaddEvent(Event)andShadowUsageStatsManager.EventBuilderinstead.Adds an event to be returned byUsageStatsManager.queryEvents(long, long).This method won't affect the results of queryUsageStats(int, long, long)method.
- 
addEventAdds an event to be returned byUsageStatsManager.queryEvents(long, long).This method won't affect the results of queryUsageStats(int, long, long)method.The UsageEvents.Eventcan be built byShadowUsageStatsManager.EventBuilder.
- 
simulateTimeChangepublic void simulateTimeChange(long offsetToAddInMillis) Simulates the operations done by the framework when there is a time change. If the time is changed, the timestamps of all existing usage events will be shifted by the same offset as the time change, in order to make sure they remain stable relative to the new time.This method won't affect the results of queryUsageStats(int, long, long)method.- Parameters:
- offsetToAddInMillis- the offset to be applied to all events. For example, if- offsetInMillisis 60,000, then all- UsageEvents.Events will be shifted forward by 1 minute (into the future). Likewise, if- offsetInMillisis -60,000, then all- UsageEvents.Events will be shifted backward by 1 minute (into the past).
 
- 
queryUsageStats@Implementation protected List<UsageStats> queryUsageStats(int intervalType, long beginTime, long endTime) Returns aggregated UsageStats added by callingaddUsageStats(int, android.app.usage.UsageStats).The real implementation creates these aggregated objects from individual UsageEvents.Event. This aggregation logic is nontrivial, so the shadow implementation just returns the aggregate data added usingaddUsageStats(int, android.app.usage.UsageStats).
- 
addUsageStatsAdds an aggregatedUsageStatsobject, to be returned byqueryUsageStats(int, long, long). Construct these objects withShadowUsageStatsManager.UsageStatsBuilder, and set the firstTimestamp and lastTimestamp fields to make time filtering work inqueryUsageStats(int, long, long).- Parameters:
- intervalType- An interval type constant, e.g.- UsageStatsManager.INTERVAL_WEEKLY.
 
- 
getAppStandbyBucketReturns the current standby bucket of the specified app that is set bysetAppStandbyBucket. If the standby bucket value has never been set, returnUsageStatsManager.STANDBY_BUCKET_ACTIVE.
- 
getAppStandbyBuckets
- 
setAppStandbyBucket@Implementation(minSdk=28) @HiddenApi public void setAppStandbyBucket(String packageName, int bucket) Sets the standby bucket of the specified app.
- 
setAppStandbyBuckets@Implementation(minSdk=28) @HiddenApi public void setAppStandbyBuckets(Map<String, Integer> appBuckets) 
- 
registerAppUsageObserver@Implementation(minSdk=28) @HiddenApi protected void registerAppUsageObserver(int observerId, String[] packages, long timeLimit, TimeUnit timeUnit, PendingIntent callbackIntent) 
- 
unregisterAppUsageObserver
- 
getRegisteredAppUsageObserversReturns theShadowUsageStatsManager.AppUsageObservers currently registered inUsageStatsManager.
- 
triggerRegisteredAppUsageObserverpublic void triggerRegisteredAppUsageObserver(int observerId, long timeUsedInMillis) Triggers a currently registeredShadowUsageStatsManager.AppUsageObserverwithobserverId.The observer will be no longer registered afterwards. 
- 
registerUsageSessionObserver@Implementation(minSdk=29) protected void registerUsageSessionObserver(int observerId, String[] packages, Duration sessionStepDuration, Duration thresholdTimeDuration, PendingIntent sessionStepTriggeredIntent, PendingIntent sessionEndedIntent) 
- 
unregisterUsageSessionObserver
- 
getRegisteredUsageSessionObserversReturns theShadowUsageStatsManager.UsageSessionObservers currently registered inUsageStatsManager.
- 
triggerRegisteredSessionStepObserverpublic void triggerRegisteredSessionStepObserver(int observerId, long timeUsedInMillis) Triggers a currently registeredShadowUsageStatsManager.UsageSessionObserverwithobserverId.The observer SHOULD be registered afterwards. 
- 
triggerRegisteredSessionEndedObserverpublic void triggerRegisteredSessionEndedObserver(int observerId) Triggers a currently registeredShadowUsageStatsManager.UsageSessionObserverwithobserverId.The observer SHOULD be registered afterwards. 
- 
registerAppUsageLimitObserver@Implementation(minSdk=29) @HiddenApi protected void registerAppUsageLimitObserver(int observerId, String[] observedEntities, Duration timeLimit, Duration timeUsed, PendingIntent callbackIntent) Registers an app usage limit observer that receives a callback oncallbackIntentwhen the sum of usages of apps and tokens inobservedEntitiesexceedstimeLimit - timeUsed.
- 
unregisterAppUsageLimitObserver@Implementation(minSdk=29) @HiddenApi protected void unregisterAppUsageLimitObserver(int observerId) Unregisters the app usage limit observer specified byobserverId.
- 
getRegisteredAppUsageLimitObserverspublic com.google.common.collect.ImmutableList<ShadowUsageStatsManager.AppUsageLimitObserver> getRegisteredAppUsageLimitObservers()Returns theShadowUsageStatsManager.AppUsageLimitObservers currently registered inUsageStatsManager.
- 
triggerRegisteredAppUsageLimitObserverTriggers a currently registeredShadowUsageStatsManager.AppUsageLimitObserverwithobserverId.The observer will still be registered afterwards. 
- 
getAppStandbyBucketReturns the current app's standby bucket that is set bysetCurrentAppStandbyBucket. If the standby bucket value has never been set, returnUsageStatsManager.STANDBY_BUCKET_ACTIVE.
- 
setCurrentAppStandbyBucketpublic void setCurrentAppStandbyBucket(int bucket) Sets the current app's standby bucket
- 
getUsageSource
- 
setUsageSourceSets what app usage observers will consider the source of usage for an activity.
- 
queryBroadcastResponseStats@Implementation(minSdk=33) protected List<?> queryBroadcastResponseStats(@Nullable String packageName, long id) 
- 
clearBroadcastResponseStats@Implementation(minSdk=33) protected void clearBroadcastResponseStats(@Nullable String packageName, long id) 
- 
addBroadcastResponseStats
- 
reset
 
- 
addEvent(Event)andShadowUsageStatsManager.EventBuilderinstead.