Merge "Remove wrapper class for AutofillManager in Settings" into pi-dev
am: e33ff4e97c
Change-Id: I67c3055eb4103cb1f18d498ec8daaea4edca3cee
This commit is contained in:
@@ -23,22 +23,22 @@ import android.provider.Settings;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.autofill.AutofillManager;
|
import android.view.autofill.AutofillManager;
|
||||||
|
|
||||||
import com.android.settings.wrapper.AutofillManagerWrapper;
|
|
||||||
import com.android.settingslib.applications.DefaultAppInfo;
|
import com.android.settingslib.applications.DefaultAppInfo;
|
||||||
|
|
||||||
public class DefaultAutofillPreferenceController extends DefaultAppPreferenceController {
|
public class DefaultAutofillPreferenceController extends DefaultAppPreferenceController {
|
||||||
private AutofillManagerWrapper mAutofillManager;
|
|
||||||
|
private final AutofillManager mAutofillManager;
|
||||||
|
|
||||||
public DefaultAutofillPreferenceController(Context context) {
|
public DefaultAutofillPreferenceController(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
mAutofillManager = new AutofillManagerWrapper(
|
mAutofillManager = mContext.getSystemService(AutofillManager.class);
|
||||||
mContext.getSystemService(AutofillManager.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return mAutofillManager.hasAutofillFeature()
|
return mAutofillManager != null
|
||||||
|
&& mAutofillManager.hasAutofillFeature()
|
||||||
&& mAutofillManager.isAutofillSupported();
|
&& mAutofillManager.isAutofillSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.wrapper;
|
|
||||||
|
|
||||||
import android.view.autofill.AutofillManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class replicates a subset of the android.view.autofill.AutofillManager (AFM). The
|
|
||||||
* class 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 class AutofillManagerWrapper {
|
|
||||||
private final AutofillManager mAfm;
|
|
||||||
|
|
||||||
public AutofillManagerWrapper(AutofillManager afm) {
|
|
||||||
mAfm = afm;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls {@code AutofillManager.hasAutofillFeature()}.
|
|
||||||
*
|
|
||||||
* @see AutofillManager#hasAutofillFeature
|
|
||||||
*/
|
|
||||||
public boolean hasAutofillFeature() {
|
|
||||||
if (mAfm == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mAfm.hasAutofillFeature();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls {@code AutofillManager.isAutofillSupported()}.
|
|
||||||
*
|
|
||||||
* @see AutofillManager#isAutofillSupported
|
|
||||||
*/
|
|
||||||
public boolean isAutofillSupported() {
|
|
||||||
if (mAfm == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mAfm.isAutofillSupported();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -30,8 +30,6 @@ import android.view.autofill.AutofillManager;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.wrapper.AutofillManagerWrapper;
|
|
||||||
import com.android.settingslib.applications.DefaultAppInfo;
|
|
||||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -53,7 +51,7 @@ public class DefaultAutofillPreferenceControllerTest {
|
|||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private PackageManagerWrapper mPackageManager;
|
private PackageManagerWrapper mPackageManager;
|
||||||
@Mock
|
@Mock
|
||||||
private AutofillManagerWrapper mAutofillManager;
|
private AutofillManager mAutofillManager;
|
||||||
|
|
||||||
private DefaultAutofillPreferenceController mController;
|
private DefaultAutofillPreferenceController mController;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user