package com.android.settings.gestures;
import android.content.Context;
+import android.content.Intent;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.search.DatabaseIndexingUtils;
+import com.android.settings.search.InlineSwitchPayload;
+import com.android.settings.search.ResultPayload;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.events.OnResume;
public class AssistGesturePreferenceController extends GesturePreferenceController
implements OnResume {
+ private final int ON = 1;
+ private final int OFF = 0;
+
private static final String PREF_KEY_VIDEO = "gesture_assist_video";
private final String mAssistGesturePrefKey;
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean enabled = (boolean) newValue;
Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.ASSIST_GESTURE_ENABLED, enabled ? 1 : 0);
+ Settings.Secure.ASSIST_GESTURE_ENABLED, enabled ? ON : OFF);
updateState(preference);
return true;
}
Settings.Secure.ASSIST_GESTURE_ENABLED, 1);
return assistGestureEnabled != 0;
}
+
+ @Override
+ public ResultPayload getResultPayload() {
+ final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
+ AssistGestureSettings.class.getName(), mAssistGesturePrefKey,
+ mContext.getString(R.string.display_settings));
+
+ return new InlineSwitchPayload(Settings.Secure.ASSIST_GESTURE_ENABLED,
+ ResultPayload.SettingsSource.SECURE, ON, intent, isAvailable());
+ }
}
package com.android.settings.gestures;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.support.v7.preference.Preference;
+import com.android.settings.DisplaySettings;
+import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.search.DatabaseIndexingUtils;
+import com.android.settings.search.InlineSwitchPayload;
+import com.android.settings.search.ResultPayload;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class DoubleTapPowerPreferenceController extends GesturePreferenceController {
+ private final int ON = 0;
+ private final int OFF = 1;
+
private static final String PREF_KEY_VIDEO = "gesture_double_tap_power_video";
private final String mDoubleTapPowerKey;
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enabled = (boolean) newValue;
Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, enabled ? 0 : 1);
+ Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, enabled ? ON : OFF);
return true;
}
Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 0);
return cameraDisabled == 0;
}
+
+ @Override
+ public ResultPayload getResultPayload() {
+ final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
+ DoubleTapPowerSettings.class.getName(), mDoubleTapPowerKey,
+ mContext.getString(R.string.display_settings));
+
+ return new InlineSwitchPayload(Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED,
+ ResultPayload.SettingsSource.SECURE, ON, intent, isAvailable());
+ }
}
import android.annotation.UserIdInt;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import com.android.internal.hardware.AmbientDisplayConfiguration;
+import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.search.DatabaseIndexingUtils;
+import com.android.settings.search.InlineSwitchPayload;
+import com.android.settings.search.ResultPayload;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class DoubleTapScreenPreferenceController extends GesturePreferenceController {
+ private final int ON = 1;
+ private final int OFF = 0;
+
private static final String PREF_KEY_VIDEO = "gesture_double_tap_screen_video";
private final String mDoubleTapScreenPrefKey;
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean enabled = (boolean) newValue;
Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, enabled ? 1 : 0);
+ Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, enabled ? ON : OFF);
return true;
}
protected boolean isSwitchPrefEnabled() {
return mAmbientConfig.pulseOnDoubleTapEnabled(mUserId);
}
+
+ @Override
+ public ResultPayload getResultPayload() {
+ final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
+ DoubleTapScreenSettings.class.getName(), mDoubleTapScreenPrefKey,
+ mContext.getString(R.string.display_settings));
+
+ return new InlineSwitchPayload(Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP,
+ ResultPayload.SettingsSource.SECURE, ON, intent, isAvailable());
+ }
}
import com.android.settings.R;
import com.android.settings.Utils;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class DoubleTwistPreferenceController extends GesturePreferenceController {
+ private final int ON = 1;
+ private final int OFF = 0;
+
private static final String PREF_KEY_VIDEO = "gesture_double_twist_video";
private final String mDoubleTwistPrefKey;
private final UserManager mUserManager;
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
- final int enabled = (boolean) newValue ? 1 : 0;
+ final int enabled = (boolean) newValue ? ON : OFF;
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, enabled);
final int managedProfileUserId = getManagedProfileUserId();
import android.annotation.UserIdInt;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import com.android.internal.hardware.AmbientDisplayConfiguration;
-import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.R;
+import com.android.settings.search.DatabaseIndexingUtils;
+import com.android.settings.search.InlineSwitchPayload;
+import com.android.settings.search.ResultPayload;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class PickupGesturePreferenceController extends GesturePreferenceController {
- private static final String PREF_VIDEO_KEY = "gesture_pick_up_video";
+ private final int ON = 1;
+ private final int OFF = 0;
+
+ private static final String PREF_KEY_VIDEO = "gesture_pick_up_video";
private final String mPickUpPrefKey;
private final AmbientDisplayConfiguration mAmbientConfig;
@Override
protected String getVideoPrefKey() {
- return PREF_VIDEO_KEY;
+ return PREF_KEY_VIDEO;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean enabled = (boolean) newValue;
Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.DOZE_PULSE_ON_PICK_UP, enabled ? 1 : 0);
+ Settings.Secure.DOZE_PULSE_ON_PICK_UP, enabled ? ON : OFF);
return true;
}
public boolean canHandleClicks() {
return mAmbientConfig.pulseOnPickupCanBeModified(mUserId);
}
+
+ @Override
+ public ResultPayload getResultPayload() {
+ final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
+ PickupGestureSettings.class.getName(), mPickUpPrefKey,
+ mContext.getString(R.string.display_settings));
+
+ return new InlineSwitchPayload(Settings.Secure.DOZE_PULSE_ON_PICK_UP,
+ ResultPayload.SettingsSource.SECURE, ON, intent, isAvailable());
+ }
}
package com.android.settings.gestures;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.support.v7.preference.Preference;
+import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.search.DatabaseIndexingUtils;
+import com.android.settings.search.InlineSwitchPayload;
+import com.android.settings.search.ResultPayload;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class SwipeToNotificationPreferenceController extends GesturePreferenceController {
+ private final int ON = 1;
+ private final int OFF = 0;
+
private static final String PREF_KEY_VIDEO = "gesture_swipe_down_fingerprint_video";
private final String mSwipeDownFingerPrefKey;
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, (boolean) newValue ? 1 : 0);
+ Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, (boolean) newValue ? ON : OFF);
return true;
}
Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 1)
== 1;
}
+
+ @Override
+ public ResultPayload getResultPayload() {
+ final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
+ SwipeToNotificationSettings.class.getName(), mSwipeDownFingerPrefKey,
+ mContext.getString(R.string.display_settings));
+
+ return new InlineSwitchPayload(Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED,
+ ResultPayload.SettingsSource.SECURE, ON, intent, isAvailable());
+ }
}
import static android.provider.Settings.Secure.ASSIST_GESTURE_ENABLED;
+import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
+import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
+import android.provider.Settings.Secure;
import com.android.settings.TestConfig;
+import com.android.settings.display.AutoBrightnessPreferenceController;
+import com.android.settings.search.InlinePayload;
+import com.android.settings.search.InlineSwitchPayload;
+import com.android.settings.search.ResultPayload;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowSecureSettings;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
assertThat(mController.isSwitchPrefEnabled()).isFalse();
}
+
+ @Test
+ public void testPreferenceController_ProperResultPayloadType() {
+ final Context context = RuntimeEnvironment.application;
+ AssistGesturePreferenceController controller =
+ new AssistGesturePreferenceController(context, null /* lifecycle */, KEY_ASSIST,
+ false /* assistOnly */);
+ ResultPayload payload = controller.getResultPayload();
+ assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
+ }
+
+ @Test
+ @Config(shadows = ShadowSecureSettings.class)
+ public void testSetValue_updatesCorrectly() {
+ int newValue = 1;
+ ContentResolver resolver = mContext.getContentResolver();
+ Settings.Secure.putInt(resolver, Secure.ASSIST_GESTURE_ENABLED, 0);
+
+ ((InlinePayload) mController.getResultPayload()).setValue(mContext, newValue);
+ int updatedValue = Settings.Secure.getInt(resolver, Secure.ASSIST_GESTURE_ENABLED, -1);
+
+ assertThat(updatedValue).isEqualTo(newValue);
+ }
+
+ @Test
+ @Config(shadows = ShadowSecureSettings.class)
+ public void testGetValue_correctValueReturned() {
+ int currentValue = 1;
+ ContentResolver resolver = mContext.getContentResolver();
+ Settings.Secure.putInt(resolver, Settings.Secure.ASSIST_GESTURE_ENABLED, currentValue);
+
+ int newValue = ((InlinePayload) mController.getResultPayload()).getValue(mContext);
+
+ assertThat(newValue).isEqualTo(currentValue);
+ }
}
package com.android.settings.gestures;
+import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
import android.support.v7.preference.PreferenceScreen;
+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 com.android.settings.TestConfig;
+import com.android.settings.testutils.shadow.ShadowSecureSettings;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
assertThat(mController.isSwitchPrefEnabled()).isFalse();
}
+
+ @Test
+ public void testPreferenceController_ProperResultPayloadType() {
+ final Context context = RuntimeEnvironment.application;
+ DoubleTapPowerPreferenceController controller =
+ new DoubleTapPowerPreferenceController(context, null /* lifecycle */,
+ KEY_DOUBLE_TAP_POWER);
+ ResultPayload payload = controller.getResultPayload();
+ assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
+ }
+
+ @Test
+ @Config(shadows = ShadowSecureSettings.class)
+ public void testSetValue_updatesCorrectly() {
+ int newValue = 1;
+ ContentResolver resolver = mContext.getContentResolver();
+ Settings.Secure.putInt(resolver, Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED,
+ 0);
+
+ InlinePayload payload = ((InlineSwitchPayload) mController.getResultPayload());
+ payload.setValue(mContext, newValue);
+ int updatedValue = Settings.Secure.getInt(resolver,
+ Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, -1);
+ updatedValue = 1 - updatedValue; // DoubleTapPower is a non-standard switch
+
+ assertThat(updatedValue).isEqualTo(newValue);
+ }
+
+ @Test
+ @Config(shadows = ShadowSecureSettings.class)
+ public void testGetValue_correctValueReturned() {
+ int currentValue = 1;
+ ContentResolver resolver = mContext.getContentResolver();
+ Settings.Secure.putInt(resolver,
+ Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, currentValue);
+
+ int newValue = ((InlinePayload) mController.getResultPayload()).getValue(mContext);
+ newValue = 1 - newValue; // DoubleTapPower is a non-standard switch
+ assertThat(newValue).isEqualTo(currentValue);
+ }
}
package com.android.settings.gestures;
+import android.content.ContentResolver;
import android.content.Context;
+import android.provider.Settings;
import com.android.internal.hardware.AmbientDisplayConfiguration;
+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 com.android.settings.TestConfig;
+import com.android.settings.testutils.shadow.ShadowSecureSettings;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
assertThat(mController.isSwitchPrefEnabled()).isFalse();
}
+
+ @Test
+ public void testPreferenceController_ProperResultPayloadType() {
+ final Context context = RuntimeEnvironment.application;
+ DoubleTapScreenPreferenceController controller =
+ new DoubleTapScreenPreferenceController(context, null /* lifecycle */,
+ mAmbientDisplayConfiguration, 0 /* userid */, KEY_DOUBLE_TAP_SCREEN);
+ ResultPayload payload = controller.getResultPayload();
+ assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
+ }
+
+ @Test
+ @Config(shadows = ShadowSecureSettings.class)
+ public void testSetValue_updatesCorrectly() {
+ int newValue = 1;
+ ContentResolver resolver = mContext.getContentResolver();
+ Settings.Secure.putInt(resolver, Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, 0);
+
+ ((InlinePayload) mController.getResultPayload()).setValue(mContext, newValue);
+ int updatedValue = Settings.Secure.getInt(resolver,
+ Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, -1);
+
+ assertThat(updatedValue).isEqualTo(newValue);
+ }
+
+ @Test
+ @Config(shadows = ShadowSecureSettings.class)
+ public void testGetValue_correctValueReturned() {
+ int currentValue = 1;
+ ContentResolver resolver = mContext.getContentResolver();
+ Settings.Secure.putInt(resolver,
+ Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, currentValue);
+
+ int newValue = ((InlinePayload) mController.getResultPayload()).getValue(mContext);
+
+ assertThat(newValue).isEqualTo(currentValue);
+ }
}
import java.util.ArrayList;
import java.util.List;
-import static android.provider.Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doReturn;
public void onPreferenceChange_hasWorkProfile_shouldUpdateSettingForWorkProfileUser() {
final int managedId = 2;
ShadowSecureSettings.putIntForUser(
- null, CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0, managedId);
+ null, Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0, managedId);
DoubleTwistPreferenceController controller =
spy(new DoubleTwistPreferenceController(mContext, null, KEY_DOUBLE_TWIST));
doReturn(managedId).when(controller).getManagedProfileUserId();
// enable the gesture
controller.onPreferenceChange(null, true);
assertThat(Settings.Secure.getIntForUser(mContext.getContentResolver(),
- CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0, managedId)).isEqualTo(1);
+ Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0, managedId)).isEqualTo(1);
// disable the gesture
controller.onPreferenceChange(null, false);
assertThat(Settings.Secure.getIntForUser(mContext.getContentResolver(),
- CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1, managedId)).isEqualTo(0);
+ Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1, managedId)).isEqualTo(0);
}
@Test
// Set the setting to be enabled.
final Context context = ShadowApplication.getInstance().getApplicationContext();
Settings.System.putInt(context.getContentResolver(),
- CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1);
+ Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1);
mController = new DoubleTwistPreferenceController(context, null, KEY_DOUBLE_TWIST);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
// Set the setting to be disabled.
final Context context = ShadowApplication.getInstance().getApplicationContext();
Settings.System.putInt(context.getContentResolver(),
- CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0);
+ Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0);
mController = new DoubleTwistPreferenceController(context, null, KEY_DOUBLE_TWIST);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
package com.android.settings.gestures;
+import android.content.ContentResolver;
import android.content.Context;
+import android.provider.Settings;
import com.android.internal.hardware.AmbientDisplayConfiguration;
+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 com.android.settings.TestConfig;
+import com.android.settings.testutils.shadow.ShadowSecureSettings;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
assertThat(mController.canHandleClicks()).isFalse();
}
+
+ @Test
+ public void testPreferenceController_ProperResultPayloadType() {
+ final Context context = RuntimeEnvironment.application;
+ PickupGesturePreferenceController controller =
+ new PickupGesturePreferenceController(
+ context, null, mAmbientDisplayConfiguration, 0, KEY_PICK_UP);
+ ResultPayload payload = controller.getResultPayload();
+ assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
+ }
+
+ @Test
+ @Config(shadows = ShadowSecureSettings.class)
+ public void testSetValue_updatesCorrectly() {
+ int newValue = 1;
+ ContentResolver resolver = mContext.getContentResolver();
+ Settings.Secure.putInt(resolver, Settings.Secure.DOZE_PULSE_ON_PICK_UP, 0);
+
+ ((InlinePayload) mController.getResultPayload()).setValue(mContext, newValue);
+ int updatedValue = Settings.Secure.getInt(resolver,
+ Settings.Secure.DOZE_PULSE_ON_PICK_UP, -1);
+
+ assertThat(updatedValue).isEqualTo(newValue);
+ }
+
+ @Test
+ @Config(shadows = ShadowSecureSettings.class)
+ public void testGetValue_correctValueReturned() {
+ int currentValue = 1;
+ ContentResolver resolver = mContext.getContentResolver();
+ Settings.Secure.putInt(resolver, Settings.Secure.DOZE_PULSE_ON_PICK_UP, currentValue);
+
+ int newValue = ((InlinePayload) mController.getResultPayload()).getValue(mContext);
+
+ assertThat(newValue).isEqualTo(currentValue);
+ }
}
package com.android.settings.gestures;
+import android.content.ContentResolver;
import android.content.Context;
+import android.content.res.Resources;
import android.provider.Settings;
+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 com.android.settings.TestConfig;
+import com.android.settings.testutils.shadow.ShadowSecureSettings;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import static android.provider.Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
assertThat(mController.isSwitchPrefEnabled()).isFalse();
}
+
+ @Test
+ public void testPreferenceController_ProperResultPayloadType() {
+ when(mContext.getResources().
+ getBoolean(com.android.internal.R.bool.config_supportSystemNavigationKeys))
+ .thenReturn(true);
+
+ SwipeToNotificationPreferenceController controller =
+ new SwipeToNotificationPreferenceController(mContext, null /* lifecycle */,
+ SYSTEM_NAVIGATION_KEYS_ENABLED);
+ ResultPayload payload = controller.getResultPayload();
+ assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
+ }
+
+ @Test
+ @Config(shadows = ShadowSecureSettings.class)
+ public void testSetValue_updatesCorrectly() {
+ int newValue = 1;
+ ContentResolver resolver = mContext.getContentResolver();
+ Settings.Secure.putInt(resolver, Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 0);
+
+ ((InlinePayload) mController.getResultPayload()).setValue(mContext, newValue);
+ int updatedValue = Settings.Secure.getInt(resolver,
+ Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, -1);
+
+ assertThat(updatedValue).isEqualTo(newValue);
+ }
+
+ @Test
+ @Config(shadows = ShadowSecureSettings.class)
+ public void testGetValue_correctValueReturned() {
+ int currentValue = 1;
+ ContentResolver resolver = mContext.getContentResolver();
+ Settings.Secure.putInt(resolver,
+ Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, currentValue);
+
+ int newValue = ((InlinePayload) mController.getResultPayload()).getValue(mContext);
+
+ assertThat(newValue).isEqualTo(currentValue);
+ }
}