Merge "[Settings] Code refactor for device without SIM"
diff --git a/res/xml/network_provider_internet.xml b/res/xml/network_provider_internet.xml
index 981afb3..a4b5faa 100644
--- a/res/xml/network_provider_internet.xml
+++ b/res/xml/network_provider_internet.xml
@@ -42,7 +42,7 @@
settings:keywords="@string/calls_and_sms"
settings:useAdminDisabledSummary="true" />
- <com.android.settings.widget.AddPreference
+ <com.android.settingslib.RestrictedPreference
android:key="mobile_network_list"
android:title="@string/provider_network_settings_title"
android:summary="@string/summary_placeholder"
diff --git a/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceController.java b/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceController.java
index 3ea8cb4..b75853d 100644
--- a/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceController.java
@@ -72,6 +72,9 @@
@Override
public int getAvailabilityStatus() {
+ if (getSimSlotIndex() == SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
+ return UNSUPPORTED_ON_DEVICE;
+ }
boolean isAvailable = SubscriptionUtil.isSimHardwareVisible(mContext) &&
mContext.getSystemService(UserManager.class).isAdminUser() &&
!Utils.isWifiOnly(mContext);
@@ -81,7 +84,7 @@
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
- if (!SubscriptionUtil.isSimHardwareVisible(mContext)) {
+ if ((!SubscriptionUtil.isSimHardwareVisible(mContext)) || (mSlotSimStatus == null)) {
return;
}
String basePreferenceKey = mSlotSimStatus.getPreferenceKey(
@@ -133,17 +136,23 @@
R.string.sim_status_title);
}
- private CharSequence getCarrierName(int simSlot) {
+ private SubscriptionInfo getSubscriptionInfo(int simSlot) {
final List<SubscriptionInfo> subscriptionInfoList =
mSubscriptionManager.getActiveSubscriptionInfoList();
if (subscriptionInfoList != null) {
for (SubscriptionInfo info : subscriptionInfoList) {
if (info.getSimSlotIndex() == simSlot) {
- return info.getCarrierName();
+ return info;
}
}
}
- return mContext.getText(R.string.device_info_not_available);
+ return null;
+ }
+
+ private CharSequence getCarrierName(int simSlot) {
+ SubscriptionInfo subInfo = getSubscriptionInfo(simSlot);
+ return (subInfo != null) ? subInfo.getCarrierName() :
+ mContext.getText(R.string.device_info_not_available);
}
@VisibleForTesting
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffData.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffData.java
index b5d4dde..caf2cf3 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffData.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffData.java
@@ -26,23 +26,14 @@
private final List<BatteryDiffEntry> mAppEntries;
private final List<BatteryDiffEntry> mSystemEntries;
- /** Constructor for the diff entries which already have totalConsumePower value. */
+ /** Constructor for the diff entries. */
public BatteryDiffData(
@NonNull List<BatteryDiffEntry> appDiffEntries,
@NonNull List<BatteryDiffEntry> systemDiffEntries) {
mAppEntries = appDiffEntries;
mSystemEntries = systemDiffEntries;
- sortEntries();
- }
-
- /** Constructor for the diff entries which have not set totalConsumePower value. */
- public BatteryDiffData(
- @NonNull List<BatteryDiffEntry> appDiffEntries,
- @NonNull List<BatteryDiffEntry> systemDiffEntries,
- final double totalConsumePower) {
- mAppEntries = appDiffEntries;
- mSystemEntries = systemDiffEntries;
- setTotalConsumePowerForAllEntries(totalConsumePower);
+ setTotalConsumePowerForAllEntries(mAppEntries);
+ setTotalConsumePowerForAllEntries(mSystemEntries);
sortEntries();
}
@@ -55,9 +46,14 @@
}
// Sets total consume power for each entry.
- private void setTotalConsumePowerForAllEntries(final double totalConsumePower) {
- mAppEntries.forEach(diffEntry -> diffEntry.setTotalConsumePower(totalConsumePower));
- mSystemEntries.forEach(diffEntry -> diffEntry.setTotalConsumePower(totalConsumePower));
+ private void setTotalConsumePowerForAllEntries(List<BatteryDiffEntry> batteryDiffEntries) {
+ double totalConsumePower = 0.0;
+ for (BatteryDiffEntry batteryDiffEntry : batteryDiffEntries) {
+ totalConsumePower += batteryDiffEntry.mConsumePower;
+ }
+ for (BatteryDiffEntry batteryDiffEntry : batteryDiffEntries) {
+ batteryDiffEntry.setTotalConsumePower(totalConsumePower);
+ }
}
// Sorts entries based on consumed percentage.
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryEntry.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryEntry.java
index 2b56cc1..e9e0347 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryEntry.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryEntry.java
@@ -200,16 +200,13 @@
/** Battery entry for a power component of AggregateBatteryConsumer */
public BatteryEntry(Context context, int powerComponentId, double devicePowerMah,
- double appsPowerMah, long usageDurationMs) {
+ long usageDurationMs) {
mContext = context;
mBatteryConsumer = null;
mUid = Process.INVALID_UID;
mIsHidden = false;
mPowerComponentId = powerComponentId;
- mConsumedPower =
- powerComponentId == BatteryConsumer.POWER_COMPONENT_SCREEN
- ? devicePowerMah
- : devicePowerMah - appsPowerMah;
+ mConsumedPower = devicePowerMah;
mUsageDurationMs = usageDurationMs;
mConsumerType = ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY;
@@ -224,7 +221,7 @@
/** Battery entry for a custom power component of AggregateBatteryConsumer */
public BatteryEntry(Context context, int powerComponentId, String powerComponentName,
- double devicePowerMah, double appsPowerMah) {
+ double devicePowerMah) {
mContext = context;
mBatteryConsumer = null;
mUid = Process.INVALID_UID;
@@ -234,10 +231,7 @@
mIconId = R.drawable.ic_power_system;
mIcon = context.getDrawable(mIconId);
mName = powerComponentName;
- mConsumedPower =
- powerComponentId == BatteryConsumer.POWER_COMPONENT_SCREEN
- ? devicePowerMah
- : devicePowerMah - appsPowerMah;
+ mConsumedPower = devicePowerMah;
mConsumerType = ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY;
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java b/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java
index b510e5b..0f02d1c 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java
@@ -372,7 +372,7 @@
@VisibleForTesting
static long[] findNearestTimestamp(final List<Long> timestamps, final long target) {
- final long[] results = new long[] {Long.MIN_VALUE, Long.MAX_VALUE};
+ final long[] results = new long[]{Long.MIN_VALUE, Long.MAX_VALUE};
// Searches the nearest lower and upper timestamp value.
timestamps.forEach(timestamp -> {
if (timestamp <= target && timestamp > results[0]) {
@@ -398,7 +398,7 @@
}
/**
- * Returns whether currentSlot will be used in daily chart.
+ * Returns whether currentSlot will be used in daily chart.
*/
@VisibleForTesting
static boolean isForDailyChart(final boolean isStartOrEnd, final long currentSlot) {
@@ -468,13 +468,11 @@
userHandle != null ? userHandle.getIdentifier() : Integer.MIN_VALUE;
final List<BatteryDiffEntry> appEntries = new ArrayList<>();
final List<BatteryDiffEntry> systemEntries = new ArrayList<>();
- double totalConsumePower = 0f;
double consumePowerFromOtherUsers = 0f;
for (BatteryHistEntry entry : batteryHistEntryList) {
final boolean isFromOtherUsers = isConsumedFromOtherUsers(
currentUserId, workProfileUserId, entry);
- totalConsumePower += entry.mConsumePower;
if (isFromOtherUsers) {
consumePowerFromOtherUsers += entry.mConsumePower;
} else {
@@ -504,7 +502,7 @@
return null;
}
- return new BatteryDiffData(appEntries, systemEntries, totalConsumePower);
+ return new BatteryDiffData(appEntries, systemEntries);
}
/**
@@ -588,9 +586,7 @@
|| (entry.getConsumedPower() == 0
&& (foregroundMs != 0 || backgroundMs != 0));
})
- .map(entry -> ConvertUtils.convertToBatteryHistEntry(
- entry,
- batteryUsageStats))
+ .map(entry -> ConvertUtils.convertToBatteryHistEntry(entry, batteryUsageStats))
.collect(Collectors.toList());
}
@@ -949,7 +945,6 @@
allBatteryHistEntryKeys.addAll(nextBatteryHistMap.keySet());
allBatteryHistEntryKeys.addAll(nextTwoBatteryHistMap.keySet());
- double totalConsumePower = 0.0;
double consumePowerFromOtherUsers = 0f;
// Calculates all packages diff usage data in a specific time slot.
for (String key : allBatteryHistEntryKeys) {
@@ -1028,7 +1023,6 @@
backgroundUsageConsumePower = backgroundUsageConsumePower * ratio;
cachedUsageConsumePower = cachedUsageConsumePower * ratio;
}
- totalConsumePower += consumePower;
final boolean isFromOtherUsers = isConsumedFromOtherUsers(
currentUserId, workProfileUserId, selectedBatteryEntry);
@@ -1061,9 +1055,7 @@
return null;
}
- final BatteryDiffData resultDiffData =
- new BatteryDiffData(appEntries, systemEntries, totalConsumePower);
- return resultDiffData;
+ return new BatteryDiffData(appEntries, systemEntries);
}
private static boolean isConsumedFromOtherUsers(
@@ -1078,7 +1070,6 @@
@Nullable
private static BatteryDiffData getAccumulatedUsageDiffData(
final Collection<BatteryDiffData> diffEntryListData) {
- double totalConsumePower = 0f;
final Map<String, BatteryDiffEntry> diffEntryMap = new HashMap<>();
final List<BatteryDiffEntry> appEntries = new ArrayList<>();
final List<BatteryDiffEntry> systemEntries = new ArrayList<>();
@@ -1089,18 +1080,14 @@
}
for (BatteryDiffEntry entry : diffEntryList.getAppDiffEntryList()) {
computeUsageDiffDataPerEntry(entry, diffEntryMap);
- totalConsumePower += entry.mConsumePower;
}
for (BatteryDiffEntry entry : diffEntryList.getSystemDiffEntryList()) {
computeUsageDiffDataPerEntry(entry, diffEntryMap);
- totalConsumePower += entry.mConsumePower;
}
}
final Collection<BatteryDiffEntry> diffEntryList = diffEntryMap.values();
for (BatteryDiffEntry entry : diffEntryList) {
- // Sets total daily consume power data into all BatteryDiffEntry.
- entry.setTotalConsumePower(totalConsumePower);
if (entry.isSystemEntry()) {
systemEntries.add(entry);
} else {
@@ -1243,14 +1230,11 @@
final BatteryConsumer deviceConsumer = batteryUsageStats.getAggregateBatteryConsumer(
BatteryUsageStats.AGGREGATE_BATTERY_CONSUMER_SCOPE_DEVICE);
- final BatteryConsumer appsConsumer = batteryUsageStats.getAggregateBatteryConsumer(
- BatteryUsageStats.AGGREGATE_BATTERY_CONSUMER_SCOPE_ALL_APPS);
for (int componentId = 0; componentId < BatteryConsumer.POWER_COMPONENT_COUNT;
componentId++) {
results.add(new BatteryEntry(context, componentId,
deviceConsumer.getConsumedPower(componentId),
- appsConsumer.getConsumedPower(componentId),
deviceConsumer.getUsageDurationMillis(componentId)));
}
@@ -1260,8 +1244,7 @@
componentId++) {
results.add(new BatteryEntry(context, componentId,
deviceConsumer.getCustomPowerComponentName(componentId),
- deviceConsumer.getConsumedPowerForCustomComponent(componentId),
- appsConsumer.getConsumedPowerForCustomComponent(componentId)));
+ deviceConsumer.getConsumedPowerForCustomComponent(componentId)));
}
final List<UserBatteryConsumer> userBatteryConsumers =
diff --git a/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
index 805821f..c7cf70e 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
@@ -34,8 +34,6 @@
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
-import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.SearchIndexable;
@@ -61,7 +59,6 @@
new BatteryHistoryLoaderCallbacks();
private boolean mIsChartDataLoaded = false;
- private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
private BatteryChartPreferenceController mBatteryChartPreferenceController;
private final ContentObserver mBatteryObserver =
@@ -78,9 +75,7 @@
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
- final Context context = getContext();
- refreshFeatureFlag(context);
- mHistPref = (BatteryHistoryPreference) findPreference(KEY_BATTERY_CHART);
+ mHistPref = findPreference(KEY_BATTERY_CHART);
setBatteryChartPreferenceController();
}
@@ -130,7 +125,6 @@
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
- refreshFeatureFlag(context);
final List<AbstractPreferenceController> controllers = new ArrayList<>();
mBatteryChartPreferenceController =
new BatteryChartPreferenceController(
@@ -176,13 +170,6 @@
}
}
- private void refreshFeatureFlag(Context context) {
- if (mPowerUsageFeatureProvider == null) {
- mPowerUsageFeatureProvider = FeatureFactory.getFactory(context)
- .getPowerUsageFeatureProvider(context);
- }
- }
-
private void setBatteryChartPreferenceController() {
if (mHistPref != null && mBatteryChartPreferenceController != null) {
mHistPref.setChartPreferenceController(mBatteryChartPreferenceController);
diff --git a/src/com/android/settings/network/MobileNetworkSummaryController.java b/src/com/android/settings/network/MobileNetworkSummaryController.java
index 0bb1bb3..0e2ea09 100644
--- a/src/com/android/settings/network/MobileNetworkSummaryController.java
+++ b/src/com/android/settings/network/MobileNetworkSummaryController.java
@@ -37,7 +37,7 @@
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.widget.AddPreference;
+import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.Utils;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -58,7 +58,7 @@
private final MetricsFeatureProvider mMetricsFeatureProvider;
private UserManager mUserManager;
- private AddPreference mPreference;
+ private RestrictedPreference mPreference;
private MobileNetworkRepository mMobileNetworkRepository;
private List<SubscriptionInfoEntity> mSubInfoEntityList;
@@ -89,6 +89,7 @@
mUserManager = context.getSystemService(UserManager.class);
mLifecycleOwner = lifecycleOwner;
mMobileNetworkRepository = MobileNetworkRepository.create(context, this);
+ mIsAirplaneModeOn = mMobileNetworkRepository.isAirplaneModeOn();
if (lifecycle != null) {
lifecycle.addObserver(this);
}
@@ -152,7 +153,6 @@
private void initPreference() {
refreshSummary(mPreference);
mPreference.setOnPreferenceClickListener(null);
- mPreference.setOnAddClickListener(null);
mPreference.setFragment(null);
mPreference.setEnabled(!mIsAirplaneModeOn);
}
@@ -179,33 +179,7 @@
return;
}
- // We have one or more existing subscriptions, so we want the plus button if eSIM is
- // supported.
- if (MobileNetworkUtils.showEuiccSettingsDetecting(mContext)) {
- mPreference.setAddWidgetEnabled(!mIsAirplaneModeOn);
- mPreference.setOnAddClickListener(p -> {
- logPreferenceClick(p);
- startAddSimFlow();
- });
- }
-
- if (mSubInfoEntityList.size() == 1) {
- mPreference.setOnPreferenceClickListener((Preference pref) -> {
- logPreferenceClick(pref);
- SubscriptionInfoEntity info = mSubInfoEntityList.get(0);
- if (info.isEmbedded || mUiccInfoEntityList.get(0).isActive
- || mMobileNetworkInfoEntityList.get(0).showToggleForPhysicalSim) {
- MobileNetworkUtils.launchMobileNetworkSettings(mContext, info);
- return true;
- }
-
- SubscriptionUtil.startToggleSubscriptionDialogActivity(
- mContext, Integer.parseInt(info.subId), true);
- return true;
- });
- } else {
- mPreference.setFragment(MobileNetworkListFragment.class.getCanonicalName());
- }
+ mPreference.setFragment(MobileNetworkListFragment.class.getCanonicalName());
}
@Override
@@ -221,8 +195,10 @@
@Override
public void onAirplaneModeChanged(boolean airplaneModeEnabled) {
- mIsAirplaneModeOn = airplaneModeEnabled;
- update();
+ if (mIsAirplaneModeOn != airplaneModeEnabled) {
+ mIsAirplaneModeOn = airplaneModeEnabled;
+ update();
+ }
}
@Override
@@ -239,14 +215,19 @@
@Override
public void onAllUiccInfoChanged(List<UiccInfoEntity> uiccInfoEntityList) {
- mUiccInfoEntityList = uiccInfoEntityList;
- update();
+ if (DataServiceUtils.shouldUpdateEntityList(mUiccInfoEntityList, uiccInfoEntityList)) {
+ mUiccInfoEntityList = uiccInfoEntityList;
+ update();
+ }
}
@Override
public void onAllMobileNetworkInfoChanged(
List<MobileNetworkInfoEntity> mobileNetworkInfoEntityList) {
- mMobileNetworkInfoEntityList = mobileNetworkInfoEntityList;
- update();
+ if (DataServiceUtils.shouldUpdateEntityList(mMobileNetworkInfoEntityList,
+ mobileNetworkInfoEntityList)) {
+ mMobileNetworkInfoEntityList = mobileNetworkInfoEntityList;
+ update();
+ }
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryEntryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryEntryTest.java
index 90fa572..463a66d 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryEntryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryEntryTest.java
@@ -104,11 +104,19 @@
}
private BatteryEntry createAggregateBatteryEntry(int powerComponentId) {
- return new BatteryEntry(mMockContext, powerComponentId, 200, 100, 1000);
+ return new BatteryEntry(
+ mMockContext,
+ powerComponentId,
+ /* devicePowerMah= */ 200,
+ /* usageDurationMs= */ 1000);
}
private BatteryEntry createCustomAggregateBatteryEntry(int powerComponentId) {
- return new BatteryEntry(mMockContext, powerComponentId, "CUSTOM", 200, 100);
+ return new BatteryEntry(
+ mMockContext,
+ powerComponentId,
+ /* powerComponentName= */ "CUSTOM",
+ /* devicePowerMah= */ 200);
}
private BatteryEntry createUserBatteryConsumer(int userId) {
@@ -159,7 +167,9 @@
@Test
public void batteryEntryForAOD_containCorrectInfo() {
final BatteryEntry entry = new BatteryEntry(RuntimeEnvironment.application,
- BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY, 200, 100, 1000);
+ BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY,
+ /* devicePowerMah= */ 200,
+ /* usageDurationMs= */ 1000);
assertThat(entry.mIconId).isEqualTo(R.drawable.ic_settings_aod);
assertThat(entry.mName).isEqualTo("Ambient display");
@@ -168,7 +178,9 @@
@Test
public void batteryEntryForCustomComponent_containCorrectInfo() {
final BatteryEntry entry = new BatteryEntry(RuntimeEnvironment.application,
- BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID + 42, "ABC", 200, 100);
+ BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID + 42,
+ /* powerComponentName= */ "ABC",
+ /* devicePowerMah= */ 200);
assertThat(entry.mIconId).isEqualTo(R.drawable.ic_power_system);
assertThat(entry.mName).isEqualTo("ABC");
@@ -188,7 +200,9 @@
@Test
public void getTimeInForegroundMs_aggregateBatteryConsumer() {
final BatteryEntry entry = new BatteryEntry(RuntimeEnvironment.application,
- BatteryConsumer.POWER_COMPONENT_BLUETOOTH, 10, 20, 100);
+ BatteryConsumer.POWER_COMPONENT_BLUETOOTH,
+ /* devicePowerMah= */ 10,
+ /* usageDurationMs= */ 100);
assertThat(entry.getTimeInForegroundMs()).isEqualTo(100L);
}
@@ -207,7 +221,9 @@
@Test
public void getTimeInBackgroundMs_systemConsumer() {
final BatteryEntry entry = new BatteryEntry(RuntimeEnvironment.application,
- BatteryConsumer.POWER_COMPONENT_BLUETOOTH, 100, 200, 1000);
+ BatteryConsumer.POWER_COMPONENT_BLUETOOTH,
+ /* devicePowerMah= */ 100,
+ /* usageDurationMs= */ 1000);
assertThat(entry.getTimeInBackgroundMs()).isEqualTo(0);
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownControllerTest.java
index d6b5a3e..0bc8693 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownControllerTest.java
@@ -211,7 +211,7 @@
SettingsEnums.ACTION_BATTERY_USAGE_SYSTEM_ITEM,
SettingsEnums.OPEN_BATTERY_USAGE,
/* package name */ "none",
- /* percentage of total */ 0);
+ /* percentage of total */ 100);
}
@Test
@@ -227,7 +227,7 @@
SettingsEnums.ACTION_BATTERY_USAGE_APP_ITEM,
SettingsEnums.OPEN_BATTERY_USAGE,
/* package name */ "none",
- /* percentage of total */ 0);
+ /* percentage of total */ 100);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java
index ce6a917..5b69e7c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java
@@ -671,19 +671,19 @@
.get(DataProcessor.SELECTED_INDEX_ALL);
assertBatteryDiffEntry(
resultDiffData.getAppDiffEntryList().get(0), currentUserId, /*uid=*/ 2L,
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY, /*consumePercentage=*/ 40.0,
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY, /*consumePercentage=*/ 50.0,
/*foregroundUsageConsumePower=*/ 14, /*foregroundServiceUsageConsumePower=*/ 9,
/*backgroundUsageConsumePower=*/ 9, /*cachedUsageConsumePower=*/ 8,
/*foregroundUsageTimeInMs=*/ 30, /*backgroundUsageTimeInMs=*/ 40);
assertBatteryDiffEntry(
resultDiffData.getAppDiffEntryList().get(1), currentUserId, /*uid=*/ 4L,
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY, /*consumePercentage=*/ 40.0,
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY, /*consumePercentage=*/ 50.0,
/*foregroundUsageConsumePower=*/ 8, /*foregroundServiceUsageConsumePower=*/ 8,
/*backgroundUsageConsumePower=*/ 8, /*cachedUsageConsumePower=*/ 8,
/*foregroundUsageTimeInMs=*/ 5, /*backgroundUsageTimeInMs=*/ 5);
assertBatteryDiffEntry(
resultDiffData.getSystemDiffEntryList().get(0), currentUserId, /*uid=*/ 3L,
- ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY, /*consumePercentage=*/ 20.0,
+ ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY, /*consumePercentage=*/ 100.0,
/*foregroundUsageConsumePower=*/ 5, /*foregroundServiceUsageConsumePower=*/ 5,
/*backgroundUsageConsumePower=*/ 5, /*cachedUsageConsumePower=*/ 5,
/*foregroundUsageTimeInMs=*/ 50, /*backgroundUsageTimeInMs=*/ 60);
@@ -697,19 +697,19 @@
resultDiffData = resultMap.get(1).get(DataProcessor.SELECTED_INDEX_ALL);
assertBatteryDiffEntry(
resultDiffData.getAppDiffEntryList().get(0), currentUserId, /*uid=*/ 4L,
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY, /*consumePercentage=*/ 50.0,
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY, /*consumePercentage=*/ 66.66666666666666,
/*foregroundUsageConsumePower=*/ 8, /*foregroundServiceUsageConsumePower=*/ 8,
/*backgroundUsageConsumePower=*/ 8, /*cachedUsageConsumePower=*/ 8,
/*foregroundUsageTimeInMs=*/ 5, /*backgroundUsageTimeInMs=*/ 5);
assertBatteryDiffEntry(
resultDiffData.getAppDiffEntryList().get(1), currentUserId, /*uid=*/ 2L,
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY, /*consumePercentage=*/ 25.0,
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY, /*consumePercentage=*/ 33.33333333333333,
/*foregroundUsageConsumePower=*/ 9, /*foregroundServiceUsageConsumePower=*/ 4,
/*backgroundUsageConsumePower=*/ 4, /*cachedUsageConsumePower=*/ 3,
/*foregroundUsageTimeInMs=*/ 15, /*backgroundUsageTimeInMs=*/ 15);
assertBatteryDiffEntry(
resultDiffData.getSystemDiffEntryList().get(0), currentUserId, /*uid=*/ 3L,
- ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY, /*consumePercentage=*/ 25.0,
+ ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY, /*consumePercentage=*/ 100.0,
/*foregroundUsageConsumePower=*/ 5, /*foregroundServiceUsageConsumePower=*/ 5,
/*backgroundUsageConsumePower=*/ 5, /*cachedUsageConsumePower=*/ 5,
/*foregroundUsageTimeInMs=*/ 50, /*backgroundUsageTimeInMs=*/ 60);
@@ -830,14 +830,14 @@
.get(DataProcessor.SELECTED_INDEX_ALL);
assertBatteryDiffEntry(
resultDiffData.getAppDiffEntryList().get(0), currentUserId, /*uid=*/ 1L,
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY, /*consumePercentage=*/ 25.0,
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY, /*consumePercentage=*/ 100.0,
/*foregroundUsageConsumePower=*/ 5, /*foregroundServiceUsageConsumePower=*/ 5,
/*backgroundUsageConsumePower=*/ 5, /*cachedUsageConsumePower=*/ 5,
/*foregroundUsageTimeInMs=*/ 10, /*backgroundUsageTimeInMs=*/ 10);
assertBatteryDiffEntry(
resultDiffData.getSystemDiffEntryList().get(0), BatteryUtils.UID_OTHER_USERS,
/*uid=*/ BatteryUtils.UID_OTHER_USERS, ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
- /*consumePercentage=*/ 75.0,
+ /*consumePercentage=*/ 100.0,
/*foregroundUsageConsumePower=*/ 0, /*foregroundServiceUsageConsumePower=*/ 0,
/*backgroundUsageConsumePower=*/ 0, /*cachedUsageConsumePower=*/ 0,
/*foregroundUsageTimeInMs=*/ 0, /*backgroundUsageTimeInMs=*/ 0);
@@ -1193,7 +1193,7 @@
assertBatteryDiffEntry(
batteryDiffData.getAppDiffEntryList().get(0), 0, /*uid=*/ 2L,
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY, /*consumePercentage=*/ 25.0,
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY, /*consumePercentage=*/ 100.0,
/*foregroundUsageConsumePower=*/ 0.5, /*foregroundServiceUsageConsumePower=*/ 0,
/*backgroundUsageConsumePower=*/ 0, /*cachedUsageConsumePower=*/ 0,
/*foregroundUsageTimeInMs=*/ 20, /*backgroundUsageTimeInMs=*/ 20);
@@ -1205,7 +1205,7 @@
/*foregroundUsageTimeInMs=*/ 30, /*backgroundUsageTimeInMs=*/ 40);
assertBatteryDiffEntry(
batteryDiffData.getSystemDiffEntryList().get(0), 0, /*uid=*/ 4L,
- ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY, /*consumePercentage=*/ 75.0,
+ ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY, /*consumePercentage=*/ 100.0,
/*foregroundUsageConsumePower=*/ 0.9, /*foregroundServiceUsageConsumePower=*/ 0.2,
/*backgroundUsageConsumePower=*/ 0.3, /*cachedUsageConsumePower=*/ 0.1,
/*foregroundUsageTimeInMs=*/ 10, /*backgroundUsageTimeInMs=*/ 10);
diff --git a/tests/unit/src/com/android/settings/deviceinfo/simstatus/SlotSimStatusTest.java b/tests/unit/src/com/android/settings/deviceinfo/simstatus/SlotSimStatusTest.java
index 71f0faf..4c17d15 100644
--- a/tests/unit/src/com/android/settings/deviceinfo/simstatus/SlotSimStatusTest.java
+++ b/tests/unit/src/com/android/settings/deviceinfo/simstatus/SlotSimStatusTest.java
@@ -19,6 +19,7 @@
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
@@ -30,17 +31,22 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import java.util.concurrent.Executor;
@RunWith(AndroidJUnit4.class)
public class SlotSimStatusTest {
@Mock
private TelephonyManager mTelephonyManager;
+ @Mock
+ private Executor mExecutor;
+ @Captor
+ private ArgumentCaptor<Runnable> mRunnableCaptor;
private Context mContext;
@@ -65,8 +71,10 @@
public void size_returnNumberOfPhone_whenQueryInBackgroundThread() {
doReturn(2).when(mTelephonyManager).getPhoneCount();
- ExecutorService executor = Executors.newSingleThreadExecutor();
- SlotSimStatus target = new SlotSimStatus(mContext, executor);
+ SlotSimStatus target = new SlotSimStatus(mContext, mExecutor);
+
+ verify(mExecutor).execute(mRunnableCaptor.capture());
+ mRunnableCaptor.getValue().run();
assertEquals(new Integer(target.size()), new Integer(2));
}