use of android.app.usage.UsageStats in project android_packages_apps_Settings by DirtyUnicorns.
the class RecentAppsPreferenceControllerTest method display_hasRecentButNoneDisplayable_showAppInfo.
@Test
public void display_hasRecentButNoneDisplayable_showAppInfo() {
when(mMockContext.getResources().getBoolean(R.bool.config_display_recent_apps)).thenReturn(true);
final List<UsageStats> stats = new ArrayList<>();
final UsageStats stat1 = new UsageStats();
final UsageStats stat2 = new UsageStats();
stat1.mLastTimeUsed = System.currentTimeMillis();
stat1.mPackageName = "com.android.phone";
stats.add(stat1);
stat2.mLastTimeUsed = System.currentTimeMillis();
stat2.mPackageName = "com.android.settings";
stats.add(stat2);
// stat1, stat2 are not displayable
when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId())).thenReturn(mock(ApplicationsState.AppEntry.class));
when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId())).thenReturn(mock(ApplicationsState.AppEntry.class));
when(mMockContext.getPackageManager().resolveActivity(any(Intent.class), anyInt())).thenReturn(new ResolveInfo());
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong())).thenReturn(stats);
mController = new RecentAppsPreferenceController(mMockContext, mAppState, null);
mController.displayPreference(mScreen);
verify(mCategory, never()).addPreference(any(Preference.class));
verify(mCategory).setTitle(null);
verify(mSeeAllPref).setTitle(R.string.applications_settings);
verify(mSeeAllPref).setIcon(null);
}
use of android.app.usage.UsageStats in project android_packages_apps_Settings by DirtyUnicorns.
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;
}
use of android.app.usage.UsageStats in project platform_packages_apps_Settings by BlissRoms.
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;
}
use of android.app.usage.UsageStats in project MusicLake by caiyonglong.
the class SystemUtils method isNoSwitch.
/**
* 判断调用该设备中“有权查看使用权限的应用”这个选项的APP有没有打开
*
* @return
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static boolean isNoSwitch() {
long dujinyang = System.currentTimeMillis();
UsageStatsManager usageStatsManager = (UsageStatsManager) MusicApp.getAppContext().getSystemService(Context.USAGE_STATS_SERVICE);
List<UsageStats> queryUsageStats = null;
if (usageStatsManager != null) {
queryUsageStats = usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, 0, dujinyang);
}
if (queryUsageStats == null || queryUsageStats.isEmpty()) {
return false;
}
return true;
}
use of android.app.usage.UsageStats in project robolectric by robolectric.
the class ShadowUsageStatsManagerTest method queryUsageStats.
@Test
public void queryUsageStats() {
UsageStats usageStats1 = newUsageStats(TEST_PACKAGE_NAME1, 0, 1000);
UsageStats usageStats2 = newUsageStats(TEST_PACKAGE_NAME1, 1001, 2000);
UsageStats usageStats3 = newUsageStats(TEST_PACKAGE_NAME1, 2001, 3000);
UsageStats usageStats4 = newUsageStats(TEST_PACKAGE_NAME1, 3001, 4000);
shadowOf(usageStatsManager).addUsageStats(INTERVAL_WEEKLY, usageStats1);
shadowOf(usageStatsManager).addUsageStats(INTERVAL_WEEKLY, usageStats2);
shadowOf(usageStatsManager).addUsageStats(INTERVAL_WEEKLY, usageStats3);
shadowOf(usageStatsManager).addUsageStats(INTERVAL_WEEKLY, usageStats4);
// Query fully covers usageStats 2 and 3, and partially overlaps with 4.
List<UsageStats> results = usageStatsManager.queryUsageStats(INTERVAL_WEEKLY, 1001, 3500);
assertThat(results).containsExactly(usageStats2, usageStats3, usageStats4);
}
Aggregations