| 64 | } |
| 65 | |
| 66 | Result GetApplicationSupportPath(const char* application_name, char* path, uint32_t path_len) |
| 67 | { |
| 68 | struct android_app* app = dmAndroid::GetAndroidApp(); |
| 69 | if (!app) |
| 70 | { |
| 71 | // For unit tests |
| 72 | dmSnPrintf(path, path_len, "/data/local/tmp"); |
| 73 | return RESULT_OK; |
| 74 | } |
| 75 | |
| 76 | dmAndroid::ThreadAttacher thread; |
| 77 | JNIEnv* env = thread.GetEnv(); |
| 78 | if (!env) |
| 79 | { |
| 80 | return RESULT_UNKNOWN; |
| 81 | } |
| 82 | |
| 83 | jclass activity_class = env->FindClass("android/app/NativeActivity"); |
| 84 | jmethodID get_files_dir_method = env->GetMethodID(activity_class, "getFilesDir", "()Ljava/io/File;"); |
| 85 | jobject files_dir_obj = env->CallObjectMethod(thread.GetActivity()->clazz, get_files_dir_method); |
| 86 | jclass file_class = env->FindClass("java/io/File"); |
| 87 | jmethodID getPathMethod = env->GetMethodID(file_class, "getPath", "()Ljava/lang/String;"); |
| 88 | jstring path_obj = (jstring)env->CallObjectMethod(files_dir_obj, getPathMethod); |
| 89 | |
| 90 | Result res = RESULT_OK; |
| 91 | |
| 92 | if (path_obj) |
| 93 | { |
| 94 | const char* filesDir = env->GetStringUTFChars(path_obj, NULL); |
| 95 | |
| 96 | if (dmStrlCpy(path, filesDir, path_len) >= path_len) |
| 97 | { |
| 98 | res = RESULT_INVAL; |
| 99 | } |
| 100 | env->ReleaseStringUTFChars(path_obj, filesDir); |
| 101 | } |
| 102 | else |
| 103 | { |
| 104 | res = RESULT_UNKNOWN; |
| 105 | } |
| 106 | return res; |
| 107 | } |
| 108 | |
| 109 | Result GetApplicationPath(char* path_out, uint32_t path_len) |
| 110 | { |
no test coverage detected