@Implements(value=android.app.usage.UsageStatsManager.class, minSdk=21) public class ShadowUsageStatsManager extends java.lang.Object
Shadow of UsageStatsManager
.
Modifier and Type | Class and Description |
---|---|
static class |
ShadowUsageStatsManager.AppUsageObserver
App usage observer registered via
UsageStatsManager.registerAppUsageObserver(int,
String[], long, TimeUnit, PendingIntent) . |
static class |
ShadowUsageStatsManager.EventBuilder
Builder for constructing
UsageEvents.Event objects. |
static class |
ShadowUsageStatsManager.UsageStatsBuilder
Builder for constructing
UsageStats objects. |
Constructor and Description |
---|
ShadowUsageStatsManager() |
Modifier and Type | Method and Description |
---|---|
void |
addEvent(java.lang.String packageName,
long timeStamp,
int eventType)
Deprecated.
Use
#addEvent(Event) and ShadowUsageStatsManager.EventBuilder instead. |
void |
addEvent(android.app.usage.UsageEvents.Event event)
Adds an event to be returned by
UsageStatsManager.queryEvents(long, long) . |
void |
addUsageStats(int intervalType,
android.app.usage.UsageStats stats)
Adds an aggregated
UsageStats object, to be returned by queryUsageStats(int, long, long) . |
protected int |
getAppStandbyBucket()
Returns the current app’s standby bucket that is set by
setCurrentAppStandbyBucket . |
int |
getAppStandbyBucket(java.lang.String packageName)
Returns the current standby bucket of the specified app that is set by
setAppStandbyBucket . |
java.util.Map<java.lang.String,java.lang.Integer> |
getAppStandbyBuckets() |
java.util.Collection<ShadowUsageStatsManager.AppUsageObserver> |
getRegisteredAppUsageObservers()
Returns the
ShadowUsageStatsManager.AppUsageObserver s currently registered in UsageStatsManager . |
protected android.app.usage.UsageEvents |
queryEvents(long beginTime,
long endTime) |
protected java.util.List<android.app.usage.UsageStats> |
queryUsageStats(int intervalType,
long beginTime,
long endTime)
Returns aggregated UsageStats added by calling
addUsageStats(int, android.app.usage.UsageStats) . |
protected void |
registerAppUsageObserver(int observerId,
java.lang.String[] packages,
long timeLimit,
java.util.concurrent.TimeUnit timeUnit,
android.app.PendingIntent callbackIntent) |
static void |
reset() |
void |
setAppStandbyBucket(java.lang.String packageName,
int bucket)
Sets the standby bucket of the specified app.
|
void |
setAppStandbyBuckets(java.util.Map<java.lang.String,java.lang.Integer> appBuckets) |
void |
setCurrentAppStandbyBucket(int bucket)
Sets the current app’s standby bucket
|
void |
simulateTimeChange(long offsetToAddInMillis)
Simulates the operations done by the framework when there is a time change.
|
void |
triggerRegisteredAppUsageObserver(int observerId,
long timeUsedInMillis)
Triggers a currently registered
ShadowUsageStatsManager.AppUsageObserver with observerId . |
protected void |
unregisterAppUsageObserver(int observerId) |
@Implementation protected android.app.usage.UsageEvents queryEvents(long beginTime, long endTime)
@Deprecated public void addEvent(java.lang.String packageName, long timeStamp, int eventType)
#addEvent(Event)
and ShadowUsageStatsManager.EventBuilder
instead.Adds an event to be returned by UsageStatsManager.queryEvents(long, long)
.
This method won’t affect the results of queryUsageStats(int, long, long)
method.
public void addEvent(android.app.usage.UsageEvents.Event event)
Adds an event to be returned by UsageStatsManager.queryEvents(long, long)
.
This method won’t affect the results of queryUsageStats(int, long, long)
method.
The UsageEvents.Event
can be built by ShadowUsageStatsManager.EventBuilder
.
public 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.
offsetToAddInMillis
- the offset to be applied to all events. For example, if offsetInMillis
is 60,000, then all UsageEvents.Event
s will be shifted forward by 1 minute (into the future). Likewise, if offsetInMillis
is -60,000, then all UsageEvents.Event
s will be shifted backward by 1 minute (into the past).@Implementation protected java.util.List<android.app.usage.UsageStats> queryUsageStats(int intervalType, long beginTime, long endTime)
Returns aggregated UsageStats added by calling addUsageStats(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 using addUsageStats(int, android.app.usage.UsageStats)
.
public void addUsageStats(int intervalType, android.app.usage.UsageStats stats)
Adds an aggregated UsageStats
object, to be returned by queryUsageStats(int, long, long)
. Construct these objects with ShadowUsageStatsManager.UsageStatsBuilder
, and set the firstTimestamp and lastTimestamp fields to make time filtering work in queryUsageStats(int, long, long)
.
intervalType
- An interval type constant, e.g. UsageStatsManager.INTERVAL_WEEKLY
.@Implementation(minSdk=28) @HiddenApi public int getAppStandbyBucket(java.lang.String packageName)
Returns the current standby bucket of the specified app that is set by setAppStandbyBucket
. If the standby bucket value has never been set, return UsageStatsManager.STANDBY_BUCKET_ACTIVE
.
@Implementation(minSdk=28) @HiddenApi public java.util.Map<java.lang.String,java.lang.Integer> getAppStandbyBuckets()
@Implementation(minSdk=28) @HiddenApi public void setAppStandbyBucket(java.lang.String packageName, int bucket)
Sets the standby bucket of the specified app.
@Implementation(minSdk=28) @HiddenApi public void setAppStandbyBuckets(java.util.Map<java.lang.String,java.lang.Integer> appBuckets)
@Implementation(minSdk=28) @HiddenApi protected void registerAppUsageObserver(int observerId, java.lang.String[] packages, long timeLimit, java.util.concurrent.TimeUnit timeUnit, android.app.PendingIntent callbackIntent)
@Implementation(minSdk=28) @HiddenApi protected void unregisterAppUsageObserver(int observerId)
public java.util.Collection<ShadowUsageStatsManager.AppUsageObserver> getRegisteredAppUsageObservers()
Returns the ShadowUsageStatsManager.AppUsageObserver
s currently registered in UsageStatsManager
.
public void triggerRegisteredAppUsageObserver(int observerId, long timeUsedInMillis)
Triggers a currently registered ShadowUsageStatsManager.AppUsageObserver
with observerId
.
The observer will be no longer registered afterwards.
@Implementation(minSdk=28) protected int getAppStandbyBucket()
Returns the current app’s standby bucket that is set by setCurrentAppStandbyBucket
. If the standby bucket value has never been set, return UsageStatsManager.STANDBY_BUCKET_ACTIVE
.
public void setCurrentAppStandbyBucket(int bucket)
Sets the current app’s standby bucket
@Resetter public static void reset()