Clear preferences when dialog acknowledged and increase order
This CL makes it so that the order on the seekbar is increased to a very large value to ensure it gets added to the end in the case where a refresh is triggered due to the first time battery saver dialog. Additionally it clears the preferences on the screen when we receive confirmation to ensure that no caching can cause the seekbar ot show up on top of other preferences. Test: atest BatterySaverScheduleSeekBarControllerTest Bug: 132107662 Change-Id: I26bf2772ed7135daa4879bca17e0ecfc22a2d0dd
This commit is contained in:
@@ -99,10 +99,15 @@ public class BatterySaverScheduleSeekBarController implements
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the seekbar to the end of the provided preference screen
|
||||
*
|
||||
* @param screen The preference screen to add the seekbar to
|
||||
*/
|
||||
public void addToScreen(PreferenceScreen screen) {
|
||||
// makes sure it gets added after the preferences if called due to first time battery
|
||||
// saver message
|
||||
mSeekBarPreference.setOrder(5);
|
||||
mSeekBarPreference.setOrder(100);
|
||||
screen.addPreference(mSeekBarPreference);
|
||||
}
|
||||
}
|
||||
|
@@ -64,6 +64,7 @@ public class BatterySaverScheduleSettings extends RadioButtonPickerFragment {
|
||||
final ContentObserver mSettingsObserver = new ContentObserver(new Handler()) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
getPreferenceScreen().removeAll();
|
||||
updateCandidates();
|
||||
}
|
||||
};
|
||||
|
@@ -7,9 +7,14 @@ import android.content.Context;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.Global;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@@ -19,9 +24,12 @@ public class BatterySaverScheduleSeekBarControllerTest {
|
||||
private Context mContext;
|
||||
private ContentResolver mResolver;
|
||||
private BatterySaverScheduleSeekBarController mController;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new BatterySaverScheduleSeekBarController(mContext);
|
||||
mResolver = mContext.getContentResolver();
|
||||
@@ -62,4 +70,14 @@ public class BatterySaverScheduleSeekBarControllerTest {
|
||||
mController.updateSeekBar();
|
||||
assertThat(mController.mSeekBarPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addToScreen_addsToEnd() {
|
||||
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||
Settings.Global.putInt(mResolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 15);
|
||||
mController.addToScreen(mScreen);
|
||||
assertThat(mController.mSeekBarPreference.getOrder()).isEqualTo(100);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user