summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2020-08-28 11:41:45 -0400
committerJoey Grover <joeygrover@gmail.com>2020-08-28 11:41:45 -0400
commit17b352a54bec89bba496e9ef19a432b3e3b9e9f1 (patch)
treec90336dfd445f4013d7435f393e7f684848d13e6
parentea2de3df25e84f9861a1e459ece8850900bea465 (diff)
downloadsdl_android-feature/remove_old_transport_classes.tar.gz
Remove old transport classesfeature/remove_old_transport_classes
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/AbstractPacketizerTests.java2
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/StreamPacketizerTests.java2
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/transport/BTTransportConfigTests.java43
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java22
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java17
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/BTTransportConfig.java71
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java4
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlTransport.java154
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/TCPTransport.java557
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/USBAccessoryAttachmentActivity.java2
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/USBTransport.java915
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/USBTransportConfig.java135
-rw-r--r--base/src/main/java/com/smartdevicelink/transport/ITransportListener.java48
-rw-r--r--base/src/main/java/com/smartdevicelink/transport/TransportConstants.java10
14 files changed, 13 insertions, 1969 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/AbstractPacketizerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/AbstractPacketizerTests.java
index e5e47f3a5..28b1520d2 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/AbstractPacketizerTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/AbstractPacketizerTests.java
@@ -5,8 +5,6 @@ import com.smartdevicelink.protocol.enums.SessionType;
import com.smartdevicelink.proxy.RPCRequest;
import com.smartdevicelink.streaming.IStreamListener;
import com.smartdevicelink.test.TestValues;
-import com.smartdevicelink.transport.BTTransportConfig;
-import com.smartdevicelink.transport.BaseTransportConfig;
import com.smartdevicelink.transport.MultiplexTransportConfig;
import com.smartdevicelink.util.Version;
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/StreamPacketizerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/StreamPacketizerTests.java
index 736798d67..bf6f6a850 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/StreamPacketizerTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/StreamPacketizerTests.java
@@ -7,8 +7,6 @@ import com.smartdevicelink.proxy.interfaces.IVideoStreamListener;
import com.smartdevicelink.streaming.IStreamListener;
import com.smartdevicelink.streaming.StreamPacketizer;
import com.smartdevicelink.test.TestValues;
-import com.smartdevicelink.transport.BTTransportConfig;
-import com.smartdevicelink.transport.BaseTransportConfig;
import com.smartdevicelink.transport.MultiplexTransportConfig;
import junit.framework.TestCase;
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/transport/BTTransportConfigTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/transport/BTTransportConfigTests.java
deleted file mode 100644
index edb932f62..000000000
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/transport/BTTransportConfigTests.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.smartdevicelink.test.transport;
-
-import com.smartdevicelink.test.TestValues;
-import com.smartdevicelink.transport.BTTransportConfig;
-import com.smartdevicelink.transport.enums.TransportType;
-
-import junit.framework.TestCase;
-
-/**
- * This is a unit test class for the SmartDeviceLink library project class :
- * {@link com.smartdevicelink.transport.BtTransportConfig}
- */
-public class BTTransportConfigTests extends TestCase {
-
- /**
- * This is a unit test for the following methods :
- * {@link com.smartdevicelink.transport.BtTransportConfig#getTransportType()}
- * {@link com.smartdevicelink.transport.BtTransportConfig#setKeepSocketActive(boolean)}
- * {@link com.smartdevicelink.transport.BtTransportConfig#getKeepSocketActive}
- */
- public void testConfigs () {
-
- // Test Values
- boolean testBoolean = true;
- BTTransportConfig testConfig1 = new BTTransportConfig();
- BTTransportConfig testConfig2 = new BTTransportConfig(testBoolean);
-
- // Comparison Values
- TransportType expectedTransportType = TransportType.BLUETOOTH;
- boolean actualShareConnection = testConfig2.shareConnection();
- TransportType actualTransportType = testConfig1.getTransportType();
-
- // Valid Tests
- assertEquals(TestValues.MATCH, expectedTransportType, actualTransportType);
- assertTrue(TestValues.TRUE, actualShareConnection);
-
-
- testConfig1.setKeepSocketActive(true);
- assertTrue(TestValues.TRUE, testConfig1.getKeepSocketActive());
- testConfig1.setKeepSocketActive(false);
- assertFalse(TestValues.FALSE, testConfig1.getKeepSocketActive());
- }
-} \ No newline at end of file
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java
index 6f4f0231b..075f89a81 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java
@@ -6,7 +6,6 @@ import android.os.Looper;
import android.os.Message;
import androidx.test.ext.junit.runners.AndroidJUnit4;
-import com.smartdevicelink.protocol.SdlPacket;
import org.junit.Before;
import org.junit.Test;
@@ -15,13 +14,11 @@ import org.junit.runner.RunWith;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
-import static junit.framework.TestCase.assertTrue;
@RunWith(AndroidJUnit4.class)
public class MultiplexTransportTest {
RouterServiceValidator rsvp;
- ITransportListener transportListener;
@Before
@@ -29,26 +26,7 @@ public class MultiplexTransportTest {
rsvp = new RouterServiceValidator(getInstrumentation().getTargetContext());
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_NONE);
rsvp.validate();
-
- transportListener = new ITransportListener(){
-
- @Override
- public void onTransportPacketReceived(SdlPacket packet) {
- }
-
- @Override
- public void onTransportConnected() {
- }
-
- @Override
- public void onTransportDisconnected(String info) {
- }
- @Override
- public void onTransportError(String info, Exception e) {
- }
-
- };
}
// test for setting error state.
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java
index 73757292b..2fe65b2fc 100644
--- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java
+++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java
@@ -48,7 +48,6 @@ import com.smartdevicelink.streaming.video.VideoStreamingParameters;
import com.smartdevicelink.transport.BaseTransportConfig;
import com.smartdevicelink.transport.MultiplexTransportConfig;
import com.smartdevicelink.transport.TCPTransportConfig;
-import com.smartdevicelink.transport.USBTransportConfig;
import com.smartdevicelink.transport.enums.TransportType;
import com.smartdevicelink.util.DebugTool;
@@ -76,22 +75,6 @@ public class LifecycleManager extends BaseLifecycleManager {
void initialize() {
super.initialize();
- //Handle legacy USB connections
- if (_transportConfig != null && TransportType.USB.equals(_transportConfig.getTransportType())) {
- //A USB transport config was provided
- USBTransportConfig usbTransportConfig = (USBTransportConfig) _transportConfig;
- if (usbTransportConfig.getUsbAccessory() == null) {
- DebugTool.logInfo(TAG,"Legacy USB transport config was used, but received null for accessory. Attempting to connect with router service");
- //The accessory was null which means it came from a router service
- MultiplexTransportConfig multiplexTransportConfig = new MultiplexTransportConfig(usbTransportConfig.getUSBContext(), appConfig.getAppID());
- multiplexTransportConfig.setRequiresHighBandwidth(true);
- multiplexTransportConfig.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_OFF);
- multiplexTransportConfig.setPrimaryTransports(Collections.singletonList(TransportType.USB));
- multiplexTransportConfig.setSecondaryTransports(new ArrayList<TransportType>());
- _transportConfig = multiplexTransportConfig;
- }
- }
-
if (_transportConfig != null && _transportConfig.getTransportType().equals(TransportType.MULTIPLEX)) {
this.session = new SdlSession(sdlSessionListener, (MultiplexTransportConfig) _transportConfig);
} else if (_transportConfig != null && _transportConfig.getTransportType().equals(TransportType.TCP)) {
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/BTTransportConfig.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/BTTransportConfig.java
deleted file mode 100644
index 3b4123b3a..000000000
--- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/BTTransportConfig.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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 com.smartdevicelink.transport.enums.TransportType;
-
-/**
- * Container of Bluetooth transport specific configuration.
- */
-@Deprecated
-public final class BTTransportConfig extends BaseTransportConfig {
-
- private boolean bKeepSocketActive = true;
-
- /**
- * Overridden abstract method which returns specific type of this transport configuration.
- *
- * @return Constant value TransportType.BLUETOOTH.
- *
- * @see TransportType
- */
- public TransportType getTransportType() {
- return TransportType.BLUETOOTH;
- }
-
- public BTTransportConfig() {
- this(true);
- }
-
- public BTTransportConfig(boolean shareConnection) {
- super.shareConnection = shareConnection;
- }
-
- public void setKeepSocketActive(boolean bValue) {
- bKeepSocketActive = bValue;
- }
-
- public boolean getKeepSocketActive() {
- return bKeepSocketActive;
- }
-
-}
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java
index 4ed1b85f4..1ad6a3e9a 100644
--- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java
+++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java
@@ -113,14 +113,14 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{
}
if(!(action.equalsIgnoreCase(BluetoothDevice.ACTION_ACL_CONNECTED)
- || action.equalsIgnoreCase(USBTransport.ACTION_USB_ACCESSORY_ATTACHED)
+ || action.equalsIgnoreCase(TransportConstants.ACTION_USB_ACCESSORY_ATTACHED)
|| action.equalsIgnoreCase(TransportConstants.START_ROUTER_SERVICE_ACTION))){
//We don't want anything else here if the child class called super and has different intent filters
//Log.i(TAG, "Unwanted intent from child class");
return;
}
- if(action.equalsIgnoreCase(USBTransport.ACTION_USB_ACCESSORY_ATTACHED)){
+ if(action.equalsIgnoreCase(TransportConstants.ACTION_USB_ACCESSORY_ATTACHED)){
DebugTool.logInfo(TAG,"Usb connected");
intent.setAction(null);
onSdlEnabled(context, intent);
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlTransport.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlTransport.java
deleted file mode 100644
index 32fe26fee..000000000
--- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlTransport.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * 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 com.smartdevicelink.exception.SdlException;
-import com.smartdevicelink.protocol.SdlPacket;
-import com.smartdevicelink.trace.SdlTrace;
-import com.smartdevicelink.trace.enums.InterfaceActivityDirection;
-import com.smartdevicelink.transport.enums.TransportType;
-import com.smartdevicelink.util.DebugTool;
-
-public abstract class SdlTransport {
- private static final String TAG = "SdlTransport";
- private static final String SDL_LIB_TRACE_KEY = "42baba60-eb57-11df-98cf-0800200c9a66";
-
- private final static String FailurePropagating_Msg = "Failure propagating ";
- private Boolean isConnected = false;
-
- private String _sendLockObj = "lock";
-
-
- // Get status of transport connection
- public Boolean getIsConnected() {
- return isConnected;
- }
-
- //protected SdlTransport(String endpointName, String param2, ITransportListener transportListener)
- protected SdlTransport(ITransportListener transportListener) {
- if (transportListener == null) {
- throw new IllegalArgumentException("Provided transport listener interface reference is null");
- } // end-if
- _transportListener = transportListener;
- } // end-method
-
- // This method is called by the subclass to indicate that data has arrived from
- // the transport.
- protected void handleReceivedPacket(SdlPacket packet) {
- try {
- // Trace received data
- if (packet!=null) {
- // Send transport data to the siphon server
- //FIXME SiphonServer.sendBytesFromSDL(receivedBytes, 0, receivedBytesLength);
- //SdlTrace.logTransportEvent("", null, InterfaceActivityDirection.Receive, receivedBytes, receivedBytesLength, SDL_LIB_TRACE_KEY);
-
- _transportListener.onTransportPacketReceived(packet);
- } // end-if
- } catch (Exception excp) {
- DebugTool.logError(TAG, FailurePropagating_Msg + "handleBytesFromTransport: " + excp.toString(), excp);
- handleTransportError(FailurePropagating_Msg, excp);
- } // end-catch
- } // end-method
-
- // This method must be implemented by transport subclass, and is called by this
- // base class to actually send an array of bytes out over the transport. This
- // method is meant to only be callable within the class hierarchy.
- protected abstract boolean sendBytesOverTransport(SdlPacket packet);
-
- // This method is called by whomever has reference to transport to have bytes
- // sent out over transport.
- /* public boolean sendBytes(byte[] message) {
- return sendBytes(message, 0, message.length);
- }*/ // end-method
-
- // This method is called by whomever has reference to transport to have bytes
- // sent out over transport.
- public boolean sendBytes(SdlPacket packet) {
- boolean bytesWereSent = false;
- synchronized (_sendLockObj) {
- bytesWereSent = sendBytesOverTransport(packet);//message, offset, length);
- } // end-lock
- // Send transport data to the siphon server
- //FIXME SiphonServer.sendBytesFromAPP(message, offset, length);
-
- //FIXME SdlTrace.logTransportEvent("", null, InterfaceActivityDirection.Transmit, message, offset, length, SDL_LIB_TRACE_KEY);
- return bytesWereSent;
- } // end-method
-
- private ITransportListener _transportListener = null;
-
- // This method is called by the subclass to indicate that transport connection
- // has been established.
- protected void handleTransportConnected() {
- isConnected = true;
- try {
- SdlTrace.logTransportEvent("Transport.connected", null, InterfaceActivityDirection.Receive, null, 0, SDL_LIB_TRACE_KEY);
- _transportListener.onTransportConnected();
- } catch (Exception excp) {
- DebugTool.logError(TAG, FailurePropagating_Msg + "onTransportConnected: " + excp.toString(), excp);
- handleTransportError(FailurePropagating_Msg + "onTransportConnected", excp);
- } // end-catch
- } // end-method
-
- // This method is called by the subclass to indicate that transport disconnection
- // has occurred.
- protected void handleTransportDisconnected(final String info) {
- isConnected = false;
-
- try {
- SdlTrace.logTransportEvent("Transport.disconnect: " + info, null, InterfaceActivityDirection.Transmit, null, 0, SDL_LIB_TRACE_KEY);
- _transportListener.onTransportDisconnected(info);
- } catch (Exception excp) {
- DebugTool.logError(TAG, FailurePropagating_Msg + "onTransportDisconnected: " + excp.toString(), excp);
- } // end-catch
- } // end-method
-
- // This method is called by the subclass to indicate a transport error has occurred.
- protected void handleTransportError(final String message, final Exception ex) {
- isConnected = false;
- _transportListener.onTransportError(message, ex);
- }
-
- public abstract void openConnection() throws SdlException;
- public abstract void disconnect();
-
- /**
- * Abstract method which should be implemented by subclasses in order to return actual type of the transport.
- *
- * @return One of {@link TransportType} enumeration values.
- *
- * @see TransportType
- */
- public abstract TransportType getTransportType();
-
- public abstract String getBroadcastComment();
-} // end-class
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/TCPTransport.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/TCPTransport.java
deleted file mode 100644
index cc123d041..000000000
--- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/TCPTransport.java
+++ /dev/null
@@ -1,557 +0,0 @@
-/*
- * 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;
-import android.os.NetworkOnMainThreadException;
-
-import com.smartdevicelink.exception.SdlException;
-import com.smartdevicelink.exception.SdlExceptionCause;
-import com.smartdevicelink.protocol.SdlPacket;
-import com.smartdevicelink.transport.enums.TransportType;
-import com.smartdevicelink.util.DebugTool;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-
-/**
- * General comments:
- *
- * 1) Transport layer can be reorganized to properly incapsulate thread-related code according to Android OS guidelines
- * 2) Currently there are different cases when transport error information sent to listener components
- * a) when there are some errors during writing data to transport
- * b) when there are errors during connection establishing/reading data
- * But information about transport disconnection is sent only if disconnection was successful. So we have following
- * sequences:
- * a) handleTransportConnected -> read without errors -> handleTransportDisconnected
- * b) handleTransportConnected -> handleTransportError(write with errors) -> handleTransportDisconnected
- * c) handleTransportConnected -> handleTransportError(read with errors) -> handleTransportError(socket closed)
- *
- * They can be changed to be more natural and easy to use.
- *
- * 3) Public api is inconsistent. During single call of some api method (for example "openConnection") some of the
- * following result can appears:
- * a) SdlException thrown
- * b) onTransportError callback called on listeners
- *
- * 4) Handling of connection must be more stable
- * 5) General solution in case of reconnecting must be implemented
- * 6) It must be common and same solution for handling information about physical device adapters (BT, WiFi etc.)
- */
-
-/**
- * Class that implements TCP transport
- */
-public class TCPTransport extends SdlTransport {
- private static final String TAG = "TCPTransport";
- /**
- * Size of the read buffer.
- */
- private static final int READ_BUFFER_SIZE = 4096;
-
- /**
- * Delay between reconnect attempts
- */
- private static final int RECONNECT_DELAY = 5000;
-
- /**
- * Count of the reconnect retries
- */
- private static final int RECONNECT_RETRY_COUNT = 30;
-
- /**
- * Instance of TCP transport configuration
- */
- private TCPTransportConfig mConfig = null;
-
- /**
- * Instance of the client socket
- */
- private Socket mSocket = null;
-
- /**
- * Instance of the input stream. Used to read data from SmartDeviceLinkCore
- */
- private InputStream mInputStream = null;
-
- /**
- * Instance of the output stream. Used to send data to SmartDeviceLinkCore
- */
- private OutputStream mOutputStream = null;
-
- /**
- * Instance of the separate thread, that does actual work, related to connecting/reading/writing data
- */
- private TCPTransportThread mThread = null;
-
- /**
- * Initial internal state of the component. Used like a simple lightweight FSM replacement while component
- * must behave differently in response to it's public function calls depending of it's current state
- */
- private TCPTransportState mCurrentState = TCPTransportState.IDLE;
-
- /**
- * Constructs TCP transport component instance
- *
- * @param tcpTransportConfig Instance of the TCP transport configuration
- * @param transportListener Listener that will be notified on different TCP transport activities
- */
- public TCPTransport(TCPTransportConfig tcpTransportConfig, ITransportListener transportListener) {
- super(transportListener);
- this.mConfig = tcpTransportConfig;
- }
-
- /**
- * Performs actual work of sending array of bytes over the transport
- * @param packet The SdlPacket that should be sent over the transport
- * @return True if data was sent successfully, False otherwise
- */
- @SuppressLint("DefaultLocale")
- @Override
- protected boolean sendBytesOverTransport(SdlPacket packet) {
- TCPTransportState currentState = getCurrentState();
- byte[] msgBytes = packet.constructPacket();
- logInfo(String.format("TCPTransport: sendBytesOverTransport requested. Size: %d, Offset: %d, Length: %d, Current state is: %s"
- , msgBytes.length, 0, msgBytes.length, currentState.name()));
-
- boolean bResult = false;
-
- if(currentState == TCPTransportState.CONNECTED) {
- if (mOutputStream != null) {
- logInfo("TCPTransport: sendBytesOverTransport request accepted. Trying to send data");
- try {
- mOutputStream.write(msgBytes, 0, msgBytes.length);
- bResult = true;
- logInfo("TCPTransport.sendBytesOverTransport: successfully send data");
- } catch (IOException | NetworkOnMainThreadException e) {
- logError("TCPTransport.sendBytesOverTransport: error during sending data: " + e.getMessage());
- bResult = false;
- }
- } else {
- logError("TCPTransport: sendBytesOverTransport request accepted, but output stream is null");
- }
- }
- else {
- logInfo("TCPTransport: sendBytesOverTransport request rejected. Transport is not connected");
- bResult = false;
- }
-
- return bResult;
- }
-
- /**
- * Tries to open connection to SmartDeviceLinkCore.
- * Actual try will be performed only if no actual connection is available
- * @throws SdlException
- */
- @Override
- public void openConnection() throws SdlException {
- TCPTransportState currentState = getCurrentState();
- logInfo(String.format("TCPTransport: openConnection requested. Current state is: %s", currentState.name()));
-
- if(currentState == TCPTransportState.IDLE) {
- synchronized (this) {
- setCurrentState(TCPTransportState.CONNECTING);
- logInfo("TCPTransport: openConnection request accepted. Starting transport thread");
- try {
- mThread = new TCPTransportThread();
- mThread.setDaemon(true);
- mThread.start();
-
- // Initialize the SiphonServer
- if (SiphonServer.getSiphonEnabledStatus()) {
- SiphonServer.init();
- }
-
- } catch (Exception e) {
- logError("TCPTransport: Exception during transport thread starting", e);
- throw new SdlException(e);
- }
- }
- } else {
- logInfo("TCPTransport: openConnection request rejected. Another connection is not finished");
- }
- }
-
-
- /**
- * Tries to disconnect from SmartDeviceLinkCore.
- * Actual try will be performed only if connection is available
- */
- @Override
- public void disconnect() {
- TCPTransportState currentState = getCurrentState();
- logInfo(String.format("TCPTransport: disconnect requested from client. Current state is: %s", currentState.name()));
-
- if(currentState == TCPTransportState.CONNECTED) {
- logInfo("TCPTransport: disconnect request accepted.");
- synchronized (this) {
- disconnect(null, null, true);
- }
- } else {
- logInfo("TCPTransport: disconnect request rejected. Transport is not connected");
- }
- }
-
- /**
- * Performs actual work related to disconnecting from SmartDeviceLinkCore.
- *
- * @param message Message that describes disconnect reason
- * @param exception Some of the possible exceptions that was the reason of disconnecting
- * @param stopThread True if not only disconnection must be done but also thread that handles connection must be
- * also stopped so no reconnect attempts will be made
- */
- private synchronized void disconnect(String message, Exception exception, boolean stopThread) {
-
- if(getCurrentState() == TCPTransportState.DISCONNECTING) {
- logInfo("TCPTransport: disconnecting already in progress");
- return;
- }
-
- setCurrentState(TCPTransportState.DISCONNECTING);
-
- String disconnectMsg = (message == null ? "" : message);
- if (exception != null) {
- disconnectMsg += ", " + exception.toString();
- }
-
- try {
- if(mThread != null && stopThread) {
- mThread.halt();
- mThread.interrupt();
- }
-
- if(mSocket != null){
- mSocket.close();
- }
- mSocket = null;
- } catch (IOException e) {
- logError("TCPTransport.disconnect: Exception during disconnect: " + e.getMessage());
- }
-
- if (exception == null) {
- // This disconnect was not caused by an error, notify the proxy that
- // the transport has been disconnected.
- logInfo("Disconnect is correct. Handling it");
- handleTransportDisconnected(disconnectMsg);
- } else {
- // This disconnect was caused by an error, notify the proxy
- // that there was a transport error.
- logError("Disconnect is incorrect. Handling it as error");
- handleTransportError(disconnectMsg, exception);
- }
- }
-
- /**
- * Overridden abstract method which returns specific type of this transport.
- *
- * @return Constant value - TransportType.TCP.
- *
- * @see TransportType
- */
- public TransportType getTransportType() {
- return TransportType.TCP;
- }
-
- /**
- * Internal method for logging information messages
- * @param message Message to log
- */
- protected void logInfo(String message) {
- DebugTool.logInfo(TAG, message);
- }
-
- /**
- * Internal method for logging error messages
- * @param message Message to log
- */
- protected void logError(String message) {
- DebugTool.logError(TAG, message);
- }
-
- /**
- * Internal method for logging warning messages
- * @param message Message to log
- */
- protected void logWarning(String message) {
- DebugTool.logWarning(TAG, message);
- }
-
- /**
- * Internal method for logging error message together with information about exception that was the reason of it
- * @param message Message to log
- * @param throwable Exception, that was the main reason for logged error message
- */
- protected void logError(String message, Throwable throwable) {
- DebugTool.logError(TAG, message, throwable);
- }
-
- /**
- * Internal class that represents separate thread, that does actual work, related to connecting/reading/writing data
- */
- private class TCPTransportThread extends Thread {
- SdlPsm psm;
- public TCPTransportThread(){
- psm = new SdlPsm();
- }
- /**
- * Represents current thread state - halted or not. This flag is used to change internal behavior depending
- * on current state.
- */
- private Boolean isHalted = false;
-
- /**
- * Method that marks thread as halted.
- */
- public void halt() {
- isHalted = true;
- }
-
- /**
- * Tries to connect to the SmartDeviceLink core. Behavior depends autoReconnect configuration param:
- * a) If autoReconnect is false, then only one connect try will be performed.
- * b) If autoReconnect is true, then in case of connection error continuous reconnect will be performed
- * after short delay until connection will be established or retry count will be reached
- *
- * @return true if connection established and false otherwise
- */
- @SuppressLint("DefaultLocale")
- private boolean connect() {
- boolean bConnected;
- int remainingRetry = RECONNECT_RETRY_COUNT;
-
- synchronized (TCPTransport.this) {
- do {
- try {
-
- if ((null != mSocket) && (!mSocket.isClosed())) {
- logInfo("TCPTransport.connect: Socket is not closed. Trying to close it");
- mSocket.close();
- }
-
- logInfo(String.format("TCPTransport.connect: Socket is closed. Trying to connect to %s", mConfig));
- mSocket = new Socket();
- mSocket.connect(new InetSocketAddress(mConfig.getIPAddress(), mConfig.getPort()));
- mOutputStream = mSocket.getOutputStream();
- mInputStream = mSocket.getInputStream();
-
- } catch (IOException e) {
- logError("TCPTransport.connect: Exception during connect stage: " + e.getMessage());
- }
-
- bConnected = (null != mSocket) && mSocket.isConnected();
-
- if(bConnected){
- logInfo("TCPTransport.connect: Socket connected");
- }else{
- if(mConfig.getAutoReconnect()){
- remainingRetry--;
- logInfo(String.format("TCPTransport.connect: Socket not connected. AutoReconnect is ON. retryCount is: %d. Waiting for reconnect delay: %d"
- , remainingRetry, RECONNECT_DELAY));
- waitFor(RECONNECT_DELAY);
- } else {
- logInfo("TCPTransport.connect: Socket not connected. AutoReconnect is OFF");
- }
- }
- } while ((!bConnected) && (mConfig.getAutoReconnect()) && (remainingRetry > 0) && (!isHalted));
-
- return bConnected;
- }
- }
-
- /**
- * Performs actual thread work
- */
- @Override
- public void run() {
- logInfo("TCPTransport.run: transport thread created. Starting connect stage");
- psm.reset();
- while(!isHalted) {
- setCurrentState(TCPTransportState.CONNECTING);
- if(!connect()){
- if (isHalted) {
- logInfo("TCPTransport.run: Connection failed, but thread already halted");
- } else {
- disconnect("Failed to connect to Sdl", new SdlException("Failed to connect to Sdl"
- , SdlExceptionCause.SDL_CONNECTION_FAILED), true);
- }
- break;
- }
-
- synchronized (TCPTransport.this) {
- setCurrentState(TCPTransportState.CONNECTED);
- handleTransportConnected();
- }
-
- byte input;
- byte[] buffer = new byte[READ_BUFFER_SIZE];
- int bytesRead;
- boolean stateProgress = false;
- while (!isHalted) {
- //logInfo("TCPTransport.run: Waiting for data...");
- try {
- //input = (byte) mInputStream.read();
- bytesRead = mInputStream.read(buffer);
- } catch (IOException e) {
- internalHandleStreamReadError();
- break;
- }
-
- synchronized (TCPTransport.this) {
- if (mThread.isInterrupted()) {
- logInfo("TCPTransport.run: Got new data but thread is interrupted");
- break;
- }
- }
- for (int i = 0; i < bytesRead; i++) {
- //logInfo("TCPTransport.run: Got new data");
- // Send the response of what we received
- input = buffer[i];
- stateProgress = psm.handleByte(input);
- if (!stateProgress) {//We are trying to weed through the bad packet info until we get something
-
- //Log.w(TAG, "Packet State Machine did not move forward from state - "+ psm.getState()+". PSM being Reset.");
- psm.reset();
- }
-
- if (psm.getState() == SdlPsm.FINISHED_STATE)
- {
- synchronized (TCPTransport.this) {
- //Log.d(TAG, "Packet formed, sending off");
- handleReceivedPacket((SdlPacket) psm.getFormedPacket());
- }
- //We put a trace statement in the message read so we can avoid all the extra bytes
- psm.reset();
- }
- //FIXME logInfo(String.format("TCPTransport.run: Received %d bytes", bytesRead));
- }
- }
- }
-
- logInfo("TCPTransport.run: Thread terminated");
- setCurrentState(TCPTransportState.IDLE);
- }
-
- /**
- * Internal handling of Tcp disconnection
- */
- private void internalHandleTCPDisconnect() {
- if(isHalted){
- logInfo("TCPTransport.run: TCP disconnect received, but thread already halted");
- } else {
- logInfo("TCPTransport.run: TCP disconnect received");
- disconnect("TCPTransport.run: End of stream reached", null, false);
- }
- }
-
- /**
- * Internal handling of reading data from input stream
- */
- private void internalHandleStreamReadError() {
- if(isHalted){
- logError("TCPTransport.run: Exception during reading data, but thread already halted");
- } else {
- logError("TCPTransport.run: Exception during reading data");
- disconnect("Failed to read data from Sdl", new SdlException("Failed to read data from Sdl"
- , SdlExceptionCause.SDL_CONNECTION_FAILED), false);
- }
- }
- }
-
- /**
- * Returns current TCP transport state
- *
- * @return current state
- */
- private synchronized TCPTransportState getCurrentState() {
- return mCurrentState;
- }
-
- /**
- * Sets current TCP transport state
- * @param currentState New state
- */
- private synchronized void setCurrentState(TCPTransportState currentState) {
- logInfo(String.format("Current state changed to: %s", currentState));
- this.mCurrentState = currentState;
- }
-
- /**
- * Implementation of waiting required delay that cannot be interrupted
- * @param timeMs Time in milliseconds of required delay
- */
- private void waitFor(long timeMs) {
- long endTime = System.currentTimeMillis() +timeMs;
- while (System.currentTimeMillis() < endTime) {
- synchronized (this) {
- try {
- wait(endTime - System.currentTimeMillis());
- } catch (Exception e) {
- // Nothing To Do, simple wait
- }
- }
- }
- }
-
- /**
- * Defines available states of the TCP transport
- */
- private enum TCPTransportState {
- /**
- * TCP transport is created. No connection opened
- */
- IDLE,
-
- /**
- * TCP transport is in progress of establishing connection.
- */
- CONNECTING,
-
- /**
- * TCP transport is connected to SmartDeviceLink core
- */
- CONNECTED,
-
- /**
- * TCP transport is in progress of disconnecting
- */
- DISCONNECTING
- }
-
- @Override
- public String getBroadcastComment() {
- return "";
- }
-} // end-class
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 17942b49d..dbe7898ef 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
@@ -222,7 +222,7 @@ public class USBAccessoryAttachmentActivity extends Activity {
private void attemptLegacyUsbConnection(UsbAccessory usbAccessory){
if(usbAccessory != null) {
DebugTool.logInfo(TAG, "Attempting to send USB connection intent using legacy method");
- Intent usbAccessoryAttachedIntent = new Intent(USBTransport.ACTION_USB_ACCESSORY_ATTACHED);
+ Intent usbAccessoryAttachedIntent = new Intent(TransportConstants.ACTION_USB_ACCESSORY_ATTACHED);
usbAccessoryAttachedIntent.putExtra(UsbManager.EXTRA_ACCESSORY, usbAccessory);
usbAccessoryAttachedIntent.putExtra(UsbManager.EXTRA_PERMISSION_GRANTED, permissionGranted);
AndroidTools.sendExplicitBroadcast(getApplicationContext(), usbAccessoryAttachedIntent, null);
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
deleted file mode 100644
index 0ab2f2fcf..000000000
--- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBTransport.java
+++ /dev/null
@@ -1,915 +0,0 @@
-/*
- * 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;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.hardware.usb.UsbAccessory;
-import android.hardware.usb.UsbManager;
-import android.os.ParcelFileDescriptor;
-
-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.enums.TransportType;
-import com.smartdevicelink.util.DebugTool;
-
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * Class that implements USB transport.
- *
- * A note about USB Accessory protocol. If the device is already in the USB
- * accessory mode, any side (computer or Android) can open connection even if
- * the other side is not connected. Conversely, if one side simply disconnects,
- * the other side will NOT be notified and unblocked from reading data until
- * some data is sent again or the USB is physically disconnected.
- */
-@SuppressLint("NewApi")
-@Deprecated
-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
- * been attached.
- */
- public static final String ACTION_USB_ACCESSORY_ATTACHED =
- "com.smartdevicelink.USB_ACCESSORY_ATTACHED";
- /**
- * String tag for logging.
- */
- private static final String TAG = USBTransport.class.getSimpleName();
- /**
- * Key for SdlTrace.
- */
- private static final String SDL_LIB_TRACE_KEY =
- "42baba60-eb57-11df-98cf-0800200c9a66";
- /**
- * Broadcast action: sent when the user has granted access to the USB
- * accessory.
- */
- private static final String ACTION_USB_PERMISSION =
- "com.smartdevicelink.USB_PERMISSION";
- /**
- * Manufacturer name of the accessory we want to connect to. Must be the
- * same as in accessory_filter.xml to work properly.
- */
- private final static String ACCESSORY_MANUFACTURER = "SDL";
- /**
- * Model name of the accessory we want to connect to. Must be the same as
- * in accessory_filter.xml to work properly.
- */
- private final static String ACCESSORY_MODEL = "Core";
- /**
- * Version of the accessory we want to connect to. Must be the same as in
- * accessory_filter.xml to work properly.
- */
- private final static String ACCESSORY_VERSION = "1.0";
- /**
- * Prefix string to indicate debug output.
- */
- private static final String DEBUG_PREFIX = "DEBUG: ";
- /**
- * String to prefix exception output.
- */
- private static final String EXCEPTION_STRING = " Exception String: ";
- /**
- * Broadcast receiver that receives different USB-related intents: USB
- * accessory connected, disconnected, and permission granted.
- */
- private final BroadcastReceiver mUSBReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- logD("USBReceiver Action: " + action);
-
- UsbAccessory accessory =
- intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
- if (accessory != null) {
- if (ACTION_USB_ACCESSORY_ATTACHED.equals(action)) {
- logI("Accessory " + accessory + " attached");
- if (isAccessorySupported(accessory)) {
- connectToAccessory(accessory);
- } else {
- logW("Attached accessory is not supported!");
- }
- } else if (UsbManager.ACTION_USB_ACCESSORY_DETACHED
- .equals(action)) {
- logI("Accessory " + accessory + " detached");
- final String msg = "USB accessory has been detached";
- disconnect(msg, new SdlException(msg,
- SdlExceptionCause.SDL_USB_DETACHED));
- } else if (ACTION_USB_PERMISSION.equals(action)) {
- boolean permissionGranted = intent.getBooleanExtra(
- UsbManager.EXTRA_PERMISSION_GRANTED, false);
- if (permissionGranted) {
- logI("Permission granted for accessory " + accessory);
- openAccessory(accessory);
- } else {
- final String msg =
- "Permission denied for accessory " + accessory;
- logW(msg);
- disconnect(msg, new SdlException(msg,
- SdlExceptionCause.SDL_USB_PERMISSION_DENIED));
- }
- }
- } else {
- logW("Accessory is null");
- }
- }
- };
- /**
- * USB config object.
- */
- private USBTransportConfig mConfig = null;
- /**
- * Current state of transport.
- *
- * Use setter and getter to access it.
- */
- private State mState = State.IDLE;
- /**
- * Current accessory the transport is working with if any.
- */
- private UsbAccessory mAccessory = null;
- /**
- * FileDescriptor that owns the input and output streams. We have to keep
- * it, otherwise it will be garbage collected and the streams will become
- * invalid.
- */
- private ParcelFileDescriptor mParcelFD = null;
- /**
- * Data input stream to read data from USB accessory.
- */
- private InputStream mInputStream = null;
- /**
- * Data output stream to write data to USB accessory.
- */
- private OutputStream mOutputStream = null;
- /**
- * Thread that connects and reads data from USB accessory.
- *
- * @see USBTransportReader
- */
- private Thread mReaderThread = null;
-
- /**
- * Constructs the USBTransport instance.
- *
- * @param usbTransportConfig Config object for the USB transport
- * @param transportListener Listener that gets notified on different
- * transport events
- */
- public USBTransport(USBTransportConfig usbTransportConfig,
- ITransportListener transportListener) {
- super(transportListener);
- this.mConfig = usbTransportConfig;
- registerReciever();
- }
-
- /**
- * Returns the current state of transport.
- *
- * @return Current state of transport
- */
- public State getState() {
- return this.mState;
- }
-
- /**
- * Changes current state of transport.
- *
- * @param state New state
- */
- private void setState(State state) {
- logD("Changing state " + this.mState + " to " + state);
- this.mState = state;
- }
-
- /**
- * Sends the array of bytes over USB.
- *
- * @param packet The packet that is to be written out on the USB transport
- * @return true if the bytes are sent successfully
- */
- @Override
- protected boolean sendBytesOverTransport(SdlPacket packet) {
- byte[] msgBytes = packet.constructPacket();
- logD("SendBytes: array size " + msgBytes.length + ", offset " + 0 +
- ", length " + msgBytes.length);
-
- boolean result = false;
- final State state = getState();
- switch (state) {
- case CONNECTED:
- if (mOutputStream != null) {
- try {
- mOutputStream.write(msgBytes, 0, msgBytes.length);
- result = true;
-
- logI("Bytes successfully sent");
- SdlTrace.logTransportEvent(TAG + ": bytes sent",
- null, InterfaceActivityDirection.Transmit,
- msgBytes, 0, msgBytes.length,
- SDL_LIB_TRACE_KEY);
- } catch (IOException e) {
- final String msg = "Failed to send bytes over USB";
- logW(msg, e);
- disconnect(msg, e);
- }
- } else {
- final String msg =
- "Can't send bytes when output stream is null";
- logW(msg);
- disconnect(msg, null);
- }
- break;
-
- default:
- logW("Can't send bytes from " + state + " state");
- break;
- }
-
- return result;
- }
-
-
- public void registerReciever()
- {
- IntentFilter filter = new IntentFilter();
- filter.addAction(ACTION_USB_ACCESSORY_ATTACHED);
- filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
- filter.addAction(ACTION_USB_PERMISSION);
- filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
- getContext().registerReceiver(mUSBReceiver, filter);
- }
-
- /**
- * Opens a USB connection if not open yet.
- *
- * @throws SdlException
- */
- @Override
- public void openConnection() throws SdlException {
- final State state = getState();
- switch (state) {
- case IDLE:
- synchronized (this) {
- logI("openConnection()");
- setState(State.LISTENING);
- }
-
- logD("Registering receiver");
- try {
- IntentFilter filter = new IntentFilter();
- filter.addAction(ACTION_USB_ACCESSORY_ATTACHED);
- 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";
- logE(msg, e);
- throw new SdlException(msg, e,
- SdlExceptionCause.SDL_CONNECTION_FAILED);
- }
-
- break;
-
- default:
- logW("openConnection() called from state " + state +
- "; doing nothing");
- break;
- }
- }
-
- /**
- * Closes the USB connection if open.
- */
- @Override
- public void disconnect() {
- disconnect(null, null);
- }
-
- /**
- * Asks the reader thread to stop while it's possible. If it's blocked on
- * read(), there is no way to stop it except for physical USB disconnect.
- */
- //@Override
- public void stopReading() {
- DebugTool.logInfo(TAG, "USBTransport: stop reading requested, doing nothing");
- // TODO - put back stopUSBReading(); @see <a href="https://adc.luxoft.com/jira/browse/SmartDeviceLink-3450">SmartDeviceLink-3450</a>
- }
-
- @SuppressWarnings("unused")
- private void stopUSBReading() {
- final State state = getState();
- switch (state) {
- case CONNECTED:
- logI("Stopping reading");
- synchronized (this) {
- stopReaderThread();
- }
- break;
-
- default:
- logW("Stopping reading called from state " + state +
- "; doing nothing");
- break;
- }
- }
-
- /**
- * Actually asks the reader thread to interrupt.
- */
- private void stopReaderThread() {
- if (mReaderThread != null) {
- logI("Interrupting USB reader");
- mReaderThread.interrupt();
- // don't join() now
- mReaderThread = null;
- } else {
- logD("USB reader is null");
- }
- }
-
- /**
- * Closes the USB connection from inside the transport with some extra info.
- *
- * @param msg Disconnect reason message, if any
- * @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;
-
- mConfig.setUsbAccessory(null);
-
- final State state = getState();
- switch (state) {
- case LISTENING:
- case CONNECTED:
- synchronized (this) {
- logI("Disconnect from state " + getState() + "; message: " +
- msg + "; exception: " + ex);
- setState(State.IDLE);
-
- SdlTrace.logTransportEvent(TAG + ": disconnect", null,
- InterfaceActivityDirection.None, null, 0,
- SDL_LIB_TRACE_KEY);
-
- stopReaderThread();
-
- if (mAccessory != null) {
- if (mOutputStream != null) {
- try {
- mOutputStream.close();
- mOutputStream = null;
- } catch (IOException e) {
- logW("Can't close output stream", e);
- mOutputStream = null;
- }
- }
- if (mInputStream != null) {
- try {
- mInputStream.close();
- mInputStream = null;
- } catch (IOException e) {
- logW("Can't close input stream", e);
- mInputStream = null;
- }
- }
- if (mParcelFD != null) {
- try {
- mParcelFD.close();
- mParcelFD = null;
- } catch (IOException e) {
- logW("Can't close file descriptor", e);
- mParcelFD = null;
- }
- }
-
- mAccessory = null;
- }
- }
-
- logD("Unregistering receiver");
- try {
- getContext().unregisterReceiver(mUSBReceiver);
- } catch (IllegalArgumentException e) {
- logW("Receiver was already unregistered", e);
- }
-
- String disconnectMsg = (msg == null ? "" : msg);
- if (ex != null) {
- disconnectMsg += ", " + ex.toString();
-
- if(ex instanceof SdlException
- && SdlExceptionCause.SDL_USB_PERMISSION_DENIED.equals(((SdlException)ex).getSdlExceptionCause())){
- //If the USB device disconnected we don't want to cycle the proxy ourselves
- ex = null;
- }
- }
-
- if (ex == null) {
- // This disconnect was not caused by an error, notify the
- // proxy that the transport has been disconnected.
- logI("Disconnect is correct. Handling it");
- handleTransportDisconnected(disconnectMsg);
- } else {
- // This disconnect was caused by an error, notify the proxy
- // that there was a transport error.
- logI("Disconnect is incorrect. Handling it as error");
- handleTransportError(disconnectMsg, ex);
- }
- break;
-
- default:
- logW("Disconnect called from state " + state +
- "; doing nothing");
- break;
- }
- _disconnecting = false;
- }
-
- /**
- * Returns the type of the transport.
- *
- * @return TransportType.USB
- * @see com.smartdevicelink.transport.enums.TransportType
- */
- @Override
- public TransportType getTransportType() {
- return TransportType.USB;
- }
-
- /**
- * Looks for an already connected compatible accessory and connect to it.
- */
- private void initializeAccessory() {
- UsbAccessory acc = mConfig.getUsbAccessory();
-
- if (!mConfig.getQueryUsbAcc() && acc == null){
- logI("Query for accessory is disabled and accessory in config was null.");
- return;
- }
- logI("Looking for connected accessories");
-
- 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);
- }
-
- /**
- * Checks if the specified connected USB accessory is what we expect.
- *
- * @param accessory Accessory to check
- * @return true if the accessory is right
- */
- 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());
- boolean versionMatches =
- ACCESSORY_VERSION.equals(accessory.getVersion());
- return manufacturerMatches && modelMatches && versionMatches;
- }
-
- /**
- * Attempts to connect to the specified accessory.
- *
- * If the permission is already granted, opens the accessory. Otherwise,
- * requests permission to use it.
- *
- * @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:
- UsbManager usbManager = getUsbManager();
- if (usbManager.hasPermission(accessory)) {
- logI("Already have permission to use " + accessory);
- openAccessory(accessory);
- } else {
- logI("Requesting permission to use " + accessory);
-
- PendingIntent permissionIntent = PendingIntent
- .getBroadcast(getContext(), 0,
- new Intent(ACTION_USB_PERMISSION), 0);
- usbManager.requestPermission(accessory, permissionIntent);
- }
-
- break;
-
- default:
- logW("connectToAccessory() called from state " + state +
- "; doing nothing");
- }
- }
-
- /**
- * Returns the UsbManager to use with accessories.
- *
- * @return System UsbManager
- */
- private UsbManager getUsbManager() {
- return (UsbManager) getContext().getSystemService(Context.USB_SERVICE);
- }
-
- /**
- * Opens a connection to the accessory.
- *
- * When this function is called, the permission to use it must have already
- * been granted.
- *
- * @param accessory Accessory to open connection to
- */
- private void openAccessory(UsbAccessory accessory) {
- final State state = getState();
- switch (state) {
- case LISTENING:
- synchronized (this) {
- logI("Opening accessory " + accessory);
- mAccessory = accessory;
-
- mReaderThread = new Thread(new USBTransportReader());
- mReaderThread.setDaemon(true);
- mReaderThread
- .setName(USBTransportReader.class.getSimpleName());
- mReaderThread.start();
-
- // Initialize the SiphonServer
- if (SiphonServer.getSiphonEnabledStatus()) {
- SiphonServer.init();
- }
- }
-
- break;
-
- default:
- logW("openAccessory() called from state " + state +
- "; doing nothing");
- }
- }
-
- /**
- * Logs the string and the throwable with ERROR level.
- *
- * @param s string to log
- * @param tr throwable to log
- */
- private void logE(String s, Throwable tr) {
- DebugTool.logError(TAG, s, tr);
- }
-
- /**
- * Logs the string with WARN level.
- *
- * @param s string to log
- */
- private void logW(String s) {
- DebugTool.logWarning(TAG, s);
- }
-
- /**
- * Logs the string and the throwable with WARN level.
- *
- * @param s string to log
- * @param tr throwable to log
- */
- private void logW(String s, Throwable tr) {
- StringBuilder res = new StringBuilder(s);
- if (tr != null) {
- res.append(EXCEPTION_STRING);
- res.append(tr.toString());
- }
- logW(res.toString());
- }
-
- /**
- * Logs the string with INFO level.
- *
- * @param s string to log
- */
- private void logI(String s) {
- DebugTool.logInfo(TAG, s);
- }
-
- /**
- * Logs the string with DEBUG level.
- *
- * @param s string to log
- */
- private void logD(String s) {
- // DebugTool doesn't support DEBUG level, so we use INFO instead
- DebugTool.logInfo(TAG, DEBUG_PREFIX + s);
- }
-
- /**
- * Returns Context to communicate with the OS.
- *
- * @return current context to be used by the USB transport
- */
- private Context getContext() {
- return mConfig.getUSBContext();
- }
-
- /**
- * Possible states of the USB transport.
- */
- private enum State {
- /**
- * Transport initialized; no connections.
- */
- IDLE,
-
- /**
- * USB accessory not attached; SdlProxy wants connection as soon as
- * accessory is attached.
- */
- LISTENING,
-
- /**
- * USB accessory attached; permission granted; data IO in progress.
- */
- CONNECTED
- }
-
- /**
- * Internal task that connects to and reads data from a USB accessory.
- *
- * Since the class has to have access to the parent class' variables,
- * synchronization must be taken in consideration! For now, all access
- * to variables of USBTransport must be surrounded with
- * synchronized (USBTransport.this) { … }
- */
- private class USBTransportReader implements Runnable {
- /**
- * String tag for logging inside the task.
- */
- private final String TAG = USBTransportReader.class.getSimpleName();
-
- SdlPsm psm;
-
- /**
- * Checks if the thread has been interrupted.
- *
- * @return true if the thread has been interrupted
- */
- private boolean isInterrupted() {
- return Thread.interrupted();
- }
-
- /**
- * Entry function that is called when the task is started. It attempts
- * to connect to the accessory, then starts a read loop until
- * interrupted.
- */
- @Override
- public void run() {
- logD("USB reader started!");
- psm = new SdlPsm();
- psm.reset();
- if (connect()) {
- readFromTransport();
- }
-
- logD("USB reader finished!");
- }
-
- /**
- * Attemps to open connection to USB accessory.
- *
- * @return true if connected successfully
- */
- private boolean connect() {
- if (isInterrupted()) {
- logI("Thread is interrupted, not connecting");
- return false;
- }
-
- final State state = getState();
- switch (state) {
- case LISTENING:
-
- synchronized (USBTransport.this) {
- try {
- mParcelFD =
- getUsbManager().openAccessory(mAccessory);
- } catch (Exception e) {
- final String msg =
- "Have no permission to open the accessory";
- logE(msg, e);
- disconnect(msg, e);
- return false;
- }
- if (mParcelFD == null) {
- if (isInterrupted()) {
- logW("Can't open accessory, and thread is interrupted");
- } else {
- logW("Can't open accessory, disconnecting!");
- String msg = "Failed to open USB accessory";
- disconnect(msg, new SdlException(msg,
- SdlExceptionCause.SDL_CONNECTION_FAILED));
- }
- return false;
- }
- FileDescriptor fd = mParcelFD.getFileDescriptor();
- mInputStream = new FileInputStream(fd);
- mOutputStream = new FileOutputStream(fd);
- }
-
- logI("Accessory opened!");
-
- synchronized (USBTransport.this) {
- setState(State.CONNECTED);
- handleTransportConnected();
- }
- break;
-
- default:
- logW("connect() called from state " + state +
- ", will not try to connect");
- return false;
- }
-
- return true;
- }
-
- /**
- * Continuously reads data from the transport's input stream, blocking
- * when no data is available.
- */
- private void readFromTransport() {
- final int READ_BUFFER_SIZE = 4096;
- byte[] buffer = new byte[READ_BUFFER_SIZE];
- int bytesRead;
- // byte input;
- boolean stateProgress = false;
-
- // read loop
- while (!isInterrupted()) {
- try {
- if (mInputStream == null)
- continue;
-
- bytesRead = mInputStream.read(buffer);
- if (bytesRead == -1) {
- if (isInterrupted()) {
- logI("EOF reached, and thread is interrupted");
- } else {
- logI("EOF reached, disconnecting!");
- disconnect("EOF reached", null);
- }
- return;
- }
- } catch (IOException e) {
- if (isInterrupted()) {
- logW("Can't read data, and thread is interrupted", e);
- } else {
- logW("Can't read data, disconnecting!", e);
- disconnect("Can't read data from USB", e);
- }
- return;
- }
-
- logD("Read " + bytesRead + " bytes");
- //FIXME SdlTrace.logTransportEvent(TAG + ": read bytes", null,
- // InterfaceActivityDirection.Receive, buffer, bytesRead,
- // SDL_LIB_TRACE_KEY);
-
- if (isInterrupted()) {
- logI("Read some data, but thread is interrupted");
- return;
- }
- byte input;
- for(int i=0;i<bytesRead; i++){
- input=buffer[i];
- stateProgress = psm.handleByte(input);
- if(!stateProgress){//We are trying to weed through the bad packet info until we get something
- //Log.w(TAG, "Packet State Machine did not move forward from state - "+ psm.getState()+". PSM being Reset.");
- psm.reset();
- buffer = new byte[READ_BUFFER_SIZE];
- }
-
- if(psm.getState() == SdlPsm.FINISHED_STATE){
- synchronized (USBTransport.this) {
- //Log.d(TAG, "Packet formed, sending off");
- handleReceivedPacket((SdlPacket)psm.getFormedPacket());
- }
- //We put a trace statement in the message read so we can avoid all the extra bytes
- psm.reset();
- buffer = new byte[READ_BUFFER_SIZE]; //FIXME just do an array copy and send off
-
- }
- }
- }
- }
-
- // Log functions
-
- private void logD(String s) {
- DebugTool.logInfo(TAG, DEBUG_PREFIX + s);
- }
-
- private void logI(String s) {
- DebugTool.logInfo(TAG, s);
- }
-
- private void logW(String s) {
- DebugTool.logWarning(TAG, s);
- }
-
- private void logW(String s, Throwable tr) {
- StringBuilder res = new StringBuilder(s);
- if (tr != null) {
- res.append(EXCEPTION_STRING);
- res.append(tr.toString());
- }
- logW(res.toString());
- }
-
- private void logE(String s, Throwable tr) {
- DebugTool.logError(TAG, s, tr);
- }
- }
-
- @Override
- public String getBroadcastComment() {
- // TODO Auto-generated method stub
- return null;
- }
-}
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBTransportConfig.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBTransportConfig.java
deleted file mode 100644
index 9aeb1a33a..000000000
--- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBTransportConfig.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * 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.content.Context;
-import android.hardware.usb.UsbAccessory;
-
-import com.smartdevicelink.transport.enums.TransportType;
-
-/**
- * <b>NOTE: </b> This should no longer be used. See the MultplexTransportConfig and guides to
- * understand how to implement USB multiplexing. This class and method of USB connection will be
- * removed in the next major release. If a router service is available to handle multiplexing of the
- * usb transport it will be used, and this app will connect to whatever router service hosts the USB
- * connection.
- * @see MultiplexTransportConfig
- */
-@Deprecated
-public class USBTransportConfig extends BaseTransportConfig {
-
- private Context mainActivity = null;
- private UsbAccessory usbAccessory = null;
- private Boolean queryUsbAcc = true;
-
- /**
- * <b>NOTE: </b> This should no longer be used. See the MultplexTransportConfig and guides to
- * understand how to implement USB multiplexing. This class and method of USB connection will be
- * removed in the next major release. If a router service is available to handle multiplexing of the
- * usb transport it will be used, and this app will connect to whatever router service hosts the USB
- * connection.
- * @param mainActivity context used to start USB transport
- * @see MultiplexTransportConfig
- */
- public USBTransportConfig (Context mainActivity) {
- this.mainActivity = mainActivity;
- }
-
- /**
- * <b>NOTE: </b> This should no longer be used. See the MultplexTransportConfig and guides to
- * understand how to implement USB multiplexing. This class and method of USB connection will be
- * removed in the next major release. If a router service is available to handle multiplexing of the
- * usb transport it will be used, and this app will connect to whatever router service hosts the USB
- * connection.
- * @param mainActivity context used to start USB transport
- * @param usbAccessory the accessory that was given to this app
- * @see MultiplexTransportConfig
- */
- public USBTransportConfig (Context mainActivity, UsbAccessory usbAccessory) {
- this.mainActivity = mainActivity;
- this.usbAccessory = usbAccessory;
- }
-
- /**
- * <b>NOTE: </b> This should no longer be used. See the MultplexTransportConfig and guides to
- * understand how to implement USB multiplexing. This class and method of USB connection will be
- * removed in the next major release. If a router service is available to handle multiplexing of the
- * usb transport it will be used, and this app will connect to whatever router service hosts the USB
- * connection.
- * @param mainActivity context used to start USB transport
- * @param shareConnection enable other sessions on this app to use this USB connection
- * @param queryUsbAcc attempt to query the USB accessory if none is provided
- * @see MultiplexTransportConfig
- */
- public USBTransportConfig (Context mainActivity, boolean shareConnection, boolean queryUsbAcc) {
- this.mainActivity = mainActivity;
- this.queryUsbAcc = queryUsbAcc;
- super.shareConnection = shareConnection;
- }
-
- /**
- * <b>NOTE: </b> This should no longer be used. See the MultplexTransportConfig and guides to
- * understand how to implement USB multiplexing. This class and method of USB connection will be
- * removed in the next major release. If a router service is available to handle multiplexing of the
- * usb transport it will be used, and this app will connect to whatever router service hosts the USB
- * connection.
- * @param mainActivity context used to start USB transport
- * @param usbAccessory the accessory that was given to this app
- * @param shareConnection enable other sessions on this app to use this USB connection
- * @param queryUsbAcc attempt to query the USB accessory if none is provided
- * @see MultiplexTransportConfig
- */
- 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;
- }
-
- public UsbAccessory getUsbAccessory () {
- return usbAccessory;
- }
-
- public void setUsbAccessory (UsbAccessory value) { usbAccessory = value; }
-
- public TransportType getTransportType() {
- return TransportType.USB;
- }
-} \ No newline at end of file
diff --git a/base/src/main/java/com/smartdevicelink/transport/ITransportListener.java b/base/src/main/java/com/smartdevicelink/transport/ITransportListener.java
deleted file mode 100644
index 46baf5296..000000000
--- a/base/src/main/java/com/smartdevicelink/transport/ITransportListener.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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 com.smartdevicelink.protocol.SdlPacket;
-
-public interface ITransportListener {
- // Called to indicate and deliver a packet received from transport
- void onTransportPacketReceived(SdlPacket packet);
-
- // Called to indicate that transport connection was established
- void onTransportConnected();
-
- // Called to indicate that transport was disconnected (by either side)
- void onTransportDisconnected(String info);
-
- // Called to indicate that some error occurred on the transport
- void onTransportError(String info, Exception e);
-} // end-interface \ No newline at end of file
diff --git a/base/src/main/java/com/smartdevicelink/transport/TransportConstants.java b/base/src/main/java/com/smartdevicelink/transport/TransportConstants.java
index 9b2eba9ed..19579c19b 100644
--- a/base/src/main/java/com/smartdevicelink/transport/TransportConstants.java
+++ b/base/src/main/java/com/smartdevicelink/transport/TransportConstants.java
@@ -294,4 +294,14 @@ public class TransportConstants {
public static final String AOA_USB = "AOA_USB";
public static final String TCP_WIFI = "TCP_WIFI";
+
+ /**
+ * Broadcast action: sent when a USB accessory is attached.
+ *
+ * UsbManager.EXTRA_ACCESSORY extra contains UsbAccessory object that has
+ * been attached.
+ */
+ public static final String ACTION_USB_ACCESSORY_ATTACHED = "com.smartdevicelink.USB_ACCESSORY_ATTACHED";
+
+
}