use of android.app.usage.UsageStats in project android_frameworks_base by ResurrectionRemix.
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");
}
use of android.app.usage.UsageStats in project android_frameworks_base by crdroidandroid.
the class ResolverComparator method compute.
public void compute(List<ResolvedComponentInfo> targets) {
mScoredTargets.clear();
final long recentSinceTime = mCurrentTime - RECENCY_TIME_PERIOD;
long mostRecentlyUsedTime = recentSinceTime + 1;
long mostTimeSpent = 1;
int mostLaunched = 1;
for (ResolvedComponentInfo target : targets) {
final ScoredTarget scoredTarget = new ScoredTarget(target.getResolveInfoAt(0).activityInfo);
mScoredTargets.put(target.name, scoredTarget);
final UsageStats pkStats = mStats.get(target.name.getPackageName());
if (pkStats != null) {
// Persistent processes muck this up, so omit them too.
if (!target.name.getPackageName().equals(mReferrerPackage) && !isPersistentProcess(target)) {
final long lastTimeUsed = pkStats.getLastTimeUsed();
scoredTarget.lastTimeUsed = lastTimeUsed;
if (lastTimeUsed > mostRecentlyUsedTime) {
mostRecentlyUsedTime = lastTimeUsed;
}
}
final long timeSpent = pkStats.getTotalTimeInForeground();
scoredTarget.timeSpent = timeSpent;
if (timeSpent > mostTimeSpent) {
mostTimeSpent = timeSpent;
}
final int launched = pkStats.mLaunchCount;
scoredTarget.launchCount = launched;
if (launched > mostLaunched) {
mostLaunched = launched;
}
}
}
if (DEBUG) {
Log.d(TAG, "compute - mostRecentlyUsedTime: " + mostRecentlyUsedTime + " mostTimeSpent: " + mostTimeSpent + " recentSinceTime: " + recentSinceTime + " mostLaunched: " + mostLaunched);
}
for (ScoredTarget target : mScoredTargets.values()) {
final float recency = (float) Math.max(target.lastTimeUsed - recentSinceTime, 0) / (mostRecentlyUsedTime - recentSinceTime);
final float recencyScore = recency * recency * RECENCY_MULTIPLIER;
final float usageTimeScore = (float) target.timeSpent / mostTimeSpent;
final float launchCountScore = (float) target.launchCount / mostLaunched;
target.score = recencyScore + usageTimeScore + launchCountScore;
if (DEBUG) {
Log.d(TAG, "Scores: recencyScore: " + recencyScore + " usageTimeScore: " + usageTimeScore + " launchCountScore: " + launchCountScore + " - " + target);
}
}
}
use of android.app.usage.UsageStats in project android_frameworks_base by crdroidandroid.
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;
}
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");
}
use of android.app.usage.UsageStats in project android_packages_apps_Settings by LineageOS.
the class RecentAppsPreferenceController method getDisplayableRecentAppList.
private List<UsageStats> getDisplayableRecentAppList() {
final List<UsageStats> recentApps = new ArrayList<>();
final Map<String, UsageStats> map = new ArrayMap<>();
final int statCount = mStats.size();
for (int i = 0; i < statCount; i++) {
final UsageStats pkgStats = mStats.get(i);
if (!shouldIncludePkgInRecents(pkgStats)) {
continue;
}
final String pkgName = pkgStats.getPackageName();
final UsageStats existingStats = map.get(pkgName);
if (existingStats == null) {
map.put(pkgName, pkgStats);
} else {
existingStats.add(pkgStats);
}
}
final List<UsageStats> packageStats = new ArrayList<>();
packageStats.addAll(map.values());
Collections.sort(packageStats, this);
int count = 0;
for (UsageStats stat : packageStats) {
final ApplicationsState.AppEntry appEntry = mApplicationsState.getEntry(stat.getPackageName(), mUserId);
if (appEntry == null) {
continue;
}
recentApps.add(stat);
count++;
if (count >= SHOW_RECENT_APP_COUNT) {
break;
}
}
return recentApps;
}
Aggregations