[email protected] | 672898b | 2012-07-02 20:04:04 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 5 | // Defines base::PathProviderAndroid which replaces base::PathProviderPosix for |
6 | // Android in base/path_service.cc. | ||||
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 7 | |
avi | 51ba3e69 | 2015-12-26 17:30:50 | [diff] [blame] | 8 | #include <limits.h> |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 9 | #include <unistd.h> |
10 | |||||
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 11 | #include "base/android/jni_android.h" |
12 | #include "base/android/path_utils.h" | ||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 13 | #include "base/base_paths.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 14 | #include "base/files/file_path.h" |
[email protected] | e3177dd5 | 2014-08-13 20:22:14 | [diff] [blame] | 15 | #include "base/files/file_util.h" |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 16 | #include "base/logging.h" |
[email protected] | dd4b5126 | 2013-07-25 21:38:23 | [diff] [blame] | 17 | #include "base/process/process_metrics.h" |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 18 | |
19 | namespace base { | ||||
20 | |||||
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 21 | bool PathProviderAndroid(int key, FilePath* result) { |
22 | switch (key) { | ||||
23 | case base::FILE_EXE: { | ||||
tfarina | 0cead9c | 2017-05-10 18:56:29 | [diff] [blame] | 24 | FilePath bin_dir; |
25 | if (!ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) { | ||||
falken | fa35291 | 2016-05-10 02:55:43 | [diff] [blame] | 26 | NOTREACHED() << "Unable to resolve " << kProcSelfExe << "."; |
27 | return false; | ||||
28 | } | ||||
tfarina | 0cead9c | 2017-05-10 18:56:29 | [diff] [blame] | 29 | *result = bin_dir; |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 30 | return true; |
31 | } | ||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 32 | case base::FILE_MODULE: |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 33 | // dladdr didn't work in Android as only the file name was returned. |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 34 | NOTIMPLEMENTED(); |
35 | return false; | ||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 36 | case base::DIR_MODULE: |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 37 | return base::android::GetNativeLibraryDirectory(result); |
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 38 | case base::DIR_SOURCE_ROOT: |
agrieve | d4d66d4 | 2016-06-08 16:53:39 | [diff] [blame] | 39 | // Used only by tests. |
40 | // In that context, hooked up via base/test/test_support_android.cc. | ||||
41 | NOTIMPLEMENTED(); | ||||
42 | return false; | ||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 43 | case base::DIR_USER_DESKTOP: |
44 | // Android doesn't support GetUserDesktop. | ||||
45 | NOTIMPLEMENTED(); | ||||
46 | return false; | ||||
47 | case base::DIR_CACHE: | ||||
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 48 | return base::android::GetCacheDirectory(result); |
Sergey Ulanov | d5ae68e | 2018-02-07 20:14:21 | [diff] [blame] | 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. | ||||
53 | return false; | ||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 54 | case base::DIR_ANDROID_APP_DATA: |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 55 | return base::android::GetDataDirectory(result); |
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 56 | case base::DIR_ANDROID_EXTERNAL_STORAGE: |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 57 | return base::android::GetExternalStorageDirectory(result); |
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 58 | default: |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 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. | ||||
62 | return false; | ||||
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 63 | } |
64 | } | ||||
65 | |||||
66 | } // namespace base |