Status writeToParcel no OK on ERR
This is a port of the original change to libbinder.
The same idea applies here:
Right now, it's possible to have Status such that:
- mException = EX_TRANSACTION_FAILED
- mErrorCode = OK
When this happens, writeToParcel will return OK and also not write
anything to the parcel.
From the comment here:
// Something really bad has happened, and we're not going to even
// try returning rich error data.
The intention here is to use the status_t return from transact for
error messages and also not have clients read the parcel. For instance,
here is the AIDL generated code (primary user of this API):
::android::status_t _aidl_ret_status = ::android::OK;
switch (_aidl_code) {
case ...:
{
...
::android::binder::Status _aidl_status(TestVoidReturn());
_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
if (((_aidl_ret_status) != (::android::OK))) {
break;
}
if (!_aidl_status.isOk()) {
break;
}
}
...
}
return _aidl_ret_status;
As you can see, if writeToParcel returns OK for a non-okay transaction,
the transaction will be considered okay. In general, this doesn't cause
a problem since readToParcel will fail, but the error would be
confusing (out of space).
Bug: 111445392
Test: system/tools/hidl/runtests.sh
Change-Id: I8ce8d229c8a8c9c62e5196a27d04eae6c8048155
diff --git a/transport/HidlBinderSupport.cpp b/transport/HidlBinderSupport.cpp
index add1f5e..a2ca5fa 100644
--- a/transport/HidlBinderSupport.cpp
+++ b/transport/HidlBinderSupport.cpp
@@ -212,7 +212,8 @@
// Something really bad has happened, and we're not going to even
// try returning rich error data.
if (s.exceptionCode() == Status::EX_TRANSACTION_FAILED) {
- return s.transactionError();
+ status_t status = s.transactionError();
+ return status == OK ? FAILED_TRANSACTION : status;
}
status_t status = parcel->writeInt32(s.exceptionCode());