aboutsummaryrefslogtreecommitdiffstats
path: root/android-mobile
diff options
context:
space:
mode:
authorGravatar Christof Arnosti <charno@charno.ch>2020-03-14 17:31:51 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-16 07:58:20 -0700
commit779b84bfa02b3e11f295263971a693bef19c3f9e (patch)
tree0f03428bbaa800fbd345a163ef4ae1c92c16fff6 /android-mobile
parenta34a81d120fa2c66522bfcd450003e58dae62d3b (diff)
downloadsubsurface-779b84bfa02b3e11f295263971a693bef19c3f9e.tar.gz
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 <charno@charno.ch> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'android-mobile')
-rw-r--r--android-mobile/AndroidManifest.xml1
-rw-r--r--android-mobile/src/org/subsurfacedivelog/mobile/AndroidSerial.java9
2 files changed, 10 insertions, 0 deletions
diff --git a/android-mobile/AndroidManifest.xml b/android-mobile/AndroidManifest.xml
index bab23a250..578624baf 100644
--- a/android-mobile/AndroidManifest.xml
+++ b/android-mobile/AndroidManifest.xml
@@ -92,6 +92,7 @@
android:normalScreens="true"
android:smallScreens="true" />
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
<!--
The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
Remove the comment if you do not require these default permissions.
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<Byte> readBuffer = new LinkedList<Byte>();
+ private WakeLock wakeLock = null;
private static String printQueue(LinkedList<Byte> 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);