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

Commit f8f55e57 authored by Fan Zhang's avatar Fan Zhang
Browse files

Convert auto-fill default selector to full screen pattern.

Bug: 34280137
Test: RunSettingsRoboTests
Change-Id: Icde3bcaf11615010d481f39d8b32d28dfc120018
parent 3fca717d
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -26,19 +26,12 @@
        android:fragment="com.android.settings.applications.ManageAssist"
        android:order="-20"/>

    <com.android.settings.applications.DefaultAutoFillPreference
        android:key="default_autofill"
        android:title="@string/autofill_app"
        android:summary="@string/app_list_preference_none"
        settings:keywords="@string/autofill_keywords"
        android:order="-19"/>

    <Preference
        android:key="default_browser"
        android:title="@string/default_browser_title"
        android:summary="@string/default_browser_title_none"
        android:fragment="com.android.settings.applications.defaultapps.DefaultBrowserPicker"
        android:order="-18">
        android:order="-19">
        <extra android:name="for_work" android:value="false"/>
    </Preference>

@@ -48,26 +41,34 @@
        android:summary="@string/no_default_home"
        android:fragment="com.android.settings.applications.defaultapps.DefaultHomePicker"
        settings:keywords="@string/keywords_home"
        android:order="-17"/>
        android:order="-18"/>

    <Preference
        android:key="default_phone_app"
        android:title="@string/default_phone_title"
        android:fragment="com.android.settings.applications.defaultapps.DefaultPhonePicker"
        settings:keywords="@string/keywords_default_phone_app"
        android:order="-16"/>
        android:order="-17"/>

    <Preference
        android:key="default_sms_app"
        android:title="@string/sms_application_title"
        android:fragment="com.android.settings.applications.defaultapps.DefaultSmsPicker"
        settings:keywords="@string/keywords_more_default_sms_app"
        android:order="-15"/>
        android:order="-16"/>

    <Preference
        android:key="default_emergency_app"
        android:title="@string/default_emergency_app"
        settings:keywords="@string/keywords_emergency_app"
        android:order="-15"/>

    <com.android.settings.widget.GearPreference
        android:key="default_autofill"
        android:title="@string/autofill_app"
        android:summary="@string/app_list_preference_none"
        android:fragment="com.android.settings.applications.defaultapps.DefaultAutoFillPicker"
        settings:keywords="@string/autofill_keywords"
        android:order="-14"/>

    <Preference
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ import android.view.ViewGroup;
/**
 * An AppListPreference with optional settings button.
 */
@Deprecated
public class AppListPreferenceWithSettings extends AppListPreference {

    private View mSettingsIcon;
+2 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.provider.SearchIndexableResource;

import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.applications.defaultapps.DefaultAutoFillPreferenceController;
import com.android.settings.applications.defaultapps.DefaultBrowserPreferenceController;
import com.android.settings.applications.defaultapps.DefaultEmergencyPreferenceController;
import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
@@ -60,6 +61,7 @@ public class AdvancedAppSettings extends DashboardFragment {
        controllers.add(new DefaultSmsPreferenceController(context));
        controllers.add(new DefaultEmergencyPreferenceController(context));
        controllers.add(new DefaultHomePreferenceController(context));
        controllers.add(new DefaultAutoFillPreferenceController(context));
        return controllers;
    }

+0 −135
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.annotation.Nullable;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.provider.Settings;
import android.service.autofill.AutoFillService;
import android.service.autofill.AutoFillServiceInfo;
import android.util.AttributeSet;
import android.util.Log;

import com.android.settings.R;
import com.android.settings.AppListPreferenceWithSettings;

import java.util.ArrayList;
import java.util.List;

public class DefaultAutoFillPreference extends AppListPreferenceWithSettings {
    private static final String TAG = "DefaultAutoFill";

    private static final String SETTING = Settings.Secure.AUTO_FILL_SERVICE;

    public DefaultAutoFillPreference(Context context, AttributeSet attrs) {
        super(context, attrs);

        setSavesState(false);
        setShowItemNone(true);

        refreshData();
    }

    @Override
    protected CharSequence getConfirmationMessage(String value) {
        if (value == null || value.isEmpty()) {
            return null;
        }

        int index = findIndexOfValue(value);
        CharSequence[] entries = getEntries();
        if (index < 0 || index >= entries.length) {
            return null;
        }

        CharSequence entry = entries[index];
        return getContext().getString(R.string.autofill_confirmation_message, entry);
    }

    @Override
    protected boolean persistString(String value) {
        Settings.Secure.putString(getContext().getContentResolver(), SETTING, value);
        refreshData();
        return true;
    }

    private void refreshData() {
        ComponentName selectedComponent = getSelectedComponentName();
        List<AutoFillServiceInfo> infos = getInfos();

        AutoFillServiceInfo selectedInfo = null;
        int numberOfComponents = infos.size();
        ComponentName[] components = new ComponentName[numberOfComponents];
        for (int i = 0; i < numberOfComponents; ++i) {
            AutoFillServiceInfo info = infos.get(i);
            ServiceInfo serviceInfo = info.getServiceInfo();
            ComponentName component =
                    new ComponentName(serviceInfo.packageName, serviceInfo.name);
            components[i] = component;

            if (component.equals(selectedComponent)) {
                selectedInfo = info;
            }
        }

        ComponentName selectedComponentSettings = null;
        if (selectedInfo != null) {
            String settingsActivity = selectedInfo.getSettingsActivity();
            selectedComponentSettings = settingsActivity != null
                    ? new ComponentName(selectedComponent.getPackageName(), settingsActivity)
                    : null;
        } else { // selected component not found
            Log.w(TAG, "Selected AutoFillService not found " + selectedComponent);
            selectedComponent = null;
            selectedComponentSettings = null;
        }

        setComponentNames(components, selectedComponent);
        setSettingsComponent(selectedComponentSettings);
        setSummary(getEntry());
    }

    @Nullable
    private ComponentName getSelectedComponentName() {
        String componentString =
                Settings.Secure.getString(getContext().getContentResolver(), SETTING);
        if (componentString == null) {
            return null;
        }

        return ComponentName.unflattenFromString(componentString);
    }

    private List<AutoFillServiceInfo> getInfos() {
        PackageManager pm = getContext().getPackageManager();
        List<ResolveInfo> resolveInfos = pm.queryIntentServices(
                new Intent(AutoFillService.SERVICE_INTERFACE),
                PackageManager.GET_META_DATA);
        List<AutoFillServiceInfo> infos = new ArrayList<>(resolveInfos.size());
        for (ResolveInfo resolveInfo : resolveInfos) {
            ServiceInfo serviceInfo = resolveInfo.serviceInfo;
            AutoFillServiceInfo info = new AutoFillServiceInfo(pm, serviceInfo);
            infos.add(info);
        }
        return infos;
    }
}
+5 −3
Original line number Diff line number Diff line
@@ -118,15 +118,17 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
        for (Map.Entry<String, DefaultAppInfo> app : mCandidates.entrySet()) {
            final RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());
            final String appKey = app.getKey();

            pref.setTitle(app.getValue().loadLabel(mPm.getPackageManager()));
            pref.setIcon(app.getValue().loadIcon(mPm.getPackageManager()));
            final DefaultAppInfo info = app.getValue();
            pref.setTitle(info.loadLabel(mPm.getPackageManager()));
            pref.setIcon(info.loadIcon(mPm.getPackageManager()));
            pref.setKey(appKey);
            if (TextUtils.equals(defaultAppKey, appKey)) {
                pref.setChecked(true);
            }
            if (TextUtils.equals(systemDefaultAppKey, appKey)) {
                pref.setSummary(R.string.system_app);
            } else if (!TextUtils.isEmpty(info.summary)) {
                pref.setSummary(info.summary);
            }
            if (!TextUtils.isEmpty(app.getValue().disabledDescription)) {
                pref.setEnabled(false);
Loading