blob: 428c73a01f22e69cf60b898d8609fde71ed12c93 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2012 The Chromium Authors
[email protected]f7d69972011-06-21 22:34:502// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]dea1d7d2012-09-20 16:24:525// Defines base::PathProviderAndroid which replaces base::PathProviderPosix for
6// Android in base/path_service.cc.
[email protected]f7d69972011-06-21 22:34:507
avi51ba3e692015-12-26 17:30:508#include <limits.h>
[email protected]f7d69972011-06-21 22:34:509#include <unistd.h>
10
Jean-Philippe Gravel47159f162022-11-27 20:32:5811#include <ostream>
12
[email protected]61c86c62011-08-02 16:11:1613#include "base/android/jni_android.h"
14#include "base/android/path_utils.h"
[email protected]dea1d7d2012-09-20 16:24:5215#include "base/base_paths.h"
[email protected]57999812013-02-24 05:40:5216#include "base/files/file_path.h"
[email protected]e3177dd52014-08-13 20:22:1417#include "base/files/file_util.h"
Andrew Grieve165155c2023-03-09 03:23:0518#include "base/logging.h"
Hans Wennborgc3cffa62020-04-27 10:09:1219#include "base/notreached.h"
[email protected]dd4b51262013-07-25 21:38:2320#include "base/process/process_metrics.h"
[email protected]61c86c62011-08-02 16:11:1621
22namespace base {
23
[email protected]f7d69972011-06-21 22:34:5024bool PathProviderAndroid(int key, FilePath* result) {
25 switch (key) {
26 case base::FILE_EXE: {
tfarina0cead9c2017-05-10 18:56:2927 FilePath bin_dir;
28 if (!ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) {
Andrew Grieve165155c2023-03-09 03:23:0529 // This fails for some devices (maybe custom OEM selinux policy?)
30 // https://crbug.com/1416753
31 LOG(ERROR) << "Unable to resolve " << kProcSelfExe << ".";
falkenfa352912016-05-10 02:55:4332 return false;
33 }
tfarina0cead9c2017-05-10 18:56:2934 *result = bin_dir;
[email protected]f7d69972011-06-21 22:34:5035 return true;
36 }
[email protected]dea1d7d2012-09-20 16:24:5237 case base::FILE_MODULE:
[email protected]61c86c62011-08-02 16:11:1638 // dladdr didn't work in Android as only the file name was returned.
[email protected]f7d69972011-06-21 22:34:5039 NOTIMPLEMENTED();
40 return false;
[email protected]dea1d7d2012-09-20 16:24:5241 case base::DIR_MODULE:
[email protected]18011cb72012-10-02 22:03:3342 return base::android::GetNativeLibraryDirectory(result);
David Dorwinc694f722021-10-29 22:46:5943 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();
agrieved4d66d42016-06-08 16:53:3948 return false;
[email protected]dea1d7d2012-09-20 16:24:5249 case base::DIR_USER_DESKTOP:
50 // Android doesn't support GetUserDesktop.
51 NOTIMPLEMENTED();
52 return false;
53 case base::DIR_CACHE:
[email protected]18011cb72012-10-02 22:03:3354 return base::android::GetCacheDirectory(result);
Sergey Ulanovd5ae68e2018-02-07 20:14:2155 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]dea1d7d2012-09-20 16:24:5260 case base::DIR_ANDROID_APP_DATA:
[email protected]18011cb72012-10-02 22:03:3361 return base::android::GetDataDirectory(result);
[email protected]dea1d7d2012-09-20 16:24:5262 case base::DIR_ANDROID_EXTERNAL_STORAGE:
[email protected]18011cb72012-10-02 22:03:3363 return base::android::GetExternalStorageDirectory(result);
[email protected]f7d69972011-06-21 22:34:5064 }
David Dorwinc694f722021-10-29 22:46:5965
66 // For all other keys, let the PathService fall back to a default, if defined.
67 return false;
[email protected]f7d69972011-06-21 22:34:5068}
69
70} // namespace base