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

Commit a4a22ded authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6420265 from 85c2ee61 to rvc-release

Change-Id: Iba489e9462a07701e006c72799473d5a8ce2108e
parents 2874f1f5 85c2ee61
Loading
Loading
Loading
Loading
+42 −30
Original line number Diff line number Diff line
@@ -987,12 +987,22 @@ status_t Parcel::writeCString(const char* str)

status_t Parcel::writeString8(const String8& str)
{
    status_t err = writeInt32(str.bytes());
    // only write string if its length is more than zero characters,
    // as readString8 will only read if the length field is non-zero.
    // this is slightly different from how writeString16 works.
    if (str.bytes() > 0 && err == NO_ERROR) {
        err = write(str.string(), str.bytes()+1);
    return writeString8(str.string(), str.size());
}

status_t Parcel::writeString8(const char* str, size_t len)
{
    if (str == nullptr) return writeInt32(-1);

    status_t err = writeInt32(len);
    if (err == NO_ERROR) {
        uint8_t* data = (uint8_t*)writeInplace(len+sizeof(char));
        if (data) {
            memcpy(data, str, len);
            *reinterpret_cast<char*>(data+len) = 0;
            return NO_ERROR;
        }
        err = mError;
    }
    return err;
}
@@ -1832,37 +1842,39 @@ const char* Parcel::readCString() const

String8 Parcel::readString8() const
{
    String8 retString;
    status_t status = readString8(&retString);
    if (status != OK) {
        // We don't care about errors here, so just return an empty string.
    size_t len;
    const char* str = readString8Inplace(&len);
    if (str) return String8(str, len);
    ALOGE("Reading a NULL string not supported here.");
    return String8();
}
    return retString;
}

status_t Parcel::readString8(String8* pArg) const
{
    int32_t size;
    status_t status = readInt32(&size);
    if (status != OK) {
        return status;
    }
    // watch for potential int overflow from size+1
    if (size < 0 || size >= INT32_MAX) {
        return BAD_VALUE;
    }
    // |writeString8| writes nothing for empty string.
    if (size == 0) {
    size_t len;
    const char* str = readString8Inplace(&len);
    if (str) {
        pArg->setTo(str, len);
        return 0;
    } else {
        *pArg = String8();
        return OK;
        return UNEXPECTED_NULL;
    }
}

const char* Parcel::readString8Inplace(size_t* outLen) const
{
    int32_t size = readInt32();
    // watch for potential int overflow from size+1
    if (size >= 0 && size < INT32_MAX) {
        *outLen = size;
        const char* str = (const char*)readInplace(size+1);
    if (str == nullptr) {
        return BAD_VALUE;
        if (str != nullptr) {
            return str;
        }
    pArg->setTo(str, size);
    return OK;
    }
    *outLen = 0;
    return nullptr;
}

String16 Parcel::readString16() const
+2 −0
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ public:
    status_t            writeDouble(double val);
    status_t            writeCString(const char* str);
    status_t            writeString8(const String8& str);
    status_t            writeString8(const char* str, size_t len);
    status_t            writeString16(const String16& str);
    status_t            writeString16(const std::unique_ptr<String16>& str);
    status_t            writeString16(const char16_t* str, size_t len);
@@ -283,6 +284,7 @@ public:
    const char*         readCString() const;
    String8             readString8() const;
    status_t            readString8(String8* pArg) const;
    const char*         readString8Inplace(size_t* outLen) const;
    String16            readString16() const;
    status_t            readString16(String16* pArg) const;
    status_t            readString16(std::unique_ptr<String16>* pArg) const;
+3 −3
Original line number Diff line number Diff line
@@ -535,13 +535,13 @@ Status<void> Endpoint::ReceiveMessageForChannel(
  *message = Message{info};
  auto* state = static_cast<MessageState*>(message->GetState());
  state->request = std::move(request);
  if (request.send_len > 0 && !request.is_impulse) {
    state->request_data.resize(request.send_len);
  if (state->request.send_len > 0 && !state->request.is_impulse) {
    state->request_data.resize(state->request.send_len);
    status = ReceiveData(channel_fd, state->request_data.data(),
                         state->request_data.size());
  }

  if (status && request.is_impulse)
  if (status && state->request.is_impulse)
    status = ReenableEpollEvent(channel_fd);

  if (!status) {
+2 −1
Original line number Diff line number Diff line
@@ -1748,7 +1748,8 @@ protected:

    virtual void SetUp() override {
        mFakePolicy = new FakeInputReaderPolicy();
        mTestListener = new TestInputListener(50ms);
        mTestListener = new TestInputListener(2000ms /*eventHappenedTimeout*/,
                                              30ms /*eventDidNotHappenTimeout*/);

        mReader = new InputReader(std::make_shared<EventHub>(), mFakePolicy, mTestListener);
        ASSERT_EQ(mReader->start(), OK);
+10 −7
Original line number Diff line number Diff line
@@ -23,7 +23,10 @@ namespace android {

// --- TestInputListener ---

TestInputListener::TestInputListener(const std::chrono::milliseconds timeout) : mTimeout(timeout) {}
TestInputListener::TestInputListener(std::chrono::milliseconds eventHappenedTimeout,
                                     std::chrono::milliseconds eventDidNotHappenTimeout)
      : mEventHappenedTimeout(eventHappenedTimeout),
        mEventDidNotHappenTimeout(eventDidNotHappenTimeout) {}

TestInputListener::~TestInputListener() { }

@@ -86,9 +89,9 @@ void TestInputListener::assertCalled(NotifyArgsType* outEventArgs, std::string m

    std::vector<NotifyArgsType>& queue = std::get<std::vector<NotifyArgsType>>(mQueues);
    if (queue.empty()) {
        const bool eventReceived = mCondition.wait_for(lock, mTimeout, [&queue]() REQUIRES(mLock) {
            return !queue.empty();
        });
        const bool eventReceived =
                mCondition.wait_for(lock, mEventHappenedTimeout,
                                    [&queue]() REQUIRES(mLock) { return !queue.empty(); });
        if (!eventReceived) {
            FAIL() << "Timed out waiting for event: " << message.c_str();
        }
@@ -105,9 +108,9 @@ void TestInputListener::assertNotCalled(std::string message) {
    base::ScopedLockAssertion assumeLocked(mLock);

    std::vector<NotifyArgsType>& queue = std::get<std::vector<NotifyArgsType>>(mQueues);
    const bool eventReceived = mCondition.wait_for(lock, mTimeout, [&queue]() REQUIRES(mLock) {
        return !queue.empty();
    });
    const bool eventReceived =
            mCondition.wait_for(lock, mEventDidNotHappenTimeout,
                                [&queue]() REQUIRES(mLock) { return !queue.empty(); });
    if (eventReceived) {
        FAIL() << "Unexpected event: " << message.c_str();
    }
Loading