Auto merge of #20912 - paulrouget:androidv2, r=jdm,mortimergoro,simonsapin

Revisit how the Android port works.

Fix #20855
Fix #18625
Fix #21147

Before polishing and making sure everything works fine (like the VR code, the android-x86 version, the non-android version of the lib, …), I'd like to get some early feedback on the approach.

I recommend reviewing commit by commit.

To test, just follow the regular steps:

```
    ./mach build -d --android
    ./mach package --dev --android builds servo.apk
    ./mach install --dev --android && ./mach run --android
```

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20912)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-07-31 13:07:33 -04:00 committed by GitHub
commit 95b54ca8f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
57 changed files with 2450 additions and 915 deletions

View file

@ -30,6 +30,3 @@ embedder_traits = { path = "../embedder_traits", features = ["tests"] }
[target.'cfg(not(target_os = "android"))'.dependencies]
dirs = "1.0"
[target.'cfg(target_os = "android")'.dependencies]
android_injected_glue = "0.2"

View file

@ -6,41 +6,33 @@
//! 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(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")))]
pub fn default_config_dir() -> PathBuf {
pub fn default_config_dir() -> Option<PathBuf> {
let mut config_dir = ::dirs::config_dir().unwrap();
config_dir.push("servo");
config_dir.push("default");
config_dir
Some(config_dir)
}
#[cfg(target_os = "android")]
#[allow(unsafe_code)]
pub fn default_config_dir() -> PathBuf {
let dir = unsafe {
CStr::from_ptr((*android_injected_glue::get_app().activity).externalDataPath)
};
PathBuf::from(dir.to_str().unwrap())
pub fn default_config_dir() -> Option<PathBuf> {
None
}
#[cfg(target_os = "macos")]
pub fn default_config_dir() -> PathBuf {
pub fn default_config_dir() -> Option<PathBuf> {
// FIXME: use `config_dir()` ($HOME/Library/Preferences)
// instead of `data_dir()` ($HOME/Library/Application Support) ?
let mut config_dir = ::dirs::data_dir().unwrap();
config_dir.push("Servo");
config_dir
Some(config_dir)
}
#[cfg(target_os = "windows")]
pub fn default_config_dir() -> PathBuf {
pub fn default_config_dir() -> Option<PathBuf> {
let mut config_dir = ::dirs::config_dir().unwrap();
config_dir.push("Servo");
config_dir
Some(config_dir)
}

View file

@ -4,8 +4,6 @@
#![deny(unsafe_code)]
#[cfg(target_os = "android")]
extern crate android_injected_glue;
#[cfg(not(target_os = "android"))]
extern crate dirs;
extern crate embedder_traits;

View file

@ -183,9 +183,10 @@ pub fn add_user_prefs() {
init_user_prefs(&mut path);
}
None => {
let mut path = default_config_dir();
if path.join("prefs.json").exists() {
init_user_prefs(&mut path);
if let Some(mut path) = default_config_dir() {
if path.join("prefs.json").exists() {
init_user_prefs(&mut path);
}
}
}
}

View file

@ -48,6 +48,7 @@ fn test_get_set_reset_extend() {
assert_eq!(*PREFS.get("extra.stuff"), PrefValue::Boolean(false));
}
#[cfg(not(target_os = "android"))]
#[test]
fn test_default_config_dir_create_read_write() {
let json_str = "{\
@ -56,7 +57,7 @@ fn test_default_config_dir_create_read_write() {
\"shell.homepage\": \"https://google.com\"\
}";
let mut expected_json = String::new();
let config_path = basedir::default_config_dir();
let config_path = basedir::default_config_dir().unwrap();
if !config_path.exists() {
fs::create_dir_all(&config_path).unwrap();