Skip to content

Commit

Permalink
Android life cycle improvements and Gradle integration
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Apr 21, 2017
1 parent 350d9c6 commit 7a2a909
Show file tree
Hide file tree
Showing 30 changed files with 945 additions and 634 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -24,6 +24,10 @@ Servo.app
# IntelliJ
.idea
*.iws
*.iml

#Gradle
.gradle

# VSCode
.vscode
Expand Down
17 changes: 5 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Expand Up @@ -3,7 +3,6 @@ members = [
"ports/cef",
"ports/geckolib",
"ports/servo",
"support/android/build-apk",
]

[profile.dev]
Expand Down
3 changes: 3 additions & 0 deletions components/config/Cargo.toml
Expand Up @@ -27,3 +27,6 @@ env_logger = "0.4"

[target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))'.dependencies]
xdg = "2.0"

[target.'cfg(target_os = "android")'.dependencies]
android_injected_glue = {git = "https://github.com/mmatyas/android-rs-injected-glue"}
24 changes: 21 additions & 3 deletions components/config/basedir.rs
Expand Up @@ -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;
Expand All @@ -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")))]
Expand All @@ -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")))]
Expand All @@ -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")]
Expand Down
2 changes: 2 additions & 0 deletions components/config/lib.rs
Expand Up @@ -4,6 +4,8 @@

#![deny(unsafe_code)]

#[cfg(target_os = "android")]
extern crate android_injected_glue;
extern crate euclid;
extern crate getopts;
#[macro_use] extern crate lazy_static;
Expand Down
10 changes: 9 additions & 1 deletion components/config/resource_files.rs
Expand Up @@ -2,8 +2,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#[cfg(target_os = "android")]
use android_injected_glue;
#[cfg(not(target_os = "android"))]
use std::env;
#[cfg(target_os = "android")]
use std::ffi::CStr;
use std::fs::File;
use std::io::{self, Read};
use std::path::{Path, PathBuf};
Expand All @@ -21,8 +25,12 @@ pub fn set_resources_path(path: Option<String>) {
}

#[cfg(target_os = "android")]
#[allow(unsafe_code)]
pub fn resources_dir_path() -> io::Result<PathBuf> {
Ok(PathBuf::from("/sdcard/servo/"))
let dir = unsafe {
CStr::from_ptr((*android_injected_glue::get_app().activity).externalDataPath)
};
Ok(PathBuf::from(dir.to_str().unwrap()))
}

#[cfg(not(target_os = "android"))]
Expand Down
4 changes: 2 additions & 2 deletions etc/ci/buildbot_steps.yml
Expand Up @@ -94,15 +94,15 @@ linux-nightly:
android:
- ./mach clean-nightlies --keep 3 --force
- env SERVO_RUSTC_LLVM_ASSERTIONS=1 ./mach build --android --dev
- env SERVO_RUSTC_LLVM_ASSERTIONS=1 ./mach package --android --dev
- env SERVO_RUSTC_LLVM_ASSERTIONS=1 ANDROID_SDK=/home/servo/android/sdk/r25.2.3 ./mach package --android --dev
- bash ./etc/ci/lockfile_changed.sh
- bash ./etc/ci/manifest_changed.sh
- python ./etc/ci/check_dynamic_symbols.py

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

arm32:
Expand Down
8 changes: 0 additions & 8 deletions ports/glutin/window.rs
Expand Up @@ -940,14 +940,6 @@ impl Window {
}
}

// WindowProxy is not implemented for android yet

#[cfg(target_os = "android")]
fn create_window_proxy(_: &Window) -> Option<glutin::WindowProxy> {
None
}

#[cfg(not(target_os = "android"))]
fn create_window_proxy(window: &Window) -> Option<glutin::WindowProxy> {
match window.kind {
WindowKind::Window(ref window) => {
Expand Down
8 changes: 5 additions & 3 deletions ports/servo/main.rs
Expand Up @@ -33,6 +33,7 @@ extern crate sig;
use backtrace::Backtrace;
use servo::Browser;
use servo::compositing::windowing::WindowEvent;
use servo::config;
use servo::config::opts::{self, ArgumentParsingResult};
use servo::config::servo_version;
use std::env;
Expand Down Expand Up @@ -219,8 +220,9 @@ fn args() -> Vec<String> {
use std::fs::File;
use std::io::{BufRead, BufReader};

const PARAMS_FILE: &'static str = "/sdcard/servo/android_params";
match File::open(PARAMS_FILE) {
let mut params_file = config::basedir::default_config_dir().unwrap();
params_file.push("android_params");
match File::open(params_file.to_str().unwrap()) {
Ok(f) => {
let mut vec = Vec::new();
let file = BufReader::new(&f);
Expand All @@ -236,7 +238,7 @@ fn args() -> Vec<String> {
},
Err(e) => {
debug!("Failed to open params file '{}': {}",
PARAMS_FILE,
params_file.to_str().unwrap(),
Error::description(&e));
vec!["servo".to_owned(), "http://en.wikipedia.org/wiki/Rust".to_owned()]
},
Expand Down
31 changes: 4 additions & 27 deletions python/servo/package_commands.py
Expand Up @@ -28,7 +28,6 @@
BuildNotFound,
cd,
CommandBase,
find_dep_path_newest,
is_macosx,
is_windows,
get_browserhtml_path,
Expand Down Expand Up @@ -143,34 +142,12 @@ def package(self, release=False, dev=False, android=None, debug=False, debugger=
target_dir = path.dirname(binary_path)
if android:
if dev:
env["NDK_DEBUG"] = "1"
env["ANT_FLAVOR"] = "debug"
dev_flag = "-d"
task_name = "assembleArmDebug"
else:
env["ANT_FLAVOR"] = "release"
dev_flag = ""

output_apk = "{}.apk".format(binary_path)

dir_to_apk = path.join(target_dir, "apk")
if path.exists(dir_to_apk):
print("Cleaning up from previous packaging")
delete(dir_to_apk)
shutil.copytree(path.join(dir_to_root, "support", "android", "apk"), dir_to_apk)

blurdroid_path = find_dep_path_newest('blurdroid', binary_path)
if blurdroid_path is None:
print("Could not find blurdroid package; perhaps you haven't built Servo.")
return 1
else:
dir_to_libs = path.join(dir_to_apk, "libs")
if not path.exists(dir_to_libs):
os.makedirs(dir_to_libs)
shutil.copy2(blurdroid_path + '/out/blurdroid.jar', dir_to_libs)
task_name = "assembleArmRelease"
try:
with cd(path.join("support", "android", "build-apk")):
subprocess.check_call(["cargo", "run", "--", dev_flag, "-o", output_apk, "-t", target_dir,
"-r", dir_to_root], env=env)
with cd(path.join("support", "android", "apk")):
subprocess.check_call(["./gradlew", "--no-daemon", task_name], env=env)
except subprocess.CalledProcessError as e:
print("Packaging Android exited with return value %d" % e.returncode)
return e.returncode
Expand Down
5 changes: 3 additions & 2 deletions python/servo/post_build_commands.py
Expand Up @@ -83,11 +83,12 @@ def run(self, params, release=False, dev=False, android=None, debug=False, debug
return
script = [
"am force-stop com.mozilla.servo",
"echo servo >/sdcard/servo/android_params"
"echo servo >/sdcard/Android/data/com.mozilla.servo/files/android_params"
]
for param in params:
script += [
"echo '%s' >>/sdcard/servo/android_params" % param.replace("'", "\\'")
"echo '%s' >>/sdcard/Android/data/com.mozilla.servo/files/android_params"
% param.replace("'", "\\'")
]
script += [
"am start com.mozilla.servo/com.mozilla.servo.MainActivity",
Expand Down
2 changes: 2 additions & 0 deletions resources/prefs.json
Expand Up @@ -63,5 +63,7 @@
"session-history.max-length": 20,
"shell.builtin-key-shortcuts.enabled": true,
"shell.homepage": "https://servo.org",
"shell.keep_screen_on.enabled": false,
"shell.native-orientation": "both",
"shell.native-titlebar.enabled": true
}

0 comments on commit 7a2a909

Please sign in to comment.