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

Commit db2b55a2 authored by Felipe Leme's avatar Felipe Leme
Browse files

Implemented ACTION_REQUEST_SET_AUTOFILL_SERVICE.

Bug: 37673809
Fixes: 37576671
Test: manual verification
Test: make RunSettingsRoboTests -j90

Change-Id: I36170cb715473dfbf598deedd9719a46168aabc8
parent 0cdade8a
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -3077,6 +3077,16 @@
            android:permission="android.permission.DUMP"
            android:enabled="@bool/config_has_help" />

        <activity android:name=".applications.defaultapps.AutofillPickerActivity"
                android:taskAffinity=""
                android:noHistory="true">
            <intent-filter android:priority="1">
                <action android:name="android.settings.REQUEST_SET_AUTOFILL_SERVICE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="package" />
            </intent-filter>
        </activity>

        <!-- This is the longest AndroidManifest.xml ever. -->
    </application>
</manifest>
+44 −0
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.defaultapps;

import android.content.Intent;
import android.os.Bundle;

import com.android.settings.R;
import com.android.settings.SettingsActivity;

/**
 * Standalone activity used to launch {@link DefaultAppPickerFragment} from a
 * {@link android.provider.Settings#ACTION_REQUEST_SET_AUTOFILL_SERVICE} intent.
 */
public class AutofillPickerActivity extends SettingsActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        final Intent intent = getIntent();
        final String packageName = intent.getData().getSchemeSpecificPart();
        intent.putExtra(EXTRA_SHOW_FRAGMENT, DefaultAutofillPicker.class.getName());
        intent.putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, R.string.autofill_app);
        intent.putExtra(DefaultAutofillPicker.EXTRA_PACKAGE_NAME, packageName);

        super.onCreate(savedInstanceState);
    }

    @Override
    protected boolean isValidFragment(String fragmentName) {
        return super.isValidFragment(fragmentName)
                || DefaultAutofillPicker.class.getName().equals(fragmentName);
    }
}
+17 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.applications.defaultapps;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -38,6 +39,8 @@ public class DefaultAutofillPicker extends DefaultAppPickerFragment {
    static final String SETTING = Settings.Secure.AUTOFILL_SERVICE;
    static final Intent AUTOFILL_PROBE = new Intent(AutofillService.SERVICE_INTERFACE);

    static final String EXTRA_PACKAGE_NAME = "package_name";

    @Override
    public int getMetricsCategory() {
        return MetricsProto.MetricsEvent.DEFAULT_AUTOFILL_PICKER;
@@ -79,11 +82,24 @@ public class DefaultAutofillPicker extends DefaultAppPickerFragment {
    @Override
    protected boolean setDefaultKey(String key) {
        Settings.Secure.putString(getContext().getContentResolver(), SETTING, key);

        // Check if activity was launched from Settings.ACTION_REQUEST_SET_AUTOFILL_SERVICE
        // intent, and set proper result if so...
        final Activity activity = getActivity();
        if (activity != null) {
            final String packageName = activity.getIntent().getStringExtra(EXTRA_PACKAGE_NAME);
            if (packageName != null) {
                final int result = key != null && key.startsWith(packageName) ? Activity.RESULT_OK
                        : Activity.RESULT_CANCELED;
                activity.setResult(result);
                activity.finish();
            }
        }
        return true;
    }

    /**
     * Provides Intent to setting activity for the specified auto-fill service.
     * Provides Intent to setting activity for the specified autofill service.
     */
    static final class AutofillSettingIntentProvider implements SettingIntentProvider {