Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 778c95ce authored by Riddle Hsu's avatar Riddle Hsu
Browse files

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
parent 06328c7a
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -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);
+4 −0
Original line number Diff line number Diff line
@@ -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
+1 −9
Original line number Diff line number Diff line
@@ -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;