识别和匹配idc配置文件

来源:互联网 发布:php文章管理系统 初学 编辑:程序博客网 时间:2024/05/19 19:34

转自http://blog.csdn.net/coldsnow33/article/details/16808161

  1. void EventHub::loadConfigurationLocked(Device* device) {  
  2.     device->configurationFile = getInputDeviceConfigurationFilePathByDeviceIdentifier(  
  3.             device->identifier, INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION);//get IDC文件  
  4.     if (device->configurationFile.isEmpty()) {  
  5.         ALOGD("No input device configuration file found for device '%s'.",  
  6.                 device->identifier.name.string());  
  7.     } else {  
  8.         status_t status = PropertyMap::load(device->configurationFile,  
  9.                 &device->configuration);//找到配置文件,解析出来保存到device->configuration中  
  10.         if (status) {//解析出错,  
  11.             ALOGE("Error loading input device configuration file for device '%s'.  "  
  12.                     "Using default configuration.",  
  13.                     device->identifier.name.string());  
  14.         }  
  15.     }  
  16. }  
[cpp] view plain copy print?
  1. String8 getInputDeviceConfigurationFilePathByDeviceIdentifier(  
  2.         const InputDeviceIdentifier& deviceIdentifier,  
  3.         InputDeviceConfigurationFileType type) {  
  4.     if (deviceIdentifier.vendor !=0 && deviceIdentifier.product != 0) {  
  5.         if (deviceIdentifier.version != 0) {  
  6.             // Try vendor product version.  
  7.             String8 versionPath(getInputDeviceConfigurationFilePathByName(  
  8.                     String8::format("Vendor_%04x_Product_%04x_Version_%04x",  
  9.                             deviceIdentifier.vendor, deviceIdentifier.product,  
  10.                             deviceIdentifier.version),  
  11.                     type));  
  12.             if (!versionPath.isEmpty()) {  
  13.                 return versionPath;  
  14.             }  
  15.         }  
  16.   
  17.         // Try vendor product.  
  18.         String8 productPath(getInputDeviceConfigurationFilePathByName(  
  19.                 String8::format("Vendor_%04x_Product_%04x",  
  20.                         deviceIdentifier.vendor, deviceIdentifier.product),  
  21.                 type));  
  22.         if (!productPath.isEmpty()) {  
  23.             return productPath;  
  24.         }  
  25.     }  
  26.   
  27.     // Try device name.  
  28.     return getInputDeviceConfigurationFilePathByName(deviceIdentifier.name, type);  
  29. }  
[cpp] view plain copy print?
  1. String8 getInputDeviceConfigurationFilePathByName(  
  2.         const String8& name, InputDeviceConfigurationFileType type) {  
  3.     // Search system repository.  
  4.     String8 path;  
  5.     path.setTo(getenv("ANDROID_ROOT"));  
  6.     path.append("/usr/");  
  7.     appendInputDeviceConfigurationFileRelativePath(path, name, type);  
  8. #if DEBUG_PROBE  
  9.     ALOGD("Probing for system provided input device configuration file: path='%s'", path.string());  
  10. #endif  
  11.     if (!access(path.string(), R_OK)) {  
  12. #if DEBUG_PROBE  
  13.         ALOGD("Found");  
  14. #endif  
  15.         return path;  
  16.     }  
  17.   
  18.     // Search user repository.  
  19.     // TODO Should only look here if not in safe mode.  
  20.     path.setTo(getenv("ANDROID_DATA"));  
  21.     path.append("/system/devices/");  
  22.     appendInputDeviceConfigurationFileRelativePath(path, name, type);  
  23. #if DEBUG_PROBE  
  24.     ALOGD("Probing for system user input device configuration file: path='%s'", path.string());  
  25. #endif  
  26.     if (!access(path.string(), R_OK)) {  
  27. #if DEBUG_PROBE  
  28.         ALOGD("Found");  
  29. #endif  
  30.         return path;  
  31.     }  
  32.   
  33.     // Not found.  
  34. #if DEBUG_PROBE  
  35.     ALOGD("Probe failed to find input device configuration file: name='%s', type=%d",  
  36.             name.string(), type);  
  37. #endif  
  38.     return String8();  
  39. }  

这里出现了两个环境变量:
echo $ANDROID_ROOT /system
echo $ANDROID_DATA /data
识别和匹配配置文件的顺序为:
/system/usr/idc/Vendor_XXXX_Product_XXXX_Version_XXXX.idc
/data/system/devices/idc/Vendor_XXXX_Product_XXXX_Version_XXXX.idc
/system/usr/idc/Vendor_XXXX_Product_XXXX.idc
/data/system/devices/idc/Vendor_XXXX_Product_XXXX.idc
/system/usr/idc/DEVICE_NAME.idc
/data/system/devices/idc/DEVICE_NAME.idc
需要注意的是文件名中的数字需要小写。例如
input_dev­>id.vendor = 0xDEAD;
input_dev­>id.product = 0xBEEF;
input_dev­>id.version = 0x0102;
对应的配置文件名应该是Vendor_dead_Product_beef_Version_0102.idc或者Vendor_dead_Product_beef.idc。
获取配置文件名的时候,如果发现文件名中含有不是ascii(<=0x7f)的字符;或者是ascii,但不是数字,不是希腊字母,也不是“-”和“_”,比如说空格、tab等,就要转成字符'_'。所以dumpsys input看到的ConfigurationFile: /system/usr/idc/Vendor_dead_Product_beef.idc,也许和我们定义的有点不一样,那就是定义了非法字符,被转了。只要找到ConfigurationFile就可以了。


0 0