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.
11 #include "base/android/jni_android.h"
12 #include "base/android/path_utils.h"
13 #include "base/base_paths.h"
14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h"
16 #include "base/logging.h"
17 #include "base/process/process_metrics.h"
21 bool PathProviderAndroid(int key, FilePath* result) {
23 case base::FILE_EXE: {
25 if (!ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) {
26 NOTREACHED() << "Unable to resolve " << kProcSelfExe << ".";
32 case base::FILE_MODULE:
33 // dladdr didn't work in Android as only the file name was returned.
36 case base::DIR_MODULE:
37 return base::android::GetNativeLibraryDirectory(result);
38 case base::DIR_SOURCE_ROOT:
39 // Used only by tests.
40 // In that context, hooked up via base/test/test_support_android.cc.
43 case base::DIR_USER_DESKTOP:
44 // Android doesn't support GetUserDesktop.
48 return base::android::GetCacheDirectory(result);
49 case base::DIR_ASSETS:
50 // On Android assets are normally loaded from the APK using
51 // base::android::OpenApkAsset(). In tests, since the assets are no
52 // packaged, DIR_ASSETS is overridden to point to the build directory.
54 case base::DIR_ANDROID_APP_DATA:
55 return base::android::GetDataDirectory(result);
56 case base::DIR_ANDROID_EXTERNAL_STORAGE:
57 return base::android::GetExternalStorageDirectory(result);
59 // Note: the path system expects this function to override the default
60 // behavior. So no need to log an error if we don't support a given
61 // path. The system will just use the default.