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

Commit 1db5e5d1 authored by Daniel's avatar Daniel
Browse files

Enable credential suggestions without autofill provider

When the user does not select an autofill provider as the main password
provider, the autofill feature gets disabled. However, for views that
have credman requests, we still want to support providing credman
suggestions. To enable this, credential autofill service will be the
default autofill provider if there is no valid autofill provider. The
autofill session, in this case, will only be activated when the views
have credman requests.

Bug: 330177328
Test: cts
Change-Id: I9a7c8c6763d2814ed5a46790442f0133f0bd7537
parent 82612236
Loading
Loading
Loading
Loading
+10 −3
Original line number Original line Diff line number Diff line
@@ -1592,7 +1592,8 @@ public final class AutofillManager {
                // request comes in but PCC Detection hasn't been triggered. There is no benefit to
                // request comes in but PCC Detection hasn't been triggered. There is no benefit to
                // trigger PCC Detection separately in those cases.
                // trigger PCC Detection separately in those cases.
                if (!isActiveLocked()) {
                if (!isActiveLocked()) {
                    final boolean clientAdded = tryAddServiceClientIfNeededLocked();
                    final boolean clientAdded =
                            tryAddServiceClientIfNeededLocked(isCredmanRequested);
                    if (clientAdded) {
                    if (clientAdded) {
                        startSessionLocked(/* id= */ AutofillId.NO_AUTOFILL_ID, /* bounds= */ null,
                        startSessionLocked(/* id= */ AutofillId.NO_AUTOFILL_ID, /* bounds= */ null,
                            /* value= */ null, /* flags= */ FLAG_PCC_DETECTION);
                            /* value= */ null, /* flags= */ FLAG_PCC_DETECTION);
@@ -1850,7 +1851,8 @@ public final class AutofillManager {
            Rect bounds, AutofillValue value, int flags) {
            Rect bounds, AutofillValue value, int flags) {
        if (shouldIgnoreViewEnteredLocked(id, flags)) return null;
        if (shouldIgnoreViewEnteredLocked(id, flags)) return null;


        final boolean clientAdded = tryAddServiceClientIfNeededLocked();
        boolean credmanRequested = isCredmanRequested(view);
        final boolean clientAdded = tryAddServiceClientIfNeededLocked(credmanRequested);
        if (!clientAdded) {
        if (!clientAdded) {
            if (sVerbose) Log.v(TAG, "ignoring notifyViewEntered(" + id + "): no service client");
            if (sVerbose) Log.v(TAG, "ignoring notifyViewEntered(" + id + "): no service client");
            return null;
            return null;
@@ -2645,6 +2647,11 @@ public final class AutofillManager {
     */
     */
    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private boolean tryAddServiceClientIfNeededLocked() {
    private boolean tryAddServiceClientIfNeededLocked() {
        return tryAddServiceClientIfNeededLocked(/*credmanRequested=*/ false);
    }

    @GuardedBy("mLock")
    private boolean tryAddServiceClientIfNeededLocked(boolean credmanRequested) {
        final AutofillClient client = getClient();
        final AutofillClient client = getClient();
        if (client == null) {
        if (client == null) {
            return false;
            return false;
@@ -2659,7 +2666,7 @@ public final class AutofillManager {
                final int userId = mContext.getUserId();
                final int userId = mContext.getUserId();
                final SyncResultReceiver receiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS);
                final SyncResultReceiver receiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS);
                mService.addClient(mServiceClient, client.autofillClientGetComponentName(),
                mService.addClient(mServiceClient, client.autofillClientGetComponentName(),
                        userId, receiver);
                        userId, receiver, credmanRequested);
                int flags = 0;
                int flags = 0;
                try {
                try {
                    flags = receiver.getIntResult();
                    flags = receiver.getIntResult();
+1 −1
Original line number Original line Diff line number Diff line
@@ -38,7 +38,7 @@ import com.android.internal.os.IResultReceiver;
oneway interface IAutoFillManager {
oneway interface IAutoFillManager {
    // Returns flags: FLAG_ADD_CLIENT_ENABLED | FLAG_ADD_CLIENT_DEBUG | FLAG_ADD_CLIENT_VERBOSE
    // Returns flags: FLAG_ADD_CLIENT_ENABLED | FLAG_ADD_CLIENT_DEBUG | FLAG_ADD_CLIENT_VERBOSE
    void addClient(in IAutoFillManagerClient client, in ComponentName componentName, int userId,
    void addClient(in IAutoFillManagerClient client, in ComponentName componentName, int userId,
        in IResultReceiver result);
        in IResultReceiver result, boolean credmanRequested);
    void removeClient(in IAutoFillManagerClient client, int userId);
    void removeClient(in IAutoFillManagerClient client, int userId);
    void startSession(IBinder activityToken, in IBinder appCallback, in AutofillId autoFillId,
    void startSession(IBinder activityToken, in IBinder appCallback, in AutofillId autoFillId,
        in Rect bounds, in AutofillValue value, int userId, boolean hasCallback, int flags,
        in Rect bounds, in AutofillValue value, int userId, boolean hasCallback, int flags,
+1 −1
Original line number Original line Diff line number Diff line
@@ -5,6 +5,6 @@
   Note: This file is ignored for devices older that API 31
   Note: This file is ignored for devices older that API 31
   See https://developer.android.com/about/versions/12/backup-restore
   See https://developer.android.com/about/versions/12/backup-restore
-->
-->
<autofill-service-configuration
<autofill-service
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:supportsInlineSuggestions="true"/>
    android:supportsInlineSuggestions="true"/>
 No newline at end of file
+3 −3
Original line number Original line Diff line number Diff line
@@ -1625,13 +1625,13 @@ public final class AutofillManagerService
    final class AutoFillManagerServiceStub extends IAutoFillManager.Stub {
    final class AutoFillManagerServiceStub extends IAutoFillManager.Stub {
        @Override
        @Override
        public void addClient(IAutoFillManagerClient client, ComponentName componentName,
        public void addClient(IAutoFillManagerClient client, ComponentName componentName,
                int userId, IResultReceiver receiver) {
                int userId, IResultReceiver receiver, boolean credmanRequested) {
            int flags = 0;
            int flags = 0;
            try {
            try {
                synchronized (mLock) {
                synchronized (mLock) {
                    final int enabledFlags =
                    final int enabledFlags =
                            getServiceForUserWithLocalBinderIdentityLocked(userId)
                            getServiceForUserWithLocalBinderIdentityLocked(userId)
                            .addClientLocked(client, componentName);
                            .addClientLocked(client, componentName, credmanRequested);
                    if (enabledFlags != 0) {
                    if (enabledFlags != 0) {
                        flags |= enabledFlags;
                        flags |= enabledFlags;
                    }
                    }
@@ -1644,7 +1644,7 @@ public final class AutofillManagerService
                }
                }
            } catch (Exception ex) {
            } catch (Exception ex) {
                // Don't do anything, send back default flags
                // Don't do anything, send back default flags
                Log.wtf(TAG, "addClient(): failed " + ex.toString());
                Log.wtf(TAG, "addClient(): failed " + ex.toString(), ex);
            } finally {
            } finally {
                send(receiver, flags);
                send(receiver, flags);
            }
            }
+41 −11
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.ActivityManagerInternal;
import android.app.ActivityManagerInternal;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManager.NameNotFoundException;
@@ -96,6 +97,7 @@ import com.android.server.wm.ActivityTaskManagerInternal;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.Random;
/**
/**
 * Bridge between the {@code system_server}'s {@link AutofillManagerService} and the
 * Bridge between the {@code system_server}'s {@link AutofillManagerService} and the
@@ -293,8 +295,19 @@ final class AutofillManagerServiceImpl
     * @return {@code 0} if disabled, {@code FLAG_ADD_CLIENT_ENABLED} if enabled (it might be
     * @return {@code 0} if disabled, {@code FLAG_ADD_CLIENT_ENABLED} if enabled (it might be
     * OR'ed with {@code FLAG_AUGMENTED_AUTOFILL_REQUEST}).
     * OR'ed with {@code FLAG_AUGMENTED_AUTOFILL_REQUEST}).
     */
     */
    @GuardedBy("mLock")
    int addClientLocked(IAutoFillManagerClient client, ComponentName componentName,
    int addClientLocked(IAutoFillManagerClient client, ComponentName componentName) {
            boolean credmanRequested) {
        synchronized (mLock) {
            ComponentName credComponentName = getCredentialAutofillService(getContext());

            if (!credmanRequested
                    && Objects.equals(credComponentName,
                    mInfo == null ? null : mInfo.getServiceInfo().getComponentName())) {
                // If the service component name corresponds to cred component name, then it means
                // no autofill provider is selected by the user. Cred Autofill Service should only
                // be active if there is a credman request.
                return 0;
            }
            if (mClients == null) {
            if (mClients == null) {
                mClients = new RemoteCallbackList<>();
                mClients = new RemoteCallbackList<>();
            }
            }
@@ -307,6 +320,7 @@ final class AutofillManagerServiceImpl
                    && isWhitelistedForAugmentedAutofillLocked(componentName)) {
                    && isWhitelistedForAugmentedAutofillLocked(componentName)) {
                return FLAG_ADD_CLIENT_ENABLED_FOR_AUGMENTED_AUTOFILL_ONLY;
                return FLAG_ADD_CLIENT_ENABLED_FOR_AUGMENTED_AUTOFILL_ONLY;
            }
            }
        }


        // No flags / disabled
        // No flags / disabled
        return 0;
        return 0;
@@ -1486,6 +1500,22 @@ final class AutofillManagerServiceImpl
        return true;
        return true;
    }
    }


    @Nullable
    private ComponentName getCredentialAutofillService(Context context) {
        ComponentName componentName = null;
        String credentialManagerAutofillCompName = context.getResources().getString(
                R.string.config_defaultCredentialManagerAutofillService);
        if (credentialManagerAutofillCompName != null
                && !credentialManagerAutofillCompName.isEmpty()) {
            componentName = ComponentName.unflattenFromString(
                    credentialManagerAutofillCompName);
        }
        if (componentName == null) {
            Slog.w(TAG, "Invalid CredentialAutofillService");
        }
        return componentName;
    }

    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private int getAugmentedAutofillServiceUidLocked() {
    private int getAugmentedAutofillServiceUidLocked() {
        if (mRemoteAugmentedAutofillServiceInfo == null) {
        if (mRemoteAugmentedAutofillServiceInfo == null) {
Loading