123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include <android_runtime/AndroidRuntime.h>
- #include <log/log.h>
- #include <string>
- extern "C" const char* rsQueryCacheDir() {
- static std::string cacheDir;
-
- if (android::AndroidRuntime::getJavaVM()) {
- JNIEnv* env = android::AndroidRuntime::getJNIEnv();
- if (env) {
- jclass cacheDirClass = env->FindClass("android/renderscript/RenderScriptCacheDir");
- jfieldID cacheDirID = env->GetStaticFieldID(cacheDirClass, "mCacheDir", "Ljava/io/File;");
- jobject cache_dir = env->GetStaticObjectField(cacheDirClass, cacheDirID);
- if (cache_dir) {
- jclass fileClass = env->FindClass("java/io/File");
- jmethodID getPath = env->GetMethodID(fileClass, "getPath", "()Ljava/lang/String;");
- jstring path_string = (jstring)env->CallObjectMethod(cache_dir, getPath);
- const char *path_chars = env->GetStringUTFChars(path_string, NULL);
- ALOGD("Successfully queried cache dir: %s", path_chars);
- cacheDir = std::string(path_chars);
- env->ReleaseStringUTFChars(path_string, path_chars);
- } else {
- ALOGD("Cache dir not initialized");
- }
- } else {
- ALOGD("Failed to query the default cache dir.");
- }
- }
- return cacheDir.c_str();
- }
|