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

Commit 6c5cc261 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add checked exceptions to HwBinder transact."

parents 63270f2b e62b1f32
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -33,11 +33,14 @@ public abstract class HwBinder implements IHwBinder {
                mNativeContext);
    }

    @Override
    public final native void transact(
            int code, HwParcel request, HwParcel reply, int flags);
            int code, HwParcel request, HwParcel reply, int flags)
        throws RemoteException;

    public abstract void onTransact(
            int code, HwParcel request, HwParcel reply, int flags);
            int code, HwParcel request, HwParcel reply, int flags)
        throws RemoteException;

    public native final void registerService(
            ArrayList<String> interfaceChain,
+4 −1
Original line number Diff line number Diff line
@@ -32,12 +32,15 @@ public class HwRemoteBinder implements IHwBinder {
                mNativeContext);
    }

    @Override
    public IHwInterface queryLocalInterface(String descriptor) {
        return null;
    }

    @Override
    public native final void transact(
            int code, HwParcel request, HwParcel reply, int flags);
            int code, HwParcel request, HwParcel reply, int flags)
        throws RemoteException;

    public native boolean linkToDeath(DeathRecipient recipient, long cookie);
    public native boolean unlinkToDeath(DeathRecipient recipient);
+2 −1
Original line number Diff line number Diff line
@@ -23,7 +23,8 @@ public interface IHwBinder {
    public static final int FLAG_ONEWAY = 1;

    public void transact(
            int code, HwParcel request, HwParcel reply, int flags);
            int code, HwParcel request, HwParcel reply, int flags)
        throws RemoteException;

    public IHwInterface queryLocalInterface(String descriptor);

+21 −0
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ static struct {
    jmethodID get;
} gArrayListMethods;

static jclass gErrorClass;

static struct fields_t {
    jfieldID contextID;
    jmethodID onTransactID;
@@ -144,6 +146,22 @@ status_t JHwBinder::onTransact(
            replyObj.get(),
            flags);

    if (env->ExceptionCheck()) {
        jthrowable excep = env->ExceptionOccurred();
        env->ExceptionDescribe();

        if (env->IsInstanceOf(excep, gErrorClass)) {
            /* It's an error */
            LOG(ERROR) << "Forcefully exiting";
            exit(1);
        } else {
            env->ExceptionClear();
            LOG(ERROR) << "Uncaught exception!";
        }

        env->DeleteLocalRef(excep);
    }

    status_t err = OK;

    if (!replyContext->wasSent()) {
@@ -356,6 +374,9 @@ int register_android_os_HwBinder(JNIEnv *env) {
    gArrayListMethods.size = GetMethodIDOrDie(env, arrayListClass, "size", "()I");
    gArrayListMethods.get = GetMethodIDOrDie(env, arrayListClass, "get", "(I)Ljava/lang/Object;");

    jclass errorClass = FindClassOrDie(env, "java/lang/Error");
    gErrorClass = MakeGlobalRefOrDie(env, errorClass);

    return RegisterMethodsOrDie(env, CLASS_PATH, gMethods, NELEM(gMethods));
}

+7 −2
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ static struct fields_t {

} gFields;

void signalExceptionForError(JNIEnv *env, status_t err) {
void signalExceptionForError(JNIEnv *env, status_t err, bool canThrowRemoteException) {
    switch (err) {
        case OK:
            break;
@@ -114,8 +114,13 @@ void signalExceptionForError(JNIEnv *env, status_t err) {

        default:
        {
            std::stringstream ss;
            ss << "HwBinder Error: (" << err << ")";

            jniThrowException(
                    env, "java/lang/RuntimeException", "Unknown error");
                    env,
                    canThrowRemoteException ? "android/os/RemoteException" : "java/lang/RuntimeException",
                    ss.str().c_str());

            break;
        }
Loading