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

Commit b1691e85 authored by Peiyong Lin's avatar Peiyong Lin Committed by Gerrit Code Review
Browse files

Merge "Align default implementation with latest VSR."

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


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


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


#include <android-base/logging.h>
#include <android-base/logging.h>


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


using namespace std::chrono_literals;

using ndk::ScopedAStatus;

const std::vector<Boost> BOOST_RANGE{ndk::enum_range<Boost>().begin(),
const std::vector<Boost> BOOST_RANGE{ndk::enum_range<Boost>().begin(),
                                     ndk::enum_range<Boost>().end()};
                                     ndk::enum_range<Boost>().end()};
const std::vector<Mode> MODE_RANGE{ndk::enum_range<Mode>().begin(), ndk::enum_range<Mode>().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;
    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);
    LOG(INFO) << "Power isModeSupported: " << static_cast<int32_t>(type);
    *_aidl_return = type >= MODE_RANGE.front() && type <= MODE_RANGE.back();
    *_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)
    LOG(VERBOSE) << "Power setBoost: " << static_cast<int32_t>(type)
                 << ", duration: " << durationMs;
                 << ", 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);
    LOG(INFO) << "Power isBoostSupported: " << static_cast<int32_t>(type);
    *_aidl_return = type >= BOOST_RANGE.front() && type <= BOOST_RANGE.back();
    *_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) {
                                       std::shared_ptr<IPowerHintSession>* _aidl_return) {
    if (tids.size() == 0) {
        *_aidl_return = nullptr;
        *_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) {
ScopedAStatus Power::getHintSessionPreferredRate(int64_t* outNanoseconds) {
    *outNanoseconds = -1;
    *outNanoseconds = std::chrono::nanoseconds(1ms).count();
    return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
    return ScopedAStatus::ok();
}
}


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


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

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


}  // namespace example
}  // namespace example
+50 −0
Original line number Original line 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 Original line 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