sensors: als & tilt: fix E build errors

Recognize M (version 6)
Fix LOG% macros to work with version >= L
Fix missing includes

BUG: 23034764

Change-Id: I069fe0c4efd720386f97dff656c4b90a1ec12ce4
diff --git a/als/AlsSensor.cpp b/als/AlsSensor.cpp
index 11837d5..a0f8c1a 100644
--- a/als/AlsSensor.cpp
+++ b/als/AlsSensor.cpp
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <math.h>
 #include <stdlib.h>
+#include <string.h>
 #include <poll.h>
 #include <unistd.h>
 #include <dirent.h>
diff --git a/als/Android.mk b/als/Android.mk
index a2cc63c..7d756fc 100644
--- a/als/Android.mk
+++ b/als/Android.mk
@@ -28,6 +28,7 @@
 VERSION_JB_MR2 := $(shell test $(MAJOR_VERSION) -eq 4 -a $(MINOR_VERSION) -eq 3 && echo true)
 VERSION_KK := $(shell test $(MAJOR_VERSION) -eq 4 -a $(MINOR_VERSION) -eq 4 && echo true)
 VERSION_L := $(shell test $(MAJOR_VERSION) -eq 5 && echo true)
+VERSION_M := $(shell test $(MAJOR_VERSION) -eq 6 && echo true)
 #ANDROID version check END
 
 LOCAL_MODULE := sensor_als.robby
@@ -37,7 +38,7 @@
 
 LOCAL_MODULE_TAGS := optional
 # TODO: remove LOG_NDEBUG=0 for production builds, keep it during integration
-LOCAL_CFLAGS := -DLOG_TAG=\"LightSensor\"
+LOCAL_CFLAGS := -DLOG_TAG=\"LightSensor\" -DANDROID_VERSION=$(MAJOR_VERSION)
 
 ifeq ($(VERSION_JB),true)
 LOCAL_CFLAGS += -DANDROID_JB
@@ -65,7 +66,15 @@
 LOCAL_CFLAGS += -DHAL_VERSION_GT_1_0
 endif
 
-#LOCAL_C_INCLUDES += hardware/invensense/libsensors_iio
+ifeq ($(VERSION_M),true)
+LOCAL_CFLAGS += -DANDROID_M
+#hal version is greater than and equal 1_0
+LOCAL_CFLAGS += -DHAL_VERSION_GE_1_0
+#hal version is greater than 1_0
+LOCAL_CFLAGS += -DHAL_VERSION_GT_1_0
+endif
+
+##LOCAL_C_INCLUDES += hardware/invensense/libsensors_iio
 LOCAL_SRC_FILES := \
     sensors.cpp \
     InputEventReader.cpp \
diff --git a/als/InputEventReader.cpp b/als/InputEventReader.cpp
index 7efee2d..4799dfa 100644
--- a/als/InputEventReader.cpp
+++ b/als/InputEventReader.cpp
@@ -15,6 +15,8 @@
 */
 
 #include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
 #include <errno.h>
 #include <unistd.h>
 #include <poll.h>
diff --git a/als/SensorBase.cpp b/als/SensorBase.cpp
index 5617e92..20ab370 100644
--- a/als/SensorBase.cpp
+++ b/als/SensorBase.cpp
@@ -18,6 +18,8 @@
 #include <errno.h>
 #include <math.h>
 #include <poll.h>
+#include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include <dirent.h>
 #include <sys/select.h>
diff --git a/als/SensorBase.h b/als/SensorBase.h
index 417ba20..78b7c38 100644
--- a/als/SensorBase.h
+++ b/als/SensorBase.h
@@ -22,7 +22,7 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
-#if defined ANDROID_L
+#if ANDROID_VERSION >= 5
 /* #warning "build for Wear" */
 #define LOGV_IF ALOGV_IF
 #define LOGE_IF ALOGE_IF
diff --git a/als/sensors.cpp b/als/sensors.cpp
index 04d349d..76a4537 100644
--- a/als/sensors.cpp
+++ b/als/sensors.cpp
@@ -22,6 +22,7 @@
 #include <poll.h>
 #include <pthread.h>
 #include <stdlib.h>
+#include <string.h>
 #include <linux/input.h>
 #include <utils/Atomic.h>
 #include <utils/Log.h>
diff --git a/tilt/Android.mk b/tilt/Android.mk
index 8e6af2f..3b543a3 100644
--- a/tilt/Android.mk
+++ b/tilt/Android.mk
@@ -28,6 +28,7 @@
 VERSION_JB_MR2 := $(shell test $(MAJOR_VERSION) -eq 4 -a $(MINOR_VERSION) -eq 3 && echo true)
 VERSION_KK := $(shell test $(MAJOR_VERSION) -eq 4 -a $(MINOR_VERSION) -eq 4 && echo true)
 VERSION_L := $(shell test $(MAJOR_VERSION) -eq 5 && echo true)
+VERSION_M := $(shell test $(MAJOR_VERSION) -eq 6 && echo true)
 #ANDROID version check END
 
 LOCAL_MODULE := sensor_tilt.robby
@@ -37,7 +38,7 @@
 
 LOCAL_MODULE_TAGS := optional
 # TODO: remove LOG_NDEBUG=0 for production builds, keep it during integration
-LOCAL_CFLAGS := -DLOG_TAG=\"TiltSensor\"
+LOCAL_CFLAGS := -DLOG_TAG=\"TiltSensor\" -DANDROID_VERSION=$(MAJOR_VERSION)
 
 ifeq ($(VERSION_JB),true)
 LOCAL_CFLAGS += -DANDROID_JB
@@ -65,7 +66,15 @@
 LOCAL_CFLAGS += -DHAL_VERSION_GT_1_0
 endif
 
-#LOCAL_C_INCLUDES += hardware/invensense/libsensors_iio
+ifeq ($(VERSION_M),true)
+LOCAL_CFLAGS += -DANDROID_M
+#hal version is greater than and equal 1_0
+LOCAL_CFLAGS += -DHAL_VERSION_GE_1_0
+#hal version is greater than 1_0
+LOCAL_CFLAGS += -DHAL_VERSION_GT_1_0
+endif
+
+##LOCAL_C_INCLUDES += hardware/invensense/libsensors_iio
 LOCAL_SRC_FILES := \
     sensors.cpp \
     InputEventReader.cpp \
diff --git a/tilt/InputEventReader.cpp b/tilt/InputEventReader.cpp
index f3590c7..1812cf5 100644
--- a/tilt/InputEventReader.cpp
+++ b/tilt/InputEventReader.cpp
@@ -15,6 +15,8 @@
  */
 
 #include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
 #include <errno.h>
 #include <unistd.h>
 #include <poll.h>
diff --git a/tilt/SensorBase.cpp b/tilt/SensorBase.cpp
index c90a948..cba4831 100644
--- a/tilt/SensorBase.cpp
+++ b/tilt/SensorBase.cpp
@@ -18,6 +18,8 @@
 #include <errno.h>
 #include <math.h>
 #include <poll.h>
+#include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include <dirent.h>
 #include <sys/select.h>
diff --git a/tilt/SensorBase.h b/tilt/SensorBase.h
index deedb22..7c2913c 100644
--- a/tilt/SensorBase.h
+++ b/tilt/SensorBase.h
@@ -22,7 +22,7 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
-#if defined ANDROID_L
+#if ANDROID_VERSION >= 5
 /* #warning "build for Wear" */
 #define LOGV_IF ALOGV_IF
 #define LOGE_IF ALOGE_IF
diff --git a/tilt/TiltSensor.cpp b/tilt/TiltSensor.cpp
index 93aefc8..710882b 100644
--- a/tilt/TiltSensor.cpp
+++ b/tilt/TiltSensor.cpp
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <math.h>
 #include <stdlib.h>
+#include <string.h>
 #include <poll.h>
 #include <unistd.h>
 #include <dirent.h>
diff --git a/tilt/sensors.cpp b/tilt/sensors.cpp
index 5075590..0374cd0 100644
--- a/tilt/sensors.cpp
+++ b/tilt/sensors.cpp
@@ -22,6 +22,7 @@
 #include <poll.h>
 #include <pthread.h>
 #include <stdlib.h>
+#include <string.h>
 #include <linux/input.h>
 #include <utils/Atomic.h>
 #include <utils/Log.h>