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

Commit fb574cb0 authored by Greg Kaiser's avatar Greg Kaiser Committed by android-build-merger
Browse files

ContextHubService: Maintain hub result meaning am: 6d9e7f66 am: 9ea48989

am: e84227f2

Change-Id: I84f8715bb57ec68c749c31abc0705c8f140a512e
parents 7976a9d4 e84227f2
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
@@ -595,7 +595,32 @@ static void passOnOsResponse(uint32_t hubHandle, uint32_t msgType,
    header[HEADER_FIELD_HUB_HANDLE] = hubHandle;
    header[HEADER_FIELD_APP_INSTANCE] = OS_APP_ID;

    msg[0] = rsp->result;
    // Due to API constraints, at the moment we can't change the fact that
    // we're changing our 4-byte response to a 1-byte value.  But we can prevent
    // the possible change in sign (and thus meaning) that would happen from
    // a naive cast.  Further, we can log when we're losing part of the value.
    // TODO(b/30918279): Don't truncate this result.
    int8_t truncatedResult;
    bool neededToTruncate;
    if (rsp->result < INT8_MIN) {
        neededToTruncate = true;
        truncatedResult = INT8_MIN;
    } else if (rsp->result > INT8_MAX) {
        neededToTruncate = true;
        truncatedResult = INT8_MAX;
    } else {
        neededToTruncate = false;
        // Since this value fits within an int8_t, this is a safe cast which
        // won't change the value or sign.
        truncatedResult = static_cast<int8_t>(rsp->result);
    }
    if (neededToTruncate) {
        ALOGW("Response from Context Hub truncated.  Value was %" PRId32
              ", but giving Java layer %" PRId8,
              rsp->result, (int)truncatedResult);
    }

    msg[0] = truncatedResult;

    if (additionalData) {
        memcpy(&msg[1], additionalData, additionalDataLen);