kai-morich / SimpleUsbTerminal

Android terminal app for devices with a serial / UART interface connected with a USB-to-serial-converter
MIT License
529 stars 195 forks source link

foreground service to buffer receive data while the app is in background, #75

Closed skymoomy closed 3 months ago

skymoomy commented 3 months ago

Hi: I need to capture log through the USB device when I operate my phone。So I hope the app can still work in the background。I use this project :SimpleUsbTerminal , and found that When I successfully connected at the beginning, pressed the Home key and my phone displayed a notification,show that the app is still working. However, if the data is being receiving and the Home key is pressed, the notification will not appear, and re entering the APP interface will show the UI of USB Devices, which means i have to re connect my device.

Can this be solved? when the app is in the background, can we continue to maintain port connection and revieve datas from my device (capture logs)?

kai-morich commented 3 months ago

Same question as https://github.com/mik3y/usb-serial-for-android/issues/590 ?

skymoomy commented 3 months ago

Same question as mik3y/usb-serial-for-android#590 ?

I add "receiveText.setText("");" in onPause() ,and the notification will appear after I pressed the Home key. But I still have a question, Can the function onSerialRead receive data when the app is in the background? Or, in other words, how does the app handle data when it is in the background?I

After running the app in the background for a while, I encountered a crash:

08-27 14:51:14.847 30831 30831 I le_usb_terminal: This is non sticky GC, maxfree is 16777216 minfree is 8388608 08-27 14:51:14.847 30831 30831 I le_usb_terminal: Alloc concurrent copying GC freed 10(256B) AllocSpace objects, 0(0B) LOS objects, 24% free, 150MB/198MB, paused 51us,9us total 11.969ms 08-27 14:51:14.847 30831 30831 W le_usb_terminal: Throwing OutOfMemoryError "Failed to allocate a 122340496 byte allocation with 50331648 free bytes and 105MB until OOM, target footprint 207698616, growth limit 268435456" (VmSize 7110420 kB) 08-27 14:51:14.848 30831 30831 D AndroidRuntime: Shutting down VM --------- beginning of crash 08-27 14:51:14.849 30831 30831 E AndroidRuntime: FATAL EXCEPTION: main 08-27 14:51:14.849 30831 30831 E AndroidRuntime: Process: de.kai_morich.simple_usb_terminal, PID: 30831 08-27 14:51:14.849 30831 30831 E AndroidRuntime: java.lang.OutOfMemoryError: Failed to allocate a 122340496 byte allocation with 50331648 free bytes and 105MB until OOM, target footprint 207698616, growth limit 268435456

skymoomy commented 3 months ago

Referring to the SimpleUsbTerminal project, I implemented the function of running log scraping in the background by integrating the code of the SimpleUsbTerminal project into the USB serial for android project 。