From 06ccd09f912d3409397ddbefe70c6de0e2df1fa6 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Wed, 21 Oct 2020 23:22:17 +0800 Subject: Only rely on ActivityConfigurationChangeItem to update activity config This removes the legacy path that updates or set the pending activity config when process config is changed. Since the handling of activity config is separated, the legacy path from process config change almost becomes no-op because the activity override config will dominate the result of config difference. This removal may also avoid the config change happened on unexpected timing if the process registered to an activity as a config listener. And the condition (in collectComponentCallbacks) for deciding whether to deliver config to activity is not consistent with task manager service on server side. Bug: 171389102 Test: CtsWindowManagerDeviceTestCases:AppConfigurationTests Change-Id: Ia4f9a9cc3538f5f419bdc9d125e2a930074e2f86 --- core/java/android/app/ActivityThread.java | 88 +++++-------------------------- 1 file changed, 12 insertions(+), 76 deletions(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 4ea2aacdf7c2..87c729b20c71 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -513,7 +513,6 @@ public final class ActivityThread extends ClientTransactionHandler { @UnsupportedAppUsage boolean stopped; boolean hideForNow; - Configuration newConfig; Configuration createdConfig; Configuration overrideConfig; // Used to save the last reported configuration from server side so that activity @@ -2222,21 +2221,6 @@ public final class ActivityThread extends ClientTransactionHandler { return sPermissionManager; } - private Configuration mMainThreadConfig = new Configuration(); - - Configuration applyConfigCompatMainThread(int displayDensity, Configuration config, - CompatibilityInfo compat) { - if (config == null) { - return null; - } - if (!compat.supportsScreen()) { - mMainThreadConfig.setTo(config); - config = mMainThreadConfig; - compat.applyToConfiguration(displayDensity, config); - } - return config; - } - /** * Creates the top level resources for the given package. Will return an existing * Resources if one has already been created. @@ -4597,14 +4581,6 @@ public final class ActivityThread extends ClientTransactionHandler { // The window is now visible if it has been added, we are not // simply finishing, and we are not starting another activity. if (!r.activity.mFinished && willBeVisible && r.activity.mDecor != null && !r.hideForNow) { - if (r.newConfig != null) { - performConfigurationChangedForActivity(r, r.newConfig); - if (DEBUG_CONFIGURATION) { - Slog.v(TAG, "Resuming activity " + r.activityInfo.name + " with newConfig " - + r.activity.mCurrentConfig); - } - r.newConfig = null; - } if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward=" + isForward); ViewRootImpl impl = r.window.getDecorView().getViewRootImpl(); WindowManager.LayoutParams l = impl != null @@ -4910,13 +4886,6 @@ public final class ActivityThread extends ClientTransactionHandler { r.activity.makeVisible(); } } - if (r.newConfig != null) { - performConfigurationChangedForActivity(r, r.newConfig); - if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis " - + r.activityInfo.name + " with new config " - + r.activity.mCurrentConfig); - r.newConfig = null; - } } else { if (r.activity.mVisibleFromServer) { r.activity.mVisibleFromServer = false; @@ -5488,8 +5457,7 @@ public final class ActivityThread extends ClientTransactionHandler { } } - ArrayList collectComponentCallbacks( - boolean allActivities, Configuration newConfig) { + ArrayList collectComponentCallbacks(boolean includeActivities) { ArrayList callbacks = new ArrayList(); @@ -5498,29 +5466,11 @@ public final class ActivityThread extends ClientTransactionHandler { for (int i=0; i= 0; i--) { + final Activity a = mActivities.valueAt(i).activity; + if (a != null && !a.mFinished) { callbacks.add(a); - } else if (thisConfig != null) { - // Otherwise, we will tell it about the change - // the next time it is resumed or shown. Note that - // the activity manager may, before then, decide the - // activity needs to be destroyed to handle its new - // configuration. - if (DEBUG_CONFIGURATION) { - Slog.v(TAG, "Setting activity " - + ar.activityInfo.name + " newConfig=" + thisConfig); - } - ar.newConfig = thisConfig; } } } @@ -5543,17 +5493,6 @@ public final class ActivityThread extends ClientTransactionHandler { return callbacks; } - /** - * Updates the configuration for an Activity in its current display. - * - * @see #performConfigurationChangedForActivity(ActivityClientRecord, Configuration, int, - * boolean) - */ - private void performConfigurationChangedForActivity(ActivityClientRecord r, - Configuration newBaseConfig) { - performConfigurationChangedForActivity(r, newBaseConfig, r.activity.getDisplayId()); - } - /** * Updates the configuration for an Activity. The ActivityClientRecord's * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for @@ -5804,7 +5743,8 @@ public final class ActivityThread extends ClientTransactionHandler { } } - ArrayList callbacks = collectComponentCallbacks(false, config); + final ArrayList callbacks = + collectComponentCallbacks(false /* includeActivities */); freeTextLayoutCachesIfNeeded(configDiff); @@ -5812,13 +5752,7 @@ public final class ActivityThread extends ClientTransactionHandler { final int N = callbacks.size(); for (int i=0; i callbacks = collectComponentCallbacks(true, null); + final ArrayList callbacks = + collectComponentCallbacks(true /* includeActivities */); final int N = callbacks.size(); for (int i=0; i callbacks = collectComponentCallbacks(true, null); + final ArrayList callbacks = + collectComponentCallbacks(true /* includeActivities */); final int N = callbacks.size(); for (int i = 0; i < N; i++) { -- cgit v1.2.3-59-g8ed1b