sensor HAL v3

Bug: 32021636
Test: no
Change-Id: I7a4c5c47f8621209daef5af4d0dcbb806a236e41
diff --git a/sensors/1.0/default/Android.bp b/sensors/1.0/default/Android.bp
new file mode 100644
index 0000000..d454cdb
--- /dev/null
+++ b/sensors/1.0/default/Android.bp
@@ -0,0 +1,38 @@
+cc_library_shared {
+    name: "android.hardware.sensors@1.0-impl",
+    relative_install_path: "hw",
+    srcs: ["Sensors.cpp"],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+        "libhardware",
+        "libhwbinder",
+        "libbase",
+        "libcutils",
+        "libutils",
+        "libhidl",
+        "android.hardware.sensors@1.0",
+    ],
+    static_libs: [
+        "android.hardware.sensors@1.0-convert",
+    ],
+}
+
+cc_library_static {
+    name: "android.hardware.sensors@1.0-convert",
+    srcs: ["convert.cpp"],
+    export_include_dirs: ["include"],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+        "libhardware",
+        "libhwbinder",
+        "libbase",
+        "libcutils",
+        "libutils",
+        "libhidl",
+        "android.hardware.sensors@1.0",
+    ],
+}
+
+
diff --git a/sensors/1.0/default/Android.mk b/sensors/1.0/default/Android.mk
new file mode 100644
index 0000000..4f418cb
--- /dev/null
+++ b/sensors/1.0/default/Android.mk
@@ -0,0 +1,24 @@
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_MODULE := android.hardware.sensors@1.0-service
+LOCAL_INIT_RC := android.hardware.sensors@1.0-service.rc
+LOCAL_SRC_FILES := \
+	service.cpp \
+
+LOCAL_SHARED_LIBRARIES := \
+	liblog \
+	libcutils \
+	libdl \
+	libbase \
+	libutils \
+	libhardware_legacy \
+	libhardware \
+
+LOCAL_SHARED_LIBRARIES += \
+	libhwbinder \
+	libhidl \
+	android.hardware.sensors@1.0 \
+
+include $(BUILD_EXECUTABLE)
diff --git a/sensors/1.0/default/Sensors.cpp b/sensors/1.0/default/Sensors.cpp
new file mode 100644
index 0000000..ef052c3
--- /dev/null
+++ b/sensors/1.0/default/Sensors.cpp
@@ -0,0 +1,250 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Sensors.h"
+
+#include "convert.h"
+
+#include <android-base/logging.h>
+
+namespace android {
+namespace hardware {
+namespace sensors {
+namespace V1_0 {
+namespace implementation {
+
+static Result ResultFromStatus(status_t err) {
+    switch (err) {
+        case OK:
+            return Result::OK;
+        case BAD_VALUE:
+            return Result::BAD_VALUE;
+        case PERMISSION_DENIED:
+            return Result::PERMISSION_DENIED;
+        default:
+            return Result::INVALID_OPERATION;
+    }
+}
+
+Sensors::Sensors()
+    : mInitCheck(NO_INIT),
+      mSensorModule(nullptr),
+      mSensorDevice(nullptr) {
+    status_t err = hw_get_module(
+            SENSORS_HARDWARE_MODULE_ID,
+            (hw_module_t const **)&mSensorModule);
+
+    if (mSensorModule == NULL) {
+        err = UNKNOWN_ERROR;
+    }
+
+    if (err != OK) {
+        LOG(ERROR) << "Couldn't load "
+                   << SENSORS_HARDWARE_MODULE_ID
+                   << " module ("
+                   << strerror(-err)
+                   << ")";
+
+        mInitCheck = err;
+        return;
+    }
+
+    err = sensors_open_1(&mSensorModule->common, &mSensorDevice);
+
+    if (err != OK) {
+        LOG(ERROR) << "Couldn't open device for module "
+                   << SENSORS_HARDWARE_MODULE_ID
+                   << " ("
+                   << strerror(-err)
+                   << ")";
+
+        mInitCheck = err;
+        return;
+    }
+
+    // Require all the old HAL APIs to be present except for injection, which
+    // is considered optional.
+    CHECK_GE(getHalDeviceVersion(), SENSORS_DEVICE_API_VERSION_1_3);
+
+    mInitCheck = OK;
+}
+
+status_t Sensors::initCheck() const {
+    return mInitCheck;
+}
+
+Return<void> Sensors::getSensorsList(getSensorsList_cb _aidl_cb) {
+    sensor_t const *list;
+    size_t count = mSensorModule->get_sensors_list(mSensorModule, &list);
+
+    hidl_vec<SensorInfo> out;
+    out.resize(count);
+
+    for (size_t i = 0; i < count; ++i) {
+        const sensor_t *src = &list[i];
+        SensorInfo *dst = &out[i];
+
+        convertFromSensor(*src, dst);
+    }
+
+    _aidl_cb(out);
+
+    return Void();
+}
+
+int Sensors::getHalDeviceVersion() const {
+    if (!mSensorDevice) {
+        return -1;
+    }
+
+    return mSensorDevice->common.version;
+}
+
+Return<Result> Sensors::setOperationMode(OperationMode mode) {
+    return ResultFromStatus(mSensorModule->set_operation_mode((uint32_t)mode));
+}
+
+Return<Result> Sensors::activate(
+        int32_t sensor_handle, bool enabled) {
+    return ResultFromStatus(
+            mSensorDevice->activate(
+                reinterpret_cast<sensors_poll_device_t *>(mSensorDevice),
+                sensor_handle,
+                enabled));
+}
+
+Return<Result> Sensors::setDelay(
+        int32_t sensor_handle, int64_t sampling_period_ns) {
+    return ResultFromStatus(
+            mSensorDevice->setDelay(
+                reinterpret_cast<sensors_poll_device_t *>(mSensorDevice),
+                sensor_handle,
+                sampling_period_ns));
+}
+
+Return<void> Sensors::poll(int32_t maxCount, poll_cb _aidl_cb) {
+    hidl_vec<Event> out;
+    hidl_vec<SensorInfo> dynamicSensorsAdded;
+
+    if (maxCount <= 0) {
+        _aidl_cb(Result::BAD_VALUE, out, dynamicSensorsAdded);
+        return Void();
+    }
+
+    std::unique_ptr<sensors_event_t[]> data(new sensors_event_t[maxCount]);
+
+    int err = mSensorDevice->poll(
+            reinterpret_cast<sensors_poll_device_t *>(mSensorDevice),
+            data.get(),
+            maxCount);
+
+    if (err < 0) {
+        _aidl_cb(ResultFromStatus(err), out, dynamicSensorsAdded);
+        return Void();
+    }
+
+    const size_t count = (size_t)err;
+
+    for (size_t i = 0; i < count; ++i) {
+        if (data[i].type != SENSOR_TYPE_DYNAMIC_SENSOR_META) {
+            continue;
+        }
+
+        const dynamic_sensor_meta_event_t *dyn = &data[i].dynamic_sensor_meta;
+
+        if (!dyn->connected) {
+            continue;
+        }
+
+        CHECK(dyn->sensor != nullptr);
+        CHECK_EQ(dyn->sensor->handle, dyn->handle);
+
+        SensorInfo info;
+        convertFromSensor(*dyn->sensor, &info);
+
+        size_t numDynamicSensors = dynamicSensorsAdded.size();
+        dynamicSensorsAdded.resize(numDynamicSensors + 1);
+        dynamicSensorsAdded[numDynamicSensors] = info;
+    }
+
+    out.resize(count);
+    convertFromSensorEvents(err, data.get(), &out);
+
+    _aidl_cb(Result::OK, out, dynamicSensorsAdded);
+
+    return Void();
+}
+
+Return<Result> Sensors::batch(
+        int32_t sensor_handle,
+        int32_t flags,
+        int64_t sampling_period_ns,
+        int64_t max_report_latency_ns) {
+    return ResultFromStatus(
+            mSensorDevice->batch(
+                mSensorDevice,
+                sensor_handle,
+                flags,
+                sampling_period_ns,
+                max_report_latency_ns));
+}
+
+Return<Result> Sensors::flush(int32_t sensor_handle) {
+    return ResultFromStatus(mSensorDevice->flush(mSensorDevice, sensor_handle));
+}
+
+Return<Result> Sensors::injectSensorData(const Event& event) {
+    if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4) {
+        return Result::INVALID_OPERATION;
+    }
+
+    sensors_event_t out;
+    convertToSensorEvent(event, &out);
+
+    return ResultFromStatus(
+            mSensorDevice->inject_sensor_data(mSensorDevice, &out));
+}
+
+// static
+void Sensors::convertFromSensorEvents(
+        size_t count,
+        const sensors_event_t *srcArray,
+        hidl_vec<Event> *dstVec) {
+    for (size_t i = 0; i < count; ++i) {
+        const sensors_event_t &src = srcArray[i];
+        Event *dst = &(*dstVec)[i];
+
+        convertFromSensorEvent(src, dst);
+    }
+}
+
+ISensors *HIDL_FETCH_ISensors(const char * /* hal */) {
+    Sensors *sensors = new Sensors;
+    if (sensors->initCheck() != OK) {
+        delete sensors;
+        sensors = nullptr;
+
+        return nullptr;
+    }
+
+    return sensors;
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace sensors
+}  // namespace hardware
+}  // namespace android
diff --git a/sensors/1.0/default/Sensors.h b/sensors/1.0/default/Sensors.h
new file mode 100644
index 0000000..f9b837d
--- /dev/null
+++ b/sensors/1.0/default/Sensors.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_SENSORS_H_
+
+#define HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_SENSORS_H_
+
+#include <android/hardware/sensors/1.0/ISensors.h>
+#include <hardware/sensors.h>
+
+namespace android {
+namespace hardware {
+namespace sensors {
+namespace V1_0 {
+namespace implementation {
+
+struct Sensors : public ::android::hardware::sensors::V1_0::ISensors {
+    Sensors();
+
+    status_t initCheck() const;
+
+    Return<void> getSensorsList(getSensorsList_cb _aidl_cb) override;
+
+    Return<Result> setOperationMode(OperationMode mode) override;
+
+    Return<Result> activate(
+            int32_t sensor_handle, bool enabled) override;
+
+    Return<Result> setDelay(
+            int32_t sensor_handle, int64_t sampling_period_ns) override;
+
+    Return<void> poll(int32_t maxCount, poll_cb _hidl_cb) override;
+
+    Return<Result> batch(
+            int32_t sensor_handle,
+            int32_t flags,
+            int64_t sampling_period_ns,
+            int64_t max_report_latency_ns) override;
+
+    Return<Result> flush(int32_t sensor_handle) override;
+
+    Return<Result> injectSensorData(const Event& event) override;
+
+private:
+    status_t mInitCheck;
+    sensors_module_t *mSensorModule;
+    sensors_poll_device_1_t *mSensorDevice;
+
+    int getHalDeviceVersion() const;
+
+    static void convertFromSensorEvents(
+            size_t count, const sensors_event_t *src, hidl_vec<Event> *dst);
+
+    DISALLOW_COPY_AND_ASSIGN(Sensors);
+};
+
+extern "C" ISensors *HIDL_FETCH_ISensors(const char *name);
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace sensors
+}  // namespace hardware
+}  // namespace android
+
+#endif  // HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_SENSORS_H_
diff --git a/sensors/1.0/default/android.hardware.sensors@1.0-service.rc b/sensors/1.0/default/android.hardware.sensors@1.0-service.rc
new file mode 100644
index 0000000..2cba0fc
--- /dev/null
+++ b/sensors/1.0/default/android.hardware.sensors@1.0-service.rc
@@ -0,0 +1,4 @@
+service sensors-hal-1-0 /system/bin/hw/android.hardware.sensors@1.0-service
+    class main
+    user system
+    group system readproc
diff --git a/sensors/1.0/default/convert.cpp b/sensors/1.0/default/convert.cpp
new file mode 100644
index 0000000..f4e1841
--- /dev/null
+++ b/sensors/1.0/default/convert.cpp
@@ -0,0 +1,346 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/convert.h"
+
+#include <android-base/logging.h>
+
+namespace android {
+namespace hardware {
+namespace sensors {
+namespace V1_0 {
+namespace implementation {
+
+void convertFromSensor(const sensor_t &src, SensorInfo *dst) {
+    dst->name = src.name;
+    dst->vendor = src.vendor;
+    dst->version = src.version;
+    dst->sensorHandle = src.handle;
+    dst->type = (SensorType)src.type;
+    dst->maxRange = src.maxRange;
+    dst->resolution = src.resolution;
+    dst->power = src.power;
+    dst->minDelay = src.minDelay;
+    dst->fifoReservedEventCount = src.fifoReservedEventCount;
+    dst->fifoMaxEventCount = src.fifoMaxEventCount;
+    dst->typeAsString = src.stringType;
+    dst->requiredPermission = src.requiredPermission;
+    dst->maxDelay = src.maxDelay;
+    dst->flags = src.flags;
+}
+
+void convertToSensor(
+        const ::android::hardware::sensors::V1_0::SensorInfo &src,
+        sensor_t *dst) {
+    dst->name = strdup(src.name.c_str());
+    dst->vendor = strdup(src.vendor.c_str());
+    dst->version = src.version;
+    dst->handle = src.sensorHandle;
+    dst->type = (int)src.type;
+    dst->maxRange = src.maxRange;
+    dst->resolution = src.resolution;
+    dst->power = src.power;
+    dst->minDelay = src.minDelay;
+    dst->fifoReservedEventCount = src.fifoReservedEventCount;
+    dst->fifoMaxEventCount = src.fifoMaxEventCount;
+    dst->stringType = strdup(src.typeAsString.c_str());
+    dst->requiredPermission = strdup(src.requiredPermission.c_str());
+    dst->maxDelay = src.maxDelay;
+    dst->flags = src.flags;
+    dst->reserved[0] = dst->reserved[1] = 0;
+}
+
+void convertFromSensorEvent(const sensors_event_t &src, Event *dst) {
+    typedef ::android::hardware::sensors::V1_0::SensorType SensorType;
+    typedef ::android::hardware::sensors::V1_0::MetaDataEventType MetaDataEventType;
+
+    dst->sensorHandle = src.sensor;
+    dst->sensorType = (SensorType)src.type;
+    dst->timestamp = src.timestamp;
+
+    switch (dst->sensorType) {
+        case SensorType::SENSOR_TYPE_META_DATA:
+        {
+            dst->u.meta.what = (MetaDataEventType)src.meta_data.what;
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_ACCELEROMETER:
+        case SensorType::SENSOR_TYPE_GEOMAGNETIC_FIELD:
+        case SensorType::SENSOR_TYPE_ORIENTATION:
+        case SensorType::SENSOR_TYPE_GYROSCOPE:
+        case SensorType::SENSOR_TYPE_GRAVITY:
+        case SensorType::SENSOR_TYPE_LINEAR_ACCELERATION:
+        {
+            dst->u.vec3.x = src.acceleration.x;
+            dst->u.vec3.y = src.acceleration.y;
+            dst->u.vec3.z = src.acceleration.z;
+            dst->u.vec3.status = (SensorStatus)src.acceleration.status;
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_ROTATION_VECTOR:
+        case SensorType::SENSOR_TYPE_GAME_ROTATION_VECTOR:
+        case SensorType::SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR:
+        {
+            dst->u.vec4.x = src.data[0];
+            dst->u.vec4.y = src.data[1];
+            dst->u.vec4.z = src.data[2];
+            dst->u.vec4.w = src.data[3];
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED:
+        case SensorType::SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
+        {
+            dst->u.uncal.x = src.uncalibrated_gyro.x_uncalib;
+            dst->u.uncal.y = src.uncalibrated_gyro.y_uncalib;
+            dst->u.uncal.z = src.uncalibrated_gyro.z_uncalib;
+            dst->u.uncal.x_bias = src.uncalibrated_gyro.x_bias;
+            dst->u.uncal.y_bias = src.uncalibrated_gyro.y_bias;
+            dst->u.uncal.z_bias = src.uncalibrated_gyro.z_bias;
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_DEVICE_ORIENTATION:
+        case SensorType::SENSOR_TYPE_LIGHT:
+        case SensorType::SENSOR_TYPE_PRESSURE:
+        case SensorType::SENSOR_TYPE_TEMPERATURE:
+        case SensorType::SENSOR_TYPE_PROXIMITY:
+        case SensorType::SENSOR_TYPE_RELATIVE_HUMIDITY:
+        case SensorType::SENSOR_TYPE_AMBIENT_TEMPERATURE:
+        case SensorType::SENSOR_TYPE_SIGNIFICANT_MOTION:
+        case SensorType::SENSOR_TYPE_STEP_DETECTOR:
+        case SensorType::SENSOR_TYPE_TILT_DETECTOR:
+        case SensorType::SENSOR_TYPE_WAKE_GESTURE:
+        case SensorType::SENSOR_TYPE_GLANCE_GESTURE:
+        case SensorType::SENSOR_TYPE_PICK_UP_GESTURE:
+        case SensorType::SENSOR_TYPE_WRIST_TILT_GESTURE:
+        case SensorType::SENSOR_TYPE_STATIONARY_DETECT:
+        case SensorType::SENSOR_TYPE_MOTION_DETECT:
+        case SensorType::SENSOR_TYPE_HEART_BEAT:
+        {
+            dst->u.scalar = src.data[0];
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_STEP_COUNTER:
+        {
+            dst->u.stepCount = src.u64.step_counter;
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_HEART_RATE:
+        {
+            dst->u.heartRate.bpm = src.heart_rate.bpm;
+            dst->u.heartRate.status = (SensorStatus)src.heart_rate.status;
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_POSE_6DOF:  // 15 floats
+        {
+            for (size_t i = 0; i < 15; ++i) {
+                dst->u.pose6DOF[i] = src.data[i];
+            }
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_DYNAMIC_SENSOR_META:
+        {
+            dst->u.dynamic.connected = src.dynamic_sensor_meta.connected;
+            dst->u.dynamic.sensorHandle = src.dynamic_sensor_meta.handle;
+
+            memcpy(dst->u.dynamic.uuid.data(),
+                   src.dynamic_sensor_meta.uuid,
+                   16);
+
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_ADDITIONAL_INFO:
+        {
+            ::android::hardware::sensors::V1_0::AdditionalInfo *dstInfo =
+                &dst->u.additional;
+
+            const additional_info_event_t &srcInfo = src.additional_info;
+
+            dstInfo->type =
+                (::android::hardware::sensors::V1_0::AdditionalInfoType)
+                    srcInfo.type;
+
+            dstInfo->serial = srcInfo.serial;
+
+            CHECK_EQ(sizeof(dstInfo->u), sizeof(srcInfo.data_int32));
+            memcpy(&dstInfo->u, srcInfo.data_int32, sizeof(srcInfo.data_int32));
+            break;
+        }
+
+        default:
+        {
+            CHECK_GE((int32_t)dst->sensorType,
+                     (int32_t)SensorType::SENSOR_TYPE_DEVICE_PRIVATE_BASE);
+
+            memcpy(dst->u.data.data(), src.data, 16 * sizeof(float));
+            break;
+        }
+    }
+}
+
+void convertToSensorEvent(const Event &src, sensors_event_t *dst) {
+    dst->version = sizeof(sensors_event_t);
+    dst->sensor = src.sensorHandle;
+    dst->type = (int32_t)src.sensorType;
+    dst->reserved0 = 0;
+    dst->timestamp = src.timestamp;
+    dst->flags = 0;
+    dst->reserved1[0] = dst->reserved1[1] = dst->reserved1[2] = 0;
+
+    switch (src.sensorType) {
+        case SensorType::SENSOR_TYPE_META_DATA:
+        {
+            dst->meta_data.what = (int32_t)src.u.meta.what;
+            dst->meta_data.sensor = dst->sensor;
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_ACCELEROMETER:
+        case SensorType::SENSOR_TYPE_GEOMAGNETIC_FIELD:
+        case SensorType::SENSOR_TYPE_ORIENTATION:
+        case SensorType::SENSOR_TYPE_GYROSCOPE:
+        case SensorType::SENSOR_TYPE_GRAVITY:
+        case SensorType::SENSOR_TYPE_LINEAR_ACCELERATION:
+        {
+            dst->acceleration.x = src.u.vec3.x;
+            dst->acceleration.y = src.u.vec3.y;
+            dst->acceleration.z = src.u.vec3.z;
+            dst->acceleration.status = (int8_t)src.u.vec3.status;
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_ROTATION_VECTOR:
+        case SensorType::SENSOR_TYPE_GAME_ROTATION_VECTOR:
+        case SensorType::SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR:
+        {
+            dst->data[0] = src.u.vec4.x;
+            dst->data[1] = src.u.vec4.y;
+            dst->data[2] = src.u.vec4.z;
+            dst->data[3] = src.u.vec4.w;
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED:
+        case SensorType::SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
+        {
+            dst->uncalibrated_gyro.x_uncalib = src.u.uncal.x;
+            dst->uncalibrated_gyro.y_uncalib = src.u.uncal.y;
+            dst->uncalibrated_gyro.z_uncalib = src.u.uncal.z;
+            dst->uncalibrated_gyro.x_bias = src.u.uncal.x_bias;
+            dst->uncalibrated_gyro.y_bias = src.u.uncal.y_bias;
+            dst->uncalibrated_gyro.z_bias = src.u.uncal.z_bias;
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_DEVICE_ORIENTATION:
+        case SensorType::SENSOR_TYPE_LIGHT:
+        case SensorType::SENSOR_TYPE_PRESSURE:
+        case SensorType::SENSOR_TYPE_TEMPERATURE:
+        case SensorType::SENSOR_TYPE_PROXIMITY:
+        case SensorType::SENSOR_TYPE_RELATIVE_HUMIDITY:
+        case SensorType::SENSOR_TYPE_AMBIENT_TEMPERATURE:
+        case SensorType::SENSOR_TYPE_SIGNIFICANT_MOTION:
+        case SensorType::SENSOR_TYPE_STEP_DETECTOR:
+        case SensorType::SENSOR_TYPE_TILT_DETECTOR:
+        case SensorType::SENSOR_TYPE_WAKE_GESTURE:
+        case SensorType::SENSOR_TYPE_GLANCE_GESTURE:
+        case SensorType::SENSOR_TYPE_PICK_UP_GESTURE:
+        case SensorType::SENSOR_TYPE_WRIST_TILT_GESTURE:
+        case SensorType::SENSOR_TYPE_STATIONARY_DETECT:
+        case SensorType::SENSOR_TYPE_MOTION_DETECT:
+        case SensorType::SENSOR_TYPE_HEART_BEAT:
+        {
+            dst->data[0] = src.u.scalar;
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_STEP_COUNTER:
+        {
+            dst->u64.step_counter = src.u.stepCount;
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_HEART_RATE:
+        {
+            dst->heart_rate.bpm = src.u.heartRate.bpm;
+            dst->heart_rate.status = (int8_t)src.u.heartRate.status;
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_POSE_6DOF:  // 15 floats
+        {
+            for (size_t i = 0; i < 15; ++i) {
+                dst->data[i] = src.u.pose6DOF[i];
+            }
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_DYNAMIC_SENSOR_META:
+        {
+            dst->dynamic_sensor_meta.connected = src.u.dynamic.connected;
+            dst->dynamic_sensor_meta.handle = src.u.dynamic.sensorHandle;
+            dst->dynamic_sensor_meta.sensor = NULL;  // to be filled in later
+
+            memcpy(dst->dynamic_sensor_meta.uuid,
+                   src.u.dynamic.uuid.data(),
+                   16);
+
+            break;
+        }
+
+        case SensorType::SENSOR_TYPE_ADDITIONAL_INFO:
+        {
+            const ::android::hardware::sensors::V1_0::AdditionalInfo &srcInfo =
+                src.u.additional;
+
+            additional_info_event_t *dstInfo = &dst->additional_info;
+            dstInfo->type = (int32_t)srcInfo.type;
+            dstInfo->serial = srcInfo.serial;
+
+            CHECK_EQ(sizeof(srcInfo.u), sizeof(dstInfo->data_int32));
+
+            memcpy(dstInfo->data_int32,
+                   &srcInfo.u,
+                   sizeof(dstInfo->data_int32));
+
+            break;
+        }
+
+        default:
+        {
+            CHECK_GE((int32_t)src.sensorType,
+                     (int32_t)SensorType::SENSOR_TYPE_DEVICE_PRIVATE_BASE);
+
+            memcpy(dst->data, src.u.data.data(), 16 * sizeof(float));
+            break;
+        }
+    }
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace sensors
+}  // namespace hardware
+}  // namespace android
+
diff --git a/sensors/1.0/default/include/convert.h b/sensors/1.0/default/include/convert.h
new file mode 100644
index 0000000..d289a81
--- /dev/null
+++ b/sensors/1.0/default/include/convert.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_INCLUDE_CONVERT_H_
+
+#define HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_INCLUDE_CONVERT_H_
+
+#include <android/hardware/sensors/1.0/ISensors.h>
+#include <hardware/sensors.h>
+
+namespace android {
+namespace hardware {
+namespace sensors {
+namespace V1_0 {
+namespace implementation {
+
+void convertFromSensor(const sensor_t &src, SensorInfo *dst);
+void convertToSensor(const SensorInfo &src, sensor_t *dst);
+
+void convertFromSensorEvent(const sensors_event_t &src, Event *dst);
+void convertToSensorEvent(const Event &src, sensors_event_t *dst);
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace sensors
+}  // namespace hardware
+}  // namespace android
+
+#endif  // HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_INCLUDE_CONVERT_H_
diff --git a/sensors/1.0/default/service.cpp b/sensors/1.0/default/service.cpp
new file mode 100644
index 0000000..da543ef
--- /dev/null
+++ b/sensors/1.0/default/service.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <android-base/logging.h>
+#include <android/hardware/sensors/1.0/ISensors.h>
+#include <hwbinder/IPCThreadState.h>
+#include <hwbinder/ProcessState.h>
+
+int main() {
+    using android::hardware::sensors::V1_0::ISensors;
+    using android::sp;
+    using android::OK;
+    using namespace android::hardware;
+
+    LOG(INFO) << "Service is starting.";
+    sp<ISensors> sensors = ISensors::getService("sensors", true /* getStub */);
+
+    if (sensors.get() == nullptr) {
+        LOG(ERROR) << "ISensors::getService returned nullptr, exiting.";
+        return 1;
+    }
+
+    LOG(INFO) << "Default implementation using sensors is "
+              << (sensors->isRemote() ? "REMOTE" : "LOCAL");
+
+    CHECK(!sensors->isRemote());
+
+    LOG(INFO) << "Registering instance sensors.";
+    sensors->registerAsService("sensors");
+    LOG(INFO) << "Ready.";
+
+    ProcessState::self()->setThreadPoolMaxThreadCount(0);
+    ProcessState::self()->startThreadPool();
+    IPCThreadState::self()->joinThreadPool();
+
+    return 0;
+}
+