fix viewdraghelper's crash with invalid PointerId

This commit is contained in:
侯歌 2024-05-05 14:33:40 +08:00
parent 6afd464ace
commit e8ccf6b9ed
3 changed files with 17 additions and 15 deletions

View File

@ -403,6 +403,7 @@ void TouchDevice::setAxisValue(int raw_axis,int value,bool isRelative){
switch(raw_axis){
case ABS_X ... ABS_Z :
mSlotID = 0 ; mTrackID = 0;
mProp.id = 0;
mDeviceClasses &= ~INPUT_DEVICE_CLASS_TOUCH_MT;
break;
case ABS_MT_POSITION_X...ABS_MT_POSITION_Y:

View File

@ -294,13 +294,13 @@ void ViewDragHelper::clearMotionHistory(int pointerId) {
void ViewDragHelper::ensureMotionHistorySizeForId(int pointerId) {
if (mInitialMotionX.size() <= pointerId) {
mInitialMotionX.resize(pointerId + 1);// = imx;
mInitialMotionY.resize(pointerId + 1);// = imy;
mLastMotionX.resize(pointerId + 1);// = lmx;
mLastMotionY.resize(pointerId + 1);// = lmy;
mInitialEdgesTouched.resize(pointerId + 1);// = iit;
mEdgeDragsInProgress.resize(pointerId + 1);// = edip;
mEdgeDragsLocked.resize(pointerId + 1);// = edl;
//mInitialMotionX.resize(pointerId + 1);// = imx;
//mInitialMotionY.resize(pointerId + 1);// = imy;
//mLastMotionX.resize(pointerId + 1);// = lmx;
//mLastMotionY.resize(pointerId + 1);// = lmy;
//mInitialEdgesTouched.resize(pointerId + 1);// = iit;
//mEdgeDragsInProgress.resize(pointerId + 1);// = edip;
//mEdgeDragsLocked.resize(pointerId + 1);// = edl;
}
}
@ -748,7 +748,8 @@ bool ViewDragHelper::isEdgeTouched(int edges)const{
}
bool ViewDragHelper::isEdgeTouched(int edges, int pointerId)const{
return isPointerDown(pointerId) && (mInitialEdgesTouched[pointerId] & edges) != 0;
auto it = mInitialEdgesTouched.find(pointerId);
return isPointerDown(pointerId) && (it->second & edges) != 0;
}
void ViewDragHelper::releaseViewForPointerUp() {

View File

@ -73,13 +73,13 @@ private:
// Last known position/pointer tracking
int mActivePointerId = INVALID_POINTER;
std::vector<float> mInitialMotionX;
std::vector<float> mInitialMotionY;
std::vector<float> mLastMotionX;
std::vector<float> mLastMotionY;
std::vector<int> mInitialEdgesTouched;
std::vector<int> mEdgeDragsInProgress;
std::vector<int> mEdgeDragsLocked;
std::map<int,float> mInitialMotionX;
std::map<int,float> mInitialMotionY;
std::map<int,float> mLastMotionX;
std::map<int,float> mLastMotionY;
std::map<int,int> mInitialEdgesTouched;
std::map<int,int> mEdgeDragsInProgress;
std::map<int,int> mEdgeDragsLocked;
int mPointersDown;
VelocityTracker* mVelocityTracker;