base_paths_android.cc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // Defines base::PathProviderAndroid which replaces base::PathProviderPosix for
  5. // Android in base/path_service.cc.
  6. #include <limits.h>
  7. #include <unistd.h>
  8. #include "base/android/jni_android.h"
  9. #include "base/android/path_utils.h"
  10. #include "base/base_paths.h"
  11. #include "base/files/file_path.h"
  12. #include "base/files/file_util.h"
  13. #include "base/notreached.h"
  14. #include "base/process/process_metrics.h"
  15. namespace base {
  16. bool PathProviderAndroid(int key, FilePath* result) {
  17. switch (key) {
  18. case base::FILE_EXE: {
  19. FilePath bin_dir;
  20. if (!ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) {
  21. NOTREACHED() << "Unable to resolve " << kProcSelfExe << ".";
  22. return false;
  23. }
  24. *result = bin_dir;
  25. return true;
  26. }
  27. case base::FILE_MODULE:
  28. // dladdr didn't work in Android as only the file name was returned.
  29. NOTIMPLEMENTED();
  30. return false;
  31. case base::DIR_MODULE:
  32. return base::android::GetNativeLibraryDirectory(result);
  33. case base::DIR_SRC_TEST_DATA_ROOT:
  34. case base::DIR_GEN_TEST_DATA_ROOT:
  35. // These are only used by tests. In that context, they are overridden by
  36. // PathProviders in //base/test/test_support_android.cc.
  37. NOTREACHED();
  38. return false;
  39. case base::DIR_USER_DESKTOP:
  40. // Android doesn't support GetUserDesktop.
  41. NOTIMPLEMENTED();
  42. return false;
  43. case base::DIR_CACHE:
  44. return base::android::GetCacheDirectory(result);
  45. case base::DIR_ASSETS:
  46. // On Android assets are normally loaded from the APK using
  47. // base::android::OpenApkAsset(). In tests, since the assets are no
  48. // packaged, DIR_ASSETS is overridden to point to the build directory.
  49. return false;
  50. case base::DIR_ANDROID_APP_DATA:
  51. return base::android::GetDataDirectory(result);
  52. case base::DIR_ANDROID_EXTERNAL_STORAGE:
  53. return base::android::GetExternalStorageDirectory(result);
  54. }
  55. // For all other keys, let the PathService fall back to a default, if defined.
  56. return false;
  57. }
  58. } // namespace base