Search in sources :

Example 31 with UsageStats

use of android.app.usage.UsageStats in project android_frameworks_base by crdroidandroid.

the class UserUsageStatsService method rolloverStats.

private void rolloverStats(final long currentTimeMillis) {
    final long startTime = SystemClock.elapsedRealtime();
    Slog.i(TAG, mLogPrefix + "Rolling over usage stats");
    // Finish any ongoing events with an END_OF_DAY event. Make a note of which components
    // need a new CONTINUE_PREVIOUS_DAY entry.
    final Configuration previousConfig = mCurrentStats[UsageStatsManager.INTERVAL_DAILY].activeConfiguration;
    ArraySet<String> continuePreviousDay = new ArraySet<>();
    for (IntervalStats stat : mCurrentStats) {
        final int pkgCount = stat.packageStats.size();
        for (int i = 0; i < pkgCount; i++) {
            UsageStats pkgStats = stat.packageStats.valueAt(i);
            if (pkgStats.mLastEvent == UsageEvents.Event.MOVE_TO_FOREGROUND || pkgStats.mLastEvent == UsageEvents.Event.CONTINUE_PREVIOUS_DAY) {
                continuePreviousDay.add(pkgStats.mPackageName);
                stat.update(pkgStats.mPackageName, mDailyExpiryDate.getTimeInMillis() - 1, UsageEvents.Event.END_OF_DAY);
                notifyStatsChanged();
            }
        }
        stat.updateConfigurationStats(null, mDailyExpiryDate.getTimeInMillis() - 1);
    }
    persistActiveStats();
    mDatabase.prune(currentTimeMillis);
    loadActiveStats(currentTimeMillis);
    final int continueCount = continuePreviousDay.size();
    for (int i = 0; i < continueCount; i++) {
        String name = continuePreviousDay.valueAt(i);
        final long beginTime = mCurrentStats[UsageStatsManager.INTERVAL_DAILY].beginTime;
        for (IntervalStats stat : mCurrentStats) {
            stat.update(name, beginTime, UsageEvents.Event.CONTINUE_PREVIOUS_DAY);
            stat.updateConfigurationStats(previousConfig, beginTime);
            notifyStatsChanged();
        }
    }
    persistActiveStats();
    final long totalTime = SystemClock.elapsedRealtime() - startTime;
    Slog.i(TAG, mLogPrefix + "Rolling over usage stats complete. Took " + totalTime + " milliseconds");
}
Also used : ArraySet(android.util.ArraySet) Configuration(android.content.res.Configuration) UsageStats(android.app.usage.UsageStats)

Aggregations

UsageStats (android.app.usage.UsageStats)31 Configuration (android.content.res.Configuration)8 ResolvedComponentInfo (com.android.internal.app.ResolverActivity.ResolvedComponentInfo)5 ConfigurationStats (android.app.usage.ConfigurationStats)4 UsageEvents (android.app.usage.UsageEvents)4 Event (android.app.usage.UsageEvents.Event)4 ArraySet (android.util.ArraySet)4 ProtocolException (java.net.ProtocolException)4 UsageStatsManager (android.app.usage.UsageStatsManager)2 Intent (android.content.Intent)2 TargetApi (android.annotation.TargetApi)1 ActivityManager (android.app.ActivityManager)1 AppOpsManager (android.app.AppOpsManager)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 Comparator (java.util.Comparator)1