Refine WindowManagerInternal#getDisplayImePolicy

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

Bug: 197848765
Test: atest CtsInputMethodTestCases
Change-Id: Ib00124b33409bce716fc01af33521bcd35ab02ec
This commit is contained in:
Ming-Shin Lu
2021-11-25 01:46:31 +08:00
parent 501107a445
commit 2c174780d8
3 changed files with 24 additions and 8 deletions

View File

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

View File

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

View File

@@ -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,9 +7883,7 @@ public class WindowManagerService extends IWindowManager.Stub
@Override
public @DisplayImePolicy int getDisplayImePolicy(int displayId) {
synchronized (mGlobalLock) {
return WindowManagerService.this.getDisplayImePolicy(displayId);
}
return WindowManagerService.this.getDisplayImePolicy(displayId);
}
@Override