diff options
| author | 2020-10-21 23:22:17 +0800 | |
|---|---|---|
| committer | 2020-10-22 13:23:22 +0800 | |
| commit | 06ccd09f912d3409397ddbefe70c6de0e2df1fa6 (patch) | |
| tree | 4b9af544e3744d25837f60d0774a04f676209904 | |
| parent | a3eea61e3aa91c10a82bc2d201570ffa93da06af (diff) | |
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
| -rw-r--r-- | core/java/android/app/ActivityThread.java | 88 |
1 files 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<ComponentCallbacks2> collectComponentCallbacks( - boolean allActivities, Configuration newConfig) { + ArrayList<ComponentCallbacks2> collectComponentCallbacks(boolean includeActivities) { ArrayList<ComponentCallbacks2> callbacks = new ArrayList<ComponentCallbacks2>(); @@ -5498,29 +5466,11 @@ public final class ActivityThread extends ClientTransactionHandler { for (int i=0; i<NAPP; i++) { callbacks.add(mAllApplications.get(i)); } - final int NACT = mActivities.size(); - for (int i=0; i<NACT; i++) { - ActivityClientRecord ar = mActivities.valueAt(i); - Activity a = ar.activity; - if (a != null) { - Configuration thisConfig = applyConfigCompatMainThread( - mCurDefaultDisplayDpi, newConfig, - ar.packageInfo.getCompatibilityInfo()); - if (!ar.activity.mFinished && (allActivities || !ar.paused)) { - // If the activity is currently resumed, its configuration - // needs to change right now. + if (includeActivities) { + for (int i = mActivities.size() - 1; 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; } } } @@ -5544,17 +5494,6 @@ public final class ActivityThread extends ClientTransactionHandler { } /** - * 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 * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering @@ -5804,7 +5743,8 @@ public final class ActivityThread extends ClientTransactionHandler { } } - ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); + final ArrayList<ComponentCallbacks2> 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<N; i++) { ComponentCallbacks2 cb = callbacks.get(i); - if (cb instanceof Activity) { - // If callback is an Activity - call corresponding method to consider override - // config and avoid onConfigurationChanged if it hasn't changed. - Activity a = (Activity) cb; - performConfigurationChangedForActivity(mActivities.get(a.getActivityToken()), - config); - } else if (!equivalent) { + if (!equivalent) { performConfigurationChanged(cb, config); } else { // TODO (b/135719017): Temporary log for debugging IME service. @@ -6206,7 +6140,8 @@ public final class ActivityThread extends ClientTransactionHandler { } final void handleLowMemory() { - ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); + final ArrayList<ComponentCallbacks2> callbacks = + collectComponentCallbacks(true /* includeActivities */); final int N = callbacks.size(); for (int i=0; i<N; i++) { @@ -6238,7 +6173,8 @@ public final class ActivityThread extends ClientTransactionHandler { } } - ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); + final ArrayList<ComponentCallbacks2> callbacks = + collectComponentCallbacks(true /* includeActivities */); final int N = callbacks.size(); for (int i = 0; i < N; i++) { |