Disable recently used apps in battery saver mode.

UsageStats query is too slow.

Change-Id: I53fa13924514e71221d3a6407139ff00ae5eb378
Fixes: 114788699
Test: robotests
This commit is contained in:
Fan Zhang
2018-09-21 14:14:16 -07:00
parent a114c09c7a
commit 2a1e59063d
2 changed files with 44 additions and 6 deletions

View File

@@ -25,6 +25,7 @@ import android.app.usage.UsageStatsManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.PowerManager;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.ArrayMap;
@@ -78,6 +79,7 @@ public class RecentAppsPreferenceController extends AbstractPreferenceController
private final ApplicationsState mApplicationsState;
private final int mUserId;
private final IconDrawableFactory mIconDrawableFactory;
private final PowerManager mPowerManager;
private Calendar mCal;
private List<UsageStats> mStats;
@@ -108,6 +110,8 @@ public class RecentAppsPreferenceController extends AbstractPreferenceController
mIconDrawableFactory = IconDrawableFactory.newInstance(context);
mUserId = UserHandle.myUserId();
mPm = context.getPackageManager();
mPowerManager = context.getSystemService(PowerManager.class);
mHost = host;
mUsageStatsManager =
(UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
@@ -183,9 +187,11 @@ public class RecentAppsPreferenceController extends AbstractPreferenceController
void reloadData() {
mCal = Calendar.getInstance();
mCal.add(Calendar.DAY_OF_YEAR, -1);
mStats = mUsageStatsManager.queryUsageStats(
UsageStatsManager.INTERVAL_BEST, mCal.getTimeInMillis(),
System.currentTimeMillis());
mStats = mPowerManager.isPowerSaveMode()
? new ArrayList<>()
: mUsageStatsManager.queryUsageStats(
UsageStatsManager.INTERVAL_BEST, mCal.getTimeInMillis(),
System.currentTimeMillis());
}
private void displayOnlyAppInfo() {
@@ -244,8 +250,8 @@ public class RecentAppsPreferenceController extends AbstractPreferenceController
pref.setOrder(i);
pref.setOnPreferenceClickListener(preference -> {
AppInfoBase.startAppInfoFragment(AppInfoDashboardFragment.class,
R.string.application_info_label, pkgName, appEntry.info.uid, mHost,
1001 /*RequestCode*/, SETTINGS_APP_NOTIF_CATEGORY);
R.string.application_info_label, pkgName, appEntry.info.uid, mHost,
1001 /*RequestCode*/, SETTINGS_APP_NOTIF_CATEGORY);
return true;
});
if (!rebindPref) {
@@ -301,7 +307,8 @@ public class RecentAppsPreferenceController extends AbstractPreferenceController
private boolean shouldIncludePkgInRecents(UsageStats stat) {
final String pkgName = stat.getPackageName();
if (stat.getLastTimeUsed() < mCal.getTimeInMillis()) {
Log.d(TAG, "Invalid timestamp, skipping " + pkgName);
Log.d(TAG, "Invalid timestamp (usage time is more than 24 hours ago), skipping "
+ pkgName);
return false;
}