summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett <3911458+BrettyWhite@users.noreply.github.com>2019-10-01 13:31:49 -0400
committerGitHub <noreply@github.com>2019-10-01 13:31:49 -0400
commitf0135859b139cc8db3b8cc4d791936ff6b507fa0 (patch)
treeebbe0695395562c98cade4216416ae6f3c92025c
parent91524a90b93177995a1fc1080f3958c926188688 (diff)
parentc8175d836ab69e4786dbedc530457276e0e76919 (diff)
downloadsdl_android-f0135859b139cc8db3b8cc4d791936ff6b507fa0.tar.gz
Merge pull request #1177 from smartdevicelink/bugfix/issue_1086
Add safeguards for null usbAccessory
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/USBAccessoryAttachmentActivity.java28
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/USBTransport.java73
2 files changed, 57 insertions, 44 deletions
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBAccessoryAttachmentActivity.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBAccessoryAttachmentActivity.java
index 878715147..b724377ed 100644
--- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBAccessoryAttachmentActivity.java
+++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBAccessoryAttachmentActivity.java
@@ -103,7 +103,7 @@ public class USBAccessoryAttachmentActivity extends Activity {
@Override
protected void onResume() {
super.onResume();
- checkUsbAccessoryIntent("Resume");
+ checkUsbAccessoryIntent();
}
@Override
@@ -112,13 +112,13 @@ public class USBAccessoryAttachmentActivity extends Activity {
this.setIntent(intent);
}
- private synchronized void checkUsbAccessoryIntent(String sourceAction) {
+ private synchronized void checkUsbAccessoryIntent() {
if(usbAccessory != null){
return;
}
final Intent intent = getIntent();
String action = intent.getAction();
- Log.d(TAG, sourceAction + " with action: " + action);
+ Log.d(TAG, "Received intent with action: " + action);
if (UsbManager.ACTION_USB_ACCESSORY_ATTACHED.equals(action)) {
usbAccessory = intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
@@ -157,7 +157,7 @@ public class USBAccessoryAttachmentActivity extends Activity {
// The most optimal router service doesn't support the USB connection
// At this point to ensure that USB connection is still possible it might be
// worth trying to use the legacy USB transport scheme
- attemptLegacyUsbConnection();
+ attemptLegacyUsbConnection(usbAccessory);
return;
}
@@ -168,7 +168,7 @@ public class USBAccessoryAttachmentActivity extends Activity {
Log.d(TAG, "WARNING: This application has not specified its SdlRouterService correctly in the manifest. THIS WILL THROW AN EXCEPTION IN FUTURE RELEASES!!");
// At this point to ensure that USB connection is still possible it might be
// worth trying to use the legacy USB transport scheme
- attemptLegacyUsbConnection();
+ attemptLegacyUsbConnection(usbAccessory);
return;
}
serviceIntent.setAction(TransportConstants.BIND_REQUEST_TYPE_ALT_TRANSPORT);
@@ -185,7 +185,7 @@ public class USBAccessoryAttachmentActivity extends Activity {
if(startedService == null){
// A router service was not started or is not running.
DebugTool.logError(TAG + " - Error starting router service. Attempting legacy connection ");
- attemptLegacyUsbConnection();
+ attemptLegacyUsbConnection(usbAccessory);
return;
}
@@ -224,12 +224,16 @@ public class USBAccessoryAttachmentActivity extends Activity {
});
}
- private void attemptLegacyUsbConnection(){
- DebugTool.logInfo("Attempting to send USB connection intent using legacy method");
- Intent usbAccessoryAttachedIntent = new Intent(USBTransport.ACTION_USB_ACCESSORY_ATTACHED);
- usbAccessoryAttachedIntent.putExtra(UsbManager.EXTRA_ACCESSORY, usbAccessory);
- usbAccessoryAttachedIntent.putExtra(UsbManager.EXTRA_PERMISSION_GRANTED, permissionGranted);
- AndroidTools.sendExplicitBroadcast(getApplicationContext(),usbAccessoryAttachedIntent,null);
+ private void attemptLegacyUsbConnection(UsbAccessory usbAccessory){
+ if(usbAccessory != null) {
+ DebugTool.logInfo("Attempting to send USB connection intent using legacy method");
+ Intent usbAccessoryAttachedIntent = new Intent(USBTransport.ACTION_USB_ACCESSORY_ATTACHED);
+ usbAccessoryAttachedIntent.putExtra(UsbManager.EXTRA_ACCESSORY, usbAccessory);
+ usbAccessoryAttachedIntent.putExtra(UsbManager.EXTRA_PERMISSION_GRANTED, permissionGranted);
+ AndroidTools.sendExplicitBroadcast(getApplicationContext(), usbAccessoryAttachedIntent, null);
+ }else{
+ DebugTool.logError("Unable to start legacy USB mode as the accessory was null");
+ }
finish();
}
}
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBTransport.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBTransport.java
index 03e0fbb59..698396ae1 100644
--- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBTransport.java
+++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBTransport.java
@@ -1,34 +1,34 @@
-/*
- * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
+/*
+ * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
package com.smartdevicelink.transport;
import android.annotation.SuppressLint;
@@ -529,7 +529,11 @@ public class USBTransport extends SdlTransport {
* @param accessory Accessory to check
* @return true if the accessory is right
*/
- public static boolean isAccessorySupported(UsbAccessory accessory) {
+ public static boolean isAccessorySupported(final UsbAccessory accessory) {
+ if (accessory == null) {
+ return false;
+ }
+
boolean manufacturerMatches =
ACCESSORY_MANUFACTURER.equals(accessory.getManufacturer());
boolean modelMatches = ACCESSORY_MODEL.equals(accessory.getModel());
@@ -547,6 +551,11 @@ public class USBTransport extends SdlTransport {
* @param accessory Accessory to connect to
*/
private void connectToAccessory(UsbAccessory accessory) {
+
+ if (accessory == null) {
+ handleTransportError("Can't connect to null accessory", null);
+ }
+
final State state = getState();
switch (state) {
case LISTENING: