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

Commit 2d24e8a8 authored by Zimuzo Ezeozue's avatar Zimuzo Ezeozue Committed by Android (Google) Code Review
Browse files

Merge "Add autofill service setting in managed profile"

parents 5ad8ef26 fcf3f586
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2018 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.
  -->

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:key="default_autofill_picker"
    android:title="@string/autofill_app"
    settings:keywords="@string/autofill_keywords">

  <com.android.settings.widget.GearPreference
      android:key="default_autofill_main"
      android:title="@string/autofill_app"
      android:fragment="com.android.settings.applications.defaultapps.DefaultAutofillPicker"
      settings:keywords="@string/autofill_keywords">
    <extra android:name="for_work" android:value="false" />
  </com.android.settings.widget.GearPreference>


  <com.android.settings.widget.WorkOnlyCategory
      android:key="work_app_defaults"
      android:title="@string/default_for_work">

    <com.android.settings.widget.GearPreference
        android:key="default_autofill_work"
        android:title="@string/autofill_app"
        android:fragment="com.android.settings.applications.defaultapps.DefaultAutofillPicker"
        settings:keywords="@string/autofill_keywords">
      <extra android:name="for_work" android:value="true" />
    </com.android.settings.widget.GearPreference>
  </com.android.settings.widget.WorkOnlyCategory>
</PreferenceScreen>
+2 −2
Original line number Diff line number Diff line
@@ -54,10 +54,10 @@
            android:persistent="false"
            android:fragment="com.android.settings.inputmethod.SpellCheckersSettings" />

        <com.android.settings.widget.GearPreference
        <Preference
            android:key="default_autofill"
            android:title="@string/autofill_app"
            android:fragment="com.android.settings.applications.defaultapps.DefaultAutofillPicker"
            android:fragment="com.android.settings.applications.defaultapps.AutofillPicker"
            settings:keywords="@string/autofill_keywords" />

        <!-- User dictionary preference title and fragment will be set programmatically. -->
+3 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ package com.android.settings.applications.autofill;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.UserHandle;
import android.view.autofill.AutofillManager;

import com.android.settings.applications.defaultapps.DefaultAutofillPicker;
@@ -36,7 +37,8 @@ public class AutofillPickerTrampolineActivity extends Activity {
        // First check if the current user's service already belongs to the app...
        final Intent intent = getIntent();
        final String packageName = intent.getData().getSchemeSpecificPart();
        final String currentService = DefaultAutofillPicker.getDefaultKey(this);
        final String currentService = DefaultAutofillPicker.getDefaultKey(
                this, UserHandle.myUserId());
        if (currentService != null && currentService.startsWith(packageName)) {
            // ...and succeed right away if it does.
            setResult(RESULT_OK);
+84 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.defaultapps;

import android.content.Context;
import android.provider.SearchIndexableResource;

import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.applications.defaultapps.DefaultAutofillPreferenceController;
import com.android.settings.applications.defaultapps.DefaultWorkAutofillPreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.SearchIndexable;

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

@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class AutofillPicker extends DashboardFragment {
    private static final String TAG = "AutofillPicker";

    @Override
    public int getMetricsCategory() {
        return MetricsProto.MetricsEvent.DEFAULT_AUTOFILL_PICKER;
    }

    @Override
    protected String getLogTag() {
        return TAG;
    }

    @Override
    protected int getPreferenceScreenResId() {
        return R.xml.default_autofill_picker_settings;
    }

    @Override
    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
        return buildPreferenceControllers(context);
    }

    public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
            new BaseSearchIndexProvider() {
                @Override
                public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
                        boolean enabled) {
                    SearchIndexableResource searchIndexableResource =
                            new SearchIndexableResource(context);
                    searchIndexableResource.xmlResId = R.xml.default_autofill_picker_settings;
                    return Arrays.asList(searchIndexableResource);
                }

                @Override
                public List<AbstractPreferenceController> getPreferenceControllers(Context
                        context) {
                    return buildPreferenceControllers(context);
                }
            };

    private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
        return Arrays.asList(
                new DefaultAutofillPreferenceController(context),
                new DefaultWorkAutofillPreferenceController(context));
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -82,12 +82,16 @@ public abstract class DefaultAppPreferenceController extends AbstractPreferenceC
        final Intent settingIntent = getSettingIntent(app);
        if (settingIntent != null) {
            ((GearPreference) preference).setOnGearClickListener(
                    p -> mContext.startActivity(settingIntent));
                    p -> startActivity(settingIntent));
        } else {
            ((GearPreference) preference).setOnGearClickListener(null);
        }
    }

    protected void startActivity(Intent intent) {
        mContext.startActivity(intent);
    }

    protected abstract DefaultAppInfo getDefaultAppInfo();

    /**
Loading