use of android.app.usage.UsageStats in project android_packages_apps_Settings by omnirom.
the class AppsPreferenceController method displayRecentApps.
private void displayRecentApps() {
if (mRecentAppsCategory != null) {
final Map<String, Preference> existedAppPreferences = new ArrayMap<>();
final int prefCount = mRecentAppsCategory.getPreferenceCount();
for (int i = 0; i < prefCount; i++) {
final Preference pref = mRecentAppsCategory.getPreference(i);
final String key = pref.getKey();
if (!TextUtils.equals(key, KEY_SEE_ALL)) {
existedAppPreferences.put(key, pref);
}
}
int showAppsCount = 0;
for (UsageStats stat : mRecentApps) {
final String pkgName = stat.getPackageName();
final ApplicationsState.AppEntry appEntry = mApplicationsState.getEntry(pkgName, mUserId);
if (appEntry == null) {
continue;
}
boolean rebindPref = true;
Preference pref = existedAppPreferences.remove(pkgName);
if (pref == null) {
pref = new AppPreference(mContext);
rebindPref = false;
}
pref.setKey(pkgName);
pref.setTitle(appEntry.label);
pref.setIcon(Utils.getBadgedIcon(mContext, appEntry.info));
pref.setSummary(StringUtil.formatRelativeTime(mContext, System.currentTimeMillis() - stat.getLastTimeUsed(), false, RelativeDateTimeFormatter.Style.SHORT));
pref.setOrder(showAppsCount++);
pref.setOnPreferenceClickListener(preference -> {
AppInfoBase.startAppInfoFragment(AppInfoDashboardFragment.class, R.string.application_info_label, pkgName, appEntry.info.uid, mHost, 1001, /*RequestCode*/
getMetricsCategory());
return true;
});
if (!rebindPref) {
mRecentAppsCategory.addPreference(pref);
}
}
// Remove unused preferences from pref category.
for (Preference unusedPref : existedAppPreferences.values()) {
mRecentAppsCategory.removePreference(unusedPref);
}
}
}
use of android.app.usage.UsageStats in project android_packages_apps_Settings by omnirom.
the class HibernatedAppsPreferenceControllerTest method setAutoRevokedPackageUsageStats.
private void setAutoRevokedPackageUsageStats() {
final UsageStats us = new UsageStats();
us.mPackageName = AUTO_REVOKED_PACKAGE_NAME;
us.mLastTimeVisible = System.currentTimeMillis();
try {
when(mIUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong(), anyString(), anyInt())).thenReturn(new ParceledListSlice(Arrays.asList(us)));
} catch (RemoteException e) {
// no-op
}
}
use of android.app.usage.UsageStats in project Taskbar by farmerbb.
the class TaskbarController method getAppEntriesUsingUsageStats.
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
private List<AppEntry> getAppEntriesUsingUsageStats() {
UsageStatsManager mUsageStatsManager = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
List<UsageStats> usageStatsList = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, searchInterval, System.currentTimeMillis());
List<AppEntry> entries = new ArrayList<>();
for (UsageStats usageStats : usageStatsList) {
AppEntry newEntry = new AppEntry(usageStats.getPackageName(), null, null, null, false);
newEntry.setTotalTimeInForeground(usageStats.getTotalTimeInForeground());
newEntry.setLastTimeUsed(usageStats.getLastTimeUsed());
entries.add(newEntry);
}
return entries;
}
Aggregations