Add SettingsPrefController for Slices

Adds a new abstraction layer between preference controllers
and the AbstractPreferenceController. The layer is used to
consolidate the logic for each the setting type for getting
and setting values. This will be extended to support UI
information for Slices.

For reference how this fits into Slices, look at the
like-named classes added in this prototype:
ag/3221891

The changes in Search are as a transition into deprecation.
The code for Search in Settings is out-of-date from the
unbundled counterpart, and this change is made so that the
current code behaves as normal.

Test: robotests
Bug: 67996707
Change-Id: Ib1faab706485039edad66119a27a3fd5cabe6009
This commit is contained in:
Matthew Fritze
2017-11-15 15:12:52 -08:00
parent c61ed6356d
commit 3a4168360b
11 changed files with 502 additions and 119 deletions

View File

@@ -19,6 +19,7 @@ package com.android.settings.display;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
import static com.google.common.truth.Truth.assertThat;
import android.content.ContentResolver;
@@ -26,9 +27,6 @@ import android.content.Context;
import android.provider.Settings;
import com.android.settings.TestConfig;
import com.android.settings.search.InlinePayload;
import com.android.settings.search.InlineSwitchPayload;
import com.android.settings.search.ResultPayload;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
@@ -38,10 +36,9 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AutoBrightnessPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@@ -73,34 +70,28 @@ public class AutoBrightnessPreferenceControllerTest {
assertThat(mode).isEqualTo(SCREEN_BRIGHTNESS_MODE_MANUAL);
}
@Test
public void testPreferenceController_ProperResultPayloadType() {
final Context context = ShadowApplication.getInstance().getApplicationContext();
mController = new AutoBrightnessPreferenceController(context, PREFERENCE_KEY);
ResultPayload payload = mController.getResultPayload();
assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
}
@Test
public void testSetValue_updatesCorrectly() {
int newValue = 1;
boolean newValue = true;
ContentResolver resolver = mContext.getContentResolver();
Settings.System.putInt(resolver, SCREEN_BRIGHTNESS_MODE, 0);
Settings.System.putInt(resolver, SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL);
((InlinePayload) mController.getResultPayload()).setValue(mContext, newValue);
int updatedValue = Settings.System.getInt(resolver, SCREEN_BRIGHTNESS_MODE, -1);
mController.setChecked(newValue);
boolean updatedValue = Settings.System.getInt(resolver, SCREEN_BRIGHTNESS_MODE, -1)
!= SCREEN_BRIGHTNESS_MODE_MANUAL;
assertThat(updatedValue).isEqualTo(newValue);
}
@Test
public void testGetValue_correctValueReturned() {
int currentValue = 1;
ContentResolver resolver = mContext.getContentResolver();
Settings.System.putInt(resolver, SCREEN_BRIGHTNESS_MODE, currentValue);
Settings.System.putInt(resolver, SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
int newValue = ((InlinePayload) mController.getResultPayload()).getValue(mContext);
int newValue = mController.isChecked() ?
SCREEN_BRIGHTNESS_MODE_AUTOMATIC
: SCREEN_BRIGHTNESS_MODE_MANUAL;
assertThat(newValue).isEqualTo(currentValue);
assertThat(newValue).isEqualTo(SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
}
}