diff options
| author | 2021-12-13 18:52:54 +0800 | |
|---|---|---|
| committer | 2021-12-13 18:52:54 +0800 | |
| commit | 778c95ce7c540745bd647ac00b244b8ec044434b (patch) | |
| tree | 9fd226808fabbf1228a344c9a0d509f81a2f21a1 | |
| parent | 06328c7ada4e91cf09ec3e0b34480e6a91354d86 (diff) | |
Reduce cost of WindowTokenClient config change
The SizeConfigurationBuckets was used to avoid activity relaunch
by insignificant configuration change. Because WindowTokenClient
doesn't have relaunch operation, it is unnecessary to use it.
Especially Resources#getSizeConfigurations() is a heavy invocation,
which may create hundreds of temporal Configuration when calling it
in system server.
Also fix leakage of SystemUiContext if it is detached, e.g. the
associated display is removed.
Bug: 207620458
Test: atest WindowContextControllerTest
Change-Id: I8388a2ab25f3deed2e29eb5636c4b2130f4f1b87
| -rw-r--r-- | core/java/android/app/ActivityThread.java | 10 | ||||
| -rw-r--r-- | core/java/android/app/ContextImpl.java | 4 | ||||
| -rw-r--r-- | core/java/android/window/WindowTokenClient.java | 10 |
3 files changed, 15 insertions, 9 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 76e392d6cead..46f6597bb042 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -2685,6 +2685,16 @@ public final class ActivityThread extends ClientTransactionHandler } } + void onSystemUiContextCleanup(ContextImpl context) { + synchronized (this) { + if (mDisplaySystemUiContexts == null) return; + final int index = mDisplaySystemUiContexts.indexOfValue(context); + if (index >= 0) { + mDisplaySystemUiContexts.removeAt(index); + } + } + } + public void installSystemApplicationInfo(ApplicationInfo info, ClassLoader classLoader) { synchronized (this) { getSystemContext().installSystemApplicationInfo(info, classLoader); diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index db3c7d9bcb02..fc1884a41653 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -3191,6 +3191,10 @@ class ContextImpl extends Context { final void performFinalCleanup(String who, String what) { //Log.i(TAG, "Cleanup up context: " + this); mPackageInfo.removeContextRegistrations(getOuterContext(), who, what); + if (mContextType == CONTEXT_TYPE_SYSTEM_OR_SYSTEM_UI + && mToken instanceof WindowTokenClient) { + mMainThread.onSystemUiContextCleanup(this); + } } @UnsupportedAppUsage diff --git a/core/java/android/window/WindowTokenClient.java b/core/java/android/window/WindowTokenClient.java index b331a9e81e27..4ba7ef26e9cb 100644 --- a/core/java/android/window/WindowTokenClient.java +++ b/core/java/android/window/WindowTokenClient.java @@ -15,7 +15,6 @@ */ package android.window; -import static android.window.ConfigurationHelper.diffPublicWithSizeBuckets; import static android.window.ConfigurationHelper.freeTextLayoutCachesIfNeeded; import static android.window.ConfigurationHelper.isDifferentDisplay; import static android.window.ConfigurationHelper.shouldUpdateResources; @@ -222,14 +221,7 @@ public class WindowTokenClient extends IWindowToken.Stub { () -> windowContext.dispatchConfigurationChanged(newConfig)); } - // Dispatch onConfigurationChanged only if there's a significant public change to - // make it compatible with the original behavior. - final Configuration[] sizeConfigurations = context.getResources() - .getSizeConfigurations(); - final SizeConfigurationBuckets buckets = sizeConfigurations != null - ? new SizeConfigurationBuckets(sizeConfigurations) : null; - final int diff = diffPublicWithSizeBuckets(mConfiguration, newConfig, buckets); - + final int diff = mConfiguration.diffPublicOnly(newConfig); if (shouldReportConfigChange && diff != 0 && context instanceof WindowProviderService) { final WindowProviderService windowProviderService = (WindowProviderService) context; |