Merge "Display IME locally on virtual displays" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
76d22dca3d
@@ -37,6 +37,7 @@ import android.util.ArrayMap;
|
||||
import android.util.Slog;
|
||||
import android.view.Display;
|
||||
import android.view.InputDevice;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
@@ -83,22 +84,26 @@ class InputController {
|
||||
private final NativeWrapper mNativeWrapper;
|
||||
private final DisplayManagerInternal mDisplayManagerInternal;
|
||||
private final InputManagerInternal mInputManagerInternal;
|
||||
private final WindowManager mWindowManager;
|
||||
private final DeviceCreationThreadVerifier mThreadVerifier;
|
||||
|
||||
InputController(@NonNull Object lock, @NonNull Handler handler) {
|
||||
this(lock, new NativeWrapper(), handler,
|
||||
InputController(@NonNull Object lock, @NonNull Handler handler,
|
||||
@NonNull WindowManager windowManager) {
|
||||
this(lock, new NativeWrapper(), handler, windowManager,
|
||||
// Verify that virtual devices are not created on the handler thread.
|
||||
() -> !handler.getLooper().isCurrentThread());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
InputController(@NonNull Object lock, @NonNull NativeWrapper nativeWrapper,
|
||||
@NonNull Handler handler, @NonNull DeviceCreationThreadVerifier threadVerifier) {
|
||||
@NonNull Handler handler, @NonNull WindowManager windowManager,
|
||||
@NonNull DeviceCreationThreadVerifier threadVerifier) {
|
||||
mLock = lock;
|
||||
mHandler = handler;
|
||||
mNativeWrapper = nativeWrapper;
|
||||
mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
|
||||
mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
|
||||
mWindowManager = windowManager;
|
||||
mThreadVerifier = threadVerifier;
|
||||
}
|
||||
|
||||
@@ -209,6 +214,15 @@ class InputController {
|
||||
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")
|
||||
private void updateActivePointerDisplayIdLocked() {
|
||||
InputDeviceDescriptor mostRecentlyCreatedMouse = null;
|
||||
|
||||
@@ -62,6 +62,7 @@ import android.util.ArraySet;
|
||||
import android.util.Slog;
|
||||
import android.util.SparseArray;
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
import android.window.DisplayWindowPolicyController;
|
||||
|
||||
@@ -167,7 +168,9 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
|
||||
mParams = params;
|
||||
if (inputController == null) {
|
||||
mInputController = new InputController(
|
||||
mVirtualDeviceLock, context.getMainThreadHandler());
|
||||
mVirtualDeviceLock,
|
||||
context.getMainThreadHandler(),
|
||||
context.getSystemService(WindowManager.class));
|
||||
} else {
|
||||
mInputController = inputController;
|
||||
}
|
||||
@@ -537,6 +540,7 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
|
||||
mInputController.setPointerAcceleration(1f, displayId);
|
||||
mInputController.setDisplayEligibilityForPointerCapture(/* isEligible= */ false,
|
||||
displayId);
|
||||
mInputController.setLocalIme(displayId);
|
||||
|
||||
// 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
|
||||
|
||||
@@ -34,6 +34,9 @@ import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
import android.view.Display;
|
||||
import android.view.DisplayInfo;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
|
||||
import com.android.server.LocalServices;
|
||||
|
||||
@@ -79,7 +82,9 @@ public class InputControllerTest {
|
||||
// Allow virtual devices to be created on the looper thread for testing.
|
||||
final InputController.DeviceCreationThreadVerifier threadVerifier = () -> true;
|
||||
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
|
||||
|
||||
@@ -77,6 +77,7 @@ import android.testing.TestableLooper;
|
||||
import android.util.ArraySet;
|
||||
import android.view.DisplayInfo;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
|
||||
@@ -208,7 +209,8 @@ public class VirtualDeviceManagerServiceTest {
|
||||
// Allow virtual devices to be created on the looper thread for testing.
|
||||
final InputController.DeviceCreationThreadVerifier threadVerifier = () -> true;
|
||||
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,
|
||||
MacAddress.BROADCAST_ADDRESS, "", null, true, false, 0, 0);
|
||||
|
||||
Reference in New Issue
Block a user