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

Commit a8192e1c authored by Adam He's avatar Adam He
Browse files

Use AFM.getAutofillServiceComponentName() in Settings's AutofillPickerTrampolineActivity

Fixes: 80189659
Test: m -j Settings && adb sync && adb shell kill `pid com.android.settings` && adb shell am start com.android.settings

Change-Id: I3dc4ebd1a8ffb26b131905c3fc4ed59567049925
parent c08dcbd7
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -14,9 +14,9 @@
package com.android.settings.applications.autofill;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.os.UserHandle;
import android.view.autofill.AutofillManager;

import com.android.settings.applications.defaultapps.DefaultAutofillPicker;
@@ -34,20 +34,9 @@ public class AutofillPickerTrampolineActivity extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // 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, UserHandle.myUserId());
        if (currentService != null && currentService.startsWith(packageName)) {
            // ...and succeed right away if it does.
            setResult(RESULT_OK);
            finish();
            return;
        }

        // Then check if the Autofill is available for the current user...
        final AutofillManager afm = getSystemService(AutofillManager.class);

        // First check if the Autofill is available for the current user...
        if (afm == null || !afm.hasAutofillFeature() || !afm.isAutofillSupported()) {
            // ... and fail right away if it is not.
            setResult(RESULT_CANCELED);
@@ -55,6 +44,17 @@ public class AutofillPickerTrampolineActivity extends Activity {
            return;
        }

        // Then check if the current user's service already belongs to the app...
        final Intent intent = getIntent();
        final String packageName = intent.getData().getSchemeSpecificPart();
        final ComponentName currentService = afm.getAutofillServiceComponentName();
        if (currentService != null && currentService.getPackageName().equals(packageName)) {
            // ...and succeed right away if it does.
            setResult(RESULT_OK);
            finish();
            return;
        }

        // Otherwise, go ahead and show the real UI...
        final Intent newIntent = new Intent(this, AutofillPickerActivity.class)
                .setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT)