diff options
| author | Vadim Caen <caen@google.com> | 2022-02-21 21:52:41 +0100 |
|---|---|---|
| committer | Vadim Caen <caen@google.com> | 2022-03-24 14:14:26 +0100 |
| commit | 6a074eca5cca62cfd49bb65af6b2152e051c9ef6 (patch) | |
| tree | e0ccc0d980719b727d78413d4c917c6d3062e9fe /core/java/android | |
| parent | c20089e4beab2ba7700ff29a66d0f569ce0593eb (diff) | |
Improve startBackNavigation stability
- Use the focused window instead of the topApp window
- Instead we now rely on WindowManagerService to get
the focused window.
- SystemUI does not have ActivityRecord so we can't rely
on the top window of the Task to find the correct
window on which the callback will be called.
- Introduce a Builder for BackNavigationInfo
- This reduces the number of variable needed outside the synchonized
block.
- It also reduces the number of early return of BackNavigationInfo
instances
- Adding log messages to help further debug the method.
Test: BackNavigationControllerTests
Test: Manual dismiss of SystemUi dialog in QS
Bug: 216604581
Fixes: 221458292
Change-Id: I9ba2c7f89956f34d6338824502c210b3e58dc076
Introduce builder for BackNavigationInfo
Change-Id: I14b4a4b3abc8f417998b7b32831cb3d5c4faa491
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/view/ViewRootImpl.java | 7 | ||||
| -rw-r--r-- | core/java/android/window/BackNavigationInfo.java | 99 | ||||
| -rw-r--r-- | core/java/android/window/ProxyOnBackInvokedDispatcher.java | 10 |
3 files changed, 108 insertions, 8 deletions
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 172cd03900e7..17e3914ab24b 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -147,6 +147,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; @@ -10885,6 +10886,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); } diff --git a/core/java/android/window/BackNavigationInfo.java b/core/java/android/window/BackNavigationInfo.java index 6653758e6c50..0ab6db58ab4b 100644 --- a/core/java/android/window/BackNavigationInfo.java +++ b/core/java/android/window/BackNavigationInfo.java @@ -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); + } + } } diff --git a/core/java/android/window/ProxyOnBackInvokedDispatcher.java b/core/java/android/window/ProxyOnBackInvokedDispatcher.java index 2b2f5e945710..eb776310b8bb 100644 --- a/core/java/android/window/ProxyOnBackInvokedDispatcher.java +++ b/core/java/android/window/ProxyOnBackInvokedDispatcher.java @@ -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) { |
