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 | |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 8 | #include "base/base_paths.h" |
9 | |||||
avi | 51ba3e69 | 2015-12-26 17:30:50 | [diff] [blame] | 10 | #include <limits.h> |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 11 | #include <unistd.h> |
12 | |||||
Jean-Philippe Gravel | 47159f16 | 2022-11-27 20:32:58 | [diff] [blame] | 13 | #include <ostream> |
14 | |||||
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 15 | #include "base/android/jni_android.h" |
16 | #include "base/android/path_utils.h" | ||||
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 17 | #include "base/files/file_path.h" |
[email protected] | e3177dd5 | 2014-08-13 20:22:14 | [diff] [blame] | 18 | #include "base/files/file_util.h" |
Andrew Grieve | 165155c | 2023-03-09 03:23:05 | [diff] [blame] | 19 | #include "base/logging.h" |
Peter Boström | 6e2fd08 | 2024-01-23 01:17:55 | [diff] [blame] | 20 | #include "base/notimplemented.h" |
[email protected] | dd4b5126 | 2013-07-25 21:38:23 | [diff] [blame] | 21 | #include "base/process/process_metrics.h" |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 22 | |
23 | namespace base { | ||||
24 | |||||
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 25 | bool PathProviderAndroid(int key, FilePath* result) { |
26 | switch (key) { | ||||
27 | case base::FILE_EXE: { | ||||
tfarina | 0cead9c | 2017-05-10 18:56:29 | [diff] [blame] | 28 | FilePath bin_dir; |
29 | if (!ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) { | ||||
Andrew Grieve | 165155c | 2023-03-09 03:23:05 | [diff] [blame] | 30 | // This fails for some devices (maybe custom OEM selinux policy?) |
31 | // https://crbug.com/1416753 | ||||
32 | LOG(ERROR) << "Unable to resolve " << kProcSelfExe << "."; | ||||
falken | fa35291 | 2016-05-10 02:55:43 | [diff] [blame] | 33 | return false; |
34 | } | ||||
tfarina | 0cead9c | 2017-05-10 18:56:29 | [diff] [blame] | 35 | *result = bin_dir; |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 36 | return true; |
37 | } | ||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 38 | case base::FILE_MODULE: |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 39 | // dladdr didn't work in Android as only the file name was returned. |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 40 | NOTIMPLEMENTED(); |
41 | return false; | ||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 42 | case base::DIR_MODULE: |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 43 | return base::android::GetNativeLibraryDirectory(result); |
David Dorwin | c694f72 | 2021-10-29 22:46:59 | [diff] [blame] | 44 | case base::DIR_SRC_TEST_DATA_ROOT: |
Etienne Pierre-doray | f4dcbd6a | 2023-07-06 16:12:03 | [diff] [blame] | 45 | case base::DIR_OUT_TEST_DATA_ROOT: |
David Dorwin | c694f72 | 2021-10-29 22:46:59 | [diff] [blame] | 46 | // These are only used by tests. In that context, they are overridden by |
47 | // PathProviders in //base/test/test_support_android.cc. | ||||
Etienne Pierre-doray | f4dcbd6a | 2023-07-06 16:12:03 | [diff] [blame] | 48 | NOTIMPLEMENTED(); |
agrieve | d4d66d4 | 2016-06-08 16:53:39 | [diff] [blame] | 49 | return false; |
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 50 | case base::DIR_USER_DESKTOP: |
51 | // Android doesn't support GetUserDesktop. | ||||
52 | NOTIMPLEMENTED(); | ||||
53 | return false; | ||||
54 | case base::DIR_CACHE: | ||||
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 55 | return base::android::GetCacheDirectory(result); |
Sergey Ulanov | d5ae68e | 2018-02-07 20:14:21 | [diff] [blame] | 56 | case base::DIR_ASSETS: |
57 | // On Android assets are normally loaded from the APK using | ||||
58 | // base::android::OpenApkAsset(). In tests, since the assets are no | ||||
59 | // packaged, DIR_ASSETS is overridden to point to the build directory. | ||||
60 | return false; | ||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 61 | case base::DIR_ANDROID_APP_DATA: |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 62 | return base::android::GetDataDirectory(result); |
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 63 | case base::DIR_ANDROID_EXTERNAL_STORAGE: |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 64 | return base::android::GetExternalStorageDirectory(result); |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 65 | } |
David Dorwin | c694f72 | 2021-10-29 22:46:59 | [diff] [blame] | 66 | |
67 | // For all other keys, let the PathService fall back to a default, if defined. | ||||
68 | return false; | ||||
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 69 | } |
70 | |||||
71 | } // namespace base |