Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[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 | |||||
Jean-Philippe Gravel | 47159f16 | 2022-11-27 20:32:58 | [diff] [blame] | 11 | #include <ostream> |
12 | |||||
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 13 | #include "base/android/jni_android.h" |
14 | #include "base/android/path_utils.h" | ||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 15 | #include "base/base_paths.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 16 | #include "base/files/file_path.h" |
[email protected] | e3177dd5 | 2014-08-13 20:22:14 | [diff] [blame] | 17 | #include "base/files/file_util.h" |
Andrew Grieve | 165155c | 2023-03-09 03:23:05 | [diff] [blame^] | 18 | #include "base/logging.h" |
Hans Wennborg | c3cffa6 | 2020-04-27 10:09:12 | [diff] [blame] | 19 | #include "base/notreached.h" |
[email protected] | dd4b5126 | 2013-07-25 21:38:23 | [diff] [blame] | 20 | #include "base/process/process_metrics.h" |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 21 | |
22 | namespace base { | ||||
23 | |||||
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 24 | bool PathProviderAndroid(int key, FilePath* result) { |
25 | switch (key) { | ||||
26 | case base::FILE_EXE: { | ||||
tfarina | 0cead9c | 2017-05-10 18:56:29 | [diff] [blame] | 27 | FilePath bin_dir; |
28 | if (!ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) { | ||||
Andrew Grieve | 165155c | 2023-03-09 03:23:05 | [diff] [blame^] | 29 | // This fails for some devices (maybe custom OEM selinux policy?) |
30 | // https://crbug.com/1416753 | ||||
31 | LOG(ERROR) << "Unable to resolve " << kProcSelfExe << "."; | ||||
falken | fa35291 | 2016-05-10 02:55:43 | [diff] [blame] | 32 | return false; |
33 | } | ||||
tfarina | 0cead9c | 2017-05-10 18:56:29 | [diff] [blame] | 34 | *result = bin_dir; |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 35 | return true; |
36 | } | ||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 37 | case base::FILE_MODULE: |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 38 | // dladdr didn't work in Android as only the file name was returned. |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 39 | NOTIMPLEMENTED(); |
40 | return false; | ||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 41 | case base::DIR_MODULE: |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 42 | return base::android::GetNativeLibraryDirectory(result); |
David Dorwin | c694f72 | 2021-10-29 22:46:59 | [diff] [blame] | 43 | case base::DIR_SRC_TEST_DATA_ROOT: |
44 | case base::DIR_GEN_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. | ||||
47 | NOTREACHED(); | ||||
agrieve | d4d66d4 | 2016-06-08 16:53:39 | [diff] [blame] | 48 | return false; |
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 49 | case base::DIR_USER_DESKTOP: |
50 | // Android doesn't support GetUserDesktop. | ||||
51 | NOTIMPLEMENTED(); | ||||
52 | return false; | ||||
53 | case base::DIR_CACHE: | ||||
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 54 | return base::android::GetCacheDirectory(result); |
Sergey Ulanov | d5ae68e | 2018-02-07 20:14:21 | [diff] [blame] | 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. | ||||
59 | return false; | ||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 60 | case base::DIR_ANDROID_APP_DATA: |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 61 | return base::android::GetDataDirectory(result); |
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 62 | case base::DIR_ANDROID_EXTERNAL_STORAGE: |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 63 | return base::android::GetExternalStorageDirectory(result); |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 64 | } |
David Dorwin | c694f72 | 2021-10-29 22:46:59 | [diff] [blame] | 65 | |
66 | // For all other keys, let the PathService fall back to a default, if defined. | ||||
67 | return false; | ||||
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 68 | } |
69 | |||||
70 | } // namespace base |