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

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

Snap for 8581162 from e8207cf8 to tm-release

Change-Id: I2edfcd56b4f18b3d16a42d7ad0f32c52ba98a471
parents 63eab596 e8207cf8
Loading
Loading
Loading
Loading
+34 −89
Original line number Diff line number Diff line
@@ -195,35 +195,6 @@ using ErrorHandler = void(*)(T*);
status_t encodeMetadataType(const MetadataType& input, OutputHidlVec* output);
status_t validateMetadataType(InputHidlVec* input, const MetadataType& expectedMetadataType);

/**
 * Private helper functions
 */
template <class T>
status_t encodeInteger(const T& input, OutputHidlVec* output) {
    static_assert(std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value ||
                  std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value ||
                  std::is_same<T, float>::value || std::is_same<T, double>::value);
    if (!output) {
        return BAD_VALUE;
    }

    const uint8_t* tmp = reinterpret_cast<const uint8_t*>(&input);
    return output->encode(tmp, sizeof(input));
}

template <class T>
status_t decodeInteger(InputHidlVec* input, T* output) {
    static_assert(std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value ||
                  std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value ||
                  std::is_same<T, float>::value || std::is_same<T, double>::value);
    if (!output) {
        return BAD_VALUE;
    }

    uint8_t* tmp = reinterpret_cast<uint8_t*>(output);
    return input->decode(tmp, sizeof(*output));
}

/**
 * encode/encodeMetadata are the main encoding functions. They take in T and uses the encodeHelper
 * function to turn T into the hidl_vec byte stream.
@@ -280,46 +251,11 @@ status_t encodeMetadata(const MetadataType& metadataType, const T& input, hidl_v
template <class T>
status_t encodeOptionalMetadata(const MetadataType& metadataType, const std::optional<T>& input,
                        hidl_vec<uint8_t>* output, EncodeHelper<T> encodeHelper) {
    OutputHidlVec outputHidlVec{output};

    status_t err = encodeMetadataType(metadataType, &outputHidlVec);
    if (err) {
        return err;
    }

    err = encodeInteger<uint32_t>(input.has_value() ? 1 : 0, &outputHidlVec);
    if (err) {
        return err;
    }

    if (input) {
        err = encodeHelper(*input, &outputHidlVec);
        if (err) {
            return err;
        }
    }

    err = outputHidlVec.resize();
    if (err) {
        return err;
    }

    err = encodeMetadataType(metadataType, &outputHidlVec);
    if (err) {
        return err;
    }

    err = encodeInteger<uint32_t>(input.has_value() ? 1 : 0, &outputHidlVec);
    if (err) {
        return err;
    }

    if (input) {
        return encodeHelper(*input, &outputHidlVec);
    }

    if (!input) {
        return NO_ERROR;
    }
    return encodeMetadata(metadataType, *input, output, encodeHelper);
}

/**
 * decode/decodeMetadata are the main decoding functions. They take in a hidl_vec and use the
@@ -379,36 +315,45 @@ status_t decodeOptionalMetadata(const MetadataType& metadataType, const hidl_vec
    if (!output) {
        return BAD_VALUE;
    }

    InputHidlVec inputHidlVec{&input};

    status_t err = validateMetadataType(&inputHidlVec, metadataType);
    if (err) {
        return err;
    if (input.size() <= 0) {
        output->reset();
        return NO_ERROR;
    }
    T tmp;
    status_t err = decodeMetadata(metadataType, input, &tmp, decodeHelper);
    if (!err) {
        *output = tmp;
    }

    uint32_t present = 0;
    err = decodeInteger<uint32_t>(&inputHidlVec, &present);
    if (err) {
    return err;
}

    if (present) {
        T tmp;
        err = decodeHelper(&inputHidlVec, &tmp);
        if (err) {
            return err;
/**
 * Private helper functions
 */
template <class T>
status_t encodeInteger(const T& input, OutputHidlVec* output) {
    static_assert(std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value ||
                  std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value ||
                  std::is_same<T, float>::value || std::is_same<T, double>::value);
    if (!output) {
        return BAD_VALUE;
    }

        *output = tmp;
    const uint8_t* tmp = reinterpret_cast<const uint8_t*>(&input);
    return output->encode(tmp, sizeof(input));
}

    err = inputHidlVec.hasRemainingData();
    if (err) {
template <class T>
status_t decodeInteger(InputHidlVec* input, T* output) {
    static_assert(std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value ||
                  std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value ||
                  std::is_same<T, float>::value || std::is_same<T, double>::value);
    if (!output) {
        return BAD_VALUE;
    }

    return NO_ERROR;
    uint8_t* tmp = reinterpret_cast<uint8_t*>(output);
    return input->decode(tmp, sizeof(*output));
}

status_t encodeString(const std::string& input, OutputHidlVec* output) {
+35 −16
Original line number Diff line number Diff line
@@ -80,22 +80,33 @@ void traceExpensiveRendering(bool enabled) {

} // namespace

PowerAdvisor::PowerAdvisor(SurfaceFlinger& flinger)
      : mFlinger(flinger),
        mUseScreenUpdateTimer(getUpdateTimeout() > 0),
        mScreenUpdateTimer(
                "UpdateImminentTimer", OneShotTimer::Interval(getUpdateTimeout()),
                /* resetCallback */ [this] { mSendUpdateImminent.store(false); },
PowerAdvisor::PowerAdvisor(SurfaceFlinger& flinger) : mFlinger(flinger) {
    if (getUpdateTimeout()) {
        mScreenUpdateTimer.emplace("UpdateImminentTimer",
                                   OneShotTimer::Interval(getUpdateTimeout()),
                                   /* resetCallback */ nullptr,
                                   /* timeoutCallback */
                                   [this] {
                                       const nsecs_t timeSinceLastUpdate =
                                               systemTime() - mLastScreenUpdatedTime.load();
                                       if (timeSinceLastUpdate < getUpdateTimeout()) {
                                           // We may try to disable expensive rendering and allow
                                           // for sending DISPLAY_UPDATE_IMMINENT hints too early if
                                           // we idled very shortly after updating the screen, so
                                           // make sure we wait enough time.
                                           std::this_thread::sleep_for(std::chrono::nanoseconds(
                                                   getUpdateTimeout() - timeSinceLastUpdate));
                                       }
                                       mSendUpdateImminent.store(true);
                                       mFlinger.disableExpensiveRendering();
                }) {}
                                   });
    }
}

void PowerAdvisor::init() {
    // Defer starting the screen update timer until SurfaceFlinger finishes construction.
    if (mUseScreenUpdateTimer) {
        mScreenUpdateTimer.start();
    if (mScreenUpdateTimer) {
        mScreenUpdateTimer->start();
    }
}

@@ -135,7 +146,7 @@ void PowerAdvisor::notifyDisplayUpdateImminent() {
        return;
    }

    if (mSendUpdateImminent.load()) {
    if (mSendUpdateImminent.exchange(false)) {
        std::lock_guard lock(mPowerHalMutex);
        HalWrapper* const halWrapper = getPowerHal();
        if (halWrapper == nullptr) {
@@ -147,10 +158,18 @@ void PowerAdvisor::notifyDisplayUpdateImminent() {
            mReconnectPowerHal = true;
            return;
        }

        if (mScreenUpdateTimer) {
            mScreenUpdateTimer->reset();
        } else {
            // If we don't have a screen update timer, then we don't throttle power hal calls so
            // flip this bit back to allow for calling into power hal again.
            mSendUpdateImminent.store(true);
        }
    }

    if (mUseScreenUpdateTimer) {
        mScreenUpdateTimer.reset();
    if (mScreenUpdateTimer) {
        mLastScreenUpdatedTime.store(systemTime());
    }
}

+2 −2
Original line number Diff line number Diff line
@@ -114,9 +114,9 @@ private:
    bool mNotifiedExpensiveRendering = false;

    SurfaceFlinger& mFlinger;
    const bool mUseScreenUpdateTimer;
    std::atomic_bool mSendUpdateImminent = true;
    scheduler::OneShotTimer mScreenUpdateTimer;
    std::atomic<nsecs_t> mLastScreenUpdatedTime = 0;
    std::optional<scheduler::OneShotTimer> mScreenUpdateTimer;
};

class AidlPowerHalWrapper : public PowerAdvisor::HalWrapper {