在雙屏異顯產(chǎn)品中,有時(shí)候主副屏都帶有觸摸屏祟峦,并且要求主副屏觸摸各自操作互不干擾芒填。
Android 現(xiàn)有框架中已經(jīng)支持副輸入設(shè)備的邏輯,只是默認(rèn)將所有的外部熱插拔設(shè)備統(tǒng)一指定為副輸入設(shè)備帐要,這種邏輯我們?nèi)绻且粋€(gè) i2c 加上一個(gè) usb 觸摸那么默認(rèn)就可以支持,usb觸摸就是副tp弥奸。
但榨惠,有時(shí)候我們是雙 i2c 或雙 usb 的搭配,我們就需要改造現(xiàn)有邏輯,方案如下:
通過(guò)屬性配置副屏 tp 的: 設(shè)備名赠橙、pid&vid耽装、usb端口,在 EventHub 中獲取輸入設(shè)備的設(shè)備名期揪、pid&vid掉奄、usb端口與屬性值進(jìn)行對(duì)比,如果是配置中的設(shè)備就將其標(biāo)記為副輸入設(shè)備凤薛。
源碼
實(shí)現(xiàn)
diff --git a/frameworks/native/services/inputflinger/EventHub.cpp b/frameworks/native/services/inputflinger/EventHub.cpp
old mode 100644
new mode 100755
index 2bcc5c7..1542a7b
--- a/frameworks/native/services/inputflinger/EventHub.cpp
+++ b/frameworks/native/services/inputflinger/EventHub.cpp
@@ -64,6 +64,11 @@
#define INDENT2 " "
#define INDENT3 " "
+// for multi touch panel
+#define DEVICE_MATCH_METHOD_MAX 10
+#define USB_LOCATION_MATCH_START 13 //"usb-ff540000."
+#define USB_LOCATION_MATCH_LEN 7 //"usb-1.1"
+
namespace android {
static const char *WAKE_LOCK_ID = "KeyEvents";
@@ -1184,17 +1189,17 @@ status_t EventHub::openDeviceLocked(const char *devicePath) {
int32_t deviceId = mNextDeviceId++;
Device* device = new Device(fd, deviceId, String8(devicePath), identifier);
- ALOGV("add device %d: %s\n", deviceId, devicePath);
- ALOGV(" bus: %04x\n"
+ ALOGI("add device %d: %s\n", deviceId, devicePath);
+ ALOGI(" bus: %04x\n"
" vendor %04x\n"
" product %04x\n"
" version %04x\n",
identifier.bus, identifier.vendor, identifier.product, identifier.version);
- ALOGV(" name: \"%s\"\n", identifier.name.string());
- ALOGV(" location: \"%s\"\n", identifier.location.string());
- ALOGV(" unique id: \"%s\"\n", identifier.uniqueId.string());
- ALOGV(" descriptor: \"%s\"\n", identifier.descriptor.string());
- ALOGV(" driver: v%d.%d.%d\n",
+ ALOGI(" name: \"%s\"\n", identifier.name.string());
+ ALOGI(" location: \"%s\"\n", identifier.location.string());
+ ALOGI(" unique id: \"%s\"\n", identifier.uniqueId.string());
+ ALOGI(" descriptor: \"%s\"\n", identifier.descriptor.string());
+ ALOGI(" driver: v%d.%d.%d\n",
driverVersion >> 16, (driverVersion >> 8) & 0xff, driverVersion & 0xff);
// Load the configuration file for the device.
@@ -1357,10 +1362,35 @@ status_t EventHub::openDeviceLocked(const char *devicePath) {
}
// Determine whether the device is external or internal.
- if (isExternalDeviceLocked(device)) {
+ if((device->classes & 0x04) == INPUT_DEVICE_CLASS_TOUCH) {
+ int count = 0;
+ char flag[DEVICE_MATCH_METHOD_MAX][PROPERTY_VALUE_MAX];
+ char value[PROPERTY_VALUE_MAX] = {0};
+
+ property_get("ro.input.external", value, "");
+
+ if (isExternalDeviceLocked(device)) {
+ sprintf(flag[count++], "%04x:%04x", identifier.vendor, identifier.product);
+ if (identifier.location.length() >= USB_LOCATION_MATCH_START+USB_LOCATION_MATCH_LEN) {
+ strncpy(flag[count++], identifier.location.string()+USB_LOCATION_MATCH_START, USB_LOCATION_MATCH_LEN);
+ }
+ } else {
+ sprintf(flag[count++], "%s", device->identifier.name.string());
+ }
+
+ for (int i=0; i<count; i++) {
+ ALOGI("openDeviceLocked:%d, value=%s flag=%s\n", __LINE__, value, flag[i]);
+ if (strstr(value, flag[i])) {
+ device->classes |= INPUT_DEVICE_CLASS_EXTERNAL;
+ ALOGI("openDeviceLocked:%d, name:\"%s\" id:%d device_class:%x vid:%04x pid:%04x is external input device\n",
+ __LINE__, device->identifier.name.string(), device->id, device->classes, identifier.vendor, identifier.product);
+ break;
+ }
+ }
+ } else {
device->classes |= INPUT_DEVICE_CLASS_EXTERNAL;
}
-
+
if (device->classes & (INPUT_DEVICE_CLASS_JOYSTICK | INPUT_DEVICE_CLASS_DPAD)
&& device->classes & INPUT_DEVICE_CLASS_GAMEPAD) {
device->controllerNumber = getNextControllerNumberLocked(device);
屬性配置格式說(shuō)明
屬性名:ro.input.external
屬性值:
設(shè)備類型 | 格式 | 例如 |
---|---|---|
usb | vid:pid | 222a:0001 |
usb | usb端口 | usb-1.4 |
i2c | 設(shè)備名 | Hanvon electromagnetic pen |
也可以同時(shí)配置多個(gè)設(shè)備姓建,各屬性值之間用“,”隔開(kāi)。
例如:
ro.input.external=222a:0001,Hanvon electromagnetic pen,usb-1.4
以上屬性配置“vid=222a,pid=0001”的 usb tp 和設(shè)備名為“Hanvon electromagnetic pen”的 i2c tp 以及 usb 端口為 1.4 的 tp 為副屏 tp缤苫,其它未配置的都默認(rèn)為主屏 tp速兔。