From 779b84bfa02b3e11f295263971a693bef19c3f9e Mon Sep 17 00:00:00 2001 From: Christof Arnosti Date: Sat, 14 Mar 2020 17:31:51 +0100 Subject: usb-serial-for-android: Use wakelock Android takes some pretty hard measures to save power, including shutting down the CPU. Since this can interfer with the download from an usb serial device, we now use a wakelock to keep the CPU running during download. Signed-off-by: Christof Arnosti Signed-off-by: Dirk Hohndel --- .../src/org/subsurfacedivelog/mobile/AndroidSerial.java | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'android-mobile/src') diff --git a/android-mobile/src/org/subsurfacedivelog/mobile/AndroidSerial.java b/android-mobile/src/org/subsurfacedivelog/mobile/AndroidSerial.java index fa26f065e..c31e79786 100644 --- a/android-mobile/src/org/subsurfacedivelog/mobile/AndroidSerial.java +++ b/android-mobile/src/org/subsurfacedivelog/mobile/AndroidSerial.java @@ -5,6 +5,8 @@ import com.hoho.android.usbserial.driver.*; import android.hardware.usb.UsbDeviceConnection; import android.hardware.usb.UsbManager; import android.hardware.usb.UsbDevice; +import android.os.PowerManager; +import android.os.PowerManager.WakeLock; import android.content.Context; import android.util.Log; @@ -69,6 +71,7 @@ public class AndroidSerial { private UsbSerialPort usbSerialPort; private int timeout = 0; private LinkedList readBuffer = new LinkedList(); + private WakeLock wakeLock = null; private static String printQueue(LinkedList readBuffer) { @@ -83,6 +86,10 @@ public class AndroidSerial { private AndroidSerial(UsbSerialPort usbSerialPort) { this.usbSerialPort = usbSerialPort; + + PowerManager powerManager = (PowerManager) SubsurfaceMobileActivity.getAppContext().getSystemService(Context.POWER_SERVICE); + wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Subsurface::AndroidSerialWakelock"); + wakeLock.acquire(); } public static AndroidSerial open_android_serial(UsbDevice usbDevice, String driverClassName) @@ -320,6 +327,8 @@ public class AndroidSerial { Log.d(TAG, "in " + Thread.currentThread().getStackTrace()[2].getMethodName()); try { usbSerialPort.close(); + if(wakeLock != null) + wakeLock.release(); return AndroidSerial.DC_STATUS_SUCCESS; } catch (Exception e) { Log.e(TAG, "Error in " + Thread.currentThread().getStackTrace()[2].getMethodName(), e); -- cgit v1.2.3-70-g09d2