From 858cf036a39e01bd35216a9194001a4536c03c80 Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Mon, 9 May 2016 15:45:37 -0700 Subject: [PATCH] Move Activity multi-window event logic out of the public methods Move the logic for dispatching multi-window mode change events to fragments and the activity window out of the public API onFoo methods meant to be overridden by apps. This prevents problems if an extending class forgets to call super.onFoo in these methods and removes the need for doing so. Bug 28667205 Change-Id: Ibf4c543e22b95753e1e4812bbd3e81f7648de54d --- core/java/android/app/Activity.java | 32 +++++++++++++++-------- core/java/android/app/ActivityThread.java | 4 +-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 9b4c8bd070d81..07d3b8acd85e3 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -1879,14 +1879,9 @@ public class Activity extends ContextThemeWrapper * * @param isInMultiWindowMode True if the activity is in multi-window mode. */ - @CallSuper public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { - if (DEBUG_LIFECYCLE) Slog.v(TAG, - "onMultiWindowModeChanged " + this + ": " + isInMultiWindowMode); - mFragments.dispatchMultiWindowModeChanged(isInMultiWindowMode); - if (mWindow != null) { - mWindow.onMultiWindowModeChanged(); - } + // Left deliberately empty. There should be no side effects if a direct + // subclass of Activity does not call super. } /** @@ -1909,11 +1904,9 @@ public class Activity extends ContextThemeWrapper * * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode. */ - @CallSuper public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { - if (DEBUG_LIFECYCLE) Slog.v(TAG, - "onPictureInPictureModeChanged " + this + ": " + isInPictureInPictureMode); - mFragments.dispatchPictureInPictureModeChanged(isInPictureInPictureMode); + // Left deliberately empty. There should be no side effects if a direct + // subclass of Activity does not call super. } /** @@ -6875,6 +6868,23 @@ public class Activity extends ContextThemeWrapper } } + final void dispatchMultiWindowModeChanged(boolean isInMultiWindowMode) { + if (DEBUG_LIFECYCLE) Slog.v(TAG, + "dispatchMultiWindowModeChanged " + this + ": " + isInMultiWindowMode); + mFragments.dispatchMultiWindowModeChanged(isInMultiWindowMode); + if (mWindow != null) { + mWindow.onMultiWindowModeChanged(); + } + onMultiWindowModeChanged(isInMultiWindowMode); + } + + final void dispatchPictureInPictureModeChanged(boolean isInPictureInPictureMode) { + if (DEBUG_LIFECYCLE) Slog.v(TAG, + "dispatchPictureInPictureModeChanged " + this + ": " + isInPictureInPictureMode); + mFragments.dispatchPictureInPictureModeChanged(isInPictureInPictureMode); + onPictureInPictureModeChanged(isInPictureInPictureMode); + } + /** * @hide */ diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index cf2ef45212917..f78f121c9922a 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -2905,14 +2905,14 @@ public final class ActivityThread { private void handleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode) { final ActivityClientRecord r = mActivities.get(token); if (r != null) { - r.activity.onMultiWindowModeChanged(isInMultiWindowMode); + r.activity.dispatchMultiWindowModeChanged(isInMultiWindowMode); } } private void handlePictureInPictureModeChanged(IBinder token, boolean isInPipMode) { final ActivityClientRecord r = mActivities.get(token); if (r != null) { - r.activity.onPictureInPictureModeChanged(isInPipMode); + r.activity.dispatchPictureInPictureModeChanged(isInPipMode); } }