Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ toml = "0.5"
[target.'cfg(target_os="android")'.dependencies]
jni = { version = "0.5", default-features = false }
libc = "0.2"
android_logger = "0.8"
1 change: 1 addition & 0 deletions compile-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if [ $RELEASE ]; then
echo "Building in release mode... (slow)";
else
echo "Building in debug mode... (fast)"
RELEASE=false;
fi

ORIG_PATH="$PATH"
Expand Down
96 changes: 0 additions & 96 deletions src/android/logcat.rs

This file was deleted.

31 changes: 21 additions & 10 deletions src/android/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// Based On the following guide from Mozilla:
// https://mozilla.github.io/firefox-browser-architecture/experiments/2017-09-21-rust-on-android.html

extern crate android_logger;

use std::os::raw::{c_char};
use std::ffi::{CString, CStr};
use std::sync::Mutex;


mod logcat;
use crate::dirs;
use crate::android::logcat::{redirect_stdout_to_logcat};

use log::Level;
use android_logger::Config;


#[no_mangle]
pub extern fn rust_greeting(to: *const c_char) -> *mut c_char {
Expand Down Expand Up @@ -79,10 +82,10 @@ pub mod android {

use crate::endpoints;

println!("Building server state...");
info!("Building server state...");

let asset_path = jstring_to_string(&env, java_asset_path);
println!("Using asset dir: {}", asset_path);
info!("Using asset dir: {}", asset_path);

let server_state = endpoints::ServerState {
datastore: Mutex::new(openDatastore()),
Expand All @@ -101,11 +104,19 @@ pub mod android {
#[no_mangle]
pub unsafe extern fn Java_net_activitywatch_android_RustInterface_initialize(env: JNIEnv, _: JClass) {
if !INITIALIZED {
redirect_stdout_to_logcat();
println!("Initializing aw-server-rust...");
println!("Redirecting aw-server-rust stdout/stderr to logcat");
android_logger::init_once(
Config::default()
.with_min_level(Level::Trace) // limit log level
.with_tag("aw-server-rust") // logs will show under mytag tag
//.with_filter( // configure messages for specific crate
// FilterBuilder::new()
// .parse("debug,hello::crate=error")
// .build())
);
info!("Initializing aw-server-rust...");
debug!("Redirected aw-server-rust stdout/stderr to logcat");
} else {
println!("Already initialized");
info!("Already initialized");
}
INITIALIZED = true;

Expand All @@ -116,7 +127,7 @@ pub mod android {

#[no_mangle]
pub unsafe extern fn Java_net_activitywatch_android_RustInterface_setDataDir(env: JNIEnv, _: JClass, java_dir: JString) {
println!("Setting android data dir");
debug!("Setting android data dir");
dirs::set_android_data_dir(&jstring_to_string(&env, java_dir));
}

Expand Down
2 changes: 1 addition & 1 deletion src/query/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod qfunctions {

pub fn print(args: Vec<DataType>, _env: &HashMap<&str, DataType>, _ds: &Datastore) -> Result<DataType, QueryError> {
for arg in args {
println!("{:?}", arg);
info!("{:?}", arg);
}
return Ok(DataType::None());
}
Expand Down
4 changes: 2 additions & 2 deletions src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn flood(events: Vec<Event>, pulsetime: chrono::Duration) -> Vec<Event> {
if gap < pulsetime {
if e1.data == e2.data {
if chrono::Duration::seconds(0) > gap && !warned_negative_gap_safe {
println!("Gap was of negative duration ({}s), but could be safely merged. This error will only show once per batch.", gap);
warn!("Gap was of negative duration ({}s), but could be safely merged. This error will only show once per batch.", gap);
warned_negative_gap_safe = true;
}
// Extend e1 to the middle between e1 and e2
Expand All @@ -102,7 +102,7 @@ pub fn flood(events: Vec<Event>, pulsetime: chrono::Duration) -> Vec<Event> {
} else {
if chrono::Duration::seconds(0) > gap {
if !warned_negative_gap_unsafe {
println!("Gap was of negative duration ({}s) and could NOT be safely merged. This error will only show once per batch.", gap);
warn!("Gap was of negative duration ({}s) and could NOT be safely merged. This error will only show once per batch.", gap);
warned_negative_gap_unsafe = true;
}
continue;
Expand Down