Update battery percentage column to UsageProgressBarPref (1/2)
- Change battery percentage column to new design - Remove debug info case Screenshots: https://screenshot.googleplex.com/9rvRfK3wBtpnarZ.png https://screenshot.googleplex.com/5iAjNXTptDechAm.png Bug: 177407113 Test: make RunSettingsRoboTests -j40 Change-Id: I5d046be29a036910036e72edb677b69bc2c0a03f
This commit is contained in:
committed by
Wesley Wang
parent
2e47875c06
commit
f4bc35333b
@@ -23,13 +23,11 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -38,8 +36,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.loader.app.LoaderManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -53,19 +49,14 @@ import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
import com.android.settingslib.core.instrumentation.VisibilityLoggerMixin;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
@@ -79,15 +70,12 @@ import java.util.List;
|
||||
public class PowerUsageSummaryTest {
|
||||
|
||||
private static final int UID = 123;
|
||||
private static final int UID_2 = 234;
|
||||
private static final int POWER_MAH = 100;
|
||||
private static final long TIME_SINCE_LAST_FULL_CHARGE_MS = 120 * 60 * 1000;
|
||||
private static final long TIME_SINCE_LAST_FULL_CHARGE_US =
|
||||
TIME_SINCE_LAST_FULL_CHARGE_MS * 1000;
|
||||
private static final long USAGE_TIME_MS = 65 * 60 * 1000;
|
||||
private static final double TOTAL_POWER = 200;
|
||||
private static final String NEW_ML_EST_SUFFIX = "(New ML est)";
|
||||
private static final String OLD_EST_SUFFIX = "(Old est)";
|
||||
private static Intent sAdditionalBatteryInfoIntent;
|
||||
|
||||
@BeforeClass
|
||||
@@ -101,12 +89,6 @@ public class PowerUsageSummaryTest {
|
||||
private BatterySipper mScreenBatterySipper;
|
||||
@Mock
|
||||
private BatterySipper mCellBatterySipper;
|
||||
@Mock
|
||||
private LayoutPreference mBatteryLayoutPref;
|
||||
@Mock
|
||||
private TextView mBatteryPercentText;
|
||||
@Mock
|
||||
private TextView mSummary1;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private BatteryStatsHelper mBatteryHelper;
|
||||
@Mock
|
||||
@@ -114,8 +96,6 @@ public class PowerUsageSummaryTest {
|
||||
@Mock
|
||||
private LoaderManager mLoaderManager;
|
||||
@Mock
|
||||
private BatteryInfo mBatteryInfo;
|
||||
@Mock
|
||||
private ContentResolver mContentResolver;
|
||||
@Mock
|
||||
private BatteryBroadcastReceiver mBatteryBroadcastReceiver;
|
||||
@@ -128,8 +108,6 @@ public class PowerUsageSummaryTest {
|
||||
private Context mRealContext;
|
||||
private TestFragment mFragment;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private BatteryMeterView mBatteryMeterView;
|
||||
private Intent mIntent;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -139,8 +117,6 @@ public class PowerUsageSummaryTest {
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mFragment = spy(new TestFragment(mRealContext));
|
||||
mFragment.initFeatureProvider();
|
||||
mBatteryMeterView = new BatteryMeterView(mRealContext);
|
||||
mBatteryMeterView.mDrawable = new BatteryMeterView.BatteryMeterDrawable(mRealContext, 0);
|
||||
doNothing().when(mFragment).restartBatteryStatsLoader(anyInt());
|
||||
doReturn(mock(LoaderManager.class)).when(mFragment).getLoaderManager();
|
||||
|
||||
@@ -158,12 +134,6 @@ public class PowerUsageSummaryTest {
|
||||
mCellBatterySipper.drainType = BatterySipper.DrainType.CELL;
|
||||
mCellBatterySipper.totalPowerMah = POWER_MAH;
|
||||
|
||||
when(mBatteryLayoutPref.findViewById(R.id.summary1)).thenReturn(mSummary1);
|
||||
when(mBatteryLayoutPref.findViewById(R.id.battery_percent)).thenReturn(mBatteryPercentText);
|
||||
when(mBatteryLayoutPref.findViewById(R.id.battery_header_icon))
|
||||
.thenReturn(mBatteryMeterView);
|
||||
mFragment.setBatteryLayoutPreference(mBatteryLayoutPref);
|
||||
|
||||
mScreenBatterySipper.drainType = BatterySipper.DrainType.SCREEN;
|
||||
mScreenBatterySipper.usageTimeMs = USAGE_TIME_MS;
|
||||
|
||||
@@ -206,51 +176,6 @@ public class PowerUsageSummaryTest {
|
||||
.restartLoader(eq(PowerUsageSummary.BATTERY_TIP_LOADER), eq(Bundle.EMPTY), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showBothEstimates_summariesAreBothModified() {
|
||||
when(mFeatureFactory.powerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(any()))
|
||||
.thenReturn(true);
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
return mRealContext.getString(
|
||||
R.string.power_usage_old_debug, invocation.getArguments()[0]);
|
||||
}
|
||||
}).when(mFeatureFactory.powerUsageFeatureProvider).getOldEstimateDebugString(any());
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
return mRealContext.getString(
|
||||
R.string.power_usage_enhanced_debug, invocation.getArguments()[0]);
|
||||
}
|
||||
}).when(mFeatureFactory.powerUsageFeatureProvider).getEnhancedEstimateDebugString(any());
|
||||
|
||||
doReturn(new TextView(mRealContext)).when(mBatteryLayoutPref).findViewById(R.id.summary1);
|
||||
mFragment.onLongClick(new View(mRealContext));
|
||||
TextView summary1 = mFragment.mBatteryLayoutPref.findViewById(R.id.summary1);
|
||||
Robolectric.flushBackgroundThreadScheduler();
|
||||
assertThat(summary1.getText().toString()).contains(NEW_ML_EST_SUFFIX);
|
||||
assertThat(summary1.getText().toString()).contains(OLD_EST_SUFFIX);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void debugMode() {
|
||||
doReturn(true).when(mFeatureFactory.powerUsageFeatureProvider).isEstimateDebugEnabled();
|
||||
|
||||
mFragment.restartBatteryInfoLoader();
|
||||
ArgumentCaptor<View.OnLongClickListener> listener = ArgumentCaptor.forClass(
|
||||
View.OnLongClickListener.class);
|
||||
verify(mSummary1).setOnLongClickListener(listener.capture());
|
||||
|
||||
// Calling the listener should disable it.
|
||||
listener.getValue().onLongClick(mSummary1);
|
||||
verify(mSummary1).setOnLongClickListener(null);
|
||||
|
||||
// Restarting the loader should reset the listener.
|
||||
mFragment.restartBatteryInfoLoader();
|
||||
verify(mSummary1, times(2)).setOnLongClickListener(any(View.OnLongClickListener.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshUi_deviceRotate_doNotUpdateBatteryTip() {
|
||||
mFragment.mBatteryTipPreferenceController = mock(BatteryTipPreferenceController.class);
|
||||
@@ -330,23 +255,5 @@ public class PowerUsageSummaryTest {
|
||||
// Override it so we can access this method in test
|
||||
return super.getContentResolver();
|
||||
}
|
||||
|
||||
@Override
|
||||
void showBothEstimates() {
|
||||
List<BatteryInfo> fakeBatteryInfo = new ArrayList<>(2);
|
||||
BatteryInfo info1 = new BatteryInfo();
|
||||
info1.batteryLevel = 10;
|
||||
info1.remainingTimeUs = 10000;
|
||||
info1.discharging = true;
|
||||
|
||||
BatteryInfo info2 = new BatteryInfo();
|
||||
info2.batteryLevel = 10;
|
||||
info2.remainingTimeUs = 10000;
|
||||
info2.discharging = true;
|
||||
|
||||
fakeBatteryInfo.add(info1);
|
||||
fakeBatteryInfo.add(info2);
|
||||
updateViews(fakeBatteryInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user