Save country code information in InputDevice
Country code information is passed by a HID device over sysfs. We can read that information and save it in InputDevice which will be later used for auto-detecting Layout for PK. More information in DD: go/pk_auto_layout_detection Test: atest InputDeviceTest Bug: 242715614 Change-Id: I97bde1f2338ad601a7e2636600038e6ca124e3ff
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -33,6 +33,7 @@ import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.hardware.input.IInputDevicesChangedListener;
|
||||
import android.hardware.input.IInputManager;
|
||||
import android.hardware.input.InputDeviceCountryCode;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.os.CombinedVibration;
|
||||
import android.os.Handler;
|
||||
@@ -328,7 +329,8 @@ public class InputDeviceDelegateTest {
|
||||
|
||||
private InputDevice createInputDevice(int id, boolean hasVibrator) {
|
||||
return new InputDevice(id, 0, 0, "name", 0, 0, "description", false, 0, 0,
|
||||
null, hasVibrator, false, false, false /* hasSensor */, false /* hasBattery */);
|
||||
null, InputDeviceCountryCode.INVALID, hasVibrator, false, false,
|
||||
false /* hasSensor */, false /* hasBattery */);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.pm.PackageManagerInternal;
|
||||
import android.hardware.input.IInputManager;
|
||||
import android.hardware.input.InputDeviceCountryCode;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.hardware.vibrator.IVibrator;
|
||||
import android.hardware.vibrator.IVibratorManager;
|
||||
@@ -1814,7 +1815,8 @@ public class VibratorManagerServiceTest {
|
||||
|
||||
private InputDevice createInputDeviceWithVibrator(int id) {
|
||||
return new InputDevice(id, 0, 0, "name", 0, 0, "description", false, 0, 0,
|
||||
null, /* hasVibrator= */ true, false, false, false, false);
|
||||
null, InputDeviceCountryCode.INVALID, /* hasVibrator= */ true, false, false, false,
|
||||
false);
|
||||
}
|
||||
|
||||
private static <T> void addLocalServiceMock(Class<T> clazz, T mock) {
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package android.view;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.hardware.input.InputDeviceCountryCode;
|
||||
import android.os.Parcel;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
@@ -55,11 +55,12 @@ public class InputDeviceTest {
|
||||
assertEquals(device.isExternal(), outDevice.isExternal());
|
||||
assertEquals(device.getSources(), outDevice.getSources());
|
||||
assertEquals(device.getKeyboardType(), outDevice.getKeyboardType());
|
||||
assertEquals(device.getCountryCode(), outDevice.getCountryCode());
|
||||
assertEquals(device.getMotionRanges().size(), outDevice.getMotionRanges().size());
|
||||
|
||||
KeyCharacterMap keyCharacterMap = device.getKeyCharacterMap();
|
||||
KeyCharacterMap outKeyCharacterMap = outDevice.getKeyCharacterMap();
|
||||
assertTrue("keyCharacterMap not equal", keyCharacterMap.equals(outKeyCharacterMap));
|
||||
assertEquals("keyCharacterMap not equal", keyCharacterMap, outKeyCharacterMap);
|
||||
|
||||
for (int j = 0; j < device.getMotionRanges().size(); j++) {
|
||||
assertMotionRangeEquals(device.getMotionRanges().get(j),
|
||||
@@ -70,10 +71,11 @@ public class InputDeviceTest {
|
||||
private void assertInputDeviceParcelUnparcel(KeyCharacterMap keyCharacterMap) {
|
||||
final InputDevice device =
|
||||
new InputDevice(DEVICE_ID, 0 /* generation */, 0 /* controllerNumber */, "name",
|
||||
0 /* vendorId */, 0 /* productId */, "descriptor", true /* isExternal */,
|
||||
0 /* sources */, 0 /* keyboardType */, keyCharacterMap,
|
||||
false /* hasVibrator */, false /* hasMicrophone */, false /* hasButtonUnderpad */,
|
||||
true /* hasSensor */, false /* hasBattery */);
|
||||
0 /* vendorId */, 0 /* productId */, "descriptor", true /* isExternal */,
|
||||
0 /* sources */, 0 /* keyboardType */, keyCharacterMap,
|
||||
InputDeviceCountryCode.INTERNATIONAL, false /* hasVibrator */,
|
||||
false /* hasMicrophone */, false /* hasButtonUnderpad */,
|
||||
true /* hasSensor */, false /* hasBattery */);
|
||||
|
||||
Parcel parcel = Parcel.obtain();
|
||||
device.writeToParcel(parcel, 0);
|
||||
|
||||
Reference in New Issue
Block a user