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

Commit a834309b authored by Koji Fukui's avatar Koji Fukui Committed by android-build-merger
Browse files

Merge "Remove AutofillManagerClient after AutofillManager is finalized" am:...

Merge "Remove AutofillManagerClient after AutofillManager is finalized" am: dd5384a4 am: 8d36beec
am: bb4a13b0

Change-Id: I5f3eea81f662d0396b7fd384b2e91c2087f41c0f
parents d28796d3 bb4a13b0
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.os;
import android.util.ArrayMap;
import android.util.Slog;

import java.io.PrintWriter;
import java.util.function.Consumer;

/**
@@ -399,6 +400,13 @@ public class RemoteCallbackList<E extends IInterface> {
        }
    }

    /** @hide */
    public void dump(PrintWriter pw, String prefix) {
        pw.print(prefix); pw.print("callbacks: "); pw.println(mCallbacks.size());
        pw.print(prefix); pw.print("killed: "); pw.println(mKilled);
        pw.print(prefix); pw.print("broadcasts count: "); pw.println(mBroadcastCount);
    }

    private void logExcessiveCallbacks() {
        final long size = mCallbacks.size();
        final long TOO_MANY = 3000;
+20 −1
Original line number Diff line number Diff line
@@ -54,6 +54,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

// TODO: use java.lang.ref.Cleaner once Android supports Java 9
import sun.misc.Cleaner;

/**
 * The {@link AutofillManager} provides ways for apps and custom views to integrate with the
 * Autofill Framework lifecycle.
@@ -302,6 +305,9 @@ public final class AutofillManager {
    @GuardedBy("mLock")
    private IAutoFillManagerClient mServiceClient;

    @GuardedBy("mLock")
    private Cleaner mServiceClientCleaner;

    @GuardedBy("mLock")
    private AutofillCallback mCallback;

@@ -1172,10 +1178,19 @@ public final class AutofillManager {
        if (mServiceClient == null) {
            mServiceClient = new AutofillManagerClient(this);
            try {
                final int flags = mService.addClient(mServiceClient, mContext.getUserId());
                final int userId = mContext.getUserId();
                final int flags = mService.addClient(mServiceClient, userId);
                mEnabled = (flags & FLAG_ADD_CLIENT_ENABLED) != 0;
                sDebug = (flags & FLAG_ADD_CLIENT_DEBUG) != 0;
                sVerbose = (flags & FLAG_ADD_CLIENT_VERBOSE) != 0;
                final IAutoFillManager service = mService;
                final IAutoFillManagerClient serviceClient = mServiceClient;
                mServiceClientCleaner = Cleaner.create(this, () -> {
                    try {
                        service.removeClient(serviceClient, userId);
                    } catch (RemoteException e) {
                    }
                });
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -1294,6 +1309,10 @@ public final class AutofillManager {
            if ((flags & SET_STATE_FLAG_RESET_CLIENT) != 0) {
                // Reset connection to system
                mServiceClient = null;
                if (mServiceClientCleaner != null) {
                    mServiceClientCleaner.clean();
                    mServiceClientCleaner = null;
                }
            }
        }
        sDebug = (flags & SET_STATE_FLAG_DEBUG) != 0;
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.view.autofill.IAutoFillManagerClient;
interface IAutoFillManager {
    // Returns flags: FLAG_ADD_CLIENT_ENABLED | FLAG_ADD_CLIENT_DEBUG | FLAG_ADD_CLIENT_VERBOSE
    int addClient(in IAutoFillManagerClient client, int userId);
    void removeClient(in IAutoFillManagerClient client, int userId);
    int startSession(IBinder activityToken, in IBinder appCallback, in AutofillId autoFillId,
            in Rect bounds, in AutofillValue value, int userId, boolean hasCallback, int flags,
            in ComponentName componentName);
+10 −0
Original line number Diff line number Diff line
@@ -511,6 +511,16 @@ public final class AutofillManagerService extends SystemService {
            }
        }

        @Override
        public void removeClient(IAutoFillManagerClient client, int userId) {
            synchronized (mLock) {
                final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
                if (service != null) {
                    service.removeClientLocked(client);
                }
            }
        }

        @Override
        public void setAuthenticationResult(Bundle data, int sessionId, int authenticationId,
                int userId) {
+13 −0
Original line number Diff line number Diff line
@@ -273,6 +273,12 @@ final class AutofillManagerServiceImpl {
        return isEnabled();
    }

    void removeClientLocked(IAutoFillManagerClient client) {
        if (mClients != null) {
            mClients.unregister(client);
        }
    }

    void setAuthenticationResultLocked(Bundle data, int sessionId, int authenticationId, int uid) {
        if (!isEnabled()) {
            return;
@@ -548,6 +554,10 @@ final class AutofillManagerServiceImpl {
        }

        sendStateToClients(true);
        if (mClients != null) {
            mClients.kill();
            mClients = null;
        }
    }

    @NonNull
@@ -752,6 +762,9 @@ final class AutofillManagerServiceImpl {
            }
        }

        pw.print(prefix); pw.println("Clients");
        mClients.dump(pw, prefix2);

        if (mEventHistory == null || mEventHistory.getEvents() == null
                || mEventHistory.getEvents().size() == 0) {
            pw.print(prefix); pw.println("No event on last fill response");