Merge Android 24Q1 Release (ab/11220357)
Bug: 319669529 Merged-In: I0da896913f09a8215189974cf294d6b2a26d12f8 Change-Id: I63cb7d1631b3b27002ec06eae3609d6570cc90e4
This commit is contained in:
commit
191d41f5c8
6 changed files with 186 additions and 10 deletions
|
@ -35,9 +35,17 @@ cc_defaults {
|
|||
export_include_dirs: ["."],
|
||||
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libhidparser",
|
||||
"server_configurable_flags",
|
||||
],
|
||||
|
||||
static_libs: [
|
||||
"dynamic_sensors_flags_c_lib",
|
||||
],
|
||||
|
||||
cpp_std: "c++20",
|
||||
|
||||
target: {
|
||||
android: {
|
||||
srcs: [
|
||||
|
@ -53,12 +61,12 @@ cc_defaults {
|
|||
"RingBuffer.cpp",
|
||||
],
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libcutils",
|
||||
"liblog",
|
||||
"libutils",
|
||||
],
|
||||
header_libs: [
|
||||
"libbase_headers",
|
||||
"libhardware_headers",
|
||||
"libstagefright_foundation_headers",
|
||||
],
|
||||
|
@ -182,3 +190,16 @@ cc_binary {
|
|||
"HidUtils/test",
|
||||
],
|
||||
}
|
||||
|
||||
aconfig_declarations {
|
||||
name: "dynamic_sensors_flags",
|
||||
package: "com.android.libhardware.dynamic.sensors.flags",
|
||||
srcs: ["dynamic_sensors.aconfig"],
|
||||
}
|
||||
|
||||
cc_aconfig_library {
|
||||
name: "dynamic_sensors_flags_c_lib",
|
||||
aconfig_declarations: "dynamic_sensors_flags",
|
||||
host_supported: true,
|
||||
vendor: true,
|
||||
}
|
|
@ -118,7 +118,7 @@ Return<void> DynamicSensorsSubHal::getSensorsList_2_1(
|
|||
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;
|
||||
|
@ -210,7 +210,7 @@ void DynamicSensorsSubHal::onSensorConnected(
|
|||
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;
|
||||
|
|
|
@ -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 @@ void HidRawSensor::detectSensorFromDescription(const std::string &description) {
|
|||
|
||||
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 @@ bool HidRawSensor::findSensorControlUsage(const std::vector<HidParser::ReportPac
|
|||
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 @@ bool HidRawSensor::findSensorControlUsage(const std::vector<HidParser::ReportPac
|
|||
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 {
|
||||
|
@ -928,6 +996,49 @@ int HidRawSensor::enable(bool enable) {
|
|||
}
|
||||
|
||||
std::vector<uint8_t> buffer;
|
||||
// TODO(b/298450041): Refactor the operations below in a separate function.
|
||||
bool setLeAudioTransportOk = true;
|
||||
if (mLeTransportId >= 0 && enable) {
|
||||
setLeAudioTransportOk = 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);
|
||||
setLeAudioTransportOk = device->setFeature(id, buffer);
|
||||
if (!setLeAudioTransportOk) {
|
||||
LOG_E << "enable: setFeature VENDOR LE TRANSPORT failed" << LOG_ENDL;
|
||||
}
|
||||
} else {
|
||||
LOG_E << "enable: changing VENDOR LE TRANSPORT failed" << LOG_ENDL;
|
||||
}
|
||||
}
|
||||
|
||||
bool setPowerOk = true;
|
||||
if (mPowerStateId >= 0) {
|
||||
setPowerOk = false;
|
||||
|
@ -939,6 +1050,9 @@ int HidRawSensor::enable(bool enable) {
|
|||
HidUtil::copyBits(&index, &(buffer[0]), buffer.size(),
|
||||
0, mPowerStateBitOffset, mPowerStateBitSize);
|
||||
setPowerOk = device->setFeature(id, buffer);
|
||||
if (!setPowerOk) {
|
||||
LOG_E << "enable: setFeature POWER STATE failed" << LOG_ENDL;
|
||||
}
|
||||
} else {
|
||||
LOG_E << "enable: changing POWER STATE failed" << LOG_ENDL;
|
||||
}
|
||||
|
@ -956,12 +1070,15 @@ int HidRawSensor::enable(bool enable) {
|
|||
HidUtil::copyBits(&index, &(buffer[0]), buffer.size(),0,
|
||||
mReportingStateBitOffset, mReportingStateBitSize);
|
||||
setReportingOk = device->setFeature(id, buffer);
|
||||
if (!setReportingOk) {
|
||||
LOG_E << "enable: setFeature REPORTING STATE failed" << LOG_ENDL;
|
||||
}
|
||||
} else {
|
||||
LOG_E << "enable: changing REPORTING STATE failed" << LOG_ENDL;
|
||||
}
|
||||
}
|
||||
|
||||
if (setPowerOk && setReportingOk) {
|
||||
if (setPowerOk && setReportingOk && setLeAudioTransportOk) {
|
||||
mEnabled = enable;
|
||||
return NO_ERROR;
|
||||
} else {
|
||||
|
@ -1100,6 +1217,7 @@ std::string HidRawSensor::dump() const {
|
|||
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
|
||||
|
|
|
@ -200,6 +200,13 @@ private:
|
|||
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 +221,20 @@ private:
|
|||
|
||||
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
|
||||
|
|
|
@ -42,6 +42,7 @@ enum {
|
|||
SENSOR_MODEL = 0x200306,
|
||||
SENSOR_SERIAL_NUMBER = 0x200307,
|
||||
SENSOR_STATUS = 0x200303,
|
||||
VENDOR_LE_TRANSPORT = 0x20F410,
|
||||
};
|
||||
} // nsmespace PropertyUsage
|
||||
|
||||
|
@ -99,6 +100,13 @@ enum {
|
|||
};
|
||||
} // namespace PowerStateUsage
|
||||
|
||||
namespace LeTransportUsage {
|
||||
enum {
|
||||
LE_TRANSPORT_ACL = 0xF800,
|
||||
LE_TRANSPORT_ISO = 0xF801,
|
||||
};
|
||||
} // namespace LeTransportUsage
|
||||
|
||||
} // namespace Sensor
|
||||
} // namespace Hid
|
||||
#endif // HID_SENSOR_DEF_H_
|
||||
|
|
8
modules/sensors/dynamic_sensor/dynamic_sensors.aconfig
Normal file
8
modules/sensors/dynamic_sensor/dynamic_sensors.aconfig
Normal file
|
@ -0,0 +1,8 @@
|
|||
package: "com.android.libhardware.dynamic.sensors.flags"
|
||||
|
||||
flag {
|
||||
name: "dynamic_sensors_le_audio"
|
||||
namespace: "sensors"
|
||||
description: "This flag controls the enablement of LE audio support on dynamic sensors"
|
||||
bug: "298450041"
|
||||
}
|
Loading…
Reference in a new issue