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.
5 // Defines base::PathProviderAndroid which replaces base::PathProviderPosix for
6 // Android in base/path_service.cc.
10 #include "base/android/jni_android.h"
11 #include "base/android/path_utils.h"
12 #include "base/base_paths.h"
13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h"
15 #include "base/logging.h"
16 #include "base/process/process_metrics.h"
20 bool PathProviderAndroid(int key
, FilePath
* result
) {
22 case base::FILE_EXE
: {
23 char bin_dir
[PATH_MAX
+ 1];
24 int bin_dir_size
= readlink(kProcSelfExe
, bin_dir
, PATH_MAX
);
25 if (bin_dir_size
< 0 || bin_dir_size
> PATH_MAX
) {
26 NOTREACHED() << "Unable to resolve " << kProcSelfExe
<< ".";
29 bin_dir
[bin_dir_size
] = 0;
30 *result
= FilePath(bin_dir
);
33 case base::FILE_MODULE
:
34 // dladdr didn't work in Android as only the file name was returned.
37 case base::DIR_MODULE
:
38 return base::android::GetNativeLibraryDirectory(result
);
39 case base::DIR_SOURCE_ROOT
:
40 // This const is only used for tests.
41 return base::android::GetExternalStorageDirectory(result
);
42 case base::DIR_USER_DESKTOP
:
43 // Android doesn't support GetUserDesktop.
47 return base::android::GetCacheDirectory(result
);
48 case base::DIR_ANDROID_APP_DATA
:
49 return base::android::GetDataDirectory(result
);
50 case base::DIR_ANDROID_EXTERNAL_STORAGE
:
51 return base::android::GetExternalStorageDirectory(result
);
53 // Note: the path system expects this function to override the default
54 // behavior. So no need to log an error if we don't support a given
55 // path. The system will just use the default.