sensorservice: Add proximity active callback APIs.

Bug: 175793106
Test: Tested using a temporary debug line in onProximityActiveLocked()
      and checking the counter going and up and down using the sensor
      test app plus the sensor_test CLI.
      Also tested willDisableAllSensors/didEnableAllSensors path by
      putting the service into restricted mode at various times.

Change-Id: Ic44d29f8f9de681cc6abaf722d6dca5266e358a3
diff --git a/services/sensorservice/SensorInterface.cpp b/services/sensorservice/SensorInterface.cpp
index 73a6db5..560834f 100644
--- a/services/sensorservice/SensorInterface.cpp
+++ b/services/sensorservice/SensorInterface.cpp
@@ -17,6 +17,7 @@
 #include "SensorInterface.h"
 #include "SensorDevice.h"
 #include "SensorFusion.h"
+#include "SensorService.h"
 
 #include <stdint.h>
 #include <sys/types.h>
@@ -85,4 +86,35 @@
 }
 
 // ---------------------------------------------------------------------------
+
+ProximitySensor::ProximitySensor(const sensor_t& sensor, SensorService& service)
+        : HardwareSensor(sensor), mSensorService(service) {
+}
+
+status_t ProximitySensor::activate(void* ident, bool enabled) {
+    bool wasActive = mActive;
+    status_t status = HardwareSensor::activate(ident, enabled);
+    if (status != NO_ERROR) {
+        return status;
+    }
+    mActive = enabled;
+    if (wasActive != enabled) {
+        mSensorService.onProximityActiveLocked(enabled);
+    }
+    return NO_ERROR;
+}
+
+void ProximitySensor::willDisableAllSensors() {
+    if (mSensorDevice.isSensorActive(mSensor.getHandle())) {
+        mSensorService.onProximityActiveLocked(false);
+    }
+}
+
+void ProximitySensor::didEnableAllSensors() {
+    if (mSensorDevice.isSensorActive(mSensor.getHandle())) {
+        mSensorService.onProximityActiveLocked(true);
+    }
+}
+
+// ---------------------------------------------------------------------------
 }; // namespace android