ImmediateInterpreter: Fix TapRecord T5R2 situation detection.

If three fingers on a T5R2 pad, and one is removd, we often see a
frame with no fingers, but with positive touch count, then a frame
with 2 fingers and touch count of 2. Previously, this latter frame
would look like two added fingers, but we can tell, from the previous
frame, that that is not the case, and we are instead only having
fingers removed, not added.

BUG=chromium-os:25718
TEST=unittest; replayed problematic log and saw fix; tested on device.

Change-Id: Id580663e7304b8d95a00db5e7014a02487400cc9
diff --git a/src/immediate_interpreter.cc b/src/immediate_interpreter.cc
index e821703..e06a288 100644
--- a/src/immediate_interpreter.cc
+++ b/src/immediate_interpreter.cc
@@ -60,7 +60,8 @@
                        const set<short, kMaxTapFingers>& removed,
                        const set<short, kMaxFingers>& dead) {
   Log("Updating TapRecord.");
-  if (!t5r2_ && hwstate.finger_cnt != hwstate.touch_cnt) {
+  if (!t5r2_ && (hwstate.finger_cnt != hwstate.touch_cnt ||
+                 prev_hwstate.finger_cnt != prev_hwstate.touch_cnt)) {
     // switch to T5R2 mode
     t5r2_ = true;
     t5r2_touched_size_ = touched_.size();
diff --git a/src/immediate_interpreter_unittest.cc b/src/immediate_interpreter_unittest.cc
index 95dd906..b1fdbd9 100644
--- a/src/immediate_interpreter_unittest.cc
+++ b/src/immediate_interpreter_unittest.cc
@@ -1061,6 +1061,12 @@
     {{ 1.01, 0, 1, 5, &fs[16] }, -1, MkSet(70),   0,   0, kFTB, false },
     {{ 1.02, 0, 2, 5, &fs[16] }, -1, MkSet(70, 91), 0, 0, kFTB, false },
     {{ 1.03, 0, 1, 1, &fs[16] }, -1, MkSet(70), kBR, kBR, kIdl, false },
+    // 3f letting go, shouldn't tap at all
+    {{ 0.00, 0, 2, 3, &fs[0] },  -1, MkSet(91, 92), 0, 0, kFTB, false },  // 157
+    {{ 1.01, 0, 2, 3, &fs[0] },  -1, MkSet(91, 92), 0, 0, kIdl, false },
+    {{ 1.02, 0, 0, 2, NULL   },  -1, MkSet(),       0, 0, kIdl, false },
+    {{ 1.03, 0, 2, 2, &fs[10] }, -1, MkSet(97, 98), 0, 0, kIdl, false },
+    {{ 1.04, 0, 0, 0, NULL   },  -1, MkSet(),       0, 0, kIdl, false },
   };
   const size_t kSlowDoubleTapStartIndex = 114;
   const size_t kT5R2TestFirstIndex = 119;