| 6 |
| 7 | #include "base/android/jni_android.h" |
| 8 | #include "base/android/jni_array.h" |
| 9 | #include "base/android/jni_string.h" |
| 10 | #include "base/android/scoped_java_ref.h" |
| 11 | #include "base/files/file_path.h" |
| 12 |
| 13 | #include "base/base_jni_headers/PathUtils_jni.h" |
| 14 |
| 15 | namespace base { |
| 16 | namespace android { |
| 17 |
| 18 | bool GetDataDirectory(FilePath* result) { |
| 19 | JNIEnv* env = AttachCurrentThread(); |
| 20 | ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDataDirectory(env); |
| 21 | FilePath data_path(ConvertJavaStringToUTF8(path)); |
| 22 | *result = data_path; |
| 23 | return true; |
| 24 | } |
| 25 |
| 26 | bool GetCacheDirectory(FilePath* result) { |
| 27 | JNIEnv* env = AttachCurrentThread(); |
| 28 | ScopedJavaLocalRef<jstring> path = Java_PathUtils_getCacheDirectory(env); |
| 29 | FilePath cache_path(ConvertJavaStringToUTF8(path)); |
| 30 | *result = cache_path; |
| 31 | return true; |
| 32 | } |
| 33 |
| 34 | bool GetThumbnailCacheDirectory(FilePath* result) { |
| 35 | JNIEnv* env = AttachCurrentThread(); |
| 36 | ScopedJavaLocalRef<jstring> path = |
| 37 | Java_PathUtils_getThumbnailCacheDirectory(env); |
| 38 | FilePath thumbnail_cache_path(ConvertJavaStringToUTF8(path)); |
| 39 | *result = thumbnail_cache_path; |
| 40 | return true; |
| 41 | } |
| 42 |
| 43 | bool GetDownloadsDirectory(FilePath* result) { |
| 44 | JNIEnv* env = AttachCurrentThread(); |
| 45 | ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDownloadsDirectory(env); |
| 46 | FilePath downloads_path(ConvertJavaStringToUTF8(path)); |
| 47 | *result = downloads_path; |
| 48 | return true; |
| 49 | } |
| 50 |
| 51 | std::vector<FilePath> GetAllPrivateDownloadsDirectories() { |
| 52 | std::vector<std::string> dirs; |
| 53 | JNIEnv* env = AttachCurrentThread(); |
| 54 | auto jarray = Java_PathUtils_getAllPrivateDownloadsDirectories(env); |
| 55 | base::android::AppendJavaStringArrayToStringVector(env, jarray, &dirs); |
| 56 |
| 57 | std::vector<base::FilePath> file_paths; |
| 58 | for (const auto& dir : dirs) |
| 59 | file_paths.emplace_back(dir); |
| 60 | return file_paths; |
| 61 | } |
| 62 |
| 63 | bool GetNativeLibraryDirectory(FilePath* result) { |
| 64 | JNIEnv* env = AttachCurrentThread(); |
| 65 | ScopedJavaLocalRef<jstring> path = |
| 66 | Java_PathUtils_getNativeLibraryDirectory(env); |
| 67 | FilePath library_path(ConvertJavaStringToUTF8(path)); |
| 68 | *result = library_path; |
| 69 | return true; |
| 70 | } |
| 71 |
| 72 | bool GetExternalStorageDirectory(FilePath* result) { |
| 73 | JNIEnv* env = AttachCurrentThread(); |
| 74 | ScopedJavaLocalRef<jstring> path = |
| 75 | Java_PathUtils_getExternalStorageDirectory(env); |
| 76 | FilePath storage_path(ConvertJavaStringToUTF8(path)); |
| 77 | *result = storage_path; |
| 78 | return true; |
| 79 | } |
| 80 |
| 81 | } // namespace android |
| 82 | } // namespace base |
| 83 |