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

Commit ae1cc2a8 authored by Christine Franks's avatar Christine Franks Committed by Automerger Merge Worker
Browse files

Merge "Display IME locally on virtual displays" into tm-dev am: 76d22dca

parents 02e4ae49 76d22dca
Loading
Loading
Loading
Loading
+17 −3
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ import android.util.ArrayMap;
import android.util.Slog;
import android.util.Slog;
import android.view.Display;
import android.view.Display;
import android.view.InputDevice;
import android.view.InputDevice;
import android.view.WindowManager;


import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
@@ -83,22 +84,26 @@ class InputController {
    private final NativeWrapper mNativeWrapper;
    private final NativeWrapper mNativeWrapper;
    private final DisplayManagerInternal mDisplayManagerInternal;
    private final DisplayManagerInternal mDisplayManagerInternal;
    private final InputManagerInternal mInputManagerInternal;
    private final InputManagerInternal mInputManagerInternal;
    private final WindowManager mWindowManager;
    private final DeviceCreationThreadVerifier mThreadVerifier;
    private final DeviceCreationThreadVerifier mThreadVerifier;


    InputController(@NonNull Object lock, @NonNull Handler handler) {
    InputController(@NonNull Object lock, @NonNull Handler handler,
        this(lock, new NativeWrapper(), handler,
            @NonNull WindowManager windowManager) {
        this(lock, new NativeWrapper(), handler, windowManager,
                // Verify that virtual devices are not created on the handler thread.
                // Verify that virtual devices are not created on the handler thread.
                () -> !handler.getLooper().isCurrentThread());
                () -> !handler.getLooper().isCurrentThread());
    }
    }


    @VisibleForTesting
    @VisibleForTesting
    InputController(@NonNull Object lock, @NonNull NativeWrapper nativeWrapper,
    InputController(@NonNull Object lock, @NonNull NativeWrapper nativeWrapper,
            @NonNull Handler handler, @NonNull DeviceCreationThreadVerifier threadVerifier) {
            @NonNull Handler handler, @NonNull WindowManager windowManager,
            @NonNull DeviceCreationThreadVerifier threadVerifier) {
        mLock = lock;
        mLock = lock;
        mHandler = handler;
        mHandler = handler;
        mNativeWrapper = nativeWrapper;
        mNativeWrapper = nativeWrapper;
        mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
        mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
        mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
        mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
        mWindowManager = windowManager;
        mThreadVerifier = threadVerifier;
        mThreadVerifier = threadVerifier;
    }
    }


@@ -209,6 +214,15 @@ class InputController {
        mInputManagerInternal.setDisplayEligibilityForPointerCapture(displayId, isEligible);
        mInputManagerInternal.setDisplayEligibilityForPointerCapture(displayId, isEligible);
    }
    }


    void setLocalIme(int displayId) {
        // WM throws a SecurityException if the display is untrusted.
        if ((mDisplayManagerInternal.getDisplayInfo(displayId).flags & Display.FLAG_TRUSTED)
                == Display.FLAG_TRUSTED) {
            mWindowManager.setDisplayImePolicy(displayId,
                    WindowManager.DISPLAY_IME_POLICY_LOCAL);
        }
    }

    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private void updateActivePointerDisplayIdLocked() {
    private void updateActivePointerDisplayIdLocked() {
        InputDeviceDescriptor mostRecentlyCreatedMouse = null;
        InputDeviceDescriptor mostRecentlyCreatedMouse = null;
+5 −1
Original line number Original line Diff line number Diff line
@@ -62,6 +62,7 @@ import android.util.ArraySet;
import android.util.Slog;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseArray;
import android.view.Display;
import android.view.Display;
import android.view.WindowManager;
import android.widget.Toast;
import android.widget.Toast;
import android.window.DisplayWindowPolicyController;
import android.window.DisplayWindowPolicyController;


@@ -167,7 +168,9 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
        mParams = params;
        mParams = params;
        if (inputController == null) {
        if (inputController == null) {
            mInputController = new InputController(
            mInputController = new InputController(
                    mVirtualDeviceLock, context.getMainThreadHandler());
                    mVirtualDeviceLock,
                    context.getMainThreadHandler(),
                    context.getSystemService(WindowManager.class));
        } else {
        } else {
            mInputController = inputController;
            mInputController = inputController;
        }
        }
@@ -537,6 +540,7 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
            mInputController.setPointerAcceleration(1f, displayId);
            mInputController.setPointerAcceleration(1f, displayId);
            mInputController.setDisplayEligibilityForPointerCapture(/* isEligible= */ false,
            mInputController.setDisplayEligibilityForPointerCapture(/* isEligible= */ false,
                    displayId);
                    displayId);
            mInputController.setLocalIme(displayId);


            // Since we're being called in the middle of the display being created, we post a
            // Since we're being called in the middle of the display being created, we post a
            // task to grab the wakelock instead of doing it synchronously here, to avoid
            // task to grab the wakelock instead of doing it synchronously here, to avoid
+6 −1
Original line number Original line Diff line number Diff line
@@ -34,6 +34,9 @@ import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.testing.TestableLooper;
import android.view.Display;
import android.view.Display;
import android.view.DisplayInfo;
import android.view.DisplayInfo;
import android.view.WindowManager;

import androidx.test.InstrumentationRegistry;


import com.android.server.LocalServices;
import com.android.server.LocalServices;


@@ -79,7 +82,9 @@ public class InputControllerTest {
        // Allow virtual devices to be created on the looper thread for testing.
        // Allow virtual devices to be created on the looper thread for testing.
        final InputController.DeviceCreationThreadVerifier threadVerifier = () -> true;
        final InputController.DeviceCreationThreadVerifier threadVerifier = () -> true;
        mInputController = new InputController(new Object(), mNativeWrapperMock,
        mInputController = new InputController(new Object(), mNativeWrapperMock,
                new Handler(TestableLooper.get(this).getLooper()), threadVerifier);
                new Handler(TestableLooper.get(this).getLooper()),
                InstrumentationRegistry.getTargetContext().getSystemService(WindowManager.class),
                threadVerifier);
    }
    }


    @Test
    @Test
+3 −1
Original line number Original line Diff line number Diff line
@@ -77,6 +77,7 @@ import android.testing.TestableLooper;
import android.util.ArraySet;
import android.util.ArraySet;
import android.view.DisplayInfo;
import android.view.DisplayInfo;
import android.view.KeyEvent;
import android.view.KeyEvent;
import android.view.WindowManager;


import androidx.test.InstrumentationRegistry;
import androidx.test.InstrumentationRegistry;


@@ -208,7 +209,8 @@ public class VirtualDeviceManagerServiceTest {
        // Allow virtual devices to be created on the looper thread for testing.
        // Allow virtual devices to be created on the looper thread for testing.
        final InputController.DeviceCreationThreadVerifier threadVerifier = () -> true;
        final InputController.DeviceCreationThreadVerifier threadVerifier = () -> true;
        mInputController = new InputController(new Object(), mNativeWrapperMock,
        mInputController = new InputController(new Object(), mNativeWrapperMock,
                new Handler(TestableLooper.get(this).getLooper()), threadVerifier);
                new Handler(TestableLooper.get(this).getLooper()),
                mContext.getSystemService(WindowManager.class), threadVerifier);


        mAssociationInfo = new AssociationInfo(1, 0, null,
        mAssociationInfo = new AssociationInfo(1, 0, null,
                MacAddress.BROADCAST_ADDRESS, "", null, true, false, 0, 0);
                MacAddress.BROADCAST_ADDRESS, "", null, true, false, 0, 0);