Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19b9f120 authored by Fan Zhang's avatar Fan Zhang
Browse files

Remove wrapper class for AutofillManager in Settings

Robolectric now supports new system services. So we no longer need any
wrapper class.

Bug: 76167422
Test: robotests
Change-Id: Ic54b95f747bea933bacec299b00a29f3cc4f7bb5
parent e6455580
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -23,22 +23,22 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.view.autofill.AutofillManager;

import com.android.settings.wrapper.AutofillManagerWrapper;
import com.android.settingslib.applications.DefaultAppInfo;

public class DefaultAutofillPreferenceController extends DefaultAppPreferenceController {
    private AutofillManagerWrapper mAutofillManager;

    private final AutofillManager mAutofillManager;

    public DefaultAutofillPreferenceController(Context context) {
        super(context);

        mAutofillManager = new AutofillManagerWrapper(
                mContext.getSystemService(AutofillManager.class));
        mAutofillManager = mContext.getSystemService(AutofillManager.class);
    }

    @Override
    public boolean isAvailable() {
        return mAutofillManager.hasAutofillFeature()
        return mAutofillManager != null
                && mAutofillManager.hasAutofillFeature()
                && mAutofillManager.isAutofillSupported();
    }

+0 −59
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.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();
    }
}
+1 −3
Original line number Diff line number Diff line
@@ -30,8 +30,6 @@ import android.view.autofill.AutofillManager;

import com.android.settings.R;
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 org.junit.Before;
@@ -53,7 +51,7 @@ public class DefaultAutofillPreferenceControllerTest {
    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
    private PackageManagerWrapper mPackageManager;
    @Mock
    private AutofillManagerWrapper mAutofillManager;
    private AutofillManager mAutofillManager;

    private DefaultAutofillPreferenceController mController;