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 // Defines base::PathProviderAndroid which replaces base::PathProviderPosix for
6 // Android in base/path_service.cc.
13 #include "base/android/jni_android.h"
14 #include "base/android/path_utils.h"
15 #include "base/base_paths.h"
16 #include "base/files/file_path.h"
17 #include "base/files/file_util.h"
18 #include "base/logging.h"
19 #include "base/notreached.h"
20 #include "base/process/process_metrics.h"
24 bool PathProviderAndroid(int key, FilePath* result) {
26 case base::FILE_EXE: {
28 if (!ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) {
29 // This fails for some devices (maybe custom OEM selinux policy?)
30 // https://crbug.com/1416753
31 LOG(ERROR) << "Unable to resolve " << kProcSelfExe << ".";
37 case base::FILE_MODULE:
38 // dladdr didn't work in Android as only the file name was returned.
41 case base::DIR_MODULE:
42 return base::android::GetNativeLibraryDirectory(result);
43 case base::DIR_SRC_TEST_DATA_ROOT:
44 case base::DIR_OUT_TEST_DATA_ROOT:
45 // These are only used by tests. In that context, they are overridden by
46 // PathProviders in //base/test/test_support_android.cc.
49 case base::DIR_USER_DESKTOP:
50 // Android doesn't support GetUserDesktop.
54 return base::android::GetCacheDirectory(result);
55 case base::DIR_ASSETS:
56 // On Android assets are normally loaded from the APK using
57 // base::android::OpenApkAsset(). In tests, since the assets are no
58 // packaged, DIR_ASSETS is overridden to point to the build directory.
60 case base::DIR_ANDROID_APP_DATA:
61 return base::android::GetDataDirectory(result);
62 case base::DIR_ANDROID_EXTERNAL_STORAGE:
63 return base::android::GetExternalStorageDirectory(result);
66 // For all other keys, let the PathService fall back to a default, if defined.