Merge "Add checked exceptions to HwBinder transact."

am: 6c5cc261f8

Change-Id: I3bcac03a745722acd983dc4e7bdc31ae806bdbd4
This commit is contained in:
Steven Moreland
2017-01-04 05:03:28 +00:00
committed by android-build-merger
7 changed files with 41 additions and 8 deletions

View File

@@ -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,

View File

@@ -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);

View File

@@ -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);

View File

@@ -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));
}

View File

@@ -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;
}

View File

@@ -67,7 +67,7 @@ private:
DISALLOW_COPY_AND_ASSIGN(JHwParcel);
};
void signalExceptionForError(JNIEnv *env, status_t err);
void signalExceptionForError(JNIEnv *env, status_t err, bool canThrowRemoteException = false);
int register_android_os_HwParcel(JNIEnv *env);
} // namespace android

View File

@@ -347,7 +347,7 @@ static void JHwRemoteBinder_native_transact(
JHwParcel::GetNativeContext(env, replyObj)->getParcel();
status_t err = binder->transact(code, *request, reply, flags);
signalExceptionForError(env, err);
signalExceptionForError(env, err, true /* canThrowRemoteException */);
}
static jboolean JHwRemoteBinder_linkToDeath(JNIEnv* env, jobject thiz,