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

Commit 9c8e645d authored by Chris Li's avatar Chris Li
Browse files

Migrate WindowContext#onConfigurationChanged to ClientTransaction (4/n)

Update WMS#attachWindowContextTo* function signature:
1. Be consistent on the naming.
2. Take an IApplicationThread as part of the migration.

Bug: 290876897
Test: Renaming. Pass existing tests.
Change-Id: I23a41d699ec9bca0f42e92c0a5f39409d062e9c4
parent 4367c8ed
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -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();
        }
+11 −5
Original line number Diff line number Diff line
@@ -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.</p>
     *
     * @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)}
     * </p>
     *
     * @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)}
     * </p>
     *
     * @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.
+1 −1
Original line number Diff line number Diff line
@@ -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) {
+1 −1
Original line number Diff line number Diff line
@@ -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
 */
+28 −23
Original line number Diff line number Diff line
@@ -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
Loading