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

Commit c67f5149 authored by Peiyong Lin's avatar Peiyong Lin Committed by Automerger Merge Worker
Browse files

Merge "Align default implementation with latest VSR." am: b1691e85 am: f85b1d5e

parents b54957cd f85b1d5e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ cc_binary {
    srcs: [
        "main.cpp",
        "Power.cpp",
        "PowerHintSession.cpp",
    ],
}

+27 −15
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */

#include "Power.h"
#include "PowerHintSession.h"

#include <android-base/logging.h>

@@ -25,42 +26,53 @@ namespace power {
namespace impl {
namespace example {

using namespace std::chrono_literals;

using ndk::ScopedAStatus;

const std::vector<Boost> BOOST_RANGE{ndk::enum_range<Boost>().begin(),
                                     ndk::enum_range<Boost>().end()};
const std::vector<Mode> MODE_RANGE{ndk::enum_range<Mode>().begin(), ndk::enum_range<Mode>().end()};

ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) {
ScopedAStatus Power::setMode(Mode type, bool enabled) {
    LOG(VERBOSE) << "Power setMode: " << static_cast<int32_t>(type) << " to: " << enabled;
    return ndk::ScopedAStatus::ok();
    return ScopedAStatus::ok();
}

ndk::ScopedAStatus Power::isModeSupported(Mode type, bool* _aidl_return) {
ScopedAStatus Power::isModeSupported(Mode type, bool* _aidl_return) {
    LOG(INFO) << "Power isModeSupported: " << static_cast<int32_t>(type);
    *_aidl_return = type >= MODE_RANGE.front() && type <= MODE_RANGE.back();
    return ndk::ScopedAStatus::ok();
    return ScopedAStatus::ok();
}

ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) {
ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) {
    LOG(VERBOSE) << "Power setBoost: " << static_cast<int32_t>(type)
                 << ", duration: " << durationMs;
    return ndk::ScopedAStatus::ok();
    return ScopedAStatus::ok();
}

ndk::ScopedAStatus Power::isBoostSupported(Boost type, bool* _aidl_return) {
ScopedAStatus Power::isBoostSupported(Boost type, bool* _aidl_return) {
    LOG(INFO) << "Power isBoostSupported: " << static_cast<int32_t>(type);
    *_aidl_return = type >= BOOST_RANGE.front() && type <= BOOST_RANGE.back();
    return ndk::ScopedAStatus::ok();
    return ScopedAStatus::ok();
}

ndk::ScopedAStatus Power::createHintSession(int32_t, int32_t, const std::vector<int32_t>&, int64_t,
ScopedAStatus Power::createHintSession(int32_t, int32_t, const std::vector<int32_t>& tids, int64_t,
                                       std::shared_ptr<IPowerHintSession>* _aidl_return) {
    if (tids.size() == 0) {
        *_aidl_return = nullptr;
    return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
        return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
    }
    std::shared_ptr<IPowerHintSession> powerHintSession =
            ndk::SharedRefBase::make<PowerHintSession>();
    mPowerHintSessions.push_back(powerHintSession);
    *_aidl_return = powerHintSession;
    return ScopedAStatus::ok();
}

ndk::ScopedAStatus Power::getHintSessionPreferredRate(int64_t* outNanoseconds) {
    *outNanoseconds = -1;
    return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
ScopedAStatus Power::getHintSessionPreferredRate(int64_t* outNanoseconds) {
    *outNanoseconds = std::chrono::nanoseconds(1ms).count();
    return ScopedAStatus::ok();
}

}  // namespace example
+4 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ namespace impl {
namespace example {

class Power : public BnPower {
  public:
    ndk::ScopedAStatus setMode(Mode type, bool enabled) override;
    ndk::ScopedAStatus isModeSupported(Mode type, bool* _aidl_return) override;
    ndk::ScopedAStatus setBoost(Boost type, int32_t durationMs) override;
@@ -35,6 +36,9 @@ class Power : public BnPower {
                                         int64_t durationNanos,
                                         std::shared_ptr<IPowerHintSession>* _aidl_return) override;
    ndk::ScopedAStatus getHintSessionPreferredRate(int64_t* outNanoseconds) override;

  private:
    std::vector<std::shared_ptr<IPowerHintSession>> mPowerHintSessions;
};

}  // namespace example
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.
 */

#include "PowerHintSession.h"

#include <android-base/logging.h>

namespace aidl::android::hardware::power::impl::example {

using ndk::ScopedAStatus;

PowerHintSession::PowerHintSession() {}

ScopedAStatus PowerHintSession::updateTargetWorkDuration(int64_t targetDurationNanos) {
    LOG(VERBOSE) << __func__ << "target duration in nanoseconds: " << targetDurationNanos;
    return ScopedAStatus::ok();
}

ScopedAStatus PowerHintSession::reportActualWorkDuration(
        const std::vector<WorkDuration>& /* durations */) {
    LOG(VERBOSE) << __func__;
    return ScopedAStatus::ok();
}

ScopedAStatus PowerHintSession::pause() {
    return ScopedAStatus::ok();
}

ScopedAStatus PowerHintSession::resume() {
    return ScopedAStatus::ok();
}

ScopedAStatus PowerHintSession::close() {
    return ScopedAStatus::ok();
}

}  // namespace aidl::android::hardware::power::impl::example
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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 <aidl/android/hardware/power/BnPowerHintSession.h>
#include <aidl/android/hardware/power/WorkDuration.h>

namespace aidl::android::hardware::power::impl::example {

class PowerHintSession : public BnPowerHintSession {
  public:
    explicit PowerHintSession();
    ndk::ScopedAStatus updateTargetWorkDuration(int64_t targetDurationNanos) override;
    ndk::ScopedAStatus reportActualWorkDuration(
            const std::vector<WorkDuration>& durations) override;
    ndk::ScopedAStatus pause() override;
    ndk::ScopedAStatus resume() override;
    ndk::ScopedAStatus close() override;
};

}  // namespace aidl::android::hardware::power::impl::example