Update DoubleTapScreenPrefCtrl to sdk 26
Test: make RunSettingsRoboTests -j40 Change-Id: Ia4ed886381e2758b7b1523648833fc57ca58a5b3
This commit is contained in:
@@ -22,6 +22,7 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -55,8 +56,13 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) {
|
public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) {
|
||||||
AmbientDisplayConfiguration ambientConfig = new AmbientDisplayConfiguration(context);
|
return isSuggestionComplete(new AmbientDisplayConfiguration(context), prefs);
|
||||||
return !ambientConfig.pulseOnDoubleTapAvailable()
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static boolean isSuggestionComplete(AmbientDisplayConfiguration config,
|
||||||
|
SharedPreferences prefs) {
|
||||||
|
return !config.pulseOnDoubleTapAvailable()
|
||||||
|| prefs.getBoolean(DoubleTapScreenSettings.PREF_KEY_SUGGESTION_COMPLETE, false);
|
|| prefs.getBoolean(DoubleTapScreenSettings.PREF_KEY_SUGGESTION_COMPLETE, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.gestures;
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -46,9 +47,7 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
|
||||||
SettingsShadowResources.class
|
|
||||||
})
|
|
||||||
public class DoubleTapScreenPreferenceControllerTest {
|
public class DoubleTapScreenPreferenceControllerTest {
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
@@ -139,25 +138,19 @@ public class DoubleTapScreenPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSuggestionCompleted_ambientDisplay_falseWhenNotVisited() {
|
public void isSuggestionCompleted_ambientDisplay_falseWhenNotVisited() {
|
||||||
SettingsShadowResources.overrideResource(
|
when(mAmbientDisplayConfiguration.pulseOnDoubleTapAvailable()).thenReturn(true);
|
||||||
com.android.internal.R.string.config_dozeComponent, "foo");
|
|
||||||
SettingsShadowResources.overrideResource(
|
|
||||||
com.android.internal.R.string.config_dozeDoubleTapSensorType, "bar");
|
|
||||||
// No stored value in shared preferences if not visited yet.
|
// No stored value in shared preferences if not visited yet.
|
||||||
final Context context = RuntimeEnvironment.application;
|
final Context context = RuntimeEnvironment.application;
|
||||||
final SharedPreferences prefs = new SuggestionFeatureProviderImpl(context)
|
final SharedPreferences prefs = new SuggestionFeatureProviderImpl(context)
|
||||||
.getSharedPrefs(context);
|
.getSharedPrefs(context);
|
||||||
|
|
||||||
assertThat(DoubleTapScreenPreferenceController.isSuggestionComplete(context, prefs))
|
assertThat(DoubleTapScreenPreferenceController.isSuggestionComplete(
|
||||||
.isFalse();
|
mAmbientDisplayConfiguration, prefs)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSuggestionCompleted_ambientDisplay_trueWhenVisited() {
|
public void isSuggestionCompleted_ambientDisplay_trueWhenVisited() {
|
||||||
SettingsShadowResources.overrideResource(
|
when(mAmbientDisplayConfiguration.pulseOnDoubleTapAvailable()).thenReturn(false);
|
||||||
com.android.internal.R.string.config_dozeComponent, "foo");
|
|
||||||
SettingsShadowResources.overrideResource(
|
|
||||||
com.android.internal.R.string.config_dozeDoubleTapSensorType, "bar");
|
|
||||||
final Context context = RuntimeEnvironment.application;
|
final Context context = RuntimeEnvironment.application;
|
||||||
final SharedPreferences prefs = new SuggestionFeatureProviderImpl(context)
|
final SharedPreferences prefs = new SuggestionFeatureProviderImpl(context)
|
||||||
.getSharedPrefs(context);
|
.getSharedPrefs(context);
|
||||||
@@ -165,7 +158,7 @@ public class DoubleTapScreenPreferenceControllerTest {
|
|||||||
prefs.edit().putBoolean(
|
prefs.edit().putBoolean(
|
||||||
DoubleTapScreenSettings.PREF_KEY_SUGGESTION_COMPLETE, true).commit();
|
DoubleTapScreenSettings.PREF_KEY_SUGGESTION_COMPLETE, true).commit();
|
||||||
|
|
||||||
assertThat(DoubleTapScreenPreferenceController.isSuggestionComplete(context, prefs))
|
assertThat(DoubleTapScreenPreferenceController.isSuggestionComplete(
|
||||||
.isTrue();
|
mAmbientDisplayConfiguration, prefs)).isTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user