summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2016-12-11 10:43:53 -0500
committerGitHub <noreply@github.com>2016-12-11 10:43:53 -0500
commit77a2be92877a040f7531e06b7cc50048a2d9738f (patch)
tree79ac7a0dfa762873cce83fc0f30b82b51dfb90c5
parentf94f227db3b7c96fa453108b0a209ac22838e354 (diff)
parent30af19cd17231b8cca2a2c18589d0468f15778f4 (diff)
downloadsdl_android-77a2be92877a040f7531e06b7cc50048a2d9738f.tar.gz
Merge pull request #367 from smartdevicelink/bugfix/issue_347
Fix continuous proxy cycle after AOA usb disconnect occurs
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/USBTransport.java77
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/USBTransportConfig.java18
2 files changed, 65 insertions, 30 deletions
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/USBTransport.java b/sdl_android_lib/src/com/smartdevicelink/transport/USBTransport.java
index 2f2091e5b..f1d221bf3 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/USBTransport.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/USBTransport.java
@@ -19,10 +19,7 @@ import com.smartdevicelink.exception.SdlException;
import com.smartdevicelink.exception.SdlExceptionCause;
import com.smartdevicelink.protocol.SdlPacket;
import com.smartdevicelink.trace.SdlTrace;
-import com.smartdevicelink.trace.enums.InterfaceActivityDirection;
-import com.smartdevicelink.transport.ITransportListener;
-import com.smartdevicelink.transport.SdlTransport;
-import com.smartdevicelink.transport.SiphonServer;
+import com.smartdevicelink.trace.enums.InterfaceActivityDirection;
import com.smartdevicelink.transport.enums.TransportType;
import com.smartdevicelink.util.DebugTool;
@@ -37,7 +34,10 @@ import com.smartdevicelink.util.DebugTool;
*/
@SuppressLint("NewApi")
public class USBTransport extends SdlTransport {
- /**
+
+ // Boolean to monitor if the transport is in a disconnecting state
+ private boolean _disconnecting = false;
+ /**
* Broadcast action: sent when a USB accessory is attached.
*
* UsbManager.EXTRA_ACCESSORY extra contains UsbAccessory object that has
@@ -278,7 +278,6 @@ public class USBTransport extends SdlTransport {
filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
filter.addAction(ACTION_USB_PERMISSION);
getContext().registerReceiver(mUSBReceiver, filter);
-
initializeAccessory();
} catch (Exception e) {
String msg = "Couldn't start opening connection";
@@ -353,6 +352,14 @@ public class USBTransport extends SdlTransport {
* @param ex Disconnect exception, if any
*/
private void disconnect(String msg, Exception ex) {
+
+ // If already disconnecting, return
+ if (_disconnecting) {
+ // No need to recursively call
+ return;
+ }
+ _disconnecting = true;
+
final State state = getState();
switch (state) {
case LISTENING:
@@ -372,6 +379,7 @@ public class USBTransport extends SdlTransport {
if (mOutputStream != null) {
try {
mOutputStream.close();
+ mOutputStream = null;
} catch (IOException e) {
logW("Can't close output stream", e);
mOutputStream = null;
@@ -380,6 +388,7 @@ public class USBTransport extends SdlTransport {
if (mInputStream != null) {
try {
mInputStream.close();
+ mInputStream = null;
} catch (IOException e) {
logW("Can't close input stream", e);
mInputStream = null;
@@ -388,6 +397,7 @@ public class USBTransport extends SdlTransport {
if (mParcelFD != null) {
try {
mParcelFD.close();
+ mParcelFD = null;
} catch (IOException e) {
logW("Can't close file descriptor", e);
mParcelFD = null;
@@ -428,6 +438,7 @@ public class USBTransport extends SdlTransport {
"; doing nothing");
break;
}
+ _disconnecting = false;
}
/**
@@ -440,31 +451,34 @@ public class USBTransport extends SdlTransport {
public TransportType getTransportType() {
return TransportType.USB;
}
-
+
/**
* Looks for an already connected compatible accessory and connect to it.
*/
private void initializeAccessory() {
- logI("Looking for connected accessories");
+ if (!mConfig.getQueryUsbAcc()){
+ logI("Query for accessory is disabled.");
+ return;
+ }
+ logI("Looking for connected accessories");
UsbAccessory acc = mConfig.getUsbAccessory();
- if(acc == null || !isAccessorySupported(acc)){ //Check to see if our config included an accessory and that it is supported. If not, see if there are any other accessories connected.
- UsbManager usbManager = getUsbManager();
- UsbAccessory[] accessories = usbManager.getAccessoryList();
- if (accessories != null) {
- logD("Found total " + accessories.length + " accessories");
- for (UsbAccessory accessory : accessories) {
- if (isAccessorySupported(accessory)) {
- acc = accessory;
- break;
- }
- }
- } else {
- logI("No connected accessories found");
- return;
- }
- }
-
- connectToAccessory(acc);
+ if( acc == null || !isAccessorySupported(acc)){ //Check to see if our config included an accessory and that it is supported. If not, see if there are any other accessories connected.
+ UsbManager usbManager = getUsbManager();
+ UsbAccessory[] accessories = usbManager.getAccessoryList();
+ if (accessories != null) {
+ logD("Found total " + accessories.length + " accessories");
+ for (UsbAccessory accessory : accessories) {
+ if (isAccessorySupported(accessory)) {
+ acc = accessory;
+ break;
+ }
+ }
+ } else {
+ logI("No connected accessories found");
+ return;
+ }
+ }
+ connectToAccessory(acc);
}
/**
@@ -647,7 +661,7 @@ public class USBTransport extends SdlTransport {
* Internal task that connects to and reads data from a USB accessory.
*
* Since the class has to have access to the parent class' variables,
- * sdlhronization must be taken in consideration! For now, all access
+ * synchronization must be taken in consideration! For now, all access
* to variables of USBTransport must be surrounded with
* synchronized (USBTransport.this) { … }
*/
@@ -728,8 +742,8 @@ public class USBTransport extends SdlTransport {
}
logI("Accessory opened!");
-
- synchronized (USBTransport.this) {
+
+ synchronized (USBTransport.this) {
setState(State.CONNECTED);
handleTransportConnected();
}
@@ -758,7 +772,10 @@ public class USBTransport extends SdlTransport {
// read loop
while (!isInterrupted()) {
try {
- bytesRead = mInputStream.read(buffer);
+ if (mInputStream == null)
+ continue;
+
+ bytesRead = mInputStream.read(buffer);
if (bytesRead == -1) {
if (isInterrupted()) {
logI("EOF reached, and thread is interrupted");
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/USBTransportConfig.java b/sdl_android_lib/src/com/smartdevicelink/transport/USBTransportConfig.java
index 0309753a9..7e6e416ee 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/USBTransportConfig.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/USBTransportConfig.java
@@ -9,6 +9,7 @@ public class USBTransportConfig extends BaseTransportConfig {
private Context mainActivity = null;
private UsbAccessory usbAccessory = null;
+ private Boolean queryUsbAcc = true;
public USBTransportConfig (Context mainActivity) {
this.mainActivity = mainActivity;
@@ -19,6 +20,23 @@ public class USBTransportConfig extends BaseTransportConfig {
this.usbAccessory = usbAccessory;
}
+ public USBTransportConfig (Context mainActivity, boolean shareConnection, boolean queryUsbAcc) {
+ this.mainActivity = mainActivity;
+ this.queryUsbAcc = queryUsbAcc;
+ super.shareConnection = shareConnection;
+ }
+
+ public USBTransportConfig (Context mainActivity, UsbAccessory usbAccessory, boolean shareConnection, boolean queryUsbAcc) {
+ this.mainActivity = mainActivity;
+ this.queryUsbAcc = queryUsbAcc;
+ this.usbAccessory = usbAccessory;
+ super.shareConnection = shareConnection;
+ }
+
+ public Boolean getQueryUsbAcc () {
+ return queryUsbAcc;
+ }
+
public Context getUSBContext () {
return mainActivity;
}