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

Commit 00f72644 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Determine whether an input device supports USI using IDC files

It is necessary to identify a USI device so that additional logic can be
applied to the battery information that is exposed via USI.

Bug: 243005009
Test: manual, check dumpsys output
Change-Id: I2bd655c55fcec733b362d044aac06d5508a86ce4
parent 202617a4
Loading
Loading
Loading
Loading
+24 −2
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ public final class InputDevice implements Parcelable {
    private final boolean mHasButtonUnderPad;
    private final boolean mHasSensor;
    private final boolean mHasBattery;
    private final boolean mSupportsUsi;
    private final ArrayList<MotionRange> mMotionRanges = new ArrayList<MotionRange>();

    @GuardedBy("mMotionRanges")
@@ -462,7 +463,7 @@ public final class InputDevice implements Parcelable {
            int productId, String descriptor, boolean isExternal, int sources, int keyboardType,
            KeyCharacterMap keyCharacterMap, @InputDeviceCountryCode int countryCode,
            boolean hasVibrator, boolean hasMicrophone, boolean hasButtonUnderPad,
            boolean hasSensor, boolean hasBattery) {
            boolean hasSensor, boolean hasBattery, boolean supportsUsi) {
        mId = id;
        mGeneration = generation;
        mControllerNumber = controllerNumber;
@@ -481,6 +482,7 @@ public final class InputDevice implements Parcelable {
        mHasSensor = hasSensor;
        mHasBattery = hasBattery;
        mIdentifier = new InputDeviceIdentifier(descriptor, vendorId, productId);
        mSupportsUsi = supportsUsi;
    }

    private InputDevice(Parcel in) {
@@ -501,6 +503,7 @@ public final class InputDevice implements Parcelable {
        mHasButtonUnderPad = in.readInt() != 0;
        mHasSensor = in.readInt() != 0;
        mHasBattery = in.readInt() != 0;
        mSupportsUsi = in.readInt() != 0;
        mIdentifier = new InputDeviceIdentifier(mDescriptor, mVendorId, mProductId);

        int numRanges = in.readInt();
@@ -538,6 +541,7 @@ public final class InputDevice implements Parcelable {
        private boolean mHasBattery = false;
        @InputDeviceCountryCode
        private int mCountryCode = InputDeviceCountryCode.INVALID;
        private boolean mSupportsUsi = false;

        /** @see InputDevice#getId()  */
        public Builder setId(int id) {
@@ -641,12 +645,18 @@ public final class InputDevice implements Parcelable {
            return this;
        }

        /** @see InputDevice#supportsUsi() ()  */
        public Builder setSupportsUsi(boolean supportsUsi) {
            mSupportsUsi = supportsUsi;
            return this;
        }

        /** Build {@link InputDevice}. */
        public InputDevice build() {
            return new InputDevice(mId, mGeneration, mControllerNumber, mName, mVendorId,
                    mProductId, mDescriptor, mIsExternal, mSources, mKeyboardType, mKeyCharacterMap,
                    mCountryCode, mHasVibrator, mHasMicrophone, mHasButtonUnderPad, mHasSensor,
                    mHasBattery);
                    mHasBattery, mSupportsUsi);
        }
    }

@@ -1178,6 +1188,15 @@ public final class InputDevice implements Parcelable {
        return mHasBattery;
    }

    /**
     * Reports whether the device supports the Universal Stylus Initiative (USI) protocol for
     * styluses.
     * @hide
     */
    public boolean supportsUsi() {
        return mSupportsUsi;
    }

    /**
     * Provides information about the range of values for a particular {@link MotionEvent} axis.
     *
@@ -1308,6 +1327,7 @@ public final class InputDevice implements Parcelable {
        out.writeInt(mHasButtonUnderPad ? 1 : 0);
        out.writeInt(mHasSensor ? 1 : 0);
        out.writeInt(mHasBattery ? 1 : 0);
        out.writeInt(mSupportsUsi ? 1 : 0);

        final int numRanges = mMotionRanges.size();
        out.writeInt(numRanges);
@@ -1361,6 +1381,8 @@ public final class InputDevice implements Parcelable {

        description.append("  Has mic: ").append(mHasMicrophone).append("\n");

        description.append("  Supports USI: ").append(mSupportsUsi).append("\n");

        description.append("  Sources: 0x").append(Integer.toHexString(mSources)).append(" (");
        appendSourceDescriptionIfApplicable(description, SOURCE_KEYBOARD, "keyboard");
        appendSourceDescriptionIfApplicable(description, SOURCE_DPAD, "dpad");
+4 −6
Original line number Diff line number Diff line
@@ -57,9 +57,6 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi

    const InputDeviceIdentifier& ident = deviceInfo.getIdentifier();

    // Not sure why, but JNI is complaining when I pass this through directly.
    jboolean hasMic = deviceInfo.hasMic() ? JNI_TRUE : JNI_FALSE;

    ScopedLocalRef<jobject>
            inputDeviceObj(env,
                           env->NewObject(gInputDeviceClassInfo.clazz, gInputDeviceClassInfo.ctor,
@@ -70,8 +67,9 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi
                                          deviceInfo.isExternal(), deviceInfo.getSources(),
                                          deviceInfo.getKeyboardType(), kcmObj.get(),
                                          deviceInfo.getCountryCode(), deviceInfo.hasVibrator(),
                                          hasMic, deviceInfo.hasButtonUnderPad(),
                                          deviceInfo.hasSensor(), deviceInfo.hasBattery()));
                                          deviceInfo.hasMic(), deviceInfo.hasButtonUnderPad(),
                                          deviceInfo.hasSensor(), deviceInfo.hasBattery(),
                                          deviceInfo.supportsUsi()));

    const std::vector<InputDeviceInfo::MotionRange>& ranges = deviceInfo.getMotionRanges();
    for (const InputDeviceInfo::MotionRange& range: ranges) {
@@ -94,7 +92,7 @@ int register_android_view_InputDevice(JNIEnv* env)
    gInputDeviceClassInfo.ctor =
            GetMethodIDOrDie(env, gInputDeviceClassInfo.clazz, "<init>",
                             "(IIILjava/lang/String;IILjava/lang/"
                             "String;ZIILandroid/view/KeyCharacterMap;IZZZZZ)V");
                             "String;ZIILandroid/view/KeyCharacterMap;IZZZZZZ)V");

    gInputDeviceClassInfo.addMotionRange = GetMethodIDOrDie(env, gInputDeviceClassInfo.clazz,
            "addMotionRange", "(IIFFFFF)V");
+1 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ public class InputDeviceTest {
                .setHasSensor(true)
                .setHasBattery(true)
                .setCountryCode(InputDeviceCountryCode.INTERNATIONAL)
                .setSupportsUsi(true)
                .build();

        Parcel parcel = Parcel.obtain();