Loading src/com/android/settings/applications/AutofillManagerWrapper.java 0 → 100644 +41 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.applications; import android.view.autofill.AutofillManager; /** * This interface replicates a subset of the android.view.autofill.AutofillManager (AFM). The * interface exists so that we can use a thin wrapper around the AFM in production code and a mock * in tests. We cannot directly mock or shadow the AFM, because some of the methods we rely on are * newer than the API version supported by Robolectric. */ public interface AutofillManagerWrapper { /** * Calls {@code AutofillManager.hasAutofillFeature()}. * * @see AutofillManager#hasAutofillFeature */ public boolean hasAutofillFeature(); /** * Calls {@code AutofillManager.isAutofillSupported()}. * * @see AutofillManager#isAutofillSupported */ public boolean isAutofillSupported(); } src/com/android/settings/applications/AutofillManagerWrapperImpl.java 0 → 100644 +45 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.applications; import android.view.autofill.AutofillManager; public class AutofillManagerWrapperImpl implements AutofillManagerWrapper { private final AutofillManager mAfm; public AutofillManagerWrapperImpl(AutofillManager afm) { mAfm = afm; } @Override public boolean hasAutofillFeature() { if (mAfm == null) { return false; } return mAfm.hasAutofillFeature(); } @Override public boolean isAutofillSupported() { if (mAfm == null) { return false; } return mAfm.isAutofillSupported(); } } src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceController.java +10 −1 Original line number Diff line number Diff line Loading @@ -21,16 +21,25 @@ import android.content.Context; import android.content.Intent; import android.provider.Settings; import android.text.TextUtils; import android.view.autofill.AutofillManager; import com.android.settings.applications.AutofillManagerWrapper; import com.android.settings.applications.AutofillManagerWrapperImpl; public class DefaultAutofillPreferenceController extends DefaultAppPreferenceController { private AutofillManagerWrapper mAutofillManager; public DefaultAutofillPreferenceController(Context context) { super(context); mAutofillManager = new AutofillManagerWrapperImpl( mContext.getSystemService(AutofillManager.class)); } @Override public boolean isAvailable() { return true; return mAutofillManager.hasAutofillFeature() && mAutofillManager.isAutofillSupported(); } @Override Loading src/com/android/settings/language/LanguageAndInputSettings.java +23 −7 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ import android.os.UserHandle; import android.provider.SearchIndexableResource; import android.provider.Settings; import android.speech.tts.TtsEngines; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; import android.text.TextUtils; import android.view.inputmethod.InputMethodInfo; Loading Loading @@ -81,7 +83,16 @@ public class LanguageAndInputSettings extends DashboardFragment { @Override protected List<PreferenceController> getPreferenceControllers(Context context) { final Lifecycle lifecycle = getLifecycle(); if (mAmbientDisplayConfig == null) { mAmbientDisplayConfig = new AmbientDisplayConfiguration(context); } return buildPreferenceControllers(context, getLifecycle(), mAmbientDisplayConfig); } private static List<PreferenceController> buildPreferenceControllers(@NonNull Context context, @Nullable Lifecycle lifecycle, @NonNull AmbientDisplayConfiguration ambientDisplayConfiguration) { final List<PreferenceController> controllers = new ArrayList<>(); // Language controllers.add(new PhoneLanguagePreferenceController(context)); Loading @@ -93,11 +104,10 @@ public class LanguageAndInputSettings extends DashboardFragment { controllers.add(new PhysicalKeyboardPreferenceController(context, lifecycle)); final GameControllerPreferenceController gameControllerPreferenceController = new GameControllerPreferenceController(context); if (lifecycle != null) { lifecycle.addObserver(gameControllerPreferenceController); if (mAmbientDisplayConfig == null) { mAmbientDisplayConfig = new AmbientDisplayConfiguration(context); } controllers.add(gameControllerPreferenceController); // Gestures controllers.add(new AssistGesturePreferenceController(context, lifecycle)); Loading @@ -105,9 +115,9 @@ public class LanguageAndInputSettings extends DashboardFragment { controllers.add(new DoubleTwistPreferenceController(context, lifecycle)); controllers.add(new DoubleTapPowerPreferenceController(context, lifecycle)); controllers.add(new PickupGesturePreferenceController( context, lifecycle, mAmbientDisplayConfig, UserHandle.myUserId())); context, lifecycle, ambientDisplayConfiguration, UserHandle.myUserId())); controllers.add(new DoubleTapScreenPreferenceController( context, lifecycle, mAmbientDisplayConfig, UserHandle.myUserId())); context, lifecycle, ambientDisplayConfiguration, UserHandle.myUserId())); controllers.add(new DefaultAutofillPreferenceController(context)); return controllers; } Loading Loading @@ -163,5 +173,11 @@ public class LanguageAndInputSettings extends DashboardFragment { sir.xmlResId = R.xml.language_and_input; return Arrays.asList(sir); } @Override public List<PreferenceController> getPreferenceControllers(Context context) { return buildPreferenceControllers(context, null, new AmbientDisplayConfiguration(context)); } }; } tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceControllerTest.java +18 −1 Original line number Diff line number Diff line Loading @@ -22,10 +22,12 @@ import android.content.pm.PackageManager; import android.os.UserManager; import android.provider.Settings; import android.support.v7.preference.Preference; import android.view.autofill.AutofillManager; import com.android.settings.R; import com.android.settings.SettingsRobolectricTestRunner; import com.android.settings.TestConfig; import com.android.settings.applications.AutofillManagerWrapper; import com.android.settings.applications.PackageManagerWrapper; import org.junit.Before; Loading Loading @@ -54,6 +56,8 @@ public class DefaultAutofillPreferenceControllerTest { private UserManager mUserManager; @Mock(answer = Answers.RETURNS_DEEP_STUBS) private PackageManagerWrapper mPackageManager; @Mock private AutofillManagerWrapper mAutofillManager; private DefaultAutofillPreferenceController mController; Loading @@ -64,10 +68,23 @@ public class DefaultAutofillPreferenceControllerTest { mController = spy(new DefaultAutofillPreferenceController(mContext)); ReflectionHelpers.setField(mController, "mPackageManager", mPackageManager); ReflectionHelpers.setField(mController, "mAutofillManager", mAutofillManager); } @Test public void isAlwaysAvailable() { public void isAvailableIfHasFeatureAndSupported() { when(mContext.getSystemService(AutofillManager.class)).thenReturn(null); assertThat(mController.isAvailable()).isFalse(); when(mAutofillManager.hasAutofillFeature()).thenReturn(false); assertThat(mController.isAvailable()).isFalse(); when(mAutofillManager.hasAutofillFeature()).thenReturn(true); when(mAutofillManager.isAutofillSupported()).thenReturn(false); assertThat(mController.isAvailable()).isFalse(); when(mAutofillManager.hasAutofillFeature()).thenReturn(true); when(mAutofillManager.isAutofillSupported()).thenReturn(true); assertThat(mController.isAvailable()).isTrue(); } Loading Loading
src/com/android/settings/applications/AutofillManagerWrapper.java 0 → 100644 +41 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.applications; import android.view.autofill.AutofillManager; /** * This interface replicates a subset of the android.view.autofill.AutofillManager (AFM). The * interface exists so that we can use a thin wrapper around the AFM in production code and a mock * in tests. We cannot directly mock or shadow the AFM, because some of the methods we rely on are * newer than the API version supported by Robolectric. */ public interface AutofillManagerWrapper { /** * Calls {@code AutofillManager.hasAutofillFeature()}. * * @see AutofillManager#hasAutofillFeature */ public boolean hasAutofillFeature(); /** * Calls {@code AutofillManager.isAutofillSupported()}. * * @see AutofillManager#isAutofillSupported */ public boolean isAutofillSupported(); }
src/com/android/settings/applications/AutofillManagerWrapperImpl.java 0 → 100644 +45 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.applications; import android.view.autofill.AutofillManager; public class AutofillManagerWrapperImpl implements AutofillManagerWrapper { private final AutofillManager mAfm; public AutofillManagerWrapperImpl(AutofillManager afm) { mAfm = afm; } @Override public boolean hasAutofillFeature() { if (mAfm == null) { return false; } return mAfm.hasAutofillFeature(); } @Override public boolean isAutofillSupported() { if (mAfm == null) { return false; } return mAfm.isAutofillSupported(); } }
src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceController.java +10 −1 Original line number Diff line number Diff line Loading @@ -21,16 +21,25 @@ import android.content.Context; import android.content.Intent; import android.provider.Settings; import android.text.TextUtils; import android.view.autofill.AutofillManager; import com.android.settings.applications.AutofillManagerWrapper; import com.android.settings.applications.AutofillManagerWrapperImpl; public class DefaultAutofillPreferenceController extends DefaultAppPreferenceController { private AutofillManagerWrapper mAutofillManager; public DefaultAutofillPreferenceController(Context context) { super(context); mAutofillManager = new AutofillManagerWrapperImpl( mContext.getSystemService(AutofillManager.class)); } @Override public boolean isAvailable() { return true; return mAutofillManager.hasAutofillFeature() && mAutofillManager.isAutofillSupported(); } @Override Loading
src/com/android/settings/language/LanguageAndInputSettings.java +23 −7 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ import android.os.UserHandle; import android.provider.SearchIndexableResource; import android.provider.Settings; import android.speech.tts.TtsEngines; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; import android.text.TextUtils; import android.view.inputmethod.InputMethodInfo; Loading Loading @@ -81,7 +83,16 @@ public class LanguageAndInputSettings extends DashboardFragment { @Override protected List<PreferenceController> getPreferenceControllers(Context context) { final Lifecycle lifecycle = getLifecycle(); if (mAmbientDisplayConfig == null) { mAmbientDisplayConfig = new AmbientDisplayConfiguration(context); } return buildPreferenceControllers(context, getLifecycle(), mAmbientDisplayConfig); } private static List<PreferenceController> buildPreferenceControllers(@NonNull Context context, @Nullable Lifecycle lifecycle, @NonNull AmbientDisplayConfiguration ambientDisplayConfiguration) { final List<PreferenceController> controllers = new ArrayList<>(); // Language controllers.add(new PhoneLanguagePreferenceController(context)); Loading @@ -93,11 +104,10 @@ public class LanguageAndInputSettings extends DashboardFragment { controllers.add(new PhysicalKeyboardPreferenceController(context, lifecycle)); final GameControllerPreferenceController gameControllerPreferenceController = new GameControllerPreferenceController(context); if (lifecycle != null) { lifecycle.addObserver(gameControllerPreferenceController); if (mAmbientDisplayConfig == null) { mAmbientDisplayConfig = new AmbientDisplayConfiguration(context); } controllers.add(gameControllerPreferenceController); // Gestures controllers.add(new AssistGesturePreferenceController(context, lifecycle)); Loading @@ -105,9 +115,9 @@ public class LanguageAndInputSettings extends DashboardFragment { controllers.add(new DoubleTwistPreferenceController(context, lifecycle)); controllers.add(new DoubleTapPowerPreferenceController(context, lifecycle)); controllers.add(new PickupGesturePreferenceController( context, lifecycle, mAmbientDisplayConfig, UserHandle.myUserId())); context, lifecycle, ambientDisplayConfiguration, UserHandle.myUserId())); controllers.add(new DoubleTapScreenPreferenceController( context, lifecycle, mAmbientDisplayConfig, UserHandle.myUserId())); context, lifecycle, ambientDisplayConfiguration, UserHandle.myUserId())); controllers.add(new DefaultAutofillPreferenceController(context)); return controllers; } Loading Loading @@ -163,5 +173,11 @@ public class LanguageAndInputSettings extends DashboardFragment { sir.xmlResId = R.xml.language_and_input; return Arrays.asList(sir); } @Override public List<PreferenceController> getPreferenceControllers(Context context) { return buildPreferenceControllers(context, null, new AmbientDisplayConfiguration(context)); } }; }
tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceControllerTest.java +18 −1 Original line number Diff line number Diff line Loading @@ -22,10 +22,12 @@ import android.content.pm.PackageManager; import android.os.UserManager; import android.provider.Settings; import android.support.v7.preference.Preference; import android.view.autofill.AutofillManager; import com.android.settings.R; import com.android.settings.SettingsRobolectricTestRunner; import com.android.settings.TestConfig; import com.android.settings.applications.AutofillManagerWrapper; import com.android.settings.applications.PackageManagerWrapper; import org.junit.Before; Loading Loading @@ -54,6 +56,8 @@ public class DefaultAutofillPreferenceControllerTest { private UserManager mUserManager; @Mock(answer = Answers.RETURNS_DEEP_STUBS) private PackageManagerWrapper mPackageManager; @Mock private AutofillManagerWrapper mAutofillManager; private DefaultAutofillPreferenceController mController; Loading @@ -64,10 +68,23 @@ public class DefaultAutofillPreferenceControllerTest { mController = spy(new DefaultAutofillPreferenceController(mContext)); ReflectionHelpers.setField(mController, "mPackageManager", mPackageManager); ReflectionHelpers.setField(mController, "mAutofillManager", mAutofillManager); } @Test public void isAlwaysAvailable() { public void isAvailableIfHasFeatureAndSupported() { when(mContext.getSystemService(AutofillManager.class)).thenReturn(null); assertThat(mController.isAvailable()).isFalse(); when(mAutofillManager.hasAutofillFeature()).thenReturn(false); assertThat(mController.isAvailable()).isFalse(); when(mAutofillManager.hasAutofillFeature()).thenReturn(true); when(mAutofillManager.isAutofillSupported()).thenReturn(false); assertThat(mController.isAvailable()).isFalse(); when(mAutofillManager.hasAutofillFeature()).thenReturn(true); when(mAutofillManager.isAutofillSupported()).thenReturn(true); assertThat(mController.isAvailable()).isTrue(); } Loading