Merge "Multihal 2.0 - Small tweaks to sensorHandle handling"

This commit is contained in:
TreeHugger Robot
2019-09-14 09:19:47 +00:00
committed by Android (Google) Code Review
2 changed files with 13 additions and 11 deletions

View File

@@ -113,7 +113,7 @@ Return<Result> HalProxy::setOperationMode(OperationMode mode) {
Return<Result> HalProxy::activate(int32_t sensorHandle, bool enabled) {
return getSubHalForSensorHandle(sensorHandle)
->activate(zeroOutFirstByte(sensorHandle), enabled);
->activate(clearSubHalIndex(sensorHandle), enabled);
}
Return<Result> HalProxy::initialize(
@@ -154,11 +154,11 @@ Return<Result> HalProxy::initialize(
Return<Result> HalProxy::batch(int32_t sensorHandle, int64_t samplingPeriodNs,
int64_t maxReportLatencyNs) {
return getSubHalForSensorHandle(sensorHandle)
->batch(zeroOutFirstByte(sensorHandle), samplingPeriodNs, maxReportLatencyNs);
->batch(clearSubHalIndex(sensorHandle), samplingPeriodNs, maxReportLatencyNs);
}
Return<Result> HalProxy::flush(int32_t sensorHandle) {
return getSubHalForSensorHandle(sensorHandle)->flush(zeroOutFirstByte(sensorHandle));
return getSubHalForSensorHandle(sensorHandle)->flush(clearSubHalIndex(sensorHandle));
}
Return<Result> HalProxy::injectSensorData(const Event& /* event */) {
@@ -244,7 +244,7 @@ void HalProxy::initializeSensorList() {
ISensorsSubHal* subHal = mSubHalList[subHalIndex];
auto result = subHal->getSensorsList([&](const auto& list) {
for (SensorInfo sensor : list) {
if ((sensor.sensorHandle & 0xFF000000) != 0) {
if ((sensor.sensorHandle & kSensorHandleSubHalIndexMask) != 0) {
ALOGE("SubHal sensorHandle's first byte was not 0");
} else {
ALOGV("Loaded sensor: %s", sensor.name.c_str());
@@ -278,8 +278,8 @@ ISensorsSubHal* HalProxy::getSubHalForSensorHandle(uint32_t sensorHandle) {
return mSubHalList[static_cast<size_t>(sensorHandle >> 24)];
}
uint32_t HalProxy::zeroOutFirstByte(uint32_t num) {
return num & 0x00FFFFFF;
uint32_t HalProxy::clearSubHalIndex(uint32_t sensorHandle) {
return sensorHandle & (~kSensorHandleSubHalIndexMask);
}
} // namespace implementation

View File

@@ -135,6 +135,9 @@ class HalProxy : public ISensors {
//! The single subHal that supports directChannel reporting.
ISensorsSubHal* mDirectChannelSubHal = nullptr;
//! The bit mask used to get the subhal index from a sensor handle.
static constexpr uint32_t kSensorHandleSubHalIndexMask = 0xFF000000;
/**
* Initialize the list of SubHal objects in mSubHalList by reading from dynamic libraries
* listed in a config file.
@@ -167,14 +170,13 @@ class HalProxy : public ISensors {
ISensorsSubHal* getSubHalForSensorHandle(uint32_t sensorHandle);
/*
* Zero out the first (most significant) byte in a number. Used in modifying the sensor handles
* before passing them to subhals.
* Clear out the subhal index bytes from a sensorHandle.
*
* @param num The uint32_t number to work with.
* @param sensorHandle The sensor handle to modify.
*
* @return The modified version of num param.
* @return The modified version of the sensor handle.
*/
static uint32_t zeroOutFirstByte(uint32_t num);
static uint32_t clearSubHalIndex(uint32_t sensorHandle);
};
} // namespace implementation