Loading src/com/android/settings/fuelgauge/PowerUsageSummary.java +5 −2 Original line number Diff line number Diff line Loading @@ -535,6 +535,10 @@ public class PowerUsageSummary extends PowerUsageBase { @VisibleForTesting void updateHeaderPreference(BatteryInfo info) { final Context context = getContext(); if (context == null) { return; } final BatteryMeterView batteryView = (BatteryMeterView) mBatteryLayoutPref .findViewById(R.id.battery_header_icon); final TextView timeText = (TextView) mBatteryLayoutPref.findViewById(R.id.time); Loading @@ -545,8 +549,7 @@ public class PowerUsageSummary extends PowerUsageBase { R.string.estimated_time_left : R.string.estimated_charging_time_left; if (info.remainingTimeUs != 0) { timeText.setText(Utils.formatElapsedTime(getContext(), info.remainingTimeUs / 1000, false)); timeText.setText(Utils.formatElapsedTime(context, info.remainingTimeUs / 1000, false)); } else { timeText.setText(info.statusLabel); } Loading tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java +8 −0 Original line number Diff line number Diff line Loading @@ -362,6 +362,14 @@ public class PowerUsageSummaryTest { verify(mSummary1).setText(R.string.estimated_time_left); } @Test public void testUpdateHeaderPreference_AsyncUpdate_ShouldNotCrash() { when(mPowerUsageSummary.getContext()).thenReturn(null); mBatteryInfo.remainingTimeUs = REMAINING_TIME_US; //Should not crash mPowerUsageSummary.updateHeaderPreference(mBatteryInfo); } private void testToggleAllApps(final boolean isShowApps) { mFragment.mShowAllApps = isShowApps; Loading Loading
src/com/android/settings/fuelgauge/PowerUsageSummary.java +5 −2 Original line number Diff line number Diff line Loading @@ -535,6 +535,10 @@ public class PowerUsageSummary extends PowerUsageBase { @VisibleForTesting void updateHeaderPreference(BatteryInfo info) { final Context context = getContext(); if (context == null) { return; } final BatteryMeterView batteryView = (BatteryMeterView) mBatteryLayoutPref .findViewById(R.id.battery_header_icon); final TextView timeText = (TextView) mBatteryLayoutPref.findViewById(R.id.time); Loading @@ -545,8 +549,7 @@ public class PowerUsageSummary extends PowerUsageBase { R.string.estimated_time_left : R.string.estimated_charging_time_left; if (info.remainingTimeUs != 0) { timeText.setText(Utils.formatElapsedTime(getContext(), info.remainingTimeUs / 1000, false)); timeText.setText(Utils.formatElapsedTime(context, info.remainingTimeUs / 1000, false)); } else { timeText.setText(info.statusLabel); } Loading
tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java +8 −0 Original line number Diff line number Diff line Loading @@ -362,6 +362,14 @@ public class PowerUsageSummaryTest { verify(mSummary1).setText(R.string.estimated_time_left); } @Test public void testUpdateHeaderPreference_AsyncUpdate_ShouldNotCrash() { when(mPowerUsageSummary.getContext()).thenReturn(null); mBatteryInfo.remainingTimeUs = REMAINING_TIME_US; //Should not crash mPowerUsageSummary.updateHeaderPreference(mBatteryInfo); } private void testToggleAllApps(final boolean isShowApps) { mFragment.mShowAllApps = isShowApps; Loading