1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/android/path_utils.h" 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 "jni/PathUtils_jni.h" 14 15 namespace base { 16 namespace android { 17 GetDataDirectory(FilePath * result)18bool 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 GetCacheDirectory(FilePath * result)26bool 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 GetThumbnailCacheDirectory(FilePath * result)34bool 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 GetDownloadsDirectory(FilePath * result)43bool 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 GetAllPrivateDownloadsDirectories()51std::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.obj(), &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 GetNativeLibraryDirectory(FilePath * result)63bool 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 GetExternalStorageDirectory(FilePath * result)72bool 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