mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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>
This commit is contained in:
parent
a34a81d120
commit
779b84bfa0
2 changed files with 10 additions and 0 deletions
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue