blob: 8a400e5bd14ae9e29c9350bafe0c10fc163604f0 [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: {
24 char bin_dir[PATH_MAX + 1];
[email protected]094797b72012-09-15 10:51:0525 int bin_dir_size = readlink(kProcSelfExe, bin_dir, PATH_MAX);
falkenfa352912016-05-10 02:55:4326 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) {
27 NOTREACHED() << "Unable to resolve " << kProcSelfExe << ".";
28 return false;
29 }
[email protected]f7d69972011-06-21 22:34:5030 bin_dir[bin_dir_size] = 0;
31 *result = FilePath(bin_dir);
32 return true;
33 }
[email protected]dea1d7d2012-09-20 16:24:5234 case base::FILE_MODULE:
[email protected]61c86c62011-08-02 16:11:1635 // dladdr didn't work in Android as only the file name was returned.
[email protected]f7d69972011-06-21 22:34:5036 NOTIMPLEMENTED();
37 return false;
[email protected]dea1d7d2012-09-20 16:24:5238 case base::DIR_MODULE:
[email protected]18011cb72012-10-02 22:03:3339 return base::android::GetNativeLibraryDirectory(result);
[email protected]dea1d7d2012-09-20 16:24:5240 case base::DIR_SOURCE_ROOT:
agrieved4d66d42016-06-08 16:53:3941 // Used only by tests.
42 // In that context, hooked up via base/test/test_support_android.cc.
43 NOTIMPLEMENTED();
44 return false;
[email protected]dea1d7d2012-09-20 16:24:5245 case base::DIR_USER_DESKTOP:
46 // Android doesn't support GetUserDesktop.
47 NOTIMPLEMENTED();
48 return false;
49 case base::DIR_CACHE:
[email protected]18011cb72012-10-02 22:03:3350 return base::android::GetCacheDirectory(result);
[email protected]dea1d7d2012-09-20 16:24:5251 case base::DIR_ANDROID_APP_DATA:
[email protected]18011cb72012-10-02 22:03:3352 return base::android::GetDataDirectory(result);
[email protected]dea1d7d2012-09-20 16:24:5253 case base::DIR_ANDROID_EXTERNAL_STORAGE:
[email protected]18011cb72012-10-02 22:03:3354 return base::android::GetExternalStorageDirectory(result);
[email protected]dea1d7d2012-09-20 16:24:5255 default:
[email protected]f7d69972011-06-21 22:34:5056 // 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]f7d69972011-06-21 22:34:5060 }
61}
62
63} // namespace base