Merge "Add checked exceptions to HwBinder transact." am: 6c5cc261f8 am: ca5d560090
am: d38478cb50
Change-Id: Ic0c6eb87c57aca798ff167a71929f1a0e3132a75
This commit is contained in:
@@ -33,11 +33,14 @@ public abstract class HwBinder implements IHwBinder {
|
|||||||
mNativeContext);
|
mNativeContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final native void transact(
|
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(
|
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(
|
public native final void registerService(
|
||||||
ArrayList<String> interfaceChain,
|
ArrayList<String> interfaceChain,
|
||||||
|
|||||||
@@ -32,12 +32,15 @@ public class HwRemoteBinder implements IHwBinder {
|
|||||||
mNativeContext);
|
mNativeContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IHwInterface queryLocalInterface(String descriptor) {
|
public IHwInterface queryLocalInterface(String descriptor) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public native final void transact(
|
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 linkToDeath(DeathRecipient recipient, long cookie);
|
||||||
public native boolean unlinkToDeath(DeathRecipient recipient);
|
public native boolean unlinkToDeath(DeathRecipient recipient);
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ public interface IHwBinder {
|
|||||||
public static final int FLAG_ONEWAY = 1;
|
public static final int FLAG_ONEWAY = 1;
|
||||||
|
|
||||||
public void transact(
|
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);
|
public IHwInterface queryLocalInterface(String descriptor);
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ static struct {
|
|||||||
jmethodID get;
|
jmethodID get;
|
||||||
} gArrayListMethods;
|
} gArrayListMethods;
|
||||||
|
|
||||||
|
static jclass gErrorClass;
|
||||||
|
|
||||||
static struct fields_t {
|
static struct fields_t {
|
||||||
jfieldID contextID;
|
jfieldID contextID;
|
||||||
jmethodID onTransactID;
|
jmethodID onTransactID;
|
||||||
@@ -144,6 +146,22 @@ status_t JHwBinder::onTransact(
|
|||||||
replyObj.get(),
|
replyObj.get(),
|
||||||
flags);
|
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;
|
status_t err = OK;
|
||||||
|
|
||||||
if (!replyContext->wasSent()) {
|
if (!replyContext->wasSent()) {
|
||||||
@@ -356,6 +374,9 @@ int register_android_os_HwBinder(JNIEnv *env) {
|
|||||||
gArrayListMethods.size = GetMethodIDOrDie(env, arrayListClass, "size", "()I");
|
gArrayListMethods.size = GetMethodIDOrDie(env, arrayListClass, "size", "()I");
|
||||||
gArrayListMethods.get = GetMethodIDOrDie(env, arrayListClass, "get", "(I)Ljava/lang/Object;");
|
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));
|
return RegisterMethodsOrDie(env, CLASS_PATH, gMethods, NELEM(gMethods));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ static struct fields_t {
|
|||||||
|
|
||||||
} gFields;
|
} gFields;
|
||||||
|
|
||||||
void signalExceptionForError(JNIEnv *env, status_t err) {
|
void signalExceptionForError(JNIEnv *env, status_t err, bool canThrowRemoteException) {
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case OK:
|
case OK:
|
||||||
break;
|
break;
|
||||||
@@ -114,8 +114,13 @@ void signalExceptionForError(JNIEnv *env, status_t err) {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "HwBinder Error: (" << err << ")";
|
||||||
|
|
||||||
jniThrowException(
|
jniThrowException(
|
||||||
env, "java/lang/RuntimeException", "Unknown error");
|
env,
|
||||||
|
canThrowRemoteException ? "android/os/RemoteException" : "java/lang/RuntimeException",
|
||||||
|
ss.str().c_str());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ private:
|
|||||||
DISALLOW_COPY_AND_ASSIGN(JHwParcel);
|
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);
|
int register_android_os_HwParcel(JNIEnv *env);
|
||||||
|
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ static void JHwRemoteBinder_native_transact(
|
|||||||
JHwParcel::GetNativeContext(env, replyObj)->getParcel();
|
JHwParcel::GetNativeContext(env, replyObj)->getParcel();
|
||||||
|
|
||||||
status_t err = binder->transact(code, *request, reply, flags);
|
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,
|
static jboolean JHwRemoteBinder_linkToDeath(JNIEnv* env, jobject thiz,
|
||||||
|
|||||||
Reference in New Issue
Block a user