Loading libs/binder/BinderStatsPusher.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -74,9 +74,11 @@ void BinderStatsPusher::aggregateStatsLocked(const std::vector<BinderCallData>& // to the VM then skip pushing. This is required since StatsBootstrap is // a Java service and needs a JNI interface to be called from native code. bool isProcessSystemServer = IInterface::asBinder(service)->localBinder() != nullptr; if (isProcessSystemServer && getJavaVM() == nullptr) { if (isProcessSystemServer) { if (!isThreadAttachedToJVM()) { return; } } // Clear calling identity if this is called from system server. This // will allow libStatsBootstrap to verify calling uid correctly. int64_t callingIdentity; Loading libs/binder/JvmUtils.h +12 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,9 @@ namespace { static void* getJavaVM() { return nullptr; } bool isThreadAttachedToJVM() { return false; } #else static JavaVM* getJavaVM() { static auto fn = reinterpret_cast<decltype(&AndroidRuntimeGetJavaVM)>( Loading @@ -30,5 +33,14 @@ static JavaVM* getJavaVM() { if (fn == nullptr) return nullptr; return fn(); } bool isThreadAttachedToJVM() { JNIEnv* env = nullptr; JavaVM* vm = getJavaVM(); if (vm == nullptr || vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_4) < 0) { return false; } return env != nullptr; } #endif } // namespace Loading
libs/binder/BinderStatsPusher.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -74,9 +74,11 @@ void BinderStatsPusher::aggregateStatsLocked(const std::vector<BinderCallData>& // to the VM then skip pushing. This is required since StatsBootstrap is // a Java service and needs a JNI interface to be called from native code. bool isProcessSystemServer = IInterface::asBinder(service)->localBinder() != nullptr; if (isProcessSystemServer && getJavaVM() == nullptr) { if (isProcessSystemServer) { if (!isThreadAttachedToJVM()) { return; } } // Clear calling identity if this is called from system server. This // will allow libStatsBootstrap to verify calling uid correctly. int64_t callingIdentity; Loading
libs/binder/JvmUtils.h +12 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,9 @@ namespace { static void* getJavaVM() { return nullptr; } bool isThreadAttachedToJVM() { return false; } #else static JavaVM* getJavaVM() { static auto fn = reinterpret_cast<decltype(&AndroidRuntimeGetJavaVM)>( Loading @@ -30,5 +33,14 @@ static JavaVM* getJavaVM() { if (fn == nullptr) return nullptr; return fn(); } bool isThreadAttachedToJVM() { JNIEnv* env = nullptr; JavaVM* vm = getJavaVM(); if (vm == nullptr || vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_4) < 0) { return false; } return env != nullptr; } #endif } // namespace