Search in sources :

Example 36 with UsageStats

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

Example 37 with UsageStats

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;
}
Also used : ApplicationsState(com.android.settingslib.applications.ApplicationsState) ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap) UsageStats(android.app.usage.UsageStats)

Example 38 with UsageStats

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;
}
Also used : ApplicationsState(com.android.settingslib.applications.ApplicationsState) ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap) UsageStats(android.app.usage.UsageStats)

Example 39 with UsageStats

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;
}
Also used : UsageStatsManager(android.app.usage.UsageStatsManager) UsageStats(android.app.usage.UsageStats) RequiresApi(android.support.annotation.RequiresApi)

Example 40 with UsageStats

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);
}
Also used : 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