Search in sources :

Example 41 with UsageStats

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);
}
Also used : UsageStats(android.app.usage.UsageStats) Test(org.junit.Test)

Example 42 with UsageStats

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);
}
Also used : UsageStats(android.app.usage.UsageStats) Test(org.junit.Test)

Example 43 with UsageStats

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);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ModuleInfo(android.content.pm.ModuleInfo) ApplicationsState(com.android.settingslib.applications.ApplicationsState) ArrayList(java.util.ArrayList) Intent(android.content.Intent) UsageStats(android.app.usage.UsageStats) Test(org.junit.Test)

Example 44 with UsageStats

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);
}
Also used : ApplicationsState(com.android.settingslib.applications.ApplicationsState) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) UsageStats(android.app.usage.UsageStats) Test(org.junit.Test)

Example 45 with UsageStats

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);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ArrayList(java.util.ArrayList) Intent(android.content.Intent) UsageStats(android.app.usage.UsageStats) Test(org.junit.Test)

Aggregations

UsageStats (android.app.usage.UsageStats)98 ArrayList (java.util.ArrayList)45 Test (org.junit.Test)38 Intent (android.content.Intent)35 ResolveInfo (android.content.pm.ResolveInfo)33 Configuration (android.content.res.Configuration)20 ApplicationsState (com.android.settingslib.applications.ApplicationsState)19 Preference (android.support.v7.preference.Preference)18 ArrayMap (android.util.ArrayMap)16 UsageStatsManager (android.app.usage.UsageStatsManager)13 ApplicationInfo (android.content.pm.ApplicationInfo)7 PackageManager (android.content.pm.PackageManager)6 ActivityManager (android.app.ActivityManager)5 AppOpsManager (android.app.AppOpsManager)5 ResolvedComponentInfo (com.android.internal.app.ResolverActivity.ResolvedComponentInfo)5 TargetApi (android.annotation.TargetApi)4 ConfigurationStats (android.app.usage.ConfigurationStats)4 UsageEvents (android.app.usage.UsageEvents)4 Event (android.app.usage.UsageEvents.Event)4 ArraySet (android.util.ArraySet)4