Fix registerDirectChannel in HAL wrappers
Bug: 228645167
Test: CTS+VTS
Change-Id: I14348a7fe98a9681bc03109af8610c0aab679265
diff --git a/services/sensorservice/HidlSensorHalWrapper.cpp b/services/sensorservice/HidlSensorHalWrapper.cpp
index 4c64e59..c55c9b4 100644
--- a/services/sensorservice/HidlSensorHalWrapper.cpp
+++ b/services/sensorservice/HidlSensorHalWrapper.cpp
@@ -281,7 +281,7 @@
}
status_t HidlSensorHalWrapper::registerDirectChannel(const sensors_direct_mem_t* memory,
- int32_t* /*channelHandle*/) {
+ int32_t* outChannelHandle) {
if (mSensors == nullptr) return NO_INIT;
SharedMemType type;
@@ -309,14 +309,16 @@
.memoryHandle = memory->handle,
};
- status_t ret;
- checkReturn(mSensors->registerDirectChannel(mem, [&ret](auto result, auto channelHandle) {
- if (result == Result::OK) {
- ret = channelHandle;
- } else {
- ret = statusFromResult(result);
- }
- }));
+ status_t ret = OK;
+ checkReturn(mSensors->registerDirectChannel(mem,
+ [&ret, &outChannelHandle](auto result,
+ auto channelHandle) {
+ if (result == Result::OK) {
+ *outChannelHandle = channelHandle;
+ } else {
+ ret = statusFromResult(result);
+ }
+ }));
return ret;
}
diff --git a/services/sensorservice/HidlSensorHalWrapper.h b/services/sensorservice/HidlSensorHalWrapper.h
index 71c3512..d6ed178 100644
--- a/services/sensorservice/HidlSensorHalWrapper.h
+++ b/services/sensorservice/HidlSensorHalWrapper.h
@@ -112,7 +112,7 @@
virtual status_t injectSensorData(const sensors_event_t* event) override;
virtual status_t registerDirectChannel(const sensors_direct_mem_t* memory,
- int32_t* channelHandle) override;
+ int32_t* outChannelHandle) override;
virtual status_t unregisterDirectChannel(int32_t channelHandle) override;
diff --git a/services/sensorservice/SensorDevice.cpp b/services/sensorservice/SensorDevice.cpp
index a0e30ac..53a3025 100644
--- a/services/sensorservice/SensorDevice.cpp
+++ b/services/sensorservice/SensorDevice.cpp
@@ -766,7 +766,13 @@
if (mHalWrapper == nullptr) return NO_INIT;
Mutex::Autolock _l(mLock);
- return mHalWrapper->registerDirectChannel(memory, nullptr);
+ int32_t channelHandle;
+ status_t status = mHalWrapper->registerDirectChannel(memory, &channelHandle);
+ if (status != OK) {
+ channelHandle = -1;
+ }
+
+ return channelHandle;
}
void SensorDevice::unregisterDirectChannel(int32_t channelHandle) {