双屏异触实现

平台:RK3399

Android 10.0

Android系统对于USB,蓝牙接口的触摸设备默认判断为外接设备,外接设备默认操控的是副屏,在双屏异显情况下就会发现只能点击到副屏,判断条件如下:

frameworks/native/services/inputflinger/EventHub.cpp
status_t EventHub::openDeviceLocked(const char* devicePath) {
...
 // Determine whether the device is external or internal.判断是否为外接设备,如果是加入外接设备标识
    if (isExternalDeviceLocked(device)) {
        device->classes |= INPUT_DEVICE_CLASS_EXTERNAL;
    }
    ...
    }

一种改法是不管是判断条件是否通过都不加入这个标识,即注释掉 device->classes |= INPUT_DEVICE_CLASS_EXTERNAL ,这种方法可以保证主屏一直能正常触控,但是副屏如果再接触摸就无法正常触控

查看判断方法:

frameworks/native/services/inputflinger/EventHub.cpp

bool EventHub::isExternalDeviceLocked(Device* device) {
    if (device->configuration) {
        bool value;
        if (device->configuration->tryGetProperty(String8("device.internal"), value)) {
            return !value;
        }
    }
    return device->identifier.bus == BUS_USB || device->identifier.bus == BUS_BLUETOOTH; 设备标识符未USB或蓝牙设备返回true 即外接设备
}

此处发现除了设备标识符还可以通过device.internal属性来控制是否为外接设备,查询资料知道,这个属性是输入设备配置文件(.idc)文件里面的属性。

1.idc是什么?
idc 是Input Device Configuration的缩写,输入设备配置文件(.idc 文件)包含特定设备的配置属性,这些属性会影响输入设备的行为。
输入设备配置文件通常并非标准外围设备(例如 HID 键盘和鼠标)所必需的,因为默认的系统行为通常可确保它们即插即用。另一方面,内置的嵌入式设备(尤其是触摸屏)几乎总是需要输入设备配置文件来指定其行为。

2.idc位置按顺序查阅以下路径。
/odm/usr/idc/Vendor_XXXX_Product_XXXX_Version_XXXX.idc
/vendor/usr/idc/Vendor_XXXX_Product_XXXX_Version_XXXX.idc
/system/usr/idc/Vendor_XXXX_Product_XXXX_Version_XXXX.idc
/data/system/devices/idc/Vendor_XXXX_Product_XXXX_Version_XXXX.idc
/odm/usr/idc/Vendor_XXXX_Product_XXXX.idc
/vendor/usr/idc/Vendor_XXXX_Product_XXXX.idc
/system/usr/idc/Vendor_XXXX_Product_XXXX.idc
/data/system/devices/idc/Vendor_XXXX_Product_XXXX.idc
/odm/usr/idc/device-name.idc
/vendor/usr/idc/device-name.idc
/system/usr/idc/device-name.idc
/data/system/devices/idc/device-name.idc
当构建包含设备名称的文件路径时,设备名称中除“0-9”、“a-z”、“A-Z”、“-”或“_”之外的所有字符将替换为“_”。

3.idc文件常用配置属性
#=0 外部设备 =1内部设备
device.internal = 0
#定义:keyboard.layout = <name>
#指定与输入设备关联的键布局文件的名称,不包括.kl扩展名。 如果找不到此文件,输入系统将使用默认键布局。
keyboard.layout = qwerty
#定义:keyboard.characterMap = <name>
#指定与输入设备关联的键字符映射文件的名称,不包括.kcm扩展名。 如果找不到此文件,输入系统将使用默认的键字符映射。
#在查找期间,名称中的空格将转换为下划线。
keyboard.characterMap = qwerty
#定义:keyboard.orientationAware = 0 |1
#指定键盘是否应对显示方向更改做出反应。
#如果值为1,则在关联的显示方向改变时旋转方向键盘键。
#如果值为0,则键盘不受显示方向更改的影响。
#默认值为0。
#方向感知用于支持方向键盘键的旋转,例如Motorola Droid上的旋转。 例如,当设备从其自然方向顺时针旋转90度时,
#KEYCODE_DPAD_UP被重新映射以产生KEYCODE_DPAD_RIGHT,因为当设备保持在该方向时,“向上”键最终指向“右”。
keyboard.orientationAware = 1
#定义:keyboard.builtIn = 0 |1
#指定键盘是否为内置(物理连接)键盘。
#如果设备名称以-keypad结尾,则默认值为1,否则为0。
#内置键盘的设备ID始终为0.其他非内置键盘将分配唯一的非零设备ID。
#对于内置键盘使用id为0对于保持与KeyCharacterMap.BUILT_IN_KEYBOARD字段的兼容性非常重要,该字段指定内置键盘的id并且值为0.
#此字段已在API中弃用但较旧 应用程序可能仍在使用它。
#无论此属性的设置如何,特殊功能键盘(其键字符映射指定SPECIAL_FUNCTION的类型)将永远不会注册为内置键盘。
#这是因为根据定义,特殊功能键盘不打算用于通用键入。
keyboard.builtIn = 1

4.idc代码流程
Eventhub在打开设备时会读取设备的idc文件

->Eventhub.openDeviceLocked->loadConfigurationLocked

void EventHub::loadConfigurationLocked(Device* device) {
device->configurationFile = getInputDeviceConfigurationFilePathByDeviceIdentifier(
device->identifier, INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION);
if (device->configurationFile.isEmpty()) {
ALOGD("No input device configuration file found for device '%s'.",
device->identifier.name.string());
} else {
status_t status = PropertyMap::load(device->configurationFile,
&device->configuration);
if (status) {
ALOGE("Error loading input device configuration file for device '%s'. "
"Using default configuration.",
device->identifier.name.string());
}
}
}

综上可知,我们需要添加idc文件来控制触摸屏的属性

添加方法:

1.获取输入设备的vendorID和productId:dumpsys input 即可列出系统目前所有的输入设备的信息,得到以下信息,

********** Touch

Classes: 0x00000014

Path: /dev/input/event3

Enabled: true

Descriptor: 7836b2735840690ea51fda95d6119dfc7eed5e9c

Location: usb-fe3e0000.usb-1/input0

ControllerNumber: 0

UniqueId:

Identifier: bus=0x0003, vendor=0x1fd2, product=0x0201, version=0x0111

KeyLayoutFile:

KeyCharacterMapFile:

ConfigurationFile: /vendor/usr/idc/Vendor_1fd2_Product_0201.idc

HaveKeyboardLayoutOverlay: false

VideoDevice: <none>

2.编写idc文件

Vendor_1fd2_Product_0201.idc

# Filename:Vendor_1fd2_Product_0201.idc
# My TouchScreen Device configuration file.
#add by zhouxw 


touch.deviceType = touchScreen
device.internal = 1
touch.orientationAware = 1

keyboard.layout = Vendor_1fd2_Product_0201
keyboard.orientationAware = 1

cursor.mode = navigation
cursor.orientationAware = 1

3.mk文件中将idc文件拷贝到/vendor/usr/idc/ 目录

PRODUCT_COPY_FILES += \
    $(LOCAL_PATH)/keylayout/Vendor_1fd2_Product_0201.idc:vendor/usr/idc/Vendor_1fd2_Product_0201.idc

编译系统固件升级,触摸屏即能正常操控主屏了

第二部分:

在进行屏幕旋转以后,触摸的坐标并没有跟着屏幕旋转导致触摸的position存在问题。

修改如下:

diff --git a/frameworks/native/services/inputflinger/InputReader.cpp b/frameworks/native/services/inputflinger/InputReader.cpp
index c541d3e..dcc1ac7 100755
--- a/frameworks/native/services/inputflinger/InputReader.cpp
+++ b/frameworks/native/services/inputflinger/InputReader.cpp
@@ -3837,6 +3837,27 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
     bool viewportChanged = mViewport != *newViewport;
     if (viewportChanged) {
         mViewport = *newViewport;
+               char buffer_orientation[PROP_VALUE_MAX];   
+        memset(buffer_orientation, 0, sizeof(buffer_orientation));
+        property_get("persist.sys.panel.flip", buffer_orientation, "270");    
+        int cmpRet = atoi(buffer_orientation);        
+        ALOGE("persist.sys.hwrotation~~~~~~~~~~~~~~~~~~~~~~~~~ = %d",cmpRet);    
+        if (cmpRet == 0)    
+        {        
+            mViewport.orientation = DISPLAY_ORIENTATION_0;
+        }  
+        else if(cmpRet == 90)    
+        {
+            mViewport.orientation = DISPLAY_ORIENTATION_90;  
+        }
+        else if(cmpRet == 180)
+        {
+            mViewport.orientation = DISPLAY_ORIENTATION_180;  
+        }
+        else if(cmpRet == 270)
+        {
+            mViewport.orientation = DISPLAY_ORIENTATION_270;  
+        }
 
         if (mDeviceMode == DEVICE_MODE_DIRECT || mDeviceMode == DEVICE_MODE_POINTER) {
             // Convert rotated viewport to natural surface coordinates.

添加系统属性,然后根据系统属性对触摸方向进行旋转。

猜你喜欢

转载自blog.csdn.net/weixin_40774418/article/details/122466562
今日推荐