[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: { | ||||
24 | char bin_dir[PATH_MAX + 1]; | ||||
[email protected] | 094797b7 | 2012-09-15 10:51:05 | [diff] [blame] | 25 | int bin_dir_size = readlink(kProcSelfExe, bin_dir, PATH_MAX); |
falken | fa35291 | 2016-05-10 02:55:43 | [diff] [blame] | 26 | if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { |
27 | NOTREACHED() << "Unable to resolve " << kProcSelfExe << "."; | ||||
28 | return false; | ||||
29 | } | ||||
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 30 | bin_dir[bin_dir_size] = 0; |
31 | *result = FilePath(bin_dir); | ||||
32 | return true; | ||||
33 | } | ||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 34 | case base::FILE_MODULE: |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 35 | // dladdr didn't work in Android as only the file name was returned. |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 36 | NOTIMPLEMENTED(); |
37 | return false; | ||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 38 | case base::DIR_MODULE: |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 39 | return base::android::GetNativeLibraryDirectory(result); |
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 40 | case base::DIR_SOURCE_ROOT: |
agrieve | d4d66d4 | 2016-06-08 16:53:39 | [diff] [blame] | 41 | // Used only by tests. |
42 | // In that context, hooked up via base/test/test_support_android.cc. | ||||
43 | NOTIMPLEMENTED(); | ||||
44 | return false; | ||||
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 45 | case base::DIR_USER_DESKTOP: |
46 | // Android doesn't support GetUserDesktop. | ||||
47 | NOTIMPLEMENTED(); | ||||
48 | return false; | ||||
49 | case base::DIR_CACHE: | ||||
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 50 | return base::android::GetCacheDirectory(result); |
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 51 | case base::DIR_ANDROID_APP_DATA: |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 52 | return base::android::GetDataDirectory(result); |
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 53 | case base::DIR_ANDROID_EXTERNAL_STORAGE: |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 54 | return base::android::GetExternalStorageDirectory(result); |
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 55 | default: |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 56 | // Note: the path system expects this function to override the default |
57 | // behavior. So no need to log an error if we don't support a given | ||||
58 | // path. The system will just use the default. | ||||
59 | return false; | ||||
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 60 | } |
61 | } | ||||
62 | |||||
63 | } // namespace base |