Updates LE transport selection logic

Bug: 298450041
Test: Tested on device
Change-Id: Ifb541280f12a72496e887b4d99d18064e97cda3f
diff --git a/modules/sensors/dynamic_sensor/HidRawSensor.cpp b/modules/sensors/dynamic_sensor/HidRawSensor.cpp
index 57df74d..336461c 100644
--- a/modules/sensors/dynamic_sensor/HidRawSensor.cpp
+++ b/modules/sensors/dynamic_sensor/HidRawSensor.cpp
@@ -849,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
@@ -948,6 +949,26 @@
             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;
+            }
         }
     }
 
@@ -1009,7 +1030,10 @@
             } else {
                 value = (capability & kIsoBitMask) ? kLeIsoValue : kLeAclValue;
             }
-            HidUtil::copyBits(&value, &(buffer[0]), buffer.size(), 0,
+
+            uint8_t index = (value == kLeAclValue) ? mLeTransportAclIndex :
+                                     mLeTransportIsoIndex;
+            HidUtil::copyBits(&index, &(buffer[0]), buffer.size(), 0,
                               mLeTransportBitOffset, mLeTransportBitSize);
             setLeAudioTransportOk = device->setFeature(id, buffer);
             if (!setLeAudioTransportOk) {
diff --git a/modules/sensors/dynamic_sensor/HidRawSensor.h b/modules/sensors/dynamic_sensor/HidRawSensor.h
index 3d2d94d..a9847c8 100644
--- a/modules/sensors/dynamic_sensor/HidRawSensor.h
+++ b/modules/sensors/dynamic_sensor/HidRawSensor.h
@@ -204,6 +204,8 @@
     unsigned int mLeTransportBitOffset;
     unsigned int mLeTransportBitSize;
     bool mRequiresLeTransport;
+    int mLeTransportAclIndex;
+    int mLeTransportIsoIndex;
 
     // Input report translate table
     std::vector<ReportTranslateRecord> mTranslateTable;
diff --git a/modules/sensors/dynamic_sensor/HidSensorDef.h b/modules/sensors/dynamic_sensor/HidSensorDef.h
index 30c2f88..d347ef6 100644
--- a/modules/sensors/dynamic_sensor/HidSensorDef.h
+++ b/modules/sensors/dynamic_sensor/HidSensorDef.h
@@ -100,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_