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

Commit db69719a authored by Linnan Li's avatar Linnan Li Committed by Prabir Pradhan
Browse files

Add enabled state to InputDevice and remove isInputDeviceEnabled(1/n)



Since we have added a field for the enabled state to InputDeviceInfo, we
have also added the same status field to InputDevice.java. This way, we
won't need to call the isInputDeviceEnabled method in InputManager again
to send a request to InputManagerService to check if the device is
enabled. At this point, we can directly remove the isInputDeviceEnabled
method in InputManager, which is used as a hidden API, since it is no
longer in use.

Bug: 336420877
Test: build & atest InputTests

Change-Id: I9274f0bc66b64b81f9375049cc7bf9535c27d06f
Signed-off-by: default avatarLinnan Li <lilinnan@xiaomi.corp-partner.google.com>
parent c791ff7e
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ interface IInputManager {
    int[] getInputDeviceIds();

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

+0 −13
Original line number Diff line number Diff line
@@ -332,19 +332,6 @@ public final class InputManager {
        return mGlobal.getInputDeviceIds();
    }

    /**
     * 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>
+0 −12
Original line number Diff line number Diff line
@@ -410,18 +410,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)
     */
+17 −3
Original line number Diff line number Diff line
@@ -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) {
+3 −2
Original line number Diff line number Diff line
@@ -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");
Loading