[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; return mLocalRef != nullptr;
} }
operator bool() const {
return mLocalRef;
}
private: private:
JNIEnv *mEnv; JNIEnv *mEnv;
T mLocalRef; T mLocalRef;
DISALLOW_COPY_AND_ASSIGN(ScopedLocalRef); DISALLOW_COPY_AND_ASSIGN(ScopedLocalRef);
}; };
[[maybe_unused]] inline ScopedLocalRef<jstring> ClearException(JNIEnv *env) {
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;");
if (auto exception = env->ExceptionOccurred()) { if (auto exception = env->ExceptionOccurred()) {
env->ExceptionClear(); 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> template<typename T>
@ -191,7 +171,7 @@ inline auto JNI_SafeInvoke(JNIEnv *env, Func f, Args &&... args) {
~finally() { ~finally() {
if (auto exception = ClearException(env_)) { 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(); String processName = data.readString();
IBinder heartBeat = data.readStrongBinder(); IBinder heartBeat = data.readStrongBinder();
var applicationService = service.requestApplicationService(Binder.getCallingUid(), Binder.getCallingPid(), processName, heartBeat); 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) { } catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(e)); Log.e(TAG, Log.getStackTraceString(e));
} }