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
This commit is contained in:
Riddle Hsu
2021-12-13 18:52:54 +08:00
parent 06328c7ada
commit 778c95ce7c
3 changed files with 15 additions and 9 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -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;