aboutsummaryrefslogtreecommitdiffstats
path: root/components/config/basedir.rs
diff options
context:
space:
mode:
authorImanol Fernandez <mortimergoro@gmail.com>2017-02-28 14:17:59 +0100
committerImanol Fernandez <mortimergoro@gmail.com>2017-04-21 18:24:10 +0200
commit7a2a90959ecf96043fc879abacee79310528eccc (patch)
tree50e38f451d334c8111435f57e1134107d86e535b /components/config/basedir.rs
parent350d9c6c47fe1f20ebbd911f7675c23bcaa9ba2f (diff)
downloadservo-7a2a90959ecf96043fc879abacee79310528eccc.tar.gz
servo-7a2a90959ecf96043fc879abacee79310528eccc.zip
Android life cycle improvements and Gradle integration
Diffstat (limited to 'components/config/basedir.rs')
-rw-r--r--components/config/basedir.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/components/config/basedir.rs b/components/config/basedir.rs
index 5c7896a388b..521eb4e9dfd 100644
--- a/components/config/basedir.rs
+++ b/components/config/basedir.rs
@@ -6,8 +6,12 @@
//! For linux based platforms, it uses the XDG base directory spec but provides
//! similar abstractions for non-linux platforms.
+#[cfg(target_os = "android")]
+use android_injected_glue;
#[cfg(any(target_os = "macos", target_os = "windows"))]
use std::env;
+#[cfg(target_os = "android")]
+use std::ffi::CStr;
use std::path::PathBuf;
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
use xdg;
@@ -20,8 +24,12 @@ pub fn default_config_dir() -> Option<PathBuf> {
}
#[cfg(target_os = "android")]
+#[allow(unsafe_code)]
pub fn default_config_dir() -> Option<PathBuf> {
- Some(PathBuf::from("/sdcard/servo"))
+ let dir = unsafe {
+ CStr::from_ptr((*android_injected_glue::get_app().activity).externalDataPath)
+ };
+ Some(PathBuf::from(dir.to_str().unwrap()))
}
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
@@ -32,8 +40,12 @@ pub fn default_data_dir() -> Option<PathBuf> {
}
#[cfg(target_os = "android")]
+#[allow(unsafe_code)]
pub fn default_data_dir() -> Option<PathBuf> {
- Some(PathBuf::from("/sdcard/servo"))
+ let dir = unsafe {
+ CStr::from_ptr((*android_injected_glue::get_app().activity).internalDataPath)
+ };
+ Some(PathBuf::from(dir.to_str().unwrap()))
}
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
@@ -44,8 +56,14 @@ pub fn default_cache_dir() -> Option<PathBuf> {
}
#[cfg(target_os = "android")]
+#[allow(unsafe_code)]
pub fn default_cache_dir() -> Option<PathBuf> {
- Some(PathBuf::from("/sdcard/servo"))
+ // TODO: Use JNI to call context.getCacheDir().
+ // There is no equivalent function in NDK/NativeActivity.
+ let dir = unsafe {
+ CStr::from_ptr((*android_injected_glue::get_app().activity).externalDataPath)
+ };
+ Some(PathBuf::from(dir.to_str().unwrap()))
}
#[cfg(target_os = "macos")]