Add gestures as inline actions for Phone Buddy

Add the following gestures as inline:
- Assist gesture
- Double tap power
- Double tap screen
- Pickup
- Swipe for notification

Bug:62022517
Test: make RunSettingsRoboTests
Change-Id: Ib246b97a0b924bf18f464d3548b7e4c393fc1931
This commit is contained in:
Matthew Fritze
2017-07-08 16:15:24 -07:00
parent 4b4ad6efc2
commit 469e4ea228
12 changed files with 334 additions and 16 deletions

View File

@@ -17,6 +17,7 @@
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;
@@ -25,12 +26,18 @@ import android.support.v7.preference.TwoStatePreference;
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;
@@ -136,7 +143,7 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll
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;
}
@@ -157,4 +164,14 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll
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());
}
}

View File

@@ -17,15 +17,24 @@
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;
@@ -63,7 +72,7 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
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;
}
@@ -73,4 +82,14 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
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());
}
}

View File

@@ -18,16 +18,24 @@ package com.android.settings.gestures;
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;
@@ -63,7 +71,7 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro
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;
}
@@ -76,4 +84,14 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro
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());
}
}

View File

@@ -30,11 +30,13 @@ import android.text.TextUtils;
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;
@@ -83,7 +85,7 @@ public class DoubleTwistPreferenceController extends GesturePreferenceController
@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();

View File

@@ -18,17 +18,24 @@ package com.android.settings.gestures;
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;
@@ -56,7 +63,7 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
@Override
protected String getVideoPrefKey() {
return PREF_VIDEO_KEY;
return PREF_KEY_VIDEO;
}
@Override
@@ -73,7 +80,7 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
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;
}
@@ -81,4 +88,14 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
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());
}
}

View File

@@ -17,15 +17,23 @@
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;
@@ -64,7 +72,7 @@ public class SwipeToNotificationPreferenceController extends GesturePreferenceCo
@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;
}
@@ -74,4 +82,14 @@ public class SwipeToNotificationPreferenceController extends GesturePreferenceCo
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());
}
}

View File

@@ -18,23 +18,32 @@ package com.android.settings.gestures;
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;
@@ -89,5 +98,40 @@ public class AssistGesturePreferenceControllerTest {
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);
}
}

View File

@@ -16,19 +16,25 @@
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;
@@ -92,4 +98,44 @@ public class DoubleTapPowerPreferenceControllerTest {
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);
}
}

View File

@@ -16,18 +16,25 @@
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;
@@ -81,4 +88,41 @@ public class DoubleTapScreenPreferenceControllerTest {
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);
}
}

View File

@@ -39,7 +39,6 @@ import org.robolectric.shadows.ShadowApplication;
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;
@@ -107,7 +106,7 @@ public class DoubleTwistPreferenceControllerTest {
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();
@@ -115,12 +114,12 @@ public class DoubleTwistPreferenceControllerTest {
// 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
@@ -128,7 +127,7 @@ public class DoubleTwistPreferenceControllerTest {
// 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();
@@ -139,7 +138,7 @@ public class DoubleTwistPreferenceControllerTest {
// 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();

View File

@@ -16,18 +16,25 @@
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;
@@ -97,4 +104,40 @@ public class PIckupGesturePreferenceControllerTest {
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);
}
}

View File

@@ -16,23 +16,34 @@
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)
@@ -88,4 +99,44 @@ public class SwipeToNotificationPreferenceControllerTest {
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);
}
}