11#![ cfg( feature = "game-activity" ) ]
22
33use std:: collections:: HashMap ;
4- use std:: ffi:: { CStr , CString } ;
5- use std:: fs:: File ;
6- use std:: io:: { BufRead , BufReader } ;
74use std:: marker:: PhantomData ;
85use std:: ops:: Deref ;
9- use std:: os:: unix:: prelude:: * ;
106use std:: panic:: catch_unwind;
7+ use std:: ptr;
118use std:: ptr:: NonNull ;
129use std:: sync:: Weak ;
1310use std:: sync:: { Arc , Mutex , RwLock } ;
1411use std:: time:: Duration ;
15- use std:: { ptr, thread} ;
1612
1713use libc:: c_void;
18- use log:: { error, trace, Level } ;
14+ use log:: { error, trace} ;
1915
2016use jni_sys:: * ;
2117
@@ -29,9 +25,9 @@ use ndk::native_window::NativeWindow;
2925use crate :: error:: InternalResult ;
3026use crate :: input:: { Axis , KeyCharacterMap , KeyCharacterMapBinding } ;
3127use 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 } ;
3329use crate :: {
34- util , AndroidApp , ConfigurationRef , InputStatus , MainEvent , PollEvent , Rect , WindowManagerFlags ,
30+ AndroidApp , ConfigurationRef , InputStatus , MainEvent , PollEvent , Rect , WindowManagerFlags ,
3531} ;
3632
3733mod ffi;
@@ -617,21 +613,21 @@ impl AndroidAppInner {
617613 pub fn internal_data_path ( & self ) -> Option < std:: path:: PathBuf > {
618614 unsafe {
619615 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 )
621617 }
622618 }
623619
624620 pub fn external_data_path ( & self ) -> Option < std:: path:: PathBuf > {
625621 unsafe {
626622 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 )
628624 }
629625 }
630626
631627 pub fn obb_path ( & self ) -> Option < std:: path:: PathBuf > {
632628 unsafe {
633629 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 )
635631 }
636632 }
637633}
@@ -913,36 +909,7 @@ extern "Rust" {
913909#[ no_mangle]
914910pub unsafe extern "C" fn _rust_glue_entry ( native_app : * mut ffi:: android_app ) {
915911 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:: Builder :: new ( )
929- . name ( "stdio-to-logcat" . to_string ( ) )
930- . spawn ( move || {
931- let tag = CStr :: from_bytes_with_nul ( b"RustStdoutStderr\0 " ) . unwrap ( ) ;
932- let mut reader = BufReader :: new ( file) ;
933- let mut buffer = String :: new ( ) ;
934- loop {
935- buffer. clear ( ) ;
936- if let Ok ( len) = reader. read_line ( & mut buffer) {
937- if len == 0 {
938- break ;
939- } else if let Ok ( msg) = CString :: new ( buffer. clone ( ) ) {
940- android_log ( Level :: Info , tag, & msg) ;
941- }
942- }
943- }
944- } )
945- . unwrap ( ) ;
912+ let _join_log_forwarder = forward_stdio_to_logcat ( ) ;
946913
947914 let jvm = unsafe {
948915 let jvm = ( * ( * native_app) . activity ) . vm ;
0 commit comments