Merge "Sensor HAL 2.1 Migration"
diff --git a/aosp_trout_arm64.mk b/aosp_trout_arm64.mk
index 082d32e..9adf7a7 100644
--- a/aosp_trout_arm64.mk
+++ b/aosp_trout_arm64.mk
@@ -60,9 +60,9 @@
 # Sensor HAL
 # The implementations use SCMI, which only works on arm architecture
 LOCAL_SENSOR_PRODUCT_PACKAGE ?= \
-    android.hardware.sensors@2.0-service.multihal \
-    android.hardware.sensors@2.0-service.multihal.rc \
-    android.hardware.sensors@2.0-Google-IIO-Subhal \
+    android.hardware.sensors-service.multihal \
+    android.hardware.sensors-service.multihal.rc \
+    android.hardware.sensors@2.1-Google-IIO-Subhal \
 
 LOCAL_SENSOR_FILE_OVERRIDES := true
 
@@ -72,7 +72,7 @@
 
 PRODUCT_COPY_FILES += \
     $(UEVENTD_ODM_COPY_FILE):$(TARGET_COPY_OUT_ODM)/etc/ueventd.rc \
-    device/google/trout/hal/sensors/2.0/config/sensor_hal_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/sensors/sensor_hal_configuration.xml \
+    device/google/trout/hal/sensors/2.1/config/sensor_hal_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/sensors/sensor_hal_configuration.xml \
     device/google/trout/product_files/odm/usr/idc/Vendor_0fff_Product_0fff.idc:$(TARGET_COPY_OUT_ODM)/usr/idc/Vendor_0fff_Product_0fff.idc \
     device/google/trout/product_files/vendor/etc/sensors/hals.conf:$(TARGET_COPY_OUT_VENDOR)/etc/sensors/hals.conf \
     frameworks/native/data/etc/android.hardware.sensor.gyroscope.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.gyroscope.xml \
diff --git a/hal/sensors/2.0/Android.bp b/hal/sensors/2.1/Android.bp
similarity index 84%
rename from hal/sensors/2.0/Android.bp
rename to hal/sensors/2.1/Android.bp
index e33e8ad..1243675 100644
--- a/hal/sensors/2.0/Android.bp
+++ b/hal/sensors/2.1/Android.bp
@@ -18,7 +18,7 @@
 }
 
 cc_library {
-    name: "android.hardware.sensors@2.0-Google-IIO-Subhal",
+    name: "android.hardware.sensors@2.1-Google-IIO-Subhal",
     vendor: true,
     srcs: [
         "iio_utils.cpp",
@@ -28,11 +28,12 @@
         "SensorThread.cpp",
     ],
     header_libs: [
-        "android.hardware.sensors@2.0-multihal.header",
+        "android.hardware.sensors@2.1-multihal.header",
     ],
     shared_libs: [
         "android.hardware.sensors@1.0",
         "android.hardware.sensors@2.0",
+        "android.hardware.sensors@2.1",
         "android.hardware.sensors@2.0-ScopedWakelock",
         "libcutils",
         "libfmq",
@@ -57,7 +58,7 @@
 }
 
 cc_test_host {
-    name: "android.hardware.sensors@2.0-Google-IIO-Subhal_test",
+    name: "android.hardware.sensors@2.1-Google-IIO-Subhal_test",
     srcs: [
         "iio_utils.cpp",
         "tests/IioUtilsTest.cpp",
@@ -66,6 +67,7 @@
         "libgtest",
         "android.hardware.sensors@1.0",
         "android.hardware.sensors@2.0",
+        "android.hardware.sensors@2.1",
     ],
     shared_libs: [
         "libbase",
@@ -74,7 +76,7 @@
 }
 
 cc_test_host {
-    name: "android.hardware.sensors@2.0-Google-IIO-Subhal_test-MultiPoll",
+    name: "android.hardware.sensors@2.1-Google-IIO-Subhal_test-MultiPoll",
     srcs: [
         "MultiPoll.cpp",
         "tests/MultiPoll.cpp"
@@ -83,6 +85,7 @@
         "libgtest",
         "android.hardware.sensors@1.0",
         "android.hardware.sensors@2.0",
+        "android.hardware.sensors@2.1",
     ],
     shared_libs: [
         "libbase",
diff --git a/hal/sensors/2.0/MultiPoll.cpp b/hal/sensors/2.1/MultiPoll.cpp
similarity index 91%
rename from hal/sensors/2.0/MultiPoll.cpp
rename to hal/sensors/2.1/MultiPoll.cpp
index 7014c98..65369c2 100644
--- a/hal/sensors/2.0/MultiPoll.cpp
+++ b/hal/sensors/2.1/MultiPoll.cpp
@@ -16,7 +16,7 @@
 
 #include "MultiPoll.h"
 
-namespace android::hardware::sensors::V2_0::subhal::implementation {
+namespace android::hardware::sensors::V2_1::subhal::implementation {
 
 MultiPoll::MultiPoll(uint64_t periodMs) : mSamplingPeriodMs(periodMs) {}
 
@@ -46,4 +46,4 @@
     return 0;
 }
 
-}  // namespace android::hardware::sensors::V2_0::subhal::implementation
+}  // namespace android::hardware::sensors::V2_1::subhal::implementation
diff --git a/hal/sensors/2.0/MultiPoll.h b/hal/sensors/2.1/MultiPoll.h
similarity index 89%
rename from hal/sensors/2.0/MultiPoll.h
rename to hal/sensors/2.1/MultiPoll.h
index e6ee889..08994b7 100644
--- a/hal/sensors/2.0/MultiPoll.h
+++ b/hal/sensors/2.1/MultiPoll.h
@@ -21,7 +21,7 @@
 #include <mutex>
 #include <vector>
 
-namespace android::hardware::sensors::V2_0::subhal::implementation {
+namespace android::hardware::sensors::V2_1::subhal::implementation {
 
 class MultiPoll {
   public:
@@ -39,4 +39,4 @@
     std::vector<pollfd> mDescriptors;
 };
 
-}  // namespace android::hardware::sensors::V2_0::subhal::implementation
+}  // namespace android::hardware::sensors::V2_1::subhal::implementation
diff --git a/hal/sensors/2.0/OWNERS b/hal/sensors/2.1/OWNERS
similarity index 97%
rename from hal/sensors/2.0/OWNERS
rename to hal/sensors/2.1/OWNERS
index 7644fa1..e51139a 100644
--- a/hal/sensors/2.0/OWNERS
+++ b/hal/sensors/2.1/OWNERS
@@ -1,3 +1,2 @@
 ankitarora@google.com
 egranata@google.com
-
diff --git a/hal/sensors/2.0/README b/hal/sensors/2.1/README
similarity index 86%
rename from hal/sensors/2.0/README
rename to hal/sensors/2.1/README
index dc813ff..9a0e6f9 100644
--- a/hal/sensors/2.0/README
+++ b/hal/sensors/2.1/README
@@ -1,5 +1,5 @@
 This directory contains a reference implementation for sensors sub-HAL to be
-used by sensors Multi-Hal 2.0 service for Android Automotive OS with Android
+used by sensors Multi-Hal 2.1 service for Android Automotive OS with Android
 running as a VM. This HAL accesses sensors exposed as IIO devices by the kernel.
 
 This HAL is currently only supported for use with the IIO SCMI driver in the kernel
diff --git a/hal/sensors/2.0/Sensor.cpp b/hal/sensors/2.1/Sensor.cpp
similarity index 97%
rename from hal/sensors/2.0/Sensor.cpp
rename to hal/sensors/2.1/Sensor.cpp
index d53a11e..bfa1ca0 100644
--- a/hal/sensors/2.0/Sensor.cpp
+++ b/hal/sensors/2.1/Sensor.cpp
@@ -24,7 +24,7 @@
 namespace android {
 namespace hardware {
 namespace sensors {
-namespace V2_0 {
+namespace V2_1 {
 namespace subhal {
 namespace implementation {
 
@@ -114,7 +114,9 @@
         });
     }
 
-    if (!events.empty()) mCallback->postEvents(events, isWakeUpSensor());
+    if (!events.empty()) {
+        mCallback->postEvents(events, mCallback->createScopedWakelock(isWakeUpSensor()));
+    }
 }
 
 void HWSensorBase::activate(bool enable) {
@@ -141,7 +143,7 @@
     ev.sensorType = SensorType::META_DATA;
     ev.u.meta.what = MetaDataEventType::META_DATA_FLUSH_COMPLETE;
     std::vector<Event> evs{ev};
-    mCallback->postEvents(evs, isWakeUpSensor());
+    mCallback->postEvents(evs, mCallback->createScopedWakelock(isWakeUpSensor()));
     return Result::OK;
 }
 
@@ -198,7 +200,7 @@
 
         Event evt;
         processScanData(&mSensorRawData[0], &evt);
-        mCallback->postEvents({evt}, isWakeUpSensor());
+        mCallback->postEvents({evt}, mCallback->createScopedWakelock(isWakeUpSensor()));
     }
 }
 
@@ -240,7 +242,7 @@
     } else if (!supportsDataInjection()) {
         result = Result::INVALID_OPERATION;
     } else if (mMode == OperationMode::DATA_INJECTION) {
-        mCallback->postEvents(std::vector<Event>{event}, isWakeUpSensor());
+        mCallback->postEvents({event}, mCallback->createScopedWakelock(isWakeUpSensor()));
     } else {
         result = Result::BAD_VALUE;
     }
@@ -488,7 +490,7 @@
 
 }  // namespace implementation
 }  // namespace subhal
-}  // namespace V2_0
+}  // namespace V2_1
 }  // namespace sensors
 }  // namespace hardware
 }  // namespace android
diff --git a/hal/sensors/2.0/Sensor.h b/hal/sensors/2.1/Sensor.h
similarity index 87%
rename from hal/sensors/2.0/Sensor.h
rename to hal/sensors/2.1/Sensor.h
index 235a286..e45cdd9 100644
--- a/hal/sensors/2.0/Sensor.h
+++ b/hal/sensors/2.1/Sensor.h
@@ -13,10 +13,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifndef ANDROID_HARDWARE_SENSORS_V2_0_SENSOR_H
-#define ANDROID_HARDWARE_SENSORS_V2_0_SENSOR_H
+#ifndef ANDROID_HARDWARE_SENSORS_V2_1_SENSOR_H
+#define ANDROID_HARDWARE_SENSORS_V2_1_SENSOR_H
 
-#include <android/hardware/sensors/1.0/types.h>
+#include <android/hardware/sensors/2.1/types.h>
 #include <poll.h>
 #include <condition_variable>
 #include <memory>
@@ -25,6 +25,7 @@
 #include <vector>
 
 #include "SensorThread.h"
+#include "V2_0/ScopedWakelock.h"
 #include "iio_utils.h"
 #include "sensor_hal_configuration_V1_0.h"
 
@@ -33,17 +34,18 @@
 #define NUM_OF_DATA_CHANNELS NUM_OF_CHANNEL_SUPPORTED - 1
 
 using ::android::hardware::sensors::V1_0::AdditionalInfo;
-using ::android::hardware::sensors::V1_0::Event;
 using ::android::hardware::sensors::V1_0::OperationMode;
 using ::android::hardware::sensors::V1_0::Result;
-using ::android::hardware::sensors::V1_0::SensorInfo;
-using ::android::hardware::sensors::V1_0::SensorType;
+using ::android::hardware::sensors::V2_0::implementation::ScopedWakelock;
+using ::android::hardware::sensors::V2_1::Event;
+using ::android::hardware::sensors::V2_1::SensorInfo;
+using ::android::hardware::sensors::V2_1::SensorType;
 using ::sensor::hal::configuration::V1_0::Configuration;
 
 namespace android {
 namespace hardware {
 namespace sensors {
-namespace V2_0 {
+namespace V2_1 {
 namespace subhal {
 namespace implementation {
 
@@ -63,7 +65,8 @@
 class ISensorsEventCallback {
   public:
     virtual ~ISensorsEventCallback() = default;
-    virtual void postEvents(const std::vector<Event>& events, bool wakeup) = 0;
+    virtual void postEvents(const std::vector<Event>& events, ScopedWakelock wakelock) = 0;
+    virtual ScopedWakelock createScopedWakelock(bool lock) = 0;
 };
 
 // Virtual Base Class for Sensor
@@ -147,8 +150,8 @@
 };
 }  // namespace implementation
 }  // namespace subhal
-}  // namespace V2_0
+}  // namespace V2_1
 }  // namespace sensors
 }  // namespace hardware
 }  // namespace android
-#endif  // ANDROID_HARDWARE_SENSORS_V2_0_SENSOR_H
+#endif  // ANDROID_HARDWARE_SENSORS_V2_1_SENSOR_H
diff --git a/hal/sensors/2.0/SensorThread.cpp b/hal/sensors/2.1/SensorThread.cpp
similarity index 91%
rename from hal/sensors/2.0/SensorThread.cpp
rename to hal/sensors/2.1/SensorThread.cpp
index 844c7db..6517769 100644
--- a/hal/sensors/2.0/SensorThread.cpp
+++ b/hal/sensors/2.1/SensorThread.cpp
@@ -17,7 +17,7 @@
 #include "SensorThread.h"
 #include "Sensor.h"
 
-namespace android::hardware::sensors::V2_0::subhal::implementation {
+namespace android::hardware::sensors::V2_1::subhal::implementation {
 
 SensorThread::SensorThread(SensorBase* sensor)
     : mSensor(sensor), mStopThread(false), mWaitCV(), mRunMutex() {}
@@ -61,4 +61,4 @@
     return std::move(std::unique_lock<std::mutex>(mRunMutex));
 }
 
-}  // namespace android::hardware::sensors::V2_0::subhal::implementation
+}  // namespace android::hardware::sensors::V2_1::subhal::implementation
diff --git a/hal/sensors/2.0/SensorThread.h b/hal/sensors/2.1/SensorThread.h
similarity index 90%
rename from hal/sensors/2.0/SensorThread.h
rename to hal/sensors/2.1/SensorThread.h
index 058f148..e0cf3ce 100644
--- a/hal/sensors/2.0/SensorThread.h
+++ b/hal/sensors/2.1/SensorThread.h
@@ -21,7 +21,7 @@
 #include <mutex>
 #include <thread>
 
-namespace android::hardware::sensors::V2_0::subhal::implementation {
+namespace android::hardware::sensors::V2_1::subhal::implementation {
 
 class SensorBase;
 
@@ -52,4 +52,4 @@
     std::thread mThread;
 };
 
-}  // namespace android::hardware::sensors::V2_0::subhal::implementation
+}  // namespace android::hardware::sensors::V2_1::subhal::implementation
diff --git a/hal/sensors/2.0/SensorsSubHal.cpp b/hal/sensors/2.1/SensorsSubHal.cpp
similarity index 92%
rename from hal/sensors/2.0/SensorsSubHal.cpp
rename to hal/sensors/2.1/SensorsSubHal.cpp
index 4a615af..6c61bc5 100644
--- a/hal/sensors/2.0/SensorsSubHal.cpp
+++ b/hal/sensors/2.1/SensorsSubHal.cpp
@@ -16,29 +16,31 @@
 #define LOG_TAG "GoogleIIOSensorSubHal"
 
 #include "SensorsSubHal.h"
-#include <android/hardware/sensors/2.0/types.h>
+#include <android/hardware/sensors/2.1/types.h>
 #include <log/log.h>
 
-ISensorsSubHal* sensorsHalGetSubHal(uint32_t* version) {
-    static ::android::hardware::sensors::V2_0::subhal::implementation::SensorsSubHal subHal;
-    *version = SUB_HAL_2_0_VERSION;
+using ::android::hardware::sensors::V2_1::implementation::ISensorsSubHal;
+
+ISensorsSubHal* sensorsHalGetSubHal_2_1(uint32_t* version) {
+    static ::android::hardware::sensors::V2_1::subhal::implementation::SensorsSubHal subHal;
+    *version = SUB_HAL_2_1_VERSION;
     return &subHal;
 }
 
 namespace android {
 namespace hardware {
 namespace sensors {
-namespace V2_0 {
+namespace V2_1 {
 namespace subhal {
 namespace implementation {
 
 using ::android::hardware::Void;
-using ::android::hardware::sensors::V1_0::Event;
 using ::android::hardware::sensors::V1_0::RateLevel;
 using ::android::hardware::sensors::V1_0::SharedMemInfo;
 using ::android::hardware::sensors::V2_0::SensorTimeout;
 using ::android::hardware::sensors::V2_0::WakeLockQueueFlagBits;
 using ::android::hardware::sensors::V2_0::implementation::ScopedWakelock;
+using ::android::hardware::sensors::V2_1::Event;
 using ::sensor::hal::configuration::V1_0::Sensor;
 using ::sensor::hal::configuration::V1_0::SensorHalConfiguration;
 
@@ -47,7 +49,7 @@
 static const int gSensorConfigLocationListSize =
         (sizeof(gSensorConfigLocationList) / sizeof(gSensorConfigLocationList[0]));
 
-#define MODULE_NAME "android.hardware.sensors@2.0-Google-IIO-Subhal"
+#define MODULE_NAME "android.hardware.sensors@2.1-Google-IIO-Subhal"
 
 static std::optional<std::vector<Sensor>> readSensorsConfigFromXml() {
     for (int i = 0; i < gSensorConfigLocationListSize; i++) {
@@ -134,8 +136,8 @@
     }
 }
 
-// Methods from ::android::hardware::sensors::V2_0::ISensors follow.
-Return<void> SensorsSubHal::getSensorsList(getSensorsList_cb _hidl_cb) {
+// Methods from ::android::hardware::sensors::V2_1::ISensors follow.
+Return<void> SensorsSubHal::getSensorsList_2_1(getSensorsList_2_1_cb _hidl_cb) {
     std::vector<SensorInfo> sensors;
     for (const auto& sensor : mSensors) {
         SensorInfo sensorInfo = sensor.second->getSensorInfo();
@@ -183,7 +185,7 @@
     return Result::BAD_VALUE;
 }
 
-Return<Result> SensorsSubHal::injectSensorData(const Event& /* event */) {
+Return<Result> SensorsSubHal::injectSensorData_2_1(const Event& /* event */) {
     return Result::INVALID_OPERATION;
 }
 
@@ -244,10 +246,14 @@
     return Result::OK;
 }
 
-void SensorsSubHal::postEvents(const std::vector<Event>& events, bool wakeup) {
-    ScopedWakelock wakelock = mCallback->createScopedWakelock(wakeup);
+void SensorsSubHal::postEvents(const std::vector<Event>& events, ScopedWakelock wakelock) {
     mCallback->postEvents(events, std::move(wakelock));
 }
+
+ScopedWakelock SensorsSubHal::createScopedWakelock(bool lock) {
+    return mCallback->createScopedWakelock(lock);
+}
+
 void SensorsSubHal::AddSensor(const struct iio_device_data& iio_data,
                               const std::optional<std::vector<Configuration>>& config) {
     HWSensorBase* sensor = HWSensorBase::buildSensor(mNextHandle++ /* sensorHandle */,
@@ -260,7 +266,7 @@
 
 }  // namespace implementation
 }  // namespace subhal
-}  // namespace V2_0
+}  // namespace V2_1
 }  // namespace sensors
 }  // namespace hardware
 }  // namespace android
diff --git a/hal/sensors/2.0/SensorsSubHal.h b/hal/sensors/2.1/SensorsSubHal.h
similarity index 79%
rename from hal/sensors/2.0/SensorsSubHal.h
rename to hal/sensors/2.1/SensorsSubHal.h
index 26a5aad..0d5d82a 100644
--- a/hal/sensors/2.0/SensorsSubHal.h
+++ b/hal/sensors/2.1/SensorsSubHal.h
@@ -13,26 +13,27 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifndef ANDROID_HARDWARE_SENSORS_V2_0_SENSORS_SUBHAL_H
-#define ANDROID_HARDWARE_SENSORS_V2_0_SENSORS_SUBHAL_H
+#ifndef ANDROID_HARDWARE_SENSORS_V2_1_SENSORS_SUBHAL_H
+#define ANDROID_HARDWARE_SENSORS_V2_1_SENSORS_SUBHAL_H
 
 #include <vector>
 #include "Sensor.h"
 #include "SubHal.h"
 
-using ::android::hardware::sensors::V1_0::SensorType;
+using ::android::hardware::sensors::V2_1::SensorType;
 
 namespace android {
 namespace hardware {
 namespace sensors {
-namespace V2_0 {
+namespace V2_1 {
 namespace subhal {
 namespace implementation {
 
 using ::android::hardware::sensors::V1_0::OperationMode;
 using ::android::hardware::sensors::V1_0::Result;
-using ::android::hardware::sensors::V2_0::implementation::IHalProxyCallback;
-using ::android::hardware::sensors::V2_0::subhal::implementation::ISensorsEventCallback;
+using ::android::hardware::sensors::V2_1::implementation::IHalProxyCallback;
+using ::android::hardware::sensors::V2_1::implementation::ISensorsSubHal;
+using ::android::hardware::sensors::V2_1::subhal::implementation::ISensorsEventCallback;
 using ::sensor::hal::configuration::V1_0::Configuration;
 
 /**
@@ -40,15 +41,16 @@
  * multihal 2.0. See the README file for more details.
  */
 class SensorsSubHal : public ISensorsSubHal, public ISensorsEventCallback {
-    using Event = ::android::hardware::sensors::V1_0::Event;
+    using Event = ::android::hardware::sensors::V2_1::Event;
     using RateLevel = ::android::hardware::sensors::V1_0::RateLevel;
     using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo;
+    using ScopedWakelock = ::android::hardware::sensors::V2_0::implementation::ScopedWakelock;
 
   public:
     SensorsSubHal();
 
-    // Methods from ::android::hardware::sensors::V2_0::ISensors follow.
-    Return<void> getSensorsList(getSensorsList_cb _hidl_cb) override;
+    // Methods from ::android::hardware::sensors::V2_1::ISensors follow.
+    Return<void> getSensorsList_2_1(getSensorsList_2_1_cb _hidl_cb) override;
 
     Return<Result> setOperationMode(OperationMode mode) override;
 
@@ -61,7 +63,7 @@
 
     Return<Result> flush(int32_t sensorHandle) override;
 
-    Return<Result> injectSensorData(const Event& event) override;
+    Return<Result> injectSensorData_2_1(const Event& event) override;
 
     Return<void> registerDirectChannel(const SharedMemInfo& mem,
                                        registerDirectChannel_cb _hidl_cb) override;
@@ -79,7 +81,9 @@
     Return<Result> initialize(const sp<IHalProxyCallback>& halProxyCallback) override;
 
     // Method from ISensorsEventCallback.
-    void postEvents(const std::vector<Event>& events, bool wakeup) override;
+    void postEvents(const std::vector<Event>& events, ScopedWakelock wakelock) override;
+
+    ScopedWakelock createScopedWakelock(bool lock) override;
 
   protected:
     void AddSensor(const struct iio_device_data& iio_data,
@@ -112,7 +116,7 @@
 
 }  // namespace implementation
 }  // namespace subhal
-}  // namespace V2_0
+}  // namespace V2_1
 }  // namespace sensors
 }  // namespace hardware
 }  // namespace android
diff --git a/hal/sensors/2.0/config/Android.bp b/hal/sensors/2.1/config/Android.bp
similarity index 100%
rename from hal/sensors/2.0/config/Android.bp
rename to hal/sensors/2.1/config/Android.bp
diff --git a/hal/sensors/2.0/config/api/current.txt b/hal/sensors/2.1/config/api/current.txt
similarity index 100%
rename from hal/sensors/2.0/config/api/current.txt
rename to hal/sensors/2.1/config/api/current.txt
diff --git a/hal/sensors/2.0/config/api/last_current.txt b/hal/sensors/2.1/config/api/last_current.txt
similarity index 100%
rename from hal/sensors/2.0/config/api/last_current.txt
rename to hal/sensors/2.1/config/api/last_current.txt
diff --git a/hal/sensors/2.0/config/api/last_removed.txt b/hal/sensors/2.1/config/api/last_removed.txt
similarity index 100%
rename from hal/sensors/2.0/config/api/last_removed.txt
rename to hal/sensors/2.1/config/api/last_removed.txt
diff --git a/hal/sensors/2.0/config/api/removed.txt b/hal/sensors/2.1/config/api/removed.txt
similarity index 100%
rename from hal/sensors/2.0/config/api/removed.txt
rename to hal/sensors/2.1/config/api/removed.txt
diff --git a/hal/sensors/2.0/config/sensor_hal_configuration.xml b/hal/sensors/2.1/config/sensor_hal_configuration.xml
similarity index 95%
rename from hal/sensors/2.0/config/sensor_hal_configuration.xml
rename to hal/sensors/2.1/config/sensor_hal_configuration.xml
index cdf8732..8985fe1 100644
--- a/hal/sensors/2.0/config/sensor_hal_configuration.xml
+++ b/hal/sensors/2.1/config/sensor_hal_configuration.xml
@@ -16,7 +16,7 @@
 
 <sensorHalConfiguration version="1.0" xmlns:xi="http://www.w3.org/2001/XInclude">
     <modules>
-        <module halName="android.hardware.sensors@2.0-Google-IIO-Subhal" halVersion="2.0">
+        <module halName="android.hardware.sensors@2.1-Google-IIO-Subhal" halVersion="2.1">
             <sensors>
                 <sensor name="scmi.iio.accel" type="1">
                     <configuration>
diff --git a/hal/sensors/2.0/config/sensor_hal_configuration.xsd b/hal/sensors/2.1/config/sensor_hal_configuration.xsd
similarity index 96%
rename from hal/sensors/2.0/config/sensor_hal_configuration.xsd
rename to hal/sensors/2.1/config/sensor_hal_configuration.xsd
index 78a42e6..a55eaf0 100644
--- a/hal/sensors/2.0/config/sensor_hal_configuration.xsd
+++ b/hal/sensors/2.1/config/sensor_hal_configuration.xsd
@@ -40,7 +40,9 @@
         </xs:sequence>
     </xs:complexType>
     <!-- attribute type describes the sensor type. Possible values are the Enum
-        values of SensorType specified in hardware/interfaces/sensors/1.0/types.hal
+        values of SensorType specified in hardware/interfaces/sensors/2.1/types.hal
+        (which inherits most of its values from SensorType in
+        hardware/interfaces/sensors/1.0/types.hal)
     -->
     <xs:complexType name="sensor">
         <xs:sequence>
diff --git a/hal/sensors/2.0/iio_utils.cpp b/hal/sensors/2.1/iio_utils.cpp
similarity index 99%
rename from hal/sensors/2.0/iio_utils.cpp
rename to hal/sensors/2.1/iio_utils.cpp
index 84360b2..2b5abe9 100644
--- a/hal/sensors/2.0/iio_utils.cpp
+++ b/hal/sensors/2.1/iio_utils.cpp
@@ -40,7 +40,7 @@
 namespace android {
 namespace hardware {
 namespace sensors {
-namespace V2_0 {
+namespace V2_1 {
 namespace subhal {
 namespace implementation {
 
@@ -413,7 +413,7 @@
 }
 }  // namespace implementation
 }  // namespace subhal
-}  // namespace V2_0
+}  // namespace V2_1
 }  // namespace sensors
 }  // namespace hardware
 }  // namespace android
diff --git a/hal/sensors/2.0/iio_utils.h b/hal/sensors/2.1/iio_utils.h
similarity index 93%
rename from hal/sensors/2.0/iio_utils.h
rename to hal/sensors/2.1/iio_utils.h
index a84d369..9415e83 100644
--- a/hal/sensors/2.0/iio_utils.h
+++ b/hal/sensors/2.1/iio_utils.h
@@ -16,7 +16,7 @@
 #ifndef ANDROID_SENSORS_IIO_UTILS_H
 #define ANDROID_SENSORS_IIO_UTILS_H
 
-#include <android/hardware/sensors/1.0/types.h>
+#include <android/hardware/sensors/2.1/types.h>
 #include <dirent.h>
 #include <linux/ioctl.h>
 #include <linux/types.h>
@@ -27,11 +27,11 @@
 namespace android {
 namespace hardware {
 namespace sensors {
-namespace V2_0 {
+namespace V2_1 {
 namespace subhal {
 namespace implementation {
 
-using ::android::hardware::sensors::V1_0::SensorType;
+using ::android::hardware::sensors::V2_1::SensorType;
 
 extern const char* DEFAULT_IIO_DIR;
 
@@ -75,7 +75,7 @@
 int set_sampling_frequency(const std::string& name, const double frequency);
 }  // namespace implementation
 }  // namespace subhal
-}  // namespace V2_0
+}  // namespace V2_1
 }  // namespace sensors
 }  // namespace hardware
 }  // namespace android
diff --git a/hal/sensors/2.0/tests/IioUtilsTest.cpp b/hal/sensors/2.1/tests/IioUtilsTest.cpp
similarity index 93%
rename from hal/sensors/2.0/tests/IioUtilsTest.cpp
rename to hal/sensors/2.1/tests/IioUtilsTest.cpp
index 034a6b8..e953b37 100644
--- a/hal/sensors/2.0/tests/IioUtilsTest.cpp
+++ b/hal/sensors/2.1/tests/IioUtilsTest.cpp
@@ -15,7 +15,7 @@
  */
 
 #include <android-base/file.h>
-#include <android/hardware/sensors/2.0/types.h>
+#include <android/hardware/sensors/2.1/types.h>
 #include <gtest/gtest.h>
 #include <sys/stat.h>
 #include <fstream>
@@ -25,10 +25,10 @@
 
 #include "iio_utils.h"
 
-using ::android::hardware::sensors::V1_0::SensorType;
-using android::hardware::sensors::V2_0::subhal::implementation::iio_device_data;
-using android::hardware::sensors::V2_0::subhal::implementation::load_iio_devices;
-using android::hardware::sensors::V2_0::subhal::implementation::sensors_supported_hal;
+using ::android::hardware::sensors::V2_1::SensorType;
+using android::hardware::sensors::V2_1::subhal::implementation::iio_device_data;
+using android::hardware::sensors::V2_1::subhal::implementation::load_iio_devices;
+using android::hardware::sensors::V2_1::subhal::implementation::sensors_supported_hal;
 
 static bool sensorFilter(iio_device_data* dev) {
     static std::map<std::string, SensorType> KNOWN_SENSORS = {
diff --git a/hal/sensors/2.0/tests/MultiPoll.cpp b/hal/sensors/2.1/tests/MultiPoll.cpp
similarity index 98%
rename from hal/sensors/2.0/tests/MultiPoll.cpp
rename to hal/sensors/2.1/tests/MultiPoll.cpp
index 5adef7e..86f5f6e 100644
--- a/hal/sensors/2.0/tests/MultiPoll.cpp
+++ b/hal/sensors/2.1/tests/MultiPoll.cpp
@@ -21,7 +21,7 @@
 
 #include "MultiPoll.h"
 
-using android::hardware::sensors::V2_0::subhal::implementation::MultiPoll;
+using android::hardware::sensors::V2_1::subhal::implementation::MultiPoll;
 
 // using namespace here is the sanctioned C++ way
 // NOLINTNEXTLINE(build/namespaces)
diff --git a/product_files/vendor/etc/sensors/hals.conf b/product_files/vendor/etc/sensors/hals.conf
index e7c145b..98c3447 100644
--- a/product_files/vendor/etc/sensors/hals.conf
+++ b/product_files/vendor/etc/sensors/hals.conf
@@ -1 +1 @@
-/vendor/lib64/android.hardware.sensors@2.0-Google-IIO-Subhal.so
+/vendor/lib64/android.hardware.sensors@2.1-Google-IIO-Subhal.so