Class ShadowUsageStatsManager

    • Constructor Detail

      • ShadowUsageStatsManager

        public ShadowUsageStatsManager()
    • Method Detail

      • queryEvents

        @Implementation
        protected UsageEvents queryEvents​(long beginTime,
                                          long endTime)
      • queryEventsForSelf

        @Implementation(minSdk=28)
        protected UsageEvents queryEventsForSelf​(long beginTime,
                                                 long endTime)
      • simulateTimeChange

        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.

        Parameters:
        offsetToAddInMillis - the offset to be applied to all events. For example, if offsetInMillis is 60,000, then all UsageEvents.Events will be shifted forward by 1 minute (into the future). Likewise, if offsetInMillis is -60,000, then all UsageEvents.Events will be shifted backward by 1 minute (into the past).
      • getAppStandbyBucket

        @Implementation(minSdk=28)
        @HiddenApi
        public int getAppStandbyBucket​(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.
      • getAppStandbyBuckets

        @Implementation(minSdk=28)
        @HiddenApi
        public Map<String,​Integer> 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

        @Implementation(minSdk=28)
        @HiddenApi
        protected void unregisterAppUsageObserver​(int observerId)
      • triggerRegisteredAppUsageObserver

        public void triggerRegisteredAppUsageObserver​(int observerId,
                                                      long timeUsedInMillis)
        Triggers a currently registered ShadowUsageStatsManager.AppUsageObserver with observerId.

        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

        @Implementation(minSdk=29)
        protected void unregisterUsageSessionObserver​(int observerId)
      • triggerRegisteredSessionStepObserver

        public void triggerRegisteredSessionStepObserver​(int observerId,
                                                         long timeUsedInMillis)
        Triggers a currently registered ShadowUsageStatsManager.UsageSessionObserver with observerId.

        The observer SHOULD be registered afterwards.

      • triggerRegisteredSessionEndedObserver

        public void triggerRegisteredSessionEndedObserver​(int observerId)
        Triggers a currently registered ShadowUsageStatsManager.UsageSessionObserver with observerId.

        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 on callbackIntent when the sum of usages of apps and tokens in observedEntities exceeds timeLimit - timeUsed.
      • unregisterAppUsageLimitObserver

        @Implementation(minSdk=29)
        @HiddenApi
        protected void unregisterAppUsageLimitObserver​(int observerId)
        Unregisters the app usage limit observer specified by observerId.
      • triggerRegisteredAppUsageLimitObserver

        public void triggerRegisteredAppUsageLimitObserver​(int observerId,
                                                           Duration timeUsed)
        Triggers a currently registered ShadowUsageStatsManager.AppUsageLimitObserver with observerId.

        The observer will still be registered afterwards.

      • getAppStandbyBucket

        @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.
      • setCurrentAppStandbyBucket

        public void setCurrentAppStandbyBucket​(int bucket)
        Sets the current app's standby bucket
      • getUsageSource

        @Implementation(minSdk=29)
        @HiddenApi
        protected int getUsageSource()
      • setUsageSource

        public void setUsageSource​(int usageSource)
        Sets what app usage observers will consider the source of usage for an activity.
      • reset

        @Resetter
        public static void reset()