From 60880311dc564295445507798c6a2bede0c42241 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 16 Oct 2021 15:31:24 -0700 Subject: [PATCH] Android: use more recent usb library Builds start to fail because v2.2.2 (about 18 months old) can't be found anymore. Let's switch to the latest and see if that helps. Some of the interfaces changed in the Java library and our code had to be adjusted to accomodate this. Signed-off-by: Dirk Hohndel --- android-mobile/build.gradle | 7 ++++++- .../org/subsurfacedivelog/mobile/AndroidSerial.java | 12 +++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/android-mobile/build.gradle b/android-mobile/build.gradle index f55c805cb..4ea834941 100644 --- a/android-mobile/build.gradle +++ b/android-mobile/build.gradle @@ -28,7 +28,7 @@ apply plugin: 'com.android.application' dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.github.mik3y:usb-serial-for-android:v2.2.2' + implementation 'com.github.mik3y:usb-serial-for-android:v3.4.3' } android { @@ -62,6 +62,11 @@ android { } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + lintOptions { abortOnError false } diff --git a/android-mobile/src/org/subsurfacedivelog/mobile/AndroidSerial.java b/android-mobile/src/org/subsurfacedivelog/mobile/AndroidSerial.java index c31e79786..be91cb2e3 100644 --- a/android-mobile/src/org/subsurfacedivelog/mobile/AndroidSerial.java +++ b/android-mobile/src/org/subsurfacedivelog/mobile/AndroidSerial.java @@ -298,9 +298,10 @@ public class AndroidSerial { Log.d(TAG, "in " + Thread.currentThread().getStackTrace()[2].getMethodName()); try { Log.d(TAG, "write length: " + data.length); - int retval = usbSerialPort.write(data, timeout); - Log.d(TAG, "actual write length: " + retval); - return retval; + usbSerialPort.write(data, timeout); + /* throws an exception if we didn't write all data successfully */ + Log.d(TAG, "successfully written"); + return data.length; } catch (Exception e) { Log.e(TAG, "Error in " + Thread.currentThread().getStackTrace()[2].getMethodName(), e); return AndroidSerial.DC_STATUS_IO; @@ -313,8 +314,9 @@ public class AndroidSerial { Log.d(TAG, "in " + Thread.currentThread().getStackTrace()[2].getMethodName()); try { if ((direction | AndroidSerial.DC_DIRECTION_INPUT) > 0) readBuffer.clear(); - boolean retval = this.usbSerialPort.purgeHwBuffers((direction | AndroidSerial.DC_DIRECTION_OUTPUT) > 0, (direction | AndroidSerial.DC_DIRECTION_INPUT) > 0); - return retval ? AndroidSerial.DC_STATUS_SUCCESS : AndroidSerial.DC_STATUS_IO; + this.usbSerialPort.purgeHwBuffers((direction | AndroidSerial.DC_DIRECTION_OUTPUT) > 0, (direction | AndroidSerial.DC_DIRECTION_INPUT) > 0); + /* throws exeption if an error occured or flush isn't supported */ + return AndroidSerial.DC_STATUS_SUCCESS; } catch (Exception e) { Log.e(TAG, "Error in " + Thread.currentThread().getStackTrace()[2].getMethodName(), e); return AndroidSerial.DC_STATUS_IO;