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

Commit 69e43f0e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I93e9ea44,I0443e9c9 into main

* changes:
  Prevent duplicate IME callback registrations
  Add logging to ImeOnBackInvokedDispatcher
parents 0698161c 9d370d65
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5079,6 +5079,7 @@ public final class InputMethodManager {
                + " mCursorSelEnd=" + mCursorSelEnd
                + " mCursorCandStart=" + mCursorCandStart
                + " mCursorCandEnd=" + mCursorCandEnd);
        mImeDispatcher.dump(p, "  ");
    }

    /**
+36 −5
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.RemoteException;
import android.os.ResultReceiver;
import android.util.Log;
import android.util.Pair;
import android.util.Printer;
import android.view.ViewRootImpl;

import com.android.internal.annotations.VisibleForTesting;
@@ -181,12 +182,26 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc
        } else {
            imeCallback = new ImeOnBackInvokedCallback(iCallback, callbackId, priority);
        }
        if (unregisterCallback(callbackId, receivingDispatcher)) {
            Log.w(TAG, "Received IME callback that's already registered. Unregistering and "
                    + "reregistering. (callbackId: " + callbackId
                    + " current callbacks: " + mImeCallbacks.size() + ")");
        }
        mImeCallbacks.add(imeCallback);
        receivingDispatcher.registerOnBackInvokedCallbackUnchecked(imeCallback, priority);
    }

    private void unregisterReceivedCallback(
            int callbackId, OnBackInvokedDispatcher receivingDispatcher) {
            int callbackId, @NonNull OnBackInvokedDispatcher receivingDispatcher) {
        if (!unregisterCallback(callbackId, receivingDispatcher)) {
            Log.e(TAG, "Ime callback not found. Ignoring unregisterReceivedCallback. "
                    + "callbackId: " + callbackId
                    + " remaining callbacks: " + mImeCallbacks.size());
        }
    }

    private boolean unregisterCallback(int callbackId,
            @NonNull OnBackInvokedDispatcher receivingDispatcher) {
        ImeOnBackInvokedCallback callback = null;
        for (ImeOnBackInvokedCallback imeCallback : mImeCallbacks) {
            if (imeCallback.getId() == callbackId) {
@@ -195,12 +210,11 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc
            }
        }
        if (callback == null) {
            Log.e(TAG, "Ime callback not found. Ignoring unregisterReceivedCallback. "
                    + "callbackId: " + callbackId);
            return;
            return false;
        }
        receivingDispatcher.unregisterOnBackInvokedCallback(callback);
        mImeCallbacks.remove(callback);
        return true;
    }

    /**
@@ -243,6 +257,23 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc
        mQueuedReceive.clear();
    }

    /**
     * Dumps the registered IME callbacks.
     *
     * @param prefix prefix to be prepended to each line
     * @param p      printer to write the dump to
     */
    public void dump(@NonNull Printer p, @NonNull String prefix) {
        if (mImeCallbacks.isEmpty()) {
            p.println(prefix + TAG + " mImeCallbacks: []");
        } else {
            p.println(prefix + TAG + " mImeCallbacks:");
            for (ImeOnBackInvokedCallback callback : mImeCallbacks) {
                p.println(prefix + "  " + callback);
            }
        }
    }

    @VisibleForTesting(visibility = PACKAGE)
    public static class ImeOnBackInvokedCallback implements OnBackAnimationCallback {
        @NonNull
+0 −3
Original line number Diff line number Diff line
@@ -322,9 +322,6 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
            if (DEBUG) {
                Log.d(TAG, "sendCancelIfRunning: callback canceled");
            }
        } else {
            Log.w(TAG, "sendCancelIfRunning: isInProgress=" + isInProgress
                    + " callback=" + callback);
        }
    }