Add info string to advanced battery usage page

This CL adds an FYI string under the battery graph to let users
know that their current estimate is coming from the enhanced
estimate provider when it is enabled.

Test: Robotests
Bug: 38399654
Change-Id: If5cd622ef0251a5a483cef870fc2261369e14845
This commit is contained in:
Salvador Martinez
2017-06-19 10:33:41 -07:00
parent 39efd4ec44
commit cbefbc261f
7 changed files with 104 additions and 2 deletions

View File

@@ -15,6 +15,7 @@
*/
package com.android.settings.fuelgauge;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.spy;
@@ -49,6 +50,7 @@ import org.robolectric.annotation.Config;
SettingsShadowResources.SettingsShadowTheme.class
})
public class BatteryHistoryPreferenceTest {
public static final String TEST_STRING = "test";
@Mock
private PreferenceViewHolder mViewHolder;
@Mock
@@ -86,4 +88,24 @@ public class BatteryHistoryPreferenceTest {
verify(mTextView).setText(nullable(String.class));
verify(mBatteryInfo).bindHistory(mUsageView);
}
@Test
public void testSetBottomSummary_updatesBottomSummaryTextIfSet() {
mBatteryHistoryPreference.setBottomSummary(TEST_STRING);
mBatteryHistoryPreference.onBindViewHolder(mViewHolder);
TextView view = (TextView) mViewHolder.findViewById(R.id.bottom_summary);
assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(view.getText()).isEqualTo(TEST_STRING);
}
@Test
public void testSetBottomSummary_leavesBottomSummaryTextBlankIfNotSet() {
mBatteryHistoryPreference.hideBottomSummary();
mBatteryHistoryPreference.onBindViewHolder(mViewHolder);
TextView view = (TextView) mViewHolder.findViewById(R.id.bottom_summary);
assertThat(view.getVisibility()).isEqualTo(View.GONE);
assertThat(view.getText()).isEqualTo("");
}
}

View File

@@ -20,7 +20,9 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -81,6 +83,10 @@ public class PowerUsageAdvancedTest {
private PackageManager mPackageManager;
@Mock
private UserManager mUserManager;
@Mock
private BatteryHistoryPreference mHistPref;
@Mock
private PreferenceGroup mUsageListGroup;
private PowerUsageAdvanced mPowerUsageAdvanced;
private PowerUsageData mPowerUsageData;
private Context mShadowContext;
@@ -352,4 +358,26 @@ public class PowerUsageAdvancedTest {
assertThat(mPowerUsageAdvanced.calculateHiddenPower(powerUsageDataList)).isWithin(
PRECISION).of(unaccountedPower);
}
@Test
public void testRefreshUi_addsSubtextWhenAppropriate() {
// Mock out all the battery stuff
mPowerUsageAdvanced.mHistPref = mHistPref;
mPowerUsageAdvanced.mStatsHelper = mBatteryStatsHelper;
doReturn(new ArrayList<PowerUsageData>())
.when(mPowerUsageAdvanced).parsePowerUsageData(any());
doReturn("").when(mPowerUsageAdvanced).getString(anyInt());
mPowerUsageAdvanced.mUsageListGroup = mUsageListGroup;
// refresh the ui and check that text was not updated when enhanced prediction disabled
when(mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(any()))
.thenReturn(false);
mPowerUsageAdvanced.refreshUi();
verify(mHistPref, never()).setBottomSummary(any());
// refresh the ui and check that text was updated when enhanced prediction enabled
when(mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(any())).thenReturn(true);
mPowerUsageAdvanced.refreshUi();
verify(mHistPref, atLeastOnce()).setBottomSummary(any());
}
}