diff options
10 files changed, 25 insertions, 54 deletions
diff --git a/core/java/android/hardware/input/IInputManager.aidl b/core/java/android/hardware/input/IInputManager.aidl index 45b316aa5498..40d4fb6df4bc 100644 --- a/core/java/android/hardware/input/IInputManager.aidl +++ b/core/java/android/hardware/input/IInputManager.aidl @@ -55,7 +55,6 @@ interface IInputManager { int[] getInputDeviceIds(); // Enable/disable input device. - boolean isInputDeviceEnabled(int deviceId); void enableInputDevice(int deviceId); void disableInputDevice(int deviceId); diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java index 7527aa7197e9..9eabc8d53bb3 100644 --- a/core/java/android/hardware/input/InputManager.java +++ b/core/java/android/hardware/input/InputManager.java @@ -333,19 +333,6 @@ public final class InputManager { } /** - * Returns true if an input device is enabled. Should return true for most - * situations. Some system apps may disable an input device, for - * example to prevent unwanted touch events. - * - * @param id The input device Id. - * - * @hide - */ - public boolean isInputDeviceEnabled(int id) { - return mGlobal.isInputDeviceEnabled(id); - } - - /** * Enables an InputDevice. * <p> * Requires {@link android.Manifest.permission#DISABLE_INPUT_DEVICE}. diff --git a/core/java/android/hardware/input/InputManagerGlobal.java b/core/java/android/hardware/input/InputManagerGlobal.java index fcd5a3ed06c0..7b471806cfc1 100644 --- a/core/java/android/hardware/input/InputManagerGlobal.java +++ b/core/java/android/hardware/input/InputManagerGlobal.java @@ -411,18 +411,6 @@ public final class InputManagerGlobal { } /** - * @see InputManager#isInputDeviceEnabled(int) - */ - public boolean isInputDeviceEnabled(int id) { - try { - return mIm.isInputDeviceEnabled(id); - } catch (RemoteException ex) { - Log.w(TAG, "Could not check enabled status of input device with id = " + id); - throw ex.rethrowFromSystemServer(); - } - } - - /** * @see InputManager#enableInputDevice(int) */ public void enableInputDevice(int id) { diff --git a/core/java/android/view/InputDevice.java b/core/java/android/view/InputDevice.java index d22d2a52c8cc..a6543ce1969e 100644 --- a/core/java/android/view/InputDevice.java +++ b/core/java/android/view/InputDevice.java @@ -92,6 +92,7 @@ public final class InputDevice implements Parcelable { private final boolean mHasBattery; private final HostUsiVersion mHostUsiVersion; private final int mAssociatedDisplayId; + private final boolean mEnabled; private final ArrayList<MotionRange> mMotionRanges = new ArrayList<MotionRange>(); private final ViewBehavior mViewBehavior = new ViewBehavior(this); @@ -479,7 +480,7 @@ public final class InputDevice implements Parcelable { int keyboardType, KeyCharacterMap keyCharacterMap, @Nullable String keyboardLanguageTag, @Nullable String keyboardLayoutType, boolean hasVibrator, boolean hasMicrophone, boolean hasButtonUnderPad, boolean hasSensor, boolean hasBattery, int usiVersionMajor, - int usiVersionMinor, int associatedDisplayId) { + int usiVersionMinor, int associatedDisplayId, boolean enabled) { mId = id; mGeneration = generation; mControllerNumber = controllerNumber; @@ -510,6 +511,7 @@ public final class InputDevice implements Parcelable { mIdentifier = new InputDeviceIdentifier(descriptor, vendorId, productId); mHostUsiVersion = new HostUsiVersion(usiVersionMajor, usiVersionMinor); mAssociatedDisplayId = associatedDisplayId; + mEnabled = enabled; } private InputDevice(Parcel in) { @@ -534,6 +536,7 @@ public final class InputDevice implements Parcelable { mHasBattery = in.readInt() != 0; mHostUsiVersion = HostUsiVersion.CREATOR.createFromParcel(in); mAssociatedDisplayId = in.readInt(); + mEnabled = in.readInt() != 0; mIdentifier = new InputDeviceIdentifier(mDescriptor, mVendorId, mProductId); int numRanges = in.readInt(); @@ -578,6 +581,8 @@ public final class InputDevice implements Parcelable { private int mUsiVersionMajor = -1; private int mUsiVersionMinor = -1; private int mAssociatedDisplayId = Display.INVALID_DISPLAY; + // The default is true, the same as the native default state. + private boolean mEnabled = true; private List<MotionRange> mMotionRanges = new ArrayList<>(); private boolean mShouldSmoothScroll; @@ -708,6 +713,12 @@ public final class InputDevice implements Parcelable { return this; } + /** @see InputDevice#isEnabled() */ + public Builder setEnabled(boolean enabled) { + mEnabled = enabled; + return this; + } + /** @see InputDevice#getMotionRanges() */ public Builder addMotionRange(int axis, int source, float min, float max, float flat, float fuzz, float resolution) { @@ -749,7 +760,8 @@ public final class InputDevice implements Parcelable { mHasBattery, mUsiVersionMajor, mUsiVersionMinor, - mAssociatedDisplayId); + mAssociatedDisplayId, + mEnabled); final int numRanges = mMotionRanges.size(); for (int i = 0; i < numRanges; i++) { @@ -1298,7 +1310,7 @@ public final class InputDevice implements Parcelable { * @return Whether the input device is enabled. */ public boolean isEnabled() { - return InputManagerGlobal.getInstance().isInputDeviceEnabled(mId); + return mEnabled; } /** @@ -1588,6 +1600,7 @@ public final class InputDevice implements Parcelable { out.writeInt(mHasBattery ? 1 : 0); mHostUsiVersion.writeToParcel(out, flags); out.writeInt(mAssociatedDisplayId); + out.writeInt(mEnabled ? 1 : 0); int numRanges = mMotionRanges.size(); numRanges = numRanges > MAX_RANGES ? MAX_RANGES : numRanges; @@ -1619,6 +1632,7 @@ public final class InputDevice implements Parcelable { description.append(" Generation: ").append(mGeneration).append("\n"); description.append(" Location: ").append(mIsExternal ? "external" : "built-in").append( "\n"); + description.append(" Enabled: ").append(isEnabled()).append("\n"); description.append(" Keyboard Type: "); switch (mKeyboardType) { diff --git a/core/jni/android_view_InputDevice.cpp b/core/jni/android_view_InputDevice.cpp index aae0da9006a2..f5992d906323 100644 --- a/core/jni/android_view_InputDevice.cpp +++ b/core/jni/android_view_InputDevice.cpp @@ -90,7 +90,8 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi deviceInfo.hasButtonUnderPad(), deviceInfo.hasSensor(), deviceInfo.hasBattery(), usiVersion.majorVersion, usiVersion.minorVersion, - deviceInfo.getAssociatedDisplayId())); + deviceInfo.getAssociatedDisplayId(), + deviceInfo.isEnabled())); // Note: We do not populate the Bluetooth address into the InputDevice object to avoid leaking // it to apps that do not have the Bluetooth permission. @@ -126,7 +127,7 @@ int register_android_view_InputDevice(JNIEnv* env) gInputDeviceClassInfo.ctor = GetMethodIDOrDie(env, gInputDeviceClassInfo.clazz, "<init>", "(IIILjava/lang/String;IIILjava/lang/" "String;ZIILandroid/view/KeyCharacterMap;Ljava/" - "lang/String;Ljava/lang/String;ZZZZZIII)V"); + "lang/String;Ljava/lang/String;ZZZZZIIIZ)V"); gInputDeviceClassInfo.addMotionRange = GetMethodIDOrDie(env, gInputDeviceClassInfo.clazz, "addMotionRange", "(IIFFFFF)V"); diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index 8e85b81d9bd2..48cccd5b5b39 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -960,12 +960,6 @@ public class InputManagerService extends IInputManager.Stub // Binder call @Override - public boolean isInputDeviceEnabled(int deviceId) { - return mNative.isInputDeviceEnabled(deviceId); - } - - // Binder call - @Override public void enableInputDevice(int deviceId) { if (!checkCallingPermission(android.Manifest.permission.DISABLE_INPUT_DEVICE, "enableInputDevice()")) { diff --git a/services/core/java/com/android/server/input/NativeInputManagerService.java b/services/core/java/com/android/server/input/NativeInputManagerService.java index 0208a325a1d5..a9d40bb54f96 100644 --- a/services/core/java/com/android/server/input/NativeInputManagerService.java +++ b/services/core/java/com/android/server/input/NativeInputManagerService.java @@ -183,8 +183,6 @@ interface NativeInputManagerService { void monitor(); - boolean isInputDeviceEnabled(int deviceId); - void enableInputDevice(int deviceId); void disableInputDevice(int deviceId); @@ -463,9 +461,6 @@ interface NativeInputManagerService { public native void monitor(); @Override - public native boolean isInputDeviceEnabled(int deviceId); - - @Override public native void enableInputDevice(int deviceId); @Override diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index f8dda6073b0b..28b844d35a1e 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -4372,11 +4372,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. private static IntArray getStylusInputDeviceIds(InputManager im) { IntArray stylusIds = new IntArray(); for (int id : im.getInputDeviceIds()) { - if (!im.isInputDeviceEnabled(id)) { - continue; - } InputDevice device = im.getInputDevice(id); - if (device != null && isStylusDevice(device)) { + if (device != null && device.isEnabled() && isStylusDevice(device)) { stylusIds.add(id); } } diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index 97f1e19e35b1..4c746a97bafa 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -2451,12 +2451,6 @@ static void nativeMonitor(JNIEnv* env, jobject nativeImplObj) { im->getInputManager()->getDispatcher().monitor(); } -static jboolean nativeIsInputDeviceEnabled(JNIEnv* env, jobject nativeImplObj, jint deviceId) { - NativeInputManager* im = getNativeInputManager(env, nativeImplObj); - - return im->getInputManager()->getReader().isInputDeviceEnabled(deviceId); -} - static void nativeEnableInputDevice(JNIEnv* env, jobject nativeImplObj, jint deviceId) { NativeInputManager* im = getNativeInputManager(env, nativeImplObj); @@ -2798,7 +2792,6 @@ static const JNINativeMethod gInputManagerMethods[] = { {"sysfsNodeChanged", "(Ljava/lang/String;)V", (void*)nativeSysfsNodeChanged}, {"dump", "()Ljava/lang/String;", (void*)nativeDump}, {"monitor", "()V", (void*)nativeMonitor}, - {"isInputDeviceEnabled", "(I)Z", (void*)nativeIsInputDeviceEnabled}, {"enableInputDevice", "(I)V", (void*)nativeEnableInputDevice}, {"disableInputDevice", "(I)V", (void*)nativeDisableInputDevice}, {"reloadPointerIcons", "()V", (void*)nativeReloadPointerIcons}, diff --git a/tests/Input/src/com/android/test/input/InputDeviceTest.java b/tests/Input/src/com/android/test/input/InputDeviceTest.java index 5f1bc8748db8..87a0de63120e 100644 --- a/tests/Input/src/com/android/test/input/InputDeviceTest.java +++ b/tests/Input/src/com/android/test/input/InputDeviceTest.java @@ -61,6 +61,7 @@ public class InputDeviceTest { assertEquals(device.getMotionRanges().size(), outDevice.getMotionRanges().size()); assertEquals(device.getHostUsiVersion(), outDevice.getHostUsiVersion()); assertEquals(device.getAssociatedDisplayId(), outDevice.getAssociatedDisplayId()); + assertEquals(device.isEnabled(), outDevice.isEnabled()); KeyCharacterMap keyCharacterMap = device.getKeyCharacterMap(); KeyCharacterMap outKeyCharacterMap = outDevice.getKeyCharacterMap(); @@ -100,7 +101,9 @@ public class InputDeviceTest { .setKeyboardLanguageTag("en-US") .setKeyboardLayoutType("qwerty") .setUsiVersion(new HostUsiVersion(2, 0)) - .setShouldSmoothScroll(true); + .setShouldSmoothScroll(true) + .setAssociatedDisplayId(Display.DEFAULT_DISPLAY) + .setEnabled(false); for (int i = 0; i < 30; i++) { deviceBuilder.addMotionRange( |