summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chris Li <lihongyu@google.com> 2023-07-26 03:37:45 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-07-26 03:37:45 +0000
commit6927452e34ea94505f6a17dfbcf37d0c7dd4f0e9 (patch)
treecffb7bd90738e13da6ef370206a82883d2edcaaa
parent46d2d95b04a62589478353158d85786cf11d683d (diff)
parente70174eac3ca83cd6103bfa8124b4a48ad001724 (diff)
Merge "Migrate WindowContext#onConfigurationChanged to ClientTransaction (8/n)" into main
-rw-r--r--services/core/java/com/android/server/wm/DisplayContent.java3
-rw-r--r--services/core/java/com/android/server/wm/WindowContextListenerController.java23
-rw-r--r--services/core/java/com/android/server/wm/WindowManagerService.java9
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/InputMethodDialogWindowContextTest.java3
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/WindowContextListenerControllerTests.java31
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java6
6 files changed, 36 insertions, 39 deletions
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index a29aeff935d6..614493dca2d8 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -34,7 +34,6 @@ import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.content.res.Configuration.ORIENTATION_UNDEFINED;
import static android.os.Build.VERSION_CODES.N;
-import static android.os.Process.SYSTEM_UID;
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
import static android.util.DisplayMetrics.DENSITY_DEFAULT;
import static android.util.RotationUtils.deltaRotation;
@@ -5425,7 +5424,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
final WindowProcessController wpc = mAtmService.getProcessController(
getDisplayUiContext().getIApplicationThread());
mWmService.mWindowContextListenerController.registerWindowContainerListener(
- wpc, getDisplayUiContext().getWindowContextToken(), this, SYSTEM_UID,
+ wpc, getDisplayUiContext().getWindowContextToken(), this,
INVALID_WINDOW_TYPE, null /* options */);
}
}
diff --git a/services/core/java/com/android/server/wm/WindowContextListenerController.java b/services/core/java/com/android/server/wm/WindowContextListenerController.java
index a59c23007b93..26aab07695ca 100644
--- a/services/core/java/com/android/server/wm/WindowContextListenerController.java
+++ b/services/core/java/com/android/server/wm/WindowContextListenerController.java
@@ -70,12 +70,12 @@ class WindowContextListenerController {
/**
* @see #registerWindowContainerListener(WindowProcessController, IBinder, WindowContainer, int,
- * int, Bundle, boolean)
+ * Bundle, boolean)
*/
void registerWindowContainerListener(@NonNull WindowProcessController wpc,
- @NonNull IBinder clientToken, @NonNull WindowContainer<?> container, int ownerUid,
+ @NonNull IBinder clientToken, @NonNull WindowContainer<?> container,
@WindowType int type, @Nullable Bundle options) {
- registerWindowContainerListener(wpc, clientToken, container, ownerUid, type, options,
+ registerWindowContainerListener(wpc, clientToken, container, type, options,
true /* shouDispatchConfigWhenRegistering */);
}
@@ -89,7 +89,6 @@ class WindowContextListenerController {
* @param wpc the process that we should send the window configuration change to
* @param clientToken the token to associate with the listener
* @param container the {@link WindowContainer} which the listener is going to listen to.
- * @param ownerUid the caller UID
* @param type the window type
* @param options a bundle used to pass window-related options.
* @param shouDispatchConfigWhenRegistering {@code true} to indicate the current
@@ -97,12 +96,12 @@ class WindowContextListenerController {
* registering the {@link WindowContextListenerImpl}
*/
void registerWindowContainerListener(@NonNull WindowProcessController wpc,
- @NonNull IBinder clientToken, @NonNull WindowContainer<?> container, int ownerUid,
+ @NonNull IBinder clientToken, @NonNull WindowContainer<?> container,
@WindowType int type, @Nullable Bundle options,
boolean shouDispatchConfigWhenRegistering) {
WindowContextListenerImpl listener = mListeners.get(clientToken);
if (listener == null) {
- listener = new WindowContextListenerImpl(wpc, clientToken, container, ownerUid, type,
+ listener = new WindowContextListenerImpl(wpc, clientToken, container, type,
options);
listener.register(shouDispatchConfigWhenRegistering);
} else {
@@ -160,9 +159,9 @@ class WindowContextListenerController {
if (callerCanManageAppTokens) {
return true;
}
- if (callingUid != listener.mOwnerUid) {
+ if (callingUid != listener.getUid()) {
throw new UnsupportedOperationException("Uid mismatch. Caller uid is " + callingUid
- + ", while the listener's owner is from " + listener.mOwnerUid);
+ + ", while the listener's owner is from " + listener.getUid());
}
return true;
}
@@ -208,7 +207,6 @@ class WindowContextListenerController {
private final WindowProcessController mWpc;
@NonNull
private final IWindowToken mClientToken;
- private final int mOwnerUid;
@NonNull
private WindowContainer<?> mContainer;
/**
@@ -228,11 +226,10 @@ class WindowContextListenerController {
private WindowContextListenerImpl(@NonNull WindowProcessController wpc,
@NonNull IBinder clientToken, @NonNull WindowContainer<?> container,
- int ownerUid, @WindowType int type, @Nullable Bundle options) {
+ @WindowType int type, @Nullable Bundle options) {
mWpc = Objects.requireNonNull(wpc);
mClientToken = IWindowToken.Stub.asInterface(clientToken);
mContainer = Objects.requireNonNull(container);
- mOwnerUid = ownerUid;
mType = type;
mOptions = options;
@@ -252,6 +249,10 @@ class WindowContextListenerController {
return mContainer;
}
+ int getUid() {
+ return mWpc.mUid;
+ }
+
private void updateContainer(@NonNull WindowContainer<?> newContainer) {
Objects.requireNonNull(newContainer);
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 2a28010c81a3..7cca9885deca 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -2766,8 +2766,7 @@ public class WindowManagerService extends IWindowManager.Stub
final DisplayArea<?> da = dc.findAreaForWindowType(type, options,
callerCanManageAppTokens, false /* roundedCornerOverlay */);
mWindowContextListenerController.registerWindowContainerListener(wpc, clientToken,
- da, callingUid, type, options,
- false /* shouDispatchConfigWhenRegistering */);
+ da, type, options, false /* shouDispatchConfigWhenRegistering */);
return da.getConfiguration();
}
} finally {
@@ -2798,7 +2797,7 @@ public class WindowManagerService extends IWindowManager.Stub
// registration in DisplayContent#onParentChanged at DisplayContent initialization.
final DisplayContent dc = mRoot.getDisplayContent(displayId);
if (dc == null) {
- if (Binder.getCallingPid() != MY_PID) {
+ if (callingPid != MY_PID) {
throw new WindowManager.InvalidDisplayException(
"attachWindowContextToDisplayContent: trying to attach to a"
+ " non-existing display:" + displayId);
@@ -2809,7 +2808,7 @@ public class WindowManagerService extends IWindowManager.Stub
}
mWindowContextListenerController.registerWindowContainerListener(wpc, clientToken,
- dc, callingUid, INVALID_WINDOW_TYPE, null /* options */,
+ dc, INVALID_WINDOW_TYPE, null /* options */,
false /* shouDispatchConfigWhenRegistering */);
return dc.getConfiguration();
}
@@ -2858,7 +2857,7 @@ public class WindowManagerService extends IWindowManager.Stub
return;
}
mWindowContextListenerController.registerWindowContainerListener(wpc, clientToken,
- windowToken, callingUid, windowToken.windowType, windowToken.mOptions);
+ windowToken, windowToken.windowType, windowToken.mOptions);
}
} finally {
Binder.restoreCallingIdentity(origId);
diff --git a/services/tests/wmtests/src/com/android/server/wm/InputMethodDialogWindowContextTest.java b/services/tests/wmtests/src/com/android/server/wm/InputMethodDialogWindowContextTest.java
index cac32622cb5f..1180ebdcaecb 100644
--- a/services/tests/wmtests/src/com/android/server/wm/InputMethodDialogWindowContextTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/InputMethodDialogWindowContextTest.java
@@ -98,8 +98,7 @@ public class InputMethodDialogWindowContextTest extends WindowTestsBase {
DisplayContent dc = mWm.mRoot.getDisplayContent(displayId);
final WindowProcessController wpc = mAtm.getProcessController(appThread);
mWm.mWindowContextListenerController.registerWindowContainerListener(wpc, clientToken,
- dc.getImeContainer(), 1000 /* ownerUid */, TYPE_INPUT_METHOD_DIALOG,
- null /* options */);
+ dc.getImeContainer(), TYPE_INPUT_METHOD_DIALOG, null /* options */);
return dc.getImeContainer().getConfiguration();
}).when(mIWindowManager).attachWindowContextToDisplayArea(any(), any(),
eq(TYPE_INPUT_METHOD_DIALOG), anyInt(), any());
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowContextListenerControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowContextListenerControllerTests.java
index fa42e26a883e..57a397facc61 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowContextListenerControllerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowContextListenerControllerTests.java
@@ -37,7 +37,6 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
-import static org.mockito.MockitoAnnotations.initMocks;
import android.app.IWindowToken;
import android.content.res.Configuration;
@@ -54,7 +53,6 @@ import androidx.test.filters.SmallTest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
import org.mockito.Mockito;
/**
@@ -70,37 +68,38 @@ public class WindowContextListenerControllerTests extends WindowTestsBase {
private static final int TEST_UID = 12345;
private static final int ANOTHER_UID = 1000;
- @Mock
private WindowProcessController mWpc;
private final IBinder mClientToken = new Binder();
private WindowContainer<?> mContainer;
@Before
public void setUp() {
- initMocks(this);
mController = new WindowContextListenerController();
mContainer = createTestWindowToken(TYPE_APPLICATION_OVERLAY, mDisplayContent);
// Make display on to verify configuration propagation.
mDefaultDisplay.getDisplayInfo().state = STATE_ON;
mDisplayContent.getDisplayInfo().state = STATE_ON;
+ mWpc = mSystemServicesTestRule.addProcess(
+ DEFAULT_COMPONENT_PACKAGE_NAME, DEFAULT_COMPONENT_PACKAGE_NAME, 0 /* pid */,
+ TEST_UID);
}
@Test
public void testRegisterWindowContextListener() {
- mController.registerWindowContainerListener(mWpc, mClientToken, mContainer, -1,
+ mController.registerWindowContainerListener(mWpc, mClientToken, mContainer,
TYPE_APPLICATION_OVERLAY, null /* options */);
assertEquals(1, mController.mListeners.size());
final IBinder clientToken = mock(IBinder.class);
- mController.registerWindowContainerListener(mWpc, clientToken, mContainer, -1,
+ mController.registerWindowContainerListener(mWpc, clientToken, mContainer,
TYPE_APPLICATION_OVERLAY, null /* options */);
assertEquals(2, mController.mListeners.size());
final WindowContainer<?> container = createTestWindowToken(TYPE_APPLICATION_OVERLAY,
mDefaultDisplay);
- mController.registerWindowContainerListener(mWpc, mClientToken, container, -1,
+ mController.registerWindowContainerListener(mWpc, mClientToken, container,
TYPE_APPLICATION_OVERLAY, null /* options */);
// The number of listeners doesn't increase since the listener just gets updated.
@@ -126,7 +125,7 @@ public class WindowContextListenerControllerTests extends WindowTestsBase {
config1.densityDpi = 100;
mContainer.onRequestedOverrideConfigurationChanged(config1);
- mController.registerWindowContainerListener(mWpc, clientToken, mContainer, -1,
+ mController.registerWindowContainerListener(mWpc, clientToken, mContainer,
TYPE_APPLICATION_OVERLAY, null /* options */);
assertEquals(bounds1, clientToken.mConfiguration.windowConfiguration.getBounds());
@@ -142,7 +141,7 @@ public class WindowContextListenerControllerTests extends WindowTestsBase {
config2.densityDpi = 200;
container.onRequestedOverrideConfigurationChanged(config2);
- mController.registerWindowContainerListener(mWpc, clientToken, container, -1,
+ mController.registerWindowContainerListener(mWpc, clientToken, container,
TYPE_APPLICATION_OVERLAY, null /* options */);
assertEquals(bounds2, clientToken.mConfiguration.windowConfiguration.getBounds());
@@ -169,7 +168,7 @@ public class WindowContextListenerControllerTests extends WindowTestsBase {
@Test
public void testAssertCallerCanModifyListener_CanManageAppTokens_ReturnTrue() {
- mController.registerWindowContainerListener(mWpc, mClientToken, mContainer, TEST_UID,
+ mController.registerWindowContainerListener(mWpc, mClientToken, mContainer,
TYPE_APPLICATION_OVERLAY, null /* options */);
assertTrue(mController.assertCallerCanModifyListener(mClientToken,
@@ -178,7 +177,7 @@ public class WindowContextListenerControllerTests extends WindowTestsBase {
@Test
public void testAssertCallerCanModifyListener_SameUid_ReturnTrue() {
- mController.registerWindowContainerListener(mWpc, mClientToken, mContainer, TEST_UID,
+ mController.registerWindowContainerListener(mWpc, mClientToken, mContainer,
TYPE_APPLICATION_OVERLAY, null /* options */);
assertTrue(mController.assertCallerCanModifyListener(mClientToken,
@@ -187,7 +186,7 @@ public class WindowContextListenerControllerTests extends WindowTestsBase {
@Test(expected = UnsupportedOperationException.class)
public void testAssertCallerCanModifyListener_DifferentUid_ThrowException() {
- mController.registerWindowContainerListener(mWpc, mClientToken, mContainer, TEST_UID,
+ mController.registerWindowContainerListener(mWpc, mClientToken, mContainer,
TYPE_APPLICATION_OVERLAY, null /* options */);
mController.assertCallerCanModifyListener(mClientToken,
@@ -204,7 +203,7 @@ public class WindowContextListenerControllerTests extends WindowTestsBase {
final DisplayArea<?> da = windowContextCreatedToken.getDisplayArea();
mController.registerWindowContainerListener(mWpc, mClientToken, windowContextCreatedToken,
- TEST_UID, TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY, null /* options */);
+ TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY, null /* options */);
assertThat(mController.getContainer(mClientToken)).isEqualTo(windowContextCreatedToken);
@@ -239,7 +238,7 @@ public class WindowContextListenerControllerTests extends WindowTestsBase {
.setFromClientToken(true)
.build();
mController.registerWindowContainerListener(mWpc, mClientToken, windowContextCreatedToken,
- TEST_UID, TYPE_INPUT_METHOD_DIALOG, null /* options */);
+ TYPE_INPUT_METHOD_DIALOG, null /* options */);
assertThat(mController.getContainer(mClientToken)).isEqualTo(windowContextCreatedToken);
@@ -263,7 +262,7 @@ public class WindowContextListenerControllerTests extends WindowTestsBase {
config1.densityDpi = 100;
mContainer.onRequestedOverrideConfigurationChanged(config1);
- mController.registerWindowContainerListener(mWpc, mockToken, mContainer, -1,
+ mController.registerWindowContainerListener(mWpc, mockToken, mContainer,
TYPE_APPLICATION_OVERLAY, null /* options */);
verify(mockToken, never()).onConfigurationChanged(any(), anyInt());
@@ -298,7 +297,7 @@ public class WindowContextListenerControllerTests extends WindowTestsBase {
config1.densityDpi = 100;
mContainer.onRequestedOverrideConfigurationChanged(config1);
- mController.registerWindowContainerListener(mWpc, clientToken, mContainer, -1,
+ mController.registerWindowContainerListener(mWpc, clientToken, mContainer,
TYPE_APPLICATION_OVERLAY, options);
assertThat(clientToken.mConfiguration).isEqualTo(config1);
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java
index 495a80ba8ca5..d502cd1c93cb 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java
@@ -473,7 +473,7 @@ public class WindowManagerServiceTests extends WindowTestsBase {
mWm.attachWindowContextToWindowToken(mAppThread, new Binder(), windowToken.token);
verify(mWm.mWindowContextListenerController, never()).registerWindowContainerListener(
- any(), any(), any(), anyInt(), anyInt(), any());
+ any(), any(), any(), anyInt(), any());
}
@Test
@@ -490,7 +490,7 @@ public class WindowManagerServiceTests extends WindowTestsBase {
mWm.attachWindowContextToWindowToken(mAppThread, clientToken, windowToken.token);
final WindowProcessController wpc = mAtm.getProcessController(mAppThread);
verify(mWm.mWindowContextListenerController).registerWindowContainerListener(eq(wpc),
- eq(clientToken), eq(windowToken), anyInt(), eq(TYPE_INPUT_METHOD),
+ eq(clientToken), eq(windowToken), eq(TYPE_INPUT_METHOD),
eq(windowToken.mOptions));
}
@@ -519,7 +519,7 @@ public class WindowManagerServiceTests extends WindowTestsBase {
new InsetsSourceControl.Array(), new Rect(), new float[1]);
verify(mWm.mWindowContextListenerController, never()).registerWindowContainerListener(any(),
- any(), any(), anyInt(), anyInt(), any());
+ any(), any(), anyInt(), any());
}
@Test