dynamic_sensor: Add sensor manager init to sub-HAL 2.1. am: 3c7a12d8f1

Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/libhardware/+/15905535

Change-Id: Ib2377f7425bf30da47d69557b35df158a5b9b54c
This commit is contained in:
Erik Staats 2021-09-24 17:46:31 +00:00 committed by Automerger Merge Worker
commit bf866d6dd4
6 changed files with 66 additions and 7 deletions

View file

@ -57,8 +57,6 @@ SocketConnectionDetector::SocketConnectionDetector(BaseDynamicSensorDaemon *d, i
std::ostringstream s;
s << "socket:" << port;
mDevice = s.str();
run("ddad_socket");
}
SocketConnectionDetector::~SocketConnectionDetector() {
@ -67,6 +65,12 @@ SocketConnectionDetector::~SocketConnectionDetector() {
}
}
void SocketConnectionDetector::Init() {
// run adds a strong reference to this object, so it can't be invoked from
// the constructor.
run("ddad_socket");
}
int SocketConnectionDetector::waitForConnection() {
return ::accept(mListenFd, nullptr, nullptr);
}
@ -124,9 +128,6 @@ FileConnectionDetector::FileConnectionDetector (
ALOGE("Cannot setup watch on dir %s", path.c_str());
return;
}
// mLooper != null && mInotifyFd added to looper
run("ddad_file");
}
FileConnectionDetector::~FileConnectionDetector() {
@ -138,6 +139,13 @@ FileConnectionDetector::~FileConnectionDetector() {
}
}
void FileConnectionDetector::Init() {
// mLooper != null && mInotifyFd added to looper
// run adds a strong reference to this object, so it can't be invoked from
// the constructor.
run("ddad_file");
}
bool FileConnectionDetector::matches(const std::string &name) const {
return std::regex_match(name, mRegex);
}

View file

@ -34,6 +34,7 @@ class ConnectionDetector : virtual public RefBase {
public:
ConnectionDetector(BaseDynamicSensorDaemon *d) : mDaemon(d) { }
virtual ~ConnectionDetector() = default;
virtual void Init() {}
protected:
BaseDynamicSensorDaemon* mDaemon;
};
@ -45,6 +46,7 @@ class SocketConnectionDetector : public ConnectionDetector, public Thread {
public:
SocketConnectionDetector(BaseDynamicSensorDaemon *d, int port);
virtual ~SocketConnectionDetector();
void Init() override;
private:
// implement virtual of Thread
virtual bool threadLoop();
@ -62,6 +64,7 @@ public:
FileConnectionDetector(
BaseDynamicSensorDaemon *d, const std::string &path, const std::string &regex);
virtual ~FileConnectionDetector();
void Init() override;
private:
static constexpr int POLL_IDENT = 1;
// implement virtual of Thread

View file

@ -28,7 +28,7 @@
#include <netinet/in.h>
#include <algorithm> //std::max
#define SYSPROP_PREFIX "dynamic_sensor.dummy"
#define SYSPROP_PREFIX "vendor.dynamic_sensor.mock"
#define FILE_NAME_BASE "dummy_accel_file"
#define FILE_NAME_REGEX ("^" FILE_NAME_BASE "[0-9]$")
@ -43,11 +43,13 @@ DummyDynamicAccelDaemon::DummyDynamicAccelDaemon(DynamicSensorManager& manager)
if (strcmp(property, "") != 0) {
mFileDetector = new FileConnectionDetector(
this, std::string(property), std::string(FILE_NAME_REGEX));
mFileDetector->Init();
}
property_get(SYSPROP_PREFIX ".socket", property, "");
if (strcmp(property, "") != 0) {
mSocketDetector = new SocketConnectionDetector(this, atoi(property));
mSocketDetector->Init();
}
}

View file

@ -20,12 +20,22 @@
#include <log/log.h>
using ::android::hardware::sensors::V1_0::Result;
using ::android::hardware::sensors::V2_1::SensorInfo;
using ::android::hardware::sensors::V2_1::SensorType;
template<class T> using Return = ::android::hardware::Return<T>;
using ::android::hardware::Void;
namespace android {
namespace SensorHalExt {
DynamicSensorsSubHal::DynamicSensorsSubHal() {
// initialize dynamic sensor manager
mDynamicSensorManager.reset(
DynamicSensorManager::createInstance(kDynamicHandleBase,
kMaxDynamicHandleCount,
nullptr /* callback */));
}
// ISensors.
Return<Result> DynamicSensorsSubHal::setOperationMode(OperationMode mode) {
return (mode == static_cast<OperationMode>(SENSOR_HAL_NORMAL_MODE) ?
@ -77,9 +87,32 @@ Return<void> DynamicSensorsSubHal::configDirectReport(
}
Return<void> DynamicSensorsSubHal::getSensorsList_2_1(
getSensorsList_2_1_cb callback __unused) {
getSensorsList_2_1_cb callback) {
const sensor_t& sensor_info = mDynamicSensorManager->getDynamicMetaSensor();
std::vector<SensorInfo> sensors;
ALOGD("DynamicSensorsSubHal::getSensorsList_2_1 invoked.");
// get the dynamic sensor info
sensors.resize(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].type = static_cast<SensorType>(sensor_info.type);
sensors[0].typeAsString = sensor_info.stringType;
sensors[0].maxRange = sensor_info.maxRange;
sensors[0].resolution = sensor_info.resolution;
sensors[0].power = sensor_info.power;
sensors[0].minDelay = sensor_info.minDelay;
sensors[0].fifoReservedEventCount = sensor_info.fifoReservedEventCount;
sensors[0].fifoMaxEventCount = sensor_info.fifoMaxEventCount;
sensors[0].requiredPermission = sensor_info.requiredPermission;
sensors[0].maxDelay = sensor_info.maxDelay;
sensors[0].flags = sensor_info.flags;
callback(sensors);
return Void();
}

View file

@ -17,6 +17,8 @@
#ifndef ANDROID_SENSORHAL_EXT_DYNAMIC_SENSORS_SUB_HAL_H
#define ANDROID_SENSORHAL_EXT_DYNAMIC_SENSORS_SUB_HAL_H
#include "DynamicSensorManager.h"
#include <V2_1/SubHal.h>
namespace android {
@ -37,6 +39,8 @@ class DynamicSensorsSubHal :
using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo;
public:
DynamicSensorsSubHal();
// ISensors.
Return<Result> setOperationMode(OperationMode mode) override;
Return<Result> activate(int32_t sensor_handle, bool enabled) override;
@ -60,6 +64,14 @@ public:
const std::string getName() override { return "Dynamic-SubHAL"; }
Return<Result> initialize(
const sp<IHalProxyCallback>& hal_proxy_callback) override;
private:
static constexpr int32_t kDynamicHandleBase = 0;
static constexpr int32_t kDynamicHandleEnd = 0x1000000;
static constexpr int32_t kMaxDynamicHandleCount = kDynamicHandleEnd -
kDynamicHandleBase;
std::unique_ptr<DynamicSensorManager> mDynamicSensorManager;
};
} // namespace SensorHalExt

View file

@ -39,6 +39,7 @@ HidRawSensorDaemon::HidRawSensorDaemon(DynamicSensorManager& manager)
: BaseDynamicSensorDaemon(manager) {
mDetector = new FileConnectionDetector(
this, std::string(DEV_PATH), std::string(DEV_NAME_REGEX));
mDetector->Init();
}
BaseSensorVector HidRawSensorDaemon::createSensor(const std::string &deviceKey) {