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

Commit 5596e949 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 11348195 from 424c520d to 24Q2-release

Change-Id: Id3377d5912ece79fc26e0c0be74f42672a3940ba
parents d1ed39db 424c520d
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -240,7 +240,7 @@ int APerformanceHint_setPreferPowerEfficiency(
 *     the actual GPU duration is not measured.
 *
 * @return 0 on success.
 *         EINVAL if session is nullptr or any duration is an invalid number.
 *         EINVAL if any duration is an invalid number.
 *         EPIPE if communication with the system service has failed.
 */
int APerformanceHint_reportActualWorkDuration2(
@@ -269,7 +269,7 @@ void AWorkDuration_release(AWorkDuration* _Nonnull aWorkDuration)
 *
 * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
 * @param workPeriodStartTimestampNanos The work period start timestamp in nanoseconds based on
 *        CLOCK_MONOTONIC about when the work starts, the timestamp must be positive.
 *        CLOCK_MONOTONIC about when the work starts. This timestamp must be greater than zero.
 */
void AWorkDuration_setWorkPeriodStartTimestampNanos(AWorkDuration* _Nonnull aWorkDuration,
        int64_t workPeriodStartTimestampNanos) __INTRODUCED_IN(__ANDROID_API_V__);
@@ -278,8 +278,8 @@ void AWorkDuration_setWorkPeriodStartTimestampNanos(AWorkDuration* _Nonnull aWor
 * Sets the actual total work duration in nanoseconds.
 *
 * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
 * @param actualTotalDurationNanos The actual total work duration in nanoseconds, the number must be
 *        positive.
 * @param actualTotalDurationNanos The actual total work duration in nanoseconds. This number must
 *        be greater than zero.
 */
void AWorkDuration_setActualTotalDurationNanos(AWorkDuration* _Nonnull aWorkDuration,
        int64_t actualTotalDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__);
@@ -288,8 +288,8 @@ void AWorkDuration_setActualTotalDurationNanos(AWorkDuration* _Nonnull aWorkDura
 * Sets the actual CPU work duration in nanoseconds.
 *
 * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
 * @param actualCpuDurationNanos The actual CPU work duration in nanoseconds, the number must be
 *        positive.
 * @param actualCpuDurationNanos The actual CPU work duration in nanoseconds. This number must be
 *        greater than zero.
 */
void AWorkDuration_setActualCpuDurationNanos(AWorkDuration* _Nonnull aWorkDuration,
        int64_t actualCpuDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__);
+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
+36 −0
Original line number Diff line number Diff line
@@ -1324,6 +1324,42 @@ TEST_F(CursorInputMapperUnitTestWithNewBallistics, PointerCaptureDisablesVelocit
    ASSERT_EQ(20, relY2);
}

TEST_F(CursorInputMapperUnitTestWithNewBallistics, ConfigureAccelerationWithAssociatedViewport) {
    mPropertyMap.addProperty("cursor.mode", "pointer");
    DisplayViewport primaryViewport = createPrimaryViewport(ui::Rotation::Rotation0);
    mReaderConfiguration.setDisplayViewports({primaryViewport});
    createDevice();
    ViewportFakingInputDeviceContext deviceContext(*mDevice, EVENTHUB_ID, primaryViewport);
    mMapper = createInputMapper<CursorInputMapper>(deviceContext, mReaderConfiguration);

    std::list<NotifyArgs> args;

    // Verify that acceleration is being applied by default by checking that the movement is scaled.
    args += process(ARBITRARY_TIME, EV_REL, REL_X, 10);
    args += process(ARBITRARY_TIME, EV_REL, REL_Y, 20);
    args += process(ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
    ASSERT_THAT(args,
                ElementsAre(VariantWith<NotifyMotionArgs>(
                        AllOf(WithMotionAction(HOVER_MOVE), WithDisplayId(DISPLAY_ID)))));
    const auto& coords = get<NotifyMotionArgs>(args.back()).pointerCoords[0];
    ASSERT_GT(coords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X), 10.f);
    ASSERT_GT(coords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y), 20.f);

    // Disable acceleration for the display, and verify that acceleration is no longer applied.
    mReaderConfiguration.displaysWithMousePointerAccelerationDisabled.emplace(DISPLAY_ID);
    args += mMapper->reconfigure(ARBITRARY_TIME, mReaderConfiguration,
                                 InputReaderConfiguration::Change::POINTER_SPEED);
    args.clear();

    args += process(ARBITRARY_TIME, EV_REL, REL_X, 10);
    args += process(ARBITRARY_TIME, EV_REL, REL_Y, 20);
    args += process(ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
    ASSERT_THAT(args,
                ElementsAre(VariantWith<NotifyMotionArgs>(
                        AllOf(WithMotionAction(HOVER_MOVE), WithDisplayId(DISPLAY_ID),
                              WithRelativeMotion(10, 20)))));
}

namespace {

// Minimum timestamp separation between subsequent input events from a Bluetooth device.
+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
Loading