1
1
#![ cfg( feature = "game-activity" ) ]
2
2
3
3
use std:: collections:: HashMap ;
4
- use std:: ffi:: { CStr , CString } ;
5
- use std:: fs:: File ;
6
- use std:: io:: { BufRead , BufReader } ;
7
4
use std:: marker:: PhantomData ;
8
5
use std:: ops:: Deref ;
9
- use std:: os:: unix:: prelude:: * ;
10
6
use std:: panic:: catch_unwind;
7
+ use std:: ptr;
11
8
use std:: ptr:: NonNull ;
12
9
use std:: sync:: Weak ;
13
10
use std:: sync:: { Arc , Mutex , RwLock } ;
14
11
use std:: time:: Duration ;
15
- use std:: { ptr, thread} ;
16
12
17
13
use libc:: c_void;
18
- use log:: { error, trace, Level } ;
14
+ use log:: { error, trace} ;
19
15
20
16
use jni_sys:: * ;
21
17
@@ -29,9 +25,9 @@ use ndk::native_window::NativeWindow;
29
25
use crate :: error:: InternalResult ;
30
26
use crate :: input:: { Axis , KeyCharacterMap , KeyCharacterMapBinding } ;
31
27
use crate :: jni_utils:: { self , CloneJavaVM } ;
32
- use crate :: util:: { abort_on_panic, android_log , log_panic} ;
28
+ use crate :: util:: { abort_on_panic, forward_stdio_to_logcat , log_panic, try_get_path_from_ptr } ;
33
29
use crate :: {
34
- util , AndroidApp , ConfigurationRef , InputStatus , MainEvent , PollEvent , Rect , WindowManagerFlags ,
30
+ AndroidApp , ConfigurationRef , InputStatus , MainEvent , PollEvent , Rect , WindowManagerFlags ,
35
31
} ;
36
32
37
33
mod ffi;
@@ -617,21 +613,21 @@ impl AndroidAppInner {
617
613
pub fn internal_data_path ( & self ) -> Option < std:: path:: PathBuf > {
618
614
unsafe {
619
615
let app_ptr = self . native_app . as_ptr ( ) ;
620
- util :: try_get_path_from_ptr ( ( * ( * app_ptr) . activity ) . internalDataPath )
616
+ try_get_path_from_ptr ( ( * ( * app_ptr) . activity ) . internalDataPath )
621
617
}
622
618
}
623
619
624
620
pub fn external_data_path ( & self ) -> Option < std:: path:: PathBuf > {
625
621
unsafe {
626
622
let app_ptr = self . native_app . as_ptr ( ) ;
627
- util :: try_get_path_from_ptr ( ( * ( * app_ptr) . activity ) . externalDataPath )
623
+ try_get_path_from_ptr ( ( * ( * app_ptr) . activity ) . externalDataPath )
628
624
}
629
625
}
630
626
631
627
pub fn obb_path ( & self ) -> Option < std:: path:: PathBuf > {
632
628
unsafe {
633
629
let app_ptr = self . native_app . as_ptr ( ) ;
634
- util :: try_get_path_from_ptr ( ( * ( * app_ptr) . activity ) . obbPath )
630
+ try_get_path_from_ptr ( ( * ( * app_ptr) . activity ) . obbPath )
635
631
}
636
632
}
637
633
}
@@ -913,33 +909,7 @@ extern "Rust" {
913
909
#[ no_mangle]
914
910
pub unsafe extern "C" fn _rust_glue_entry ( native_app : * mut ffi:: android_app ) {
915
911
abort_on_panic ( || {
916
- // Maybe make this stdout/stderr redirection an optional / opt-in feature?...
917
-
918
- let file = {
919
- let mut logpipe: [ RawFd ; 2 ] = Default :: default ( ) ;
920
- libc:: pipe2 ( logpipe. as_mut_ptr ( ) , libc:: O_CLOEXEC ) ;
921
- libc:: dup2 ( logpipe[ 1 ] , libc:: STDOUT_FILENO ) ;
922
- libc:: dup2 ( logpipe[ 1 ] , libc:: STDERR_FILENO ) ;
923
- libc:: close ( logpipe[ 1 ] ) ;
924
-
925
- File :: from_raw_fd ( logpipe[ 0 ] )
926
- } ;
927
-
928
- thread:: spawn ( move || {
929
- let tag = CStr :: from_bytes_with_nul ( b"RustStdoutStderr\0 " ) . unwrap ( ) ;
930
- let mut reader = BufReader :: new ( file) ;
931
- let mut buffer = String :: new ( ) ;
932
- loop {
933
- buffer. clear ( ) ;
934
- if let Ok ( len) = reader. read_line ( & mut buffer) {
935
- if len == 0 {
936
- break ;
937
- } else if let Ok ( msg) = CString :: new ( buffer. clone ( ) ) {
938
- android_log ( Level :: Info , tag, & msg) ;
939
- }
940
- }
941
- }
942
- } ) ;
912
+ let _join_log_forwarder = forward_stdio_to_logcat ( ) ;
943
913
944
914
let jvm = unsafe {
945
915
let jvm = ( * ( * native_app) . activity ) . vm ;
0 commit comments