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

Commit 3d81a3d7 authored by Vaibhav Devmurari's avatar Vaibhav Devmurari Committed by Android (Google) Code Review
Browse files

Merge "Save country code information in InputDevice"

parents 46b0e5ff 053555a7
Loading
Loading
Loading
Loading
+23 −3
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.hardware.BatteryState;
import android.hardware.SensorManager;
import android.hardware.input.InputDeviceCountryCode;
import android.hardware.input.InputDeviceIdentifier;
import android.hardware.input.InputManager;
import android.hardware.lights.LightsManager;
@@ -72,6 +73,8 @@ public final class InputDevice implements Parcelable {
    private final int mSources;
    private final int mKeyboardType;
    private final KeyCharacterMap mKeyCharacterMap;
    @InputDeviceCountryCode
    private final int mCountryCode;
    private final boolean mHasVibrator;
    private final boolean mHasMicrophone;
    private final boolean mHasButtonUnderPad;
@@ -462,8 +465,9 @@ public final class InputDevice implements Parcelable {
    @VisibleForTesting
    public InputDevice(int id, int generation, int controllerNumber, String name, int vendorId,
            int productId, String descriptor, boolean isExternal, int sources, int keyboardType,
            KeyCharacterMap keyCharacterMap, boolean hasVibrator, boolean hasMicrophone,
            boolean hasButtonUnderPad, boolean hasSensor, boolean hasBattery) {
            KeyCharacterMap keyCharacterMap, @InputDeviceCountryCode int countryCode,
            boolean hasVibrator, boolean hasMicrophone, boolean hasButtonUnderPad,
            boolean hasSensor, boolean hasBattery) {
        mId = id;
        mGeneration = generation;
        mControllerNumber = controllerNumber;
@@ -475,6 +479,7 @@ public final class InputDevice implements Parcelable {
        mSources = sources;
        mKeyboardType = keyboardType;
        mKeyCharacterMap = keyCharacterMap;
        mCountryCode = countryCode;
        mHasVibrator = hasVibrator;
        mHasMicrophone = hasMicrophone;
        mHasButtonUnderPad = hasButtonUnderPad;
@@ -495,6 +500,7 @@ public final class InputDevice implements Parcelable {
        mIsExternal = in.readInt() != 0;
        mSources = in.readInt();
        mKeyboardType = in.readInt();
        mCountryCode = in.readInt();
        mHasVibrator = in.readInt() != 0;
        mHasMicrophone = in.readInt() != 0;
        mHasButtonUnderPad = in.readInt() != 0;
@@ -728,6 +734,16 @@ public final class InputDevice implements Parcelable {
        return mKeyCharacterMap;
    }

    /**
     * Gets Country code associated with the device
     *
     * @hide
     */
    @InputDeviceCountryCode
    public int getCountryCode() {
        return mCountryCode;
    }

    /**
     * Gets whether the device is capable of producing the list of keycodes.
     * @param keys The list of android keycodes to check for.
@@ -1147,6 +1163,7 @@ public final class InputDevice implements Parcelable {
        out.writeInt(mIsExternal ? 1 : 0);
        out.writeInt(mSources);
        out.writeInt(mKeyboardType);
        out.writeInt(mCountryCode);
        out.writeInt(mHasVibrator ? 1 : 0);
        out.writeInt(mHasMicrophone ? 1 : 0);
        out.writeInt(mHasButtonUnderPad ? 1 : 0);
@@ -1178,7 +1195,8 @@ public final class InputDevice implements Parcelable {
        description.append("Input Device ").append(mId).append(": ").append(mName).append("\n");
        description.append("  Descriptor: ").append(mDescriptor).append("\n");
        description.append("  Generation: ").append(mGeneration).append("\n");
        description.append("  Location: ").append(mIsExternal ? "external" : "built-in").append("\n");
        description.append("  Location: ").append(mIsExternal ? "external" : "built-in").append(
                "\n");

        description.append("  Keyboard Type: ");
        switch (mKeyboardType) {
@@ -1194,6 +1212,8 @@ public final class InputDevice implements Parcelable {
        }
        description.append("\n");

        description.append("  Country Code: ").append(mCountryCode).append("\n");

        description.append("  Has Vibrator: ").append(mHasVibrator).append("\n");

        description.append("  Has Sensor: ").append(mHasSensor).append("\n");
+4 −4
Original line number Diff line number Diff line
@@ -69,9 +69,9 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi
                                          static_cast<int32_t>(ident.product), descriptorObj.get(),
                                          deviceInfo.isExternal(), deviceInfo.getSources(),
                                          deviceInfo.getKeyboardType(), kcmObj.get(),
                                          deviceInfo.hasVibrator(), hasMic,
                                          deviceInfo.hasButtonUnderPad(), deviceInfo.hasSensor(),
                                          deviceInfo.hasBattery()));
                                          deviceInfo.getCountryCode(), deviceInfo.hasVibrator(),
                                          hasMic, deviceInfo.hasButtonUnderPad(),
                                          deviceInfo.hasSensor(), deviceInfo.hasBattery()));

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

    gInputDeviceClassInfo.addMotionRange = GetMethodIDOrDie(env, gInputDeviceClassInfo.clazz,
            "addMotionRange", "(IIFFFFF)V");
+2 −3
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static com.google.common.truth.Truth.assertThat;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -114,8 +113,8 @@ public class InputDeviceLightsManagerTest {
        return new InputDevice(id, 0 /* generation */, 0 /* controllerNumber */, "name",
                0 /* vendorId */, 0 /* productId */, "descriptor", true /* isExternal */,
                0 /* sources */, 0 /* keyboardType */, null /* keyCharacterMap */,
                false /* hasVibrator */, false /* hasMicrophone */, false /* hasButtonUnderpad */,
                false /* hasSensor */, false /* hasBattery */);
                InputDeviceCountryCode.INVALID, false /* hasVibrator */, false /* hasMicrophone */,
                false /* hasButtonUnderpad */, false /* hasSensor */, false /* hasBattery */);
    }

    private void mockLights(Light[] lights) throws Exception {
+2 −2
Original line number Diff line number Diff line
@@ -148,8 +148,8 @@ public class InputDeviceSensorManagerTest {
        InputDevice d = new InputDevice(id, 0 /* generation */, 0 /* controllerNumber */, "name",
                0 /* vendorId */, 0 /* productId */, "descriptor", true /* isExternal */,
                0 /* sources */, 0 /* keyboardType */, null /* keyCharacterMap */,
                false /* hasVibrator */, false /* hasMicrophone */, false /* hasButtonUnderpad */,
                true /* hasSensor */, false /* hasBattery */);
                InputDeviceCountryCode.INVALID, false /* hasVibrator */, false /* hasMicrophone */,
                false /* hasButtonUnderpad */, true /* hasSensor */, false /* hasBattery */);
        assertTrue(d.hasSensor());
        return d;
    }
+2 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.when;

import android.hardware.input.IInputDevicesChangedListener;
import android.hardware.input.IInputManager;
import android.hardware.input.InputDeviceCountryCode;
import android.hardware.input.InputManager;
import android.os.RemoteException;
import android.testing.TestableLooper;
@@ -84,7 +85,7 @@ class InputManagerMockHelper {
        final InputDevice device = new InputDevice(mDevices.size() /*id*/, 1 /*generation*/, 0,
                inv.getArgument(0) /*name*/, inv.getArgument(1) /*vendorId*/,
                inv.getArgument(2) /*productId*/, inv.getArgument(3) /*descriptor*/, true, 0, 0,
                null, false, false, false, false, false);
                null, InputDeviceCountryCode.INVALID, false, false, false, false, false);
        mDevices.add(device);
        try {
            mDevicesChangedListener.onInputDevicesChanged(
Loading