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

Commit 424c520d authored by Matt Buckley's avatar Matt Buckley Committed by Android (Google) Code Review
Browse files

Merge "Add support for new PowerHAL methods to PowerHalWrapper" into main

parents e53224ab db4192ad
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -62,7 +62,15 @@ public:
    virtual HalResult<std::shared_ptr<aidl::android::hardware::power::IPowerHintSession>>
    createHintSession(int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
                      int64_t durationNanos) override;
    virtual HalResult<std::shared_ptr<aidl::android::hardware::power::IPowerHintSession>>
    createHintSessionWithConfig(int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
                                int64_t durationNanos,
                                aidl::android::hardware::power::SessionTag tag,
                                aidl::android::hardware::power::SessionConfig* config) override;
    virtual HalResult<int64_t> getHintSessionPreferredRate() override;
    virtual HalResult<aidl::android::hardware::power::ChannelConfig> getSessionChannel(
            int tgid, int uid) override;
    virtual HalResult<void> closeSessionChannel(int tgid, int uid) override;

private:
    std::mutex mConnectedHalMutex;
@@ -75,7 +83,7 @@ private:

    std::shared_ptr<HalWrapper> initHal();
    template <typename T>
    HalResult<T> processHalResult(HalResult<T> result, const char* functionName);
    HalResult<T> processHalResult(HalResult<T>&& result, const char* functionName);
};

// -------------------------------------------------------------------------------------------------
+72 −24
Original line number Diff line number Diff line
@@ -14,19 +14,22 @@
 * limitations under the License.
 */

#ifndef ANDROID_POWERHALWRAPPER_H
#define ANDROID_POWERHALWRAPPER_H
#pragma once

#include <aidl/android/hardware/power/Boost.h>
#include <aidl/android/hardware/power/ChannelConfig.h>
#include <aidl/android/hardware/power/IPower.h>
#include <aidl/android/hardware/power/IPowerHintSession.h>
#include <aidl/android/hardware/power/Mode.h>
#include <aidl/android/hardware/power/SessionConfig.h>
#include <android-base/thread_annotations.h>
#include <android/hardware/power/1.1/IPower.h>
#include <android/hardware/power/1.2/IPower.h>
#include <android/hardware/power/1.3/IPower.h>
#include <binder/Status.h>

#include <utility>

namespace android {

namespace power {
@@ -42,44 +45,63 @@ enum class HalSupport {
template <typename T>
class HalResult {
public:
    static HalResult<T> ok(T value) { return HalResult(value); }
    static HalResult<T> failed(std::string msg) {
        return HalResult(std::move(msg), /* unsupported= */ false);
    }
    static HalResult<T> ok(T&& value) { return HalResult(std::forward<T>(value)); }
    static HalResult<T> ok(T& value) { return HalResult<T>::ok(T{value}); }
    static HalResult<T> failed(std::string msg) { return HalResult(msg, /* unsupported= */ false); }
    static HalResult<T> unsupported() { return HalResult("", /* unsupported= */ true); }

    static HalResult<T> fromStatus(const binder::Status& status, T data) {
    static HalResult<T> fromStatus(const binder::Status& status, T&& data) {
        if (status.exceptionCode() == binder::Status::EX_UNSUPPORTED_OPERATION) {
            return HalResult<T>::unsupported();
        }
        if (status.isOk()) {
            return HalResult<T>::ok(data);
            return HalResult<T>::ok(std::forward<T>(data));
        }
        return HalResult<T>::failed(std::string(status.toString8().c_str()));
    }

    static HalResult<T> fromStatus(const ndk::ScopedAStatus& status, T data) {
    static HalResult<T> fromStatus(const binder::Status& status, T& data) {
        return HalResult<T>::fromStatus(status, T{data});
    }

    static HalResult<T> fromStatus(const ndk::ScopedAStatus& status, T&& data) {
        if (status.getExceptionCode() == binder::Status::EX_UNSUPPORTED_OPERATION) {
            return HalResult<T>::unsupported();
        }
        if (status.isOk()) {
            return HalResult<T>::ok(data);
            return HalResult<T>::ok(std::forward<T>(data));
        }
        return HalResult<T>::failed(std::string(status.getDescription()));
    }

    static HalResult<T> fromStatus(const ndk::ScopedAStatus& status, T& data) {
        return HalResult<T>::fromStatus(status, T{data});
    }

    template <typename R>
    static HalResult<T> fromReturn(hardware::Return<R>& ret, T data) {
        return ret.isOk() ? HalResult<T>::ok(data) : HalResult<T>::failed(ret.description());
    static HalResult<T> fromReturn(hardware::Return<R>& ret, T&& data) {
        return ret.isOk() ? HalResult<T>::ok(std::forward<T>(data))
                          : HalResult<T>::failed(ret.description());
    }

    template <typename R>
    static HalResult<T> fromReturn(hardware::Return<R>& ret, T& data) {
        return HalResult<T>::fromReturn(ret, T{data});
    }

    template <typename R>
    static HalResult<T> fromReturn(hardware::Return<R>& ret, hardware::power::V1_0::Status status,
                                   T data) {
        return ret.isOk() ? HalResult<T>::fromStatus(status, data)
                                   T&& data) {
        return ret.isOk() ? HalResult<T>::fromStatus(status, std::forward<T>(data))
                          : HalResult<T>::failed(ret.description());
    }

    template <typename R>
    static HalResult<T> fromReturn(hardware::Return<R>& ret, hardware::power::V1_0::Status status,
                                   T& data) {
        return HalResult<T>::fromReturn(ret, status, T{data});
    }

    // This will throw std::bad_optional_access if this result is not ok.
    const T& value() const { return mValue.value(); }
    bool isOk() const { return !mUnsupported && mValue.has_value(); }
@@ -92,8 +114,8 @@ private:
    std::string mErrorMessage;
    bool mUnsupported;

    explicit HalResult(T value)
          : mValue(std::make_optional(value)), mErrorMessage(), mUnsupported(false) {}
    explicit HalResult(T&& value)
          : mValue{std::move(value)}, mErrorMessage(), mUnsupported(false) {}
    explicit HalResult(std::string errorMessage, bool unsupported)
          : mValue(), mErrorMessage(std::move(errorMessage)), mUnsupported(unsupported) {}
};
@@ -158,7 +180,15 @@ public:
    virtual HalResult<std::shared_ptr<aidl::android::hardware::power::IPowerHintSession>>
    createHintSession(int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
                      int64_t durationNanos) = 0;
    virtual HalResult<std::shared_ptr<aidl::android::hardware::power::IPowerHintSession>>
    createHintSessionWithConfig(int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
                                int64_t durationNanos,
                                aidl::android::hardware::power::SessionTag tag,
                                aidl::android::hardware::power::SessionConfig* config) = 0;
    virtual HalResult<int64_t> getHintSessionPreferredRate() = 0;
    virtual HalResult<aidl::android::hardware::power::ChannelConfig> getSessionChannel(int tgid,
                                                                                       int uid) = 0;
    virtual HalResult<void> closeSessionChannel(int tgid, int uid) = 0;
};

// Empty Power HAL wrapper that ignores all api calls.
@@ -173,11 +203,22 @@ public:
    HalResult<std::shared_ptr<aidl::android::hardware::power::IPowerHintSession>> createHintSession(
            int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
            int64_t durationNanos) override;
    HalResult<std::shared_ptr<aidl::android::hardware::power::IPowerHintSession>>
    createHintSessionWithConfig(int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
                                int64_t durationNanos,
                                aidl::android::hardware::power::SessionTag tag,
                                aidl::android::hardware::power::SessionConfig* config) override;
    HalResult<int64_t> getHintSessionPreferredRate() override;
    HalResult<aidl::android::hardware::power::ChannelConfig> getSessionChannel(int tgid,
                                                                               int uid) override;
    HalResult<void> closeSessionChannel(int tgid, int uid) override;

protected:
    virtual const char* getUnsupportedMessage();
};

// Wrapper for the HIDL Power HAL v1.0.
class HidlHalWrapperV1_0 : public HalWrapper {
class HidlHalWrapperV1_0 : public EmptyHalWrapper {
public:
    explicit HidlHalWrapperV1_0(sp<hardware::power::V1_0::IPower> handleV1_0)
          : mHandleV1_0(std::move(handleV1_0)) {}
@@ -186,14 +227,11 @@ public:
    HalResult<void> setBoost(aidl::android::hardware::power::Boost boost,
                             int32_t durationMs) override;
    HalResult<void> setMode(aidl::android::hardware::power::Mode mode, bool enabled) override;
    HalResult<std::shared_ptr<aidl::android::hardware::power::IPowerHintSession>> createHintSession(
            int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
            int64_t durationNanos) override;
    HalResult<int64_t> getHintSessionPreferredRate() override;

protected:
    const sp<hardware::power::V1_0::IPower> mHandleV1_0;
    virtual HalResult<void> sendPowerHint(hardware::power::V1_3::PowerHint hintId, uint32_t data);
    const char* getUnsupportedMessage();

private:
    HalResult<void> setInteractive(bool enabled);
@@ -238,7 +276,7 @@ protected:
};

// Wrapper for the AIDL Power HAL.
class AidlHalWrapper : public HalWrapper {
class AidlHalWrapper : public EmptyHalWrapper {
public:
    explicit AidlHalWrapper(std::shared_ptr<aidl::android::hardware::power::IPower> handle)
          : mHandle(std::move(handle)) {}
@@ -250,7 +288,19 @@ public:
    HalResult<std::shared_ptr<aidl::android::hardware::power::IPowerHintSession>> createHintSession(
            int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
            int64_t durationNanos) override;
    HalResult<std::shared_ptr<aidl::android::hardware::power::IPowerHintSession>>
    createHintSessionWithConfig(int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
                                int64_t durationNanos,
                                aidl::android::hardware::power::SessionTag tag,
                                aidl::android::hardware::power::SessionConfig* config) override;

    HalResult<int64_t> getHintSessionPreferredRate() override;
    HalResult<aidl::android::hardware::power::ChannelConfig> getSessionChannel(int tgid,
                                                                               int uid) override;
    HalResult<void> closeSessionChannel(int tgid, int uid) override;

protected:
    const char* getUnsupportedMessage() override;

private:
    // Control access to the boost and mode supported arrays.
@@ -274,5 +324,3 @@ private:
}; // namespace power

}; // namespace android

#endif // ANDROID_POWERHALWRAPPER_H
+28 −9
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ std::shared_ptr<HalWrapper> PowerHalController::initHal() {
// Check if a call to Power HAL function failed; if so, log the failure and
// invalidate the current Power HAL handle.
template <typename T>
HalResult<T> PowerHalController::processHalResult(HalResult<T> result, const char* fnName) {
HalResult<T> PowerHalController::processHalResult(HalResult<T>&& result, const char* fnName) {
    if (result.isFailed()) {
        ALOGE("%s failed: %s", fnName, result.errorMessage());
        std::lock_guard<std::mutex> lock(mConnectedHalMutex);
@@ -94,15 +94,13 @@ HalResult<T> PowerHalController::processHalResult(HalResult<T> result, const cha
HalResult<void> PowerHalController::setBoost(aidl::android::hardware::power::Boost boost,
                                             int32_t durationMs) {
    std::shared_ptr<HalWrapper> handle = initHal();
    auto result = handle->setBoost(boost, durationMs);
    return processHalResult(result, "setBoost");
    return processHalResult(handle->setBoost(boost, durationMs), "setBoost");
}

HalResult<void> PowerHalController::setMode(aidl::android::hardware::power::Mode mode,
                                            bool enabled) {
    std::shared_ptr<HalWrapper> handle = initHal();
    auto result = handle->setMode(mode, enabled);
    return processHalResult(result, "setMode");
    return processHalResult(handle->setMode(mode, enabled), "setMode");
}

HalResult<std::shared_ptr<aidl::android::hardware::power::IPowerHintSession>>
@@ -110,14 +108,35 @@ PowerHalController::createHintSession(int32_t tgid, int32_t uid,
                                      const std::vector<int32_t>& threadIds,
                                      int64_t durationNanos) {
    std::shared_ptr<HalWrapper> handle = initHal();
    auto result = handle->createHintSession(tgid, uid, threadIds, durationNanos);
    return processHalResult(result, "createHintSession");
    return processHalResult(handle->createHintSession(tgid, uid, threadIds, durationNanos),
                            "createHintSession");
}

HalResult<std::shared_ptr<aidl::android::hardware::power::IPowerHintSession>>
PowerHalController::createHintSessionWithConfig(
        int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds, int64_t durationNanos,
        aidl::android::hardware::power::SessionTag tag,
        aidl::android::hardware::power::SessionConfig* config) {
    std::shared_ptr<HalWrapper> handle = initHal();
    return processHalResult(handle->createHintSessionWithConfig(tgid, uid, threadIds, durationNanos,
                                                                tag, config),
                            "createHintSessionWithConfig");
}

HalResult<int64_t> PowerHalController::getHintSessionPreferredRate() {
    std::shared_ptr<HalWrapper> handle = initHal();
    auto result = handle->getHintSessionPreferredRate();
    return processHalResult(result, "getHintSessionPreferredRate");
    return processHalResult(handle->getHintSessionPreferredRate(), "getHintSessionPreferredRate");
}

HalResult<aidl::android::hardware::power::ChannelConfig> PowerHalController::getSessionChannel(
        int tgid, int uid) {
    std::shared_ptr<HalWrapper> handle = initHal();
    return processHalResult(handle->getSessionChannel(tgid, uid), "getSessionChannel");
}

HalResult<void> PowerHalController::closeSessionChannel(int tgid, int uid) {
    std::shared_ptr<HalWrapper> handle = initHal();
    return processHalResult(handle->closeSessionChannel(tgid, uid), "closeSessionChannel");
}

} // namespace power
+63 −29
Original line number Diff line number Diff line
@@ -42,37 +42,58 @@ inline HalResult<void> toHalResult(const ndk::ScopedAStatus& result) {
// -------------------------------------------------------------------------------------------------

HalResult<void> EmptyHalWrapper::setBoost(Aidl::Boost boost, int32_t durationMs) {
    ALOGV("Skipped setBoost %s with duration %dms because Power HAL not available",
          toString(boost).c_str(), durationMs);
    ALOGV("Skipped setBoost %s with duration %dms because %s", toString(boost).c_str(), durationMs,
          getUnsupportedMessage());
    return HalResult<void>::unsupported();
}

HalResult<void> EmptyHalWrapper::setMode(Aidl::Mode mode, bool enabled) {
    ALOGV("Skipped setMode %s to %s because Power HAL not available", toString(mode).c_str(),
          enabled ? "true" : "false");
    ALOGV("Skipped setMode %s to %s because %s", toString(mode).c_str(), enabled ? "true" : "false",
          getUnsupportedMessage());
    return HalResult<void>::unsupported();
}

HalResult<std::shared_ptr<Aidl::IPowerHintSession>> EmptyHalWrapper::createHintSession(
        int32_t, int32_t, const std::vector<int32_t>& threadIds, int64_t) {
    ALOGV("Skipped createHintSession(task num=%zu) because Power HAL not available",
          threadIds.size());
    ALOGV("Skipped createHintSession(task num=%zu) because %s", threadIds.size(),
          getUnsupportedMessage());
    return HalResult<std::shared_ptr<Aidl::IPowerHintSession>>::unsupported();
}

HalResult<std::shared_ptr<Aidl::IPowerHintSession>> EmptyHalWrapper::createHintSessionWithConfig(
        int32_t, int32_t, const std::vector<int32_t>& threadIds, int64_t, Aidl::SessionTag,
        Aidl::SessionConfig*) {
    ALOGV("Skipped createHintSessionWithConfig(task num=%zu) because %s", threadIds.size(),
          getUnsupportedMessage());
    return HalResult<std::shared_ptr<Aidl::IPowerHintSession>>::unsupported();
}

HalResult<int64_t> EmptyHalWrapper::getHintSessionPreferredRate() {
    ALOGV("Skipped getHintSessionPreferredRate because Power HAL not available");
    ALOGV("Skipped getHintSessionPreferredRate because %s", getUnsupportedMessage());
    return HalResult<int64_t>::unsupported();
}

HalResult<Aidl::ChannelConfig> EmptyHalWrapper::getSessionChannel(int, int) {
    ALOGV("Skipped getSessionChannel because %s", getUnsupportedMessage());
    return HalResult<Aidl::ChannelConfig>::unsupported();
}

HalResult<void> EmptyHalWrapper::closeSessionChannel(int, int) {
    ALOGV("Skipped closeSessionChannel because %s", getUnsupportedMessage());
    return HalResult<void>::unsupported();
}

const char* EmptyHalWrapper::getUnsupportedMessage() {
    return "Power HAL is not supported";
}

// -------------------------------------------------------------------------------------------------

HalResult<void> HidlHalWrapperV1_0::setBoost(Aidl::Boost boost, int32_t durationMs) {
    if (boost == Aidl::Boost::INTERACTION) {
        return sendPowerHint(V1_3::PowerHint::INTERACTION, durationMs);
    } else {
        ALOGV("Skipped setBoost %s because Power HAL AIDL not available", toString(boost).c_str());
        return HalResult<void>::unsupported();
        return EmptyHalWrapper::setBoost(boost, durationMs);
    }
}

@@ -92,9 +113,7 @@ HalResult<void> HidlHalWrapperV1_0::setMode(Aidl::Mode mode, bool enabled) {
        case Aidl::Mode::DOUBLE_TAP_TO_WAKE:
            return setFeature(V1_0::Feature::POWER_FEATURE_DOUBLE_TAP_TO_WAKE, enabled);
        default:
            ALOGV("Skipped setMode %s because Power HAL AIDL not available",
                  toString(mode).c_str());
            return HalResult<void>::unsupported();
            return EmptyHalWrapper::setMode(mode, enabled);
    }
}

@@ -113,16 +132,8 @@ HalResult<void> HidlHalWrapperV1_0::setFeature(V1_0::Feature feature, bool enabl
    return HalResult<void>::fromReturn(ret);
}

HalResult<std::shared_ptr<Aidl::IPowerHintSession>> HidlHalWrapperV1_0::createHintSession(
        int32_t, int32_t, const std::vector<int32_t>& threadIds, int64_t) {
    ALOGV("Skipped createHintSession(task num=%zu) because Power HAL not available",
          threadIds.size());
    return HalResult<std::shared_ptr<Aidl::IPowerHintSession>>::unsupported();
}

HalResult<int64_t> HidlHalWrapperV1_0::getHintSessionPreferredRate() {
    ALOGV("Skipped getHintSessionPreferredRate because Power HAL not available");
    return HalResult<int64_t>::unsupported();
const char* HidlHalWrapperV1_0::getUnsupportedMessage() {
    return "Power HAL AIDL is not supported";
}

// -------------------------------------------------------------------------------------------------
@@ -191,7 +202,7 @@ HalResult<void> AidlHalWrapper::setBoost(Aidl::Boost boost, int32_t durationMs)

    // Quick return if boost is not supported by HAL
    if (idx >= mBoostSupportedArray.size() || mBoostSupportedArray[idx] == HalSupport::OFF) {
        ALOGV("Skipped setBoost %s because Power HAL doesn't support it", toString(boost).c_str());
        ALOGV("Skipped setBoost %s because %s", toString(boost).c_str(), getUnsupportedMessage());
        return HalResult<void>::unsupported();
    }

@@ -207,8 +218,8 @@ HalResult<void> AidlHalWrapper::setBoost(Aidl::Boost boost, int32_t durationMs)

        mBoostSupportedArray[idx] = isSupported ? HalSupport::ON : HalSupport::OFF;
        if (!isSupported) {
            ALOGV("Skipped setBoost %s because Power HAL doesn't support it",
                  toString(boost).c_str());
            ALOGV("Skipped setBoost %s because %s", toString(boost).c_str(),
                  getUnsupportedMessage());
            return HalResult<void>::unsupported();
        }
    }
@@ -223,7 +234,7 @@ HalResult<void> AidlHalWrapper::setMode(Aidl::Mode mode, bool enabled) {

    // Quick return if mode is not supported by HAL
    if (idx >= mModeSupportedArray.size() || mModeSupportedArray[idx] == HalSupport::OFF) {
        ALOGV("Skipped setMode %s because Power HAL doesn't support it", toString(mode).c_str());
        ALOGV("Skipped setMode %s because %s", toString(mode).c_str(), getUnsupportedMessage());
        return HalResult<void>::unsupported();
    }

@@ -236,8 +247,7 @@ HalResult<void> AidlHalWrapper::setMode(Aidl::Mode mode, bool enabled) {

        mModeSupportedArray[idx] = isSupported ? HalSupport::ON : HalSupport::OFF;
        if (!isSupported) {
            ALOGV("Skipped setMode %s because Power HAL doesn't support it",
                  toString(mode).c_str());
            ALOGV("Skipped setMode %s because %s", toString(mode).c_str(), getUnsupportedMessage());
            return HalResult<void>::unsupported();
        }
    }
@@ -251,7 +261,17 @@ HalResult<std::shared_ptr<Aidl::IPowerHintSession>> AidlHalWrapper::createHintSe
    std::shared_ptr<Aidl::IPowerHintSession> appSession;
    return HalResult<std::shared_ptr<Aidl::IPowerHintSession>>::
            fromStatus(mHandle->createHintSession(tgid, uid, threadIds, durationNanos, &appSession),
                       appSession);
                       std::move(appSession));
}

HalResult<std::shared_ptr<Aidl::IPowerHintSession>> AidlHalWrapper::createHintSessionWithConfig(
        int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds, int64_t durationNanos,
        Aidl::SessionTag tag, Aidl::SessionConfig* config) {
    std::shared_ptr<Aidl::IPowerHintSession> appSession;
    return HalResult<std::shared_ptr<Aidl::IPowerHintSession>>::
            fromStatus(mHandle->createHintSessionWithConfig(tgid, uid, threadIds, durationNanos,
                                                            tag, config, &appSession),
                       std::move(appSession));
}

HalResult<int64_t> AidlHalWrapper::getHintSessionPreferredRate() {
@@ -260,6 +280,20 @@ HalResult<int64_t> AidlHalWrapper::getHintSessionPreferredRate() {
    return HalResult<int64_t>::fromStatus(result, rate);
}

HalResult<Aidl::ChannelConfig> AidlHalWrapper::getSessionChannel(int tgid, int uid) {
    Aidl::ChannelConfig config;
    auto result = mHandle->getSessionChannel(tgid, uid, &config);
    return HalResult<Aidl::ChannelConfig>::fromStatus(result, std::move(config));
}

HalResult<void> AidlHalWrapper::closeSessionChannel(int tgid, int uid) {
    return toHalResult(mHandle->closeSessionChannel(tgid, uid));
}

const char* AidlHalWrapper::getUnsupportedMessage() {
    return "Power HAL doesn't support it";
}

// -------------------------------------------------------------------------------------------------

} // namespace power
+32 −0
Original line number Diff line number Diff line
@@ -256,6 +256,23 @@ TEST_F(PowerHalWrapperAidlTest, TestCreateHintSessionSuccessful) {
    ASSERT_TRUE(result.isOk());
}

TEST_F(PowerHalWrapperAidlTest, TestCreateHintSessionWithConfigSuccessful) {
    std::vector<int> threadIds{gettid()};
    int32_t tgid = 999;
    int32_t uid = 1001;
    int64_t durationNanos = 16666666L;
    SessionTag tag = SessionTag::OTHER;
    SessionConfig out;
    EXPECT_CALL(*mMockHal.get(),
                createHintSessionWithConfig(Eq(tgid), Eq(uid), Eq(threadIds), Eq(durationNanos),
                                            Eq(tag), _, _))
            .Times(Exactly(1))
            .WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::ok())));
    auto result =
            mWrapper->createHintSessionWithConfig(tgid, uid, threadIds, durationNanos, tag, &out);
    ASSERT_TRUE(result.isOk());
}

TEST_F(PowerHalWrapperAidlTest, TestCreateHintSessionFailed) {
    int32_t tgid = 999;
    int32_t uid = 1001;
@@ -279,3 +296,18 @@ TEST_F(PowerHalWrapperAidlTest, TestGetHintSessionPreferredRate) {
    int64_t rate = result.value();
    ASSERT_GE(0, rate);
}

TEST_F(PowerHalWrapperAidlTest, TestSessionChannel) {
    int32_t tgid = 999;
    int32_t uid = 1001;
    EXPECT_CALL(*mMockHal.get(), getSessionChannel(Eq(tgid), Eq(uid), _))
            .Times(Exactly(1))
            .WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::ok())));
    EXPECT_CALL(*mMockHal.get(), closeSessionChannel(Eq(tgid), Eq(uid)))
            .Times(Exactly(1))
            .WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::ok())));
    auto createResult = mWrapper->getSessionChannel(tgid, uid);
    ASSERT_TRUE(createResult.isOk());
    auto closeResult = mWrapper->closeSessionChannel(tgid, uid);
    ASSERT_TRUE(closeResult.isOk());
}
Loading