Merge "Update fuelguage to use uid in AppInfo" into pi-dev

This commit is contained in:
TreeHugger Robot
2018-03-08 03:22:40 +00:00
committed by Android (Google) Code Review
7 changed files with 76 additions and 47 deletions

View File

@@ -74,6 +74,7 @@ public class RestrictAppPreferenceController extends BasePreferenceController {
final AppOpsManager.PackageOps packageOps = packageOpsList.get(i);
mAppInfos.add(new AppInfo.Builder()
.setPackageName(packageOps.getPackageName())
.setUid(packageOps.getUid())
.build());
}

View File

@@ -130,19 +130,15 @@ public class RestrictedAppDetails extends DashboardFragment {
appInfo.packageName, 0 /* flags */);
checkBoxPreference.setChecked(true);
checkBoxPreference.setTitle(mPackageManager.getApplicationLabel(applicationInfo));
checkBoxPreference.setKey(appInfo.packageName);
checkBoxPreference.setIcon(
Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager,
appInfo.packageName,
UserHandle.getUserId(
mBatteryUtils.getPackageUid(appInfo.packageName))));
UserHandle.getUserId(appInfo.uid)));
checkBoxPreference.setOnPreferenceChangeListener((pref, value) -> {
// change the toggle
final int mode = (Boolean) value ? AppOpsManager.MODE_IGNORED
: AppOpsManager.MODE_ALLOWED;
final String packageName = pref.getKey();
final int uid = mBatteryUtils.getPackageUid(packageName);
mBatteryUtils.setForceAppStandby(uid, packageName, mode);
mBatteryUtils.setForceAppStandby(appInfo.uid, appInfo.packageName, mode);
return true;
});
mRestrictedAppListGroup.addPreference(checkBoxPreference);

View File

@@ -19,6 +19,7 @@ package com.android.settings.fuelgauge.batterytip;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import com.android.settings.fuelgauge.anomaly.Anomaly;
@@ -74,6 +75,22 @@ public class AppInfo implements Comparable<AppInfo>, Parcelable {
+ screenOnTimeMs;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof AppInfo)) {
return false;
}
AppInfo other = (AppInfo) obj;
return anomalyType == other.anomalyType
&& uid == other.uid
&& screenOnTimeMs == other.screenOnTimeMs
&& TextUtils.equals(packageName, other.packageName);
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public AppInfo createFromParcel(Parcel in) {
return new AppInfo(in);

View File

@@ -76,7 +76,7 @@ public class HighUsageAdapter extends RecyclerView.Adapter<HighUsageAdapter.View
final AppInfo app = mHighUsageAppList.get(position);
holder.appIcon.setImageDrawable(
Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager, app.packageName,
UserHandle.myUserId()));
UserHandle.getUserId(app.uid)));
holder.appName.setText(Utils.getApplicationLabel(mContext, app.packageName));
if (app.screenOnTimeMs != 0) {
holder.appTime.setText(StringUtil.formatElapsedTime(mContext, app.screenOnTimeMs, false));

View File

@@ -73,6 +73,7 @@ public class HighUsageDetector implements BatteryTipDetector {
BatteryUtils.StatusType.FOREGROUND, batterySipper.uidObj,
BatteryStats.STATS_SINCE_CHARGED);
mHighUsageAppList.add(new AppInfo.Builder()
.setUid(batterySipper.getUid())
.setPackageName(
mBatteryUtils.getPackageName(batterySipper.getUid()))
.setScreenOnTimeMs(foregroundTimeMs)