和菜鸟一起学android4.0.3源码之touchscreen配置+调试记录

   
http://blog.csdn.net/eastmoon502136/article/details/7697434

记得应该是上上周了,终于毕业了,离开了学校,就得面对现实的社会,以前学校实验室里,老师给了钥匙,那电脑随便用,那元器件随便玩,什么51单片机 啊,PIC单片机啊,FPGA啊,arm11啊什么的。想着做什么就直接万用版+电烙铁什么的一起搞定。调试,写程序,焊板子都是自己一手操办啊,多么自 由啊。到了公司,可不依你,对于上市公司来说,管理什么的总归还是有些规范化的。
        对于嵌入式,虽然早有所耳闻,大三也玩过arm7,编了几个基于GUI的贪吃蛇啊,黑白棋啊,连连看啊什么的。自己也买来arm11,烧写linux系 统,搭建环境,最终也成功完成了hello world驱动模块。待以后有时间再好好整理整理。废话不多说了,既然是anrdroid下的touchscreen的配置,那就专心点,不东扯西扯了。
     都说android4.0.3的touchscreen有了很大的变化,菜鸟也不知道这么庞大的代码,各个功能模块式干嘛的。只能找找资料,瞎折腾了。公 司的任务,触摸屏得上了,android的东西,只用鼠标可不好玩啊。开始调试SPI模式的ads7846的电阻屏,板子没有SPI接口,于是就用 GPIO模拟SPI的方式来实现SPI的功能,在此要说明下,这个嵌入式的板子就是和51,PIC的板子用起来不一样啊,什么工作队列,什么中断下半部分 工作,什么总线啊,I2C啊,SPI啊,I2S啊,USB啊,都这么纠结,顿时觉得学得好少啊,自己又有点懒,什么都想学,至于什么也没学好。调试好驱动 后,总算是完成了一半的工作,接着,是否要直接上android去跑呢?android里什么机制都不知道额,虽然一开始android中实现鼠标的时候 小研究过android下的input那个框架,不过只是模模糊糊的概念,根本就没有弄清楚。看来得下点功夫啊,要不然怎么混啊。又偏题了,额,正题,正 题。。
         直接上android了,突然发现出现了一个小圈圈。向鼠标一样的。貌似触摸屏变成了鼠标了。觉得太怪了,怎么可以这样?肯定那里有问题的,找了好久的资 料,终于找到了,原来是android4.0.3,他的touchscreen是需要配置文件的。只要直接创建一个“设备名.idc”的文件,直接放到 /system/usr/idc/目录下,就可以了,设备名是驱动中定义的,在android中的Eventhub中也是可以加打印在logcat中看出 来的。

  1. # Basic Parameters  
  2.   touch.deviceType = touchScreen  
  3.   touch.orientationAware = 1  
  4.   
  5.   # Size  
  6.   touch.size.calibration = diameter  
  7.   touch.size.scale = 10  
  8.   touch.size.bias = 0  
  9.   touch.size.isSummed = 0  
  10.   
  11.   # Pressure  
  12.   # Driver reports signal strength as pressure.  
  13.   #  
  14.   # A normal thumb touch typically registers about 200 signal strength  
  15.   # units although we don't expect these values to be accurate.  
  16.   touch.pressure.calibration = amplitude  
  17.   touch.pressure.scale = 0.005  
  18.   
  19.   # Orientation  
  20.   touch.orientation.calibration = none  


        但是就知道了这个配置文件,具体那里实现的呢?怎么配置进去的呢?怎么看着你个是touch.deviceType = touchScreen这个决定的。不多说来代码
frameworks/base/services/input/InputReader.cpp

  1. void TouchInputMapper::configureParameters() {  
  2.     // Use the pointer presentation mode for devices that do not support distinct  
  3.     // multitouch.  The spot-based presentation relies on being able to accurately  
  4.     // locate two or more fingers on the touch pad.  
  5.     mParameters.gestureMode = getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_SEMI_MT)  
  6.             ? Parameters::GESTURE_MODE_POINTER : Parameters::GESTURE_MODE_SPOTS;  
  7.   
  8.     String8 gestureModeString;  
  9.     if (getDevice()->getConfiguration().tryGetProperty(String8("touch.gestureMode"),  
  10.             gestureModeString)) {  
  11.         if (gestureModeString == "pointer") {  
  12.             mParameters.gestureMode = Parameters::GESTURE_MODE_POINTER;  
  13.         } else if (gestureModeString == "spots") {  
  14.             mParameters.gestureMode = Parameters::GESTURE_MODE_SPOTS;  
  15.         } else if (gestureModeString != "default") {  
  16.             LOGW("Invalid value for touch.gestureMode: '%s'", gestureModeString.string());  
  17.         }  
  18.     }  
  19.   
  20.     if (getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_DIRECT)) {  
  21.         // The device is a touch screen.  
  22.         mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_SCREEN;  
  23.     } else if (getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_POINTER)) {  
  24.         // The device is a pointing device like a track pad.  
  25.         mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER;  
  26.     } else if (getEventHub()->hasRelativeAxis(getDeviceId(), REL_X)  
  27.             || getEventHub()->hasRelativeAxis(getDeviceId(), REL_Y)) {  
  28.         // The device is a cursor device with a touch pad attached.  
  29.         // By default don't use the touch pad to move the pointer.  
  30.         mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_PAD;  
  31.     } else {  
  32.         // The device is a touch pad of unknown purpose.  
  33.         mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER;  
  34.     }  
  35.   
  36.     String8 deviceTypeString;  
  37.     if (getDevice()->getConfiguration().tryGetProperty(String8("touch.deviceType"),  
  38.             deviceTypeString)) {  
  39.         if (deviceTypeString == "touchScreen") {  
  40.             mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_SCREEN;  
  41.         } else if (deviceTypeString == "touchPad") {  
  42.             mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_PAD;  
  43.         } else if (deviceTypeString == "pointer") {  
  44.             mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER;  
  45.         } else if (deviceTypeString != "default") {  
  46.             LOGW("Invalid value for touch.deviceType: '%s'", deviceTypeString.string());  
  47.         }  
  48.     }  
  49.   
  50.     mParameters.orientationAware = mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN;  
  51.     getDevice()->getConfiguration().tryGetProperty(String8("touch.orientationAware"),  
  52.             mParameters.orientationAware);  
  53.   
  54.     mParameters.associatedDisplayId = -1;  
  55.     mParameters.associatedDisplayIsExternal = false;  
  56.     if (mParameters.orientationAware  
  57.             || mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN  
  58.             || mParameters.deviceType == Parameters::DEVICE_TYPE_POINTER) {  
  59.         mParameters.associatedDisplayIsExternal =  
  60.                 mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN  
  61.                         && getDevice()->isExternal();  
  62.         mParameters.associatedDisplayId = 0;  
  63.     }  
  64. }  


     还是英文呢,看到第一行,如果没有配置的话,那就是pointer,pointer不就是鼠标吗?只有定义deviceType为touchScreen,那才是我们要的啊。看来英文真的好重要好重

要啊。那到底是那里去获取配置文件的呢?不是一般都是EventHub下打开什么文件吗?走,咱们去seesee。
frameworks/base/services/input/EventHub.cpp

  1. void EventHub::loadConfigurationLocked(Device* device) {  
  2.     device->configurationFile = getInputDeviceConfigurationFilePathByDeviceIdentifier(  
  3.             device->identifier, INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION);  
  4.     if (device->configurationFile.isEmpty()) {  
  5.         LOGD("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);  
  10.         if (status) {  
  11.             LOGE("Error loading input device configuration file for device '%s'.  "  
  12.                     "Using default configuration.",  
  13.                     device->identifier.name.string());  
  14.         }  
  15.     }  
  16. }  


     原来就是这里去载入配置文件的。然后再进行配置的,接着我们看看那些配置是什么功能?上面的deviceType就不用说了,就是类型是触摸屏而不是touchPad和pointer。

pointer是鼠标类似的光标,touchPad还没试过,板子上的触摸屏也拆了,也没法跳了。不知道是什么,下次有机会去试试。差不多应该和touchScreen差不多。那么

touch.size.calibration等一些配置是什么?有什么作用呢?还是代码看起
frameworks/base/services/input/InputReader.cpp

  1. void TouchInputMapper::parseCalibration() {  
  2.     const PropertyMap& in = getDevice()->getConfiguration();  
  3.     Calibration& out = mCalibration;  
  4.   
  5.     // Size  
  6.     out.sizeCalibration = Calibration::SIZE_CALIBRATION_DEFAULT;  
  7.     String8 sizeCalibrationString;  
  8.     if (in.tryGetProperty(String8("touch.size.calibration"), sizeCalibrationString)) {  
  9.         if (sizeCalibrationString == "none") {  
  10.             out.sizeCalibration = Calibration::SIZE_CALIBRATION_NONE;  
  11.         } else if (sizeCalibrationString == "geometric") {  
  12.             out.sizeCalibration = Calibration::SIZE_CALIBRATION_GEOMETRIC;  
  13.         } else if (sizeCalibrationString == "diameter") {  
  14.             out.sizeCalibration = Calibration::SIZE_CALIBRATION_DIAMETER;  
  15.         } else if (sizeCalibrationString == "area") {  
  16.             out.sizeCalibration = Calibration::SIZE_CALIBRATION_AREA;  
  17.         } else if (sizeCalibrationString != "default") {  
  18.             LOGW("Invalid value for touch.size.calibration: '%s'",  
  19.                     sizeCalibrationString.string());  
  20.         }  
  21.     }  
  22.   
  23.     out.haveSizeScale = in.tryGetProperty(String8("touch.size.scale"),  
  24.             out.sizeScale);  
  25.     out.haveSizeBias = in.tryGetProperty(String8("touch.size.bias"),  
  26.             out.sizeBias);  
  27.     out.haveSizeIsSummed = in.tryGetProperty(String8("touch.size.isSummed"),  
  28.             out.sizeIsSummed);  
  29.   
  30.     // Pressure  
  31.     out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_DEFAULT;  
  32.     String8 pressureCalibrationString;  
  33.     if (in.tryGetProperty(String8("touch.pressure.calibration"), pressureCalibrationString)) {  
  34.         if (pressureCalibrationString == "none") {  
  35.             out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_NONE;  
  36.         } else if (pressureCalibrationString == "physical") {  
  37.             out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_PHYSICAL;  
  38.         } else if (pressureCalibrationString == "amplitude") {  
  39.             out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_AMPLITUDE;  
  40.         } else if (pressureCalibrationString != "default") {  
  41.             LOGW("Invalid value for touch.pressure.calibration: '%s'",  
  42.                     pressureCalibrationString.string());  
  43.         }  
  44.     }  
  45.   
  46.     out.havePressureScale = in.tryGetProperty(String8("touch.pressure.scale"),  
  47.             out.pressureScale);  
  48.   
  49.     // Orientation  
  50.     out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_DEFAULT;  
  51.     String8 orientationCalibrationString;  
  52.     if (in.tryGetProperty(String8("touch.orientation.calibration"), orientationCalibrationString)) {  
  53.         if (orientationCalibrationString == "none") {  
  54.             out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_NONE;  
  55.         } else if (orientationCalibrationString == "interpolated") {  
  56.             out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_INTERPOLATED;  
  57.         } else if (orientationCalibrationString == "vector") {  
  58.             out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_VECTOR;  
  59.         } else if (orientationCalibrationString != "default") {  
  60.             LOGW("Invalid value for touch.orientation.calibration: '%s'",  
  61.                     orientationCalibrationString.string());  
  62.         }  
  63.     }  
  64.   
  65.     // Distance  
  66.     out.distanceCalibration = Calibration::DISTANCE_CALIBRATION_DEFAULT;  
  67.     String8 distanceCalibrationString;  
  68.     if (in.tryGetProperty(String8("touch.distance.calibration"), distanceCalibrationString)) {  
  69.         if (distanceCalibrationString == "none") {  
  70.             out.distanceCalibration = Calibration::DISTANCE_CALIBRATION_NONE;  
  71.         } else if (distanceCalibrationString == "scaled") {  
  72.             out.distanceCalibration = Calibration::DISTANCE_CALIBRATION_SCALED;  
  73.         } else if (distanceCalibrationString != "default") {  
  74.             LOGW("Invalid value for touch.distance.calibration: '%s'",  
  75.                     distanceCalibrationString.string());  
  76.         }  
  77.     }  
  78.   
  79.     out.haveDistanceScale = in.tryGetProperty(String8("touch.distance.scale"),  
  80.             out.distanceScale);  
  81. }  


        touch.size.calibration分为了1、geometric 2、diameter 3、area,老师说不懂的单词要查字典,现在都什么年代了,随便谷歌一下,手机也行。什么牛津字典啊的,那都是浮云了。geometric:几何图形? 怪怪的,是不是代表不同的触摸的形状?不懂,diameter倒是还好,直径嘛应该是一个触摸的点是以这个为直径的一个圆,至于area嘛,区域,难道是 多点的时候?也许吧。touch.pressure.calibration分为了1、physical 2、amplitude 。physical:物理的,是不是理论上的?amplitude是不是幅度就是压力的大小?不懂额。要不再来看看代码?那些配置之后肯定有执行的。不可 能简简单单的就是赋值了。找找看
frameworks/base/services/input/InputReader.cpp

  1. void TouchInputMapper::cookPointerData() {  
  2.     uint32_t currentPointerCount = mCurrentRawPointerData.pointerCount;  
  3.   
  4.     mCurrentCookedPointerData.clear();  
  5.     mCurrentCookedPointerData.pointerCount = currentPointerCount;  
  6.     mCurrentCookedPointerData.hoveringIdBits = mCurrentRawPointerData.hoveringIdBits;  
  7.     mCurrentCookedPointerData.touchingIdBits = mCurrentRawPointerData.touchingIdBits;  
  8.   
  9.     // Walk through the the active pointers and map device coordinates onto  
  10.     // surface coordinates and adjust for display orientation.  
  11.     for (uint32_t i = 0; i < currentPointerCount; i++) {  
  12.         const RawPointerData::Pointer& in = mCurrentRawPointerData.pointers[i];  
  13.   
  14.         // Size  
  15.         float touchMajor, touchMinor, toolMajor, toolMinor, size;  
  16.         switch (mCalibration.sizeCalibration) {  
  17.         case Calibration::SIZE_CALIBRATION_GEOMETRIC:  
  18.         case Calibration::SIZE_CALIBRATION_DIAMETER:  
  19.         case Calibration::SIZE_CALIBRATION_AREA:  
  20.             if (mRawPointerAxes.touchMajor.valid && mRawPointerAxes.toolMajor.valid) {  
  21.                 touchMajor = in.touchMajor;  
  22.                 touchMinor = mRawPointerAxes.touchMinor.valid ? in.touchMinor : in.touchMajor;  
  23.                 toolMajor = in.toolMajor;  
  24.                 toolMinor = mRawPointerAxes.toolMinor.valid ? in.toolMinor : in.toolMajor;  
  25.                 size = mRawPointerAxes.touchMinor.valid  
  26.                         ? avg(in.touchMajor, in.touchMinor) : in.touchMajor;  
  27.             } else if (mRawPointerAxes.touchMajor.valid) {  
  28.                 toolMajor = touchMajor = in.touchMajor;  
  29.                 toolMinor = touchMinor = mRawPointerAxes.touchMinor.valid  
  30.                         ? in.touchMinor : in.touchMajor;  
  31.                 size = mRawPointerAxes.touchMinor.valid  
  32.                         ? avg(in.touchMajor, in.touchMinor) : in.touchMajor;  
  33.             } else if (mRawPointerAxes.toolMajor.valid) {  
  34.                 touchMajor = toolMajor = in.toolMajor;  
  35.                 touchMinor = toolMinor = mRawPointerAxes.toolMinor.valid  
  36.                         ? in.toolMinor : in.toolMajor;  
  37.                 size = mRawPointerAxes.toolMinor.valid  
  38.                         ? avg(in.toolMajor, in.toolMinor) : in.toolMajor;  
  39.             } else {  
  40.                 LOG_ASSERT(false, "No touch or tool axes.  "  
  41.                         "Size calibration should have been resolved to NONE.");  
  42.                 touchMajor = 0;  
  43.                 touchMinor = 0;  
  44.                 toolMajor = 0;  
  45.                 toolMinor = 0;  
  46.                 size = 0;  
  47.             }  
  48.   
  49.             if (mCalibration.haveSizeIsSummed && mCalibration.sizeIsSummed) {  
  50.                 uint32_t touchingCount = mCurrentRawPointerData.touchingIdBits.count();  
  51.                 if (touchingCount > 1) {  
  52.                     touchMajor /= touchingCount;  
  53.                     touchMinor /= touchingCount;  
  54.                     toolMajor /= touchingCount;  
  55.                     toolMinor /= touchingCount;  
  56.                     size /= touchingCount;  
  57.                 }  
  58.             }  
  59.   
  60.             if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_GEOMETRIC) {  
  61.                 touchMajor *= mGeometricScale;  
  62.                 touchMinor *= mGeometricScale;  
  63.                 toolMajor *= mGeometricScale;  
  64.                 toolMinor *= mGeometricScale;  
  65.             } else if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_AREA) {  
  66.                 touchMajor = touchMajor > 0 ? sqrtf(touchMajor) : 0;  
  67.                 touchMinor = touchMajor;  
  68.                 toolMajor = toolMajor > 0 ? sqrtf(toolMajor) : 0;  
  69.                 toolMinor = toolMajor;  
  70.             } else if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_DIAMETER) {  
  71.                 touchMinor = touchMajor;  
  72.                 toolMinor = toolMajor;  
  73.             }  
  74.   
  75.             mCalibration.applySizeScaleAndBias(&touchMajor);  
  76.             mCalibration.applySizeScaleAndBias(&touchMinor);  
  77.             mCalibration.applySizeScaleAndBias(&toolMajor);  
  78.             mCalibration.applySizeScaleAndBias(&toolMinor);  
  79.             size *= mSizeScale;  
  80.             break;  
  81.         default:  
  82.             touchMajor = 0;  
  83.             touchMinor = 0;  
  84.             toolMajor = 0;  
  85.             toolMinor = 0;  
  86.             size = 0;  
  87.             break;  
  88.         }  
  89.   
  90.         // Pressure  
  91.         float pressure;  
  92.         switch (mCalibration.pressureCalibration) {  
  93.         case Calibration::PRESSURE_CALIBRATION_PHYSICAL:  
  94.         case Calibration::PRESSURE_CALIBRATION_AMPLITUDE:  
  95.             pressure = in.pressure * mPressureScale;  
  96.             break;  
  97.         default:  
  98.             pressure = in.isHovering ? 0 : 1;  
  99.             break;  
  100.         }  
  101.   
  102.         // Tilt and Orientation  
  103.         float tilt;  
  104.         float orientation;  
  105.         if (mHaveTilt) {  
  106.             float tiltXAngle = (in.tiltX - mTiltXCenter) * mTiltXScale;  
  107.             float tiltYAngle = (in.tiltY - mTiltYCenter) * mTiltYScale;  
  108.             orientation = atan2f(-sinf(tiltXAngle), sinf(tiltYAngle));  
  109.             tilt = acosf(cosf(tiltXAngle) * cosf(tiltYAngle));  
  110.         } else {  
  111.             tilt = 0;  
  112.   
  113.             switch (mCalibration.orientationCalibration) {  
  114.             case Calibration::ORIENTATION_CALIBRATION_INTERPOLATED:  
  115.                 orientation = (in.orientation - mOrientationCenter) * mOrientationScale;  
  116.                 break;  
  117.             case Calibration::ORIENTATION_CALIBRATION_VECTOR: {  
  118.                 int32_t c1 = signExtendNybble((in.orientation & 0xf0) >> 4);  
  119.                 int32_t c2 = signExtendNybble(in.orientation & 0x0f);  
  120.                 if (c1 != 0 || c2 != 0) {  
  121.                     orientation = atan2f(c1, c2) * 0.5f;  
  122.                     float confidence = hypotf(c1, c2);  
  123.                     float scale = 1.0f + confidence / 16.0f;  
  124.                     touchMajor *= scale;  
  125.                     touchMinor /= scale;  
  126.                     toolMajor *= scale;  
  127.                     toolMinor /= scale;  
  128.                 } else {  
  129.                     orientation = 0;  
  130.                 }  
  131.                 break;  
  132.             }  
  133.             default:  
  134.                 orientation = 0;  
  135.             }  
  136.         }  
  137.   
  138.         // Distance  
  139.         float distance;  
  140.         switch (mCalibration.distanceCalibration) {  
  141.         case Calibration::DISTANCE_CALIBRATION_SCALED:  
  142.             distance = in.distance * mDistanceScale;  
  143.             break;  
  144.         default:  
  145.             distance = 0;  
  146.         }  
  147.   
  148.         // X and Y  
  149.         // Adjust coords for surface orientation.  
  150.         float x, y;  
  151.         switch (mSurfaceOrientation) {  
  152.         case DISPLAY_ORIENTATION_90:  
  153.             x = float(in.y - mRawPointerAxes.y.minValue) * mYScale;  
  154.             y = float(mRawPointerAxes.x.maxValue - in.x) * mXScale;  
  155.             orientation -= M_PI_2;  
  156.             if (orientation < - M_PI_2) {  
  157.                 orientation += M_PI;  
  158.             }  
  159.             break;  
  160.         case DISPLAY_ORIENTATION_180:  
  161.             x = float(mRawPointerAxes.x.maxValue - in.x) * mXScale;  
  162.             y = float(mRawPointerAxes.y.maxValue - in.y) * mYScale;  
  163.             break;  
  164.         case DISPLAY_ORIENTATION_270:  
  165.             x = float(mRawPointerAxes.y.maxValue - in.y) * mYScale;  
  166.             y = float(in.x - mRawPointerAxes.x.minValue) * mXScale;  
  167.             orientation += M_PI_2;  
  168.             if (orientation > M_PI_2) {  
  169.                 orientation -= M_PI;  
  170.             }  
  171.             break;  
  172.         default:  
  173.             x = float(in.x - mRawPointerAxes.x.minValue) * mXScale;  
  174.             y = float(in.y - mRawPointerAxes.y.minValue) * mYScale;  
  175.             break;  
  176.         }  
  177.   
  178.         // Write output coords.  
  179.         PointerCoords& out = mCurrentCookedPointerData.pointerCoords[i];  
  180.         out.clear();  
  181.         out.setAxisValue(AMOTION_EVENT_AXIS_X, x);  
  182.         out.setAxisValue(AMOTION_EVENT_AXIS_Y, y);  
  183.         out.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pressure);  
  184.         out.setAxisValue(AMOTION_EVENT_AXIS_SIZE, size);  
  185.         out.setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, touchMajor);  
  186.         out.setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, touchMinor);  
  187.         out.setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, toolMajor);  
  188.         out.setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, toolMinor);  
  189.         out.setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, orientation);  
  190.         out.setAxisValue(AMOTION_EVENT_AXIS_TILT, tilt);  
  191.         out.setAxisValue(AMOTION_EVENT_AXIS_DISTANCE, distance);  
  192.   
  193.         // Write output properties.  
  194.         PointerProperties& properties = mCurrentCookedPointerData.pointerProperties[i];  
  195.         uint32_t id = in.id;  
  196.         properties.clear();  
  197.         properties.id = id;  
  198.         properties.toolType = in.toolType;  
  199.   
  200.         // Write id index.  
  201.         mCurrentCookedPointerData.idToIndex[id] = i;  
  202.     }  
  203. }  

    这数据处理的,cookPointerData,哈哈哈,原来都在这里搞定的啊。TouchMajor and TouchMinor表示了触摸时接触面积的大小范围。这个函数会把驱动上传上来的数据,也就是X、Y坐标转换为android设定的分辨率的一个映射。 差不多就这样了。具体,碰到问题了在解决了。
    在此,有时候再讲讲自己调试的时候碰到的一个问题,那就是android电源管理中会把背光给关掉,所以点死了触摸屏还是发现没用。所以调试的时候可以把其中的一个

policyFlags设置下,不要drop掉,也就是即使背光关掉了也可以有效。
frameworks/base/services/input/InputDispatcher.cpp

   

  1.  void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) {  
  2.     nsecs_t currentTime = now();  
  3.   
  4.     // Reset the key repeat timer whenever we disallow key events, even if the next event  
  5.     // is not a key.  This is to ensure that we abort a key repeat if the device is just coming  
  6.     // out of sleep.  
  7.     if (!mPolicy->isKeyRepeatEnabled()) {  
  8.         resetKeyRepeatLocked();  
  9.     }  
  10.   
  11.     // If dispatching is frozen, do not process timeouts or try to deliver any new events.  
  12.     if (mDispatchFrozen) {  
  13. #if DEBUG_FOCUS  
  14.         LOGD("Dispatch frozen.  Waiting some more.");  
  15. #endif  
  16.         return;  
  17.     }  
  18.   
  19.     // Optimize latency of app switches.  
  20.     // Essentially we start a short timeout when an app switch key (HOME / ENDCALL) has  
  21.     // been pressed.  When it expires, we preempt dispatch and drop all other pending events.  
  22.     bool isAppSwitchDue = mAppSwitchDueTime <= currentTime;  
  23.     if (mAppSwitchDueTime < *nextWakeupTime) {  
  24.         *nextWakeupTime = mAppSwitchDueTime;  
  25.     }  
  26.   
  27.     // Ready to start a new event.  
  28.     // If we don't already have a pending event, go grab one.  
  29.     if (! mPendingEvent) {  
  30.         if (mInboundQueue.isEmpty()) {  
  31.             if (isAppSwitchDue) {  
  32.                 // The inbound queue is empty so the app switch key we were waiting  
  33.                 // for will never arrive.  Stop waiting for it.  
  34.                 resetPendingAppSwitchLocked(false);  
  35.                 isAppSwitchDue = false;  
  36.             }  
  37.   
  38.             // Synthesize a key repeat if appropriate.  
  39.             if (mKeyRepeatState.lastKeyEntry) {  
  40.                 if (currentTime >= mKeyRepeatState.nextRepeatTime) {  
  41.                     mPendingEvent = synthesizeKeyRepeatLocked(currentTime);  
  42.                 } else {  
  43.                     if (mKeyRepeatState.nextRepeatTime < *nextWakeupTime) {  
  44.                         *nextWakeupTime = mKeyRepeatState.nextRepeatTime;  
  45.                     }  
  46.                 }  
  47.             }  
  48.   
  49.             // Nothing to do if there is no pending event.  
  50.             if (! mPendingEvent) {  
  51.                 if (mActiveConnections.isEmpty()) {  
  52.                     dispatchIdleLocked();  
  53.                 }  
  54.                 return;  
  55.             }  
  56.         } else {  
  57.             // Inbound queue has at least one entry.  
  58.             EventEntry* entry = mInboundQueue.head;  
  59.   
  60.             // Throttle the entry if it is a move event and there are no  
  61.             // other events behind it in the queue.  Due to movement batching, additional  
  62.             // samples may be appended to this event by the time the throttling timeout  
  63.             // expires.  
  64.             // TODO Make this smarter and consider throttling per device independently.  
  65.             if (entry->type == EventEntry::TYPE_MOTION  
  66.                     && !isAppSwitchDue  
  67.                     && mDispatchEnabled  
  68.                     && (entry->policyFlags & POLICY_FLAG_PASS_TO_USER)  
  69.                     && !entry->isInjected()) {  
  70.                 MotionEntry* motionEntry = static_cast<MotionEntry*>(entry);  
  71.                 int32_t deviceId = motionEntry->deviceId;  
  72.                 uint32_t source = motionEntry->source;  
  73.                 if (! isAppSwitchDue  
  74.                         && !motionEntry->next // exactly one event, no successors  
  75.                         && (motionEntry->action == AMOTION_EVENT_ACTION_MOVE  
  76.                                 || motionEntry->action == AMOTION_EVENT_ACTION_HOVER_MOVE)  
  77.                         && deviceId == mThrottleState.lastDeviceId  
  78.                         && source == mThrottleState.lastSource) {  
  79.                     nsecs_t nextTime = mThrottleState.lastEventTime  
  80.                             + mThrottleState.minTimeBetweenEvents;  
  81.                     if (currentTime < nextTime) {  
  82.                         // Throttle it!  
  83. #if DEBUG_THROTTLING  
  84.                         LOGD("Throttling - Delaying motion event for "  
  85.                                 "device %d, source 0x%08x by up to %0.3fms.",  
  86.                                 deviceId, source, (nextTime - currentTime) * 0.000001);  
  87. #endif  
  88.                         if (nextTime < *nextWakeupTime) {  
  89.                             *nextWakeupTime = nextTime;  
  90.                         }  
  91.                         if (mThrottleState.originalSampleCount == 0) {  
  92.                             mThrottleState.originalSampleCount =  
  93.                                     motionEntry->countSamples();  
  94.                         }  
  95.                         return;  
  96.                     }  
  97.                 }  
  98.   
  99. #if DEBUG_THROTTLING  
  100.                 if (mThrottleState.originalSampleCount != 0) {  
  101.                     uint32_t count = motionEntry->countSamples();  
  102.                     LOGD("Throttling - Motion event sample count grew by %d from %d to %d.",  
  103.                             count - mThrottleState.originalSampleCount,  
  104.                             mThrottleState.originalSampleCount, count);  
  105.                     mThrottleState.originalSampleCount = 0;  
  106.                 }  
  107. #endif  
  108.   
  109.                 mThrottleState.lastEventTime = currentTime;  
  110.                 mThrottleState.lastDeviceId = deviceId;  
  111.                 mThrottleState.lastSource = source;  
  112.             }  
  113.   
  114.             mInboundQueue.dequeue(entry);  
  115.             mPendingEvent = entry;  
  116.         }  
  117.   
  118.         // Poke user activity for this event.  
  119.         if (mPendingEvent->policyFlags & POLICY_FLAG_PASS_TO_USER) {  
  120.             pokeUserActivityLocked(mPendingEvent);  
  121.         }  
  122.     }  
  123.   
  124.     // Now we have an event to dispatch.  
  125.     // All events are eventually dequeued and processed this way, even if we intend to drop them.  
  126.     LOG_ASSERT(mPendingEvent != NULL);  
  127.     bool done = false;  
  128.     DropReason dropReason = DROP_REASON_NOT_DROPPED;  
  129.     if (!(mPendingEvent->policyFlags & POLICY_FLAG_PASS_TO_USER)) {  
  130.         dropReason = DROP_REASON_POLICY;  
  131.     } else if (!mDispatchEnabled) {  
  132.         dropReason = DROP_REASON_DISABLED;  
  133.     }  
  134.   
  135.     if (mNextUnblockedEvent == mPendingEvent) {  
  136.         mNextUnblockedEvent = NULL;  
  137.     }  
  138.   
  139.     switch (mPendingEvent->type) {  
  140.     case EventEntry::TYPE_CONFIGURATION_CHANGED: {  
  141.         ConfigurationChangedEntry* typedEntry =  
  142.                 static_cast<ConfigurationChangedEntry*>(mPendingEvent);  
  143.         done = dispatchConfigurationChangedLocked(currentTime, typedEntry);  
  144.         dropReason = DROP_REASON_NOT_DROPPED; // configuration changes are never dropped  
  145.         break;  
  146.     }  
  147.   
  148.     case EventEntry::TYPE_DEVICE_RESET: {  
  149.         DeviceResetEntry* typedEntry =  
  150.                 static_cast<DeviceResetEntry*>(mPendingEvent);  
  151.         done = dispatchDeviceResetLocked(currentTime, typedEntry);  
  152.         dropReason = DROP_REASON_NOT_DROPPED; // device resets are never dropped  
  153.         break;  
  154.     }  
  155.   
  156.     case EventEntry::TYPE_KEY: {  
  157.         KeyEntry* typedEntry = static_cast<KeyEntry*>(mPendingEvent);  
  158.         if (isAppSwitchDue) {  
  159.             if (isAppSwitchKeyEventLocked(typedEntry)) {  
  160.                 resetPendingAppSwitchLocked(true);  
  161.                 isAppSwitchDue = false;  
  162.             } else if (dropReason == DROP_REASON_NOT_DROPPED) {  
  163.                 dropReason = DROP_REASON_APP_SWITCH;  
  164.             }  
  165.         }  
  166.         if (dropReason == DROP_REASON_NOT_DROPPED  
  167.                 && isStaleEventLocked(currentTime, typedEntry)) {  
  168.             dropReason = DROP_REASON_STALE;  
  169.         }  
  170.         if (dropReason == DROP_REASON_NOT_DROPPED && mNextUnblockedEvent) {  
  171.             dropReason = DROP_REASON_BLOCKED;  
  172.         }  
  173.         done = dispatchKeyLocked(currentTime, typedEntry, &dropReason, nextWakeupTime);  
  174.         break;  
  175.     }  
  176.   
  177.     case EventEntry::TYPE_MOTION: {  
  178.         MotionEntry* typedEntry = static_cast<MotionEntry*>(mPendingEvent);  
  179.         if (dropReason == DROP_REASON_NOT_DROPPED && isAppSwitchDue) {  
  180.             dropReason = DROP_REASON_APP_SWITCH;  
  181.         }  
  182.         if (dropReason == DROP_REASON_NOT_DROPPED  
  183.                 && isStaleEventLocked(currentTime, typedEntry)) {  
  184.             dropReason = DROP_REASON_STALE;  
  185.         }  
  186.         if (dropReason == DROP_REASON_NOT_DROPPED && mNextUnblockedEvent) {  
  187.             dropReason = DROP_REASON_BLOCKED;  
  188.         }  
  189.         done = dispatchMotionLocked(currentTime, typedEntry,  
  190.                 &dropReason, nextWakeupTime);  
  191.         break;  
  192.     }  
  193.   
  194.     default:  
  195.         LOG_ASSERT(false);  
  196.         break;  
  197.     }  
  198.   
  199.     if (done) {  
  200.         if (dropReason != DROP_REASON_NOT_DROPPED) {  
  201.             dropInboundEventLocked(mPendingEvent, dropReason);  
  202.         }  
  203.   
  204.         releasePendingEventLocked();  
  205.         *nextWakeupTime = LONG_LONG_MIN;  // force next poll to wake up immediately  
  206.     }  
  207. }  

        只要把下面的东西给注释掉就好了,那具体的policyflags是哪里赋值的呢?真心找了我好久的。
frameworks/base/services/input/InputDispatcher.cpp

  1. if (!(mPendingEvent->policyFlags & POLICY_FLAG_PASS_TO_USER)) {  
  2.       dropReason = DROP_REASON_POLICY;  
  3.   } else if (!mDispatchEnabled) {  
  4.       dropReason = DROP_REASON_DISABLED;  
  5.   }  


frameworks/base/services/input/InputDispatcher.cpp 

  1. void InputDispatcher::notifyMotion(const NotifyMotionArgs* args) {  
  2. #if DEBUG_INBOUND_EVENT_DETAILS  
  3.     LOGD("notifyMotion - eventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, "  
  4.             "action=0x%x, flags=0x%x, metaState=0x%x, buttonState=0x%x, edgeFlags=0x%x, "  
  5.             "xPrecision=%f, yPrecision=%f, downTime=%lld",  
  6.             args->eventTime, args->deviceId, args->source, args->policyFlags,  
  7.             args->action, args->flags, args->metaState, args->buttonState,  
  8.             args->edgeFlags, args->xPrecision, args->yPrecision, args->downTime);  
  9.     for (uint32_t i = 0; i < args->pointerCount; i++) {  
  10.         LOGD("  Pointer %d: id=%d, toolType=%d, "  
  11.                 "x=%f, y=%f, pressure=%f, size=%f, "  
  12.                 "touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, "  
  13.                 "orientation=%f",  
  14.                 i, args->pointerProperties[i].id,  
  15.                 args->pointerProperties[i].toolType,  
  16.                 args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X),  
  17.                 args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y),  
  18.                 args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),  
  19.                 args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE),  
  20.                 args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),  
  21.                 args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),  
  22.                 args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),  
  23.                 args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),  
  24.                 args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION));  
  25.     }  
  26. #endif  
  27.     if (!validateMotionEvent(args->action, args->pointerCount, args->pointerProperties)) {  
  28.         return;  
  29.     }  
  30.   
  31.     uint32_t policyFlags = args->policyFlags;  
  32.     policyFlags |= POLICY_FLAG_TRUSTED;  
  33.     mPolicy->interceptMotionBeforeQueueing(args->eventTime, /*byref*/ policyFlags);  
  34.   
  35.     bool needWake;  
  36.     { // acquire lock  
  37.         mLock.lock();  
  38.   
  39.         if (mInputFilterEnabled) {  
  40.             mLock.unlock();  
  41.   
  42.             MotionEvent event;  
  43.             event.initialize(args->deviceId, args->source, args->action, args->flags,  
  44.                     args->edgeFlags, args->metaState, args->buttonState, 0, 0,  
  45.                     args->xPrecision, args->yPrecision,  
  46.                     args->downTime, args->eventTime,  
  47.                     args->pointerCount, args->pointerProperties, args->pointerCoords);  
  48.   
  49.             policyFlags |= POLICY_FLAG_FILTERED;  
  50.             if (!mPolicy->filterInputEvent(&event, policyFlags)) {  
  51.                 return; // event was consumed by the filter  
  52.             }  
  53.   
  54.             mLock.lock();  
  55.         }  
  56.   
  57.         // Attempt batching and streaming of move events.  
  58.         if (args->action == AMOTION_EVENT_ACTION_MOVE  
  59.                 || args->action == AMOTION_EVENT_ACTION_HOVER_MOVE) {  
  60.             // BATCHING CASE  
  61.             //  
  62.             // Try to append a move sample to the tail of the inbound queue for this device.  
  63.             // Give up if we encounter a non-move motion event for this device since that  
  64.             // means we cannot append any new samples until a new motion event has started.  
  65.             for (EventEntry* entry = mInboundQueue.tail; entry; entry = entry->prev) {  
  66.                 if (entry->type != EventEntry::TYPE_MOTION) {  
  67.                     // Keep looking for motion events.  
  68.                     continue;  
  69.                 }  
  70.   
  71.                 MotionEntry* motionEntry = static_cast<MotionEntry*>(entry);  
  72.                 if (motionEntry->deviceId != args->deviceId  
  73.                         || motionEntry->source != args->source) {  
  74.                     // Keep looking for this device and source.  
  75.                     continue;  
  76.                 }  
  77.   
  78.                 if (!motionEntry->canAppendSamples(args->action,  
  79.                         args->pointerCount, args->pointerProperties)) {  
  80.                     // Last motion event in the queue for this device and source is  
  81.                     // not compatible for appending new samples.  Stop here.  
  82.                     goto NoBatchingOrStreaming;  
  83.                 }  
  84.   
  85.                 // Do the batching magic.  
  86.                 batchMotionLocked(motionEntry, args->eventTime,  
  87.                         args->metaState, args->pointerCoords,  
  88.                         "most recent motion event for this device and source in the inbound queue");  
  89.                 mLock.unlock();  
  90.                 return; // done!  
  91.             }  
  92.   
  93.             // BATCHING ONTO PENDING EVENT CASE  
  94.             //  
  95.             // Try to append a move sample to the currently pending event, if there is one.  
  96.             // We can do this as long as we are still waiting to find the targets for the  
  97.             // event.  Once the targets are locked-in we can only do streaming.  
  98.             if (mPendingEvent  
  99.                     && (!mPendingEvent->dispatchInProgress || !mCurrentInputTargetsValid)  
  100.                     && mPendingEvent->type == EventEntry::TYPE_MOTION) {  
  101.                 MotionEntry* motionEntry = static_cast<MotionEntry*>(mPendingEvent);  
  102.                 if (motionEntry->deviceId == args->deviceId  
  103.                         && motionEntry->source == args->source) {  
  104.                     if (!motionEntry->canAppendSamples(args->action,  
  105.                             args->pointerCount, args->pointerProperties)) {  
  106.                         // Pending motion event is for this device and source but it is  
  107.                         // not compatible for appending new samples.  Stop here.  
  108.                         goto NoBatchingOrStreaming;  
  109.                     }  
  110.   
  111.                     // Do the batching magic.  
  112.                     batchMotionLocked(motionEntry, args->eventTime,  
  113.                             args->metaState, args->pointerCoords,  
  114.                             "pending motion event");  
  115.                     mLock.unlock();  
  116.                     return; // done!  
  117.                 }  
  118.             }  
  119.   
  120.             // STREAMING CASE  
  121.             //  
  122.             // There is no pending motion event (of any kind) for this device in the inbound queue.  
  123.             // Search the outbound queue for the current foreground targets to find a dispatched  
  124.             // motion event that is still in progress.  If found, then, appen the new sample to  
  125.             // that event and push it out to all current targets.  The logic in  
  126.             // prepareDispatchCycleLocked takes care of the case where some targets may  
  127.             // already have consumed the motion event by starting a new dispatch cycle if needed.  
  128.             if (mCurrentInputTargetsValid) {  
  129.                 for (size_t i = 0; i < mCurrentInputTargets.size(); i++) {  
  130.                     const InputTarget& inputTarget = mCurrentInputTargets[i];  
  131.                     if ((inputTarget.flags & InputTarget::FLAG_FOREGROUND) == 0) {  
  132.                         // Skip non-foreground targets.  We only want to stream if there is at  
  133.                         // least one foreground target whose dispatch is still in progress.  
  134.                         continue;  
  135.                     }  
  136.   
  137.                     ssize_t connectionIndex = getConnectionIndexLocked(inputTarget.inputChannel);  
  138.                     if (connectionIndex < 0) {  
  139.                         // Connection must no longer be valid.  
  140.                         continue;  
  141.                     }  
  142.   
  143.                     sp<Connection> connection = mConnectionsByReceiveFd.valueAt(connectionIndex);  
  144.                     if (connection->outboundQueue.isEmpty()) {  
  145.                         // This foreground target has an empty outbound queue.  
  146.                         continue;  
  147.                     }  
  148.   
  149.                     DispatchEntry* dispatchEntry = connection->outboundQueue.head;  
  150.                     if (! dispatchEntry->inProgress  
  151.                             || dispatchEntry->eventEntry->type != EventEntry::TYPE_MOTION  
  152.                             || dispatchEntry->isSplit()) {  
  153.                         // No motion event is being dispatched, or it is being split across  
  154.                         // windows in which case we cannot stream.  
  155.                         continue;  
  156.                     }  
  157.   
  158.                     MotionEntry* motionEntry = static_cast<MotionEntry*>(  
  159.                             dispatchEntry->eventEntry);  
  160.                     if (motionEntry->action != args->action  
  161.                             || motionEntry->deviceId != args->deviceId  
  162.                             || motionEntry->source != args->source  
  163.                             || motionEntry->pointerCount != args->pointerCount  
  164.                             || motionEntry->isInjected()) {  
  165.                         // The motion event is not compatible with this move.  
  166.                         continue;  
  167.                     }  
  168.   
  169.                     if (args->action == AMOTION_EVENT_ACTION_HOVER_MOVE) {  
  170.                         if (mLastHoverWindowHandle == NULL) {  
  171. #if DEBUG_BATCHING  
  172.                             LOGD("Not streaming hover move because there is no "  
  173.                                     "last hovered window.");  
  174. #endif  
  175.                             goto NoBatchingOrStreaming;  
  176.                         }  
  177.   
  178.                         sp<InputWindowHandle> hoverWindowHandle = findTouchedWindowAtLocked(  
  179.                                 args->pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X),  
  180.                                 args->pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y));  
  181.                         if (mLastHoverWindowHandle != hoverWindowHandle) {  
  182. #if DEBUG_BATCHING  
  183.                             LOGD("Not streaming hover move because the last hovered window "  
  184.                                     "is '%s' but the currently hovered window is '%s'.",  
  185.                                     mLastHoverWindowHandle->getName().string(),  
  186.                                     hoverWindowHandle != NULL  
  187.                                             ? hoverWindowHandle->getName().string() : "<null>");  
  188. #endif  
  189.                             goto NoBatchingOrStreaming;  
  190.                         }  
  191.                     }  
  192.   
  193.                     // Hurray!  This foreground target is currently dispatching a move event  
  194.                     // that we can stream onto.  Append the motion sample and resume dispatch.  
  195.                     motionEntry->appendSample(args->eventTime, args->pointerCoords);  
  196. #if DEBUG_BATCHING  
  197.                     LOGD("Appended motion sample onto batch for most recently dispatched "  
  198.                             "motion event for this device and source in the outbound queues.  "  
  199.                             "Attempting to stream the motion sample.");  
  200. #endif  
  201.                     nsecs_t currentTime = now();  
  202.                     dispatchEventToCurrentInputTargetsLocked(currentTime, motionEntry,  
  203.                             true /*resumeWithAppendedMotionSample*/);  
  204.   
  205.                     runCommandsLockedInterruptible();  
  206.                     mLock.unlock();  
  207.                     return; // done!  
  208.                 }  
  209.             }  
  210.   
  211. NoBatchingOrStreaming:;  
  212.         }  
  213.   
  214.         // Just enqueue a new motion event.  
  215.         MotionEntry* newEntry = new MotionEntry(args->eventTime,  
  216.                 args->deviceId, args->source, policyFlags,  
  217.                 args->action, args->flags, args->metaState, args->buttonState,  
  218.                 args->edgeFlags, args->xPrecision, args->yPrecision, args->downTime,  
  219.                 args->pointerCount, args->pointerProperties, args->pointerCoords);  
  220.   
  221.         needWake = enqueueInboundEventLocked(newEntry);  
  222.         mLock.unlock();  
  223.     } // release lock  
  224.   
  225.     if (needWake) {  
  226.         mLooper->wake();  
  227.     }  
  228. }  


 

看到了吗?就是这里了,interceptMotionBeforeQueueing()函数,

   

  1. uint32_t policyFlags = args->policyFlags;  
  2.    policyFlags |= POLICY_FLAG_TRUSTED;  
  3.    mPolicy->interceptMotionBeforeQueueing(args->eventTime, /*byref*/ policyFlags);  


 

  1. void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {  
  2.     // Policy:  
  3.     // - Ignore untrusted events and pass them along.  
  4.     // - No special filtering for injected events required at this time.  
  5.     // - Filter normal events based on screen state.  
  6.     // - For normal events brighten (but do not wake) the screen if currently dim.  
  7.     if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {  
  8.         if (isScreenOn()) {  
  9.             policyFlags |= POLICY_FLAG_PASS_TO_USER;  
  10.   
  11.             if (!isScreenBright()) {  
  12.                 policyFlags |= POLICY_FLAG_BRIGHT_HERE;  
  13.             }  
  14.         } else {  
  15.             JNIEnv* env = jniEnv();  
  16.             jint wmActions = env->CallIntMethod(mCallbacksObj,  
  17.                         gCallbacksClassInfo.interceptMotionBeforeQueueingWhenScreenOff,  
  18.                         policyFlags);  
  19.             if (checkAndClearExceptionFromCallback(env,  
  20.                     "interceptMotionBeforeQueueingWhenScreenOff")) {  
  21.                 wmActions = 0;  
  22.             }  
  23.   
  24.             policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE;  
  25.             handleInterceptActions(wmActions, when, /*byref*/ policyFlags);  
  26.         }  
  27.     } else {  
  28.         policyFlags |= POLICY_FLAG_PASS_TO_USER;  
  29.     }  
  30. }  


原来如此呢, if (isScreenOn()) 。搞定,收工,回去睡觉了,哈哈。。。

原文地址:https://www.cnblogs.com/leaven/p/2672359.html