Skip to content

Commit 7a2a909

Browse files
committed
Android life cycle improvements and Gradle integration
1 parent 350d9c6 commit 7a2a909

30 files changed

Lines changed: 945 additions & 634 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Servo.app
2424
# IntelliJ
2525
.idea
2626
*.iws
27+
*.iml
28+
29+
#Gradle
30+
.gradle
2731

2832
# VSCode
2933
.vscode

Cargo.lock

Lines changed: 5 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ members = [
33
"ports/cef",
44
"ports/geckolib",
55
"ports/servo",
6-
"support/android/build-apk",
76
]
87

98
[profile.dev]

components/config/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ env_logger = "0.4"
2727

2828
[target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))'.dependencies]
2929
xdg = "2.0"
30+
31+
[target.'cfg(target_os = "android")'.dependencies]
32+
android_injected_glue = {git = "https://github.com/mmatyas/android-rs-injected-glue"}

components/config/basedir.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
//! For linux based platforms, it uses the XDG base directory spec but provides
77
//! similar abstractions for non-linux platforms.
88
9+
#[cfg(target_os = "android")]
10+
use android_injected_glue;
911
#[cfg(any(target_os = "macos", target_os = "windows"))]
1012
use std::env;
13+
#[cfg(target_os = "android")]
14+
use std::ffi::CStr;
1115
use std::path::PathBuf;
1216
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
1317
use xdg;
@@ -20,8 +24,12 @@ pub fn default_config_dir() -> Option<PathBuf> {
2024
}
2125

2226
#[cfg(target_os = "android")]
27+
#[allow(unsafe_code)]
2328
pub fn default_config_dir() -> Option<PathBuf> {
24-
Some(PathBuf::from("/sdcard/servo"))
29+
let dir = unsafe {
30+
CStr::from_ptr((*android_injected_glue::get_app().activity).externalDataPath)
31+
};
32+
Some(PathBuf::from(dir.to_str().unwrap()))
2533
}
2634

2735
#[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> {
3240
}
3341

3442
#[cfg(target_os = "android")]
43+
#[allow(unsafe_code)]
3544
pub fn default_data_dir() -> Option<PathBuf> {
36-
Some(PathBuf::from("/sdcard/servo"))
45+
let dir = unsafe {
46+
CStr::from_ptr((*android_injected_glue::get_app().activity).internalDataPath)
47+
};
48+
Some(PathBuf::from(dir.to_str().unwrap()))
3749
}
3850

3951
#[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> {
4456
}
4557

4658
#[cfg(target_os = "android")]
59+
#[allow(unsafe_code)]
4760
pub fn default_cache_dir() -> Option<PathBuf> {
48-
Some(PathBuf::from("/sdcard/servo"))
61+
// TODO: Use JNI to call context.getCacheDir().
62+
// There is no equivalent function in NDK/NativeActivity.
63+
let dir = unsafe {
64+
CStr::from_ptr((*android_injected_glue::get_app().activity).externalDataPath)
65+
};
66+
Some(PathBuf::from(dir.to_str().unwrap()))
4967
}
5068

5169
#[cfg(target_os = "macos")]

components/config/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#![deny(unsafe_code)]
66

7+
#[cfg(target_os = "android")]
8+
extern crate android_injected_glue;
79
extern crate euclid;
810
extern crate getopts;
911
#[macro_use] extern crate lazy_static;

components/config/resource_files.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5+
#[cfg(target_os = "android")]
6+
use android_injected_glue;
57
#[cfg(not(target_os = "android"))]
68
use std::env;
9+
#[cfg(target_os = "android")]
10+
use std::ffi::CStr;
711
use std::fs::File;
812
use std::io::{self, Read};
913
use std::path::{Path, PathBuf};
@@ -21,8 +25,12 @@ pub fn set_resources_path(path: Option<String>) {
2125
}
2226

2327
#[cfg(target_os = "android")]
28+
#[allow(unsafe_code)]
2429
pub fn resources_dir_path() -> io::Result<PathBuf> {
25-
Ok(PathBuf::from("/sdcard/servo/"))
30+
let dir = unsafe {
31+
CStr::from_ptr((*android_injected_glue::get_app().activity).externalDataPath)
32+
};
33+
Ok(PathBuf::from(dir.to_str().unwrap()))
2634
}
2735

2836
#[cfg(not(target_os = "android"))]

etc/ci/buildbot_steps.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ linux-nightly:
9494
android:
9595
- ./mach clean-nightlies --keep 3 --force
9696
- env SERVO_RUSTC_LLVM_ASSERTIONS=1 ./mach build --android --dev
97-
- env SERVO_RUSTC_LLVM_ASSERTIONS=1 ./mach package --android --dev
97+
- env SERVO_RUSTC_LLVM_ASSERTIONS=1 ANDROID_SDK=/home/servo/android/sdk/r25.2.3 ./mach package --android --dev
9898
- bash ./etc/ci/lockfile_changed.sh
9999
- bash ./etc/ci/manifest_changed.sh
100100
- python ./etc/ci/check_dynamic_symbols.py
101101

102102
android-nightly:
103103
- ./mach clean-nightlies --keep 3 --force
104104
- env SERVO_RUSTC_LLVM_ASSERTIONS=1 ./mach build --android --release
105-
- env SERVO_RUSTC_LLVM_ASSERTIONS=1 ./mach package --android --release
105+
- env SERVO_RUSTC_LLVM_ASSERTIONS=1 ANDROID_SDK=/home/servo/android/sdk/r25.2.3 ./mach package --android --release
106106
- ./etc/ci/upload_nightly.sh android
107107

108108
arm32:

ports/glutin/window.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -940,14 +940,6 @@ impl Window {
940940
}
941941
}
942942

943-
// WindowProxy is not implemented for android yet
944-
945-
#[cfg(target_os = "android")]
946-
fn create_window_proxy(_: &Window) -> Option<glutin::WindowProxy> {
947-
None
948-
}
949-
950-
#[cfg(not(target_os = "android"))]
951943
fn create_window_proxy(window: &Window) -> Option<glutin::WindowProxy> {
952944
match window.kind {
953945
WindowKind::Window(ref window) => {

ports/servo/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern crate sig;
3333
use backtrace::Backtrace;
3434
use servo::Browser;
3535
use servo::compositing::windowing::WindowEvent;
36+
use servo::config;
3637
use servo::config::opts::{self, ArgumentParsingResult};
3738
use servo::config::servo_version;
3839
use std::env;
@@ -219,8 +220,9 @@ fn args() -> Vec<String> {
219220
use std::fs::File;
220221
use std::io::{BufRead, BufReader};
221222

222-
const PARAMS_FILE: &'static str = "/sdcard/servo/android_params";
223-
match File::open(PARAMS_FILE) {
223+
let mut params_file = config::basedir::default_config_dir().unwrap();
224+
params_file.push("android_params");
225+
match File::open(params_file.to_str().unwrap()) {
224226
Ok(f) => {
225227
let mut vec = Vec::new();
226228
let file = BufReader::new(&f);
@@ -236,7 +238,7 @@ fn args() -> Vec<String> {
236238
},
237239
Err(e) => {
238240
debug!("Failed to open params file '{}': {}",
239-
PARAMS_FILE,
241+
params_file.to_str().unwrap(),
240242
Error::description(&e));
241243
vec!["servo".to_owned(), "http://en.wikipedia.org/wiki/Rust".to_owned()]
242244
},

0 commit comments

Comments
 (0)