Update fuelguage to use uid in AppInfo
The uid is needed to distinguish the same app used by different users(even work profile user). So we need to store the correct uid in AppInfo and use it across the settings app. Bug: 74022362 Test: RunSettingsRoboTests Change-Id: Iaa0ea1ac1fbd3a3a1251e0cd1096d6a8c75c4ed8
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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));
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user