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

Commit 6e008806 authored by Toshiki Kikuchi's avatar Toshiki Kikuchi
Browse files

Do not assume DisplayNotificationController is thread-safe

This CL makes WM to use DisplayNotificationController thread-safely by
- changes to call dispatchDesktopModeEligibleChanged with the
global lock.
- hold the global lock to [un]register listeners

Flag: com.android.server.display.feature.flags.enable_display_content_mode_management
Test: ActivityTaskManagerServiceTests
Bug: 406462760
Change-Id: I5ac1b2a232cef14b820407bb4ec5dcc005466ae7
parent 01883486
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -1885,6 +1885,10 @@ public class DisplayPolicy {
            final boolean eligibleForDesktopMode =
                    isSystemDecorationsSupported && (mDisplayContent.isDefaultDisplay
                            || mDisplayContent.allowContentModeSwitch());
            if (eligibleForDesktopMode) {
                mService.mDisplayNotificationController.dispatchDesktopModeEligibleChanged(
                        displayId);
            }
            mHandler.post(() -> {
                if (isSystemDecorationsSupported) {
                    StatusBarManagerInternal statusBar = getStatusBarManagerInternal();
@@ -1899,10 +1903,6 @@ public class DisplayPolicy {
                        wpMgr.onDisplayAddSystemDecorations(displayId);
                    }
                }
                if (eligibleForDesktopMode) {
                    mService.mDisplayNotificationController.dispatchDesktopModeEligibleChanged(
                            displayId);
                }
            });
        } else {
            mHandler.post(() -> {
@@ -1921,9 +1921,10 @@ public class DisplayPolicy {
    }

    void notifyDisplayRemoveSystemDecorations() {
        final int displayId = getDisplayId();
        mService.mDisplayNotificationController.dispatchDesktopModeEligibleChanged(displayId);
        mHandler.post(
                () -> {
                    final int displayId = getDisplayId();
                    StatusBarManagerInternal statusBar = getStatusBarManagerInternal();
                    if (statusBar != null) {
                        statusBar.onDisplayRemoveSystemDecorations(displayId);
@@ -1933,8 +1934,6 @@ public class DisplayPolicy {
                    if (wpMgr != null) {
                        wpMgr.onDisplayRemoveSystemDecorations(displayId);
                    }
                    mService.mDisplayNotificationController.dispatchDesktopModeEligibleChanged(
                            displayId);
                    final NotificationManagerInternal notificationManager =
                            LocalServices.getService(NotificationManagerInternal.class);
                    if (notificationManager != null) {
+0 −4
Original line number Diff line number Diff line
@@ -77,8 +77,6 @@ import android.view.WindowManager;

import androidx.test.filters.MediumTest;

import com.android.server.UiThread;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -234,14 +232,12 @@ public class ActivityTaskManagerServiceTests extends WindowTestsBase {
        doReturn(true).when(newDisp1).allowContentModeSwitch();
        doReturn(true).when(newDisp1).isSystemDecorationsSupported();
        mAtm.mWindowManager.setShouldShowSystemDecors(newDisp1.mDisplayId, true);
        waitHandlerIdle(UiThread.getHandler());
        assertEquals(1, desktopModeEligibleChanged.size());
        assertEquals(newDisp1.mDisplayId, (int) desktopModeEligibleChanged.get(0));
        desktopModeEligibleChanged.clear();
        // Check removing decoration
        doReturn(false).when(newDisp1).isSystemDecorationsSupported();
        mAtm.mWindowManager.setShouldShowSystemDecors(newDisp1.mDisplayId, false);
        waitHandlerIdle(UiThread.getHandler());
        assertEquals(1, desktopModeEligibleChanged.size());
        assertEquals(newDisp1.mDisplayId, (int) desktopModeEligibleChanged.get(0));
        desktopModeEligibleChanged.clear();