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

Commit 09f7f6f6 authored by Vadim Caen's avatar Vadim Caen Committed by Android (Google) Code Review
Browse files

Merge changes from topic "presubmit-am-b87ddd3bbf2947f1aa639cddcee6ecb8" into tm-dev

* changes:
  Remove callback before WindowState removal
  Improve startBackNavigation stability
parents fdf11ed6 d1a57ed4
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -149,6 +149,7 @@ import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.sysprop.DisplayProperties;
import android.text.TextUtils;
import android.util.AndroidRuntimeException;
import android.util.DisplayMetrics;
import android.util.EventLog;
@@ -8398,6 +8399,7 @@ public final class ViewRootImpl implements ViewParent,
                return;
            }
            mRemoved = true;
            mOnBackInvokedDispatcher.detachFromWindow();
            if (mAdded) {
                dispatchDetachedFromWindow();
            }
@@ -8432,8 +8434,6 @@ public final class ViewRootImpl implements ViewParent,

            mAdded = false;
        }
        unregisterCompatOnBackInvokedCallback();
        mOnBackInvokedDispatcher.detachFromWindow();
        WindowManagerGlobal.getInstance().doRemoveView(this);
    }

@@ -10739,6 +10739,12 @@ public final class ViewRootImpl implements ViewParent,
     * {@link OnBackInvokedCallback} to be called to the server.
     */
    private void registerBackCallbackOnWindow() {
        if (OnBackInvokedDispatcher.DEBUG) {
            Log.d(OnBackInvokedDispatcher.TAG, TextUtils.formatSimple(
                    "ViewRootImpl.registerBackCallbackOnWindow. Callback:%s Package:%s "
                            + "IWindow:%s Session:%s",
                    mOnBackInvokedDispatcher, mBasePackageName, mWindow, mWindowSession));
        }
        mOnBackInvokedDispatcher.attachToWindow(mWindowSession, mWindow);
    }

+96 −3
Original line number Diff line number Diff line
@@ -81,7 +81,9 @@ public final class BackNavigationInfo implements Parcelable {
            TYPE_DIALOG_CLOSE,
            TYPE_RETURN_TO_HOME,
            TYPE_CROSS_ACTIVITY,
            TYPE_CROSS_TASK})
            TYPE_CROSS_TASK,
            TYPE_CALLBACK
    })
    @interface BackTargetType {
    }

@@ -121,8 +123,8 @@ public final class BackNavigationInfo implements Parcelable {
            @Nullable SurfaceControl screenshotSurface,
            @Nullable HardwareBuffer screenshotBuffer,
            @Nullable WindowConfiguration taskWindowConfiguration,
            @NonNull RemoteCallback onBackNavigationDone,
            @NonNull IOnBackInvokedCallback onBackInvokedCallback) {
            @Nullable RemoteCallback onBackNavigationDone,
            @Nullable IOnBackInvokedCallback onBackInvokedCallback) {
        mType = type;
        mDepartingAnimationTarget = departingAnimationTarget;
        mScreenshotSurface = screenshotSurface;
@@ -278,7 +280,98 @@ public final class BackNavigationInfo implements Parcelable {
                return "TYPE_CROSS_ACTIVITY";
            case TYPE_CROSS_TASK:
                return "TYPE_CROSS_TASK";
            case TYPE_CALLBACK:
                return "TYPE_CALLBACK";
        }
        return String.valueOf(type);
    }

    /**
     * @hide
     */
    @SuppressWarnings("UnusedReturnValue") // Builder pattern
    public static class Builder {

        private int mType = TYPE_UNDEFINED;
        @Nullable
        private RemoteAnimationTarget mDepartingAnimationTarget = null;
        @Nullable
        private SurfaceControl mScreenshotSurface = null;
        @Nullable
        private HardwareBuffer mScreenshotBuffer = null;
        @Nullable
        private WindowConfiguration mTaskWindowConfiguration = null;
        @Nullable
        private RemoteCallback mOnBackNavigationDone = null;
        @Nullable
        private IOnBackInvokedCallback mOnBackInvokedCallback = null;

        /**
         * @see BackNavigationInfo#getType()
         */
        public Builder setType(@BackTargetType int type) {
            mType = type;
            return this;
        }

        /**
         * @see BackNavigationInfo#getDepartingAnimationTarget
         */
        public Builder setDepartingAnimationTarget(
                @Nullable RemoteAnimationTarget departingAnimationTarget) {
            mDepartingAnimationTarget = departingAnimationTarget;
            return this;
        }

        /**
         * @see BackNavigationInfo#getScreenshotSurface
         */
        public Builder setScreenshotSurface(@Nullable SurfaceControl screenshotSurface) {
            mScreenshotSurface = screenshotSurface;
            return this;
        }

        /**
         * @see BackNavigationInfo#getScreenshotHardwareBuffer()
         */
        public Builder setScreenshotBuffer(@Nullable HardwareBuffer screenshotBuffer) {
            mScreenshotBuffer = screenshotBuffer;
            return this;
        }

        /**
         * @see BackNavigationInfo#getTaskWindowConfiguration
         */
        public Builder setTaskWindowConfiguration(
                @Nullable WindowConfiguration taskWindowConfiguration) {
            mTaskWindowConfiguration = taskWindowConfiguration;
            return this;
        }

        /**
         * @see BackNavigationInfo#onBackNavigationFinished(boolean)
         */
        public Builder setOnBackNavigationDone(@Nullable RemoteCallback onBackNavigationDone) {
            mOnBackNavigationDone = onBackNavigationDone;
            return this;
        }

        /**
         * @see BackNavigationInfo#getOnBackInvokedCallback
         */
        public Builder setOnBackInvokedCallback(
                @Nullable IOnBackInvokedCallback onBackInvokedCallback) {
            mOnBackInvokedCallback = onBackInvokedCallback;
            return this;
        }

        /**
         * Builds and returns an instance of {@link BackNavigationInfo}
         */
        public BackNavigationInfo build() {
            return new BackNavigationInfo(mType, mDepartingAnimationTarget, mScreenshotSurface,
                    mScreenshotBuffer, mTaskWindowConfiguration, mOnBackNavigationDone,
                    mOnBackInvokedCallback);
        }
    }
}
+5 −5
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ public class ProxyOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
    public void unregisterOnBackInvokedCallback(
            @NonNull OnBackInvokedCallback callback) {
        if (DEBUG) {
            Log.v(TAG, String.format("Pending unregister %s. Actual=%s", callback,
            Log.v(TAG, String.format("Proxy unregister %s. Actual=%s", callback,
                    mActualDispatcherOwner));
        }
        synchronized (mLock) {
@@ -109,8 +109,8 @@ public class ProxyOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
        OnBackInvokedDispatcher dispatcher =
                mActualDispatcherOwner.getOnBackInvokedDispatcher();
        if (DEBUG) {
            Log.v(TAG, String.format("Pending transferring %d callbacks to %s", mCallbacks.size(),
                    dispatcher));
            Log.v(TAG, String.format("Proxy: transferring %d pending callbacks to %s",
                    mCallbacks.size(), dispatcher));
        }
        for (Pair<OnBackInvokedCallback, Integer> callbackPair : mCallbacks) {
            int priority = callbackPair.second;
@@ -144,7 +144,7 @@ public class ProxyOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
     */
    public void reset() {
        if (DEBUG) {
            Log.v(TAG, "Pending reset callbacks");
            Log.v(TAG, "Proxy: reset callbacks");
        }
        synchronized (mLock) {
            mCallbacks.clear();
@@ -165,7 +165,7 @@ public class ProxyOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
    public void setActualDispatcherOwner(
            @Nullable OnBackInvokedDispatcherOwner actualDispatcherOwner) {
        if (DEBUG) {
            Log.v(TAG, String.format("Pending setActual %s. Current %s",
            Log.v(TAG, String.format("Proxy setActual %s. Current %s",
                            actualDispatcherOwner, mActualDispatcherOwner));
        }
        synchronized (mLock) {
+8 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.compat.CompatChanges;
import android.content.Context;
import android.os.Debug;
import android.os.Handler;
import android.os.RemoteException;
import android.os.SystemProperties;
@@ -35,11 +36,11 @@ import java.util.TreeMap;

/**
 * Provides window based implementation of {@link OnBackInvokedDispatcher}.
 *
 * <p>
 * Callbacks with higher priorities receive back dispatching first.
 * Within the same priority, callbacks receive back dispatching in the reverse order
 * in which they are added.
 *
 * <p>
 * When the top priority callback is updated, the new callback is propagated to the Window Manager
 * if the window the instance is associated with has been attached. It is allowed to register /
 * unregister {@link OnBackInvokedCallback}s before the window is attached, although
@@ -166,6 +167,10 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
                mWindowSession.setOnBackInvokedCallback(
                        mWindow, new OnBackInvokedCallbackWrapper(callback), priority);
            }
            if (DEBUG && callback == null) {
                Log.d(TAG, TextUtils.formatSimple("setTopOnBackInvokedCallback(null) Callers:%s",
                        Debug.getCallers(5, "  ")));
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to set OnBackInvokedCallback to WM. Error: " + e);
        }
@@ -243,7 +248,7 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {

    /**
     * Returns if the legacy back behavior should be used.
     *
     * <p>
     * Legacy back behavior dispatches KEYCODE_BACK instead of invoking the application registered
     * {@link OnBackInvokedCallback}.
     */
+42 −12
Original line number Diff line number Diff line
@@ -397,6 +397,12 @@
      "group": "WM_DEBUG_WINDOW_TRANSITIONS",
      "at": "com\/android\/server\/wm\/Transition.java"
    },
    "-1717147904": {
      "message": "Current focused window is embeddedWindow. Dispatch KEYCODE_BACK.",
      "level": "DEBUG",
      "group": "WM_DEBUG_BACK_PREVIEW",
      "at": "com\/android\/server\/wm\/BackNavigationController.java"
    },
    "-1715268616": {
      "message": "Last window, removing starting window %s",
      "level": "VERBOSE",
@@ -1087,6 +1093,12 @@
      "group": "WM_DEBUG_STATES",
      "at": "com\/android\/server\/wm\/ActivityRecord.java"
    },
    "-1010850753": {
      "message": "No focused window, defaulting to top task's window",
      "level": "WARN",
      "group": "WM_DEBUG_BACK_PREVIEW",
      "at": "com\/android\/server\/wm\/BackNavigationController.java"
    },
    "-1009117329": {
      "message": "isFetchingAppTransitionSpecs=true",
      "level": "VERBOSE",
@@ -1105,6 +1117,12 @@
      "group": "WM_DEBUG_STATES",
      "at": "com\/android\/server\/wm\/ActivityRecord.java"
    },
    "-997565097": {
      "message": "Focused window found using getFocusedWindowToken",
      "level": "DEBUG",
      "group": "WM_DEBUG_BACK_PREVIEW",
      "at": "com\/android\/server\/wm\/BackNavigationController.java"
    },
    "-993378225": {
      "message": "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING %s in %s",
      "level": "VERBOSE",
@@ -1327,6 +1345,12 @@
      "group": "WM_DEBUG_FOCUS_LIGHT",
      "at": "com\/android\/server\/wm\/ActivityRecord.java"
    },
    "-767349300": {
      "message": "%s: Setting back callback %s. Client IWindow %s",
      "level": "DEBUG",
      "group": "WM_DEBUG_BACK_PREVIEW",
      "at": "com\/android\/server\/wm\/WindowState.java"
    },
    "-766059044": {
      "message": "Display id=%d selected orientation %s (%d), got rotation %s (%d)",
      "level": "VERBOSE",
@@ -1669,12 +1693,6 @@
      "group": "WM_DEBUG_STATES",
      "at": "com\/android\/server\/wm\/RootWindowContainer.java"
    },
    "-432881038": {
      "message": "startBackNavigation task=%s, topRunningActivity=%s, applicationBackCallback=%s, systemBackCallback=%s",
      "level": "DEBUG",
      "group": "WM_DEBUG_BACK_PREVIEW",
      "at": "com\/android\/server\/wm\/BackNavigationController.java"
    },
    "-415865166": {
      "message": "findFocusedWindow: Found new focus @ %s",
      "level": "VERBOSE",
@@ -1885,12 +1903,6 @@
      "group": "WM_DEBUG_SYNC_ENGINE",
      "at": "com\/android\/server\/wm\/BLASTSyncEngine.java"
    },
    "-228813488": {
      "message": "%s: Setting back callback %s",
      "level": "DEBUG",
      "group": "WM_DEBUG_BACK_PREVIEW",
      "at": "com\/android\/server\/wm\/WindowState.java"
    },
    "-208825711": {
      "message": "shouldWaitAnimatingExit: isWallpaperTarget: %s",
      "level": "DEBUG",
@@ -2359,6 +2371,12 @@
      "group": "WM_DEBUG_REMOTE_ANIMATIONS",
      "at": "com\/android\/server\/wm\/RemoteAnimationController.java"
    },
    "250620778": {
      "message": "startBackNavigation task=%s, topRunningActivity=%s, applicationBackCallback=%s, systemBackCallback=%s, currentFocus=%s",
      "level": "DEBUG",
      "group": "WM_DEBUG_BACK_PREVIEW",
      "at": "com\/android\/server\/wm\/BackNavigationController.java"
    },
    "251812577": {
      "message": "Register display organizer=%s uid=%d",
      "level": "VERBOSE",
@@ -2677,6 +2695,12 @@
      "group": "WM_SHOW_TRANSACTIONS",
      "at": "com\/android\/server\/wm\/WindowContainerThumbnail.java"
    },
    "531891870": {
      "message": "Previous Destination is Activity:%s Task:%s removedContainer:%s, backType=%s",
      "level": "DEBUG",
      "group": "WM_DEBUG_BACK_PREVIEW",
      "at": "com\/android\/server\/wm\/BackNavigationController.java"
    },
    "535103992": {
      "message": "Wallpaper may change!  Adjusting",
      "level": "VERBOSE",
@@ -2911,6 +2935,12 @@
      "group": "WM_DEBUG_LOCKTASK",
      "at": "com\/android\/server\/wm\/ActivityTaskManagerService.java"
    },
    "716528224": {
      "message": "Focused window found using wmService.getFocusedWindowLocked()",
      "level": "DEBUG",
      "group": "WM_DEBUG_BACK_PREVIEW",
      "at": "com\/android\/server\/wm\/BackNavigationController.java"
    },
    "726205185": {
      "message": "Moving to DESTROYED: %s (destroy skipped)",
      "level": "VERBOSE",
Loading