From 08315ccbb6f515e919f4758ed0de52e4dc5cb2cf Mon Sep 17 00:00:00 2001 From: Vladimir Komsiyski Date: Tue, 6 Dec 2022 13:26:09 +0100 Subject: [PATCH] Define the runtime sensor handle range in ISensors.aidl Add a test to make sure that there are no sensors with handles within this range in the HAL. Fix: 259227294 Test: VtsAidlHalSensorsTargetTest Change-Id: Ib785984a0b43457eacd41031bbf361375f9d21f8 --- compatibility_matrices/compatibility_matrix.current.xml | 1 + .../current/android/hardware/sensors/ISensors.aidl | 2 ++ sensors/aidl/android/hardware/sensors/ISensors.aidl | 9 +++++++++ sensors/aidl/convert/Android.bp | 2 +- sensors/aidl/default/Android.bp | 4 ++-- sensors/aidl/default/multihal/Android.bp | 2 +- sensors/aidl/default/sensors-default.xml | 2 +- sensors/aidl/multihal/Android.bp | 2 +- .../aidl/multihal/android.hardware.sensors-multihal.xml | 2 +- sensors/aidl/vts/Android.bp | 2 +- sensors/aidl/vts/VtsAidlHalSensorsTargetTest.cpp | 7 ++++++- 11 files changed, 26 insertions(+), 9 deletions(-) diff --git a/compatibility_matrices/compatibility_matrix.current.xml b/compatibility_matrices/compatibility_matrix.current.xml index f8954a3f7c..7a29485289 100644 --- a/compatibility_matrices/compatibility_matrix.current.xml +++ b/compatibility_matrices/compatibility_matrix.current.xml @@ -593,6 +593,7 @@ android.hardware.sensors + 2 ISensors default diff --git a/sensors/aidl/aidl_api/android.hardware.sensors/current/android/hardware/sensors/ISensors.aidl b/sensors/aidl/aidl_api/android.hardware.sensors/current/android/hardware/sensors/ISensors.aidl index f60f5bb247..b26040b56d 100644 --- a/sensors/aidl/aidl_api/android.hardware.sensors/current/android/hardware/sensors/ISensors.aidl +++ b/sensors/aidl/aidl_api/android.hardware.sensors/current/android/hardware/sensors/ISensors.aidl @@ -58,6 +58,8 @@ interface ISensors { const int DIRECT_REPORT_SENSOR_EVENT_OFFSET_SIZE_DATA = 24; const int DIRECT_REPORT_SENSOR_EVENT_OFFSET_SIZE_RESERVED = 88; const int DIRECT_REPORT_SENSOR_EVENT_TOTAL_LENGTH = 104; + const int RUNTIME_SENSORS_HANDLE_BASE = 1593835520; + const int RUNTIME_SENSORS_HANDLE_END = 1610612735; @Backing(type="int") @VintfStability enum RateLevel { STOP = 0, diff --git a/sensors/aidl/android/hardware/sensors/ISensors.aidl b/sensors/aidl/android/hardware/sensors/ISensors.aidl index 2c684897cf..5e276dd90a 100644 --- a/sensors/aidl/android/hardware/sensors/ISensors.aidl +++ b/sensors/aidl/android/hardware/sensors/ISensors.aidl @@ -371,4 +371,13 @@ interface ISensors { const int DIRECT_REPORT_SENSOR_EVENT_OFFSET_SIZE_DATA = 0x18; const int DIRECT_REPORT_SENSOR_EVENT_OFFSET_SIZE_RESERVED = 0x58; const int DIRECT_REPORT_SENSOR_EVENT_TOTAL_LENGTH = 104; + + /** + * Constants related to reserved sensor handle ranges. + * + * The following range (inclusive) is reserved for usage by the system for + * runtime sensors. + */ + const int RUNTIME_SENSORS_HANDLE_BASE = 0x5F000000; + const int RUNTIME_SENSORS_HANDLE_END = 0x5FFFFFFF; } diff --git a/sensors/aidl/convert/Android.bp b/sensors/aidl/convert/Android.bp index d47de8ec6d..79e6263d5d 100644 --- a/sensors/aidl/convert/Android.bp +++ b/sensors/aidl/convert/Android.bp @@ -35,7 +35,7 @@ cc_library_static { "libhardware", "libbase", "libutils", - "android.hardware.sensors-V1-ndk", + "android.hardware.sensors-V2-ndk", ], local_include_dirs: ["include/aidl/sensors"], export_shared_lib_headers: [ diff --git a/sensors/aidl/default/Android.bp b/sensors/aidl/default/Android.bp index 3c66744324..16b4d3558a 100644 --- a/sensors/aidl/default/Android.bp +++ b/sensors/aidl/default/Android.bp @@ -41,7 +41,7 @@ cc_library_static { "libfmq", "libpower", "libbinder_ndk", - "android.hardware.sensors-V1-ndk", + "android.hardware.sensors-V2-ndk", ], export_include_dirs: ["include"], srcs: [ @@ -68,7 +68,7 @@ cc_binary { "libcutils", "liblog", "libutils", - "android.hardware.sensors-V1-ndk", + "android.hardware.sensors-V2-ndk", ], static_libs: [ "libsensorsexampleimpl", diff --git a/sensors/aidl/default/multihal/Android.bp b/sensors/aidl/default/multihal/Android.bp index eee10625bb..a20d6d7434 100644 --- a/sensors/aidl/default/multihal/Android.bp +++ b/sensors/aidl/default/multihal/Android.bp @@ -38,7 +38,7 @@ cc_library_static { "android.hardware.sensors@1.0", "android.hardware.sensors@2.0", "android.hardware.sensors@2.1", - "android.hardware.sensors-V1-ndk", + "android.hardware.sensors-V2-ndk", ], export_include_dirs: ["include"], srcs: [ diff --git a/sensors/aidl/default/sensors-default.xml b/sensors/aidl/default/sensors-default.xml index 7898a6bab0..36b28ed0a6 100644 --- a/sensors/aidl/default/sensors-default.xml +++ b/sensors/aidl/default/sensors-default.xml @@ -1,7 +1,7 @@ android.hardware.sensors - 1 + 2 ISensors/default diff --git a/sensors/aidl/multihal/Android.bp b/sensors/aidl/multihal/Android.bp index 6d35dafd6d..522d305d86 100644 --- a/sensors/aidl/multihal/Android.bp +++ b/sensors/aidl/multihal/Android.bp @@ -40,7 +40,7 @@ cc_binary { "android.hardware.sensors@2.0-ScopedWakelock", "android.hardware.sensors@2.0", "android.hardware.sensors@2.1", - "android.hardware.sensors-V1-ndk", + "android.hardware.sensors-V2-ndk", "libbase", "libcutils", "libfmq", diff --git a/sensors/aidl/multihal/android.hardware.sensors-multihal.xml b/sensors/aidl/multihal/android.hardware.sensors-multihal.xml index d78edffaf9..5da4fbd9a1 100644 --- a/sensors/aidl/multihal/android.hardware.sensors-multihal.xml +++ b/sensors/aidl/multihal/android.hardware.sensors-multihal.xml @@ -17,7 +17,7 @@ android.hardware.sensors - 1 + 2 ISensors/default diff --git a/sensors/aidl/vts/Android.bp b/sensors/aidl/vts/Android.bp index f3972ec2a3..c17a5585fd 100644 --- a/sensors/aidl/vts/Android.bp +++ b/sensors/aidl/vts/Android.bp @@ -41,7 +41,7 @@ cc_test { "android.hardware.common.fmq-V1-ndk", ], static_libs: [ - "android.hardware.sensors-V1-ndk", + "android.hardware.sensors-V2-ndk", "VtsHalSensorsTargetTestUtils", "libaidlcommonsupport", ], diff --git a/sensors/aidl/vts/VtsAidlHalSensorsTargetTest.cpp b/sensors/aidl/vts/VtsAidlHalSensorsTargetTest.cpp index d536e290b2..ad58e213ef 100644 --- a/sensors/aidl/vts/VtsAidlHalSensorsTargetTest.cpp +++ b/sensors/aidl/vts/VtsAidlHalSensorsTargetTest.cpp @@ -560,10 +560,15 @@ TEST_P(SensorsAidlTest, SensorListValid) { EXPECT_NO_FATAL_FAILURE(assertTypeMatchStringType(info.type, info.typeAsString)); } - // Test if all sensor has name and vendor + // Test if all sensors have name and vendor EXPECT_FALSE(info.name.empty()); EXPECT_FALSE(info.vendor.empty()); + // Make sure that the sensor handle is not within the reserved range for runtime + // sensors. + EXPECT_FALSE(ISensors::RUNTIME_SENSORS_HANDLE_BASE <= info.sensorHandle && + info.sensorHandle <= ISensors::RUNTIME_SENSORS_HANDLE_END); + // Make sure that sensors of the same type have a unique name. std::vector& v = sensorTypeNameMap[static_cast(info.type)]; bool isUniqueName = std::find(v.begin(), v.end(), info.name) == v.end();