From dbb32b86c69783eaef968714b53051b2d2bb75fd Mon Sep 17 00:00:00 2001 From: jeffreyhuang Date: Thu, 30 Nov 2017 11:50:00 -0800 Subject: [PATCH] Update DoubleTapScreenPrefCtrl to sdk 26 Test: make RunSettingsRoboTests -j40 Change-Id: Ia4ed886381e2758b7b1523648833fc57ca58a5b3 --- .../DoubleTapScreenPreferenceController.java | 10 ++++++++-- .../DoubleTapScreenPreferenceControllerTest.java | 23 ++++++++-------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java b/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java index deffa97a27..5412f368ad 100644 --- a/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java +++ b/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java @@ -22,6 +22,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.provider.Settings; import android.support.v7.preference.Preference; +import android.support.annotation.VisibleForTesting; import com.android.internal.hardware.AmbientDisplayConfiguration; import com.android.settings.R; @@ -55,8 +56,13 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro } public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) { - AmbientDisplayConfiguration ambientConfig = new AmbientDisplayConfiguration(context); - return !ambientConfig.pulseOnDoubleTapAvailable() + return isSuggestionComplete(new AmbientDisplayConfiguration(context), prefs); + } + + @VisibleForTesting + static boolean isSuggestionComplete(AmbientDisplayConfiguration config, + SharedPreferences prefs) { + return !config.pulseOnDoubleTapAvailable() || prefs.getBoolean(DoubleTapScreenSettings.PREF_KEY_SUGGESTION_COMPLETE, false); } diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java index 2565dc845d..72a77b0a39 100644 --- a/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java @@ -17,6 +17,7 @@ package com.android.settings.gestures; import static com.google.common.truth.Truth.assertThat; + import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.when; @@ -46,9 +47,7 @@ import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; @RunWith(SettingsRobolectricTestRunner.class) -@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = { - SettingsShadowResources.class -}) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O) public class DoubleTapScreenPreferenceControllerTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) @@ -139,25 +138,19 @@ public class DoubleTapScreenPreferenceControllerTest { @Test public void isSuggestionCompleted_ambientDisplay_falseWhenNotVisited() { - SettingsShadowResources.overrideResource( - com.android.internal.R.string.config_dozeComponent, "foo"); - SettingsShadowResources.overrideResource( - com.android.internal.R.string.config_dozeDoubleTapSensorType, "bar"); + when(mAmbientDisplayConfiguration.pulseOnDoubleTapAvailable()).thenReturn(true); // No stored value in shared preferences if not visited yet. final Context context = RuntimeEnvironment.application; final SharedPreferences prefs = new SuggestionFeatureProviderImpl(context) .getSharedPrefs(context); - assertThat(DoubleTapScreenPreferenceController.isSuggestionComplete(context, prefs)) - .isFalse(); + assertThat(DoubleTapScreenPreferenceController.isSuggestionComplete( + mAmbientDisplayConfiguration, prefs)).isFalse(); } @Test public void isSuggestionCompleted_ambientDisplay_trueWhenVisited() { - SettingsShadowResources.overrideResource( - com.android.internal.R.string.config_dozeComponent, "foo"); - SettingsShadowResources.overrideResource( - com.android.internal.R.string.config_dozeDoubleTapSensorType, "bar"); + when(mAmbientDisplayConfiguration.pulseOnDoubleTapAvailable()).thenReturn(false); final Context context = RuntimeEnvironment.application; final SharedPreferences prefs = new SuggestionFeatureProviderImpl(context) .getSharedPrefs(context); @@ -165,7 +158,7 @@ public class DoubleTapScreenPreferenceControllerTest { prefs.edit().putBoolean( DoubleTapScreenSettings.PREF_KEY_SUGGESTION_COMPLETE, true).commit(); - assertThat(DoubleTapScreenPreferenceController.isSuggestionComplete(context, prefs)) - .isTrue(); + assertThat(DoubleTapScreenPreferenceController.isSuggestionComplete( + mAmbientDisplayConfiguration, prefs)).isTrue(); } } -- 2.11.0