Merge "coverity check: to make code more efficient and robust" into main
diff --git a/Android.bp b/Android.bp
index 210db85..67d6868 100644
--- a/Android.bp
+++ b/Android.bp
@@ -92,6 +92,7 @@
 
     srcs: ["hardware.c"],
     shared_libs: [
+        "libapexsupport",
         "libcutils",
         "liblog",
         "libvndksupport",
@@ -108,17 +109,31 @@
     host_supported: true,
     recovery_available: true,
     vendor_available: true,
-    vndk: {
-        enabled: true,
-        support_system_process: true,
-    },
+    double_loadable: true,
     target: {
         host: {
-            exclude_shared_libs: ["libvndksupport"],
+            exclude_shared_libs: [
+                "libapexsupport",
+                "libvndksupport",
+            ],
         },
         recovery: {
-            exclude_shared_libs: ["libvndksupport"],
+            exclude_shared_libs: [
+                "libapexsupport",
+                "libvndksupport",
+            ],
+        },
+        non_apex: {
+            exclude_shared_libs: [
+                "libapexsupport",
+            ],
         },
     },
     min_sdk_version: "29",
 }
+
+dirgroup {
+    name: "trusty_dirgroup_hardware_libhardware",
+    dirs: ["."],
+    visibility: ["//trusty/vendor/google/aosp/scripts"],
+}
diff --git a/Android.mk b/Android.mk
deleted file mode 100644
index d764008..0000000
--- a/Android.mk
+++ /dev/null
@@ -1,3 +0,0 @@
-# Copyright 2006 The Android Open Source Project
-
-include $(call all-named-subdir-makefiles,modules)
diff --git a/hardware.c b/hardware.c
index d0e91e9..a89077d 100644
--- a/hardware.c
+++ b/hardware.c
@@ -34,17 +34,21 @@
 #include <vndksupport/linker.h>
 #endif
 
+#ifdef __ANDROID_APEX__
+#include <android/apexsupport.h>
+#endif
+
 /** Base path of the hal modules */
 #if defined(__LP64__)
-#define HAL_LIBRARY_PATH1 "/system/lib64/hw"
-#define HAL_LIBRARY_PATH2 "/vendor/lib64/hw"
-#define HAL_LIBRARY_PATH3 "/odm/lib64/hw"
+#define HAL_LIBRARY_SUBDIR "lib64/hw"
 #else
-#define HAL_LIBRARY_PATH1 "/system/lib/hw"
-#define HAL_LIBRARY_PATH2 "/vendor/lib/hw"
-#define HAL_LIBRARY_PATH3 "/odm/lib/hw"
+#define HAL_LIBRARY_SUBDIR "lib/hw"
 #endif
 
+#define HAL_LIBRARY_PATH1 "/system/" HAL_LIBRARY_SUBDIR
+#define HAL_LIBRARY_PATH2 "/vendor/" HAL_LIBRARY_SUBDIR
+#define HAL_LIBRARY_PATH3 "/odm/" HAL_LIBRARY_SUBDIR
+
 /**
  * There are a set of variant filename for modules. The form of the filename
  * is "<MODULE_ID>.variant.so" so for the led module the Dream variants 
@@ -79,7 +83,7 @@
     int status = -EINVAL;
     void *handle = NULL;
     struct hw_module_t *hmi = NULL;
-#ifdef __ANDROID_VNDK__
+#if defined(__ANDROID_VNDK__) || defined(__ANDROID_APEX__)
     const bool try_system = false;
 #else
     const bool try_system = true;
@@ -97,7 +101,7 @@
          */
         handle = dlopen(path, RTLD_NOW);
     } else {
-#if defined(__ANDROID_RECOVERY__) || !defined(__ANDROID__)
+#if defined(__ANDROID_RECOVERY__) || !defined(__ANDROID__) || defined(__ANDROID_APEX__)
         handle = dlopen(path, RTLD_NOW);
 #else
         handle = android_load_sphal_library(path, RTLD_NOW);
@@ -151,7 +155,7 @@
 /*
  * If path is in in_path.
  */
-static bool path_in_path(const char *path, const char *in_path) {
+static bool __attribute__ ((unused)) path_in_path(const char *path, const char *in_path) {
     char real_path[PATH_MAX];
     if (realpath(path, real_path) == NULL) return false;
 
@@ -174,6 +178,20 @@
 static int hw_module_exists(char *path, size_t path_len, const char *name,
                             const char *subname)
 {
+#ifdef __ANDROID_APEX__
+    // When used in VAPEX, it should look only into the same APEX because
+    // libhardware modules don't provide ABI stability.
+    if (__builtin_available(android __ANDROID_API_V__, *)) {
+        AApexInfo *apex_info;
+        if (AApexInfo_create(&apex_info) == AAPEXINFO_OK) {
+            snprintf(path, path_len, "/apex/%s/%s/%s.%s.so",
+                    AApexInfo_getName(apex_info), HAL_LIBRARY_SUBDIR, name, subname);
+            AApexInfo_destroy(apex_info);
+            if (access(path, R_OK) == 0)
+                return 0;
+        }
+    }
+#else // __ANDROID_APEX__
     snprintf(path, path_len, "%s/%s.%s.so",
              HAL_LIBRARY_PATH3, name, subname);
     if (path_in_path(path, HAL_LIBRARY_PATH3) && access(path, R_OK) == 0)
@@ -191,6 +209,8 @@
         return 0;
 #endif
 
+#endif // __ANDROID_APEX__
+
     return -ENOENT;
 }
 
diff --git a/include_all/hardware/keymaster_defs.h b/include_all/hardware/keymaster_defs.h
index dd286d6..6f9f7bf 100644
--- a/include_all/hardware/keymaster_defs.h
+++ b/include_all/hardware/keymaster_defs.h
@@ -177,6 +177,8 @@
     KM_TAG_STORAGE_KEY = KM_BOOL | 722,             /* storage encryption key */
     KM_TAG_ATTESTATION_ID_SECOND_IMEI = KM_BYTES | 723,   /* Used to provide the device's second
                                                              IMEI to be included in attestation */
+    KM_TAG_MODULE_HASH = KM_BYTES | 724,            /* Used to record the hash of apex module
+                                                       information to be included in attestation */
 
     /* Tags used only to provide data to or receive data from operations */
     KM_TAG_ASSOCIATED_DATA = KM_BYTES | 1000, /* Used to provide associated data for AEAD modes. */
@@ -516,6 +518,8 @@
     KM_ERROR_MISSING_ISSUER_SUBJECT = -82,
     KM_ERROR_INVALID_ISSUER_SUBJECT = -83,
     KM_ERROR_BOOT_LEVEL_EXCEEDED = -84,
+    KM_ERROR_HARDWARE_NOT_YET_AVAILABLE = -85,
+    KM_ERROR_MODULE_HASH_ALREADY_SET = -86,
 
     KM_ERROR_UNIMPLEMENTED = -100,
     KM_ERROR_VERSION_MISMATCH = -101,
diff --git a/include_all/hardware/sensors.h b/include_all/hardware/sensors.h
index 7b844b8..5f490b5 100644
--- a/include_all/hardware/sensors.h
+++ b/include_all/hardware/sensors.h
@@ -481,7 +481,7 @@
 
     uint32_t reserved1[3];
 } sensors_event_t;
-// LINT.ThenChange (frameworks/native/include/android/sensor.h)
+// LINT.ThenChange(frameworks/native/include/android/sensor.h)
 
 
 /* see SENSOR_TYPE_META_DATA */
diff --git a/modules/Android.mk b/modules/Android.mk
deleted file mode 100644
index 9d934c5..0000000
--- a/modules/Android.mk
+++ /dev/null
@@ -1,5 +0,0 @@
-hardware_modules := \
-    camera \
-    gralloc \
-    sensors
-include $(call all-named-subdir-makefiles,$(hardware_modules))
diff --git a/modules/audio_remote_submix/audio_hw.cpp b/modules/audio_remote_submix/audio_hw.cpp
index 5019ae5..d6c8c7b 100644
--- a/modules/audio_remote_submix/audio_hw.cpp
+++ b/modules/audio_remote_submix/audio_hw.cpp
@@ -199,9 +199,9 @@
 // Determine whether the specified sample rate is supported by the submix module.
 static bool sample_rate_supported(const uint32_t sample_rate)
 {
-    // Set of sample rates supported by Format_from_SR_C() frameworks/av/media/libnbaio/NAIO.cpp.
     static const unsigned int supported_sample_rates[] = {
         8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000,
+        192000 /* for IEC 61937 encapsulated E-AC-3(-JOC) */
     };
     bool return_value;
     SUBMIX_VALUE_IN_SET(sample_rate, supported_sample_rates, &return_value);
@@ -1240,6 +1240,10 @@
     *stream_out = NULL;
 
     // Make sure it's possible to open the device given the current audio config.
+    if (!audio_is_linear_pcm(config->format)) {
+        ALOGD("adev_open_output_stream(): not supported for audio format %#x", config->format);
+        return -EINVAL;
+    }
     submix_sanitize_config(config, false);
 
     int route_idx = -1;
@@ -1455,6 +1459,11 @@
 
     *stream_in = NULL;
 
+    if (!audio_is_linear_pcm(config->format)) {
+        ALOGD("adev_open_input_stream(): not supported for audio format %#x", config->format);
+        return -EINVAL;
+    }
+
     // Do we already have a route for this address
     int route_idx = -1;
 
diff --git a/modules/camera/3_4/Android.bp b/modules/camera/3_4/Android.bp
new file mode 100644
index 0000000..3e3ba0a
--- /dev/null
+++ b/modules/camera/3_4/Android.bp
@@ -0,0 +1,132 @@
+//
+// Copyright 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.
+//
+package {
+    // See: http://go/android-license-faq
+    default_applicable_licenses: [
+        "hardware_libhardware_license",
+    ],
+    default_team: "trendy_team_camera_framework",
+}
+
+v4l2_shared_libs = [
+    "libbase",
+    "libchrome",
+    "libcamera_client",
+    "libcamera_metadata",
+    "libcutils",
+    "libexif",
+    "libhardware",
+    "liblog",
+    "libsync",
+    "libutils",
+]
+
+v4l2_static_libs = [
+    "libyuv_static",
+    "libjpeg_static_ndk",
+]
+
+v4l2_cflags = [
+    "-fno-short-enums",
+    "-Wall",
+    "-Wextra",
+    "-Werror",
+    "-fvisibility=hidden",
+    "-DHAVE_JPEG",
+]
+
+v4l2_c_includes = [
+    "system/media/camera/include",
+]
+
+v4l2_src_files = [
+    "arc/cached_frame.cpp",
+    "arc/exif_utils.cpp",
+    "arc/frame_buffer.cpp",
+    "arc/image_processor.cpp",
+    "arc/jpeg_compressor.cpp",
+    "camera.cpp",
+    "capture_request.cpp",
+    "format_metadata_factory.cpp",
+    "metadata/boottime_state_delegate.cpp",
+    "metadata/enum_converter.cpp",
+    "metadata/metadata.cpp",
+    "metadata/metadata_reader.cpp",
+    "request_tracker.cpp",
+    "static_properties.cpp",
+    "stream_format.cpp",
+    "v4l2_camera.cpp",
+    "v4l2_camera_hal.cpp",
+    "v4l2_metadata_factory.cpp",
+    "v4l2_wrapper.cpp",
+]
+
+v4l2_test_files = [
+    "format_metadata_factory_test.cpp",
+    "metadata/control_test.cpp",
+    "metadata/default_option_delegate_test.cpp",
+    "metadata/enum_converter_test.cpp",
+    "metadata/ignored_control_delegate_test.cpp",
+    "metadata/map_converter_test.cpp",
+    "metadata/menu_control_options_test.cpp",
+    "metadata/metadata_reader_test.cpp",
+    "metadata/metadata_test.cpp",
+    "metadata/no_effect_control_delegate_test.cpp",
+    "metadata/partial_metadata_factory_test.cpp",
+    "metadata/property_test.cpp",
+    "metadata/ranged_converter_test.cpp",
+    "metadata/slider_control_options_test.cpp",
+    "metadata/state_test.cpp",
+    "metadata/tagged_control_delegate_test.cpp",
+    "metadata/tagged_control_options_test.cpp",
+    "metadata/v4l2_control_delegate_test.cpp",
+    "request_tracker_test.cpp",
+    "static_properties_test.cpp",
+]
+
+// V4L2 Camera HAL.
+// ==============================================================================
+cc_library_shared {
+    name: "camera.v4l2",
+    relative_install_path: "hw",
+    cflags: v4l2_cflags,
+    shared_libs: v4l2_shared_libs,
+    header_libs: ["libgtest_prod_headers"],
+    static_libs: v4l2_static_libs,
+
+    include_dirs: v4l2_c_includes,
+    srcs: v4l2_src_files,
+    enabled: select(soong_config_variable("camera", "use_camera_v4l2_hal"), {
+        true: true,
+        default: false,
+    }),
+}
+
+// Unit tests for V4L2 Camera HAL.
+// ==============================================================================
+cc_test {
+    name: "camera.v4l2_test",
+    cflags: v4l2_cflags,
+    shared_libs: v4l2_shared_libs,
+    static_libs: ["libgmock"] + v4l2_static_libs,
+
+    include_dirs: v4l2_c_includes,
+    srcs: v4l2_src_files + v4l2_test_files,
+    enabled: select(soong_config_variable("camera", "use_camera_v4l2_hal"), {
+        true: true,
+        default: false,
+    }),
+}
diff --git a/modules/camera/3_4/Android.mk b/modules/camera/3_4/Android.mk
deleted file mode 100644
index aa23097..0000000
--- a/modules/camera/3_4/Android.mk
+++ /dev/null
@@ -1,124 +0,0 @@
-#
-# Copyright 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-# Prevent the HAL from building on devices not specifically
-# requesting to use it.
-ifeq ($(USE_CAMERA_V4L2_HAL), true)
-
-v4l2_shared_libs := \
-  libbase \
-  libchrome \
-  libcamera_client \
-  libcamera_metadata \
-  libcutils \
-  libexif \
-  libhardware \
-  liblog \
-  libsync \
-  libutils \
-
-v4l2_static_libs := \
-  libyuv_static \
-  libjpeg_static_ndk \
-
-v4l2_cflags := -fno-short-enums -Wall -Wextra -Werror -fvisibility=hidden -DHAVE_JPEG
-
-v4l2_c_includes := $(call include-path-for, camera) \
-  external/libyuv/files/include \
-
-v4l2_src_files := \
-  arc/cached_frame.cpp \
-  arc/exif_utils.cpp \
-  arc/frame_buffer.cpp \
-  arc/image_processor.cpp \
-  arc/jpeg_compressor.cpp \
-  camera.cpp \
-  capture_request.cpp \
-  format_metadata_factory.cpp \
-  metadata/boottime_state_delegate.cpp \
-  metadata/enum_converter.cpp \
-  metadata/metadata.cpp \
-  metadata/metadata_reader.cpp \
-  request_tracker.cpp \
-  static_properties.cpp \
-  stream_format.cpp \
-  v4l2_camera.cpp \
-  v4l2_camera_hal.cpp \
-  v4l2_metadata_factory.cpp \
-  v4l2_wrapper.cpp \
-
-v4l2_test_files := \
-  format_metadata_factory_test.cpp \
-  metadata/control_test.cpp \
-  metadata/default_option_delegate_test.cpp \
-  metadata/enum_converter_test.cpp \
-  metadata/ignored_control_delegate_test.cpp \
-  metadata/map_converter_test.cpp \
-  metadata/menu_control_options_test.cpp \
-  metadata/metadata_reader_test.cpp \
-  metadata/metadata_test.cpp \
-  metadata/no_effect_control_delegate_test.cpp \
-  metadata/partial_metadata_factory_test.cpp \
-  metadata/property_test.cpp \
-  metadata/ranged_converter_test.cpp \
-  metadata/slider_control_options_test.cpp \
-  metadata/state_test.cpp \
-  metadata/tagged_control_delegate_test.cpp \
-  metadata/tagged_control_options_test.cpp \
-  metadata/v4l2_control_delegate_test.cpp \
-  request_tracker_test.cpp \
-  static_properties_test.cpp \
-
-# V4L2 Camera HAL.
-# ==============================================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := camera.v4l2
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../../../NOTICE
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_CFLAGS += $(v4l2_cflags)
-LOCAL_SHARED_LIBRARIES := $(v4l2_shared_libs)
-LOCAL_HEADER_LIBRARIES := libgtest_prod_headers
-LOCAL_STATIC_LIBRARIES := $(v4l2_static_libs)
-
-LOCAL_C_INCLUDES += $(v4l2_c_includes)
-LOCAL_SRC_FILES := $(v4l2_src_files)
-include $(BUILD_SHARED_LIBRARY)
-
-# Unit tests for V4L2 Camera HAL.
-# ==============================================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := camera.v4l2_test
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../../../NOTICE
-LOCAL_CFLAGS += $(v4l2_cflags)
-LOCAL_SHARED_LIBRARIES := $(v4l2_shared_libs)
-LOCAL_STATIC_LIBRARIES := \
-  libgmock \
-  $(v4l2_static_libs) \
-
-LOCAL_C_INCLUDES += $(v4l2_c_includes)
-LOCAL_SRC_FILES := \
-  $(v4l2_src_files) \
-  $(v4l2_test_files) \
-
-include $(BUILD_NATIVE_TEST)
-
-endif # USE_CAMERA_V4L2_HAL
diff --git a/modules/camera/3_4/format_metadata_factory_test.cpp b/modules/camera/3_4/format_metadata_factory_test.cpp
index 65d4415..165743d 100644
--- a/modules/camera/3_4/format_metadata_factory_test.cpp
+++ b/modules/camera/3_4/format_metadata_factory_test.cpp
@@ -24,6 +24,7 @@
 #include "v4l2_wrapper_mock.h"
 
 using testing::AtLeast;
+using testing::DoAll;
 using testing::Expectation;
 using testing::Return;
 using testing::SetArgPointee;
diff --git a/modules/camera/3_4/metadata/control_test.cpp b/modules/camera/3_4/metadata/control_test.cpp
index 6284330..c68958f 100644
--- a/modules/camera/3_4/metadata/control_test.cpp
+++ b/modules/camera/3_4/metadata/control_test.cpp
@@ -26,6 +26,7 @@
 #include "test_common.h"
 
 using testing::AtMost;
+using testing::DoAll;
 using testing::Expectation;
 using testing::Return;
 using testing::SetArgPointee;
diff --git a/modules/camera/3_4/metadata/map_converter_test.cpp b/modules/camera/3_4/metadata/map_converter_test.cpp
index 0361810..87fbe20 100644
--- a/modules/camera/3_4/metadata/map_converter_test.cpp
+++ b/modules/camera/3_4/metadata/map_converter_test.cpp
@@ -21,6 +21,7 @@
 
 #include "converter_interface_mock.h"
 
+using testing::DoAll;
 using testing::Return;
 using testing::SetArgPointee;
 using testing::Test;
diff --git a/modules/camera/3_4/metadata/menu_control_options_test.cpp b/modules/camera/3_4/metadata/menu_control_options_test.cpp
index b8eea74..560d55f 100644
--- a/modules/camera/3_4/metadata/menu_control_options_test.cpp
+++ b/modules/camera/3_4/metadata/menu_control_options_test.cpp
@@ -23,6 +23,7 @@
 #include <hardware/camera3.h>
 #include "default_option_delegate_mock.h"
 
+using testing::DoAll;
 using testing::Return;
 using testing::SetArgPointee;
 using testing::Test;
diff --git a/modules/camera/3_4/metadata/partial_metadata_factory_test.cpp b/modules/camera/3_4/metadata/partial_metadata_factory_test.cpp
index f039b54..433f539 100644
--- a/modules/camera/3_4/metadata/partial_metadata_factory_test.cpp
+++ b/modules/camera/3_4/metadata/partial_metadata_factory_test.cpp
@@ -26,6 +26,7 @@
 #include "v4l2_wrapper_mock.h"
 
 using testing::AtMost;
+using testing::DoAll;
 using testing::Expectation;
 using testing::Return;
 using testing::SetArgPointee;
diff --git a/modules/camera/3_4/metadata/ranged_converter_test.cpp b/modules/camera/3_4/metadata/ranged_converter_test.cpp
index 2b5ccc6..f4048fe 100644
--- a/modules/camera/3_4/metadata/ranged_converter_test.cpp
+++ b/modules/camera/3_4/metadata/ranged_converter_test.cpp
@@ -21,6 +21,7 @@
 
 #include "converter_interface_mock.h"
 
+using testing::DoAll;
 using testing::Return;
 using testing::SetArgPointee;
 using testing::Test;
diff --git a/modules/camera/3_4/metadata/slider_control_options_test.cpp b/modules/camera/3_4/metadata/slider_control_options_test.cpp
index 7f3a643..5c5aec8 100644
--- a/modules/camera/3_4/metadata/slider_control_options_test.cpp
+++ b/modules/camera/3_4/metadata/slider_control_options_test.cpp
@@ -23,6 +23,7 @@
 #include <hardware/camera3.h>
 #include "default_option_delegate_mock.h"
 
+using testing::DoAll;
 using testing::Return;
 using testing::SetArgPointee;
 using testing::Test;
diff --git a/modules/camera/3_4/metadata/state_test.cpp b/modules/camera/3_4/metadata/state_test.cpp
index ecc1d15..61333ac 100644
--- a/modules/camera/3_4/metadata/state_test.cpp
+++ b/modules/camera/3_4/metadata/state_test.cpp
@@ -25,6 +25,7 @@
 #include "test_common.h"
 
 using testing::AtMost;
+using testing::DoAll;
 using testing::Expectation;
 using testing::Return;
 using testing::SetArgPointee;
diff --git a/modules/camera/3_4/metadata/tagged_control_delegate_test.cpp b/modules/camera/3_4/metadata/tagged_control_delegate_test.cpp
index ba29ab7..73118e2 100644
--- a/modules/camera/3_4/metadata/tagged_control_delegate_test.cpp
+++ b/modules/camera/3_4/metadata/tagged_control_delegate_test.cpp
@@ -21,6 +21,7 @@
 
 #include "control_delegate_interface_mock.h"
 
+using testing::DoAll;
 using testing::Return;
 using testing::SetArgPointee;
 using testing::Test;
diff --git a/modules/camera/3_4/metadata/tagged_control_options_test.cpp b/modules/camera/3_4/metadata/tagged_control_options_test.cpp
index 845426a..6ae72a1 100644
--- a/modules/camera/3_4/metadata/tagged_control_options_test.cpp
+++ b/modules/camera/3_4/metadata/tagged_control_options_test.cpp
@@ -21,6 +21,7 @@
 
 #include "control_options_interface_mock.h"
 
+using testing::DoAll;
 using testing::Return;
 using testing::SetArgPointee;
 using testing::Test;
diff --git a/modules/camera/3_4/metadata/v4l2_control_delegate_test.cpp b/modules/camera/3_4/metadata/v4l2_control_delegate_test.cpp
index 63ad0f6..6c8bef0 100644
--- a/modules/camera/3_4/metadata/v4l2_control_delegate_test.cpp
+++ b/modules/camera/3_4/metadata/v4l2_control_delegate_test.cpp
@@ -21,6 +21,7 @@
 #include "converter_interface_mock.h"
 #include "v4l2_wrapper_mock.h"
 
+using testing::DoAll;
 using testing::Return;
 using testing::SetArgPointee;
 using testing::Test;
diff --git a/modules/camera/3_4/static_properties_test.cpp b/modules/camera/3_4/static_properties_test.cpp
index 13b9e96..abbff87 100644
--- a/modules/camera/3_4/static_properties_test.cpp
+++ b/modules/camera/3_4/static_properties_test.cpp
@@ -24,6 +24,7 @@
 #include "metadata/metadata_reader_mock.h"
 
 using testing::AtMost;
+using testing::DoAll;
 using testing::Expectation;
 using testing::Return;
 using testing::SetArgPointee;
diff --git a/modules/camera/Android.mk b/modules/camera/Android.mk
deleted file mode 100644
index 71388aa..0000000
--- a/modules/camera/Android.mk
+++ /dev/null
@@ -1,15 +0,0 @@
-# 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 $(call all-subdir-makefiles)
diff --git a/modules/gralloc/Android.bp b/modules/gralloc/Android.bp
new file mode 100644
index 0000000..e352c80
--- /dev/null
+++ b/modules/gralloc/Android.bp
@@ -0,0 +1,45 @@
+// Copyright (C) 2008 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.
+
+// HAL module implementation stored in
+// hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so
+package {
+    // See: http://go/android-license-faq
+    default_applicable_licenses: [
+        "hardware_libhardware_license",
+    ],
+}
+
+cc_library_shared {
+    name: "gralloc.default",
+    relative_install_path: "hw",
+    proprietary: true,
+    shared_libs: [
+        "liblog",
+        "libcutils",
+    ],
+    srcs: [
+        "gralloc.cpp",
+        "framebuffer.cpp",
+        "mapper.cpp",
+    ],
+    header_libs: ["libhardware_headers"],
+    cflags: [
+        "-DLOG_TAG=\"gralloc\"",
+        "-Wno-missing-field-initializers",
+    ] + select(soong_config_variable("gralloc", "target_use_pan_display"), {
+        true: ["-DUSE_PAN_DISPLAY=1"],
+        default: [],
+    }),
+}
diff --git a/modules/gralloc/Android.mk b/modules/gralloc/Android.mk
deleted file mode 100644
index 4c4899e..0000000
--- a/modules/gralloc/Android.mk
+++ /dev/null
@@ -1,45 +0,0 @@
-# Copyright (C) 2008 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.
-
-
-LOCAL_PATH := $(call my-dir)
-
-# HAL module implemenation stored in
-# hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_PROPRIETARY_MODULE := true
-LOCAL_SHARED_LIBRARIES := liblog libcutils
-
-LOCAL_SRC_FILES := 	\
-	gralloc.cpp 	\
-	framebuffer.cpp \
-	mapper.cpp
-
-LOCAL_HEADER_LIBRARIES := libhardware_headers
-
-LOCAL_MODULE := gralloc.default
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../../NOTICE
-LOCAL_CFLAGS:= -DLOG_TAG=\"gralloc\" -Wno-missing-field-initializers
-ifeq ($(TARGET_USE_PAN_DISPLAY),true)
-LOCAL_CFLAGS += -DUSE_PAN_DISPLAY=1
-endif
-ifneq ($(GRALLOC_FRAMEBUFFER_NUM),)
-LOCAL_CFLAGS += -DNUM_BUFFERS=$(GRALLOC_FRAMEBUFFER_NUM)
-endif
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/gralloc/gralloc.cpp b/modules/gralloc/gralloc.cpp
index 87bda97..f7ea01c 100644
--- a/modules/gralloc/gralloc.cpp
+++ b/modules/gralloc/gralloc.cpp
@@ -224,7 +224,11 @@
         case HAL_PIXEL_FORMAT_RAW16:
             bytesPerPixel = 2;
             break;
+        case HAL_PIXEL_FORMAT_BLOB:
+            bytesPerPixel = 1;
+            break;
         default:
+            ALOGE("gralloc_alloc bad format %d", format);
             return -EINVAL;
     }
 
diff --git a/modules/input/evdev/InputDevice.cpp b/modules/input/evdev/InputDevice.cpp
index a1bce64..1e3da58 100644
--- a/modules/input/evdev/InputDevice.cpp
+++ b/modules/input/evdev/InputDevice.cpp
@@ -24,7 +24,6 @@
 
 #include <linux/input.h>
 
-#define __STDC_FORMAT_MACROS
 #include <cinttypes>
 #include <cstdlib>
 #include <string>
diff --git a/modules/sensors/Android.mk b/modules/sensors/Android.mk
deleted file mode 100644
index 69889de..0000000
--- a/modules/sensors/Android.mk
+++ /dev/null
@@ -1,48 +0,0 @@
-#
-# Copyright (C) 2013 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-ifeq ($(USE_SENSOR_MULTI_HAL),true)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := sensors.$(TARGET_DEVICE)
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../../NOTICE
-
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_PROPRIETARY_MODULE := true
-
-LOCAL_CFLAGS := -Wall -Werror -DLOG_TAG=\"MultiHal\"
-
-LOCAL_SRC_FILES := \
-    multihal.cpp \
-    SensorEventQueue.cpp \
-
-LOCAL_HEADER_LIBRARIES := \
-    libhardware_headers \
-
-LOCAL_SHARED_LIBRARIES := \
-    libcutils \
-    libdl \
-    liblog \
-    libutils \
-
-include $(BUILD_SHARED_LIBRARY)
-
-endif # USE_SENSOR_MULTI_HAL
diff --git a/modules/sensors/OWNERS b/modules/sensors/OWNERS
index 90c2330..7347ac7 100644
--- a/modules/sensors/OWNERS
+++ b/modules/sensors/OWNERS
@@ -1,3 +1 @@
-arthuri@google.com
 bduddie@google.com
-stange@google.com
diff --git a/modules/sensors/dynamic_sensor/Android.bp b/modules/sensors/dynamic_sensor/Android.bp
index 890da82..dbb3d93 100644
--- a/modules/sensors/dynamic_sensor/Android.bp
+++ b/modules/sensors/dynamic_sensor/Android.bp
@@ -35,9 +35,19 @@
     export_include_dirs: ["."],
 
     shared_libs: [
+        "libbase",
+        "liblog",
         "libhidparser",
+        "server_configurable_flags",
+        "libaconfig_storage_read_api_cc",
     ],
 
+    static_libs: [
+        "dynamic_sensors_flags_c_lib",
+    ],
+
+    cpp_std: "c++20",
+
     target: {
         android: {
             srcs: [
@@ -53,12 +63,12 @@
                 "RingBuffer.cpp",
             ],
             shared_libs: [
-                "libbase",
                 "libcutils",
                 "liblog",
                 "libutils",
             ],
             header_libs: [
+                "libbase_headers",
                 "libhardware_headers",
                 "libstagefright_foundation_headers",
             ],
@@ -182,3 +192,17 @@
         "HidUtils/test",
     ],
 }
+
+aconfig_declarations {
+    name: "dynamic_sensors_flags",
+    package: "com.android.libhardware.dynamic.sensors.flags",
+    container: "system",
+    srcs: ["dynamic_sensors.aconfig"],
+}
+
+cc_aconfig_library {
+    name: "dynamic_sensors_flags_c_lib",
+    aconfig_declarations: "dynamic_sensors_flags",
+    host_supported: true,
+    vendor: true,
+}
diff --git a/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.cpp b/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.cpp
index d5a9b3c..8df91c2 100644
--- a/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.cpp
+++ b/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.cpp
@@ -20,6 +20,7 @@
 #include <convertV2_1.h>
 #include <hardware/sensors-base.h>
 #include <log/log.h>
+#include <com_android_libhardware_dynamic_sensors_flags.h>
 
 #include <chrono>
 #include <thread>
@@ -32,6 +33,8 @@
 template<class T> using Return = ::android::hardware::Return<T>;
 using ::android::hardware::Void;
 
+namespace dynamic_sensors_flags = com::android::libhardware::dynamic::sensors::flags;
+
 namespace android {
 namespace SensorHalExt {
 
@@ -118,7 +121,7 @@
     sensors[0].sensorHandle = sensor_info.handle;
     sensors[0].name = sensor_info.name;
     sensors[0].vendor = sensor_info.vendor;
-    sensors[0].version = 1;
+    sensors[0].version = sensor_info.version;
     sensors[0].type = static_cast<SensorType>(sensor_info.type);
     sensors[0].typeAsString = sensor_info.stringType;
     sensors[0].maxRange = sensor_info.maxRange;
@@ -165,6 +168,8 @@
     std::vector<Event> events;
     Event hal_event;
     bool wakeup;
+    bool disconnectDynamicSensorFlag =
+        dynamic_sensors_flags::dynamic_sensors_hal_disconnect_dynamic_sensor();
 
     if (e.type == SENSOR_TYPE_DYNAMIC_SENSOR_META) {
         const dynamic_sensor_meta_event_t* sensor_meta;
@@ -172,21 +177,25 @@
         sensor_meta = static_cast<const dynamic_sensor_meta_event_t*>(
                 &(e.dynamic_sensor_meta));
         if (sensor_meta->connected != 0) {
-            // The sensor framework must be notified of the connected sensor
-            // through the callback before handling the sensor added event. If
-            // it isn't, it will assert when looking up the sensor handle when
-            // processing the sensor added event.
-            //
-            // TODO (b/201529167): Fix dynamic sensors addition / removal when
-            //                     converting to AIDL.
-            // The sensor framework runs in a separate process from the sensor
-            // HAL, and it processes events in a dedicated thread, so it's
-            // possible the event handling can be done before the callback is
-            // run. Thus, a delay is added after sending notification of the
-            // connected sensor.
             onSensorConnected(sensor_meta->handle, sensor_meta->sensor);
+        } else if (disconnectDynamicSensorFlag) {
+            onSensorDisconnected(sensor_meta->handle);
+        }
+        // The sensor framework must be notified of the connected sensor
+        // through the callback before handling the sensor added event. If
+        // it isn't, it will assert when looking up the sensor handle when
+        // processing the sensor added event.
+        //
+        // TODO (b/201529167): Fix dynamic sensors addition / removal when
+        //                     converting to AIDL.
+        // The sensor framework runs in a separate process from the sensor
+        // HAL, and it processes events in a dedicated thread, so it's
+        // possible the event handling can be done before the callback is
+        // run. Thus, a delay is added after sending notification of the
+        // connected sensor.
+        if (disconnectDynamicSensorFlag || sensor_meta->connected != 0) {
             std::this_thread::sleep_for(std::chrono::milliseconds(1000));
-       }
+        }
     }
 
     convertFromSensorEvent(e, &hal_event);
@@ -210,7 +219,7 @@
     sensor_list[0].sensorHandle = handle;
     sensor_list[0].name = sensor_info->name;
     sensor_list[0].vendor = sensor_info->vendor;
-    sensor_list[0].version = 1;
+    sensor_list[0].version = sensor_info->version;
     sensor_list[0].type = static_cast<SensorType>(sensor_info->type);
     sensor_list[0].typeAsString = sensor_info->stringType;
     sensor_list[0].maxRange = sensor_info->maxRange;
@@ -226,6 +235,14 @@
     mHalProxyCallback->onDynamicSensorsConnected_2_1(sensor_list);
 }
 
+void DynamicSensorsSubHal::onSensorDisconnected(int handle) {
+    hidl_vec<int32_t> handleList;
+    handleList.resize(1);
+    handleList[0] = handle;
+
+    mHalProxyCallback->onDynamicSensorsDisconnected(handleList);
+}
+
 } // namespace SensorHalExt
 } // namespace android
 
diff --git a/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.h b/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.h
index f59b00a..0d90dc0 100644
--- a/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.h
+++ b/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.h
@@ -77,6 +77,7 @@
                                                       kDynamicHandleBase;
 
     void onSensorConnected(int handle, const sensor_t* sensor_info);
+    void onSensorDisconnected(int handle);
 
     std::unique_ptr<DynamicSensorManager> mDynamicSensorManager;
     sp<IHalProxyCallback> mHalProxyCallback;
diff --git a/modules/sensors/dynamic_sensor/HidRawDevice.cpp b/modules/sensors/dynamic_sensor/HidRawDevice.cpp
index 2588483..6032ed9 100644
--- a/modules/sensors/dynamic_sensor/HidRawDevice.cpp
+++ b/modules/sensors/dynamic_sensor/HidRawDevice.cpp
@@ -204,7 +204,7 @@
     int res = ::ioctl(mDevFd, HIDIOCGFEATURE(size), mIoBuffer.data());
     if (res < 0) {
         LOG_E << "HidRawDevice::getFeature: feature " << static_cast<int>(id)
-              << " ioctl returns " << res << " (" << ::strerror(res) << ")" << LOG_ENDL;
+              << " ioctl returned " << res << ", errno: " << ::strerror(errno) << LOG_ENDL;
         return false;
     }
 
@@ -249,8 +249,8 @@
     std::copy(in.begin(), in.end(), &mIoBuffer[1]);
     int res = ::ioctl(mDevFd, HIDIOCSFEATURE(size), mIoBuffer.data());
     if (res < 0) {
-        LOG_E << "HidRawDevice::setFeature: feature " << id << " ioctl returns " << res
-              << " (" << ::strerror(res) << ")" << LOG_ENDL;
+        LOG_E << "HidRawDevice::setFeature: feature " << id << " ioctl returned " << res
+              << ", errno: " << ::strerror(errno) << LOG_ENDL;
         return false;
     }
     return true;
@@ -287,8 +287,8 @@
         res = ::write(mDevFd, data.data(), size);
     }
     if (res < 0) {
-        LOG_E << "HidRawDevice::sendReport: output " << id << " write returns " << res
-              << " (" << ::strerror(res) << ")" << LOG_ENDL;
+        LOG_E << "HidRawDevice::sendReport: output " << id << " write returned "
+              << res << ", errno: " << ::strerror(errno) << LOG_ENDL;
         return false;
     }
     return true;
@@ -302,8 +302,8 @@
     uint8_t buffer[256];
     int res = ::read(mDevFd, buffer, 256);
     if (res < 0) {
-        LOG_E << "HidRawDevice::receiveReport: read returns " << res
-              << " (" << ::strerror(res) << ")" << LOG_ENDL;
+        LOG_E << "HidRawDevice::receiveReport: read returned " << res
+              << ", errno: " << ::strerror(errno) << LOG_ENDL;
         return false;
     }
 
diff --git a/modules/sensors/dynamic_sensor/HidRawSensor.cpp b/modules/sensors/dynamic_sensor/HidRawSensor.cpp
index c90f4f1..b61185d 100644
--- a/modules/sensors/dynamic_sensor/HidRawSensor.cpp
+++ b/modules/sensors/dynamic_sensor/HidRawSensor.cpp
@@ -16,7 +16,9 @@
 #include "HidRawSensor.h"
 #include "HidSensorDef.h"
 
+#include <android-base/properties.h>
 #include <utils/Errors.h>
+#include <com_android_libhardware_dynamic_sensors_flags.h>
 #include "HidLog.h"
 
 #include <HidUtils.h>
@@ -30,15 +32,20 @@
 namespace android {
 namespace SensorHalExt {
 
+using ::android::base::GetProperty;
+
+namespace dynamic_sensors_flags = com::android::libhardware::dynamic::sensors::flags;
+
 namespace {
 const std::string CUSTOM_TYPE_PREFIX("com.google.hardware.sensor.hid_dynamic.");
+
 }
 
 HidRawSensor::HidRawSensor(
         SP(HidDevice) device, uint32_t usage, const std::vector<HidParser::ReportPacket> &packets)
-        : mReportingStateId(-1), mPowerStateId(-1), mReportIntervalId(-1), mInputReportId(-1),
-        mEnabled(false), mSamplingPeriod(1000LL*1000*1000), mBatchingPeriod(0),
-        mDevice(device), mValid(false) {
+        : mReportingStateId(-1), mPowerStateId(-1), mReportIntervalId(-1), mLeTransportId(-1),
+        mRequiresLeTransport(false), mInputReportId(-1), mEnabled(false),
+        mSamplingPeriod(1000LL*1000*1000), mBatchingPeriod(0), mDevice(device), mValid(false) {
     if (device == nullptr) {
         return;
     }
@@ -631,10 +638,35 @@
 
 bool HidRawSensor::detectAndroidHeadTrackerSensor(
         const std::string &description) {
-    if (description.find("#AndroidHeadTracker#1.") != 0) {
+    bool leAudioFlagEnabled = dynamic_sensors_flags::dynamic_sensors_le_audio();
+    LOG_I << "detectAndroidHeadTrackerSensor: " << description << LOG_ENDL;
+    if (!description.starts_with("#AndroidHeadTracker#1.")
+        && (!leAudioFlagEnabled || !description.starts_with("#AndroidHeadTracker#2."))) {
         return false;
     }
 
+    // #AndroidHeadTracker#<major version>.<minor version>#<capability>
+    // We encode the major, minor, and capabilities in the following format:
+    // 0xMMmmcccc (Major, minor, capability bits)
+    if (leAudioFlagEnabled) {
+        uint32_t majorVersion = 0, minorVersion = 0, capability = 0;
+        mFeatureInfo.version = 0;
+        int ret = sscanf(description.c_str(), "#AndroidHeadTracker#%d.%d#%d",
+                        &majorVersion, &minorVersion, &capability);
+        if (ret > 0) {
+            mRequiresLeTransport = (majorVersion == kLeAudioCapabilitiesMajorVersion);
+            mFeatureInfo.version = (majorVersion & 0xFF) << 24;
+        }
+        if (ret > 1) {
+            mFeatureInfo.version |= (minorVersion & 0xFF) << 16;
+        }
+        if (ret > 2) {
+            mFeatureInfo.version |= (capability & 0xFFFF);
+        }
+    } else {
+        mFeatureInfo.version = 1;
+    }
+
     mFeatureInfo.type = SENSOR_TYPE_HEAD_TRACKER;
     mFeatureInfo.typeString = SENSOR_STRING_TYPE_HEAD_TRACKER;
     mFeatureInfo.reportModeFlag = SENSOR_FLAG_CONTINUOUS_MODE;
@@ -817,6 +849,7 @@
     using namespace Hid::Sensor::PowerStateUsage;
     using namespace Hid::Sensor::PropertyUsage;
     using namespace Hid::Sensor::ReportingStateUsage;
+    using namespace Hid::Sensor::LeTransportUsage;
 
     //REPORTING_STATE
     const HidParser::ReportItem *reportingState
@@ -904,8 +937,43 @@
         mFeatureInfo.maxDelay = std::min(static_cast<int64_t>(1000000000),
                                          mFeatureInfo.maxDelay);
     }
-    return true;
-    return (mPowerStateId >= 0 || mReportingStateId >= 0) && mReportIntervalId >= 0;
+
+    bool leTransportExpected = mRequiresLeTransport;
+    if (leTransportExpected) {
+        //VENDOR_LE_TRANSPORT
+        const HidParser::ReportItem *leTransport
+                = find(packets, VENDOR_LE_TRANSPORT, HidParser::REPORT_TYPE_FEATURE);
+        if (leTransport == nullptr) {
+            LOG_W << "Cannot find valid LE transport feature" << LOG_ENDL;
+        } else {
+            mLeTransportId = leTransport->id;
+            mLeTransportBitOffset = leTransport->bitOffset;
+            mLeTransportBitSize = leTransport->bitSize;
+
+            mLeTransportAclIndex = -1;
+            mLeTransportIsoIndex = -1;
+            for (unsigned i = 0; i < leTransport->usageVector.size(); ++i) {
+                if (leTransport->usageVector[i] == LE_TRANSPORT_ACL) {
+                    mLeTransportAclIndex = i;
+                }
+                if (leTransport->usageVector[i] == LE_TRANSPORT_ISO) {
+                    mLeTransportIsoIndex = i;
+                }
+            }
+            if (mLeTransportAclIndex < 0) {
+                LOG_W << "Cannot find LE transport to enable ACL"
+                        << LOG_ENDL;
+                mLeTransportId = -1;
+            }
+            if (mLeTransportIsoIndex < 0) {
+                LOG_W << "Cannot find LE transport to enable ISO" << LOG_ENDL;
+                mLeTransportId = -1;
+            }
+        }
+    }
+
+    return (mPowerStateId >= 0 || mReportingStateId >= 0) && mReportIntervalId >= 0 &&
+           (!leTransportExpected || mLeTransportId >= 0);
 }
 
 const sensor_t* HidRawSensor::getSensor() const {
@@ -920,17 +988,79 @@
     SP(HidDevice) device = PROMOTE(mDevice);
 
     if (device == nullptr) {
+        LOG_E << "enable: no device" << LOG_ENDL;
         return NO_INIT;
     }
 
     if (enable == mEnabled) {
+        LOG_D << "enable: already in desired state" << LOG_ENDL;
         return NO_ERROR;
     }
 
+    bool setLeAudioTransportOk = setLeAudioTransport(device, enable);
+    bool setPowerOk = setPower(device, enable);
+    bool setReportingOk = setReportingState(device, enable);
+    if (setPowerOk && setReportingOk && setLeAudioTransportOk) {
+        mEnabled = enable;
+        LOG_I << "enable: success" << LOG_ENDL;
+        return NO_ERROR;
+    } else {
+        LOG_E << "enable: set feature failed" << LOG_ENDL;
+        return INVALID_OPERATION;
+    }
+}
+
+bool HidRawSensor::setLeAudioTransport(const SP(HidDevice) &device, bool enable) {
     std::vector<uint8_t> buffer;
-    bool setPowerOk = true;
+    bool success = true;
+    if (mLeTransportId >= 0 && enable) {
+        success = false;
+        uint8_t id = static_cast<uint8_t>(mLeTransportId);
+        if (device->getFeature(id, &buffer)
+                && (8 * buffer.size()) >=
+                        (mLeTransportBitOffset + mLeTransportBitSize)) {
+            // The following property, if defined, represents a comma-separated list of
+            // transport preferences for the following types: le-acl or iso-[sw|hw],
+            // which describes the priority list of transport selections used based on the
+            // capabilities reported by the HID device.
+            std::string prop = GetProperty("bluetooth.core.le.dsa_transport_preference", "");
+            std::istringstream tokenStream(prop);
+            std::string line;
+            std::vector<std::string> priorityList;
+            while (std::getline(tokenStream, line, ',')) {
+                priorityList.push_back(line);
+            }
+
+            uint16_t capability = mFeatureInfo.version & 0x0000FFFF;
+            uint8_t index;
+            if (capability == (kIsoBitMask | kAclBitMask)) {
+                if (!priorityList.empty() && priorityList[0].compare("le-acl") == 0) {
+                    index = mLeTransportAclIndex;
+                } else {
+                    index = mLeTransportIsoIndex;
+                }
+            } else {
+                index = (capability & kIsoBitMask) ? mLeTransportIsoIndex : mLeTransportAclIndex;
+            }
+
+            HidUtil::copyBits(&index, &(buffer[0]), buffer.size(), 0,
+                              mLeTransportBitOffset, mLeTransportBitSize);
+            success = device->setFeature(id, buffer);
+            if (!success) {
+              LOG_E << "enable: setFeature VENDOR LE TRANSPORT failed" << LOG_ENDL;
+            }
+        } else {
+            LOG_E << "enable: changing VENDOR LE TRANSPORT failed" << LOG_ENDL;
+        }
+    }
+    return success;
+}
+
+bool HidRawSensor::setPower(const SP(HidDevice) &device, bool enable) {
+    std::vector<uint8_t> buffer;
+    bool success = true;
     if (mPowerStateId >= 0) {
-        setPowerOk = false;
+        success = false;
         uint8_t id = static_cast<uint8_t>(mPowerStateId);
         if (device->getFeature(id, &buffer)
                 && (8 * buffer.size()) >=
@@ -938,15 +1068,22 @@
             uint8_t index = enable ? mPowerStateOnIndex : mPowerStateOffIndex;
             HidUtil::copyBits(&index, &(buffer[0]), buffer.size(),
                               0, mPowerStateBitOffset, mPowerStateBitSize);
-            setPowerOk = device->setFeature(id, buffer);
+            success = device->setFeature(id, buffer);
+            if (!success) {
+              LOG_E << "enable: setFeature POWER STATE failed" << LOG_ENDL;
+            }
         } else {
             LOG_E << "enable: changing POWER STATE failed" << LOG_ENDL;
         }
     }
+    return success;
+}
 
-    bool setReportingOk = true;
+bool HidRawSensor::setReportingState(const SP(HidDevice) &device, bool enable) {
+    std::vector<uint8_t> buffer;
+    bool success = true;
     if (mReportingStateId >= 0) {
-        setReportingOk = false;
+        success = false;
         uint8_t id = static_cast<uint8_t>(mReportingStateId);
         if (device->getFeature(id, &buffer)
                 && (8 * buffer.size()) >
@@ -955,18 +1092,15 @@
                                      mReportingStateDisableIndex;
             HidUtil::copyBits(&index, &(buffer[0]), buffer.size(),0,
                               mReportingStateBitOffset, mReportingStateBitSize);
-            setReportingOk = device->setFeature(id, buffer);
+            success = device->setFeature(id, buffer);
+            if (!success) {
+              LOG_E << "enable: setFeature REPORTING STATE failed" << LOG_ENDL;
+            }
         } else {
             LOG_E << "enable: changing REPORTING STATE failed" << LOG_ENDL;
         }
     }
-
-    if (setPowerOk && setReportingOk) {
-        mEnabled = enable;
-        return NO_ERROR;
-    } else {
-        return INVALID_OPERATION;
-    }
+    return success;
 }
 
 int HidRawSensor::batch(int64_t samplingPeriod, int64_t batchingPeriod) {
@@ -1100,6 +1234,7 @@
     std::ostringstream ss;
     ss << "Feature Values " << LOG_ENDL
           << "  name: " << mFeatureInfo.name << LOG_ENDL
+          << "  version: 0x" << std::setfill('0') << std::setw(8) << std::hex << mFeatureInfo.version << LOG_ENDL
           << "  vendor: " << mFeatureInfo.vendor << LOG_ENDL
           << "  permission: " << mFeatureInfo.permission << LOG_ENDL
           << "  typeString: " << mFeatureInfo.typeString << LOG_ENDL
diff --git a/modules/sensors/dynamic_sensor/HidRawSensor.h b/modules/sensors/dynamic_sensor/HidRawSensor.h
index e4564a0..71d80b1 100644
--- a/modules/sensors/dynamic_sensor/HidRawSensor.h
+++ b/modules/sensors/dynamic_sensor/HidRawSensor.h
@@ -149,6 +149,10 @@
     // process HID snesor spec defined orientation(quaternion) sensor usages.
     bool processQuaternionUsage(const std::vector<HidParser::ReportPacket> &packets);
 
+    bool setLeAudioTransport(const SP(HidDevice) &device, bool enable);
+    bool setPower(const SP(HidDevice) &device, bool enable);
+    bool setReportingState(const SP(HidDevice) &device, bool enable);
+
     // get the value of a report field
     template<typename ValueType>
     bool getReportFieldValue(const std::vector<uint8_t> &message,
@@ -200,6 +204,13 @@
     double mReportIntervalScale;
     int64_t mReportIntervalOffset;
 
+    int mLeTransportId;
+    unsigned int mLeTransportBitOffset;
+    unsigned int mLeTransportBitSize;
+    bool mRequiresLeTransport;
+    int mLeTransportAclIndex;
+    int mLeTransportIsoIndex;
+
     // Input report translate table
     std::vector<ReportTranslateRecord> mTranslateTable;
     unsigned mInputReportId;
@@ -214,6 +225,20 @@
 
     WP(HidDevice) mDevice;
     bool mValid;
+
+    /**
+     * The first major version which LE audio capabilities are encoded.
+     * For this version, we expect the HID descriptor to be the following format:
+     * #AndroidHeadTracker#<major version>.<minor version>#<capability>
+     * where capability is an integer that defines where LE audio supported
+     * transports are indicated:
+     * - 1: ACL
+     * - 2: ISO
+     * - 3: ACL + ISO
+     */
+    const uint8_t kLeAudioCapabilitiesMajorVersion = 2;
+    const uint8_t kAclBitMask = 0x1;
+    const uint8_t kIsoBitMask = 0x2;
 };
 
 } // namespace SensorHalExt
diff --git a/modules/sensors/dynamic_sensor/HidRawSensorDaemon.cpp b/modules/sensors/dynamic_sensor/HidRawSensorDaemon.cpp
index 4b447ac..0d561b1 100644
--- a/modules/sensors/dynamic_sensor/HidRawSensorDaemon.cpp
+++ b/modules/sensors/dynamic_sensor/HidRawSensorDaemon.cpp
@@ -59,7 +59,7 @@
         ALOGE("failed to create HidRawSensorDevice object");
     }
 
-    ALOGE("return %zu sensors", ret.size());
+    ALOGI("return %zu sensors", ret.size());
     return ret;
 }
 
diff --git a/modules/sensors/dynamic_sensor/HidSensorDef.h b/modules/sensors/dynamic_sensor/HidSensorDef.h
index 8f47a85..d347ef6 100644
--- a/modules/sensors/dynamic_sensor/HidSensorDef.h
+++ b/modules/sensors/dynamic_sensor/HidSensorDef.h
@@ -42,6 +42,7 @@
     SENSOR_MODEL = 0x200306,
     SENSOR_SERIAL_NUMBER = 0x200307,
     SENSOR_STATUS = 0x200303,
+    VENDOR_LE_TRANSPORT = 0x20F410,
 };
 } // nsmespace PropertyUsage
 
@@ -99,6 +100,13 @@
 };
 } // namespace PowerStateUsage
 
+namespace LeTransportUsage {
+enum {
+    LE_TRANSPORT_ACL = 0xF800,
+    LE_TRANSPORT_ISO = 0xF801,
+};
+} // namespace LeTransportUsage
+
 } // namespace Sensor
 } // namespace Hid
 #endif // HID_SENSOR_DEF_H_
diff --git a/modules/sensors/dynamic_sensor/README.md b/modules/sensors/dynamic_sensor/README.md
index 8af15a9..45d60ec 100644
--- a/modules/sensors/dynamic_sensor/README.md
+++ b/modules/sensors/dynamic_sensor/README.md
@@ -15,6 +15,9 @@
 in the Linux kernel (`CONFIG_HIDRAW=y`), and SELinux policy files must be updated
 to provide the necessary permissions. Example changes are provided below.
 
+Note: as of Android 15, the `hidraw_device` SELinux label is provided by the
+system.
+
 ```shell
 acme-co$ git -C device/acme/rocket-phone diff
 diff --git a/sensor_hal/hals.conf b/sensor_hal/hals.conf
@@ -68,18 +71,6 @@
  #
  # Thruster sensor enforcements.
  #
-diff --git a/sepolicy/device.te b/sepolicy/device.te
-index bc3c947..bad0be0 100644
---- a/sepolicy/device.te
-+++ b/sepolicy/device.te
-@@ -55,3 +55,7 @@
-
- # Thruster
- type thruster_device, dev_type;
-+
-+# Raw HID device
-+type hidraw_device, dev_type;
-+
 diff --git a/sepolicy/property.te b/sepolicy/property.te
 index 4b671a4..bb0894f 100644
 --- a/sepolicy/property.te
diff --git a/modules/sensors/dynamic_sensor/dynamic_sensors.aconfig b/modules/sensors/dynamic_sensor/dynamic_sensors.aconfig
new file mode 100644
index 0000000..fe9c145
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/dynamic_sensors.aconfig
@@ -0,0 +1,16 @@
+package: "com.android.libhardware.dynamic.sensors.flags"
+container: "system"
+
+flag {
+  name: "dynamic_sensors_le_audio"
+  namespace: "sensors"
+  description: "This flag controls the enablement of LE audio support on dynamic sensors"
+  bug: "298450041"
+}
+
+flag {
+  name: "dynamic_sensors_hal_disconnect_dynamic_sensor"
+  namespace: "sensors"
+  description: "This flag controls if onDynamicSensorDisconnect callback in sensors HAL will be triggered"
+  bug: "316958439"
+}
\ No newline at end of file