[core] Remove useless codes (#441)

This commit is contained in:
LoveSy 2021-04-01 18:52:44 +08:00 committed by GitHub
parent a384697655
commit caa1bef21f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 33 deletions

View File

@ -133,46 +133,26 @@ public:
return mLocalRef != nullptr;
}
operator bool() const {
return mLocalRef;
}
private:
JNIEnv *mEnv;
T mLocalRef;
DISALLOW_COPY_AND_ASSIGN(ScopedLocalRef);
};
[[maybe_unused]]
inline void JNIExceptionClear(JNIEnv *env) {
if (env->ExceptionCheck()) {
env->ExceptionClear();
}
}
[[maybe_unused]]
inline bool JNIExceptionCheck(JNIEnv *env) {
if (env->ExceptionCheck()) {
jthrowable e = env->ExceptionOccurred();
env->Throw(e);
env->DeleteLocalRef(e);
return true;
}
return false;
}
[[maybe_unused]]
inline void JNIExceptionClearAndDescribe(JNIEnv *env) {
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
}
}
inline jstring ClearException(JNIEnv *env) {
static jmethodID toString = env->GetMethodID(env->FindClass("java/lang/Object"), "toString",
"()Ljava/lang/String;");
inline ScopedLocalRef<jstring> ClearException(JNIEnv *env) {
if (auto exception = env->ExceptionOccurred()) {
env->ExceptionClear();
return (jstring) env->CallObjectMethod(exception, toString);
static jmethodID toString = env->GetMethodID(env->FindClass("java/lang/Object"), "toString",
"()Ljava/lang/String;");
auto str = (jstring) env->CallObjectMethod(exception, toString);
env->DeleteLocalRef(exception);
return {env, str};
}
return nullptr;
return {env, nullptr};
}
template<typename T>
@ -191,7 +171,7 @@ inline auto JNI_SafeInvoke(JNIEnv *env, Func f, Args &&... args) {
~finally() {
if (auto exception = ClearException(env_)) {
LOGE("%s", JUTFString(env_, exception).get());
LOGE("%s", JUTFString(env_, exception.get()).get());
}
}

View File

@ -266,7 +266,7 @@ public class BridgeService {
String processName = data.readString();
IBinder heartBeat = data.readStrongBinder();
var applicationService = service.requestApplicationService(Binder.getCallingUid(), Binder.getCallingPid(), processName, heartBeat);
if (applicationService != null) binder = service.asBinder();
if (applicationService != null) binder = applicationService.asBinder();
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(e));
}