From 72077726f51e6f0888614f86ba98059d6af85126 Mon Sep 17 00:00:00 2001 From: Vadim Caen Date: Fri, 11 Feb 2022 10:30:09 +0100 Subject: [PATCH] Move OnBackInvokedCallback to window package. Originally, View was implementing onBackInvokedDisptacherOwner, but now only Activity and Dialog and since back event are related to the window, it makes sense to move them into the android.window package This follow up comment at: ag/c/platform/frameworks/base/+/16764116/comments/e131f3ef_e3e1d2e0 Test: atest BackNavigationTests Bug: 221401221 Change-Id: Ia2f26162beb6a41b6e162b31e599e882f8bf7320 --- core/api/current.txt | 38 +++++++++---------- core/api/module-lib-current.txt | 2 +- core/api/system-current.txt | 2 +- core/api/test-current.txt | 10 ++--- core/java/android/app/Activity.java | 6 +-- core/java/android/app/Dialog.java | 6 +-- .../android/content/pm/ApplicationInfo.java | 4 +- core/java/android/view/ViewRootImpl.java | 4 +- .../android/window/BackNavigationInfo.java | 8 ++-- .../OnBackInvokedCallback.java | 4 +- .../OnBackInvokedDispatcher.java | 6 +-- .../OnBackInvokedDispatcherOwner.java | 2 +- .../window/ProxyOnBackInvokedDispatcher.java | 3 -- .../window/WindowOnBackInvokedDispatcher.java | 8 ++-- .../android/internal/policy/PhoneWindow.java | 4 +- core/res/res/values/attrs_manifest.xml | 2 +- .../android/window/BackNavigationTest.java | 1 - .../WindowOnBackInvokedDispatcherTest.java | 2 - .../java/com/android/server/wm/Session.java | 2 +- 19 files changed, 54 insertions(+), 60 deletions(-) rename core/java/android/{view => window}/OnBackInvokedCallback.java (97%) rename core/java/android/{view => window}/OnBackInvokedDispatcher.java (96%) rename core/java/android/{view => window}/OnBackInvokedDispatcherOwner.java (98%) diff --git a/core/api/current.txt b/core/api/current.txt index 27a45aca405b7..72bf4b37e5685 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -4073,7 +4073,7 @@ package android.app { method @Deprecated public void onTabUnselected(android.app.ActionBar.Tab, android.app.FragmentTransaction); } - @UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.view.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback { + @UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.window.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback { ctor public Activity(); method public void addContentView(android.view.View, android.view.ViewGroup.LayoutParams); method public void closeContextMenu(); @@ -4116,7 +4116,7 @@ package android.app { method public int getMaxNumPictureInPictureActions(); method public final android.media.session.MediaController getMediaController(); method @NonNull public android.view.MenuInflater getMenuInflater(); - method @NonNull public android.view.OnBackInvokedDispatcher getOnBackInvokedDispatcher(); + method @NonNull public android.window.OnBackInvokedDispatcher getOnBackInvokedDispatcher(); method public final android.app.Activity getParent(); method @Nullable public android.content.Intent getParentActivityIntent(); method public android.content.SharedPreferences getPreferences(int); @@ -5002,7 +5002,7 @@ package android.app { method public void onDateSet(android.widget.DatePicker, int, int, int); } - public class Dialog implements android.content.DialogInterface android.view.KeyEvent.Callback android.view.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback { + public class Dialog implements android.content.DialogInterface android.view.KeyEvent.Callback android.window.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback { ctor public Dialog(@NonNull @UiContext android.content.Context); ctor public Dialog(@NonNull @UiContext android.content.Context, @StyleRes int); ctor protected Dialog(@NonNull @UiContext android.content.Context, boolean, @Nullable android.content.DialogInterface.OnCancelListener); @@ -5022,7 +5022,7 @@ package android.app { method @NonNull @UiContext public final android.content.Context getContext(); method @Nullable public android.view.View getCurrentFocus(); method @NonNull public android.view.LayoutInflater getLayoutInflater(); - method @NonNull public android.view.OnBackInvokedDispatcher getOnBackInvokedDispatcher(); + method @NonNull public android.window.OnBackInvokedDispatcher getOnBackInvokedDispatcher(); method @Nullable public final android.app.Activity getOwnerActivity(); method @Nullable public final android.view.SearchEvent getSearchEvent(); method public final int getVolumeControlStream(); @@ -49030,21 +49030,6 @@ package android.view { field public int toolType; } - public interface OnBackInvokedCallback { - method public default void onBackInvoked(); - } - - public interface OnBackInvokedDispatcher { - method public void registerOnBackInvokedCallback(@NonNull android.view.OnBackInvokedCallback, @IntRange(from=0) int); - method public void unregisterOnBackInvokedCallback(@NonNull android.view.OnBackInvokedCallback); - field public static final int PRIORITY_DEFAULT = 0; // 0x0 - field public static final int PRIORITY_OVERLAY = 1000000; // 0xf4240 - } - - public interface OnBackInvokedDispatcherOwner { - method @NonNull public android.view.OnBackInvokedDispatcher getOnBackInvokedDispatcher(); - } - public interface OnReceiveContentListener { method @Nullable public android.view.ContentInfo onReceiveContent(@NonNull android.view.View, @NonNull android.view.ContentInfo); } @@ -57906,6 +57891,21 @@ package android.widget.inline { package android.window { + public interface OnBackInvokedCallback { + method public default void onBackInvoked(); + } + + public interface OnBackInvokedDispatcher { + method public void registerOnBackInvokedCallback(@NonNull android.window.OnBackInvokedCallback, @IntRange(from=0) int); + method public void unregisterOnBackInvokedCallback(@NonNull android.window.OnBackInvokedCallback); + field public static final int PRIORITY_DEFAULT = 0; // 0x0 + field public static final int PRIORITY_OVERLAY = 1000000; // 0xf4240 + } + + public interface OnBackInvokedDispatcherOwner { + method @NonNull public android.window.OnBackInvokedDispatcher getOnBackInvokedDispatcher(); + } + public interface SplashScreen { method public void clearOnExitAnimationListener(); method public void setOnExitAnimationListener(@NonNull android.window.SplashScreen.OnExitAnimationListener); diff --git a/core/api/module-lib-current.txt b/core/api/module-lib-current.txt index 7ec239d681d0a..90cec7413bf4a 100644 --- a/core/api/module-lib-current.txt +++ b/core/api/module-lib-current.txt @@ -10,7 +10,7 @@ package android { package android.app { - @UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.view.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback { + @UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.window.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback { method public final boolean addDumpable(@NonNull android.util.Dumpable); } diff --git a/core/api/system-current.txt b/core/api/system-current.txt index e611d6b16bd74..063dd181daac2 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -463,7 +463,7 @@ package android.accounts { package android.app { - @UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.view.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback { + @UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.window.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback { method public void convertFromTranslucent(); method public boolean convertToTranslucent(android.app.Activity.TranslucentConversionListener, android.app.ActivityOptions); method @Deprecated public boolean isBackgroundVisibleBehind(); diff --git a/core/api/test-current.txt b/core/api/test-current.txt index 22637ca95b9cf..6ca91c8c9ddab 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -103,7 +103,7 @@ package android.animation { package android.app { - @UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.view.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback { + @UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.window.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback { method public final boolean addDumpable(@NonNull android.util.Dumpable); method public void dumpInternal(@NonNull String, @Nullable java.io.FileDescriptor, @NonNull java.io.PrintWriter, @Nullable String[]); method public void onMovedToDisplay(int, android.content.res.Configuration); @@ -2829,10 +2829,6 @@ package android.view { field public static final int FLAG_IS_ACCESSIBILITY_EVENT = 2048; // 0x800 } - public interface OnBackInvokedDispatcher { - field public static final long DISPATCH_BACK_INVOCATION_AHEAD_OF_TIME = 195946584L; // 0xbade858L - } - @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @java.lang.annotation.Target({java.lang.annotation.ElementType.METHOD}) public @interface RemotableViewMethod { method public abstract String asyncImpl() default ""; } @@ -3246,6 +3242,10 @@ package android.window { field public static final int FEATURE_WINDOW_TOKENS = 2; // 0x2 } + public interface OnBackInvokedDispatcher { + field public static final long DISPATCH_BACK_INVOCATION_AHEAD_OF_TIME = 195946584L; // 0xbade858L + } + public final class SplashScreenView extends android.widget.FrameLayout { method @Nullable public android.view.View getBrandingView(); } diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index bc979fc4af84b..8f348a4e81d69 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -120,9 +120,6 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.MotionEvent; -import android.view.OnBackInvokedCallback; -import android.view.OnBackInvokedDispatcher; -import android.view.OnBackInvokedDispatcherOwner; import android.view.RemoteAnimationDefinition; import android.view.SearchEvent; import android.view.View; @@ -149,6 +146,9 @@ import android.view.translation.UiTranslationSpec; import android.widget.AdapterView; import android.widget.Toast; import android.widget.Toolbar; +import android.window.OnBackInvokedCallback; +import android.window.OnBackInvokedDispatcher; +import android.window.OnBackInvokedDispatcherOwner; import android.window.SplashScreen; import android.window.WindowOnBackInvokedDispatcher; diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java index 569fda961a4c6..82ff42b417994 100644 --- a/core/java/android/app/Dialog.java +++ b/core/java/android/app/Dialog.java @@ -52,9 +52,6 @@ import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; -import android.view.OnBackInvokedCallback; -import android.view.OnBackInvokedDispatcher; -import android.view.OnBackInvokedDispatcherOwner; import android.view.SearchEvent; import android.view.View; import android.view.View.OnCreateContextMenuListener; @@ -63,6 +60,9 @@ import android.view.ViewGroup.LayoutParams; import android.view.Window; import android.view.WindowManager; import android.view.accessibility.AccessibilityEvent; +import android.window.OnBackInvokedCallback; +import android.window.OnBackInvokedDispatcher; +import android.window.OnBackInvokedDispatcherOwner; import android.window.WindowOnBackInvokedDispatcher; import com.android.internal.R; diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java index fbb03cab8ae7b..673127e9f808b 100644 --- a/core/java/android/content/pm/ApplicationInfo.java +++ b/core/java/android/content/pm/ApplicationInfo.java @@ -40,7 +40,7 @@ import android.util.ArraySet; import android.util.Printer; import android.util.SparseArray; import android.util.proto.ProtoOutputStream; -import android.view.OnBackInvokedCallback; +import android.window.OnBackInvokedCallback; import com.android.internal.util.ArrayUtils; import com.android.internal.util.Parcelling; @@ -2582,7 +2582,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { } /** - * Returns whether the application will use the {@link android.view.OnBackInvokedCallback} + * Returns whether the application will use the {@link android.window.OnBackInvokedCallback} * navigation system instead of the {@link android.view.KeyEvent#KEYCODE_BACK} and related * callbacks. * diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 8bb7e677362c9..0cb5d88bb4b25 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -195,6 +195,9 @@ import android.view.contentcapture.MainContentCaptureSession; import android.view.inputmethod.InputMethodManager; import android.widget.Scroller; import android.window.ClientWindowFrames; +import android.window.OnBackInvokedCallback; +import android.window.OnBackInvokedDispatcher; +import android.window.OnBackInvokedDispatcherOwner; import android.window.SurfaceSyncer; import android.window.WindowOnBackInvokedDispatcher; @@ -221,7 +224,6 @@ import java.lang.ref.WeakReference; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Queue; diff --git a/core/java/android/window/BackNavigationInfo.java b/core/java/android/window/BackNavigationInfo.java index 1e922d91e7b51..6653758e6c50d 100644 --- a/core/java/android/window/BackNavigationInfo.java +++ b/core/java/android/window/BackNavigationInfo.java @@ -61,7 +61,7 @@ public final class BackNavigationInfo implements Parcelable { public static final int TYPE_CROSS_TASK = 3; /** - * A {@link android.view.OnBackInvokedCallback} is available and needs to be called. + * A {@link OnBackInvokedCallback} is available and needs to be called. *

*/ public static final int TYPE_CALLBACK = 4; @@ -206,13 +206,13 @@ public final class BackNavigationInfo implements Parcelable { } /** - * Returns the {@link android.view.OnBackInvokedCallback} of the top level window or null if + * Returns the {@link OnBackInvokedCallback} of the top level window or null if * the client didn't register a callback. *

* This is never null when {@link #getType} returns {@link #TYPE_CALLBACK}. * - * @see android.view.OnBackInvokedCallback - * @see android.view.OnBackInvokedDispatcher + * @see OnBackInvokedCallback + * @see OnBackInvokedDispatcher */ @Nullable public IOnBackInvokedCallback getOnBackInvokedCallback() { diff --git a/core/java/android/view/OnBackInvokedCallback.java b/core/java/android/window/OnBackInvokedCallback.java similarity index 97% rename from core/java/android/view/OnBackInvokedCallback.java rename to core/java/android/window/OnBackInvokedCallback.java index 37f858abf8184..dcd80fd76e09a 100644 --- a/core/java/android/view/OnBackInvokedCallback.java +++ b/core/java/android/window/OnBackInvokedCallback.java @@ -14,11 +14,11 @@ * limitations under the License. */ -package android.view; +package android.window; import android.app.Activity; import android.app.Dialog; -import android.window.BackEvent; +import android.view.View; /** * Interface for applications to register back invocation callbacks. This allows the client diff --git a/core/java/android/view/OnBackInvokedDispatcher.java b/core/java/android/window/OnBackInvokedDispatcher.java similarity index 96% rename from core/java/android/view/OnBackInvokedDispatcher.java rename to core/java/android/window/OnBackInvokedDispatcher.java index 5c4ee89bfbd3e..63e6d30c8c0b5 100644 --- a/core/java/android/view/OnBackInvokedDispatcher.java +++ b/core/java/android/window/OnBackInvokedDispatcher.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package android.view; +package android.window; import android.annotation.IntDef; import android.annotation.IntRange; @@ -39,7 +39,7 @@ import java.lang.annotation.RetentionPolicy; */ public interface OnBackInvokedDispatcher { /** - * Enables dispatching the "back" action via {@link android.view.OnBackInvokedDispatcher}. + * Enables dispatching the "back" action via {@link OnBackInvokedDispatcher}. * * When enabled, the following APIs are no longer invoked: *