Don't show autofill settings if not enabled

The non-indexable keys of language-and-input on my angler are:
  game_controller_settings_category, gesture_assist,
  gesture_double_tap_screen, default_autofill

Fixes: 35956220
Test: Disabled auto-fill and looked at settings: did not find
      autofill button and could not find auto-fill in search
      Settings robolectric test
Merged-In: I0923e707422d1b1de5153a63fa3a5fe4773c055d
Change-Id: I0923e707422d1b1de5153a63fa3a5fe4773c055d
This commit is contained in:
Philip P. Moltmann
2017-04-24 16:13:21 -07:00
parent 9797a39ad7
commit d984e90b63
6 changed files with 141 additions and 9 deletions

View File

@@ -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;
@@ -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;
@@ -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();
}

View File

@@ -31,6 +31,7 @@ import android.content.pm.PackageManager;
import android.hardware.input.InputManager;
import android.os.UserManager;
import android.provider.Settings;
import android.view.autofill.AutofillManager;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.textservice.TextServicesManager;
@@ -72,6 +73,8 @@ public class LanguageAndInputSettingsTest {
private DevicePolicyManager mDpm;
@Mock
private InputMethodManager mInputMethodManager;
@Mock
private AutofillManager mAutofillManager;
private TestFragment mFragment;
@Before
@@ -84,6 +87,7 @@ public class LanguageAndInputSettingsTest {
.thenReturn(mock(TextServicesManager.class));
when(mContext.getSystemService(Context.DEVICE_POLICY_SERVICE)).thenReturn(mDpm);
when(mContext.getSystemService(Context.INPUT_METHOD_SERVICE)).thenReturn(mImm);
when(mContext.getSystemService(AutofillManager.class)).thenReturn(mAutofillManager);
mFragment = new TestFragment(mContext);
}