Loading core/java/android/app/Activity.java +2 −1 Original line number Diff line number Diff line Loading @@ -2761,6 +2761,7 @@ public class Activity extends ContextThemeWrapper getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(mDefaultBackCallback); mDefaultBackCallback = null; } if (mCallbacksController != null) { mCallbacksController.clearCallbacks(); } Loading Loading @@ -8338,6 +8339,7 @@ public class Activity extends ContextThemeWrapper attachBaseContext(context); mFragments.attachHost(null /*parent*/); mActivityInfo = info; mWindow = new PhoneWindow(this, window, activityConfigCallback); mWindow.setWindowControllerCallback(mWindowControllerCallback); Loading @@ -8362,7 +8364,6 @@ public class Activity extends ContextThemeWrapper mIntent = intent; mReferrer = referrer; mComponent = intent.getComponent(); mActivityInfo = info; mTitle = title; mParent = parent; mEmbeddedID = id; Loading core/java/android/content/pm/ActivityInfo.java +50 −2 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.os.Parcelable; import android.os.UserHandle; import android.util.ArraySet; import android.util.Printer; import android.window.OnBackInvokedCallback; import com.android.internal.util.Parcelling; Loading Loading @@ -624,7 +625,7 @@ public class ActivityInfo extends ComponentInfo implements Parcelable { * See {@link android.R.attr#inheritShowWhenLocked}. * @hide */ public static final int FLAG_INHERIT_SHOW_WHEN_LOCKED = 0x1; public static final int FLAG_INHERIT_SHOW_WHEN_LOCKED = 1 << 0; /** * Bit in {@link #privateFlags} indicating whether a home sound effect should be played if the Loading @@ -632,13 +633,34 @@ public class ActivityInfo extends ComponentInfo implements Parcelable { * Set from the {@link android.R.attr#playHomeTransitionSound} attribute. * @hide */ public static final int PRIVATE_FLAG_HOME_TRANSITION_SOUND = 0x2; public static final int PRIVATE_FLAG_HOME_TRANSITION_SOUND = 1 << 1; /** * Bit in {@link #privateFlags} indicating {@link android.view.KeyEvent#KEYCODE_BACK} related * events will be replaced by a call to {@link OnBackInvokedCallback#onBackInvoked()} on the * focused window. * @hide * @see android.R.styleable.AndroidManifestActivity_enableOnBackInvokedCallback */ public static final int PRIVATE_FLAG_ENABLE_ON_BACK_INVOKED_CALLBACK = 1 << 2; /** * Bit in {@link #privateFlags} indicating {@link android.view.KeyEvent#KEYCODE_BACK} related * events will be forwarded to the Activity and its dialogs and views and * the {@link android.app.Activity#onBackPressed()}, {@link android.app.Dialog#onBackPressed} * will be called. * @hide * @see android.R.styleable.AndroidManifestActivity_enableOnBackInvokedCallback */ public static final int PRIVATE_FLAG_DISABLE_ON_BACK_INVOKED_CALLBACK = 1 << 3; /** * Options that have been set in the activity declaration in the manifest. * These include: * {@link #FLAG_INHERIT_SHOW_WHEN_LOCKED}, * {@link #PRIVATE_FLAG_HOME_TRANSITION_SOUND}. * {@link #PRIVATE_FLAG_ENABLE_ON_BACK_INVOKED_CALLBACK} * {@link #PRIVATE_FLAG_DISABLE_ON_BACK_INVOKED_CALLBACK} * @hide */ public int privateFlags; Loading Loading @@ -1618,6 +1640,32 @@ public class ActivityInfo extends ComponentInfo implements Parcelable { return isChangeEnabled(CHECK_MIN_WIDTH_HEIGHT_FOR_MULTI_WINDOW); } /** * Returns whether the activity will set the * {@link R.styleable.AndroidManifestActivity_enableOnBackInvokedCallback} attribute. * * @hide */ public boolean hasOnBackInvokedCallbackEnabled() { return (privateFlags & (PRIVATE_FLAG_ENABLE_ON_BACK_INVOKED_CALLBACK | PRIVATE_FLAG_DISABLE_ON_BACK_INVOKED_CALLBACK)) != 0; } /** * Returns whether the activity will use the {@link android.window.OnBackInvokedCallback} * navigation system instead of the {@link android.view.KeyEvent#KEYCODE_BACK} and related * callbacks. * * Valid when the {@link R.styleable.AndroidManifestActivity_enableOnBackInvokedCallback} * attribute has been set, or it won't indicate if the activity should use the * navigation system and the {@link hasOnBackInvokedCallbackEnabled} will return false. * @hide */ public boolean isOnBackInvokedCallbackEnabled() { return hasOnBackInvokedCallbackEnabled() && (privateFlags & PRIVATE_FLAG_ENABLE_ON_BACK_INVOKED_CALLBACK) != 0; } public void dump(Printer pw, String prefix) { dump(pw, prefix, DUMP_FLAG_ALL); } Loading core/java/android/view/ViewRootImpl.java +10 −11 Original line number Diff line number Diff line Loading @@ -994,8 +994,7 @@ public final class ViewRootImpl implements ViewParent, mFastScrollSoundEffectsEnabled = audioManager.areNavigationRepeatSoundEffectsEnabled(); mScrollCaptureRequestTimeout = SCROLL_CAPTURE_REQUEST_TIMEOUT_MILLIS; mOnBackInvokedDispatcher = new WindowOnBackInvokedDispatcher( context.getApplicationInfo().isOnBackInvokedCallbackEnabled()); mOnBackInvokedDispatcher = new WindowOnBackInvokedDispatcher(context); } public static void addFirstDrawHandler(Runnable callback) { Loading Loading @@ -1301,14 +1300,6 @@ public final class ViewRootImpl implements ViewParent, mTmpFrames); setFrame(mTmpFrames.frame); registerBackCallbackOnWindow(); if (!WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) { // For apps requesting legacy back behavior, we add a compat callback that // dispatches {@link KeyEvent#KEYCODE_BACK} to their root views. // This way from system point of view, these apps are providing custom // {@link OnBackInvokedCallback}s, and will not play system back animations // for them. registerCompatOnBackInvokedCallback(); } if (DEBUG_LAYOUT) Log.v(mTag, "Added window " + mWindow); if (res < WindowManagerGlobal.ADD_OKAY) { mAttachInfo.mRootView = null; Loading Loading @@ -2901,6 +2892,14 @@ public final class ViewRootImpl implements ViewParent, host.dispatchAttachedToWindow(mAttachInfo, 0); mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(true); dispatchApplyInsets(host); if (!mOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled()) { // For apps requesting legacy back behavior, we add a compat callback that // dispatches {@link KeyEvent#KEYCODE_BACK} to their root views. // This way from system point of view, these apps are providing custom // {@link OnBackInvokedCallback}s, and will not play system back animations // for them. registerCompatOnBackInvokedCallback(); } } else { desiredWindowWidth = frame.width(); desiredWindowHeight = frame.height(); Loading Loading @@ -6363,7 +6362,7 @@ public final class ViewRootImpl implements ViewParent, // view tree or IME, and invoke the appropriate {@link OnBackInvokedCallback}. if (isBack(event) && mContext != null && WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) { && mOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled()) { OnBackInvokedCallback topCallback = getOnBackInvokedDispatcher().getTopCallback(); if (event.getAction() == KeyEvent.ACTION_UP) { Loading core/java/android/widget/Editor.java +2 −5 Original line number Diff line number Diff line Loading @@ -133,7 +133,6 @@ import android.widget.TextView.Drawables; import android.widget.TextView.OnEditorActionListener; import android.window.OnBackInvokedCallback; import android.window.OnBackInvokedDispatcher; import android.window.WindowOnBackInvokedDispatcher; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.inputmethod.EditableInputConnection; Loading Loading @@ -770,8 +769,7 @@ public class Editor { } ViewRootImpl viewRootImpl = getTextView().getViewRootImpl(); if (viewRootImpl != null && WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled( viewRootImpl.mContext)) { && viewRootImpl.getOnBackInvokedDispatcher().isOnBackInvokedCallbackEnabled()) { viewRootImpl.getOnBackInvokedDispatcher() .unregisterOnBackInvokedCallback(mBackCallback); mBackCallbackRegistered = false; Loading @@ -784,8 +782,7 @@ public class Editor { } ViewRootImpl viewRootImpl = mTextView.getViewRootImpl(); if (viewRootImpl != null && WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled( viewRootImpl.mContext)) { && viewRootImpl.getOnBackInvokedDispatcher().isOnBackInvokedCallbackEnabled()) { viewRootImpl.getOnBackInvokedDispatcher().registerOnBackInvokedCallback( OnBackInvokedDispatcher.PRIORITY_DEFAULT, mBackCallback); mBackCallbackRegistered = true; Loading core/java/android/widget/MediaController.java +2 −5 Original line number Diff line number Diff line Loading @@ -38,7 +38,6 @@ import android.view.accessibility.AccessibilityManager; import android.widget.SeekBar.OnSeekBarChangeListener; import android.window.OnBackInvokedCallback; import android.window.OnBackInvokedDispatcher; import android.window.WindowOnBackInvokedDispatcher; import com.android.internal.policy.PhoneWindow; Loading Loading @@ -748,8 +747,7 @@ public class MediaController extends FrameLayout { } ViewRootImpl viewRootImpl = mDecor.getViewRootImpl(); if (viewRootImpl != null && WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled( viewRootImpl.mContext)) { && viewRootImpl.getOnBackInvokedDispatcher().isOnBackInvokedCallbackEnabled()) { viewRootImpl.getOnBackInvokedDispatcher() .unregisterOnBackInvokedCallback(mBackCallback); } Loading @@ -763,8 +761,7 @@ public class MediaController extends FrameLayout { ViewRootImpl viewRootImpl = mDecor.getViewRootImpl(); if (viewRootImpl != null && WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled( viewRootImpl.mContext)) { && viewRootImpl.getOnBackInvokedDispatcher().isOnBackInvokedCallbackEnabled()) { viewRootImpl.getOnBackInvokedDispatcher().registerOnBackInvokedCallback( OnBackInvokedDispatcher.PRIORITY_DEFAULT, mBackCallback); mBackCallbackRegistered = true; Loading Loading
core/java/android/app/Activity.java +2 −1 Original line number Diff line number Diff line Loading @@ -2761,6 +2761,7 @@ public class Activity extends ContextThemeWrapper getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(mDefaultBackCallback); mDefaultBackCallback = null; } if (mCallbacksController != null) { mCallbacksController.clearCallbacks(); } Loading Loading @@ -8338,6 +8339,7 @@ public class Activity extends ContextThemeWrapper attachBaseContext(context); mFragments.attachHost(null /*parent*/); mActivityInfo = info; mWindow = new PhoneWindow(this, window, activityConfigCallback); mWindow.setWindowControllerCallback(mWindowControllerCallback); Loading @@ -8362,7 +8364,6 @@ public class Activity extends ContextThemeWrapper mIntent = intent; mReferrer = referrer; mComponent = intent.getComponent(); mActivityInfo = info; mTitle = title; mParent = parent; mEmbeddedID = id; Loading
core/java/android/content/pm/ActivityInfo.java +50 −2 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.os.Parcelable; import android.os.UserHandle; import android.util.ArraySet; import android.util.Printer; import android.window.OnBackInvokedCallback; import com.android.internal.util.Parcelling; Loading Loading @@ -624,7 +625,7 @@ public class ActivityInfo extends ComponentInfo implements Parcelable { * See {@link android.R.attr#inheritShowWhenLocked}. * @hide */ public static final int FLAG_INHERIT_SHOW_WHEN_LOCKED = 0x1; public static final int FLAG_INHERIT_SHOW_WHEN_LOCKED = 1 << 0; /** * Bit in {@link #privateFlags} indicating whether a home sound effect should be played if the Loading @@ -632,13 +633,34 @@ public class ActivityInfo extends ComponentInfo implements Parcelable { * Set from the {@link android.R.attr#playHomeTransitionSound} attribute. * @hide */ public static final int PRIVATE_FLAG_HOME_TRANSITION_SOUND = 0x2; public static final int PRIVATE_FLAG_HOME_TRANSITION_SOUND = 1 << 1; /** * Bit in {@link #privateFlags} indicating {@link android.view.KeyEvent#KEYCODE_BACK} related * events will be replaced by a call to {@link OnBackInvokedCallback#onBackInvoked()} on the * focused window. * @hide * @see android.R.styleable.AndroidManifestActivity_enableOnBackInvokedCallback */ public static final int PRIVATE_FLAG_ENABLE_ON_BACK_INVOKED_CALLBACK = 1 << 2; /** * Bit in {@link #privateFlags} indicating {@link android.view.KeyEvent#KEYCODE_BACK} related * events will be forwarded to the Activity and its dialogs and views and * the {@link android.app.Activity#onBackPressed()}, {@link android.app.Dialog#onBackPressed} * will be called. * @hide * @see android.R.styleable.AndroidManifestActivity_enableOnBackInvokedCallback */ public static final int PRIVATE_FLAG_DISABLE_ON_BACK_INVOKED_CALLBACK = 1 << 3; /** * Options that have been set in the activity declaration in the manifest. * These include: * {@link #FLAG_INHERIT_SHOW_WHEN_LOCKED}, * {@link #PRIVATE_FLAG_HOME_TRANSITION_SOUND}. * {@link #PRIVATE_FLAG_ENABLE_ON_BACK_INVOKED_CALLBACK} * {@link #PRIVATE_FLAG_DISABLE_ON_BACK_INVOKED_CALLBACK} * @hide */ public int privateFlags; Loading Loading @@ -1618,6 +1640,32 @@ public class ActivityInfo extends ComponentInfo implements Parcelable { return isChangeEnabled(CHECK_MIN_WIDTH_HEIGHT_FOR_MULTI_WINDOW); } /** * Returns whether the activity will set the * {@link R.styleable.AndroidManifestActivity_enableOnBackInvokedCallback} attribute. * * @hide */ public boolean hasOnBackInvokedCallbackEnabled() { return (privateFlags & (PRIVATE_FLAG_ENABLE_ON_BACK_INVOKED_CALLBACK | PRIVATE_FLAG_DISABLE_ON_BACK_INVOKED_CALLBACK)) != 0; } /** * Returns whether the activity will use the {@link android.window.OnBackInvokedCallback} * navigation system instead of the {@link android.view.KeyEvent#KEYCODE_BACK} and related * callbacks. * * Valid when the {@link R.styleable.AndroidManifestActivity_enableOnBackInvokedCallback} * attribute has been set, or it won't indicate if the activity should use the * navigation system and the {@link hasOnBackInvokedCallbackEnabled} will return false. * @hide */ public boolean isOnBackInvokedCallbackEnabled() { return hasOnBackInvokedCallbackEnabled() && (privateFlags & PRIVATE_FLAG_ENABLE_ON_BACK_INVOKED_CALLBACK) != 0; } public void dump(Printer pw, String prefix) { dump(pw, prefix, DUMP_FLAG_ALL); } Loading
core/java/android/view/ViewRootImpl.java +10 −11 Original line number Diff line number Diff line Loading @@ -994,8 +994,7 @@ public final class ViewRootImpl implements ViewParent, mFastScrollSoundEffectsEnabled = audioManager.areNavigationRepeatSoundEffectsEnabled(); mScrollCaptureRequestTimeout = SCROLL_CAPTURE_REQUEST_TIMEOUT_MILLIS; mOnBackInvokedDispatcher = new WindowOnBackInvokedDispatcher( context.getApplicationInfo().isOnBackInvokedCallbackEnabled()); mOnBackInvokedDispatcher = new WindowOnBackInvokedDispatcher(context); } public static void addFirstDrawHandler(Runnable callback) { Loading Loading @@ -1301,14 +1300,6 @@ public final class ViewRootImpl implements ViewParent, mTmpFrames); setFrame(mTmpFrames.frame); registerBackCallbackOnWindow(); if (!WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) { // For apps requesting legacy back behavior, we add a compat callback that // dispatches {@link KeyEvent#KEYCODE_BACK} to their root views. // This way from system point of view, these apps are providing custom // {@link OnBackInvokedCallback}s, and will not play system back animations // for them. registerCompatOnBackInvokedCallback(); } if (DEBUG_LAYOUT) Log.v(mTag, "Added window " + mWindow); if (res < WindowManagerGlobal.ADD_OKAY) { mAttachInfo.mRootView = null; Loading Loading @@ -2901,6 +2892,14 @@ public final class ViewRootImpl implements ViewParent, host.dispatchAttachedToWindow(mAttachInfo, 0); mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(true); dispatchApplyInsets(host); if (!mOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled()) { // For apps requesting legacy back behavior, we add a compat callback that // dispatches {@link KeyEvent#KEYCODE_BACK} to their root views. // This way from system point of view, these apps are providing custom // {@link OnBackInvokedCallback}s, and will not play system back animations // for them. registerCompatOnBackInvokedCallback(); } } else { desiredWindowWidth = frame.width(); desiredWindowHeight = frame.height(); Loading Loading @@ -6363,7 +6362,7 @@ public final class ViewRootImpl implements ViewParent, // view tree or IME, and invoke the appropriate {@link OnBackInvokedCallback}. if (isBack(event) && mContext != null && WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) { && mOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled()) { OnBackInvokedCallback topCallback = getOnBackInvokedDispatcher().getTopCallback(); if (event.getAction() == KeyEvent.ACTION_UP) { Loading
core/java/android/widget/Editor.java +2 −5 Original line number Diff line number Diff line Loading @@ -133,7 +133,6 @@ import android.widget.TextView.Drawables; import android.widget.TextView.OnEditorActionListener; import android.window.OnBackInvokedCallback; import android.window.OnBackInvokedDispatcher; import android.window.WindowOnBackInvokedDispatcher; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.inputmethod.EditableInputConnection; Loading Loading @@ -770,8 +769,7 @@ public class Editor { } ViewRootImpl viewRootImpl = getTextView().getViewRootImpl(); if (viewRootImpl != null && WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled( viewRootImpl.mContext)) { && viewRootImpl.getOnBackInvokedDispatcher().isOnBackInvokedCallbackEnabled()) { viewRootImpl.getOnBackInvokedDispatcher() .unregisterOnBackInvokedCallback(mBackCallback); mBackCallbackRegistered = false; Loading @@ -784,8 +782,7 @@ public class Editor { } ViewRootImpl viewRootImpl = mTextView.getViewRootImpl(); if (viewRootImpl != null && WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled( viewRootImpl.mContext)) { && viewRootImpl.getOnBackInvokedDispatcher().isOnBackInvokedCallbackEnabled()) { viewRootImpl.getOnBackInvokedDispatcher().registerOnBackInvokedCallback( OnBackInvokedDispatcher.PRIORITY_DEFAULT, mBackCallback); mBackCallbackRegistered = true; Loading
core/java/android/widget/MediaController.java +2 −5 Original line number Diff line number Diff line Loading @@ -38,7 +38,6 @@ import android.view.accessibility.AccessibilityManager; import android.widget.SeekBar.OnSeekBarChangeListener; import android.window.OnBackInvokedCallback; import android.window.OnBackInvokedDispatcher; import android.window.WindowOnBackInvokedDispatcher; import com.android.internal.policy.PhoneWindow; Loading Loading @@ -748,8 +747,7 @@ public class MediaController extends FrameLayout { } ViewRootImpl viewRootImpl = mDecor.getViewRootImpl(); if (viewRootImpl != null && WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled( viewRootImpl.mContext)) { && viewRootImpl.getOnBackInvokedDispatcher().isOnBackInvokedCallbackEnabled()) { viewRootImpl.getOnBackInvokedDispatcher() .unregisterOnBackInvokedCallback(mBackCallback); } Loading @@ -763,8 +761,7 @@ public class MediaController extends FrameLayout { ViewRootImpl viewRootImpl = mDecor.getViewRootImpl(); if (viewRootImpl != null && WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled( viewRootImpl.mContext)) { && viewRootImpl.getOnBackInvokedDispatcher().isOnBackInvokedCallbackEnabled()) { viewRootImpl.getOnBackInvokedDispatcher().registerOnBackInvokedCallback( OnBackInvokedDispatcher.PRIORITY_DEFAULT, mBackCallback); mBackCallbackRegistered = true; Loading