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

Commit 21b92d5d authored by wilsonshih's avatar wilsonshih
Browse files

Preventing NPE crash when binder call isOnBackInvokedCallbackEnabled

The IME on back dispatcher may call the host context after the
context is deleted, checking whether the host context exists before
accessing it.

Flag: EXEMPT bugfix
Bug: 381495419
Test: presubmit
Change-Id: I9dc1b2d26b8f6b37a7eb57222bb9141f6d145f27
parent e4046a28
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -464,7 +464,12 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
     * Returns false if the legacy back behavior should be used.
     */
    public boolean isOnBackInvokedCallbackEnabled() {
        return isOnBackInvokedCallbackEnabled(mChecker.getContext());
        final Context hostContext = mChecker.getContext();
        if (hostContext == null) {
            Log.w(TAG, "OnBackInvokedCallback is disabled, host context is removed!");
            return false;
        }
        return isOnBackInvokedCallbackEnabled(hostContext);
    }

    /**
@@ -695,7 +700,12 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
         */
        public boolean checkApplicationCallbackRegistration(int priority,
                OnBackInvokedCallback callback) {
            if (!WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(getContext())
            final Context hostContext = getContext();
            if (hostContext == null) {
                Log.w(TAG, "OnBackInvokedCallback is disabled, host context is removed!");
                return false;
            }
            if (!WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(hostContext)
                    && !(callback instanceof CompatOnBackInvokedCallback)) {
                Log.w(TAG,
                        "OnBackInvokedCallback is not enabled for the application."
@@ -720,7 +730,7 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
            return true;
        }

        private Context getContext() {
        @Nullable private Context getContext() {
            return mContext.get();
        }
    }