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

Commit 0884cd11 authored by Christopher Tate's avatar Christopher Tate Committed by Android Git Automerger
Browse files

am 9a600725: Merge "Don\'t throw TransactionTooLargeException for small payloads" into mnc-dev

* commit '9a600725':
  Don't throw TransactionTooLargeException for small payloads
parents 77f9e5dc 9a600725
Loading
Loading
Loading
Loading
+15 −5
Original line number Original line Diff line number Diff line
@@ -682,18 +682,28 @@ void signalExceptionForError(JNIEnv* env, jobject obj, status_t err,
            break;
            break;
        case FAILED_TRANSACTION: {
        case FAILED_TRANSACTION: {
            ALOGE("!!! FAILED BINDER TRANSACTION !!!  (parcel size = %d)", parcelSize);
            ALOGE("!!! FAILED BINDER TRANSACTION !!!  (parcel size = %d)", parcelSize);
            const char* exceptionToThrow;
            char msg[128];
            char msg[128];
            snprintf(msg, sizeof(msg)-1, "data parcel size %d bytes", parcelSize);
            // TransactionTooLargeException is a checked exception, only throw from certain methods.
            // TransactionTooLargeException is a checked exception, only throw from certain methods.
            // FIXME: Transaction too large is the most common reason for FAILED_TRANSACTION
            // FIXME: Transaction too large is the most common reason for FAILED_TRANSACTION
            //        but it is not the only one.  The Binder driver can return BR_FAILED_REPLY
            //        but it is not the only one.  The Binder driver can return BR_FAILED_REPLY
            //        for other reasons also, such as if the transaction is malformed or
            //        for other reasons also, such as if the transaction is malformed or
            //        refers to an FD that has been closed.  We should change the driver
            //        refers to an FD that has been closed.  We should change the driver
            //        to enable us to distinguish these cases in the future.
            //        to enable us to distinguish these cases in the future.
            jniThrowException(env, canThrowRemoteException
            if (canThrowRemoteException && parcelSize > 200*1024) {
                    ? "android/os/TransactionTooLargeException"
                // bona fide large payload
                            : "java/lang/RuntimeException",
                exceptionToThrow = "android/os/TransactionTooLargeException";
                    parcelSize > 0 ? msg : NULL);
                snprintf(msg, sizeof(msg)-1, "data parcel size %d bytes", parcelSize);
            } else {
                // Heuristic: a payload smaller than this threshold "shouldn't" be too
                // big, so it's probably some other, more subtle problem.  In practice
                // it nearly always means that the remote process died while the binder
                // transaction was already in flight.
                exceptionToThrow = "java/lang/RuntimeException";
                snprintf(msg, sizeof(msg)-1,
                        "Transaction failed on small parcel; remote process probably died");
            }
            jniThrowException(env, exceptionToThrow, msg);
        } break;
        } break;
        case FDS_NOT_ALLOWED:
        case FDS_NOT_ALLOWED:
            jniThrowException(env, "java/lang/RuntimeException",
            jniThrowException(env, "java/lang/RuntimeException",