blob: 0962d8456fce5611771708a66a5f1e6035f8a456 [file] [log] [blame]
[email protected]672898b2012-07-02 20:04:041// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[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
[email protected]61c86c62011-08-02 16:11:1611#include "base/android/jni_android.h"
12#include "base/android/path_utils.h"
[email protected]dea1d7d2012-09-20 16:24:5213#include "base/base_paths.h"
[email protected]57999812013-02-24 05:40:5214#include "base/files/file_path.h"
[email protected]e3177dd52014-08-13 20:22:1415#include "base/files/file_util.h"
[email protected]f7d69972011-06-21 22:34:5016#include "base/logging.h"
[email protected]dd4b51262013-07-25 21:38:2317#include "base/process/process_metrics.h"
[email protected]61c86c62011-08-02 16:11:1618
19namespace base {
20
[email protected]f7d69972011-06-21 22:34:5021bool PathProviderAndroid(int key, FilePath* result) {
22 switch (key) {
23 case base::FILE_EXE: {
tfarina0cead9c2017-05-10 18:56:2924 FilePath bin_dir;
25 if (!ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) {
falkenfa352912016-05-10 02:55:4326 NOTREACHED() << "Unable to resolve " << kProcSelfExe << ".";
27 return false;
28 }
tfarina0cead9c2017-05-10 18:56:2929 *result = bin_dir;
[email protected]f7d69972011-06-21 22:34:5030 return true;
31 }
[email protected]dea1d7d2012-09-20 16:24:5232 case base::FILE_MODULE:
[email protected]61c86c62011-08-02 16:11:1633 // dladdr didn't work in Android as only the file name was returned.
[email protected]f7d69972011-06-21 22:34:5034 NOTIMPLEMENTED();
35 return false;
[email protected]dea1d7d2012-09-20 16:24:5236 case base::DIR_MODULE:
[email protected]18011cb72012-10-02 22:03:3337 return base::android::GetNativeLibraryDirectory(result);
[email protected]dea1d7d2012-09-20 16:24:5238 case base::DIR_SOURCE_ROOT:
agrieved4d66d42016-06-08 16:53:3939 // Used only by tests.
40 // In that context, hooked up via base/test/test_support_android.cc.
41 NOTIMPLEMENTED();
42 return false;
[email protected]dea1d7d2012-09-20 16:24:5243 case base::DIR_USER_DESKTOP:
44 // Android doesn't support GetUserDesktop.
45 NOTIMPLEMENTED();
46 return false;
47 case base::DIR_CACHE:
[email protected]18011cb72012-10-02 22:03:3348 return base::android::GetCacheDirectory(result);
[email protected]dea1d7d2012-09-20 16:24:5249 case base::DIR_ANDROID_APP_DATA:
[email protected]18011cb72012-10-02 22:03:3350 return base::android::GetDataDirectory(result);
[email protected]dea1d7d2012-09-20 16:24:5251 case base::DIR_ANDROID_EXTERNAL_STORAGE:
[email protected]18011cb72012-10-02 22:03:3352 return base::android::GetExternalStorageDirectory(result);
[email protected]dea1d7d2012-09-20 16:24:5253 default:
[email protected]f7d69972011-06-21 22:34:5054 // Note: the path system expects this function to override the default
55 // behavior. So no need to log an error if we don't support a given
56 // path. The system will just use the default.
57 return false;
[email protected]f7d69972011-06-21 22:34:5058 }
59}
60
61} // namespace base