Adding proximity sensor simulation

Proximity sensor is added in emulator and avd ini file is modified to
be able add a proximity seensor to a avd.

Change-Id: I4d2645c0c4861511451b606e18d2fd9b9a2d27ed
diff --git a/android/avd/hardware-properties.ini b/android/avd/hardware-properties.ini
index 615c758..68979de 100644
--- a/android/avd/hardware-properties.ini
+++ b/android/avd/hardware-properties.ini
@@ -150,3 +150,10 @@
 default     = 16
 abstract    = Max VM application heap size
 description = The maximum heap size a Dalvik application might allocate before being killed by the system. Value is in megabytes.
+
+# Proximity sensor
+name        = hw.sensors.proximity
+type        = boolean
+default     = yes
+abstract    = Proximity support
+description = Whether there is an proximity in the device.
diff --git a/android/avd/hw-config-defs.h b/android/avd/hw-config-defs.h
index 77cb8fe..9eb4335 100644
--- a/android/avd/hw-config-defs.h
+++ b/android/avd/hw-config-defs.h
@@ -150,6 +150,13 @@
   "Max VM application heap size",
   "The maximum heap size a Dalvik application might allocate before being killed by the system. Value is in megabytes.")
 
+HWCFG_BOOL(
+  hw_sensors_proximity,
+  "hw.sensors.proximity",
+  "yes",
+  "Proximity support",
+  "Whether there is an proximity in the device.")
+
 #undef HWCFG_INT
 #undef HWCFG_BOOL
 #undef HWCFG_DISKSIZE
diff --git a/android/hw-sensors.c b/android/hw-sensors.c
index 690bb49..d9f3a6f 100644
--- a/android/hw-sensors.c
+++ b/android/hw-sensors.c
@@ -85,12 +85,17 @@
 
 
 typedef struct {
-    uint8_t  enabled;
+    float  value;
+} Proximity;
+
+typedef struct {
+    char       enabled;
     union {
         Acceleration   acceleration;
         MagneticField  magnetic;
         Orientation    orientation;
         Temperature    temperature;
+        Proximity      proximity;
     } u;
 } Sensor;
 
@@ -303,6 +308,13 @@
         _hwSensorClient_send(cl, (uint8_t*)buffer, strlen(buffer));
     }
 
+    if (_hwSensorClient_enabled(cl, ANDROID_SENSOR_PROXIMITY)) {
+        sensor = &hw->sensors[ANDROID_SENSOR_PROXIMITY];
+        snprintf(buffer, sizeof buffer, "proximity:%g",
+                 sensor->u.proximity.value);
+        _hwSensorClient_send(cl, (uint8_t*) buffer, strlen(buffer));
+    }
+
     now_ns = qemu_get_clock(vm_clock);
 
     snprintf(buffer, sizeof buffer, "sync:%lld", now_ns/1000);
@@ -495,6 +507,9 @@
         case ANDROID_SENSOR_TEMPERATURE:
             qemu_put_float(f, s->u.temperature.celsius);
             break;
+        case ANDROID_SENSOR_PROXIMITY:
+            qemu_put_float(f, s->u.proximity.value);
+            break;
         case MAX_SENSORS:
             break;
         }
@@ -543,6 +558,9 @@
         case ANDROID_SENSOR_TEMPERATURE:
             s->u.temperature.celsius = qemu_get_float(f);
             break;
+        case ANDROID_SENSOR_PROXIMITY:
+            s->u.proximity.value = qemu_get_float(f);
+            break;
         case MAX_SENSORS:
             break;
         }
@@ -582,6 +600,14 @@
 }
 #endif
 
+/* change the emulated proximity */
+static void
+_hwSensors_setProximity( HwSensors*  h, float value )
+{
+    Sensor*  s = &h->sensors[ANDROID_SENSOR_PROXIMITY];
+    s->u.proximity.value = value;
+}
+
 /* change the coarse orientation (landscape/portrait) of the emulated device */
 static void
 _hwSensors_setCoarseOrientation( HwSensors*  h, AndroidCoarseOrientation  orient )
@@ -626,10 +652,14 @@
     if (android_hw->hw_accelerometer)
         h->sensors[ANDROID_SENSOR_ACCELERATION].enabled = 1;
 
+    if (android_hw->hw_sensors_proximity)
+        h->sensors[ANDROID_SENSOR_PROXIMITY].enabled = 1;
+
     /* XXX: TODO: Add other tests when we add the corresponding
         * properties to hardware-properties.ini et al. */
 
     _hwSensors_setCoarseOrientation(h, ANDROID_COARSE_PORTRAIT);
+    _hwSensors_setProximity(h, 1);
 }
 
 static HwSensors    _sensorsState[1];
diff --git a/android/hw-sensors.h b/android/hw-sensors.h
index 37bf20e..5cfc748 100644
--- a/android/hw-sensors.h
+++ b/android/hw-sensors.h
@@ -26,6 +26,7 @@
     SENSOR_(MAGNETIC_FIELD,"magnetic-field") \
     SENSOR_(ORIENTATION,"orientation") \
     SENSOR_(TEMPERATURE,"temperature") \
+    SENSOR_(PROXIMITY,"proximity") \
 
 typedef enum {
 #define  SENSOR_(x,y)  ANDROID_SENSOR_##x,