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

Commit 09e7382f authored by Charles Chen's avatar Charles Chen
Browse files

Update resources when config update of sysUiContext

Before WindowContextInfoItem, the SystemUiContext was updated directly.
After that, the change will be post to the main thread first, which
lead to DisplayPolicy#onConfigurationChanged and other methods to
get obosolete values from SystemUiContext's resources.
They still assume SystemUiContext would be updated directly.

This CL track SystemUiContext config update with ComponentCallbacks,
and changes to update fields from SystemUiContext Resurces there.

Bug: 384428048
Test: atest DisplayContentTest DisplayPolicyTest
Test: atest FrameworksCoreTests:ContextTest
Flag: com.android.window.flags.track_system_ui_context_before_wms

Change-Id: I8e1596a0f5f0fdd429d9fa66bb1da2625a1bdab2
parent e678d95e
Loading
Loading
Loading
Loading
+40 −7
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.content.ComponentCallbacks;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ActivityInfo;
@@ -470,6 +471,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    private DisplayInfo mLastDisplayInfoOverride;

    private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
    @NonNull
    private final DisplayPolicy mDisplayPolicy;
    private final DisplayRotation mDisplayRotation;

@@ -556,6 +558,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    /** Remove this display when animation on it has completed. */
    private boolean mDeferredRemoval;

    @NonNull
    final PinnedTaskController mPinnedTaskController;

    private final LinkedList<ActivityRecord> mTmpUpdateAllDrawn = new LinkedList();
@@ -1115,6 +1118,29 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        w.updateResizingWindowIfNeeded();
    };

    /**
     * Called to update fields retrieve from {@link #getDisplayUiContext()} resources when
     * there's a configuration update on {@link #getDisplayUiContext()}.
     */
    @NonNull
    private final ComponentCallbacks mSysUiContextConfigCallback = new ComponentCallbacks() {

        @Override
        public void onConfigurationChanged(@NonNull Configuration newConfig) {
            synchronized (mWmService.mGlobalLock) {
                if (mDisplayReady) {
                    mDisplayPolicy.onConfigurationChanged();
                    mMinSizeOfResizeableTaskDp = getMinimalTaskSizeDp();
                }
            }
        }

        @Override
        public void onLowMemory() {
            // Do nothing.
        }
    };

    /**
     * Create new {@link DisplayContent} instance, add itself to the root window container and
     * initialize direct children.
@@ -2823,11 +2849,10 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        final int lastOrientation = getConfiguration().orientation;
        final int lastWindowingMode = getWindowingMode();
        super.onConfigurationChanged(newParentConfig);
        if (mDisplayPolicy != null) {
            mDisplayPolicy.onConfigurationChanged();
            mPinnedTaskController.onPostDisplayConfigurationChanged();
            mMinSizeOfResizeableTaskDp = getMinimalTaskSizeDp();
        if (!Flags.trackSystemUiContextBeforeWms()) {
            mSysUiContextConfigCallback.onConfigurationChanged(newParentConfig);
        }
        mPinnedTaskController.onPostDisplayConfigurationChanged();
        // Update IME parent if needed.
        updateImeParent();

@@ -3388,6 +3413,9 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                    .getKeyguardController().onDisplayRemoved(mDisplayId);
            mWallpaperController.resetLargestDisplay(mDisplay);
            mWmService.mDisplayWindowSettings.onDisplayRemoved(this);
            if (Flags.trackSystemUiContextBeforeWms()) {
                getDisplayUiContext().unregisterComponentCallbacks(mSysUiContextConfigCallback);
            }
        } finally {
            mDisplayReady = false;
        }
@@ -5484,7 +5512,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
            reconfigureDisplayLocked();
            onRequestedOverrideConfigurationChanged(getRequestedOverrideConfiguration());
            mWmService.mDisplayNotificationController.dispatchDisplayAdded(this);
            // Attach the SystemUiContext to this DisplayContent the get latest configuration.
            // Attach the SystemUiContext to this DisplayContent to get latest configuration.
            // Note that the SystemUiContext will be removed automatically if this DisplayContent
            // is detached.
            registerSystemUiContext();
@@ -5492,11 +5520,15 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    }

    private void registerSystemUiContext() {
        final Context systemUiContext = getDisplayUiContext();
        final WindowProcessController wpc = mAtmService.getProcessController(
                getDisplayUiContext().getIApplicationThread());
                systemUiContext.getIApplicationThread());
        mWmService.mWindowContextListenerController.registerWindowContainerListener(
                wpc, getDisplayUiContext().getWindowContextToken(), this,
                wpc, systemUiContext.getWindowContextToken(), this,
                INVALID_WINDOW_TYPE, null /* options */);
        if (Flags.trackSystemUiContextBeforeWms()) {
            systemUiContext.registerComponentCallbacks(mSysUiContextConfigCallback);
        }
    }

    @Override
@@ -6689,6 +6721,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        forAllTasks((t) -> { t.getRootTask().removeChild(t, "removeAllTasks"); });
    }

    @NonNull
    Context getDisplayUiContext() {
        return mDisplayPolicy.getSystemUiContext();
    }
+1 −0
Original line number Diff line number Diff line
@@ -1865,6 +1865,7 @@ public class DisplayPolicy {
        return mContext;
    }

    @NonNull
    Context getSystemUiContext() {
        return mUiContext;
    }