Merge "Don't show autofill settings if not enabled" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
32d3d383cb
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
@@ -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
|
||||
|
@@ -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;
|
||||
@@ -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));
|
||||
@@ -93,11 +104,10 @@ public class LanguageAndInputSettings extends DashboardFragment {
|
||||
controllers.add(new PhysicalKeyboardPreferenceController(context, lifecycle));
|
||||
final GameControllerPreferenceController gameControllerPreferenceController
|
||||
= new GameControllerPreferenceController(context);
|
||||
lifecycle.addObserver(gameControllerPreferenceController);
|
||||
|
||||
if (mAmbientDisplayConfig == null) {
|
||||
mAmbientDisplayConfig = new AmbientDisplayConfiguration(context);
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(gameControllerPreferenceController);
|
||||
}
|
||||
|
||||
controllers.add(gameControllerPreferenceController);
|
||||
// Gestures
|
||||
controllers.add(new AssistGesturePreferenceController(context, lifecycle));
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user