Merge "Update fuelguage to use uid in AppInfo" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
6949175423
@@ -74,6 +74,7 @@ public class RestrictAppPreferenceController extends BasePreferenceController {
|
|||||||
final AppOpsManager.PackageOps packageOps = packageOpsList.get(i);
|
final AppOpsManager.PackageOps packageOps = packageOpsList.get(i);
|
||||||
mAppInfos.add(new AppInfo.Builder()
|
mAppInfos.add(new AppInfo.Builder()
|
||||||
.setPackageName(packageOps.getPackageName())
|
.setPackageName(packageOps.getPackageName())
|
||||||
|
.setUid(packageOps.getUid())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -130,19 +130,15 @@ public class RestrictedAppDetails extends DashboardFragment {
|
|||||||
appInfo.packageName, 0 /* flags */);
|
appInfo.packageName, 0 /* flags */);
|
||||||
checkBoxPreference.setChecked(true);
|
checkBoxPreference.setChecked(true);
|
||||||
checkBoxPreference.setTitle(mPackageManager.getApplicationLabel(applicationInfo));
|
checkBoxPreference.setTitle(mPackageManager.getApplicationLabel(applicationInfo));
|
||||||
checkBoxPreference.setKey(appInfo.packageName);
|
|
||||||
checkBoxPreference.setIcon(
|
checkBoxPreference.setIcon(
|
||||||
Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager,
|
Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager,
|
||||||
appInfo.packageName,
|
appInfo.packageName,
|
||||||
UserHandle.getUserId(
|
UserHandle.getUserId(appInfo.uid)));
|
||||||
mBatteryUtils.getPackageUid(appInfo.packageName))));
|
|
||||||
checkBoxPreference.setOnPreferenceChangeListener((pref, value) -> {
|
checkBoxPreference.setOnPreferenceChangeListener((pref, value) -> {
|
||||||
// change the toggle
|
// change the toggle
|
||||||
final int mode = (Boolean) value ? AppOpsManager.MODE_IGNORED
|
final int mode = (Boolean) value ? AppOpsManager.MODE_IGNORED
|
||||||
: AppOpsManager.MODE_ALLOWED;
|
: AppOpsManager.MODE_ALLOWED;
|
||||||
final String packageName = pref.getKey();
|
mBatteryUtils.setForceAppStandby(appInfo.uid, appInfo.packageName, mode);
|
||||||
final int uid = mBatteryUtils.getPackageUid(packageName);
|
|
||||||
mBatteryUtils.setForceAppStandby(uid, packageName, mode);
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
mRestrictedAppListGroup.addPreference(checkBoxPreference);
|
mRestrictedAppListGroup.addPreference(checkBoxPreference);
|
||||||
|
@@ -19,6 +19,7 @@ package com.android.settings.fuelgauge.batterytip;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.settings.fuelgauge.anomaly.Anomaly;
|
import com.android.settings.fuelgauge.anomaly.Anomaly;
|
||||||
|
|
||||||
@@ -74,6 +75,22 @@ public class AppInfo implements Comparable<AppInfo>, Parcelable {
|
|||||||
+ screenOnTimeMs;
|
+ 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 static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
|
||||||
public AppInfo createFromParcel(Parcel in) {
|
public AppInfo createFromParcel(Parcel in) {
|
||||||
return new AppInfo(in);
|
return new AppInfo(in);
|
||||||
|
@@ -76,7 +76,7 @@ public class HighUsageAdapter extends RecyclerView.Adapter<HighUsageAdapter.View
|
|||||||
final AppInfo app = mHighUsageAppList.get(position);
|
final AppInfo app = mHighUsageAppList.get(position);
|
||||||
holder.appIcon.setImageDrawable(
|
holder.appIcon.setImageDrawable(
|
||||||
Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager, app.packageName,
|
Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager, app.packageName,
|
||||||
UserHandle.myUserId()));
|
UserHandle.getUserId(app.uid)));
|
||||||
holder.appName.setText(Utils.getApplicationLabel(mContext, app.packageName));
|
holder.appName.setText(Utils.getApplicationLabel(mContext, app.packageName));
|
||||||
if (app.screenOnTimeMs != 0) {
|
if (app.screenOnTimeMs != 0) {
|
||||||
holder.appTime.setText(StringUtil.formatElapsedTime(mContext, app.screenOnTimeMs, false));
|
holder.appTime.setText(StringUtil.formatElapsedTime(mContext, app.screenOnTimeMs, false));
|
||||||
|
@@ -73,6 +73,7 @@ public class HighUsageDetector implements BatteryTipDetector {
|
|||||||
BatteryUtils.StatusType.FOREGROUND, batterySipper.uidObj,
|
BatteryUtils.StatusType.FOREGROUND, batterySipper.uidObj,
|
||||||
BatteryStats.STATS_SINCE_CHARGED);
|
BatteryStats.STATS_SINCE_CHARGED);
|
||||||
mHighUsageAppList.add(new AppInfo.Builder()
|
mHighUsageAppList.add(new AppInfo.Builder()
|
||||||
|
.setUid(batterySipper.getUid())
|
||||||
.setPackageName(
|
.setPackageName(
|
||||||
mBatteryUtils.getPackageName(batterySipper.getUid()))
|
mBatteryUtils.getPackageName(batterySipper.getUid()))
|
||||||
.setScreenOnTimeMs(foregroundTimeMs)
|
.setScreenOnTimeMs(foregroundTimeMs)
|
||||||
|
@@ -54,6 +54,7 @@ import java.util.List;
|
|||||||
public class RestrictedAppDetailsTest {
|
public class RestrictedAppDetailsTest {
|
||||||
|
|
||||||
private static final String PACKAGE_NAME = "com.android.app";
|
private static final String PACKAGE_NAME = "com.android.app";
|
||||||
|
private static final int UID = 234;
|
||||||
private static final String APP_NAME = "app";
|
private static final String APP_NAME = "app";
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
@@ -70,6 +71,7 @@ public class RestrictedAppDetailsTest {
|
|||||||
private InstrumentedPreferenceFragment mFragment;
|
private InstrumentedPreferenceFragment mFragment;
|
||||||
private RestrictedAppDetails mRestrictedAppDetails;
|
private RestrictedAppDetails mRestrictedAppDetails;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private AppInfo mAppInfo;
|
||||||
private Intent mIntent;
|
private Intent mIntent;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -78,19 +80,21 @@ public class RestrictedAppDetailsTest {
|
|||||||
|
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
mRestrictedAppDetails = spy(new RestrictedAppDetails());
|
mRestrictedAppDetails = spy(new RestrictedAppDetails());
|
||||||
|
mAppInfo = new AppInfo.Builder()
|
||||||
|
.setPackageName(PACKAGE_NAME)
|
||||||
|
.setUid(UID)
|
||||||
|
.build();
|
||||||
|
|
||||||
when(mRestrictedAppDetails.getPreferenceManager()).thenReturn(mPreferenceManager);
|
doReturn(mPreferenceManager).when(mRestrictedAppDetails).getPreferenceManager();
|
||||||
when(mPreferenceManager.getContext()).thenReturn(mContext);
|
doReturn(mContext).when(mPreferenceManager).getContext();
|
||||||
mRestrictedAppDetails.mPackageManager = mPackageManager;
|
mRestrictedAppDetails.mPackageManager = mPackageManager;
|
||||||
mRestrictedAppDetails.mIconDrawableFactory = mIconDrawableFactory;
|
mRestrictedAppDetails.mIconDrawableFactory = mIconDrawableFactory;
|
||||||
mRestrictedAppDetails.mAppInfos = new ArrayList<>();
|
mRestrictedAppDetails.mAppInfos = new ArrayList<>();
|
||||||
mRestrictedAppDetails.mAppInfos.add(new AppInfo.Builder()
|
mRestrictedAppDetails.mAppInfos.add(mAppInfo);
|
||||||
.setPackageName(PACKAGE_NAME)
|
|
||||||
.build());
|
|
||||||
mRestrictedAppDetails.mRestrictedAppListGroup = spy(new PreferenceCategory(mContext));
|
mRestrictedAppDetails.mRestrictedAppListGroup = spy(new PreferenceCategory(mContext));
|
||||||
mRestrictedAppDetails.mBatteryUtils = new BatteryUtils(mContext);
|
mRestrictedAppDetails.mBatteryUtils = new BatteryUtils(mContext);
|
||||||
when(mRestrictedAppDetails.mRestrictedAppListGroup.getPreferenceManager())
|
doReturn(mPreferenceManager).when(
|
||||||
.thenReturn(mPreferenceManager);
|
mRestrictedAppDetails.mRestrictedAppListGroup).getPreferenceManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -101,8 +105,8 @@ public class RestrictedAppDetailsTest {
|
|||||||
mRestrictedAppDetails.refreshUi();
|
mRestrictedAppDetails.refreshUi();
|
||||||
|
|
||||||
assertThat(mRestrictedAppDetails.mRestrictedAppListGroup.getPreferenceCount()).isEqualTo(1);
|
assertThat(mRestrictedAppDetails.mRestrictedAppListGroup.getPreferenceCount()).isEqualTo(1);
|
||||||
final Preference preference = mRestrictedAppDetails.mRestrictedAppListGroup.getPreference(0);
|
final Preference preference = mRestrictedAppDetails.mRestrictedAppListGroup.getPreference(
|
||||||
assertThat(preference.getKey()).isEqualTo(PACKAGE_NAME);
|
0);
|
||||||
assertThat(preference.getTitle()).isEqualTo(APP_NAME);
|
assertThat(preference.getTitle()).isEqualTo(APP_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,15 +119,14 @@ public class RestrictedAppDetailsTest {
|
|||||||
return true;
|
return true;
|
||||||
}).when(mSettingsActivity).startActivity(captor.capture());
|
}).when(mSettingsActivity).startActivity(captor.capture());
|
||||||
|
|
||||||
RestrictedAppDetails.
|
RestrictedAppDetails.startRestrictedAppDetails(mSettingsActivity, mFragment,
|
||||||
startRestrictedAppDetails(mSettingsActivity, mFragment, mRestrictedAppDetails.mAppInfos);
|
mRestrictedAppDetails.mAppInfos);
|
||||||
|
|
||||||
final Bundle bundle = mIntent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
|
final Bundle bundle = mIntent.getBundleExtra(
|
||||||
|
SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
|
||||||
// Verify the bundle has the correct info
|
// Verify the bundle has the correct info
|
||||||
final List<AppInfo> appInfos =
|
final List<AppInfo> appInfos = bundle.getParcelableArrayList(
|
||||||
bundle.getParcelableArrayList(RestrictedAppDetails.EXTRA_APP_INFO_LIST);
|
RestrictedAppDetails.EXTRA_APP_INFO_LIST);
|
||||||
assertThat(appInfos).isNotNull();
|
assertThat(appInfos).containsExactly(mAppInfo);
|
||||||
assertThat(appInfos).hasSize(1);
|
|
||||||
assertThat(appInfos.get(0).packageName).isEqualTo(PACKAGE_NAME);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,8 +29,10 @@ import android.text.format.DateUtils;
|
|||||||
import com.android.internal.os.BatterySipper;
|
import com.android.internal.os.BatterySipper;
|
||||||
import com.android.internal.os.BatteryStatsHelper;
|
import com.android.internal.os.BatteryStatsHelper;
|
||||||
import com.android.settings.fuelgauge.BatteryUtils;
|
import com.android.settings.fuelgauge.BatteryUtils;
|
||||||
|
import com.android.settings.fuelgauge.batterytip.AppInfo;
|
||||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
||||||
import com.android.settings.fuelgauge.batterytip.HighUsageDataParser;
|
import com.android.settings.fuelgauge.batterytip.HighUsageDataParser;
|
||||||
|
import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -46,7 +48,8 @@ import java.util.List;
|
|||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
public class HighUsageDetectorTest {
|
public class HighUsageDetectorTest {
|
||||||
|
private static final int UID = 123;
|
||||||
|
private static final long SCREEN_ON_TIME_MS = DateUtils.HOUR_IN_MILLIS;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@Mock
|
@Mock
|
||||||
private BatteryStatsHelper mBatteryStatsHelper;
|
private BatteryStatsHelper mBatteryStatsHelper;
|
||||||
@@ -57,6 +60,7 @@ public class HighUsageDetectorTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private HighUsageDataParser mDataParser;
|
private HighUsageDataParser mDataParser;
|
||||||
|
|
||||||
|
private AppInfo mAppInfo;
|
||||||
private BatteryTipPolicy mPolicy;
|
private BatteryTipPolicy mPolicy;
|
||||||
private HighUsageDetector mHighUsageDetector;
|
private HighUsageDetector mHighUsageDetector;
|
||||||
private List<BatterySipper> mUsageList;
|
private List<BatterySipper> mUsageList;
|
||||||
@@ -71,6 +75,11 @@ public class HighUsageDetectorTest {
|
|||||||
mHighUsageDetector.mBatteryUtils = mBatteryUtils;
|
mHighUsageDetector.mBatteryUtils = mBatteryUtils;
|
||||||
mHighUsageDetector.mDataParser = mDataParser;
|
mHighUsageDetector.mDataParser = mDataParser;
|
||||||
doNothing().when(mHighUsageDetector).parseBatteryData();
|
doNothing().when(mHighUsageDetector).parseBatteryData();
|
||||||
|
doReturn(UID).when(mBatterySipper).getUid();
|
||||||
|
mAppInfo = new AppInfo.Builder()
|
||||||
|
.setUid(UID)
|
||||||
|
.setScreenOnTimeMs(SCREEN_ON_TIME_MS)
|
||||||
|
.build();
|
||||||
|
|
||||||
mUsageList = new ArrayList<>();
|
mUsageList = new ArrayList<>();
|
||||||
mUsageList.add(mBatterySipper);
|
mUsageList.add(mBatterySipper);
|
||||||
@@ -87,10 +96,12 @@ public class HighUsageDetectorTest {
|
|||||||
public void testDetect_containsHighUsageApp_tipVisible() {
|
public void testDetect_containsHighUsageApp_tipVisible() {
|
||||||
doReturn(true).when(mDataParser).isDeviceHeavilyUsed();
|
doReturn(true).when(mDataParser).isDeviceHeavilyUsed();
|
||||||
when(mBatteryStatsHelper.getUsageList()).thenReturn(mUsageList);
|
when(mBatteryStatsHelper.getUsageList()).thenReturn(mUsageList);
|
||||||
doReturn(DateUtils.HOUR_IN_MILLIS).when(mBatteryUtils).getProcessTimeMs(
|
doReturn(SCREEN_ON_TIME_MS).when(mBatteryUtils).getProcessTimeMs(
|
||||||
BatteryUtils.StatusType.FOREGROUND, mBatterySipper.uidObj,
|
BatteryUtils.StatusType.FOREGROUND, mBatterySipper.uidObj,
|
||||||
BatteryStats.STATS_SINCE_CHARGED);
|
BatteryStats.STATS_SINCE_CHARGED);
|
||||||
|
|
||||||
assertThat(mHighUsageDetector.detect().isVisible()).isTrue();
|
final HighUsageTip highUsageTip = (HighUsageTip) mHighUsageDetector.detect();
|
||||||
|
assertThat(highUsageTip.isVisible()).isTrue();
|
||||||
|
assertThat(highUsageTip.getHighUsageAppList()).containsExactly(mAppInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user