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

Commit 35197b7a authored by Philip Cuadra's avatar Philip Cuadra Committed by Android (Google) Code Review
Browse files

Merge "Add powerHintAsync functionality" into oc-dr1-dev

parents 4bd2ed23 48750dc0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -197,7 +197,7 @@ fe3c3c2f572b72f15f8594c538b0577bd5c28722c31879cfe6231330cddb6747 android.hardwar

4b65763663a94a3920134011691f8fbb42ccb7b7795589efddc049a9106047d6 android.hardware.oemlock@1.0::IOemLock
e02cd3722cb5e8fa51179f5defacb4f7866f903c9c7c51dc01a3148473a71525 android.hardware.oemlock@1.0::types
9f69e783fa2c482d90b2f799ddd33378a92d22a261983df6b492358e01f4d791 android.hardware.power@1.1::IPower
224f9d22a367a0016f09b6dc676f53f1446697d9dc747163032329e5da552de5 android.hardware.power@1.1::IPower
574fd9758b7cab4922c72cc5a9f36d1cd48ffd3425fdd776426653280d3d4138 android.hardware.power@1.1::types
f79edf50a378a9c9bb737f93f205dab91b4c63ea49723afc6f856c138203ea81 android.hardware.radio@1.1::IRadio
fcc5c8c88b85a9f63fba67d9e674da466c72a98ca287f343fb5721d098713f86 android.hardware.radio@1.1::IRadioIndication
+14 −0
Original line number Diff line number Diff line
@@ -33,4 +33,18 @@ interface IPower extends android.hardware.power@1.0::IPower {
     */
    getSubsystemLowPowerStats()
            generates (vec<PowerStateSubsystem> subsystems, Status retval);

    /**
     * powerHintAsync() is called to pass hints on power requirements which
     * may result in adjustment of power/performance parameters of the
     * cpufreq governor and other controls.
     *
     * A particular platform may choose to ignore any hint.
     *
     * @param hint PowerHint which is passed
     * @param data contains additional information about the hint
     * and is described along with the comments for each of the hints.
     */
    oneway powerHintAsync(PowerHint hint, int32_t data);

};
+5 −0
Original line number Diff line number Diff line
@@ -165,6 +165,11 @@ Return<void> Power::getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl
    return Void();
}

Return<void> Power::powerHintAsync(PowerHint hint, int32_t data) {
    // just call the normal power hint in this oneway function
    return powerHint(hint, data);
}

} // namespace implementation
}  // namespace V1_1
}  // namespace power
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ struct Power : public IPower {

    // Methods from ::android::hardware::power::V1_1::IPower follow.
    Return<void> getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb) override;
    Return<void> powerHintAsync(PowerHint hint, int32_t data) override;

    // Methods from ::android::hidl::base::V1_0::IBase follow.

+36 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
using ::android::hardware::power::V1_1::IPower;
using ::android::hardware::power::V1_1::PowerStateSubsystem;
using ::android::hardware::power::V1_0::Status;
using ::android::hardware::power::V1_0::PowerHint;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::sp;
@@ -54,6 +55,41 @@ TEST_F(PowerHidlTest, GetSubsystemLowPowerStats) {
  ASSERT_TRUE(s == Status::SUCCESS || s == Status::FILESYSTEM_ERROR);
}

// Sanity check Power::powerHintAsync on good and bad inputs.
TEST_F(PowerHidlTest, PowerHintAsync) {
    PowerHint badHint = static_cast<PowerHint>(0xA);
    auto hints = {PowerHint::VSYNC,        PowerHint::INTERACTION, PowerHint::VIDEO_ENCODE,
                  PowerHint::VIDEO_DECODE, PowerHint::LOW_POWER,   PowerHint::SUSTAINED_PERFORMANCE,
                  PowerHint::VR_MODE,      PowerHint::LAUNCH,      badHint};
    Return<void> ret;
    for (auto hint : hints) {
        ret = power->powerHintAsync(hint, 30000);
        ASSERT_TRUE(ret.isOk());

        ret = power->powerHintAsync(hint, 0);
        ASSERT_TRUE(ret.isOk());
    }

    // Turning these hints on in different orders triggers different code paths,
    // so iterate over possible orderings.
    std::vector<PowerHint> hints2 = {PowerHint::LAUNCH, PowerHint::VR_MODE,
                                     PowerHint::SUSTAINED_PERFORMANCE, PowerHint::INTERACTION};
    auto compareHints = [](PowerHint l, PowerHint r) {
        return static_cast<uint32_t>(l) < static_cast<uint32_t>(r);
    };
    std::sort(hints2.begin(), hints2.end(), compareHints);
    do {
        for (auto iter = hints2.begin(); iter != hints2.end(); iter++) {
            ret = power->powerHintAsync(*iter, 0);
            ASSERT_TRUE(ret.isOk());
        }
        for (auto iter = hints2.begin(); iter != hints2.end(); iter++) {
            ret = power->powerHintAsync(*iter, 30000);
            ASSERT_TRUE(ret.isOk());
        }
    } while (std::next_permutation(hints2.begin(), hints2.end(), compareHints));
}

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  int status = RUN_ALL_TESTS();