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

Commit a7f99b5e authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
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: I1e42c6996e679c083cd3f0c9adfaef8ba22c4ee4
parent e72e61c3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -44101,6 +44101,7 @@ package android.view {
    method public android.os.Vibrator getVibrator();
    method public boolean[] hasKeys(int...);
    method public boolean hasMicrophone();
    method public boolean isEnabled();
    method public boolean isVirtual();
    method public boolean supportsSource(int);
    method public void writeToParcel(android.os.Parcel, int);
+1 −0
Original line number Diff line number Diff line
@@ -47696,6 +47696,7 @@ package android.view {
    method public android.os.Vibrator getVibrator();
    method public boolean[] hasKeys(int...);
    method public boolean hasMicrophone();
    method public boolean isEnabled();
    method public boolean isVirtual();
    method public boolean supportsSource(int);
    method public void writeToParcel(android.os.Parcel, int);
+3 −0
Original line number Diff line number Diff line
@@ -44465,6 +44465,8 @@ package android.view {
  public final class InputDevice implements android.os.Parcelable {
    method public int describeContents();
    method public void disable();
    method public void enable();
    method public int getControllerNumber();
    method public java.lang.String getDescriptor();
    method public static android.view.InputDevice getDevice(int);
@@ -44482,6 +44484,7 @@ package android.view {
    method public android.os.Vibrator getVibrator();
    method public boolean[] hasKeys(int...);
    method public boolean hasMicrophone();
    method public boolean isEnabled();
    method public boolean isVirtual();
    method public boolean supportsSource(int);
    method public void writeToParcel(android.os.Parcel, int);
+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);

+60 −4
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package android.hardware.input;

import com.android.internal.os.SomeArgs;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
@@ -31,10 +29,10 @@ import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.SystemClock;
import android.os.Vibrator;
import android.os.VibrationEffect;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.Vibrator;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.util.Log;
@@ -46,6 +44,8 @@ import android.view.PointerIcon;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;

import com.android.internal.os.SomeArgs;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
@@ -322,6 +322,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.
Loading