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

Commit 04ef4dca authored by shreerag's avatar shreerag
Browse files

Adding feature: input device disable/enable.

This functionality will only be available for signed system applications.
A disable call will cause a file descriptor to the input device
driver to be closed, which in turn may cause the input device
to switch into a low-power mode.
An enable call will reopen the input device.

Bug: 30143923
Test: developed a custom apk with signature permission that
calls disable/enable on touchscreen device. Verified that
touchscreen stops working when disable is called and starts
working again when enable is called. Verified that the file
handle to the driver is closed and reopened. Verified that
the notification onInputDeviceChanged is received in the app.
CTS test - android.view.cts.InputDeviceEnabledTest

Change-Id: Ia352deb548b73559f821afd586893393d39a0696
parent 9405262a
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -34,6 +34,11 @@ interface IInputManager {
    InputDevice getInputDevice(int deviceId);
    int[] getInputDeviceIds();

    // Enable/disable input device.
    boolean isInputDeviceEnabled(int deviceId);
    void enableInputDevice(int deviceId);
    void disableInputDevice(int deviceId);

    // Reports whether the hardware supports the given keys; returns true if successful
    boolean hasKeys(int deviceId, int sourceMask, in int[] keyCodes, out boolean[] keyExists);

+56 −0
Original line number Diff line number Diff line
@@ -318,6 +318,62 @@ 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) {
        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();
        }
    }

    /**
     * Enables an InputDevice.
     * <p>
     * Requires {@link android.Manifest.permissions.DISABLE_INPUT_DEVICE}.
     * </p>
     *
     * @param id The input device Id.
     *
     * @hide
     */
    public void enableInputDevice(int id) {
        try {
            mIm.enableInputDevice(id);
        } catch (RemoteException ex) {
            Log.w(TAG, "Could not enable input device with id = " + id);
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * Disables an InputDevice.
     * <p>
     * Requires {@link android.Manifest.permissions.DISABLE_INPUT_DEVICE}.
     * </p>
     *
     * @param id The input device Id.
     *
     * @hide
     */
    public void disableInputDevice(int id) {
        try {
            mIm.disableInputDevice(id);
        } catch (RemoteException ex) {
            Log.w(TAG, "Could not disable input device with id = " + id);
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * Registers an input device listener to receive notifications about when
     * input devices are added, removed or changed.
+34 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.view;

import android.annotation.RequiresPermission;
import android.annotation.TestApi;
import android.content.Context;
import android.hardware.input.InputDeviceIdentifier;
import android.hardware.input.InputManager;
@@ -767,6 +769,38 @@ public final class InputDevice implements Parcelable {
        }
    }

    /**
     * Returns true if input device is enabled.
     * @return Whether the input device is enabled.
     *
     * @hide
     */
    public boolean isEnabled() {
        return InputManager.getInstance().isInputDeviceEnabled(mId);
    }

    /**
     * Enables the input device.
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.DISABLE_INPUT_DEVICE)
    @TestApi
    public void enable() {
        InputManager.getInstance().enableInputDevice(mId);
    }

    /**
     * Disables the input device.
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.DISABLE_INPUT_DEVICE)
    @TestApi
    public void disable() {
        InputManager.getInstance().disableInputDevice(mId);
    }

    /**
     * Reports whether the device has a built-in microphone.
     * @return Whether the device has a built-in microphone.
+7 −0
Original line number Diff line number Diff line
@@ -2734,6 +2734,13 @@
    <permission android:name="android.permission.ACCESS_INPUT_FLINGER"
        android:protectionLevel="signature" />

    <!-- Allows an application to disable/enable input devices.
         Could be used to prevent unwanted touch events
         on a touchscreen, for example during swimming or rain.
         @hide -->
    <permission android:name="android.permission.DISABLE_INPUT_DEVICE"
                android:protectionLevel="signature" />

    <!-- Allows an application to configure and connect to Wifi displays
         @hide -->
    <permission android:name="android.permission.CONFIGURE_WIFI_DISPLAY"
+29 −0
Original line number Diff line number Diff line
@@ -232,6 +232,9 @@ public class InputManagerService extends IInputManager.Stub
    private static native void nativeReloadDeviceAliases(long ptr);
    private static native String nativeDump(long ptr);
    private static native void nativeMonitor(long ptr);
    private static native boolean nativeIsInputDeviceEnabled(long ptr, int deviceId);
    private static native void nativeEnableInputDevice(long ptr, int deviceId);
    private static native void nativeDisableInputDevice(long ptr, int deviceId);
    private static native void nativeSetPointerIconType(long ptr, int iconId);
    private static native void nativeReloadPointerIcons(long ptr);
    private static native void nativeSetCustomPointerIcon(long ptr, PointerIcon icon);
@@ -650,6 +653,32 @@ public class InputManagerService extends IInputManager.Stub
        return null;
    }

    // Binder call
    @Override
    public boolean isInputDeviceEnabled(int deviceId) {
        return nativeIsInputDeviceEnabled(mPtr, deviceId);
    }

    // Binder call
    @Override
    public void enableInputDevice(int deviceId) {
        if (!checkCallingPermission(android.Manifest.permission.DISABLE_INPUT_DEVICE,
                "enableInputDevice()")) {
            throw new SecurityException("Requires DISABLE_INPUT_DEVICE permission");
        }
        nativeEnableInputDevice(mPtr, deviceId);
    }

    // Binder call
    @Override
    public void disableInputDevice(int deviceId) {
        if (!checkCallingPermission(android.Manifest.permission.DISABLE_INPUT_DEVICE,
                "disableInputDevice()")) {
            throw new SecurityException("Requires DISABLE_INPUT_DEVICE permission");
        }
        nativeDisableInputDevice(mPtr, deviceId);
    }

    /**
     * Gets the ids of all input devices in the system.
     * @return The input device ids.
Loading