Loading services/core/java/com/android/server/wm/AccessibilityController.java +26 −0 Original line number Original line Diff line number Diff line Loading @@ -51,6 +51,7 @@ import android.accessibilityservice.AccessibilityTrace; import android.animation.ObjectAnimator; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.animation.ValueAnimator; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.Application; import android.app.Application; import android.content.Context; import android.content.Context; import android.content.pm.PackageManagerInternal; import android.content.pm.PackageManagerInternal; Loading Loading @@ -134,6 +135,8 @@ final class AccessibilityController { private SparseArray<DisplayMagnifier> mDisplayMagnifiers = new SparseArray<>(); private SparseArray<DisplayMagnifier> mDisplayMagnifiers = new SparseArray<>(); private SparseArray<WindowsForAccessibilityObserver> mWindowsForAccessibilityObserver = private SparseArray<WindowsForAccessibilityObserver> mWindowsForAccessibilityObserver = new SparseArray<>(); new SparseArray<>(); private SparseArray<IBinder> mFocusedWindow = new SparseArray<>(); private int mFocusedDisplay = -1; // Set to true if initializing window population complete. // Set to true if initializing window population complete. private boolean mAllObserversInitialized = true; private boolean mAllObserversInitialized = true; Loading Loading @@ -516,6 +519,29 @@ final class AccessibilityController { + "mWindowsForAccessibilityObserver=" + mWindowsForAccessibilityObserver); + "mWindowsForAccessibilityObserver=" + mWindowsForAccessibilityObserver); } } void onFocusChanged(InputTarget lastTarget, InputTarget newTarget) { if (lastTarget != null) { mFocusedWindow.remove(lastTarget.getDisplayId()); } if (newTarget != null) { int displayId = newTarget.getDisplayId(); IBinder clientBinder = newTarget.getIWindow().asBinder(); mFocusedWindow.put(displayId, clientBinder); } } public void onDisplayRemoved(int displayId) { mFocusedWindow.remove(displayId); } public void setFocusedDisplay(int focusedDisplayId) { mFocusedDisplay = focusedDisplayId; } @Nullable IBinder getFocusedWindowToken() { return mFocusedWindow.get(mFocusedDisplay); } /** /** * This class encapsulates the functionality related to display magnification. * This class encapsulates the functionality related to display magnification. */ */ Loading services/core/java/com/android/server/wm/AnrController.java +18 −24 Original line number Original line Diff line number Diff line Loading @@ -32,7 +32,6 @@ import android.view.InputApplicationHandle; import com.android.server.am.ActivityManagerService; import com.android.server.am.ActivityManagerService; import com.android.server.am.CriticalEventLog; import com.android.server.am.CriticalEventLog; import com.android.server.wm.EmbeddedWindowController.EmbeddedWindow; import java.io.File; import java.io.File; import java.util.ArrayList; import java.util.ArrayList; Loading Loading @@ -82,21 +81,23 @@ class AnrController { final boolean aboveSystem; final boolean aboveSystem; final ActivityRecord activity; final ActivityRecord activity; synchronized (mService.mGlobalLock) { synchronized (mService.mGlobalLock) { WindowState windowState = mService.mInputToWindowMap.get(inputToken); InputTarget target = mService.getInputTargetFromToken(inputToken); if (windowState != null) { if (target == null) { pid = windowState.mSession.mPid; activity = windowState.mActivityRecord; Slog.i(TAG_WM, "ANR in " + windowState.mAttrs.getTitle() + ". Reason:" + reason); } else { EmbeddedWindow embeddedWindow = mService.mEmbeddedWindowController.get(inputToken); if (embeddedWindow == null) { Slog.e(TAG_WM, "Unknown token, dropping notifyConnectionUnresponsive request"); Slog.e(TAG_WM, "Unknown token, dropping notifyConnectionUnresponsive request"); return; return; } } pid = embeddedWindow.mOwnerPid; windowState = embeddedWindow.mHostWindowState; WindowState windowState = target.asWindowState(); activity = null; // Don't blame the host process, instead blame the embedded pid. pid = target.getPid(); if (windowState != null) { activity = windowState.mActivityRecord; } else { // Don't blame the host process, instead blame the embedded pid. activity = null; // Use host WindowState for logging and z-order test. windowState = target.asEmbeddedWindow().mHostWindowState; } } Slog.i(TAG_WM, "ANR in " + target + ". Reason:" + reason); aboveSystem = isWindowAboveSystem(windowState); aboveSystem = isWindowAboveSystem(windowState); dumpAnrStateLocked(activity, windowState, reason); dumpAnrStateLocked(activity, windowState, reason); } } Loading @@ -110,19 +111,12 @@ class AnrController { void notifyWindowResponsive(IBinder inputToken) { void notifyWindowResponsive(IBinder inputToken) { final int pid; final int pid; synchronized (mService.mGlobalLock) { synchronized (mService.mGlobalLock) { WindowState windowState = mService.mInputToWindowMap.get(inputToken); InputTarget target = mService.getInputTargetFromToken(inputToken); if (windowState != null) { if (target == null) { pid = windowState.mSession.mPid; Slog.e(TAG_WM, "Unknown token, dropping notifyWindowConnectionResponsive request"); } else { // Check if the token belongs to an embedded window. EmbeddedWindow embeddedWindow = mService.mEmbeddedWindowController.get(inputToken); if (embeddedWindow == null) { Slog.e(TAG_WM, "Unknown token, dropping notifyWindowConnectionResponsive request"); return; return; } } pid = embeddedWindow.mOwnerPid; pid = target.getPid(); } } } mService.mAmInternal.inputDispatchingResumed(pid); mService.mAmInternal.inputDispatchingResumed(pid); } } Loading services/core/java/com/android/server/wm/DisplayContent.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -3073,6 +3073,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp mOverlayLayer.release(); mOverlayLayer.release(); mInputMonitor.onDisplayRemoved(); mInputMonitor.onDisplayRemoved(); mWmService.mDisplayNotificationController.dispatchDisplayRemoved(this); mWmService.mDisplayNotificationController.dispatchDisplayRemoved(this); mWmService.mAccessibilityController.onDisplayRemoved(mDisplayId); } finally { } finally { mDisplayReady = false; mDisplayReady = false; } } Loading services/core/java/com/android/server/wm/EmbeddedWindowController.java +24 −3 Original line number Original line Diff line number Diff line Loading @@ -127,7 +127,7 @@ class EmbeddedWindowController { } } } } static class EmbeddedWindow { static class EmbeddedWindow implements InputTarget { final IWindow mClient; final IWindow mClient; @Nullable final WindowState mHostWindowState; @Nullable final WindowState mHostWindowState; @Nullable final ActivityRecord mHostActivityRecord; @Nullable final ActivityRecord mHostActivityRecord; Loading Loading @@ -166,7 +166,8 @@ class EmbeddedWindowController { mDisplayId = displayId; mDisplayId = displayId; } } String getName() { @Override public String toString() { final String hostWindowName = (mHostWindowState != null) final String hostWindowName = (mHostWindowState != null) ? mHostWindowState.getWindowTag().toString() : "Internal"; ? mHostWindowState.getWindowTag().toString() : "Internal"; return "EmbeddedWindow{ u" + UserHandle.getUserId(mOwnerUid) + " " + hostWindowName return "EmbeddedWindow{ u" + UserHandle.getUserId(mOwnerUid) + " " + hostWindowName Loading @@ -183,7 +184,7 @@ class EmbeddedWindowController { } } InputChannel openInputChannel() { InputChannel openInputChannel() { final String name = getName(); final String name = toString(); mInputChannel = mWmService.mInputManager.createInputChannel(name); mInputChannel = mWmService.mInputManager.createInputChannel(name); return mInputChannel; return mInputChannel; } } Loading @@ -195,5 +196,25 @@ class EmbeddedWindowController { mInputChannel = null; mInputChannel = null; } } } } @Override public EmbeddedWindow asEmbeddedWindow() { return this; } @Override public int getDisplayId() { return mDisplayId; } @Override public IWindow getIWindow() { return mClient; } @Override public int getPid() { return mOwnerPid; } } } } } services/core/java/com/android/server/wm/InputTarget.java 0 → 100644 +45 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.wm; import android.view.IWindow; /** * Common interface between focusable objects. * * Both WindowState and EmbeddedWindows can receive input. This consolidates some common properties * of both targets. */ interface InputTarget { default WindowState asWindowState() { return null; } default EmbeddedWindowController.EmbeddedWindow asEmbeddedWindow() { return null; } /* Display id of the target. */ int getDisplayId(); /* Client IWindow for the target. */ IWindow getIWindow(); /* Owning pid of the target. */ int getPid(); } Loading
services/core/java/com/android/server/wm/AccessibilityController.java +26 −0 Original line number Original line Diff line number Diff line Loading @@ -51,6 +51,7 @@ import android.accessibilityservice.AccessibilityTrace; import android.animation.ObjectAnimator; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.animation.ValueAnimator; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.Application; import android.app.Application; import android.content.Context; import android.content.Context; import android.content.pm.PackageManagerInternal; import android.content.pm.PackageManagerInternal; Loading Loading @@ -134,6 +135,8 @@ final class AccessibilityController { private SparseArray<DisplayMagnifier> mDisplayMagnifiers = new SparseArray<>(); private SparseArray<DisplayMagnifier> mDisplayMagnifiers = new SparseArray<>(); private SparseArray<WindowsForAccessibilityObserver> mWindowsForAccessibilityObserver = private SparseArray<WindowsForAccessibilityObserver> mWindowsForAccessibilityObserver = new SparseArray<>(); new SparseArray<>(); private SparseArray<IBinder> mFocusedWindow = new SparseArray<>(); private int mFocusedDisplay = -1; // Set to true if initializing window population complete. // Set to true if initializing window population complete. private boolean mAllObserversInitialized = true; private boolean mAllObserversInitialized = true; Loading Loading @@ -516,6 +519,29 @@ final class AccessibilityController { + "mWindowsForAccessibilityObserver=" + mWindowsForAccessibilityObserver); + "mWindowsForAccessibilityObserver=" + mWindowsForAccessibilityObserver); } } void onFocusChanged(InputTarget lastTarget, InputTarget newTarget) { if (lastTarget != null) { mFocusedWindow.remove(lastTarget.getDisplayId()); } if (newTarget != null) { int displayId = newTarget.getDisplayId(); IBinder clientBinder = newTarget.getIWindow().asBinder(); mFocusedWindow.put(displayId, clientBinder); } } public void onDisplayRemoved(int displayId) { mFocusedWindow.remove(displayId); } public void setFocusedDisplay(int focusedDisplayId) { mFocusedDisplay = focusedDisplayId; } @Nullable IBinder getFocusedWindowToken() { return mFocusedWindow.get(mFocusedDisplay); } /** /** * This class encapsulates the functionality related to display magnification. * This class encapsulates the functionality related to display magnification. */ */ Loading
services/core/java/com/android/server/wm/AnrController.java +18 −24 Original line number Original line Diff line number Diff line Loading @@ -32,7 +32,6 @@ import android.view.InputApplicationHandle; import com.android.server.am.ActivityManagerService; import com.android.server.am.ActivityManagerService; import com.android.server.am.CriticalEventLog; import com.android.server.am.CriticalEventLog; import com.android.server.wm.EmbeddedWindowController.EmbeddedWindow; import java.io.File; import java.io.File; import java.util.ArrayList; import java.util.ArrayList; Loading Loading @@ -82,21 +81,23 @@ class AnrController { final boolean aboveSystem; final boolean aboveSystem; final ActivityRecord activity; final ActivityRecord activity; synchronized (mService.mGlobalLock) { synchronized (mService.mGlobalLock) { WindowState windowState = mService.mInputToWindowMap.get(inputToken); InputTarget target = mService.getInputTargetFromToken(inputToken); if (windowState != null) { if (target == null) { pid = windowState.mSession.mPid; activity = windowState.mActivityRecord; Slog.i(TAG_WM, "ANR in " + windowState.mAttrs.getTitle() + ". Reason:" + reason); } else { EmbeddedWindow embeddedWindow = mService.mEmbeddedWindowController.get(inputToken); if (embeddedWindow == null) { Slog.e(TAG_WM, "Unknown token, dropping notifyConnectionUnresponsive request"); Slog.e(TAG_WM, "Unknown token, dropping notifyConnectionUnresponsive request"); return; return; } } pid = embeddedWindow.mOwnerPid; windowState = embeddedWindow.mHostWindowState; WindowState windowState = target.asWindowState(); activity = null; // Don't blame the host process, instead blame the embedded pid. pid = target.getPid(); if (windowState != null) { activity = windowState.mActivityRecord; } else { // Don't blame the host process, instead blame the embedded pid. activity = null; // Use host WindowState for logging and z-order test. windowState = target.asEmbeddedWindow().mHostWindowState; } } Slog.i(TAG_WM, "ANR in " + target + ". Reason:" + reason); aboveSystem = isWindowAboveSystem(windowState); aboveSystem = isWindowAboveSystem(windowState); dumpAnrStateLocked(activity, windowState, reason); dumpAnrStateLocked(activity, windowState, reason); } } Loading @@ -110,19 +111,12 @@ class AnrController { void notifyWindowResponsive(IBinder inputToken) { void notifyWindowResponsive(IBinder inputToken) { final int pid; final int pid; synchronized (mService.mGlobalLock) { synchronized (mService.mGlobalLock) { WindowState windowState = mService.mInputToWindowMap.get(inputToken); InputTarget target = mService.getInputTargetFromToken(inputToken); if (windowState != null) { if (target == null) { pid = windowState.mSession.mPid; Slog.e(TAG_WM, "Unknown token, dropping notifyWindowConnectionResponsive request"); } else { // Check if the token belongs to an embedded window. EmbeddedWindow embeddedWindow = mService.mEmbeddedWindowController.get(inputToken); if (embeddedWindow == null) { Slog.e(TAG_WM, "Unknown token, dropping notifyWindowConnectionResponsive request"); return; return; } } pid = embeddedWindow.mOwnerPid; pid = target.getPid(); } } } mService.mAmInternal.inputDispatchingResumed(pid); mService.mAmInternal.inputDispatchingResumed(pid); } } Loading
services/core/java/com/android/server/wm/DisplayContent.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -3073,6 +3073,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp mOverlayLayer.release(); mOverlayLayer.release(); mInputMonitor.onDisplayRemoved(); mInputMonitor.onDisplayRemoved(); mWmService.mDisplayNotificationController.dispatchDisplayRemoved(this); mWmService.mDisplayNotificationController.dispatchDisplayRemoved(this); mWmService.mAccessibilityController.onDisplayRemoved(mDisplayId); } finally { } finally { mDisplayReady = false; mDisplayReady = false; } } Loading
services/core/java/com/android/server/wm/EmbeddedWindowController.java +24 −3 Original line number Original line Diff line number Diff line Loading @@ -127,7 +127,7 @@ class EmbeddedWindowController { } } } } static class EmbeddedWindow { static class EmbeddedWindow implements InputTarget { final IWindow mClient; final IWindow mClient; @Nullable final WindowState mHostWindowState; @Nullable final WindowState mHostWindowState; @Nullable final ActivityRecord mHostActivityRecord; @Nullable final ActivityRecord mHostActivityRecord; Loading Loading @@ -166,7 +166,8 @@ class EmbeddedWindowController { mDisplayId = displayId; mDisplayId = displayId; } } String getName() { @Override public String toString() { final String hostWindowName = (mHostWindowState != null) final String hostWindowName = (mHostWindowState != null) ? mHostWindowState.getWindowTag().toString() : "Internal"; ? mHostWindowState.getWindowTag().toString() : "Internal"; return "EmbeddedWindow{ u" + UserHandle.getUserId(mOwnerUid) + " " + hostWindowName return "EmbeddedWindow{ u" + UserHandle.getUserId(mOwnerUid) + " " + hostWindowName Loading @@ -183,7 +184,7 @@ class EmbeddedWindowController { } } InputChannel openInputChannel() { InputChannel openInputChannel() { final String name = getName(); final String name = toString(); mInputChannel = mWmService.mInputManager.createInputChannel(name); mInputChannel = mWmService.mInputManager.createInputChannel(name); return mInputChannel; return mInputChannel; } } Loading @@ -195,5 +196,25 @@ class EmbeddedWindowController { mInputChannel = null; mInputChannel = null; } } } } @Override public EmbeddedWindow asEmbeddedWindow() { return this; } @Override public int getDisplayId() { return mDisplayId; } @Override public IWindow getIWindow() { return mClient; } @Override public int getPid() { return mOwnerPid; } } } } }
services/core/java/com/android/server/wm/InputTarget.java 0 → 100644 +45 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.wm; import android.view.IWindow; /** * Common interface between focusable objects. * * Both WindowState and EmbeddedWindows can receive input. This consolidates some common properties * of both targets. */ interface InputTarget { default WindowState asWindowState() { return null; } default EmbeddedWindowController.EmbeddedWindow asEmbeddedWindow() { return null; } /* Display id of the target. */ int getDisplayId(); /* Client IWindow for the target. */ IWindow getIWindow(); /* Owning pid of the target. */ int getPid(); }