1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/android/path_utils.h"
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"
13 #include "base/base_jni/PathUtils_jni.h"
18 bool GetDataDirectory(FilePath* result) {
19 JNIEnv* env = AttachCurrentThread();
20 ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDataDirectory(env);
21 FilePath data_path(ConvertJavaStringToUTF8(path));
26 bool GetCacheDirectory(FilePath* result) {
27 JNIEnv* env = AttachCurrentThread();
28 ScopedJavaLocalRef<jstring> path = Java_PathUtils_getCacheDirectory(env);
29 FilePath cache_path(ConvertJavaStringToUTF8(path));
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;
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;
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);
57 std::vector<base::FilePath> file_paths;
58 for (const auto& dir : dirs)
59 file_paths.emplace_back(dir);
63 std::vector<FilePath> GetSecondaryStorageDownloadDirectories() {
64 std::vector<std::string> dirs;
65 JNIEnv* env = AttachCurrentThread();
66 auto jarray = Java_PathUtils_getExternalDownloadVolumesNames(env);
67 base::android::AppendJavaStringArrayToStringVector(env, jarray, &dirs);
69 std::vector<base::FilePath> file_paths;
70 for (const auto& dir : dirs)
71 file_paths.emplace_back(dir);
75 bool GetNativeLibraryDirectory(FilePath* result) {
76 JNIEnv* env = AttachCurrentThread();
77 ScopedJavaLocalRef<jstring> path =
78 Java_PathUtils_getNativeLibraryDirectory(env);
79 FilePath library_path(ConvertJavaStringToUTF8(path));
80 *result = library_path;
84 bool GetExternalStorageDirectory(FilePath* result) {
85 JNIEnv* env = AttachCurrentThread();
86 ScopedJavaLocalRef<jstring> path =
87 Java_PathUtils_getExternalStorageDirectory(env);
88 FilePath storage_path(ConvertJavaStringToUTF8(path));
89 *result = storage_path;
93 } // namespace android