Support checking FUSE thread execution
There are several cases where we want to behave differently depending
on if we are handling a FUSE request or Binder request. This cl adds a
method to support this check.
It relies on a TLS variable that would only be set if running on a
FUSE thread.
Test: m
Bug: 149512775
Merged-In: I8f77470443e92812598f0e90ca42b43ef25b9d10
Change-Id: I8f77470443e92812598f0e90ca42b43ef25b9d10
(cherry picked from commit 0602a41451b40264c08f48e772b16ac9d831d83c)
diff --git a/jni/com_android_providers_media_FuseDaemon.cpp b/jni/com_android_providers_media_FuseDaemon.cpp
index 9de00b6..bede40a 100644
--- a/jni/com_android_providers_media_FuseDaemon.cpp
+++ b/jni/com_android_providers_media_FuseDaemon.cpp
@@ -90,6 +90,11 @@
// TODO(b/145741152): Throw exception
}
+bool com_android_providers_media_FuseDaemon_is_fuse_thread(JNIEnv* env, jclass clazz) {
+ LOG(VERBOSE) << "Checking if FUSE thread...";
+ return pthread_getspecific(fuse::MediaProviderWrapper::gJniEnvKey) != nullptr;
+}
+
const JNINativeMethod methods[] = {
{"native_new", "(Lcom/android/providers/media/MediaProvider;)J",
reinterpret_cast<void*>(com_android_providers_media_FuseDaemon_new)},
@@ -99,6 +104,8 @@
reinterpret_cast<void*>(com_android_providers_media_FuseDaemon_delete)},
{"native_should_open_with_fuse", "(JLjava/lang/String;ZI)Z",
reinterpret_cast<void*>(com_android_providers_media_FuseDaemon_should_open_with_fuse)},
+ {"native_is_fuse_thread", "()Z",
+ reinterpret_cast<void*>(com_android_providers_media_FuseDaemon_is_fuse_thread)},
{"native_invalidate_fuse_dentry_cache", "(JLjava/lang/String;)V",
reinterpret_cast<void*>(
com_android_providers_media_FuseDaemon_invalidate_fuse_dentry_cache)}};