use of android.app.usage.UsageStats in project robolectric by robolectric.
the class ShadowUsageStatsManagerTest method usageStatsBuilder_noFieldsSet.
@Test
public void usageStatsBuilder_noFieldsSet() {
UsageStats usage = UsageStatsBuilder.newBuilder().build();
assertThat(usage.getPackageName()).isNull();
assertThat(usage.getFirstTimeStamp()).isEqualTo(0);
assertThat(usage.getLastTimeStamp()).isEqualTo(0);
assertThat(usage.getLastTimeUsed()).isEqualTo(0);
assertThat(usage.getTotalTimeInForeground()).isEqualTo(0);
}
use of android.app.usage.UsageStats in project robolectric by robolectric.
the class ShadowUsageStatsManagerTest method usageStatsBuilder.
@Test
public void usageStatsBuilder() {
long firstTimestamp = 1_500_000_000_000L;
long lastTimestamp = firstTimestamp + 10000;
long lastTimeUsed = firstTimestamp + 100;
long totalTimeInForeground = HOURS.toMillis(10);
UsageStats usage = UsageStatsBuilder.newBuilder().setPackageName(TEST_PACKAGE_NAME1).setFirstTimeStamp(firstTimestamp).setLastTimeStamp(lastTimestamp).setLastTimeUsed(lastTimeUsed).setTotalTimeInForeground(totalTimeInForeground).build();
assertThat(usage.getPackageName()).isEqualTo(TEST_PACKAGE_NAME1);
assertThat(usage.getFirstTimeStamp()).isEqualTo(firstTimestamp);
assertThat(usage.getLastTimeStamp()).isEqualTo(lastTimestamp);
assertThat(usage.getLastTimeUsed()).isEqualTo(lastTimeUsed);
assertThat(usage.getTotalTimeInForeground()).isEqualTo(totalTimeInForeground);
}
use of android.app.usage.UsageStats in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RecentAppStatsMixinTest method loadDisplayableRecentApps_hiddenSystemModuleSet_shouldNotHaveHiddenSystemModule.
@Test
public void loadDisplayableRecentApps_hiddenSystemModuleSet_shouldNotHaveHiddenSystemModule() {
final List<UsageStats> stats = new ArrayList<>();
// Regular app.
final UsageStats stat1 = new UsageStats();
stat1.mLastTimeUsed = System.currentTimeMillis();
stat1.mPackageName = "com.foo.bar";
stats.add(stat1);
// Hidden system module.
final UsageStats stat2 = new UsageStats();
stat2.mLastTimeUsed = System.currentTimeMillis() + 200;
stat2.mPackageName = "com.foo.hidden";
stats.add(stat2);
ApplicationsState.AppEntry stat1Entry = mock(ApplicationsState.AppEntry.class);
ApplicationsState.AppEntry stat2Entry = mock(ApplicationsState.AppEntry.class);
stat1Entry.info = mApplicationInfo;
stat2Entry.info = mApplicationInfo;
when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId())).thenReturn(stat1Entry);
when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId())).thenReturn(stat2Entry);
final ModuleInfo moduleInfo1 = new ModuleInfo();
moduleInfo1.setPackageName(stat1.mPackageName);
moduleInfo1.setHidden(false);
final ModuleInfo moduleInfo2 = new ModuleInfo();
moduleInfo2.setPackageName(stat2.mPackageName);
moduleInfo2.setHidden(true);
ReflectionHelpers.setStaticField(ApplicationsState.class, "sInstance", null);
final List<ModuleInfo> modules = new ArrayList<>();
modules.add(moduleInfo2);
when(mPackageManager.getInstalledModules(anyInt())).thenReturn(modules);
when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(new ResolveInfo());
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong())).thenReturn(stats);
mRecentAppStatsMixin.loadDisplayableRecentApps(3);
assertThat(mRecentAppStatsMixin.mRecentApps.size()).isEqualTo(1);
}
use of android.app.usage.UsageStats in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RecentAppStatsMixinTest method loadDisplayableRecentApps_oneInstantAppSet_shouldHaveOneRecentApp.
@Test
public void loadDisplayableRecentApps_oneInstantAppSet_shouldHaveOneRecentApp() {
final List<UsageStats> stats = new ArrayList<>();
// Instant app.
final UsageStats stat = new UsageStats();
stat.mLastTimeUsed = System.currentTimeMillis() + 200;
stat.mPackageName = "com.foo.barinstant";
stats.add(stat);
ApplicationsState.AppEntry statEntry = mock(ApplicationsState.AppEntry.class);
statEntry.info = mApplicationInfo;
when(mAppState.getEntry(stat.mPackageName, UserHandle.myUserId())).thenReturn(statEntry);
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong())).thenReturn(stats);
// Make sure stat is considered an instant app.
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider", (InstantAppDataProvider) (ApplicationInfo info) -> info == statEntry.info);
mRecentAppStatsMixin.loadDisplayableRecentApps(3);
assertThat(mRecentAppStatsMixin.mRecentApps.size()).isEqualTo(1);
}
use of android.app.usage.UsageStats in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RecentAppStatsMixinTest method loadDisplayableRecentApps_oneValidRecentAppSet_shouldHaveOneRecentApp.
@Test
public void loadDisplayableRecentApps_oneValidRecentAppSet_shouldHaveOneRecentApp() {
final List<UsageStats> stats = new ArrayList<>();
final UsageStats stat1 = new UsageStats();
stat1.mLastTimeUsed = System.currentTimeMillis();
stat1.mPackageName = "pkg.class";
stats.add(stat1);
// stat1 is valid app.
when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId())).thenReturn(mAppEntry);
when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(new ResolveInfo());
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong())).thenReturn(stats);
mAppEntry.info = mApplicationInfo;
mRecentAppStatsMixin.loadDisplayableRecentApps(3);
assertThat(mRecentAppStatsMixin.mRecentApps.size()).isEqualTo(1);
}
Aggregations