Search in sources :

Example 11 with UsageStats

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

the class UsageStatsXmlV1 method loadUsageStats.

private static void loadUsageStats(XmlPullParser parser, IntervalStats statsOut) throws IOException {
    final String pkg = parser.getAttributeValue(null, PACKAGE_ATTR);
    if (pkg == null) {
        throw new ProtocolException("no " + PACKAGE_ATTR + " attribute present");
    }
    final UsageStats stats = statsOut.getOrCreateUsageStats(pkg);
    // Apply the offset to the beginTime to find the absolute time.
    stats.mLastTimeUsed = statsOut.beginTime + XmlUtils.readLongAttribute(parser, LAST_TIME_ACTIVE_ATTR);
    stats.mTotalTimeInForeground = XmlUtils.readLongAttribute(parser, TOTAL_TIME_ACTIVE_ATTR);
    stats.mLastEvent = XmlUtils.readIntAttribute(parser, LAST_EVENT_ATTR);
}
Also used : ProtocolException(java.net.ProtocolException) UsageStats(android.app.usage.UsageStats)

Example 12 with UsageStats

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

the class UserUsageStatsService method init.

void init(final long currentTimeMillis) {
    mDatabase.init(currentTimeMillis);
    int nullCount = 0;
    for (int i = 0; i < mCurrentStats.length; i++) {
        mCurrentStats[i] = mDatabase.getLatestUsageStats(i);
        if (mCurrentStats[i] == null) {
            // Find out how many intervals we don't have data for.
            // Ideally it should be all or none.
            nullCount++;
        }
    }
    if (nullCount > 0) {
        if (nullCount != mCurrentStats.length) {
            // This is weird, but we shouldn't fail if something like this
            // happens.
            Slog.w(TAG, mLogPrefix + "Some stats have no latest available");
        } else {
        // This must be first boot.
        }
        // By calling loadActiveStats, we will
        // generate new stats for each bucket.
        loadActiveStats(currentTimeMillis);
    } else {
        // Set up the expiry date to be one day from the latest daily stat.
        // This may actually be today and we will rollover on the first event
        // that is reported.
        updateRolloverDeadline();
    }
    // Now close off any events that were open at the time this was saved.
    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) {
                stat.update(pkgStats.mPackageName, stat.lastTimeSaved, UsageEvents.Event.END_OF_DAY);
                notifyStatsChanged();
            }
        }
        stat.updateConfigurationStats(null, stat.lastTimeSaved);
    }
    if (mDatabase.isNewUpdate()) {
        notifyNewUpdate();
    }
}
Also used : UsageStats(android.app.usage.UsageStats)

Example 13 with UsageStats

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

the class IntervalStats method update.

void update(String packageName, long timeStamp, int eventType) {
    UsageStats usageStats = getOrCreateUsageStats(packageName);
    // like double MOVE_TO_BACKGROUND, etc.
    if (eventType == UsageEvents.Event.MOVE_TO_BACKGROUND || eventType == UsageEvents.Event.END_OF_DAY) {
        if (usageStats.mLastEvent == UsageEvents.Event.MOVE_TO_FOREGROUND || usageStats.mLastEvent == UsageEvents.Event.CONTINUE_PREVIOUS_DAY) {
            usageStats.mTotalTimeInForeground += timeStamp - usageStats.mLastTimeUsed;
        }
    }
    if (isStatefulEvent(eventType)) {
        usageStats.mLastEvent = eventType;
    }
    if (eventType != UsageEvents.Event.SYSTEM_INTERACTION) {
        usageStats.mLastTimeUsed = timeStamp;
    }
    usageStats.mEndTimeStamp = timeStamp;
    if (eventType == UsageEvents.Event.MOVE_TO_FOREGROUND) {
        usageStats.mLaunchCount += 1;
    }
    endTime = timeStamp;
}
Also used : UsageStats(android.app.usage.UsageStats)

Example 14 with UsageStats

use of android.app.usage.UsageStats in project platform_frameworks_base by android.

the class IntervalStats method getOrCreateUsageStats.

/**
     * Gets the UsageStats object for the given package, or creates one and adds it internally.
     */
UsageStats getOrCreateUsageStats(String packageName) {
    UsageStats usageStats = packageStats.get(packageName);
    if (usageStats == null) {
        usageStats = new UsageStats();
        usageStats.mPackageName = getCachedStringRef(packageName);
        usageStats.mBeginTimeStamp = beginTime;
        usageStats.mEndTimeStamp = endTime;
        packageStats.put(usageStats.mPackageName, usageStats);
    }
    return usageStats;
}
Also used : UsageStats(android.app.usage.UsageStats)

Example 15 with UsageStats

use of android.app.usage.UsageStats in project platform_frameworks_base by android.

the class UserUsageStatsService method printIntervalStats.

void printIntervalStats(IndentingPrintWriter pw, IntervalStats stats, boolean prettyDates) {
    if (prettyDates) {
        pw.printPair("timeRange", "\"" + DateUtils.formatDateRange(mContext, stats.beginTime, stats.endTime, sDateFormatFlags) + "\"");
    } else {
        pw.printPair("beginTime", stats.beginTime);
        pw.printPair("endTime", stats.endTime);
    }
    pw.println();
    pw.increaseIndent();
    pw.println("packages");
    pw.increaseIndent();
    final ArrayMap<String, UsageStats> pkgStats = stats.packageStats;
    final int pkgCount = pkgStats.size();
    for (int i = 0; i < pkgCount; i++) {
        final UsageStats usageStats = pkgStats.valueAt(i);
        pw.printPair("package", usageStats.mPackageName);
        pw.printPair("totalTime", formatElapsedTime(usageStats.mTotalTimeInForeground, prettyDates));
        pw.printPair("lastTime", formatDateTime(usageStats.mLastTimeUsed, prettyDates));
        pw.println();
    }
    pw.decreaseIndent();
    pw.println("configurations");
    pw.increaseIndent();
    final ArrayMap<Configuration, ConfigurationStats> configStats = stats.configurations;
    final int configCount = configStats.size();
    for (int i = 0; i < configCount; i++) {
        final ConfigurationStats config = configStats.valueAt(i);
        pw.printPair("config", Configuration.resourceQualifierString(config.mConfiguration));
        pw.printPair("totalTime", formatElapsedTime(config.mTotalTimeActive, prettyDates));
        pw.printPair("lastTime", formatDateTime(config.mLastTimeActive, prettyDates));
        pw.printPair("count", config.mActivationCount);
        pw.println();
    }
    pw.decreaseIndent();
    pw.println("events");
    pw.increaseIndent();
    final TimeSparseArray<UsageEvents.Event> events = stats.events;
    final int eventCount = events != null ? events.size() : 0;
    for (int i = 0; i < eventCount; i++) {
        final UsageEvents.Event event = events.valueAt(i);
        pw.printPair("time", formatDateTime(event.mTimeStamp, prettyDates));
        pw.printPair("type", eventToString(event.mEventType));
        pw.printPair("package", event.mPackage);
        if (event.mClass != null) {
            pw.printPair("class", event.mClass);
        }
        if (event.mConfiguration != null) {
            pw.printPair("config", Configuration.resourceQualifierString(event.mConfiguration));
        }
        if (event.mShortcutId != null) {
            pw.printPair("shortcutId", event.mShortcutId);
        }
        pw.println();
    }
    pw.decreaseIndent();
    pw.decreaseIndent();
}
Also used : ConfigurationStats(android.app.usage.ConfigurationStats) Configuration(android.content.res.Configuration) Event(android.app.usage.UsageEvents.Event) Event(android.app.usage.UsageEvents.Event) UsageStats(android.app.usage.UsageStats) UsageEvents(android.app.usage.UsageEvents)

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