Loading src/com/android/settings/applications/assist/ManageAssist.java +3 −3 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ import android.provider.SearchIndexableResource; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.gestures.AssistGesturePreferenceController; import com.android.settings.gestures.AssistGestureSettingsPreferenceController; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; import com.android.settingslib.core.AbstractPreferenceController; Loading Loading @@ -73,8 +73,8 @@ public class ManageAssist extends DashboardFragment { final List<AbstractPreferenceController> controllers = new ArrayList<>(); controllers.add(new DefaultAssistPreferenceController(context, "default_assist", true /* showSetting */)); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST, true /* assistOnly */)); controllers.add(new AssistGestureSettingsPreferenceController(context, lifecycle, KEY_ASSIST, true /* assistOnly */)); controllers.add(new AssistContextPreferenceController(context, lifecycle)); controllers.add(new AssistScreenshotPreferenceController(context, lifecycle)); controllers.add(new AssistFlashScreenPreferenceController(context, lifecycle)); Loading src/com/android/settings/gestures/AssistGestureSettings.java +2 −6 Original line number Diff line number Diff line Loading @@ -35,8 +35,6 @@ public class AssistGestureSettings extends DashboardFragment { private static final String TAG = "AssistGesture"; private static final String KEY_ASSIST = "gesture_assist"; @Override public int getMetricsCategory() { return MetricsProto.MetricsEvent.SETTINGS_ASSIST_GESTURE; Loading @@ -60,8 +58,6 @@ public class AssistGestureSettings extends DashboardFragment { private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, Lifecycle lifecycle) { final List<AbstractPreferenceController> controllers = new ArrayList<>(); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST, false /* assistOnly */)); controllers.addAll(FeatureFactory.getFactory(context).getAssistGestureFeatureProvider() .getControllers(context, lifecycle)); Loading @@ -86,8 +82,8 @@ public class AssistGestureSettings extends DashboardFragment { @Override protected boolean isPageSearchEnabled(Context context) { return new AssistGesturePreferenceController(context, null /* lifecycle */, null /* key */, false /* assistOnly */) return new AssistGestureSettingsPreferenceController(context, null /* lifecycle */, null /* key */, false /* assistOnly */) .isAvailable(); } }; Loading src/com/android/settings/gestures/AssistGesturePreferenceController.java→src/com/android/settings/gestures/AssistGestureSettingsPreferenceController.java +29 −37 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package com.android.settings.gestures; import static android.provider.Settings.Secure.ASSIST_GESTURE_ENABLED; import static android.provider.Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED; import android.content.Context; import android.content.Intent; import android.provider.Settings; Loading @@ -32,19 +35,17 @@ import com.android.settings.search.ResultPayload; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.events.OnResume; import static android.provider.Settings.Secure.ASSIST_GESTURE_ENABLED; public class AssistGesturePreferenceController extends GesturePreferenceController public class AssistGestureSettingsPreferenceController 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; private final String SECURE_KEY = ASSIST_GESTURE_ENABLED; private static final String SECURE_KEY_ASSIST = ASSIST_GESTURE_ENABLED; private static final String SECURE_KEY_SILENCE = ASSIST_GESTURE_SILENCE_ALERTS_ENABLED; private static final int ON = 1; private static final int OFF = 0; private final String mAssistGesturePrefKey; private final AssistGestureFeatureProvider mFeatureProvider; private boolean mWasAvailable; Loading @@ -54,8 +55,8 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll @VisibleForTesting boolean mAssistOnly; public AssistGesturePreferenceController(Context context, Lifecycle lifecycle, String key, boolean assistOnly) { public AssistGestureSettingsPreferenceController(Context context, Lifecycle lifecycle, String key, boolean assistOnly) { super(context, lifecycle); mFeatureProvider = FeatureFactory.getFactory(context).getAssistGestureFeatureProvider(); mWasAvailable = isAvailable(); Loading @@ -76,14 +77,6 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll public void displayPreference(PreferenceScreen screen) { mScreen = screen; mPreference = screen.findPreference(getPreferenceKey()); if (!mFeatureProvider.isSensorAvailable(mContext)) { removePreference(mScreen, getPreferenceKey()); return; } if (!mFeatureProvider.isSupported(mContext)) { mScreen.removePreference(mPreference); return; } // Call super last or AbstractPreferenceController might remove the preference from the // screen (if !isAvailable()) before we can save a reference to it. super.displayPreference(screen); Loading @@ -91,14 +84,6 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll @Override public void onResume() { // This check must be done in case the user disables Assistant while still on the settings // page. This check is slightly different than isAvailable() in some cases due to this // setting being in multiple places that require different behavior if (mScreen != null && !mFeatureProvider.isSupported(mContext)) { mScreen.removePreference(mPreference); mWasAvailable = false; return; } if (mWasAvailable != isAvailable()) { // Only update the preference visibility if the availability has changed -- otherwise // the preference may be incorrectly added to screens with collapsed sections. Loading @@ -112,7 +97,7 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll return; } if (mFeatureProvider.isSupported(mContext)) { if (isAvailable()) { if (mScreen.findPreference(getPreferenceKey()) == null) { mScreen.addPreference(mPreference); } Loading @@ -121,15 +106,22 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll } } private boolean isAssistGestureEnabled() { return Settings.Secure.getInt(mContext.getContentResolver(), SECURE_KEY_ASSIST, ON) != 0; } private boolean isSilenceGestureEnabled() { return Settings.Secure.getInt(mContext.getContentResolver(), SECURE_KEY_SILENCE, ON) != 0; } @Override public void updateState(Preference preference) { boolean isEnabled = isSwitchPrefEnabled() && mFeatureProvider.isSupported(mContext); boolean isEnabled = isAssistGestureEnabled() && mFeatureProvider.isSupported(mContext); if (!mAssistOnly) { boolean assistGestureSilenceEnabled = Settings.Secure.getInt( mContext.getContentResolver(), Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1) != 0; isEnabled = isEnabled || assistGestureSilenceEnabled; isEnabled = isEnabled || isSilenceGestureEnabled(); } if (preference != null) { Loading @@ -146,7 +138,8 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean enabled = (boolean) newValue; Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY, enabled ? ON : OFF); Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY_ASSIST, enabled ? ON : OFF); updateState(preference); return true; } Loading @@ -163,9 +156,8 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll @Override protected boolean isSwitchPrefEnabled() { final int assistGestureEnabled = Settings.Secure.getInt(mContext.getContentResolver(), SECURE_KEY, ON); return assistGestureEnabled != 0; // Does nothing return true; } @Override Loading @@ -174,7 +166,7 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll AssistGestureSettings.class.getName(), mAssistGesturePrefKey, mContext.getString(R.string.display_settings)); return new InlineSwitchPayload(SECURE_KEY, ResultPayload.SettingsSource.SECURE, return new InlineSwitchPayload(SECURE_KEY_ASSIST, ResultPayload.SettingsSource.SECURE, ON /* onValue */, intent, isAvailable(), ON /* defaultValue */); } } src/com/android/settings/gestures/GestureSettings.java +2 −2 Original line number Diff line number Diff line Loading @@ -75,8 +75,8 @@ public class GestureSettings extends DashboardFragment { @NonNull Context context, @Nullable Lifecycle lifecycle, @NonNull AmbientDisplayConfiguration ambientDisplayConfiguration) { final List<AbstractPreferenceController> controllers = new ArrayList<>(); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST, false /* assistOnly */)); controllers.add(new AssistGestureSettingsPreferenceController(context, lifecycle, KEY_ASSIST, false /* assistOnly */)); controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle, KEY_SWIPE_DOWN)); controllers.add(new DoubleTwistPreferenceController(context, lifecycle, KEY_DOUBLE_TWIST)); Loading tests/robotests/src/com/android/settings/gestures/AssistGesturePreferenceControllerTest.java→tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java +9 −33 Original line number Diff line number Diff line Loading @@ -16,9 +16,6 @@ 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; Loading @@ -26,17 +23,16 @@ 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; Loading @@ -45,16 +41,15 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowApplication; @RunWith(SettingsRobolectricTestRunner.class) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) public class AssistGesturePreferenceControllerTest { public class AssistGestureSettingsPreferenceControllerTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private Context mContext; private FakeFeatureFactory mFactory; private AssistGesturePreferenceController mController; private AssistGestureSettingsPreferenceController mController; private static final String KEY_ASSIST = "gesture_assist"; Loading @@ -63,7 +58,8 @@ public class AssistGesturePreferenceControllerTest { MockitoAnnotations.initMocks(this); FakeFeatureFactory.setupForTest(mContext); mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); mController = new AssistGesturePreferenceController(mContext, null, KEY_ASSIST, false); mController = new AssistGestureSettingsPreferenceController(mContext, null, KEY_ASSIST, false); } @Test Loading @@ -79,32 +75,12 @@ public class AssistGesturePreferenceControllerTest { assertThat(mController.isAvailable()).isFalse(); } @Test public void testSwitchEnabled_configIsSet_shouldReturnTrue() { // Set the setting to be enabled. final Context context = ShadowApplication.getInstance().getApplicationContext(); Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 1); mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST, false); assertThat(mController.isSwitchPrefEnabled()).isTrue(); } @Test public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() { // Set the setting to be disabled. final Context context = ShadowApplication.getInstance().getApplicationContext(); Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 0); mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST, false); 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 */); AssistGestureSettingsPreferenceController controller = new AssistGestureSettingsPreferenceController(context, null /* lifecycle */, KEY_ASSIST, false /* assistOnly */); ResultPayload payload = controller.getResultPayload(); assertThat(payload).isInstanceOf(InlineSwitchPayload.class); } Loading Loading
src/com/android/settings/applications/assist/ManageAssist.java +3 −3 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ import android.provider.SearchIndexableResource; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.gestures.AssistGesturePreferenceController; import com.android.settings.gestures.AssistGestureSettingsPreferenceController; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; import com.android.settingslib.core.AbstractPreferenceController; Loading Loading @@ -73,8 +73,8 @@ public class ManageAssist extends DashboardFragment { final List<AbstractPreferenceController> controllers = new ArrayList<>(); controllers.add(new DefaultAssistPreferenceController(context, "default_assist", true /* showSetting */)); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST, true /* assistOnly */)); controllers.add(new AssistGestureSettingsPreferenceController(context, lifecycle, KEY_ASSIST, true /* assistOnly */)); controllers.add(new AssistContextPreferenceController(context, lifecycle)); controllers.add(new AssistScreenshotPreferenceController(context, lifecycle)); controllers.add(new AssistFlashScreenPreferenceController(context, lifecycle)); Loading
src/com/android/settings/gestures/AssistGestureSettings.java +2 −6 Original line number Diff line number Diff line Loading @@ -35,8 +35,6 @@ public class AssistGestureSettings extends DashboardFragment { private static final String TAG = "AssistGesture"; private static final String KEY_ASSIST = "gesture_assist"; @Override public int getMetricsCategory() { return MetricsProto.MetricsEvent.SETTINGS_ASSIST_GESTURE; Loading @@ -60,8 +58,6 @@ public class AssistGestureSettings extends DashboardFragment { private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, Lifecycle lifecycle) { final List<AbstractPreferenceController> controllers = new ArrayList<>(); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST, false /* assistOnly */)); controllers.addAll(FeatureFactory.getFactory(context).getAssistGestureFeatureProvider() .getControllers(context, lifecycle)); Loading @@ -86,8 +82,8 @@ public class AssistGestureSettings extends DashboardFragment { @Override protected boolean isPageSearchEnabled(Context context) { return new AssistGesturePreferenceController(context, null /* lifecycle */, null /* key */, false /* assistOnly */) return new AssistGestureSettingsPreferenceController(context, null /* lifecycle */, null /* key */, false /* assistOnly */) .isAvailable(); } }; Loading
src/com/android/settings/gestures/AssistGesturePreferenceController.java→src/com/android/settings/gestures/AssistGestureSettingsPreferenceController.java +29 −37 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package com.android.settings.gestures; import static android.provider.Settings.Secure.ASSIST_GESTURE_ENABLED; import static android.provider.Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED; import android.content.Context; import android.content.Intent; import android.provider.Settings; Loading @@ -32,19 +35,17 @@ import com.android.settings.search.ResultPayload; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.events.OnResume; import static android.provider.Settings.Secure.ASSIST_GESTURE_ENABLED; public class AssistGesturePreferenceController extends GesturePreferenceController public class AssistGestureSettingsPreferenceController 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; private final String SECURE_KEY = ASSIST_GESTURE_ENABLED; private static final String SECURE_KEY_ASSIST = ASSIST_GESTURE_ENABLED; private static final String SECURE_KEY_SILENCE = ASSIST_GESTURE_SILENCE_ALERTS_ENABLED; private static final int ON = 1; private static final int OFF = 0; private final String mAssistGesturePrefKey; private final AssistGestureFeatureProvider mFeatureProvider; private boolean mWasAvailable; Loading @@ -54,8 +55,8 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll @VisibleForTesting boolean mAssistOnly; public AssistGesturePreferenceController(Context context, Lifecycle lifecycle, String key, boolean assistOnly) { public AssistGestureSettingsPreferenceController(Context context, Lifecycle lifecycle, String key, boolean assistOnly) { super(context, lifecycle); mFeatureProvider = FeatureFactory.getFactory(context).getAssistGestureFeatureProvider(); mWasAvailable = isAvailable(); Loading @@ -76,14 +77,6 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll public void displayPreference(PreferenceScreen screen) { mScreen = screen; mPreference = screen.findPreference(getPreferenceKey()); if (!mFeatureProvider.isSensorAvailable(mContext)) { removePreference(mScreen, getPreferenceKey()); return; } if (!mFeatureProvider.isSupported(mContext)) { mScreen.removePreference(mPreference); return; } // Call super last or AbstractPreferenceController might remove the preference from the // screen (if !isAvailable()) before we can save a reference to it. super.displayPreference(screen); Loading @@ -91,14 +84,6 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll @Override public void onResume() { // This check must be done in case the user disables Assistant while still on the settings // page. This check is slightly different than isAvailable() in some cases due to this // setting being in multiple places that require different behavior if (mScreen != null && !mFeatureProvider.isSupported(mContext)) { mScreen.removePreference(mPreference); mWasAvailable = false; return; } if (mWasAvailable != isAvailable()) { // Only update the preference visibility if the availability has changed -- otherwise // the preference may be incorrectly added to screens with collapsed sections. Loading @@ -112,7 +97,7 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll return; } if (mFeatureProvider.isSupported(mContext)) { if (isAvailable()) { if (mScreen.findPreference(getPreferenceKey()) == null) { mScreen.addPreference(mPreference); } Loading @@ -121,15 +106,22 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll } } private boolean isAssistGestureEnabled() { return Settings.Secure.getInt(mContext.getContentResolver(), SECURE_KEY_ASSIST, ON) != 0; } private boolean isSilenceGestureEnabled() { return Settings.Secure.getInt(mContext.getContentResolver(), SECURE_KEY_SILENCE, ON) != 0; } @Override public void updateState(Preference preference) { boolean isEnabled = isSwitchPrefEnabled() && mFeatureProvider.isSupported(mContext); boolean isEnabled = isAssistGestureEnabled() && mFeatureProvider.isSupported(mContext); if (!mAssistOnly) { boolean assistGestureSilenceEnabled = Settings.Secure.getInt( mContext.getContentResolver(), Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1) != 0; isEnabled = isEnabled || assistGestureSilenceEnabled; isEnabled = isEnabled || isSilenceGestureEnabled(); } if (preference != null) { Loading @@ -146,7 +138,8 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean enabled = (boolean) newValue; Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY, enabled ? ON : OFF); Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY_ASSIST, enabled ? ON : OFF); updateState(preference); return true; } Loading @@ -163,9 +156,8 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll @Override protected boolean isSwitchPrefEnabled() { final int assistGestureEnabled = Settings.Secure.getInt(mContext.getContentResolver(), SECURE_KEY, ON); return assistGestureEnabled != 0; // Does nothing return true; } @Override Loading @@ -174,7 +166,7 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll AssistGestureSettings.class.getName(), mAssistGesturePrefKey, mContext.getString(R.string.display_settings)); return new InlineSwitchPayload(SECURE_KEY, ResultPayload.SettingsSource.SECURE, return new InlineSwitchPayload(SECURE_KEY_ASSIST, ResultPayload.SettingsSource.SECURE, ON /* onValue */, intent, isAvailable(), ON /* defaultValue */); } }
src/com/android/settings/gestures/GestureSettings.java +2 −2 Original line number Diff line number Diff line Loading @@ -75,8 +75,8 @@ public class GestureSettings extends DashboardFragment { @NonNull Context context, @Nullable Lifecycle lifecycle, @NonNull AmbientDisplayConfiguration ambientDisplayConfiguration) { final List<AbstractPreferenceController> controllers = new ArrayList<>(); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST, false /* assistOnly */)); controllers.add(new AssistGestureSettingsPreferenceController(context, lifecycle, KEY_ASSIST, false /* assistOnly */)); controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle, KEY_SWIPE_DOWN)); controllers.add(new DoubleTwistPreferenceController(context, lifecycle, KEY_DOUBLE_TWIST)); Loading
tests/robotests/src/com/android/settings/gestures/AssistGesturePreferenceControllerTest.java→tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java +9 −33 Original line number Diff line number Diff line Loading @@ -16,9 +16,6 @@ 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; Loading @@ -26,17 +23,16 @@ 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; Loading @@ -45,16 +41,15 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowApplication; @RunWith(SettingsRobolectricTestRunner.class) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) public class AssistGesturePreferenceControllerTest { public class AssistGestureSettingsPreferenceControllerTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private Context mContext; private FakeFeatureFactory mFactory; private AssistGesturePreferenceController mController; private AssistGestureSettingsPreferenceController mController; private static final String KEY_ASSIST = "gesture_assist"; Loading @@ -63,7 +58,8 @@ public class AssistGesturePreferenceControllerTest { MockitoAnnotations.initMocks(this); FakeFeatureFactory.setupForTest(mContext); mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); mController = new AssistGesturePreferenceController(mContext, null, KEY_ASSIST, false); mController = new AssistGestureSettingsPreferenceController(mContext, null, KEY_ASSIST, false); } @Test Loading @@ -79,32 +75,12 @@ public class AssistGesturePreferenceControllerTest { assertThat(mController.isAvailable()).isFalse(); } @Test public void testSwitchEnabled_configIsSet_shouldReturnTrue() { // Set the setting to be enabled. final Context context = ShadowApplication.getInstance().getApplicationContext(); Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 1); mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST, false); assertThat(mController.isSwitchPrefEnabled()).isTrue(); } @Test public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() { // Set the setting to be disabled. final Context context = ShadowApplication.getInstance().getApplicationContext(); Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 0); mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST, false); 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 */); AssistGestureSettingsPreferenceController controller = new AssistGestureSettingsPreferenceController(context, null /* lifecycle */, KEY_ASSIST, false /* assistOnly */); ResultPayload payload = controller.getResultPayload(); assertThat(payload).isInstanceOf(InlineSwitchPayload.class); } Loading