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

Commit 2c174780 authored by Ming-Shin Lu's avatar Ming-Shin Lu
Browse files

Refine WindowManagerInternal#getDisplayImePolicy

..by using cache without holing WM lock to get the displayImePolicy
settings.

Bug: 197848765
Test: atest CtsInputMethodTestCases
Change-Id: Ib00124b33409bce716fc01af33521bcd35ab02ec
parent 501107a4
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2001,6 +2001,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    }

    void configureDisplayPolicy() {
        mRootWindowContainer.updateDisplayImePolicyCache();
        mDisplayPolicy.updateConfigurationAndScreenSizeDependentBehaviors();
        mDisplayRotation.configure(mBaseDisplayWidth, mBaseDisplayHeight);
    }
@@ -3939,6 +3940,9 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        }
    }

    // IMPORTANT: When introducing new dependencies in this method, make sure that
    // changes to those result in RootWindowContainer.updateDisplayImePolicyCache()
    // being called.
    @DisplayImePolicy int getImePolicy() {
        if (!isTrusted()) {
            return DISPLAY_IME_POLICY_FALLBACK_DISPLAY;
+8 −0
Original line number Diff line number Diff line
@@ -165,6 +165,7 @@ import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@@ -2530,9 +2531,16 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
            // Drop any cached DisplayInfos associated with this display id - the values are now
            // out of date given this display changed event.
            mWmService.mPossibleDisplayInfoMapper.removePossibleDisplayInfos(displayId);
            updateDisplayImePolicyCache();
        }
    }

    void updateDisplayImePolicyCache() {
        ArrayMap<Integer, Integer> displayImePolicyMap = new ArrayMap<>();
        forAllDisplays(dc -> displayImePolicyMap.put(dc.getDisplayId(), dc.getImePolicy()));
        mWmService.mDisplayImePolicyCache = Collections.unmodifiableMap(displayImePolicyMap);
    }

    /** Update lists of UIDs that are present on displays and have access to them. */
    void updateUIDsPresentOnDisplay() {
        mDisplayAccessUIDs.clear();
+12 −8
Original line number Diff line number Diff line
@@ -591,6 +591,13 @@ public class WindowManagerService extends IWindowManager.Stub
     */
    final ArrayList<WindowState> mResizingWindows = new ArrayList<>();

    /**
     * Mapping of displayId to {@link DisplayImePolicy}.
     * Note that this can be accessed without holding the lock.
     */
    volatile Map<Integer, Integer> mDisplayImePolicyCache = Collections.unmodifiableMap(
            new ArrayMap<>());

    /**
     * Windows whose surface should be destroyed.
     */
@@ -6947,6 +6954,7 @@ public class WindowManagerService extends IWindowManager.Stub
    void setForceDesktopModeOnExternalDisplays(boolean forceDesktopModeOnExternalDisplays) {
        synchronized (mGlobalLock) {
            mForceDesktopModeOnExternalDisplays = forceDesktopModeOnExternalDisplays;
            mRoot.updateDisplayImePolicyCache();
        }
    }

@@ -7378,16 +7386,14 @@ public class WindowManagerService extends IWindowManager.Stub
        if (!checkCallingPermission(INTERNAL_SYSTEM_WINDOW, "getDisplayImePolicy()")) {
            throw new SecurityException("Requires INTERNAL_SYSTEM_WINDOW permission");
        }
        final DisplayContent dc = mRoot.getDisplayContent(displayId);
        if (dc == null) {
        final Map<Integer, Integer> displayImePolicyCache = mDisplayImePolicyCache;
        if (!displayImePolicyCache.containsKey(displayId)) {
            ProtoLog.w(WM_ERROR,
                    "Attempted to get IME policy of a display that does not exist: %d",
                    displayId);
            return DISPLAY_IME_POLICY_FALLBACK_DISPLAY;
        }
        synchronized (mGlobalLock) {
            return dc.getImePolicy();
        }
        return displayImePolicyCache.get(displayId);
    }

    @Override
@@ -7877,10 +7883,8 @@ public class WindowManagerService extends IWindowManager.Stub

        @Override
        public @DisplayImePolicy int getDisplayImePolicy(int displayId) {
            synchronized (mGlobalLock) {
            return WindowManagerService.this.getDisplayImePolicy(displayId);
        }
        }

        @Override
        public void addNonHighRefreshRatePackage(@NonNull String packageName) {