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

Commit 78702edc authored by Wei Sheng Shih's avatar Wei Sheng Shih Committed by Android (Google) Code Review
Browse files

Merge "Preventing NPE crash when binder call isOnBackInvokedCallbackEnabled" into main

parents 702050b6 21b92d5d
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();
        }
    }