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

Commit b38e19fd authored by Vadim Caen's avatar Vadim Caen Committed by Automerger Merge Worker
Browse files

Merge "Prevent callback registration when back flag is disabled" into tm-dev am: 1c6de844

parents bd04837e 1c6de844
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -1482,8 +1482,6 @@ public class Dialog implements DialogInterface, Window.Callback,
    /**
     * Returns the {@link OnBackInvokedDispatcher} instance associated with the window that this
     * dialog is attached to.
     *
     * Returns null if the dialog is not attached to a window with a decor.
     */
    @NonNull
    public OnBackInvokedDispatcher getOnBackInvokedDispatcher() {
+2 −1
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.window.CompatOnBackInvokedCallback;
import android.window.ImeOnBackInvokedDispatcher;
import android.window.OnBackInvokedCallback;
import android.window.OnBackInvokedDispatcher;
@@ -350,7 +351,7 @@ public class InputMethodService extends AbstractInputMethodService {
    private RingBuffer<MotionEvent> mPendingEvents;
    private ImeOnBackInvokedDispatcher mImeDispatcher;
    private Boolean mBackCallbackRegistered = false;
    private final OnBackInvokedCallback mCompatBackCallback = this::compatHandleBack;
    private final CompatOnBackInvokedCallback mCompatBackCallback = this::compatHandleBack;

    /**
     * Returns whether {@link InputMethodService} is responsible for rendering the back button and
+5 −10
Original line number Diff line number Diff line
@@ -196,6 +196,7 @@ import android.view.contentcapture.MainContentCaptureSession;
import android.view.inputmethod.InputMethodManager;
import android.widget.Scroller;
import android.window.ClientWindowFrames;
import android.window.CompatOnBackInvokedCallback;
import android.window.OnBackInvokedCallback;
import android.window.OnBackInvokedDispatcher;
import android.window.SurfaceSyncer;
@@ -339,13 +340,12 @@ public final class ViewRootImpl implements ViewParent,
    /**
     * The top level {@link OnBackInvokedDispatcher}.
     */
    private final WindowOnBackInvokedDispatcher mOnBackInvokedDispatcher =
            new WindowOnBackInvokedDispatcher();
    private final WindowOnBackInvokedDispatcher mOnBackInvokedDispatcher;
    /**
     * Compatibility {@link OnBackInvokedCallback} that dispatches KEYCODE_BACK events
     * to view root for apps using legacy back behavior.
     */
    private OnBackInvokedCallback mCompatOnBackInvokedCallback;
    private CompatOnBackInvokedCallback mCompatOnBackInvokedCallback;

    /**
     * Callback for notifying about global configuration changes.
@@ -959,6 +959,8 @@ public final class ViewRootImpl implements ViewParent,
        mFastScrollSoundEffectsEnabled = audioManager.areNavigationRepeatSoundEffectsEnabled();

        mScrollCaptureRequestTimeout = SCROLL_CAPTURE_REQUEST_TIMEOUT_MILLIS;
        mOnBackInvokedDispatcher = new WindowOnBackInvokedDispatcher(
                context.getApplicationInfo().isOnBackInvokedCallbackEnabled());
    }

    public static void addFirstDrawHandler(Runnable callback) {
@@ -10838,13 +10840,6 @@ public final class ViewRootImpl implements ViewParent,
                OnBackInvokedDispatcher.PRIORITY_DEFAULT, mCompatOnBackInvokedCallback);
    }

    private void unregisterCompatOnBackInvokedCallback() {
        if (mCompatOnBackInvokedCallback != null) {
            mOnBackInvokedDispatcher.unregisterOnBackInvokedCallback(mCompatOnBackInvokedCallback);
            mCompatOnBackInvokedCallback = null;
        }
    }

    @Override
    public void setTouchableRegion(Region r) {
        if (r != null) {
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.window;

/**
 * Marker interface for {@link OnBackInvokedCallback} used for backward compatibility between the
 * new system back and the old back event dispatching. Callbacks implementing this interface are
 * allowed to be registered even if <code>enableOnbackInvoked</code> is set to false in the
 * application manifest.
 * @hide
 */
public interface CompatOnBackInvokedCallback extends OnBackInvokedCallback{

    @Override
    void onBackInvoked();
}
+8 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.util.Log;
import android.util.Pair;
import android.window.WindowOnBackInvokedDispatcher.Checker;

import java.util.ArrayList;
import java.util.List;
@@ -50,6 +51,11 @@ public class ProxyOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
    private final Object mLock = new Object();
    private OnBackInvokedDispatcher mActualDispatcher = null;
    private ImeOnBackInvokedDispatcher mImeDispatcher;
    private final Checker mChecker;

    public ProxyOnBackInvokedDispatcher(boolean applicationCallBackEnabled) {
        mChecker = new Checker(applicationCallBackEnabled);
    }

    @Override
    public void registerOnBackInvokedCallback(
@@ -58,12 +64,10 @@ public class ProxyOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
            Log.v(TAG, String.format("Proxy register %s. mActualDispatcher=%s", callback,
                    mActualDispatcher));
        }
        if (priority < 0) {
            throw new IllegalArgumentException("Application registered OnBackInvokedCallback "
                    + "cannot have negative priority. Priority: " + priority);
        }
        if (mChecker.checkApplicationCallbackRegistration(priority, callback)) {
            registerOnBackInvokedCallbackUnchecked(callback, priority);
        }
    }

    @Override
    public void registerSystemOnBackInvokedCallback(@NonNull OnBackInvokedCallback callback) {
Loading