use of android.app.usage.ConfigurationStats in project android_frameworks_base by ResurrectionRemix.
the class IntervalStats method getOrCreateConfigurationStats.
/**
* Gets the ConfigurationStats object for the given configuration, or creates one and adds it
* internally.
*/
ConfigurationStats getOrCreateConfigurationStats(Configuration config) {
ConfigurationStats configStats = configurations.get(config);
if (configStats == null) {
configStats = new ConfigurationStats();
configStats.mBeginTimeStamp = beginTime;
configStats.mEndTimeStamp = endTime;
configStats.mConfiguration = config;
configurations.put(config, configStats);
}
return configStats;
}
use of android.app.usage.ConfigurationStats in project android_frameworks_base by ResurrectionRemix.
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();
}
use of android.app.usage.ConfigurationStats in project android_frameworks_base by ResurrectionRemix.
the class Am method getRecentConfigurations.
private List<Configuration> getRecentConfigurations(int days) {
IUsageStatsManager usm = IUsageStatsManager.Stub.asInterface(ServiceManager.getService(Context.USAGE_STATS_SERVICE));
final long now = System.currentTimeMillis();
final long nDaysAgo = now - (days * 24 * 60 * 60 * 1000);
try {
@SuppressWarnings("unchecked") ParceledListSlice<ConfigurationStats> configStatsSlice = usm.queryConfigurationStats(UsageStatsManager.INTERVAL_BEST, nDaysAgo, now, "com.android.shell");
if (configStatsSlice == null) {
return Collections.emptyList();
}
final ArrayMap<Configuration, Integer> recentConfigs = new ArrayMap<>();
final List<ConfigurationStats> configStatsList = configStatsSlice.getList();
final int configStatsListSize = configStatsList.size();
for (int i = 0; i < configStatsListSize; i++) {
final ConfigurationStats stats = configStatsList.get(i);
final int indexOfKey = recentConfigs.indexOfKey(stats.getConfiguration());
if (indexOfKey < 0) {
recentConfigs.put(stats.getConfiguration(), stats.getActivationCount());
} else {
recentConfigs.setValueAt(indexOfKey, recentConfigs.valueAt(indexOfKey) + stats.getActivationCount());
}
}
final Comparator<Configuration> comparator = new Comparator<Configuration>() {
@Override
public int compare(Configuration a, Configuration b) {
return recentConfigs.get(b).compareTo(recentConfigs.get(a));
}
};
ArrayList<Configuration> configs = new ArrayList<>(recentConfigs.size());
configs.addAll(recentConfigs.keySet());
Collections.sort(configs, comparator);
return configs;
} catch (RemoteException e) {
return Collections.emptyList();
}
}
use of android.app.usage.ConfigurationStats in project android_frameworks_base by crdroidandroid.
the class Am method getRecentConfigurations.
private List<Configuration> getRecentConfigurations(int days) {
IUsageStatsManager usm = IUsageStatsManager.Stub.asInterface(ServiceManager.getService(Context.USAGE_STATS_SERVICE));
final long now = System.currentTimeMillis();
final long nDaysAgo = now - (days * 24 * 60 * 60 * 1000);
try {
@SuppressWarnings("unchecked") ParceledListSlice<ConfigurationStats> configStatsSlice = usm.queryConfigurationStats(UsageStatsManager.INTERVAL_BEST, nDaysAgo, now, "com.android.shell");
if (configStatsSlice == null) {
return Collections.emptyList();
}
final ArrayMap<Configuration, Integer> recentConfigs = new ArrayMap<>();
final List<ConfigurationStats> configStatsList = configStatsSlice.getList();
final int configStatsListSize = configStatsList.size();
for (int i = 0; i < configStatsListSize; i++) {
final ConfigurationStats stats = configStatsList.get(i);
final int indexOfKey = recentConfigs.indexOfKey(stats.getConfiguration());
if (indexOfKey < 0) {
recentConfigs.put(stats.getConfiguration(), stats.getActivationCount());
} else {
recentConfigs.setValueAt(indexOfKey, recentConfigs.valueAt(indexOfKey) + stats.getActivationCount());
}
}
final Comparator<Configuration> comparator = new Comparator<Configuration>() {
@Override
public int compare(Configuration a, Configuration b) {
return recentConfigs.get(b).compareTo(recentConfigs.get(a));
}
};
ArrayList<Configuration> configs = new ArrayList<>(recentConfigs.size());
configs.addAll(recentConfigs.keySet());
Collections.sort(configs, comparator);
return configs;
} catch (RemoteException e) {
return Collections.emptyList();
}
}
use of android.app.usage.ConfigurationStats in project android_frameworks_base by crdroidandroid.
the class IntervalStats method updateConfigurationStats.
void updateConfigurationStats(Configuration config, long timeStamp) {
if (activeConfiguration != null) {
ConfigurationStats activeStats = configurations.get(activeConfiguration);
activeStats.mTotalTimeActive += timeStamp - activeStats.mLastTimeActive;
activeStats.mLastTimeActive = timeStamp - 1;
}
if (config != null) {
ConfigurationStats configStats = getOrCreateConfigurationStats(config);
configStats.mLastTimeActive = timeStamp;
configStats.mActivationCount += 1;
activeConfiguration = configStats.mConfiguration;
}
endTime = timeStamp;
}
Aggregations