Simplify InlineSwitchPayloads and generalize get/set method
InlineSwitchPayload now assumes that all switches will be stored as 1 or 0, which simplifies the code. Moves Availability into ResultPayload, so that custom payloads can be created to set/get values which are more complicated than stotring ints (like bluetooth or DnD), and give more expressive reasons when unavailable. Bug: 62022517 Test: make RunSettingsRoboTests Change-Id: I87e6fc041bfd398e7daf6e6e479d502930d36f0f
This commit is contained in:
@@ -16,12 +16,15 @@
|
||||
|
||||
package com.android.settings.display;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
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.search.ResultPayload.Availability;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -78,13 +81,25 @@ public class AutoBrightnessPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreferenceController_CorrectPayload() {
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
mController = new AutoBrightnessPreferenceController(context, PREFERENCE_KEY);
|
||||
InlineSwitchPayload payload = (InlineSwitchPayload) mController.getResultPayload();
|
||||
assertThat(payload.settingsUri).isEqualTo("screen_brightness_mode");
|
||||
assertThat(payload.settingSource).isEqualTo(ResultPayload.SettingsSource.SYSTEM);
|
||||
assertThat(payload.valueMap.get(1)).isEqualTo(true);
|
||||
assertThat(payload.valueMap.get(0)).isEqualTo(false);
|
||||
public void testSetValue_updatesCorrectly() {
|
||||
int newValue = 1;
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Settings.System.putInt(resolver, SCREEN_BRIGHTNESS_MODE, 0);
|
||||
|
||||
((InlinePayload) mController.getResultPayload()).setValue(mContext, newValue);
|
||||
int updatedValue = Settings.System.getInt(resolver, SCREEN_BRIGHTNESS_MODE, -1);
|
||||
|
||||
assertThat(updatedValue).isEqualTo(newValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValue_correctValueReturned() {
|
||||
int currentValue = 1;
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Settings.System.putInt(resolver, SCREEN_BRIGHTNESS_MODE, currentValue);
|
||||
|
||||
int newValue = ((InlinePayload) mController.getResultPayload()).getValue(mContext);
|
||||
|
||||
assertThat(newValue).isEqualTo(currentValue);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user