Enable wakeup sensors.

SensorService should hold a wakelock till the app reads events from a wakeup sensor. Currently drivers hold a wakelock with a
timeout while delivering events from a wake up sensor like Significant Motion. This hack can be removed now.

Bug: 9774884
Change-Id: If3b5acb99c9cf0cd29012fcfa9d6b04c74133d01
diff --git a/include/android/sensor.h b/include/android/sensor.h
index b4e7ebe..86de930 100644
--- a/include/android/sensor.h
+++ b/include/android/sensor.h
@@ -157,7 +157,9 @@
             uint64_t        step_counter;
         } u64;
     };
-    int32_t reserved1[4];
+
+    uint32_t flags;
+    int32_t reserved1[3];
 } ASensorEvent;
 
 struct ASensorManager;
diff --git a/include/gui/ISensorEventConnection.h b/include/gui/ISensorEventConnection.h
index f64c6b8..b296797 100644
--- a/include/gui/ISensorEventConnection.h
+++ b/include/gui/ISensorEventConnection.h
@@ -40,6 +40,7 @@
                                    nsecs_t maxBatchReportLatencyNs, int reservedFlags) = 0;
     virtual status_t setEventRate(int handle, nsecs_t ns) = 0;
     virtual status_t flush() = 0;
+    virtual void decreaseWakeLockRefCount() = 0;
 };
 
 // ----------------------------------------------------------------------------
diff --git a/include/gui/Sensor.h b/include/gui/Sensor.h
index 033b262..41a6cc6 100644
--- a/include/gui/Sensor.h
+++ b/include/gui/Sensor.h
@@ -71,6 +71,7 @@
     int32_t getFifoMaxEventCount() const;
     const String8& getStringType() const;
     const String8& getRequiredPermission() const;
+    bool isWakeUpSensor() const;
 
     // LightFlattenable protocol
     inline bool isFixedSize() const { return false; }
@@ -93,6 +94,8 @@
     int32_t mFifoMaxEventCount;
     String8 mStringType;
     String8 mRequiredPermission;
+    // Todo: Surface this in java SDK.
+    bool    mWakeUpSensor;
     static void flattenString8(void*& buffer, size_t& size, const String8& string8);
     static bool unflattenString8(void const*& buffer, size_t& size, String8& outputString8);
 };
diff --git a/include/gui/SensorEventQueue.h b/include/gui/SensorEventQueue.h
index 0bfc7a0..4e8a2d2 100644
--- a/include/gui/SensorEventQueue.h
+++ b/include/gui/SensorEventQueue.h
@@ -27,7 +27,7 @@
 #include <gui/BitTube.h>
 
 // ----------------------------------------------------------------------------
-
+#define WAKE_UP_SENSOR_EVENT_NEEDS_ACK (1 << 31)
 struct ALooper;
 struct ASensorEvent;
 
@@ -75,7 +75,8 @@
                           int reservedFlags) const;
     status_t disableSensor(int32_t handle) const;
     status_t flush() const;
-
+    // Send an ack for every wake_up sensor event that is set to WAKE_UP_SENSOR_EVENT_NEEDS_ACK.
+    void sendAck(const ASensorEvent* events, int count);
 private:
     sp<Looper> getLooper() const;
     sp<ISensorEventConnection> mSensorEventConnection;