diff --git a/core/java/android/app/servertransaction/WindowTokenClientController.java b/core/java/android/app/servertransaction/WindowTokenClientController.java index 5d123a0438353..3060ab8d7cb21 100644 --- a/core/java/android/app/servertransaction/WindowTokenClientController.java +++ b/core/java/android/app/servertransaction/WindowTokenClientController.java @@ -21,6 +21,8 @@ import static android.view.WindowManagerGlobal.getWindowManagerService; import android.annotation.NonNull; import android.annotation.Nullable; +import android.app.ActivityThread; +import android.app.IApplicationThread; import android.content.Context; import android.content.res.Configuration; import android.os.Bundle; @@ -46,6 +48,8 @@ public class WindowTokenClientController { private static WindowTokenClientController sController; private final Object mLock = new Object(); + private final IApplicationThread mAppThread = ActivityThread.currentActivityThread() + .getApplicationThread(); /** Mapping from a client defined token to the {@link WindowTokenClient} it represents. */ @GuardedBy("mLock") @@ -84,8 +88,8 @@ public class WindowTokenClientController { @WindowType int type, int displayId, @Nullable Bundle options) { final Configuration configuration; try { - configuration = getWindowManagerService() - .attachWindowContextToDisplayArea(client, type, displayId, options); + configuration = getWindowManagerService().attachWindowContextToDisplayArea( + mAppThread, client, type, displayId, options); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -111,7 +115,7 @@ public class WindowTokenClientController { } final Configuration configuration; try { - configuration = wms.attachToDisplayContent(client, displayId); + configuration = wms.attachWindowContextToDisplayContent(mAppThread, client, displayId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -131,7 +135,8 @@ public class WindowTokenClientController { public void attachToWindowToken(@NonNull WindowTokenClient client, @NonNull IBinder windowToken) { try { - getWindowManagerService().attachWindowContextToWindowToken(client, windowToken); + getWindowManagerService().attachWindowContextToWindowToken( + mAppThread, client, windowToken); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -149,7 +154,7 @@ public class WindowTokenClientController { } } try { - getWindowManagerService().detachWindowContextFromWindowContainer(client); + getWindowManagerService().detachWindowContext(client); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl index bbd8255f4978c..c1474ebad2271 100644 --- a/core/java/android/view/IWindowManager.aidl +++ b/core/java/android/view/IWindowManager.aidl @@ -21,6 +21,7 @@ import com.android.internal.policy.IKeyguardDismissCallback; import com.android.internal.policy.IKeyguardLockedStateListener; import com.android.internal.policy.IShortcutService; +import android.app.IApplicationThread; import android.app.IAssistDataReceiver; import android.content.ComponentName; import android.content.res.CompatibilityInfo; @@ -850,6 +851,7 @@ interface IWindowManager * system server. {@link #attachWindowContextToWindowToken(IBinder, IBinder)} could be used in * this case to attach the WindowContext to the WindowToken.
* + * @param appThread the process that the window context is on. * @param clientToken {@link android.window.WindowContext#getWindowContextToken() * the WindowContext's token} * @param type Window type of the window context @@ -859,8 +861,8 @@ interface IWindowManager * @return the DisplayArea's {@link android.app.res.Configuration} if the WindowContext is * attached to the DisplayArea successfully. {@code null}, otherwise. */ - Configuration attachWindowContextToDisplayArea(IBinder clientToken, int type, int displayId, - in Bundle options); + @nullable Configuration attachWindowContextToDisplayArea(in IApplicationThread appThread, + IBinder clientToken, int type, int displayId, in @nullable Bundle options); /** * Attaches a {@link android.window.WindowContext} to a {@code WindowToken}. @@ -872,6 +874,7 @@ interface IWindowManager * {@link android.window.WindowTokenClient#attachContext(Context)} * * + * @param appThread the process that the window context is on. * @param clientToken {@link android.window.WindowContext#getWindowContextToken() * the WindowContext's token} * @param token the WindowToken to attach @@ -881,7 +884,8 @@ interface IWindowManager * * @see #attachWindowContextToDisplayArea(IBinder, int, int, Bundle) */ - void attachWindowContextToWindowToken(IBinder clientToken, IBinder token); + void attachWindowContextToWindowToken(in IApplicationThread appThread, IBinder clientToken, + IBinder token); /** * Attaches a {@code clientToken} to associate with DisplayContent. @@ -890,6 +894,7 @@ interface IWindowManager * {@link android.window.WindowTokenClient#attachContext(Context)} * * + * @param appThread the process that the window context is on. * @param clientToken {@link android.window.WindowContext#getWindowContextToken() * the WindowContext's token} * @param displayId The display associated with the window context @@ -898,7 +903,8 @@ interface IWindowManager * attached to the DisplayContent successfully. {@code null}, otherwise. * @throws android.view.WindowManager.InvalidDisplayException if the display ID is invalid */ - Configuration attachToDisplayContent(IBinder clientToken, int displayId); + @nullable Configuration attachWindowContextToDisplayContent(in IApplicationThread appThread, + IBinder clientToken, int displayId); /** * Detaches {@link android.window.WindowContext} from the window manager node it's currently @@ -906,7 +912,7 @@ interface IWindowManager * * @param clientToken the window context's token */ - void detachWindowContextFromWindowContainer(IBinder clientToken); + void detachWindowContext(IBinder clientToken); /** * Registers a listener, which is to be called whenever cross-window blur is enabled/disabled. diff --git a/core/java/android/window/WindowContextController.java b/core/java/android/window/WindowContextController.java index eb270e2fb2f0c..e78056e935683 100644 --- a/core/java/android/window/WindowContextController.java +++ b/core/java/android/window/WindowContextController.java @@ -135,7 +135,7 @@ public class WindowContextController { * {@link #attachToDisplayArea(int, int, Bundle)}. * * @see WindowProviderService#attachToWindowToken(IBinder)) - * @see IWindowManager#attachWindowContextToWindowToken(IBinder, IBinder) + * @see IWindowManager#attachWindowContextToWindowToken */ public void attachToWindowToken(IBinder windowToken) { if (mAttachedToDisplayArea != AttachStatus.STATUS_ATTACHED) { diff --git a/core/java/android/window/WindowTokenClient.java b/core/java/android/window/WindowTokenClient.java index 47d3df870216f..c7af25bf943fb 100644 --- a/core/java/android/window/WindowTokenClient.java +++ b/core/java/android/window/WindowTokenClient.java @@ -49,7 +49,7 @@ import java.lang.ref.WeakReference; * {@link Context#getWindowContextToken() the token of non-Activity UI Contexts}. * * @see WindowContext - * @see android.view.IWindowManager#attachWindowContextToDisplayArea(IBinder, int, int, Bundle) + * @see android.view.IWindowManager#attachWindowContextToDisplayArea * * @hide */ diff --git a/core/tests/coretests/src/android/app/servertransaction/WindowTokenClientControllerTest.java b/core/tests/coretests/src/android/app/servertransaction/WindowTokenClientControllerTest.java index 3b2fe583f6055..59a55bbb5c5a1 100644 --- a/core/tests/coretests/src/android/app/servertransaction/WindowTokenClientControllerTest.java +++ b/core/tests/coretests/src/android/app/servertransaction/WindowTokenClientControllerTest.java @@ -29,6 +29,7 @@ import static org.mockito.Mockito.verify; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; +import android.app.ActivityThread; import android.content.res.Configuration; import android.os.IBinder; import android.os.RemoteException; @@ -87,16 +88,17 @@ public class WindowTokenClientControllerTest { @Test public void testAttachToDisplayArea() throws RemoteException { doReturn(null).when(mWindowManagerService).attachWindowContextToDisplayArea( - any(), anyInt(), anyInt(), any()); + any(), any(), anyInt(), anyInt(), any()); assertFalse(mController.attachToDisplayArea(mWindowTokenClient, TYPE_APPLICATION_OVERLAY, DEFAULT_DISPLAY, null /* options */)); - verify(mWindowManagerService).attachWindowContextToDisplayArea(mWindowTokenClient, + verify(mWindowManagerService).attachWindowContextToDisplayArea( + ActivityThread.currentActivityThread().getApplicationThread(), mWindowTokenClient, TYPE_APPLICATION_OVERLAY, DEFAULT_DISPLAY, null /* options */); verify(mWindowTokenClient, never()).onConfigurationChanged(any(), anyInt(), anyBoolean()); doReturn(mConfiguration).when(mWindowManagerService).attachWindowContextToDisplayArea( - any(), anyInt(), anyInt(), any()); + any(), any(), anyInt(), anyInt(), any()); assertTrue(mController.attachToDisplayArea(mWindowTokenClient, TYPE_APPLICATION_OVERLAY, DEFAULT_DISPLAY, null /* options */)); @@ -108,36 +110,38 @@ public class WindowTokenClientControllerTest { public void testAttachToDisplayArea_detachIfNeeded() throws RemoteException { mController.detachIfNeeded(mWindowTokenClient); - verify(mWindowManagerService, never()).detachWindowContextFromWindowContainer(any()); + verify(mWindowManagerService, never()).detachWindowContext(any()); doReturn(null).when(mWindowManagerService).attachWindowContextToDisplayArea( - any(), anyInt(), anyInt(), any()); + any(), any(), anyInt(), anyInt(), any()); mController.attachToDisplayArea(mWindowTokenClient, TYPE_APPLICATION_OVERLAY, DEFAULT_DISPLAY, null /* options */); mController.detachIfNeeded(mWindowTokenClient); - verify(mWindowManagerService, never()).detachWindowContextFromWindowContainer(any()); + verify(mWindowManagerService, never()).detachWindowContext(any()); doReturn(mConfiguration).when(mWindowManagerService).attachWindowContextToDisplayArea( - any(), anyInt(), anyInt(), any()); + any(), any(), anyInt(), anyInt(), any()); mController.attachToDisplayArea(mWindowTokenClient, TYPE_APPLICATION_OVERLAY, DEFAULT_DISPLAY, null /* options */); mController.detachIfNeeded(mWindowTokenClient); - verify(mWindowManagerService).detachWindowContextFromWindowContainer(any()); + verify(mWindowManagerService).detachWindowContext(any()); } @Test public void testAttachToDisplayContent() throws RemoteException { - doReturn(null).when(mWindowManagerService).attachToDisplayContent( - any(), anyInt()); + doReturn(null).when(mWindowManagerService).attachWindowContextToDisplayContent( + any(), any(), anyInt()); assertFalse(mController.attachToDisplayContent(mWindowTokenClient, DEFAULT_DISPLAY)); - verify(mWindowManagerService).attachToDisplayContent(mWindowTokenClient, DEFAULT_DISPLAY); + verify(mWindowManagerService).attachWindowContextToDisplayContent( + ActivityThread.currentActivityThread().getApplicationThread(), mWindowTokenClient, + DEFAULT_DISPLAY); verify(mWindowTokenClient, never()).onConfigurationChanged(any(), anyInt(), anyBoolean()); - doReturn(mConfiguration).when(mWindowManagerService).attachToDisplayContent( - any(), anyInt()); + doReturn(mConfiguration).when(mWindowManagerService).attachWindowContextToDisplayContent( + any(), any(), anyInt()); assertTrue(mController.attachToDisplayContent(mWindowTokenClient, DEFAULT_DISPLAY)); verify(mWindowTokenClient).onConfigurationChanged(mConfiguration, DEFAULT_DISPLAY, @@ -148,28 +152,29 @@ public class WindowTokenClientControllerTest { public void testAttachToDisplayContent_detachIfNeeded() throws RemoteException { mController.detachIfNeeded(mWindowTokenClient); - verify(mWindowManagerService, never()).detachWindowContextFromWindowContainer(any()); + verify(mWindowManagerService, never()).detachWindowContext(any()); - doReturn(null).when(mWindowManagerService).attachToDisplayContent( - any(), anyInt()); + doReturn(null).when(mWindowManagerService).attachWindowContextToDisplayContent( + any(), any(), anyInt()); mController.attachToDisplayContent(mWindowTokenClient, DEFAULT_DISPLAY); mController.detachIfNeeded(mWindowTokenClient); - verify(mWindowManagerService, never()).detachWindowContextFromWindowContainer(any()); + verify(mWindowManagerService, never()).detachWindowContext(any()); - doReturn(mConfiguration).when(mWindowManagerService).attachToDisplayContent( - any(), anyInt()); + doReturn(mConfiguration).when(mWindowManagerService).attachWindowContextToDisplayContent( + any(), any(), anyInt()); mController.attachToDisplayContent(mWindowTokenClient, DEFAULT_DISPLAY); mController.detachIfNeeded(mWindowTokenClient); - verify(mWindowManagerService).detachWindowContextFromWindowContainer(any()); + verify(mWindowManagerService).detachWindowContext(any()); } @Test public void testAttachToWindowToken() throws RemoteException { mController.attachToWindowToken(mWindowTokenClient, mWindowToken); - verify(mWindowManagerService).attachWindowContextToWindowToken(mWindowTokenClient, + verify(mWindowManagerService).attachWindowContextToWindowToken( + ActivityThread.currentActivityThread().getApplicationThread(), mWindowTokenClient, mWindowToken); } @@ -177,12 +182,12 @@ public class WindowTokenClientControllerTest { public void testAttachToWindowToken_detachIfNeeded() throws RemoteException { mController.detachIfNeeded(mWindowTokenClient); - verify(mWindowManagerService, never()).detachWindowContextFromWindowContainer(any()); + verify(mWindowManagerService, never()).detachWindowContext(any()); mController.attachToWindowToken(mWindowTokenClient, mWindowToken); mController.detachIfNeeded(mWindowTokenClient); - verify(mWindowManagerService).detachWindowContextFromWindowContainer(any()); + verify(mWindowManagerService).detachWindowContext(any()); } @Test diff --git a/services/core/java/com/android/server/wm/WindowContextListenerController.java b/services/core/java/com/android/server/wm/WindowContextListenerController.java index 43dc9c8ff5d60..4025cbf777560 100644 --- a/services/core/java/com/android/server/wm/WindowContextListenerController.java +++ b/services/core/java/com/android/server/wm/WindowContextListenerController.java @@ -47,7 +47,7 @@ import java.util.Objects; * *