Home | History | Annotate | Download | only in android
      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_string.h"
      9 #include "base/android/scoped_java_ref.h"
     10 #include "base/files/file_path.h"
     11 
     12 #include "jni/PathUtils_jni.h"
     13 
     14 namespace base {
     15 namespace android {
     16 
     17 bool GetDataDirectory(FilePath* result) {
     18   JNIEnv* env = AttachCurrentThread();
     19   ScopedJavaLocalRef<jstring> path =
     20       Java_PathUtils_getDataDirectory(env, GetApplicationContext());
     21   FilePath data_path(ConvertJavaStringToUTF8(path));
     22   *result = data_path;
     23   return true;
     24 }
     25 
     26 bool GetDatabaseDirectory(FilePath* result) {
     27   JNIEnv* env = AttachCurrentThread();
     28   ScopedJavaLocalRef<jstring> path =
     29       Java_PathUtils_getDatabaseDirectory(env, GetApplicationContext());
     30   FilePath data_path(ConvertJavaStringToUTF8(path));
     31   *result = data_path;
     32   return true;
     33 }
     34 
     35 bool GetCacheDirectory(FilePath* result) {
     36   JNIEnv* env = AttachCurrentThread();
     37   ScopedJavaLocalRef<jstring> path =
     38       Java_PathUtils_getCacheDirectory(env, GetApplicationContext());
     39   FilePath cache_path(ConvertJavaStringToUTF8(path));
     40   *result = cache_path;
     41   return true;
     42 }
     43 
     44 bool GetDownloadsDirectory(FilePath* result) {
     45   JNIEnv* env = AttachCurrentThread();
     46   ScopedJavaLocalRef<jstring> path =
     47       Java_PathUtils_getDownloadsDirectory(env, GetApplicationContext());
     48   FilePath downloads_path(ConvertJavaStringToUTF8(path));
     49   *result = downloads_path;
     50   return true;
     51 }
     52 
     53 bool GetNativeLibraryDirectory(FilePath* result) {
     54   JNIEnv* env = AttachCurrentThread();
     55   ScopedJavaLocalRef<jstring> path =
     56       Java_PathUtils_getNativeLibraryDirectory(env, GetApplicationContext());
     57   FilePath library_path(ConvertJavaStringToUTF8(path));
     58   *result = library_path;
     59   return true;
     60 }
     61 
     62 bool GetExternalStorageDirectory(FilePath* result) {
     63   JNIEnv* env = AttachCurrentThread();
     64   ScopedJavaLocalRef<jstring> path =
     65       Java_PathUtils_getExternalStorageDirectory(env);
     66   FilePath storage_path(ConvertJavaStringToUTF8(path));
     67   *result = storage_path;
     68   return true;
     69 }
     70 
     71 bool RegisterPathUtils(JNIEnv* env) {
     72   return RegisterNativesImpl(env);
     73 }
     74 
     75 }  // namespace android
     76 }  // namespace base
     77