summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2020-07-21 11:58:38 -0400
committerJoey Grover <joeygrover@gmail.com>2020-07-21 11:58:38 -0400
commitc0c4f50e409b486f524d7ded9d0dc6d8f4f875c3 (patch)
treec2ea52b0dbec046b325242d3b0b6f5ad80d3eb64
parent9d24a0e87d83b3544a4fd4bb208bec32479e322c (diff)
downloadsdl_android-c0c4f50e409b486f524d7ded9d0dc6d8f4f875c3.tar.gz
Remove deprecated classes that used old SdlSession
Also remove deprecated classes that had to reference those deleted classes.
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlConnection.java661
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java195
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/protocol/WiProProtocol.java696
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/streaming/StreamPacketizer.java10
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/BTTransport.java586
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransport.java343
6 files changed, 1 insertions, 2490 deletions
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlConnection.java b/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlConnection.java
deleted file mode 100644
index cdba04757..000000000
--- a/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlConnection.java
+++ /dev/null
@@ -1,661 +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.SdlConnection;
-
-
-import android.content.ComponentName;
-
-import com.smartdevicelink.exception.SdlException;
-import com.smartdevicelink.protocol.AbstractProtocol;
-import com.smartdevicelink.protocol.IProtocolListener;
-import com.smartdevicelink.protocol.ProtocolMessage;
-import com.smartdevicelink.protocol.SdlPacket;
-import com.smartdevicelink.protocol.WiProProtocol;
-import com.smartdevicelink.protocol.enums.SessionType;
-import com.smartdevicelink.transport.BTTransport;
-import com.smartdevicelink.transport.BTTransportConfig;
-import com.smartdevicelink.transport.BaseTransportConfig;
-import com.smartdevicelink.transport.ITransportListener;
-import com.smartdevicelink.transport.MultiplexTransport;
-import com.smartdevicelink.transport.MultiplexTransportConfig;
-import com.smartdevicelink.transport.RouterServiceValidator;
-import com.smartdevicelink.transport.SdlBroadcastReceiver;
-import com.smartdevicelink.transport.SdlTransport;
-import com.smartdevicelink.transport.TCPTransport;
-import com.smartdevicelink.transport.TCPTransportConfig;
-import com.smartdevicelink.transport.USBTransport;
-import com.smartdevicelink.transport.USBTransportConfig;
-import com.smartdevicelink.transport.enums.TransportType;
-import com.smartdevicelink.util.DebugTool;
-
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-@Deprecated
-public class SdlConnection implements IProtocolListener, ITransportListener {
-
- private static final String TAG = "SdlConnection";
-
- SdlTransport _transport = null;
- AbstractProtocol _protocol = null;
- ISdlConnectionListener _connectionListener = null;
-
-
-
- // Thread safety locks
- static Object TRANSPORT_REFERENCE_LOCK = new Object();
- Object PROTOCOL_REFERENCE_LOCK = new Object();
-
- private Object SESSION_LOCK = new Object();
- private CopyOnWriteArrayList<SdlSession> listenerList = new CopyOnWriteArrayList<SdlSession>();
- private static TransportType legacyTransportRequest = null;
- private final static int BUFF_READ_SIZE = 1000000;
- protected static MultiplexTransportConfig cachedMultiConfig = null;
-
- /**
- * Constructor.
- *
- * @param transportConfig Transport configuration for this connection.
- */
- public SdlConnection(BaseTransportConfig transportConfig) {
- RouterServiceValidator vlad = null;
- //Let's check if we can even do multiplexing
- if(transportConfig.getTransportType() == TransportType.MULTIPLEX){
- ComponentName tempCompName = SdlBroadcastReceiver.consumeQueuedRouterService();
- MultiplexTransportConfig multiConfig = (MultiplexTransportConfig)transportConfig;
- if(tempCompName!=null){
- vlad =new RouterServiceValidator(multiConfig.getContext(),tempCompName);
- }else{
- vlad =new RouterServiceValidator(multiConfig.getContext());
- }
- //vlad.setFlags(RouterServiceValidator.FLAG_DEBUG_VERSION_CHECK);
- vlad.setSecurityLevel(multiConfig.getSecurityLevel());
- }
- constructor(transportConfig,vlad);
- }
- //For unit tests
- protected SdlConnection(BaseTransportConfig transportConfig,RouterServiceValidator rsvp){
- constructor(transportConfig,rsvp);
- }
-
- private void constructor(BaseTransportConfig transportConfig,RouterServiceValidator rsvp){
- _connectionListener = new InternalMsgDispatcher();
-
- // Initialize the transport
- synchronized(TRANSPORT_REFERENCE_LOCK) {
- // Ensure transport is null
- if (_transport != null) {
- if (_transport.getIsConnected()) {
- _transport.disconnect();
- }
- _transport = null;
- }
-
- //Let's check if we can even do multiplexing
- if(!isLegacyModeEnabled() &&
- rsvp!= null &&
- transportConfig.getTransportType() == TransportType.MULTIPLEX){
- //rsvp = new RouterServiceValidator(((MultiplexTransportConfig)transportConfig).getContext());
- //vlad.setFlags(RouterServiceValidator.FLAG_DEBUG_VERSION_CHECK);
- if(rsvp.validate()){
- DebugTool.logWarning(TAG, "SDL Router service is valid; attempting to connect");
- ((MultiplexTransportConfig)transportConfig).setService(rsvp.getService());//Let thes the transport broker know which service to connect to
- }else{
- DebugTool.logWarning(TAG, "SDL Router service isn't trusted. Enabling legacy bluetooth connection.");
- if(cachedMultiConfig == null){
- cachedMultiConfig = (MultiplexTransportConfig) transportConfig;
- cachedMultiConfig.setService(null);
- }
- enableLegacyMode(true,TransportType.BLUETOOTH); //We will use legacy bluetooth connection for this attempt
- }
- }
-
- if(!isLegacyModeEnabled() && //Make sure legacy mode is not enabled
- (transportConfig.getTransportType() == TransportType.MULTIPLEX)){
- _transport = new MultiplexTransport((MultiplexTransportConfig)transportConfig,this);
- }else if(isLegacyModeEnabled() && legacyTransportRequest == TransportType.BLUETOOTH){
- _transport = new BTTransport(this, true);
- }else if(transportConfig.getTransportType() == TransportType.BLUETOOTH){
- _transport = new BTTransport(this,((BTTransportConfig)transportConfig).getKeepSocketActive());
- }
- else if (transportConfig.getTransportType() == TransportType.TCP)
- {
- _transport = new TCPTransport((TCPTransportConfig) transportConfig, this);
- } else if (transportConfig.getTransportType() == TransportType.USB) {
- _transport = new USBTransport((USBTransportConfig) transportConfig, this);
- }
- }
-
- // Initialize the protocol
- synchronized(PROTOCOL_REFERENCE_LOCK) {
- // Ensure protocol is null
- if (_protocol != null) {
- _protocol = null;
- }
-
- _protocol = new WiProProtocol(this);
- }
- }
-
- public AbstractProtocol getWiProProtocol(){
- return _protocol;
- }
-
-
-
-
- private void closeConnection(boolean willRecycle, byte rpcSessionID, int sessionHashId) {
- synchronized(PROTOCOL_REFERENCE_LOCK) {
-
- if (_protocol != null) {
- // If transport is still connected, sent EndProtocolSessionMessage
- if (_transport != null && _transport.getIsConnected()) {
- _protocol.EndProtocolSession(SessionType.RPC, rpcSessionID, sessionHashId);
- }
- if (willRecycle) {
- _protocol = null;
- }
- } // end-if
- }
- synchronized (TRANSPORT_REFERENCE_LOCK) {
- if (willRecycle) {
- if (_transport != null) {
- _transport.disconnect();
- }
- _transport = null;
- }
- }
- }
-
-
- public void startTransport() throws SdlException {
- _transport.openConnection();
- }
-
- public Boolean getIsConnected() {
-
- // If _transport is null, then it can't be connected
- if (_transport == null) {
- return false;
- }
-
- return _transport.getIsConnected();
- }
-
- public String getBroadcastComment() {
-
- if (_transport == null) {
- return "";
- }
-
- return _transport.getBroadcastComment();
- }
-
- public void sendMessage(ProtocolMessage msg) {
- if(_protocol != null)
- _protocol.SendMessage(msg);
- }
-
- void startHandShake() {
- synchronized(PROTOCOL_REFERENCE_LOCK){
- if(_protocol != null){
- _protocol.StartProtocolSession(SessionType.RPC);
- }
- }
- }
-
- @Override
- public void onTransportPacketReceived(SdlPacket packet) {
- // Send bytes to protocol to be interpreted
- synchronized(PROTOCOL_REFERENCE_LOCK) {
- if (_protocol != null) {
- _protocol.handlePacketReceived(packet);
- }
- }
- }
-
- @Override
- public void onTransportConnected() {
- synchronized(PROTOCOL_REFERENCE_LOCK){
- if(_protocol != null){
- boolean shouldRequestSession = _transport !=null && _transport.getTransportType()== TransportType.MULTIPLEX;
- for (SdlSession s : listenerList) {
- if (s.getSessionId() == 0) {
- if(shouldRequestSession){
- ((MultiplexTransport)_transport).requestNewSession();
- }
- startHandShake();
- }
- }
- }
- }
- }
-
- @Override
- public void onTransportDisconnected(String info) {
- // Pass directly to connection listener
- _connectionListener.onTransportDisconnected(info);
- }
-
- @Override
- public void onTransportError(String info, Exception e) {
- // Pass directly to connection listener
- _connectionListener.onTransportError(info, e);
- }
-
- @Override
- public void onProtocolMessageBytesToSend(SdlPacket packet) {
- // Protocol has packaged bytes to send, pass to transport for transmission
- synchronized(TRANSPORT_REFERENCE_LOCK) {
- if (_transport != null) {
- _transport.sendBytes(packet);
- }
- }
- }
-
- @Override
- public void onProtocolMessageReceived(ProtocolMessage msg) {
- _connectionListener.onProtocolMessageReceived(msg);
- }
-
- @Override
- public void onProtocolSessionStarted(SessionType sessionType,
- byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) {
- _connectionListener.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID, isEncrypted);
- }
-
- @Override
- public void onProtocolSessionNACKed(SessionType sessionType,
- byte sessionID, byte version, String correlationID, List<String> rejectedParams) {
- _connectionListener.onProtocolSessionStartedNACKed(sessionType,
- sessionID, version, correlationID, rejectedParams);
- }
-
- @Override
- public void onProtocolSessionEnded(SessionType sessionType, byte sessionID,
- String correlationID) {
- _connectionListener.onProtocolSessionEnded(sessionType, sessionID, correlationID);
- }
-
- @Override
- public void onProtocolError(String info, Exception e) {
- _connectionListener.onProtocolError(info, e);
- }
-
-
- /**
- * Gets type of transport currently used by this connection.
- *
- * @return One of TransportType enumeration values.
- *
- * @see TransportType
- */
- public TransportType getCurrentTransportType() {
- return _transport.getTransportType();
- }
-
- public void startService (SessionType sessionType, byte sessionID, boolean isEncrypted) {
- synchronized(PROTOCOL_REFERENCE_LOCK){
- if(_protocol != null){
- _protocol.StartProtocolService(sessionType, sessionID, isEncrypted);
- }
- }
- }
-
- public void endService (SessionType sessionType, byte sessionID) {
- synchronized(PROTOCOL_REFERENCE_LOCK){
- if(_protocol != null){
- _protocol.EndProtocolService(sessionType, sessionID);
- }
- }
- }
- void registerSession(SdlSession registerListener) throws SdlException {
- boolean didAdd = listenerList.addIfAbsent(registerListener);
- if (!this.getIsConnected()) {
- this.startTransport();
- } else {
- if(didAdd && _transport !=null && _transport.getTransportType()== TransportType.MULTIPLEX){ //If we're connected we can request the extra session now
- ((MultiplexTransport)_transport).requestNewSession();
- }
- this.startHandShake();
- }
- }
-
- public void sendHeartbeat(SdlSession mySession) {
- if(_protocol != null && mySession != null)
- _protocol.SendHeartBeat(mySession.getSessionId());
- }
-
- public void unregisterSession(SdlSession registerListener) {
- boolean didRemove = listenerList.remove(registerListener);
- if(didRemove && _transport !=null && _transport.getTransportType()== TransportType.MULTIPLEX){ //If we're connected we can request the extra session now
- ((MultiplexTransport)_transport).removeSession(registerListener.getSessionId());
- }
- closeConnection(listenerList.size() == 0, registerListener.getSessionId(), registerListener.getSessionHashId());
- }
-
-
- public SdlSession findSessionById(byte id) {
- for (SdlSession listener : listenerList) {
- if (listener.getSessionId() == id) {
- return listener;
- }
- }
- return null;
- }
-
- public void onAuthTokenReceived(String authToken, byte sessionID) {
- if(this._connectionListener != null){
- this._connectionListener.onAuthTokenReceived(authToken,sessionID);
- }
- }
-
- private class InternalMsgDispatcher implements ISdlConnectionListener {
-
- @Override
- public void onTransportDisconnected(String info) {
- for (SdlSession session : listenerList) {
- session.onTransportDisconnected(info);
- }
- if(cachedMultiConfig!=null ){
- if(cachedMultiConfig.getService()!=null){
- synchronized(TRANSPORT_REFERENCE_LOCK) {
- // Ensure transport is null
- if (_transport != null) {
- if (_transport.getIsConnected()) {
- _transport.disconnect();
- }
- _transport = null;
- }
- _transport = new MultiplexTransport(cachedMultiConfig, SdlConnection.this);
- try {
- startTransport();
- } catch (SdlException e) {
- e.printStackTrace();
- }
- }
- }else{ //The service must be null or already consumed. Let's see if we can find the connection that consumed it
- for (SdlSession session : listenerList) {
- session.checkForOpenMultiplexConnection(SdlConnection.this);;
- }
- }
- }
- }
-
- @Override
- public void onTransportDisconnected(String info, boolean availablePrimary, BaseTransportConfig transportConfig) {
- onTransportDisconnected(info);
- }
-
- @Override
- public void onTransportError(String info, Exception e) {
- //If there's an error with the transport we want to make sure we clear out any reference to it held by the static list in sessions
- SdlSession.removeConnection(SdlConnection.this);
- //If we are erroring out to go into legacy mode, lets cache our multiplexing
- if(isLegacyModeEnabled() && _transport!=null && TransportType.MULTIPLEX.equals(_transport.getTransportType())){
- MultiplexTransport multi = ((MultiplexTransport)_transport);
- cachedMultiConfig = multi.getConfig();
- cachedMultiConfig.setService(null); //Make sure we're clearning this out
- }else{
- cachedMultiConfig = null; //It should now be consumed
- }
- for (SdlSession session : listenerList) {
- session.onTransportError(info, e);
- }
-
- }
-
- @Override
- public void onProtocolMessageReceived(ProtocolMessage msg) {
- SdlSession session = findSessionById(msg.getSessionID());
- if (session != null) {
- session.onProtocolMessageReceived(msg);
- }
- }
-
- @Override
- public void onProtocolSessionStarted(SessionType sessionType,
- byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) {
- for (SdlSession session : listenerList) {
- if (session.getSessionId() == 0) {
- session.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID, isEncrypted);
- break;
- }
- }
-
- if (sessionType.equals(SessionType.NAV) || sessionType.equals(SessionType.PCM) || isEncrypted){
- SdlSession session = findSessionById(sessionID);
- if (session != null) {
- session.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID, isEncrypted);
- }
- }
- }
-
- @Override
- public void onProtocolSessionEnded(SessionType sessionType,
- byte sessionID, String correlationID) {
- SdlSession session = findSessionById(sessionID);
- if (session != null) {
- session.onProtocolSessionEnded(sessionType, sessionID, correlationID);
- }
- }
-
- @Override
- public void onProtocolError(String info, Exception e) {
- for (SdlSession session : listenerList) {
- session.onProtocolError(info, e);
- }
- }
-
- @Override
- public void onProtocolSessionStartedNACKed(SessionType sessionType,
- byte sessionID, byte version, String correlationID, List<String> rejectedParams) {
- SdlSession session = findSessionById(sessionID);
- if (session != null) {
- session.onProtocolSessionStartedNACKed(sessionType,
- sessionID, version, correlationID, rejectedParams);
- }
- }
-
- @Override
- public void onHeartbeatTimedOut(byte sessionID) {
- SdlSession session = findSessionById(sessionID);
- if (session != null) {
- session.onHeartbeatTimedOut(sessionID);
- }
- }
-
- @Override
- public void onProtocolSessionEndedNACKed(SessionType sessionType, byte sessionID, String correlationID) {
- SdlSession session = findSessionById(sessionID);
- if (session != null) {
- session.onProtocolSessionEndedNACKed(sessionType, sessionID, correlationID);
- }
- }
-
- @Override
- public void onProtocolServiceDataACK(SessionType serviceType, int dataSize, byte sessionID) {
- SdlSession session = findSessionById(sessionID);
- if (session != null) {
- session.onProtocolServiceDataACK(serviceType, dataSize, sessionID);
- }
- }
-
- @Override
- public void onAuthTokenReceived(String authToken, byte sessionID) {
- SdlSession session = findSessionById(sessionID);
- if (session != null) {
- session.onAuthTokenReceived(authToken,sessionID);
- }
- }
- }
-
- public int getRegisterCount() {
- return listenerList.size();
- }
-
- @Override
- public void onProtocolHeartbeat(SessionType sessionType, byte sessionID) {
- SdlSession mySession = findSessionById(sessionID);
- if (mySession == null) return;
-
- if (mySession._outgoingHeartbeatMonitor != null) {
- mySession._outgoingHeartbeatMonitor.heartbeatReceived();
- }
- if (mySession._incomingHeartbeatMonitor != null) {
- mySession._incomingHeartbeatMonitor.heartbeatReceived();
- }
- }
-
- @Override
- public void onProtocolHeartbeatACK(SessionType sessionType, byte sessionID) {
- SdlSession mySession = findSessionById(sessionID);
- if (mySession == null) return;
-
- if (mySession._outgoingHeartbeatMonitor != null) {
- mySession._outgoingHeartbeatMonitor.heartbeatACKReceived();
- }
- if (mySession._incomingHeartbeatMonitor != null) {
- mySession._incomingHeartbeatMonitor.heartbeatACKReceived();
- }
- }
-
- @Override
- public void onResetOutgoingHeartbeat(SessionType sessionType, byte sessionID){
-
- SdlSession mySession = findSessionById(sessionID);
- if (mySession == null) return;
-
- if (mySession._outgoingHeartbeatMonitor != null) {
- mySession._outgoingHeartbeatMonitor.notifyTransportActivity();
- }
- }
-
- @Override
- public void onResetIncomingHeartbeat(SessionType sessionType, byte sessionID){
-
- SdlSession mySession = findSessionById(sessionID);
- if (mySession == null) return;
-
- if (mySession._incomingHeartbeatMonitor != null) {
- mySession._incomingHeartbeatMonitor.notifyTransportActivity();
- }
- }
-
- public void forceHardwareConnectEvent(TransportType type){
- if(_transport == null){
- DebugTool.logWarning(TAG, "Unable to force connect, transport was null!");
- return;
- }
- if(isLegacyModeEnabled()){//We know we should no longer be in legacy mode for future connections, so lets clear out that flag
- enableLegacyMode(false,null);
- }
- if(_transport!=null && (_transport.getTransportType()==TransportType.MULTIPLEX)){ //This is only valid for the multiplex connection
- MultiplexTransport multi = ((MultiplexTransport)_transport);
- MultiplexTransportConfig config = multi.getConfig();
- ComponentName tempCompName = SdlBroadcastReceiver.consumeQueuedRouterService();
- if(config.getService() != null && config.getService().equals(tempCompName)){ //If this is the same service that just connected that we are already looking at. Attempt to reconnect
- if(!multi.getIsConnected() && multi.isDisconnecting() ){ //If we aren't able to force a connection it means the
- _transport = new MultiplexTransport(config,this);
- try {
- startTransport();
- } catch (SdlException e) {
- e.printStackTrace();
- }
- }
- }else if(tempCompName!=null){
- //We have a conflicting service request
- DebugTool.logWarning(TAG, "Conflicting services. Disconnecting from current and connecting to new");
- //Log.w(TAG, "Old service " + config.getService().toShortString());
- //Log.w(TAG, "New Serivce " + tempCompName.toString());
- multi.disconnect();
- config.setService(tempCompName);
- _transport = new MultiplexTransport(config,this);
- try {
- startTransport();
- } catch (SdlException e) {
- e.printStackTrace();
- }
-
- }
- }else if(_transport.getTransportType()==TransportType.BLUETOOTH
- && !_transport.getIsConnected()){
- if(cachedMultiConfig!=null){
- //We are in legacy mode, but just received a force connect. The router service should never be pointing us here if we are truely in legacy mode
- ComponentName tempCompName = SdlBroadcastReceiver.consumeQueuedRouterService();
- RouterServiceValidator vlad = new RouterServiceValidator(cachedMultiConfig.getContext(),tempCompName);
- if(vlad.validate()){
- cachedMultiConfig.setService(tempCompName);
- //We are not connected yet so we should be able to close down
- _transport.disconnect(); //This will force us into the
- }else{
- //Log.d(TAG, "Router service not trusted during force connect. Ignoring.");
- return;
- }
- }else{
- //Log.i(TAG, "No cached multiplexing config, ignoring");
- //_transport.disconnect();
- return;
- }
- DebugTool.logWarning(TAG, "Using own transport, but not connected. Attempting to join multiplexing");
- }else{
- DebugTool.logWarning(TAG, "Currently in legacy mode connected to own transport service. Nothing will take place on trnasport cycle");
- }
- }
-
- public static void enableLegacyMode(boolean enable, TransportType type){
- synchronized(TRANSPORT_REFERENCE_LOCK) {
- if(enable){
- legacyTransportRequest = type;
- }else{
- legacyTransportRequest = null;
- }
- }
- }
- public static boolean isLegacyModeEnabled(){
- synchronized(TRANSPORT_REFERENCE_LOCK) {
- return (legacyTransportRequest!=null);
- }
- }
-
- @Override
- public void onProtocolSessionEndedNACKed(SessionType sessionType,
- byte sessionID, String correlationID) {
- _connectionListener.onProtocolSessionEndedNACKed(sessionType, sessionID, correlationID);
-
- }
-
- @Override
- public void onProtocolServiceDataACK(SessionType serviceType, int dataSize, byte sessionID) {
- _connectionListener.onProtocolServiceDataACK(serviceType, dataSize, sessionID);
- }
-}
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java b/android/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java
deleted file mode 100644
index 6b4a2b467..000000000
--- a/android/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java
+++ /dev/null
@@ -1,195 +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.protocol;
-
-
-import com.smartdevicelink.protocol.WiProProtocol.MessageFrameAssembler;
-import com.smartdevicelink.protocol.enums.SessionType;
-
-import java.util.List;
-
-/**
- * @see SdlProtocol
- */
-@Deprecated
-public abstract class AbstractProtocol {
- private static final String SDL_LIB_TRACE_KEY = "42baba60-eb57-11df-98cf-0800200c9a66";
-
- private IProtocolListener _protocolListener = null;
- //protected IProtocolListener ProtocolListener() { return _protocolListener; }
-
- // Lock to ensure all frames are sent uninterupted
- private Object _frameLock = new Object();
-
- // Caller must provide a non-null IProtocolListener interface reference.
- public AbstractProtocol(IProtocolListener protocolListener) {
- if (protocolListener == null) {
- throw new IllegalArgumentException("Provided protocol listener interface reference is null");
- } // end-if
-
- _protocolListener = protocolListener;
- } // end-ctor
-
-
- // This method receives a protocol message (e.g. RPC, BULK, etc.) and processes
- // it for transmission over the transport. The results of this processing will
- // be sent to the onProtocolMessageBytesToSend() method on protocol listener
- // interface. Note that the ProtocolMessage itself contains information
- // about the type of message (e.g. RPC, BULK, etc.) and the protocol session
- // over which to send the message, etc.
- public abstract void SendMessage(ProtocolMessage msg);
-
- public abstract int getMtu();
- public abstract long getMtu(SessionType type);
-
- public abstract void handlePacketReceived(SdlPacket packet);
-
- // This method starts a protocol session. A corresponding call to the protocol
- // listener onProtocolSessionStarted() method will be made when the protocol
- // session has been established.
- public abstract void StartProtocolSession(SessionType sessionType);
-
- public abstract void StartProtocolService(SessionType sessionType, byte sessionID, boolean isEncrypted);
-
- public abstract void EndProtocolService(SessionType serviceType, byte sessionID);
- // This method ends a protocol session. A corresponding call to the protocol
- // listener onProtocolSessionEnded() method will be made when the protocol
- // session has ended.
- public abstract void EndProtocolSession(SessionType sessionType, byte sessionID, int hashID);
-
- // TODO REMOVE
- // This method sets the interval at which heartbeat protocol messages will be
- // sent to SDL.
- public abstract void SetHeartbeatSendInterval(int heartbeatSendInterval_ms);
-
- // This method sets the interval at which heartbeat protocol messages are
- // expected to be received from SDL.
- public abstract void SetHeartbeatReceiveInterval(int heartbeatReceiveInterval_ms);
-
- public abstract void SendHeartBeat(byte sessionID);
-
- public abstract void SendHeartBeatACK(byte sessionID);
-
- // This method is called whenever the protocol receives a complete frame
- protected void handleProtocolFrameReceived(SdlPacket packet, MessageFrameAssembler assembler) {
- //FIXME SdlTrace.logProtocolEvent(InterfaceActivityDirection.Receive, header, data,
- // 0, packet.dataSize, SDL_LIB_TRACE_KEY);
-
- assembler.handleFrame(packet);
- }
-
- private synchronized void resetOutgoingHeartbeat(SessionType sessionType, byte sessionID) {
- if (_protocolListener != null) {
- _protocolListener.onResetOutgoingHeartbeat(sessionType,sessionID);
- }
- }
-
- private synchronized void resetIncomingHeartbeat(SessionType sessionType, byte sessionID) {
- if (_protocolListener != null) {
- _protocolListener.onResetIncomingHeartbeat(sessionType,sessionID);
- }
- }
-
- // This method is called whenever a protocol has an entire frame to send
- /**
- * SdlPacket should have included payload at this point.
- * @param header
- */
- protected void handlePacketToSend(SdlPacket header) {
- //FIXME SdlTrace.logProtocolEvent(InterfaceActivityDirection.Transmit, header, data,
- // offset, length, SDL_LIB_TRACE_KEY);
- if(header == null){
- return;
- }
-
- resetOutgoingHeartbeat(SessionType.valueOf((byte)header.getServiceType()), (byte)header.getSessionId());
-
- synchronized(_frameLock) {
-
- //byte[] frameHeader = header.constructPacket();
- _protocolListener.onProtocolMessageBytesToSend(header);
-
- }
- }
-
-
- // This method handles received protocol messages.
- protected void handleProtocolMessageReceived(ProtocolMessage message) {
- _protocolListener.onProtocolMessageReceived(message);
- }
-
- // This method handles the end of a protocol session. A callback is
- // sent to the protocol listener.
- protected void handleProtocolSessionEndedNACK(SessionType sessionType,
- byte sessionID, String correlationID) {
- _protocolListener.onProtocolSessionEndedNACKed(sessionType, sessionID, correlationID);
- }
-
- // This method handles the end of a protocol session. A callback is
- // sent to the protocol listener.
- protected void handleProtocolSessionEnded(SessionType sessionType,
- byte sessionID, String correlationID) {
- _protocolListener.onProtocolSessionEnded(sessionType, sessionID, correlationID);
- }
-
- // This method handles the startup of a protocol session. A callback is sent
- // to the protocol listener.
- protected void handleProtocolSessionStarted(SessionType sessionType,
- byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) {
- _protocolListener.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID, isEncrypted);
- }
-
- protected void handleProtocolSessionNACKed(SessionType sessionType,
- byte sessionID, byte version, String correlationID, List<String> rejectedParams) {
- _protocolListener.onProtocolSessionNACKed(sessionType, sessionID, version, correlationID, rejectedParams);
- }
-
- // This method handles protocol errors. A callback is sent to the protocol
- // listener.
- protected void handleProtocolError(String string, Exception ex) {
- _protocolListener.onProtocolError(string, ex);
- }
- protected void handleProtocolHeartbeat(SessionType sessionType, byte sessionID) {
- SendHeartBeatACK(sessionID);
- _protocolListener.onProtocolHeartbeat(sessionType, sessionID);
- }
- protected void handleProtocolHeartbeatACK(SessionType sessionType, byte sessionID) {
- _protocolListener.onProtocolHeartbeatACK(sessionType, sessionID);
- }
- protected void handleProtocolServiceDataACK(SessionType sessionType, int dataSize, byte sessionID) {
- _protocolListener.onProtocolServiceDataACK(sessionType, dataSize, sessionID);
- }
- protected void onResetIncomingHeartbeat(SessionType sessionType, byte sessionID) {
- resetIncomingHeartbeat(sessionType, sessionID);
- }
-
-} // end-class
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/protocol/WiProProtocol.java b/android/sdl_android/src/main/java/com/smartdevicelink/protocol/WiProProtocol.java
deleted file mode 100644
index ad887929a..000000000
--- a/android/sdl_android/src/main/java/com/smartdevicelink/protocol/WiProProtocol.java
+++ /dev/null
@@ -1,696 +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.protocol;
-
-import com.smartdevicelink.SdlConnection.SdlConnection;
-import com.smartdevicelink.SdlConnection.SdlSession;
-import com.smartdevicelink.exception.SdlException;
-import com.smartdevicelink.exception.SdlExceptionCause;
-import com.smartdevicelink.protocol.enums.ControlFrameTags;
-import com.smartdevicelink.protocol.enums.FrameDataControlFrameType;
-import com.smartdevicelink.protocol.enums.FrameType;
-import com.smartdevicelink.protocol.enums.MessageType;
-import com.smartdevicelink.protocol.enums.SessionType;
-import com.smartdevicelink.proxy.rpc.ImageResolution;
-import com.smartdevicelink.proxy.rpc.VideoStreamingFormat;
-import com.smartdevicelink.proxy.rpc.enums.VideoStreamingCodec;
-import com.smartdevicelink.proxy.rpc.enums.VideoStreamingProtocol;
-import com.smartdevicelink.security.SdlSecurityBase;
-import com.smartdevicelink.streaming.video.VideoStreamingParameters;
-import com.smartdevicelink.util.BitConverter;
-import com.smartdevicelink.util.DebugTool;
-import com.smartdevicelink.util.Version;
-
-import java.io.ByteArrayOutputStream;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-
-/**
- * @see SdlProtocol
- */
-@Deprecated
-public class WiProProtocol extends AbstractProtocol {
- private static final String TAG = "WiProProtocol";
- private final static String FailurePropagating_Msg = "Failure propagating ";
- //If increasing MAX PROTOCOL VERSION major version, make sure to alter it in SdlPsm
- public static final Version MAX_PROTOCOL_VERSION = new Version("5.0.0");
- private Version protocolVersion = new Version("1.0.0");
- byte _version = 1;
-
- public static final int V1_V2_MTU_SIZE = 1500;
- public static final int V3_V4_MTU_SIZE = 131072;
- public static final int V1_HEADER_SIZE = 8;
- public static final int V2_HEADER_SIZE = 12;
- private static int HEADER_SIZE = 8;
- private static int TLS_MAX_RECORD_SIZE = 16384;
-
- int hashID = 0;
- int messageID = 0;
- SdlConnection sdlconn = null;
-
- @SuppressWarnings("unused")
- private int _heartbeatSendInterval_ms = 0;
- @SuppressWarnings("unused")
- private int _heartbeatReceiveInterval_ms = 0;
-
- Hashtable<Integer, MessageFrameAssembler> _assemblerForMessageID = new Hashtable<Integer, MessageFrameAssembler>();
- Hashtable<Byte, Hashtable<Integer, MessageFrameAssembler>> _assemblerForSessionID = new Hashtable<Byte, Hashtable<Integer, MessageFrameAssembler>>();
- Hashtable<Byte, Object> _messageLocks = new Hashtable<Byte, Object>();
- private HashMap<SessionType, Long> mtus = new HashMap<SessionType,Long>();
-
- // Hide no-arg ctor
- private WiProProtocol() {
- super(null);
- } // end-ctor
-
-
- public WiProProtocol(IProtocolListener protocolListener) {
- super(protocolListener);
-
- if (protocolListener instanceof SdlConnection)
- {
- sdlconn = (SdlConnection) protocolListener;
- }
- mtus.put(SessionType.RPC, new Long(V1_V2_MTU_SIZE - HEADER_SIZE));
- } // end-ctor
-
- /**
- * Retrieves the max payload size for a packet to be sent to the module
- * @return the max transfer unit
- */
- public int getMtu(){
- return mtus.get(SessionType.RPC).intValue();
- }
-
- public long getMtu(SessionType type){
- Long mtu = mtus.get(type);
- if(mtu == null){
- mtu = mtus.get(SessionType.RPC);
- }
- return mtu;
- }
-
-
- /**
- * Use getProtocolVersion() or getMajorVersionByte instead.<br>
- * Returns the Major version of the currently used protocol version
- */
- @Deprecated
- public byte getVersion() {
- return getMajorVersionByte();
- }
-
- public Version getProtocolVersion(){
- return this.protocolVersion;
- }
- public byte getMajorVersionByte(){
- if(_version == 1){
- _version = new Integer(this.protocolVersion.getMajor()).byteValue();
- }
- return _version;
-
- }
-
- /**
- * This method will set the major protocol version that we should use. It will also set the default MTU based on version.
- * @param version
- */
- public void setVersion(byte version) {
- if (version > 5) {
- this.protocolVersion = new Version("5.0.0"); //protect for future, proxy only supports v5 or lower
- HEADER_SIZE = 12;
- mtus.put(SessionType.RPC,new Long(V3_V4_MTU_SIZE) );
- } else if (version == 5) {
- this.protocolVersion = new Version("5.0.0");
- HEADER_SIZE = 12;
- mtus.put(SessionType.RPC,new Long(V3_V4_MTU_SIZE) );
- }else if (version == 4) {
- this.protocolVersion = new Version("4.0.0");
- HEADER_SIZE = 12;
- mtus.put(SessionType.RPC,new Long(V3_V4_MTU_SIZE) ); //versions 4 supports 128k MTU
- } else if (version == 3) {
- this.protocolVersion = new Version("3.0.0");
- HEADER_SIZE = 12;
- mtus.put(SessionType.RPC,new Long(V3_V4_MTU_SIZE) ); //versions 3 supports 128k MTU
- } else if (version == 2) {
- this.protocolVersion = new Version("2.0.0");
- HEADER_SIZE = 12;
- mtus.put(SessionType.RPC,new Long(V1_V2_MTU_SIZE - HEADER_SIZE) );
- } else if (version == 1){
- this.protocolVersion = new Version("1.0.0");
- HEADER_SIZE = 8;
- mtus.put(SessionType.RPC,new Long(V1_V2_MTU_SIZE - HEADER_SIZE) );
- }
- }
-
- public void StartProtocolSession(SessionType sessionType) {
- SdlPacket header = SdlPacketFactory.createStartSession(sessionType, 0x00, getMajorVersionByte(), (byte) 0x00, false);
- if(sessionType.equals(SessionType.RPC)){ // check for RPC session
- header.putTag(ControlFrameTags.RPC.StartService.PROTOCOL_VERSION, MAX_PROTOCOL_VERSION.toString());
- }
- handlePacketToSend(header);
- } // end-method
-
- private void sendStartProtocolSessionACK(SessionType sessionType, byte sessionID) {
- SdlPacket header = SdlPacketFactory.createStartSessionACK(sessionType, sessionID, 0x00, getMajorVersionByte());
- handlePacketToSend(header);
- } // end-method
-
- public void EndProtocolSession(SessionType sessionType, byte sessionID, int hashId) {
- SdlPacket header;
- if (sessionType.equals(SessionType.RPC)) { // check for RPC session
- header = SdlPacketFactory.createEndSession(sessionType, sessionID, hashID, getMajorVersionByte(), hashID);
- }else{ //Any other service type we don't include the hash id
- header = SdlPacketFactory.createEndSession(sessionType, sessionID, hashID, getMajorVersionByte(), new byte[0]);
- }
- handlePacketToSend(header);
-
- } // end-method
-
- public void SendMessage(ProtocolMessage protocolMsg) {
- SessionType sessionType = protocolMsg.getSessionType();
- byte sessionID = protocolMsg.getSessionID();
-
- byte[] data = null;
- if (protocolVersion.getMajor() > 1 && sessionType != SessionType.NAV && sessionType != SessionType.PCM) {
- if (sessionType.eq(SessionType.CONTROL)) {
- final byte[] secureData = protocolMsg.getData().clone();
- data = new byte[HEADER_SIZE + secureData.length];
-
- final BinaryFrameHeader binFrameHeader =
- SdlPacketFactory.createBinaryFrameHeader(protocolMsg.getRPCType(),protocolMsg.getFunctionID(), protocolMsg.getCorrID(), 0);
- System.arraycopy(binFrameHeader.assembleHeaderBytes(), 0, data, 0, HEADER_SIZE);
- System.arraycopy(secureData, 0, data,HEADER_SIZE, secureData.length);
- }
- else if (protocolMsg.getBulkData() != null) {
- data = new byte[12 + protocolMsg.getJsonSize() + protocolMsg.getBulkData().length];
- sessionType = SessionType.BULK_DATA;
- } else {
- data = new byte[12 + protocolMsg.getJsonSize()];
- }
- if (!sessionType.eq(SessionType.CONTROL)) {
- BinaryFrameHeader binFrameHeader = SdlPacketFactory.createBinaryFrameHeader(protocolMsg.getRPCType(), protocolMsg.getFunctionID(), protocolMsg.getCorrID(), protocolMsg.getJsonSize());
- System.arraycopy(binFrameHeader.assembleHeaderBytes(), 0, data, 0, 12);
- System.arraycopy(protocolMsg.getData(), 0, data, 12, protocolMsg.getJsonSize());
- if (protocolMsg.getBulkData() != null) {
- System.arraycopy(protocolMsg.getBulkData(), 0, data, 12 + protocolMsg.getJsonSize(), protocolMsg.getBulkData().length);
- }
- }
- } else {
- data = protocolMsg.getData();
- }
-
- if (sdlconn != null && protocolMsg.getPayloadProtected())
- {
- if (data != null && data.length > 0) {
- SdlSession session = sdlconn.findSessionById(sessionID);
-
- if (session == null)
- return;
-
- byte[] dataToRead = new byte[TLS_MAX_RECORD_SIZE];
- SdlSecurityBase sdlSec = session.getSdlSecurity();
- if (sdlSec == null)
- return;
-
- Integer iNumBytes = sdlSec.encryptData(data, dataToRead);
- if ((iNumBytes == null) || (iNumBytes <= 0))
- return;
-
- byte[] encryptedData = new byte[iNumBytes];
- System.arraycopy(dataToRead, 0, encryptedData, 0, iNumBytes);
- data = encryptedData;
- }
- }
-
- // Get the message lock for this protocol session
- Object messageLock = _messageLocks.get(sessionID);
- if (messageLock == null) {
- handleProtocolError("Error sending protocol message to SDL.",
- new SdlException("Attempt to send protocol message prior to startSession ACK.", SdlExceptionCause.SDL_UNAVAILABLE));
- return;
- }
-
- synchronized(messageLock) {
- if (data.length > getMtu(sessionType)) {
-
- messageID++;
-
- // Assemble first frame.
- Long mtu = getMtu(sessionType);
- int frameCount = new Long(data.length / mtu).intValue();
- if (data.length % mtu > 0) {
- frameCount++;
- }
- //byte[] firstFrameData = new byte[HEADER_SIZE];
- byte[] firstFrameData = new byte[8];
- // First four bytes are data size.
- System.arraycopy(BitConverter.intToByteArray(data.length), 0, firstFrameData, 0, 4);
- // Second four bytes are frame count.
- System.arraycopy(BitConverter.intToByteArray(frameCount), 0, firstFrameData, 4, 4);
-
- SdlPacket firstHeader = SdlPacketFactory.createMultiSendDataFirst(sessionType, sessionID, messageID, getMajorVersionByte(),firstFrameData,protocolMsg.getPayloadProtected());
- firstHeader.setPriorityCoefficient(1+protocolMsg.priorityCoefficient);
- //Send the first frame
- handlePacketToSend(firstHeader);
-
- int currentOffset = 0;
- byte frameSequenceNumber = 0;
-
- for (int i = 0; i < frameCount; i++) {
- if (i < (frameCount - 1)) {
- ++frameSequenceNumber;
- if (frameSequenceNumber ==
- SdlPacket.FRAME_INFO_FINAL_CONNESCUTIVE_FRAME) {
- // we can't use 0x00 as frameSequenceNumber, because
- // it's reserved for the last frame
- ++frameSequenceNumber;
- }
- } else {
- frameSequenceNumber = SdlPacket.FRAME_INFO_FINAL_CONNESCUTIVE_FRAME;
- } // end-if
-
- int bytesToWrite = data.length - currentOffset;
- if (bytesToWrite > mtu) {
- bytesToWrite = mtu.intValue();
- }
- SdlPacket consecHeader = SdlPacketFactory.createMultiSendDataRest(sessionType, sessionID, bytesToWrite, frameSequenceNumber , messageID, getMajorVersionByte(),data, currentOffset, bytesToWrite, protocolMsg.getPayloadProtected());
- consecHeader.setPriorityCoefficient(i+2+protocolMsg.priorityCoefficient);
- handlePacketToSend(consecHeader);
- currentOffset += bytesToWrite;
- }
- } else {
- messageID++;
- SdlPacket header = SdlPacketFactory.createSingleSendData(sessionType, sessionID, data.length, messageID, getMajorVersionByte(),data, protocolMsg.getPayloadProtected());
- header.setPriorityCoefficient(protocolMsg.priorityCoefficient);
- handlePacketToSend(header);
- }
- }
- }
-
- public void handlePacketReceived(SdlPacket packet){
- //Check for a version difference
- if (getMajorVersionByte() == 1) {
- setVersion((byte)packet.version);
- }
-
- MessageFrameAssembler assembler = getFrameAssemblerForFrame(packet);
- assembler.handleFrame(packet);
-
- onResetIncomingHeartbeat(SessionType.valueOf((byte)packet.getServiceType()), (byte)packet.getSessionId());
-
- }
-
-
-
- protected MessageFrameAssembler getFrameAssemblerForFrame(SdlPacket packet) {
- Integer iSessionId = Integer.valueOf(packet.getSessionId());
- Byte bySessionId = iSessionId.byteValue();
-
- Hashtable<Integer, MessageFrameAssembler> hashSessionID = _assemblerForSessionID.get(bySessionId);
- if (hashSessionID == null) {
- hashSessionID = new Hashtable<Integer, MessageFrameAssembler>();
- _assemblerForSessionID.put(bySessionId, hashSessionID);
- } // end-if
-
- MessageFrameAssembler ret = (MessageFrameAssembler) _assemblerForMessageID.get(Integer.valueOf(packet.getMessageId()));
- if (ret == null) {
- ret = new MessageFrameAssembler();
- _assemblerForMessageID.put(Integer.valueOf(packet.getMessageId()), ret);
- } // end-if
-
- return ret;
- } // end-method
-
- protected class MessageFrameAssembler {
- protected boolean hasFirstFrame = false;
- protected ByteArrayOutputStream accumulator = null;
- protected int totalSize = 0;
- protected int framesRemaining = 0;
-
- protected void handleFirstDataFrame(SdlPacket packet) {
- //The message is new, so let's figure out how big it is.
- hasFirstFrame = true;
- totalSize = BitConverter.intFromByteArray(packet.payload, 0) - HEADER_SIZE;
- framesRemaining = BitConverter.intFromByteArray(packet.payload, 4);
- try {
- accumulator = new ByteArrayOutputStream(totalSize);
- }catch(OutOfMemoryError e){
- DebugTool.logError(TAG, "OutOfMemory error", e); //Garbled bits were received
- accumulator = null;
- }
- }
-
- protected void handleRemainingFrame(SdlPacket packet) {
- accumulator.write(packet.payload, 0, (int)packet.getDataSize());
- notifyIfFinished(packet);
- }
-
- protected void notifyIfFinished(SdlPacket packet) {
- //if (framesRemaining == 0) {
- if (packet.getFrameType() == FrameType.Consecutive && packet.getFrameInfo() == 0x0)
- {
- ProtocolMessage message = new ProtocolMessage();
- message.setPayloadProtected(packet.isEncrypted());
- message.setSessionType(SessionType.valueOf((byte)packet.getServiceType()));
- message.setSessionID((byte)packet.getSessionId());
- //If it is WiPro 2.0 it must have binary header
- if (protocolVersion.getMajor() > 1) {
- BinaryFrameHeader binFrameHeader = BinaryFrameHeader.
- parseBinaryHeader(accumulator.toByteArray());
- if(binFrameHeader == null) {
- return;
- }
- message.setVersion(getMajorVersionByte());
- message.setRPCType(binFrameHeader.getRPCType());
- message.setFunctionID(binFrameHeader.getFunctionID());
- message.setCorrID(binFrameHeader.getCorrID());
- if (binFrameHeader.getJsonSize() > 0) message.setData(binFrameHeader.getJsonData());
- if (binFrameHeader.getBulkData() != null) message.setBulkData(binFrameHeader.getBulkData());
- } else{
- message.setData(accumulator.toByteArray());
- }
-
- _assemblerForMessageID.remove(packet.getMessageId());
-
- try {
- handleProtocolMessageReceived(message);
- } catch (Exception excp) {
- DebugTool.logError(TAG, FailurePropagating_Msg + "onProtocolMessageReceived: " + excp.toString(), excp);
- } // end-catch
-
- hasFirstFrame = false;
- accumulator = null;
- } // end-if
- } // end-method
-
- protected void handleMultiFrameMessageFrame(SdlPacket packet) {
- if (packet.getFrameType() == FrameType.First){
- handleFirstDataFrame(packet);
- }
- else{
- if(accumulator != null)
- handleRemainingFrame(packet);
- }
-
- } // end-method
-
- protected void handleFrame(SdlPacket packet) {
-
- if (packet.getPayload() != null && packet.getDataSize() > 0 && packet.isEncrypted() )
- {
- if (sdlconn != null)
- {
- SdlSession session = sdlconn.findSessionById((byte)packet.getSessionId());
-
- if (session == null)
- return;
-
- SdlSecurityBase sdlSec = session.getSdlSecurity();
- byte[] dataToRead = new byte[4096];
-
- Integer iNumBytes = sdlSec.decryptData(packet.getPayload(), dataToRead);
- if ((iNumBytes == null) || (iNumBytes <= 0))
- return;
-
- byte[] decryptedData = new byte[iNumBytes];
- System.arraycopy(dataToRead, 0, decryptedData, 0, iNumBytes);
- packet.payload = decryptedData;
- }
- }
-
- if (packet.getFrameType().equals(FrameType.Control)) {
- handleControlFrame(packet);
- } else {
- // Must be a form of data frame (single, first, consecutive, etc.)
- if ( packet.getFrameType() == FrameType.First
- || packet.getFrameType() == FrameType.Consecutive
- ) {
- handleMultiFrameMessageFrame(packet);
- } else {
- handleSingleFrameMessageFrame(packet);
- }
- } // end-if
- } // end-method
-
- private void handleProtocolHeartbeatACK(SdlPacket packet) {
- WiProProtocol.this.handleProtocolHeartbeatACK(SessionType.valueOf((byte)packet.getServiceType()),(byte)packet.getSessionId());
- } // end-method
- private void handleProtocolHeartbeat(SdlPacket packet) {
- WiProProtocol.this.handleProtocolHeartbeat(SessionType.valueOf((byte)packet.getServiceType()),(byte)packet.getSessionId());
- } // end-method
-
- private void handleControlFrame(SdlPacket packet) {
- Integer frameTemp = Integer.valueOf(packet.getFrameInfo());
- Byte frameInfo = frameTemp.byteValue();
-
- SessionType serviceType = SessionType.valueOf((byte)packet.getServiceType());
-
- if (frameInfo == FrameDataControlFrameType.Heartbeat.getValue()) {
- handleProtocolHeartbeat(packet);
- }
- if (frameInfo == FrameDataControlFrameType.HeartbeatACK.getValue()) {
- handleProtocolHeartbeatACK(packet);
- }
- else if (frameInfo == FrameDataControlFrameType.StartSession.getValue()) {
- sendStartProtocolSessionACK(serviceType, (byte)packet.getSessionId());
- } else if (frameInfo == FrameDataControlFrameType.StartSessionACK.getValue()) {
- // Use this sessionID to create a message lock
- Object messageLock = _messageLocks.get(packet.getSessionId());
- if (messageLock == null) {
- messageLock = new Object();
- _messageLocks.put((byte)packet.getSessionId(), messageLock);
- }
- if(packet.version >= 5){
- String mtuTag = null;
- if(serviceType.equals(SessionType.RPC)){
- mtuTag = ControlFrameTags.RPC.StartServiceACK.MTU;
- }else if(serviceType.equals(SessionType.PCM)){
- mtuTag = ControlFrameTags.Audio.StartServiceACK.MTU;
- }else if(serviceType.equals(SessionType.NAV)){
- mtuTag = ControlFrameTags.Video.StartServiceACK.MTU;
- }
- Object mtu = packet.getTag(mtuTag);
- if(mtu!=null){
- mtus.put(serviceType,(Long) packet.getTag(mtuTag));
- }
- if(serviceType.equals(SessionType.RPC)){
- hashID = (Integer) packet.getTag(ControlFrameTags.RPC.StartServiceACK.HASH_ID);
- Object version = packet.getTag(ControlFrameTags.RPC.StartServiceACK.PROTOCOL_VERSION);
- if(version!=null){
- //At this point we have confirmed the negotiated version between the module and the proxy
- protocolVersion = new Version((String)version);
- }
- }else if(serviceType.equals(SessionType.NAV)){
- SdlSession session = sdlconn.findSessionById((byte) packet.sessionId);
- if(session != null) {
- ImageResolution acceptedResolution = new ImageResolution();
- VideoStreamingFormat acceptedFormat = new VideoStreamingFormat();
- acceptedResolution.setResolutionHeight((Integer) packet.getTag(ControlFrameTags.Video.StartServiceACK.HEIGHT));
- acceptedResolution.setResolutionWidth((Integer) packet.getTag(ControlFrameTags.Video.StartServiceACK.WIDTH));
- acceptedFormat.setCodec(VideoStreamingCodec.valueForString((String) packet.getTag(ControlFrameTags.Video.StartServiceACK.VIDEO_CODEC)));
- acceptedFormat.setProtocol(VideoStreamingProtocol.valueForString((String) packet.getTag(ControlFrameTags.Video.StartServiceACK.VIDEO_PROTOCOL)));
- VideoStreamingParameters agreedVideoParams = session.getDesiredVideoParams();
- agreedVideoParams.setResolution(acceptedResolution);
- agreedVideoParams.setFormat(acceptedFormat);
- session.setAcceptedVideoParams(agreedVideoParams);
- }
- }
- }else{
- if (protocolVersion.getMajor() > 1){
- if (packet.payload!= null && packet.dataSize == 4){ //hashid will be 4 bytes in length
- hashID = BitConverter.intFromByteArray(packet.payload, 0);
- }
- }
- }
- handleProtocolSessionStarted(serviceType,(byte) packet.getSessionId(), getMajorVersionByte(), "", hashID, packet.isEncrypted());
-
- if(serviceType.equals(SessionType.RPC)
- && protocolVersion.isNewerThan(new Version(5,2,0)) >= 0){
- // This has to be done after the session has been established because
- // SdlConnection is just setup that way
- String authToken = (String)packet.getTag(ControlFrameTags.RPC.StartServiceACK.AUTH_TOKEN);
- if(authToken != null){
- sdlconn.onAuthTokenReceived(authToken, (byte)packet.getSessionId());
- }
- }
- } else if (frameInfo == FrameDataControlFrameType.StartSessionNACK.getValue()) {
- List<String> rejectedParams = null;
- if(packet.version >= 5){
- String rejectedTag = null;
- if(serviceType.equals(SessionType.RPC)){
- rejectedTag = ControlFrameTags.RPC.StartServiceNAK.REJECTED_PARAMS;
- }else if(serviceType.equals(SessionType.PCM)){
- rejectedTag = ControlFrameTags.Audio.StartServiceNAK.REJECTED_PARAMS;
- }else if(serviceType.equals(SessionType.NAV)){
- rejectedTag = ControlFrameTags.Video.StartServiceNAK.REJECTED_PARAMS;
- }
- rejectedParams = (List<String>) packet.getTag(rejectedTag);
- }
- if (serviceType.eq(SessionType.NAV) || serviceType.eq(SessionType.PCM)) {
- handleProtocolSessionNACKed(serviceType, (byte)packet.getSessionId(), getMajorVersionByte(), "", rejectedParams);
- } else {
- handleProtocolError("Got StartSessionNACK for protocol sessionID=" + packet.getSessionId(), null);
- }
- } else if (frameInfo == FrameDataControlFrameType.EndSession.getValue()) {
- if (protocolVersion.getMajor() > 1) {
- handleProtocolSessionEnded(serviceType, (byte)packet.getSessionId(), "");
- } else {
- handleProtocolSessionEnded(serviceType, (byte)packet.getSessionId(), "");
- }
- } else if (frameInfo == FrameDataControlFrameType.EndSessionACK.getValue()) {
- handleProtocolSessionEnded(serviceType, (byte)packet.getSessionId(), "");
- } else if (frameInfo == FrameDataControlFrameType.EndSessionNACK.getValue()) {
- if(packet.version >= 5){
- String rejectedTag = null;
- if(serviceType.equals(SessionType.RPC)){
- rejectedTag = ControlFrameTags.RPC.EndServiceNAK.REJECTED_PARAMS;
- }else if(serviceType.equals(SessionType.PCM)){
- rejectedTag = ControlFrameTags.Audio.EndServiceNAK.REJECTED_PARAMS;
- }else if(serviceType.equals(SessionType.NAV)){
- rejectedTag = ControlFrameTags.Video.EndServiceNAK.REJECTED_PARAMS;
- }
- List<String> rejectedParams = (List<String>) packet.getTag(rejectedTag);
- // TODO: Pass these back
- }
- handleProtocolSessionEndedNACK(serviceType, (byte)packet.getSessionId(), "");
- } else if (frameInfo == FrameDataControlFrameType.ServiceDataACK.getValue()) {
- if (packet.getPayload() != null && packet.getDataSize() == 4) //service data ack will be 4 bytes in length
- {
- int serviceDataAckSize = BitConverter.intFromByteArray(packet.getPayload(), 0);
- handleProtocolServiceDataACK(serviceType, serviceDataAckSize,(byte)packet.getSessionId ());
- }
- }
- _assemblerForMessageID.remove(packet.getMessageId());
- } // end-method
-
- private void handleSingleFrameMessageFrame(SdlPacket packet) {
- ProtocolMessage message = new ProtocolMessage();
- message.setPayloadProtected(packet.isEncrypted());
- SessionType serviceType = SessionType.valueOf((byte)packet.getServiceType());
- if (serviceType == SessionType.RPC) {
- message.setMessageType(MessageType.RPC);
- } else if (serviceType == SessionType.BULK_DATA) {
- message.setMessageType(MessageType.BULK);
- } // end-if
- message.setSessionType(serviceType);
- message.setSessionID((byte)packet.getSessionId());
- //If it is WiPro 2.0 it must have binary header
- boolean isControlService = message.getSessionType().equals(SessionType.CONTROL);
- if (protocolVersion.getMajor() > 1 && !isControlService) {
- BinaryFrameHeader binFrameHeader = BinaryFrameHeader.
- parseBinaryHeader(packet.payload);
- if(binFrameHeader == null) {
- return;
- }
- message.setVersion(getMajorVersionByte());
- message.setRPCType(binFrameHeader.getRPCType());
- message.setFunctionID(binFrameHeader.getFunctionID());
- message.setCorrID(binFrameHeader.getCorrID());
- if (binFrameHeader.getJsonSize() > 0){
- message.setData(binFrameHeader.getJsonData());
- }
- if (binFrameHeader.getBulkData() != null){
- message.setBulkData(binFrameHeader.getBulkData());
- }
- } else {
- message.setData(packet.payload);
- }
-
- _assemblerForMessageID.remove(packet.getMessageId());
-
- try {
- handleProtocolMessageReceived(message);
- } catch (Exception ex) {
- DebugTool.logError(TAG,FailurePropagating_Msg + "onProtocolMessageReceived: " + ex.toString(), ex);
- handleProtocolError(FailurePropagating_Msg + "onProtocolMessageReceived: ", ex);
- } // end-catch
- } // end-method
- } // end-class
-
- @Override
- public void StartProtocolService(SessionType sessionType, byte sessionID, boolean isEncrypted) {
- SdlPacket header = SdlPacketFactory.createStartSession(sessionType, 0x00, getMajorVersionByte(), sessionID, isEncrypted);
- if(sessionType.equals(SessionType.NAV)){
- SdlSession videoSession = sdlconn.findSessionById(sessionID);
- if(videoSession != null){
- ImageResolution desiredResolution = videoSession.getDesiredVideoParams().getResolution();
- VideoStreamingFormat desiredFormat = videoSession.getDesiredVideoParams().getFormat();
- if(desiredResolution != null){
- header.putTag(ControlFrameTags.Video.StartService.WIDTH, desiredResolution.getResolutionWidth());
- header.putTag(ControlFrameTags.Video.StartService.HEIGHT, desiredResolution.getResolutionHeight());
- }
- if(desiredFormat != null){
- header.putTag(ControlFrameTags.Video.StartService.VIDEO_CODEC, desiredFormat.getCodec().toString());
- header.putTag(ControlFrameTags.Video.StartService.VIDEO_PROTOCOL, desiredFormat.getProtocol().toString());
- }
- }
- }
- handlePacketToSend(header);
- }
-
- @Override
- public void SetHeartbeatSendInterval(int heartbeatSendInterval_ms) {
- _heartbeatSendInterval_ms = heartbeatSendInterval_ms;
-
- }
-
- @Override
- public void SetHeartbeatReceiveInterval(int heartbeatReceiveInterval_ms) {
- _heartbeatReceiveInterval_ms = heartbeatReceiveInterval_ms;
-
- }
-
- @Override
- public void SendHeartBeat(byte sessionID) {
- final SdlPacket heartbeat = SdlPacketFactory.createHeartbeat(SessionType.CONTROL, sessionID, getMajorVersionByte());
- handlePacketToSend(heartbeat);
- }
-
- @Override
- public void SendHeartBeatACK(byte sessionID) {
- final SdlPacket heartbeat = SdlPacketFactory.createHeartbeatACK(SessionType.CONTROL, sessionID, getMajorVersionByte());
- handlePacketToSend(heartbeat);
- }
-
- @Override
- public void EndProtocolService(SessionType serviceType, byte sessionID) {
- if(serviceType.equals(SessionType.RPC)){ //RPC session will close all other sessions so we want to make sure we use the correct EndProtocolSession method
- EndProtocolSession(serviceType,sessionID,hashID);
- }else {
- SdlPacket header = SdlPacketFactory.createEndSession(serviceType, sessionID, hashID, getMajorVersionByte(), new byte[0]);
- handlePacketToSend(header);
- }
- }
-
-} // end-class \ No newline at end of file
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/streaming/StreamPacketizer.java b/android/sdl_android/src/main/java/com/smartdevicelink/streaming/StreamPacketizer.java
index 38164270b..2d40d4c49 100644
--- a/android/sdl_android/src/main/java/com/smartdevicelink/streaming/StreamPacketizer.java
+++ b/android/sdl_android/src/main/java/com/smartdevicelink/streaming/StreamPacketizer.java
@@ -31,7 +31,6 @@
*/
package com.smartdevicelink.streaming;
-import com.smartdevicelink.SdlConnection.SdlConnection;
import com.smartdevicelink.SdlConnection.SdlSession;
import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.protocol.ProtocolMessage;
@@ -66,7 +65,6 @@ public class StreamPacketizer extends AbstractPacketizer implements IVideoStream
// a limit of the buffer size, we avoid buffer overflows when underlying transport is too slow.
private static final int MAX_QUEUE_SIZE = 256 * 1024;
- public SdlConnection sdlConnection = null; //TODO remove completely
private Object mPauseLock;
private boolean mPaused;
private boolean isServiceProtected = false;
@@ -185,13 +183,7 @@ public class StreamPacketizer extends AbstractPacketizer implements IVideoStream
}
finally
{
- if(_session == null) {
- if (sdlConnection != null) {
- sdlConnection.endService(_serviceType, _rpcSessionID);
- }
- }else{
- _session.endService(_serviceType,_rpcSessionID);
- }
+ _session.endService(_serviceType,_rpcSessionID);
}
}
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/BTTransport.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/BTTransport.java
deleted file mode 100644
index f86a3f062..000000000
--- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/BTTransport.java
+++ /dev/null
@@ -1,586 +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.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothServerSocket;
-import android.bluetooth.BluetoothSocket;
-import android.os.Build;
-import android.os.Build.VERSION;
-
-import com.smartdevicelink.SdlConnection.SdlConnection;
-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.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.reflect.Field;
-import java.util.UUID;
-
-/**
- * Bluetooth Transport Implementation. This transport advertises its existence to SDL by publishing an SDP record and waiting for an incoming connection from SDL. Connection is verified by checking for the SDL UUID. For more detailed information please refer to the <a href="#bluetoothTransport">Bluetooth Transport Guide</a>.
- *
- */
-@Deprecated
-public class BTTransport extends SdlTransport {
- private static final String TAG = "BTTransport";
- //936DA01F9ABD4D9D80C702AF85C822A8
- private final static UUID SDL_V4_MOBILE_APPLICATION_SVC_CLASS = new UUID(0x936DA01F9ABD4D9DL, 0x80C702AF85C822A8L);
-
- private static final String SDL_LIB_TRACE_KEY = "42baba60-eb57-11df-98cf-0800200c9a66";
-
- private static final int READ_BUFFER_SIZE = 4096;
-
- private BluetoothAdapter _adapter = null;
- private BluetoothSocket _activeSocket = null;
- private UUID _listeningServiceUUID = SDL_V4_MOBILE_APPLICATION_SVC_CLASS;
- private BluetoothAdapterMonitor _bluetoothAdapterMonitor = null;
- private TransportReaderThread _transportReader = null;
- private OutputStream _output = null;
- private BluetoothServerSocket _serverSocket = null;
-
- private String sComment = "";
- private boolean bKeepSocketActive = true;
-
- // Boolean to monitor if the transport is in a disconnecting state
- private boolean _disconnecting = false;
-
- private final Object DISCONNECT_LOCK = new Object();
-
- public BTTransport(ITransportListener transportListener) {
- super(transportListener);
- } // end-ctor
-
- public BTTransport(ITransportListener transportListener, boolean bKeepSocket) {
- super(transportListener);
- bKeepSocketActive = bKeepSocket;
- } // end-ctor
-
- @Deprecated
- public BluetoothSocket getBTSocket(BluetoothServerSocket bsSocket){
-
- if(bsSocket == null || Build.VERSION.SDK_INT > Build.VERSION_CODES.O) { //Reflection is no longer allowed on SDK classes)
- return null;
- }
-
- Field[] f = bsSocket.getClass().getDeclaredFields();
-
- @SuppressWarnings("unused")
- int channel = -1;
-
- BluetoothSocket mySocket = null;
-
- for (Field field : f) {
- if(field.getName().equals("mSocket")){
- field.setAccessible(true);
- try {
-
- mySocket = (BluetoothSocket) field.get(bsSocket);
- return mySocket;
- //channel = field.getInt(bsSocket);
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- field.setAccessible(false);
- }
- }
-
- return null;
- }
-
- @Deprecated
- public int getChannel(BluetoothSocket bsSocket){
-
- int channel = -1;
- if (bsSocket == null || Build.VERSION.SDK_INT > Build.VERSION_CODES.O){ //Reflection is no longer allowed on SDK classes
- return channel;
- }
-
- Field[] f = bsSocket.getClass().getDeclaredFields();
-
- for (Field field : f) {
- if(field.getName().equals("mPort")){
- field.setAccessible(true);
- try {
-
-
- channel = field.getInt(bsSocket);
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- field.setAccessible(false);
- }
- }
-
- return channel;
- }
-
-
- /* private BluetoothServerSocket getBluetoothServerSocket() throws IOException {
- BluetoothServerSocket tmp;
-
- BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
-
-
- try {
- // compatibility with pre SDK 10 devices
- Method listener = mBluetoothAdapter.getClass().getMethod(
- "listenUsingRfcommWithServiceRecord", String.class, UUID.class);
- tmp = (BluetoothServerSocket) listener.invoke(mBluetoothAdapter, "SdlProxy", _listeningServiceUUID);
-
- } catch (NoSuchMethodException e) {
-
- throw new IOException(e);
- } catch (InvocationTargetException e) {
- throw new IOException(e);
- } catch (IllegalAccessException e) {
- throw new IOException(e);
- }
-
- return tmp;
- }*/
-
-
- public void openConnection () throws SdlException {
- if (_serverSocket != null) {
- return;
- }
-
- // Get the device's default Bluetooth Adapter
- _adapter = BluetoothAdapter.getDefaultAdapter();
-
-
- // Test if Adapter exists
- if (_adapter == null) {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("No Bluetooth adapter found. Bluetooth adapter must exist to communicate with SDL.", SdlExceptionCause.BLUETOOTH_ADAPTER_NULL);
- }
-
- // Test if Bluetooth is enabled
- try {
- if (!_adapter.isEnabled()) {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Bluetooth adapter must be enabled to instantiate a SdlProxy object.", SdlExceptionCause.BLUETOOTH_DISABLED);
- }
- } catch (SecurityException e) {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Insufficient permissions to interact with the Bluetooth Adapter.", SdlExceptionCause.PERMISSION_DENIED);
- }
-
- // Start BluetoothAdapterMonitor to ensure the Bluetooth Adapter continues to be enabled
- _bluetoothAdapterMonitor = new BluetoothAdapterMonitor(_adapter);
-
- try {
- _serverSocket = _adapter.listenUsingRfcommWithServiceRecord("SdlProxy", _listeningServiceUUID);
- BluetoothSocket mySock = getBTSocket(_serverSocket);
- int iSocket = getChannel(mySock);
-
- sComment = "Accepting Connections on SDP Server Port Number: " + iSocket + "\r\n";
- sComment += "Keep Server Socket Open: " + bKeepSocketActive;
- if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O && iSocket < 0)
- {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Could not open connection to SDL.", SdlExceptionCause.BLUETOOTH_SOCKET_UNAVAILABLE);
- }
- } catch (IOException e) {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Could not open connection to SDL.", SdlExceptionCause.BLUETOOTH_SOCKET_UNAVAILABLE);
-
- } catch (Exception ex) {
-
- // Test to determine if the bluetooth has been disabled since last check
- if (!_adapter.isEnabled()) {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Bluetooth adapter must be on to instantiate a SdlProxy object.", SdlExceptionCause.BLUETOOTH_DISABLED);
- }
-
- if(ex instanceof SdlException && ((SdlException) ex).getSdlExceptionCause() == SdlExceptionCause.BLUETOOTH_SOCKET_UNAVAILABLE) {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Could not open connection to SDL.", SdlExceptionCause.BLUETOOTH_SOCKET_UNAVAILABLE);
-
- }
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Could not open connection to SDL.", ex, SdlExceptionCause.SDL_CONNECTION_FAILED);
- }
-
- // Test to ensure serverSocket is not null
- if (_serverSocket == null) {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Could not open connection to SDL.", SdlExceptionCause.SDL_CONNECTION_FAILED);
- }
-
- SdlTrace.logTransportEvent("BTTransport: listening for incoming connect to service ID " + _listeningServiceUUID, null, InterfaceActivityDirection.Receive, null, 0, SDL_LIB_TRACE_KEY);
-
- // Setup transportReader thread
- _transportReader = new TransportReaderThread();
- _transportReader.setName("TransportReader");
- _transportReader.setDaemon(true);
- _transportReader.start();
-
- // Initialize the SiphonServer
- if (SiphonServer.getSiphonEnabledStatus()) {
- SiphonServer.init();
- }
-
- } // end-method
-
- public void disconnect() {
- disconnect(null, null);
- }
-
- /**
- * Destroys the transport between SDL and the mobile app
- *
- * @param msg
- * @param ex
- */
- private void disconnect(String msg, Exception ex) {
- synchronized(DISCONNECT_LOCK) {
- // If already disconnecting, return
- if (_disconnecting) {
- // No need to recursively call
- return;
- }
- _disconnecting = true;
- }
-
- String disconnectMsg = (msg == null ? "" : msg);
- if (ex != null) {
- disconnectMsg += ", " + ex.toString();
- } // end-if
-
- SdlTrace.logTransportEvent("BTTransport.disconnect: " + disconnectMsg, null, InterfaceActivityDirection.Transmit, null, 0, SDL_LIB_TRACE_KEY);
-
- try {
- if (_transportReader != null) {
- _transportReader.halt();
- _transportReader = null;
- }
- } catch (Exception e) {
- DebugTool.logError(TAG, "Failed to stop transport reader thread.", e);
- } // end-catch
-
- try {
- if (_bluetoothAdapterMonitor != null) {
- _bluetoothAdapterMonitor.halt();
- _bluetoothAdapterMonitor = null;
- }
- } catch (Exception e) {
- DebugTool.logError(TAG, "Failed to stop adapter monitor thread.", e);
- }
-
- try {
- if (_serverSocket != null) {
- _serverSocket.close();
- _serverSocket = null;
- }
- } catch (Exception e) {
- DebugTool.logError(TAG, "Failed to close serverSocket", e);
- } // end-catch
-
- try {
- if (_activeSocket != null) {
- _activeSocket.close();
- _activeSocket = null;
- }
- } catch (Exception e) {
- DebugTool.logError(TAG, "Failed to close activeSocket", e);
- } // end-catch
-
-
-
- try {
- if (_output != null) {
- _output.close();
- _output = null;
- }
- } catch (Exception e) {
- DebugTool.logError(TAG, "Failed to close output stream", e);
- } // end-catch
-
- if (ex == null) {
- // This disconnect was not caused by an error, notify the proxy that
- // the trasport has been disconnected.
- handleTransportDisconnected(msg);
- } else {
- // This disconnect was caused by an error, notify the proxy
- // that there was a transport error.
- handleTransportError(msg, ex);
- }
- _disconnecting = false;
- } // end-method
-
-
- /**
- * Sends data over the transport. Takes a byte array and transmits data provided starting at the
- * offset and of the provided length to fragment transmission.
- */
- public boolean sendBytesOverTransport(SdlPacket packet) {
- boolean sendResult = false;
- try {
- byte[] msgBytes = packet.constructPacket();
- _output.write(msgBytes, 0, msgBytes.length);
- sendResult = true;
- } catch (Exception ex) {
- DebugTool.logError(TAG, "Error writing to Bluetooth socket: " + ex.toString(), ex);
- handleTransportError("Error writing to Bluetooth socket:", ex);
- sendResult = false;
- } // end-catch
- return sendResult;
- } // end-method
-
-
-
- private class TransportReaderThread extends Thread {
- private Boolean isHalted = false;
- SdlPsm psm;
- int bytesRead = 0;
- byte[] buffer = new byte[READ_BUFFER_SIZE];
- byte currentByte = -1;
- boolean stateProgress = false;
-
- private InputStream _input = null;
-
-
- public TransportReaderThread(){
- psm = new SdlPsm();
- }
- public void halt() {
- isHalted = true;
- }
-
- private void acceptConnection() {
- SdlTrace.logTransportEvent("BTTransport: Waiting for incoming RFCOMM connect", "", InterfaceActivityDirection.Receive, null, 0, SDL_LIB_TRACE_KEY);
-
- try {
- // Blocks thread until connection established.
- _activeSocket = _serverSocket.accept();
-
- // If halted after serverSocket.accept(), then return immediately
- if (isHalted) {
- return;
- }
-
- // Log info of the connected device
- BluetoothDevice btDevice = _activeSocket.getRemoteDevice();
- String btDeviceInfoXml = SdlTrace.getBTDeviceInfo(btDevice);
- SdlTrace.logTransportEvent("BTTransport: RFCOMM Connection Accepted", btDeviceInfoXml, InterfaceActivityDirection.Receive, null, 0, SDL_LIB_TRACE_KEY);
-
- _output = _activeSocket.getOutputStream();
- _input = _activeSocket.getInputStream();
-
- handleTransportConnected();
-
- } catch (Exception e) {
- if (!isHalted) {
- // Only call disconnect if the thread has not been halted
- clearInputStream();
- // Check to see if Bluetooth was disabled
- if (_adapter != null && !_adapter.isEnabled()) {
- disconnect("Bluetooth Adapater has been disabled.", new SdlException("Bluetooth adapter must be enabled to instantiate a SdlProxy object.", e, SdlExceptionCause.BLUETOOTH_DISABLED));
- } else {
- disconnect("Failed to accept connection", e);
- }
- }
- } finally {
-
- if (!bKeepSocketActive && _serverSocket != null && !isHalted && (VERSION.SDK_INT > 0x00000010 /*VERSION_CODES.JELLY_BEAN*/) ) {
- try {
- _serverSocket.close();
- } catch (IOException e) {
- //do nothing
- }
- _serverSocket = null;
- }
- }
- }
-
- private void readFromTransport() {
- try {
- try {
- bytesRead = _input.read(buffer);
- } catch (Exception e) {
- if (!isHalted) {
- // Only call disconnect if the thread has not been halted
- clearInputStream();
- // Check to see if Bluetooth was disabled
- if (_adapter != null && !_adapter.isEnabled()) {
- disconnect("Bluetooth Adapater has been disabled.", new SdlException("Bluetooth adapter must be enabled to instantiate a SdlProxy object.", e, SdlExceptionCause.BLUETOOTH_DISABLED));
- } else {
- disconnect("Failed to read from Bluetooth transport.", e);
- }
- }
- return;
- } // end-catch
-
- for (int i = 0; i < bytesRead; i++) {
- currentByte = buffer[i];
- stateProgress = psm.handleByte(currentByte);
- 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(currentByte == -1){ //If we read a -1 and the psm didn't move forward, then there is a problem
- if (!isHalted) {
- // Only call disconnect if the thread has not been halted
- DebugTool.logError(TAG, "End of stream reached!");
- disconnect("End of stream reached.", null);
- }
- }
- }
- if(psm.getState() == SdlPsm.FINISHED_STATE){
- //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();
- }
- }
-
- } catch (Exception excp) {
- if (!isHalted) {
- // Only call disconnect if the thread has not been halted
- clearInputStream();
- String errString = "Failure in BTTransport reader thread: " + excp.toString();
- DebugTool.logError(TAG, errString, excp);
- disconnect(errString, excp);
- }
- return;
- } // end-catch
- } // end-method
-
- private void clearInputStream(){
- try {
- if (_input != null) {
- _input.close();
- _input = null;
- }
- } catch (Exception e) {
- DebugTool.logError(TAG, "Failed to close input stream", e);
- } // end-catch
- }
-
- public void run() {
- // acceptConnection blocks until the connection has been accepted
- acceptConnection();
- psm.reset();
- while (!isHalted) {
- readFromTransport();
- }
- }
- }
-
- private class BluetoothAdapterMonitor {
- private boolean _isHalted = false;
- private BluetoothAdapter _bluetoothAdapter = null;
- private final String THREAD_NAME = "BluetoothAdapterMonitor";
- private Thread _bluetoothAdapterMonitorThread = null;
-
- public BluetoothAdapterMonitor(BluetoothAdapter bluetoothAdapter) {
- if (bluetoothAdapter == null) {
- throw new IllegalArgumentException("BluetoothAdapter cannot be null.");
- }
-
- // Set the bluetooth adapter
- _bluetoothAdapter = bluetoothAdapter;
-
- _bluetoothAdapterMonitorThread = new Thread(new Runnable() {
- @Override
- public void run() {
- while (!_isHalted) {
- checkIfBluetoothAdapterDisabled();
- try {
- Thread.sleep(15000);
- } catch (InterruptedException e) {
- // Break if interrupted
- break;
- }
- }
- }
- });
- _bluetoothAdapterMonitorThread.setName(THREAD_NAME);
- _bluetoothAdapterMonitorThread.setDaemon(true);
- _bluetoothAdapterMonitorThread.start();
- }
-
- private void checkIfBluetoothAdapterDisabled() {
- if (_bluetoothAdapter != null && !_bluetoothAdapter.isEnabled()) {
- // Bluetooth adapter has been disabled, disconnect the transport
- disconnect("Bluetooth adapter has been disabled.",
- new SdlException("Bluetooth adapter must be enabled to instantiate a SdlProxy object.", SdlExceptionCause.BLUETOOTH_DISABLED));
- }
- }
-
- public void halt() {
- _isHalted = true;
- _bluetoothAdapterMonitorThread.interrupt();
- }
- }
-
- /**
- * Overridden abstract method which returns specific type of this transport.
- *
- * @return Constant value - TransportType.BLUETOOTH.
- *
- * @see TransportType
- */
- public TransportType getTransportType() {
- return TransportType.BLUETOOTH;
- }
-
- @Override
- public String getBroadcastComment() {
- return sComment;
- }
-
- @Override
- protected void handleTransportDisconnected(String info) {
- SdlConnection.enableLegacyMode(false, null);
- super.handleTransportDisconnected(info);
- }
-
- @Override
- protected void handleTransportError(String message, Exception ex) {
- SdlConnection.enableLegacyMode(false, null);
- super.handleTransportError(message, ex);
- }
-
-} // end-class
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransport.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransport.java
deleted file mode 100644
index 0bacd3a2f..000000000
--- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransport.java
+++ /dev/null
@@ -1,343 +0,0 @@
-/*
- * Copyright (c) 2018 Livio, 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 Livio 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.content.ComponentName;
-import android.content.Context;
-import android.os.Build;
-import android.os.Looper;
-import android.os.Parcelable;
-
-import com.smartdevicelink.SdlConnection.SdlConnection;
-import com.smartdevicelink.exception.SdlException;
-import com.smartdevicelink.protocol.SdlPacket;
-import com.smartdevicelink.transport.enums.TransportType;
-import com.smartdevicelink.transport.utl.TransportRecord;
-import com.smartdevicelink.util.DebugTool;
-
-import java.util.List;
-
-@Deprecated
-public class MultiplexTransport extends SdlTransport{
- private final static String TAG = "Multiplex Transport";
- private String sComment = "Multiplexing";
-
- TransportBrokerThread brokerThread;
- protected boolean isDisconnecting = false;
- MultiplexTransportConfig transportConfig;
- public MultiplexTransport(MultiplexTransportConfig transportConfig, final ITransportListener transportListener){
- super(transportListener);
- if(transportConfig == null){
- this.handleTransportError("Transport config was null", null);
- throw new IllegalArgumentException("Null transportConfig in MultiplexTransport constructor");
- }
- this.transportConfig = transportConfig;
- brokerThread = new TransportBrokerThread(transportConfig.context, transportConfig.appId, transportConfig.service);
- brokerThread.start();
- isDisconnecting = false;
- //brokerThread.initTransportBroker();
- //brokerThread.start();
-
- }
-
- public boolean isDisconnecting(){
- return this.isDisconnecting;
- }
- /**
- * Returns the config that was used to create this transport
- * @return
- */
- public MultiplexTransportConfig getConfig(){
- return this.transportConfig;
- }
-
- public boolean requestNewSession(){
- if(brokerThread!=null){
- brokerThread.requestNewSession();
- return true;
- }
- return false;
- }
-
- public void removeSession(long sessionId){
- if(brokerThread!=null){
- brokerThread.removeSession(sessionId);
- }
- }
-
- /**
- * Overridden abstract method which returns specific type of this transport.
- *
- * @return Constant value - TransportType.BLUETOOTH.
- * @see TransportType
- */
- public TransportType getTransportType() {
- return TransportType.MULTIPLEX;
- }
-
- @Override
- public String getBroadcastComment() {
- return sComment;
- }
-
- @Override
- protected boolean sendBytesOverTransport(SdlPacket packet) {
- if(brokerThread!=null){
- brokerThread.sendPacket(packet);
- return true;
- }
- return false; //Sure why not.
- }
-
- @Override
- public void openConnection() throws SdlException {
- DebugTool.logInfo(TAG, "Open connection");
- if(brokerThread!=null){
- brokerThread.startConnection();
- }//else should log out
-
- }
-
- @Override
- public void disconnect() {
- if(isDisconnecting){
- return;
- }
- DebugTool.logInfo(TAG, "Close connection");
- this.isDisconnecting= true;
- if(brokerThread!= null){
- brokerThread.cancel();
- brokerThread = null;
- }
- handleTransportDisconnected(TransportType.MULTIPLEX.name());
- isDisconnecting = false;
-
- }
-
-
-
- @Override
- protected void handleTransportError(String message, Exception ex) {
- if(brokerThread!=null){
- brokerThread.cancel();
- //brokerThread.interrupt();
- brokerThread = null;
- }
- super.handleTransportError(message, ex);
- }
-
-
- public boolean isPendingConnected(){
- if(brokerThread!=null){
- return brokerThread.queueStart;
- }
- return false;
- }
- /**
- * This thread will handle the broker transaction with the router service.
- *
- */
- protected class TransportBrokerThread extends Thread{
- boolean connected = false; //This helps clear up double on hardware connects
- TransportBroker broker;
- boolean queueStart = false;
- final Context context;
- final String appId;
- final ComponentName service;
- Looper threadLooper = null;
- /**
- * Thread will automatically start to prepare its looper.
- * @param context
- * @param appId
- */
- public TransportBrokerThread(Context context, String appId, ComponentName service){
- //this.start();
- super();
- this.context = context;
- this.appId = appId;
- this.service = service;
- //initTransportBroker(context, appId);
- }
-
- public void startConnection(){
- synchronized(this){
- connected = false;
- if(broker!=null){
- try{
- broker.start();
- }catch(Exception e){
- handleTransportError("Error starting transport", e);
- }
- }else{
- queueStart = true;
- }
- }
- }
-
- @SuppressLint("NewApi")
- public synchronized void cancel(){
- if(broker!=null){
- broker.stop();
- broker = null;
- }
- connected = false;
- if(threadLooper !=null){
- if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN_MR2){
- threadLooper.quitSafely();
- }else{
- threadLooper.quit();
- }
- threadLooper = null;
- }
- //this.interrupt();
-
- }
-
- public void onHardwareConnected(TransportType type){
- if(broker!=null){
- broker.onHardwareConnected(type);
- }else{
- queueStart = true;
- }
- }
-
- public void sendPacket(SdlPacket packet){
- broker.sendPacketToRouterService(packet);
- }
-
- public void requestNewSession(){
- if(broker!=null){
- broker.requestNewSession();
- }
- }
- public void removeSession(long sessionId){
- if(broker!=null){
- broker.removeSession(sessionId);
- }
- }
- @Override
- public void run() {
- Looper.prepare();
-
- if(broker==null){
- synchronized(this){
- initTransportBroker();
- if(queueStart){
- try{
- broker.start();
- }catch(Exception e){
- handleTransportError("Error starting transport", e);
- }
- }
- this.notify();
- }
- }
- threadLooper = Looper.myLooper();
- Looper.loop();
-
- }
-
- public void initTransportBroker(){
-
- broker = new TransportBroker(context, appId, service){
-
- @Override
- public boolean onHardwareConnected(TransportType type) {
- if(super.onHardwareConnected(type)){
- DebugTool.logInfo(TAG, "On transport connected...");
- if(!connected){
- connected = true;
- handleTransportConnected();
- }//else{Log.d(TAG, "Already connected");}
- return true;
- }else{
- try{
- this.start();
- }catch(Exception e){
- handleTransportError("Error starting transport", e);
- }
- }
- return false;
- }
-
- @Override
- public void onHardwareDisconnected(TransportRecord transportRecord, List<TransportRecord> connected) {
- onHardwareDisconnected(TransportType.BLUETOOTH);
- }
- @Override
- public void onHardwareDisconnected(TransportType type) {
- super.onHardwareDisconnected(type);
- if(connected){
- DebugTool.logInfo(TAG, "Handling disconnect");
- connected = false;
- SdlConnection.enableLegacyMode(isLegacyModeEnabled(), TransportType.BLUETOOTH);
- if(isLegacyModeEnabled()){
- DebugTool.logInfo(TAG, "Handle transport disconnect, legacy mode enabled");
- this.stop();
- isDisconnecting = true;
- //handleTransportDisconnected("");
- handleTransportError("",null); //This seems wrong, but it works
- }else{
- DebugTool.logInfo(TAG, "Handle transport Error");
- isDisconnecting = true;
- handleTransportError("",null); //This seems wrong, but it works
- }
- }
- }
-
- @Override
- public void onLegacyModeEnabled() {
- super.onLegacyModeEnabled();
- SdlConnection.enableLegacyMode(isLegacyModeEnabled(), TransportType.BLUETOOTH);
- if(isLegacyModeEnabled()){
- DebugTool.logInfo(TAG, "Handle on legacy mode enabled");
- this.stop();
- isDisconnecting = true;
- //handleTransportDisconnected("");
- handleTransportError("",null); //This seems wrong, but it works
- }
- }
-
- @Override
- public void onPacketReceived(Parcelable packet) {
- if(packet!=null){
- SdlPacket sdlPacket = (SdlPacket)packet;
- handleReceivedPacket(sdlPacket);
- }
- }
- };
- }
-
- }
-}