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

Commit 72aa9333 authored by Android Build Merger (Role)'s avatar Android Build Merger (Role) Committed by Android (Google) Code Review
Browse files

Merge "Merge "Destroy fill UI when app dies." into pi-dev am: 8ab878eb" into pi-dev-plus-aosp

parents 1976c21a 3ed3c421
Loading
Loading
Loading
Loading
+38 −3
Original line number Original line Diff line number Diff line
@@ -52,6 +52,7 @@ import android.os.Binder;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder;
import android.os.IBinder.DeathRecipient;
import android.os.Parcelable;
import android.os.Parcelable;
import android.os.RemoteCallback;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.RemoteException;
@@ -87,7 +88,6 @@ import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.os.HandlerCaller;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.ArrayUtils;
import com.android.server.autofill.ui.AutoFillUI;
import com.android.server.autofill.ui.AutoFillUI;
import com.android.server.autofill.ui.PendingUi;
import com.android.server.autofill.ui.PendingUi;
@@ -158,6 +158,9 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private IAutoFillManagerClient mClient;
    private IAutoFillManagerClient mClient;


    @GuardedBy("mLock")
    private DeathRecipient mClientVulture;

    private final RemoteFillService mRemoteFillService;
    private final RemoteFillService mRemoteFillService;


    @GuardedBy("mLock")
    @GuardedBy("mLock")
@@ -509,7 +512,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        mWtfHistory = wtfHistory;
        mWtfHistory = wtfHistory;
        mComponentName = componentName;
        mComponentName = componentName;
        mCompatMode = compatMode;
        mCompatMode = compatMode;
        mClient = IAutoFillManagerClient.Stub.asInterface(client);
        setClientLocked(client);


        mMetricsLogger.write(newLogMaker(MetricsEvent.AUTOFILL_SESSION_STARTED)
        mMetricsLogger.write(newLogMaker(MetricsEvent.AUTOFILL_SESSION_STARTED)
                .addTaggedData(MetricsEvent.FIELD_FLAGS, flags));
                .addTaggedData(MetricsEvent.FIELD_FLAGS, flags));
@@ -539,13 +542,44 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                return;
                return;
            }
            }
            mActivityToken = newActivity;
            mActivityToken = newActivity;
            mClient = IAutoFillManagerClient.Stub.asInterface(newClient);
            setClientLocked(newClient);


            // The tracked id are not persisted in the client, hence update them
            // The tracked id are not persisted in the client, hence update them
            updateTrackedIdsLocked();
            updateTrackedIdsLocked();
        }
        }
    }
    }


    @GuardedBy("mLock")
    private void setClientLocked(@NonNull IBinder client) {
        unlinkClientVultureLocked();
        mClient = IAutoFillManagerClient.Stub.asInterface(client);
        mClientVulture = () -> {
            Slog.d(TAG, "handling death of " + mActivityToken + " when saving=" + mIsSaving);
            synchronized (mLock) {
                if (mIsSaving) {
                    mUi.hideFillUi(this);
                } else {
                    mUi.destroyAll(mPendingSaveUi, this, false);
                }
            }
        };
        try {
            mClient.asBinder().linkToDeath(mClientVulture, 0);
        } catch (RemoteException e) {
            Slog.w(TAG, "could not set binder death listener on autofill client: " + e);
        }
    }

    @GuardedBy("mLock")
    private void unlinkClientVultureLocked() {
        if (mClient != null && mClientVulture != null) {
            final boolean unlinked = mClient.asBinder().unlinkToDeath(mClientVulture, 0);
            if (!unlinked) {
                Slog.w(TAG, "unlinking vulture from death failed for " + mActivityToken);
            }
        }
    }

    // FillServiceCallbacks
    // FillServiceCallbacks
    @Override
    @Override
    public void onFillRequestSuccess(int requestFlags, @Nullable FillResponse response,
    public void onFillRequestSuccess(int requestFlags, @Nullable FillResponse response,
@@ -2443,6 +2477,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        if (mDestroyed) {
        if (mDestroyed) {
            return null;
            return null;
        }
        }
        unlinkClientVultureLocked();
        mUi.destroyAll(mPendingSaveUi, this, true);
        mUi.destroyAll(mPendingSaveUi, this, true);
        mUi.clearCallback(this);
        mUi.clearCallback(this);
        mDestroyed = true;
        mDestroyed = true;
+8 −8
Original line number Original line Diff line number Diff line
@@ -136,7 +136,7 @@ public final class AutoFillUI {
     * Hides the fill UI.
     * Hides the fill UI.
     */
     */
    public void hideFillUi(@NonNull AutoFillUiCallback callback) {
    public void hideFillUi(@NonNull AutoFillUiCallback callback) {
        mHandler.post(() -> hideFillUiUiThread(callback));
        mHandler.post(() -> hideFillUiUiThread(callback, true));
    }
    }


    /**
    /**
@@ -189,7 +189,7 @@ public final class AutoFillUI {
                @Override
                @Override
                public void onResponsePicked(FillResponse response) {
                public void onResponsePicked(FillResponse response) {
                    log.setType(MetricsEvent.TYPE_DETAIL);
                    log.setType(MetricsEvent.TYPE_DETAIL);
                    hideFillUiUiThread(callback);
                    hideFillUiUiThread(callback, true);
                    if (mCallback != null) {
                    if (mCallback != null) {
                        mCallback.authenticate(response.getRequestId(),
                        mCallback.authenticate(response.getRequestId(),
                                AutofillManager.AUTHENTICATION_ID_DATASET_ID_UNDEFINED,
                                AutofillManager.AUTHENTICATION_ID_DATASET_ID_UNDEFINED,
@@ -200,7 +200,7 @@ public final class AutoFillUI {
                @Override
                @Override
                public void onDatasetPicked(Dataset dataset) {
                public void onDatasetPicked(Dataset dataset) {
                    log.setType(MetricsEvent.TYPE_ACTION);
                    log.setType(MetricsEvent.TYPE_ACTION);
                    hideFillUiUiThread(callback);
                    hideFillUiUiThread(callback, true);
                    if (mCallback != null) {
                    if (mCallback != null) {
                        final int datasetIndex = response.getDatasets().indexOf(dataset);
                        final int datasetIndex = response.getDatasets().indexOf(dataset);
                        mCallback.fill(response.getRequestId(), datasetIndex, dataset);
                        mCallback.fill(response.getRequestId(), datasetIndex, dataset);
@@ -210,7 +210,7 @@ public final class AutoFillUI {
                @Override
                @Override
                public void onCanceled() {
                public void onCanceled() {
                    log.setType(MetricsEvent.TYPE_DISMISS);
                    log.setType(MetricsEvent.TYPE_DISMISS);
                    hideFillUiUiThread(callback);
                    hideFillUiUiThread(callback, true);
                }
                }


                @Override
                @Override
@@ -367,9 +367,9 @@ public final class AutoFillUI {
    }
    }


    @android.annotation.UiThread
    @android.annotation.UiThread
    private void hideFillUiUiThread(@Nullable AutoFillUiCallback callback) {
    private void hideFillUiUiThread(@Nullable AutoFillUiCallback callback, boolean notifyClient) {
        if (mFillUi != null && (callback == null || callback == mCallback)) {
        if (mFillUi != null && (callback == null || callback == mCallback)) {
            mFillUi.destroy();
            mFillUi.destroy(notifyClient);
            mFillUi = null;
            mFillUi = null;
        }
        }
    }
    }
@@ -413,13 +413,13 @@ public final class AutoFillUI {
    @android.annotation.UiThread
    @android.annotation.UiThread
    private void destroyAllUiThread(@Nullable PendingUi pendingSaveUi,
    private void destroyAllUiThread(@Nullable PendingUi pendingSaveUi,
            @Nullable AutoFillUiCallback callback, boolean notifyClient) {
            @Nullable AutoFillUiCallback callback, boolean notifyClient) {
        hideFillUiUiThread(callback);
        hideFillUiUiThread(callback, notifyClient);
        destroySaveUiUiThread(pendingSaveUi, notifyClient);
        destroySaveUiUiThread(pendingSaveUi, notifyClient);
    }
    }


    @android.annotation.UiThread
    @android.annotation.UiThread
    private void hideAllUiThread(@Nullable AutoFillUiCallback callback) {
    private void hideAllUiThread(@Nullable AutoFillUiCallback callback) {
        hideFillUiUiThread(callback);
        hideFillUiUiThread(callback, true);
        final PendingUi pendingSaveUi = hideSaveUiUiThread(callback);
        final PendingUi pendingSaveUi = hideSaveUiUiThread(callback);
        if (pendingSaveUi != null && pendingSaveUi.getState() == PendingUi.STATE_FINISHED) {
        if (pendingSaveUi != null && pendingSaveUi.getState() == PendingUi.STATE_FINISHED) {
            if (sDebug) {
            if (sDebug) {
+14 −3
Original line number Original line Diff line number Diff line
@@ -415,10 +415,15 @@ final class FillUi {
        applyNewFilterText();
        applyNewFilterText();
    }
    }


    public void destroy() {
    public void destroy(boolean notifyClient) {
        throwIfDestroyed();
        throwIfDestroyed();
        if (mWindow != null) {
            mWindow.hide(false);
        }
        mCallback.onDestroy();
        mCallback.onDestroy();
        if (notifyClient) {
            mCallback.requestHideFillUi();
            mCallback.requestHideFillUi();
        }
        mDestroyed = true;
        mDestroyed = true;
    }
    }


@@ -644,6 +649,10 @@ final class FillUi {
         * Hides the window.
         * Hides the window.
         */
         */
        void hide() {
        void hide() {
            hide(true);
        }

        void hide(boolean destroyCallbackOnError) {
            try {
            try {
                if (mShowing) {
                if (mShowing) {
                    mWm.removeView(mContentView);
                    mWm.removeView(mContentView);
@@ -654,7 +663,9 @@ final class FillUi {
                // happen - since show() and hide() are always called in the UIThread - but if it
                // happen - since show() and hide() are always called in the UIThread - but if it
                // does, it should not crash the system.
                // does, it should not crash the system.
                Slog.e(TAG, "Exception hiding window ", e);
                Slog.e(TAG, "Exception hiding window ", e);
                if (destroyCallbackOnError) {
                    mCallback.onDestroy();
                    mCallback.onDestroy();
                }
            } finally {
            } finally {
                mOverlayControl.showOverlays();
                mOverlayControl.showOverlays();
            }
            }