blob: a90f3a42f1145bf5bc64d17eb36140bbab7c4564 [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
Peter Kasting134ef9af2024-12-28 02:30:098#include "base/base_paths.h"
9
avi51ba3e692015-12-26 17:30:5010#include <limits.h>
[email protected]f7d69972011-06-21 22:34:5011#include <unistd.h>
12
Jean-Philippe Gravel47159f162022-11-27 20:32:5813#include <ostream>
14
[email protected]61c86c62011-08-02 16:11:1615#include "base/android/jni_android.h"
16#include "base/android/path_utils.h"
[email protected]57999812013-02-24 05:40:5217#include "base/files/file_path.h"
[email protected]e3177dd52014-08-13 20:22:1418#include "base/files/file_util.h"
Andrew Grieve165155c2023-03-09 03:23:0519#include "base/logging.h"
Peter Boström6e2fd082024-01-23 01:17:5520#include "base/notimplemented.h"
[email protected]dd4b51262013-07-25 21:38:2321#include "base/process/process_metrics.h"
[email protected]61c86c62011-08-02 16:11:1622
23namespace base {
24
[email protected]f7d69972011-06-21 22:34:5025bool PathProviderAndroid(int key, FilePath* result) {
26 switch (key) {
27 case base::FILE_EXE: {
tfarina0cead9c2017-05-10 18:56:2928 FilePath bin_dir;
29 if (!ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) {
Andrew Grieve165155c2023-03-09 03:23:0530 // This fails for some devices (maybe custom OEM selinux policy?)
31 // https://crbug.com/1416753
32 LOG(ERROR) << "Unable to resolve " << kProcSelfExe << ".";
falkenfa352912016-05-10 02:55:4333 return false;
34 }
tfarina0cead9c2017-05-10 18:56:2935 *result = bin_dir;
[email protected]f7d69972011-06-21 22:34:5036 return true;
37 }
[email protected]dea1d7d2012-09-20 16:24:5238 case base::FILE_MODULE:
[email protected]61c86c62011-08-02 16:11:1639 // dladdr didn't work in Android as only the file name was returned.
[email protected]f7d69972011-06-21 22:34:5040 NOTIMPLEMENTED();
41 return false;
[email protected]dea1d7d2012-09-20 16:24:5242 case base::DIR_MODULE:
[email protected]18011cb72012-10-02 22:03:3343 return base::android::GetNativeLibraryDirectory(result);
David Dorwinc694f722021-10-29 22:46:5944 case base::DIR_SRC_TEST_DATA_ROOT:
Etienne Pierre-dorayf4dcbd6a2023-07-06 16:12:0345 case base::DIR_OUT_TEST_DATA_ROOT:
David Dorwinc694f722021-10-29 22:46:5946 // These are only used by tests. In that context, they are overridden by
47 // PathProviders in //base/test/test_support_android.cc.
Etienne Pierre-dorayf4dcbd6a2023-07-06 16:12:0348 NOTIMPLEMENTED();
agrieved4d66d42016-06-08 16:53:3949 return false;
[email protected]dea1d7d2012-09-20 16:24:5250 case base::DIR_USER_DESKTOP:
51 // Android doesn't support GetUserDesktop.
52 NOTIMPLEMENTED();
53 return false;
54 case base::DIR_CACHE:
[email protected]18011cb72012-10-02 22:03:3355 return base::android::GetCacheDirectory(result);
Sergey Ulanovd5ae68e2018-02-07 20:14:2156 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]dea1d7d2012-09-20 16:24:5261 case base::DIR_ANDROID_APP_DATA:
[email protected]18011cb72012-10-02 22:03:3362 return base::android::GetDataDirectory(result);
[email protected]dea1d7d2012-09-20 16:24:5263 case base::DIR_ANDROID_EXTERNAL_STORAGE:
[email protected]18011cb72012-10-02 22:03:3364 return base::android::GetExternalStorageDirectory(result);
[email protected]f7d69972011-06-21 22:34:5065 }
David Dorwinc694f722021-10-29 22:46:5966
67 // For all other keys, let the PathService fall back to a default, if defined.
68 return false;
[email protected]f7d69972011-06-21 22:34:5069}
70
71} // namespace base