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

Commit 67888489 authored by Anthony Stange's avatar Anthony Stange
Browse files

Update tests for multihal to test HAL 2.1

Updates tests and fake subhals to support Multi-HAL 2.1 to make
on-device testing feasible.

Bug: 149758467
Test: Verify that the new unit tests and subhals in this topic load and
run on a Pixel device

Change-Id: I2be51568ba8dd99aa0588b8945d3d41bda7d9941
parent 82f8d466
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ cc_library {
    vendor: true,
    defaults: ["android.hardware.sensors@2.X-fakesubhal-defaults"],
    cflags: [
        "-DSUB_HAL_VERSION_2_0",
        "-DSUPPORT_CONTINUOUS_SENSORS",
        "-DSUB_HAL_NAME=\"FakeSubHal-Continuous\"",
    ],
@@ -59,6 +60,17 @@ cc_library {
    name: "android.hardware.sensors@2.X-fakesubhal-config2",
    vendor: true,
    defaults: ["android.hardware.sensors@2.X-fakesubhal-defaults"],
    cflags: [
        "-DSUB_HAL_VERSION_2_0",
        "-DSUPPORT_ON_CHANGE_SENSORS",
        "-DSUB_HAL_NAME=\"FakeSubHal-OnChange\"",
    ],
}

cc_library {
    name: "android.hardware.sensors@2.X-fakesubhal-config3",
    vendor: true,
    defaults: ["android.hardware.sensors@2.X-fakesubhal-defaults"],
    cflags: [
        "-DSUPPORT_ON_CHANGE_SENSORS",
        "-DSUB_HAL_NAME=\"FakeSubHal-OnChange\"",
+195 −132

File changed.

Preview size limit exceeded, changes collapsed.

+107 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "V2_0/SubHal.h"
#include "V2_1/SubHal.h"
#include "convertV2_1.h"

namespace android {
namespace hardware {
namespace sensors {
namespace V2_1 {
namespace subhal {
namespace implementation {

/**
 * The following callback wrapper classes abstract away common functionality across V2.0 and V2.1
 * interfaces. Much of the logic is common between the two versions and this allows users of the
 * classes to only care about the type used at initialization and then interact with either version
 * of the callback interface without worrying about the type.
 */
class IHalProxyCallbackWrapperBase {
  protected:
    using ScopedWakelock = V2_0::implementation::ScopedWakelock;

  public:
    virtual ~IHalProxyCallbackWrapperBase() {}

    virtual Return<void> onDynamicSensorsConnected(
            const hidl_vec<V2_1::SensorInfo>& sensorInfos) = 0;

    virtual Return<void> onDynamicSensorsDisconnected(const hidl_vec<int32_t>& sensorHandles) = 0;

    virtual void postEvents(const std::vector<V2_1::Event>& events, ScopedWakelock wakelock) = 0;

    virtual ScopedWakelock createScopedWakelock(bool lock) = 0;
};

template <typename T>
class HalProxyCallbackWrapperBase : public IHalProxyCallbackWrapperBase {
  public:
    HalProxyCallbackWrapperBase(sp<T> callback) : mCallback(callback){};

    Return<void> onDynamicSensorsDisconnected(const hidl_vec<int32_t>& sensorHandles) override {
        return mCallback->onDynamicSensorsDisconnected(sensorHandles);
    }

    ScopedWakelock createScopedWakelock(bool lock) override {
        return mCallback->createScopedWakelock(lock);
    }

  protected:
    sp<T> mCallback;
};

class HalProxyCallbackWrapperV2_0
    : public HalProxyCallbackWrapperBase<V2_0::implementation::IHalProxyCallback> {
  public:
    HalProxyCallbackWrapperV2_0(sp<V2_0::implementation::IHalProxyCallback> callback)
        : HalProxyCallbackWrapperBase(callback){};

    Return<void> onDynamicSensorsConnected(const hidl_vec<V2_1::SensorInfo>& sensorInfos) override {
        return mCallback->onDynamicSensorsConnected(
                V2_1::implementation::convertToOldSensorInfos(sensorInfos));
    }

    void postEvents(const std::vector<V2_1::Event>& events, ScopedWakelock wakelock) override {
        return mCallback->postEvents(V2_1::implementation::convertToOldEvents(events),
                                     std::move(wakelock));
    }
};

class HalProxyCallbackWrapperV2_1
    : public HalProxyCallbackWrapperBase<V2_1::implementation::IHalProxyCallback> {
  public:
    HalProxyCallbackWrapperV2_1(sp<V2_1::implementation::IHalProxyCallback> callback)
        : HalProxyCallbackWrapperBase(callback){};

    Return<void> onDynamicSensorsConnected(const hidl_vec<V2_1::SensorInfo>& sensorInfos) override {
        return mCallback->onDynamicSensorsConnected_2_1(sensorInfos);
    }

    void postEvents(const std::vector<V2_1::Event>& events, ScopedWakelock wakelock) {
        return mCallback->postEvents(events, std::move(wakelock));
    }
};

}  // namespace implementation
}  // namespace subhal
}  // namespace V2_1
}  // namespace sensors
}  // namespace hardware
}  // namespace android
+7 −2
Original line number Diff line number Diff line
@@ -24,13 +24,18 @@
namespace android {
namespace hardware {
namespace sensors {
namespace V2_0 {
namespace V2_1 {
namespace subhal {
namespace implementation {

using ::android::hardware::sensors::V1_0::MetaDataEventType;
using ::android::hardware::sensors::V1_0::OperationMode;
using ::android::hardware::sensors::V1_0::Result;
using ::android::hardware::sensors::V1_0::SensorFlagBits;
using ::android::hardware::sensors::V1_0::SensorStatus;
using ::android::hardware::sensors::V2_1::Event;
using ::android::hardware::sensors::V2_1::SensorInfo;
using ::android::hardware::sensors::V2_1::SensorType;

Sensor::Sensor(int32_t sensorHandle, ISensorsEventCallback* callback)
    : mIsEnabled(false),
@@ -343,7 +348,7 @@ RelativeHumiditySensor::RelativeHumiditySensor(int32_t sensorHandle,

}  // namespace implementation
}  // namespace subhal
}  // namespace V2_0
}  // namespace V2_1
}  // namespace sensors
}  // namespace hardware
}  // namespace android
+6 −6
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

#pragma once

#include <android/hardware/sensors/1.0/types.h>
#include <android/hardware/sensors/2.1/types.h>

#include <condition_variable>
#include <memory>
@@ -24,16 +24,16 @@
#include <thread>
#include <vector>

using ::android::hardware::sensors::V1_0::Event;
using ::android::hardware::sensors::V1_0::OperationMode;
using ::android::hardware::sensors::V1_0::Result;
using ::android::hardware::sensors::V1_0::SensorInfo;
using ::android::hardware::sensors::V1_0::SensorType;
using ::android::hardware::sensors::V2_1::Event;
using ::android::hardware::sensors::V2_1::SensorInfo;
using ::android::hardware::sensors::V2_1::SensorType;

namespace android {
namespace hardware {
namespace sensors {
namespace V2_0 {
namespace V2_1 {
namespace subhal {
namespace implementation {

@@ -151,7 +151,7 @@ class RelativeHumiditySensor : public OnChangeSensor {

}  // namespace implementation
}  // namespace subhal
}  // namespace V2_0
}  // namespace V2_1
}  // namespace sensors
}  // namespace hardware
}  // namespace android
Loading