Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab19909a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Modify SensorDevice to use ISensorsWrapper"

parents 64d2116a 12f4d329
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <cinttypes>
#include <thread>

using namespace android::hardware::sensors;
using namespace android::hardware::sensors::V1_0;
using namespace android::hardware::sensors::V1_0::implementation;
using android::hardware::hidl_vec;
@@ -87,16 +88,25 @@ SensorDevice::SensorDevice()
}

bool SensorDevice::connectHidlService() {
    bool connected = connectHidlServiceV2_0();
    if (!connected) {
        connected = connectHidlServiceV1_0();
    }
    return connected;
}

bool SensorDevice::connectHidlServiceV1_0() {
    // SensorDevice will wait for HAL service to start if HAL is declared in device manifest.
    size_t retry = 10;

    while (retry-- > 0) {
        mSensors = ISensors::getService();
        if (mSensors == nullptr) {
        sp<V1_0::ISensors> sensors = V1_0::ISensors::getService();
        if (sensors == nullptr) {
            // no sensor hidl service found
            break;
        }

        mSensors = new SensorServiceUtil::SensorsWrapperV1_0(sensors);
        mRestartWaiter->reset();
        // Poke ISensor service. If it has lingering connection from previous generation of
        // system server, it will kill itself. There is no intention to handle the poll result,
@@ -114,6 +124,16 @@ bool SensorDevice::connectHidlService() {
    return (mSensors != nullptr);
}

bool SensorDevice::connectHidlServiceV2_0() {
    sp<V2_0::ISensors> sensors = V2_0::ISensors::getService();
    if (sensors != nullptr) {
        mSensors = new SensorServiceUtil::SensorsWrapperV2_0(sensors);

        // TODO: initialize message queues
    }
    return (mSensors != nullptr);
}

void SensorDevice::handleDynamicSensorConnection(int handle, bool connected) {
    // not need to check mSensors because this is is only called after successful poll()
    if (connected) {
+4 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

#include "SensorDeviceUtils.h"
#include "SensorServiceUtils.h"
#include "SensorsWrapper.h"

#include <sensor/Sensor.h>
#include <stdint.h>
@@ -31,8 +32,6 @@
#include <unordered_map>
#include <algorithm> //std::max std::min

#include "android/hardware/sensors/1.0/ISensors.h"

#include "RingBuffer.h"

// ---------------------------------------------------------------------------
@@ -103,7 +102,7 @@ public:
private:
    friend class Singleton<SensorDevice>;

    sp<hardware::sensors::V1_0::ISensors> mSensors;
    sp<SensorServiceUtil::ISensorsWrapper> mSensors;
    Vector<sensor_t> mSensorList;
    std::unordered_map<int32_t, sensor_t*> mConnectedDynamicSensors;

@@ -163,6 +162,8 @@ private:
    SortedVector<void *> mDisabledClients;
    SensorDevice();
    bool connectHidlService();
    bool connectHidlServiceV1_0();
    bool connectHidlServiceV2_0();

    static void handleHidlDeath(const std::string &detail);
    template<typename T>