Doze: Workaround vibration-related pickup gestures.

Ensure the pickup is registered a safe period of time after the
last notification before resetting the notification pulse schedule.

Bug:17496795
Change-Id: I0edc9bcbdf078cbf55df5935744a3eee7e902b5d
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index 17b3833..a8c95c1 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -203,6 +203,9 @@
     <!-- Doze: maximum number of times the notification pulse schedule can be reset -->
     <integer name="doze_pulse_schedule_resets">3</integer>
 
+    <!-- Doze: duration to avoid false pickup gestures triggered by notification vibrations -->
+    <integer name="doze_pickup_vibration_threshold">2000</integer>
+
     <!-- Doze: pulse parameter - how long does it take to fade in? -->
     <integer name="doze_pulse_duration_in">1000</integer>
 
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeService.java b/packages/SystemUI/src/com/android/systemui/doze/DozeService.java
index dae15e6..e2c8ff9 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeService.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeService.java
@@ -411,7 +411,15 @@
             }
             requestPulse();
             setListening(true);  // reregister, this sensor only fires once
-            resetNotificationResets();
+
+            // reset the notification pulse schedule, but only if we think we were not triggered
+            // by a notification-related vibration
+            final long timeSinceNotification = System.currentTimeMillis() - mNotificationPulseTime;
+            if (timeSinceNotification < mDozeParameters.getPickupVibrationThreshold()) {
+               if (DEBUG) Log.d(mTag, "Not resetting schedule, recent notification");
+            } else {
+                resetNotificationResets();
+            }
         }
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java
index bcf42de..b566bbc 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java
@@ -57,6 +57,7 @@
         pw.print("    getPulseOnNotifications(): "); pw.println(getPulseOnNotifications());
         pw.print("    getPulseSchedule(): "); pw.println(getPulseSchedule());
         pw.print("    getPulseScheduleResets(): "); pw.println(getPulseScheduleResets());
+        pw.print("    getPickupVibrationThreshold(): "); pw.println(getPickupVibrationThreshold());
     }
 
     public boolean getDisplayStateSupported() {
@@ -111,6 +112,10 @@
         return getInt("doze.pulse.schedule.resets", R.integer.doze_pulse_schedule_resets);
     }
 
+    public int getPickupVibrationThreshold() {
+        return getInt("doze.pickup.vibration.threshold", R.integer.doze_pickup_vibration_threshold);
+    }
+
     private boolean getBoolean(String propName, int resId) {
         return SystemProperties.getBoolean(propName, mContext.getResources().getBoolean(resId));
     }