summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2018-08-08 17:19:26 -0400
committerJoey Grover <joeygrover@gmail.com>2018-08-08 17:19:26 -0400
commit7b29cf5678f791460da367f9629e6f064f82e95d (patch)
treee455b96d097d55cf0d3b4d24b8c9edd1c4ae7147
parent96583a8f930c1dfa8c918a9064374a5dd2b184bb (diff)
downloadsdl_android-7b29cf5678f791460da367f9629e6f064f82e95d.tar.gz
Refactor to nonbreaking changes to sessions
- Introduce new SdlSession2 that allows for multiplexing simultaneous transports - Create seperation between old SdlConnection stack and new SdlProtocol stack - Refactor WiProProtocol to previous state - Remove secondary transport code from old stack
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlConnection.java4
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java1340
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession2.java265
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java8
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/protocol/IProtocolListener.java2
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/protocol/SdlProtocol.java3
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/protocol/WiProProtocol.java833
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java3
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/streaming/StreamPacketizer.java9
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransport.java7
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/transport/TransportBroker.java4
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/transport/TransportManager.java8
12 files changed, 1108 insertions, 1378 deletions
diff --git a/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlConnection.java b/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlConnection.java
index 8e147861f..19b60abe2 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlConnection.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlConnection.java
@@ -283,10 +283,6 @@ public class SdlConnection implements IProtocolListener, ITransportListener {
_connectionListener.onProtocolError(info, e);
}
- @Override
- public void connectSecondaryTransport(byte sessionID, TransportType transportType, Bundle params) {
-
- }
/**
* Gets type of transport currently used by this connection.
diff --git a/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java b/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java
index 844f7fc4b..304061a0b 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java
@@ -2,26 +2,19 @@ package com.smartdevicelink.SdlConnection;
import android.annotation.SuppressLint;
import android.os.Build;
-import android.os.Bundle;
import android.util.Log;
import android.view.Surface;
import com.smartdevicelink.encoder.SdlEncoder;
import com.smartdevicelink.encoder.VirtualDisplayEncoder;
import com.smartdevicelink.exception.SdlException;
-import com.smartdevicelink.protocol.IProtocolListener;
-import com.smartdevicelink.protocol.ISdlProtocol;
import com.smartdevicelink.protocol.ProtocolMessage;
-import com.smartdevicelink.protocol.SdlPacket;
-import com.smartdevicelink.protocol.SdlProtocol;
-import com.smartdevicelink.protocol.WiProProtocol;
import com.smartdevicelink.protocol.enums.SessionType;
import com.smartdevicelink.protocol.heartbeat.IHeartbeatMonitor;
import com.smartdevicelink.protocol.heartbeat.IHeartbeatMonitorListener;
import com.smartdevicelink.proxy.LockScreenManager;
import com.smartdevicelink.proxy.RPCRequest;
import com.smartdevicelink.proxy.interfaces.IAudioStreamListener;
-import com.smartdevicelink.proxy.interfaces.ISdl;
import com.smartdevicelink.proxy.interfaces.ISdlServiceListener;
import com.smartdevicelink.proxy.interfaces.IVideoStreamListener;
import com.smartdevicelink.proxy.rpc.VideoStreamingFormat;
@@ -35,10 +28,9 @@ import com.smartdevicelink.streaming.StreamRPCPacketizer;
import com.smartdevicelink.streaming.video.RTPH264Packetizer;
import com.smartdevicelink.streaming.video.VideoStreamingParameters;
import com.smartdevicelink.transport.BaseTransportConfig;
+import com.smartdevicelink.transport.MultiplexTransport;
import com.smartdevicelink.transport.MultiplexTransportConfig;
-import com.smartdevicelink.transport.TransportManager;
import com.smartdevicelink.transport.enums.TransportType;
-import com.smartdevicelink.transport.utl.TransportRecord;
import java.io.IOException;
import java.io.InputStream;
@@ -48,80 +40,66 @@ import java.io.PipedOutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
-import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
-public class SdlSession implements ISdlProtocol, IHeartbeatMonitorListener, IStreamListener, ISecurityInitializedListener {
- private static final String TAG = "SdlSession";
+@Deprecated
+public class SdlSession implements ISdlConnectionListener, IHeartbeatMonitorListener, IStreamListener, ISecurityInitializedListener {
+ private static final String TAG = "SdlSession";
- private byte sessionId;
- private ISdlConnectionListener sessionListener;
- private BaseTransportConfig transportConfig;
+ protected final static int BUFF_READ_SIZE = 1024;
- private LockScreenManager lockScreenMan = new LockScreenManager();
- private SdlSecurityBase sdlSecurity = null;
- private final static int BUFF_READ_SIZE = 1024;
- private int sessionHashId = 0;
- private HashMap<SessionType, CopyOnWriteArrayList<ISdlServiceListener>> serviceListeners;
- private VideoStreamingParameters desiredVideoParams = null;
- private VideoStreamingParameters acceptedVideoParams = null;
- private CopyOnWriteArrayList<SessionType> encryptedServices = new CopyOnWriteArrayList<SessionType>();
- private boolean requestedSession = false;
+ private static CopyOnWriteArrayList<SdlConnection> shareConnections = new CopyOnWriteArrayList<SdlConnection>();
- IHeartbeatMonitor _outgoingHeartbeatMonitor = null;
- IHeartbeatMonitor _incomingHeartbeatMonitor = null;
- StreamRPCPacketizer mRPCPacketizer = null;
- AbstractPacketizer mVideoPacketizer = null;
- StreamPacketizer mAudioPacketizer = null;
- SdlEncoder mSdlEncoder = null;
- VirtualDisplayEncoder virtualDisplayEncoder = null;
+ private byte wiproProcolVer;
- //protected TransportManager transportManager;
- //protected WiProProtocol wiProProtocol;
+ protected BaseTransportConfig transportConfig;
+ protected ISdlConnectionListener sessionListener;
+ protected LockScreenManager lockScreenMan = new LockScreenManager();
+ protected SdlSecurityBase sdlSecurity = null;
+ protected VideoStreamingParameters desiredVideoParams = null;
+ protected VideoStreamingParameters acceptedVideoParams = null;
- protected SdlProtocol sdlProtocol;
+ protected byte sessionId;
+ protected int sessionHashId = 0;
+ protected HashMap<SessionType, CopyOnWriteArrayList<ISdlServiceListener>> serviceListeners;
+ protected CopyOnWriteArrayList<SessionType> encryptedServices = new CopyOnWriteArrayList<SessionType>();
- @Deprecated
- public static SdlSession createSession(byte wiproVersion, ISdlConnectionListener listener, BaseTransportConfig btConfig) {
-
- SdlSession session = new SdlSession();
- session.sessionListener = listener;
- session.transportConfig = btConfig;
-
- return session;
- }
- public SdlSession(ISdlConnectionListener listener, MultiplexTransportConfig config){
- Log.d(TAG, "SdlSession created");
- transportConfig = config;
- sessionListener = listener;
+ SdlConnection _sdlConnection = null;
+
+ IHeartbeatMonitor _outgoingHeartbeatMonitor = null;
+ IHeartbeatMonitor _incomingHeartbeatMonitor = null;
- sdlProtocol = new SdlProtocol(this,config);
- //wiProProtocol = new WiProProtocol(this);
- //wiProProtocol.setPrimaryTransports(config.getPrimaryTransports());
- //wiProProtocol.setRequiresHighBandwidth(config.requiresHighBandwidth());
+ StreamRPCPacketizer mRPCPacketizer = null;
+ AbstractPacketizer mVideoPacketizer = null;
+ StreamPacketizer mAudioPacketizer = null;
+ SdlEncoder mSdlEncoder = null;
+ VirtualDisplayEncoder virtualDisplayEncoder = null;
- //transportManager = new TransportManager(config,this);
+ public static SdlSession createSession(byte wiproVersion, ISdlConnectionListener listener, BaseTransportConfig btConfig) {
- }
- private SdlSession(){
+ SdlSession session = new SdlSession();
+ session.wiproProcolVer = wiproVersion;
+ session.sessionListener = listener;
+ session.transportConfig = btConfig;
- }
+ return session;
+ }
+ public BaseTransportConfig getTransportConfig() {
+ return this.transportConfig;
+ }
+
+ public LockScreenManager getLockScreenMan() {
+ return lockScreenMan;
+ }
- public BaseTransportConfig getTransportConfig() {
- return this.transportConfig;
- }
-
- public LockScreenManager getLockScreenMan() {
- return lockScreenMan;
- }
public IHeartbeatMonitor getOutgoingHeartbeatMonitor() {
return _outgoingHeartbeatMonitor;
}
-
+
public IHeartbeatMonitor getIncomingHeartbeatMonitor() {
return _incomingHeartbeatMonitor;
}
@@ -129,647 +107,657 @@ public class SdlSession implements ISdlProtocol, IHeartbeatMonitorListener, IStr
public void setOutgoingHeartbeatMonitor(IHeartbeatMonitor outgoingHeartbeatMonitor) {
this._outgoingHeartbeatMonitor = outgoingHeartbeatMonitor;
_outgoingHeartbeatMonitor.setListener(this);
- }
+ }
public void setIncomingHeartbeatMonitor(IHeartbeatMonitor incomingHeartbeatMonitor) {
this._incomingHeartbeatMonitor = incomingHeartbeatMonitor;
_incomingHeartbeatMonitor.setListener(this);
- }
-
+ }
+
public int getSessionHashId() {
- return this.sessionHashId;
- }
-
- public byte getSessionId() {
- return this.sessionId;
- }
-
- @Deprecated
- public SdlConnection getSdlConnection() {
- return null;
- }
-
- public int getMtu(){
- if(this.sdlProtocol!=null){
- return this.sdlProtocol.getMtu();
- }else{
- return 0;
- }
- }
-
- public long getMtu(SessionType type) {
- if (this.sdlProtocol != null) {
- return this.sdlProtocol.getMtu(type);
- } else {
- return 0;
- }
- }
-
- public void close() {
- if (sdlSecurity != null)
- {
- sdlSecurity.resetParams();
- sdlSecurity.shutDown();
- }
- if(sdlProtocol != null){
- sdlProtocol.endSession(sessionId, sessionHashId);
- //FIXME add a shutdown to sdlProtocol.
- //transportManager.close(sessionId);
- }
- }
-
-
- public void startStream(InputStream is, SessionType sType, byte rpcSessionID) throws IOException {
+ return this.sessionHashId;
+ }
+
+ public byte getSessionId() {
+ return this.sessionId;
+ }
+
+ public SdlConnection getSdlConnection() {
+ return this._sdlConnection;
+ }
+
+ public int getMtu(){
+ if(this._sdlConnection!=null){
+ return this._sdlConnection.getWiProProtocol().getMtu();
+ }else{
+ return 0;
+ }
+ }
+
+ public long getMtu(SessionType type) {
+ if (this._sdlConnection != null) {
+ return this._sdlConnection.getWiProProtocol().getMtu(type);
+ } else {
+ return 0;
+ }
+ }
+
+ public void close() {
+ if (sdlSecurity != null)
+ {
+ sdlSecurity.resetParams();
+ sdlSecurity.shutDown();
+ }
+
+ if (_sdlConnection != null) { //sessionId == 0 means session is not started.
+ //_sdlConnection.unregisterSession(this);
+
+ if (_sdlConnection.getRegisterCount() == 0) {
+ shareConnections.remove(_sdlConnection);
+ }
+
+ _sdlConnection = null;
+ }
+ }
+
+ public void startStream(InputStream is, SessionType sType, byte rpcSessionID) throws IOException {
if (sType.equals(SessionType.NAV))
{
- // protocol is fixed to RAW
- StreamPacketizer packetizer = new StreamPacketizer(this, is, sType, rpcSessionID, this);
- //packetizer.setProtocol(wiProProtocol);
- mVideoPacketizer = packetizer;
- mVideoPacketizer.start();
+ // protocol is fixed to RAW
+ StreamPacketizer packetizer = new StreamPacketizer(this, is, sType, rpcSessionID, this);
+ packetizer.sdlConnection = this.getSdlConnection();
+ mVideoPacketizer = packetizer;
+ mVideoPacketizer.start();
}
else if (sType.equals(SessionType.PCM))
{
- mAudioPacketizer = new StreamPacketizer(this, is, sType, rpcSessionID, this);
- //mAudioPacketizer.setProtocol(wiProProtocol);
- mAudioPacketizer.start();
- }
- }
-
- @SuppressLint("NewApi")
- public OutputStream startStream(SessionType sType, byte rpcSessionID) throws IOException {
- OutputStream os = new PipedOutputStream();
- InputStream is = null;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
- is = new PipedInputStream((PipedOutputStream) os, BUFF_READ_SIZE);
- } else {
- is = new PipedInputStream((PipedOutputStream) os);
- }
+ mAudioPacketizer = new StreamPacketizer(this, is, sType, rpcSessionID, this);
+ mAudioPacketizer.sdlConnection = this.getSdlConnection();
+ mAudioPacketizer.start();
+ }
+ }
+
+ @SuppressLint("NewApi")
+ public OutputStream startStream(SessionType sType, byte rpcSessionID) throws IOException {
+ OutputStream os = new PipedOutputStream();
+ InputStream is = null;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
+ is = new PipedInputStream((PipedOutputStream) os, BUFF_READ_SIZE);
+ } else {
+ is = new PipedInputStream((PipedOutputStream) os);
+ }
if (sType.equals(SessionType.NAV))
{
// protocol is fixed to RAW
StreamPacketizer packetizer = new StreamPacketizer(this, is, sType, rpcSessionID, this);
- //packetizer.setProtocol(wiProProtocol);
- mVideoPacketizer = packetizer;
+ packetizer.sdlConnection = this.getSdlConnection();
+ mVideoPacketizer = packetizer;
mVideoPacketizer.start();
- }
+ }
else if (sType.equals(SessionType.PCM))
{
- mAudioPacketizer = new StreamPacketizer(this, is, sType, rpcSessionID, this);
- //mAudioPacketizer.setProtocol(wiProProtocol);
- mAudioPacketizer.start();
+ mAudioPacketizer = new StreamPacketizer(this, is, sType, rpcSessionID, this);
+ mAudioPacketizer.sdlConnection = this.getSdlConnection();
+ mAudioPacketizer.start();
}
else
{
- os.close();
- is.close();
- return null;
- }
- return os;
- }
-
- public IVideoStreamListener startVideoStream() {
- byte rpcSessionID = getSessionId();
- VideoStreamingProtocol protocol = getAcceptedProtocol();
- try {
- switch (protocol) {
- case RAW: {
- StreamPacketizer packetizer = new StreamPacketizer(this, null, SessionType.NAV, rpcSessionID, this);
- //packetizer.setProtocol(wiProProtocol);
- mVideoPacketizer = packetizer;
- mVideoPacketizer.start();
- return packetizer;
- }
- case RTP: {
- RTPH264Packetizer packetizer = new RTPH264Packetizer(this, SessionType.NAV, rpcSessionID, this);
- mVideoPacketizer = packetizer;
- mVideoPacketizer.start();
- return packetizer;
- }
- default:
- Log.e(TAG, "Protocol " + protocol + " is not supported.");
- return null;
- }
- } catch (IOException e) {
- return null;
- }
- }
-
- public IAudioStreamListener startAudioStream() {
- byte rpcSessionID = getSessionId();
- try {
- StreamPacketizer packetizer = new StreamPacketizer(this, null, SessionType.PCM, rpcSessionID, this);
- mAudioPacketizer = packetizer;
- //mAudioPacketizer.setProtocol(wiProProtocol);
- mAudioPacketizer.start();
- return packetizer;
- } catch (IOException e) {
- return null;
- }
- }
-
- public void startRPCStream(InputStream is, RPCRequest request, SessionType sType, byte rpcSessionID, byte wiproVersion) {
- try {
- mRPCPacketizer = new StreamRPCPacketizer(null, this, is, request, sType, rpcSessionID, wiproVersion, 0, this);
- mRPCPacketizer.start();
- } catch (Exception e) {
- Log.e("SdlConnection", "Unable to start streaming:" + e.toString());
- }
- }
-
- public OutputStream startRPCStream(RPCRequest request, SessionType sType, byte rpcSessionID, byte wiproVersion) {
- try {
- OutputStream os = new PipedOutputStream();
- InputStream is = new PipedInputStream((PipedOutputStream) os);
- mRPCPacketizer = new StreamRPCPacketizer(null, this, is, request, sType, rpcSessionID, wiproVersion, 0, this);
- mRPCPacketizer.start();
- return os;
- } catch (Exception e) {
- Log.e("SdlConnection", "Unable to start streaming:" + e.toString());
- }
- return null;
- }
-
- public void pauseRPCStream()
- {
- if (mRPCPacketizer != null)
- {
- mRPCPacketizer.pause();
- }
- }
-
- public void resumeRPCStream()
- {
- if (mRPCPacketizer != null)
- {
- mRPCPacketizer.resume();
- }
- }
-
- public void stopRPCStream()
- {
- if (mRPCPacketizer != null)
- {
- mRPCPacketizer.stop();
- }
- }
-
- public boolean stopAudioStream()
- {
- if (mAudioPacketizer != null)
- {
- mAudioPacketizer.stop();
- return true;
- }
- return false;
- }
-
- public boolean stopVideoStream()
- {
- if (mVideoPacketizer != null)
- {
- mVideoPacketizer.stop();
- return true;
- }
- return false;
- }
-
- public boolean pauseAudioStream()
- {
- if (mAudioPacketizer != null)
- {
- mAudioPacketizer.pause();
- return true;
- }
- return false;
- }
-
- public boolean pauseVideoStream()
- {
- if (mVideoPacketizer != null)
- {
- mVideoPacketizer.pause();
- return true;
- }
- return false;
- }
-
- public boolean resumeAudioStream()
- {
- if (mAudioPacketizer != null)
- {
- mAudioPacketizer.resume();
- return true;
- }
- return false;
- }
-
- public boolean resumeVideoStream()
- {
- if (mVideoPacketizer != null)
- {
- mVideoPacketizer.resume();
- return true;
- }
- return false;
- }
-
- public Surface createOpenGLInputSurface(int frameRate, int iFrameInterval, int width,
- int height, int bitrate, SessionType sType, byte rpcSessionID) {
- IVideoStreamListener encoderListener = startVideoStream();
- if (encoderListener == null) {
- return null;
- }
-
- mSdlEncoder = new SdlEncoder();
- mSdlEncoder.setFrameRate(frameRate);
- mSdlEncoder.setFrameInterval(iFrameInterval);
- mSdlEncoder.setFrameWidth(width);
- mSdlEncoder.setFrameHeight(height);
- mSdlEncoder.setBitrate(bitrate);
- mSdlEncoder.setOutputListener(encoderListener);
- return mSdlEncoder.prepareEncoder();
- }
-
- public void startEncoder () {
- if(mSdlEncoder != null) {
- mSdlEncoder.startEncoder();
- }
- }
-
- public void releaseEncoder() {
- if(mSdlEncoder != null) {
- mSdlEncoder.releaseEncoder();
- }
- }
-
- public void drainEncoder(boolean endOfStream) {
- if(mSdlEncoder != null) {
- mSdlEncoder.drainEncoder(endOfStream);
- }
- }
-
- @Override
- public void sendStreamPacket(ProtocolMessage pm) {
- sendMessage(pm);
- }
-
- public void setSdlSecurity(SdlSecurityBase sec) {
- sdlSecurity = sec;
- }
-
- public SdlSecurityBase getSdlSecurity() {
- return sdlSecurity;
- }
-
- public void startService (SessionType serviceType, byte sessionID, boolean isEncrypted) {
- if (isEncrypted){
- if (sdlSecurity != null){
- List<SessionType> serviceList = sdlSecurity.getServiceList();
- if (!serviceList.contains(serviceType))
- serviceList.add(serviceType);
-
- sdlSecurity.initialize();
- }
- return;
- }
- sdlProtocol.startService(serviceType, sessionID, isEncrypted);
- //wiProProtocol.StartProtocolService(serviceType, sessionID, isEncrypted);
- }
-
- public void endService (SessionType serviceType, byte sessionID) {
- if (sdlProtocol == null) {
- return;
- }
- sdlProtocol.endService(serviceType,sessionID);
- }
-
- private void processControlService(ProtocolMessage msg) {
- if (sdlSecurity == null)
- return;
- int ilen = msg.getData().length - 12;
- byte[] data = new byte[ilen];
- System.arraycopy(msg.getData(), 12, data, 0, ilen);
-
- byte[] dataToRead = new byte[4096];
-
- Integer iNumBytes = sdlSecurity.runHandshake(data, dataToRead);
-
- if (iNumBytes == null || iNumBytes <= 0)
- return;
-
- byte[] returnBytes = new byte[iNumBytes];
- System.arraycopy(dataToRead, 0, returnBytes, 0, iNumBytes);
- ProtocolMessage protocolMessage = new ProtocolMessage();
- protocolMessage.setSessionType(SessionType.CONTROL);
- protocolMessage.setData(returnBytes);
- protocolMessage.setFunctionID(0x01);
- protocolMessage.setVersion(sdlProtocol.getMajorVersionByte());
- protocolMessage.setSessionID(getSessionId());
-
- //sdlSecurity.hs();
-
- sendMessage(protocolMessage);
- }
-
- public String getBroadcastComment(BaseTransportConfig myTransport) {
- return "Multiplexing";
- }
-
-
- public void startSession() throws SdlException {
- sdlProtocol.start();
- }
-
- private void initialiseSession() {
+ os.close();
+ is.close();
+ return null;
+ }
+ return os;
+ }
+
+ public IVideoStreamListener startVideoStream() {
+ byte rpcSessionID = getSessionId();
+ VideoStreamingProtocol protocol = getAcceptedProtocol();
+ try {
+ switch (protocol) {
+ case RAW: {
+ StreamPacketizer packetizer = new StreamPacketizer(this, null, SessionType.NAV, rpcSessionID, this);
+ packetizer.sdlConnection = this.getSdlConnection();
+ mVideoPacketizer = packetizer;
+ mVideoPacketizer.start();
+ return packetizer;
+ }
+ case RTP: {
+ RTPH264Packetizer packetizer = new RTPH264Packetizer(this, SessionType.NAV, rpcSessionID, this);
+ mVideoPacketizer = packetizer;
+ mVideoPacketizer.start();
+ return packetizer;
+ }
+ default:
+ Log.e(TAG, "Protocol " + protocol + " is not supported.");
+ return null;
+ }
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+ public IAudioStreamListener startAudioStream() {
+ byte rpcSessionID = getSessionId();
+ try {
+ StreamPacketizer packetizer = new StreamPacketizer(this, null, SessionType.PCM, rpcSessionID, this);
+ packetizer.sdlConnection = this.getSdlConnection();
+ mAudioPacketizer = packetizer;
+ mAudioPacketizer.start();
+ return packetizer;
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+ public void startRPCStream(InputStream is, RPCRequest request, SessionType sType, byte rpcSessionID, byte wiproVersion) {
+ try {
+ mRPCPacketizer = new StreamRPCPacketizer(null, this, is, request, sType, rpcSessionID, wiproVersion, 0, this);
+ mRPCPacketizer.start();
+ } catch (Exception e) {
+ Log.e(TAG, "Unable to start streaming:" + e.toString());
+ }
+ }
+
+ public OutputStream startRPCStream(RPCRequest request, SessionType sType, byte rpcSessionID, byte wiproVersion) {
+ try {
+ OutputStream os = new PipedOutputStream();
+ InputStream is = new PipedInputStream((PipedOutputStream) os);
+ mRPCPacketizer = new StreamRPCPacketizer(null, this, is, request, sType, rpcSessionID, wiproVersion, 0, this);
+ mRPCPacketizer.start();
+ return os;
+ } catch (Exception e) {
+ Log.e(TAG, "Unable to start streaming:" + e.toString());
+ }
+ return null;
+ }
+
+ public void pauseRPCStream()
+ {
+ if (mRPCPacketizer != null)
+ {
+ mRPCPacketizer.pause();
+ }
+ }
+
+ public void resumeRPCStream()
+ {
+ if (mRPCPacketizer != null)
+ {
+ mRPCPacketizer.resume();
+ }
+ }
+
+ public void stopRPCStream()
+ {
+ if (mRPCPacketizer != null)
+ {
+ mRPCPacketizer.stop();
+ }
+ }
+
+ public boolean stopAudioStream()
+ {
+ if (mAudioPacketizer != null)
+ {
+ mAudioPacketizer.stop();
+ return true;
+ }
+ return false;
+ }
+
+ public boolean stopVideoStream()
+ {
+ if (mVideoPacketizer != null)
+ {
+ mVideoPacketizer.stop();
+ return true;
+ }
+ return false;
+ }
+
+ public boolean pauseAudioStream()
+ {
+ if (mAudioPacketizer != null)
+ {
+ mAudioPacketizer.pause();
+ return true;
+ }
+ return false;
+ }
+
+ public boolean pauseVideoStream()
+ {
+ if (mVideoPacketizer != null)
+ {
+ mVideoPacketizer.pause();
+ return true;
+ }
+ return false;
+ }
+
+ public boolean resumeAudioStream()
+ {
+ if (mAudioPacketizer != null)
+ {
+ mAudioPacketizer.resume();
+ return true;
+ }
+ return false;
+ }
+
+ public boolean resumeVideoStream()
+ {
+ if (mVideoPacketizer != null)
+ {
+ mVideoPacketizer.resume();
+ return true;
+ }
+ return false;
+ }
+
+ public Surface createOpenGLInputSurface(int frameRate, int iFrameInterval, int width,
+ int height, int bitrate, SessionType sType, byte rpcSessionID) {
+ IVideoStreamListener encoderListener = startVideoStream();
+ if (encoderListener == null) {
+ return null;
+ }
+
+ mSdlEncoder = new SdlEncoder();
+ mSdlEncoder.setFrameRate(frameRate);
+ mSdlEncoder.setFrameInterval(iFrameInterval);
+ mSdlEncoder.setFrameWidth(width);
+ mSdlEncoder.setFrameHeight(height);
+ mSdlEncoder.setBitrate(bitrate);
+ mSdlEncoder.setOutputListener(encoderListener);
+ return mSdlEncoder.prepareEncoder();
+ }
+
+ public void startEncoder () {
+ if(mSdlEncoder != null) {
+ mSdlEncoder.startEncoder();
+ }
+ }
+
+ public void releaseEncoder() {
+ if(mSdlEncoder != null) {
+ mSdlEncoder.releaseEncoder();
+ }
+ }
+
+ public void drainEncoder(boolean endOfStream) {
+ if(mSdlEncoder != null) {
+ mSdlEncoder.drainEncoder(endOfStream);
+ }
+ }
+
+ @Override
+ public void sendStreamPacket(ProtocolMessage pm) {
+ sendMessage(pm);
+ }
+
+ public void setSdlSecurity(SdlSecurityBase sec) {
+ sdlSecurity = sec;
+ }
+
+ public SdlSecurityBase getSdlSecurity() {
+ return sdlSecurity;
+ }
+
+ public void startService (SessionType serviceType, byte sessionID, boolean isEncrypted) {
+ if (_sdlConnection == null)
+ return;
+
+ if (isEncrypted)
+ {
+ if (sdlSecurity != null)
+ {
+ List<SessionType> serviceList = sdlSecurity.getServiceList();
+ if (!serviceList.contains(serviceType))
+ serviceList.add(serviceType);
+
+ sdlSecurity.initialize();
+ }
+ return;
+ }
+ _sdlConnection.startService(serviceType, sessionID, isEncrypted);
+ }
+
+ public void endService (SessionType serviceType, byte sessionID) {
+ if (_sdlConnection == null)
+ return;
+ _sdlConnection.endService(serviceType, sessionID);
+ }
+
+ protected void processControlService(ProtocolMessage msg) {
+ if (sdlSecurity == null)
+ return;
+ int ilen = msg.getData().length - 12;
+ byte[] data = new byte[ilen];
+ System.arraycopy(msg.getData(), 12, data, 0, ilen);
+
+ byte[] dataToRead = new byte[4096];
+
+ Integer iNumBytes = sdlSecurity.runHandshake(data, dataToRead);
+
+ if (iNumBytes == null || iNumBytes <= 0)
+ return;
+
+ byte[] returnBytes = new byte[iNumBytes];
+ System.arraycopy(dataToRead, 0, returnBytes, 0, iNumBytes);
+ ProtocolMessage protocolMessage = new ProtocolMessage();
+ protocolMessage.setSessionType(SessionType.CONTROL);
+ protocolMessage.setData(returnBytes);
+ protocolMessage.setFunctionID(0x01);
+ protocolMessage.setVersion(wiproProcolVer);
+ protocolMessage.setSessionID(getSessionId());
+
+ //sdlSecurity.hs();
+
+ sendMessage(protocolMessage);
+ }
+
+ public String getBroadcastComment(BaseTransportConfig myTransport) {
+ SdlConnection connection = null;
+ if (myTransport.shareConnection()) {
+ connection = findTheProperConnection(myTransport);
+ } else {
+ connection = this._sdlConnection;
+ }
+
+ if (connection != null)
+ return connection.getBroadcastComment();
+
+ return "";
+ }
+
+
+ public void startSession() throws SdlException {
+ SdlConnection connection = null;
+ if (this.transportConfig.shareConnection()) {
+ connection = findTheProperConnection(this.transportConfig);
+
+ if (connection == null) {
+ connection = new SdlConnection(this.transportConfig);
+ shareConnections.add(connection);
+ }
+ } else {
+ connection = new SdlConnection(this.transportConfig);
+ }
+
+ this._sdlConnection = connection;
+ connection.registerSession(this); //Handshake will start when register.
+ }
+
+ protected void initialiseSession() {
if (_outgoingHeartbeatMonitor != null) {
- _outgoingHeartbeatMonitor.start();
+ _outgoingHeartbeatMonitor.start();
}
if (_incomingHeartbeatMonitor != null) {
- _incomingHeartbeatMonitor.start();
- }
- }
-
- public void sendMessage(ProtocolMessage msg) {
- if (sdlProtocol == null){
- return;
- }
- sdlProtocol.sendMessage(msg);
- }
-
- public TransportType getCurrentTransportType() {
- return TransportType.MULTIPLEX;
- }
-
- public boolean getIsConnected() {
- //TODO add sdl connecction
- return sdlProtocol.isConnected();
- }
-
- public boolean isServiceProtected(SessionType sType) {
- return encryptedServices.contains(sType);
- }
-
-
- public void shutdown(String info){
- Log.d(TAG, "Shutdown - " + info);
- this.sessionListener.onTransportDisconnected(info);
-
- }
-
- @Override
- public void onTransportDisconnected(String info, boolean altTransportAvailable, MultiplexTransportConfig transportConfig) {
- this.sessionListener.onTransportDisconnected(info, altTransportAvailable, (MultiplexTransportConfig)this.transportConfig);
- }
-
- //OLD
-
- public void onTransportDisconnected(String info){ }
- public void onTransportError(String info, Exception e){ }
-
-
- /* ***********************************************************************************************************************************************************************
- * ***************************************************************** IProtocol Listener ********************************************************************************
- *************************************************************************************************************************************************************************/
-
- @Override
- public void onProtocolMessageBytesToSend(SdlPacket packet) {
- //Log.d(TAG, "onProtocolMessageBytesToSend - " + packet.getTransportType());
- sdlProtocol.sendPacket(packet);
- }
-
- @Override
- public void onProtocolMessageReceived(ProtocolMessage msg) {
- if (msg.getSessionType().equals(SessionType.CONTROL)) {
- processControlService(msg);
- return;
- }
-
- this.sessionListener.onProtocolMessageReceived(msg);
- }
-
-
- @Override
- public void onProtocolSessionStarted(SessionType sessionType, byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) {
- this.sessionId = sessionID;
- lockScreenMan.setSessionID(sessionID);
- if (isEncrypted)
- encryptedServices.addIfAbsent(sessionType);
- this.sessionListener.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID, isEncrypted);
- if(serviceListeners != null && serviceListeners.containsKey(sessionType)){
- CopyOnWriteArrayList<ISdlServiceListener> listeners = serviceListeners.get(sessionType);
- for(ISdlServiceListener listener:listeners){
- listener.onServiceStarted(this, sessionType, isEncrypted);
- }
- }
- //if (version == 3)
- initialiseSession();
- if (sessionType.eq(SessionType.RPC)){
- sessionHashId = hashID;
- }
- }
-
- @Override
- public void onProtocolSessionEnded(SessionType sessionType, byte sessionID,
- String correlationID) {
- this.sessionListener.onProtocolSessionEnded(sessionType, sessionID, correlationID);
- if(serviceListeners != null && serviceListeners.containsKey(sessionType)){
- CopyOnWriteArrayList<ISdlServiceListener> listeners = serviceListeners.get(sessionType);
- for(ISdlServiceListener listener:listeners){
- listener.onServiceEnded(this, sessionType);
- }
- }
- encryptedServices.remove(sessionType);
- }
-
- @Override
- public void onProtocolError(String info, Exception e) {
- this.sessionListener.onProtocolError(info, e);
- }
-
- @Override
- public void connectSecondaryTransport(byte sessionId, TransportType transportType, Bundle params) {
- Log.d(TAG, "Connect Secondary Transport");
- //transportManager.requestSecondaryTransportConnection(sessionId, params);
- }
-
- @Override
+ _incomingHeartbeatMonitor.start();
+ }
+ }
+
+ public void sendMessage(ProtocolMessage msg) {
+ if (_sdlConnection == null)
+ return;
+ _sdlConnection.sendMessage(msg);
+ }
+
+ public TransportType getCurrentTransportType() {
+ if (_sdlConnection == null)
+ return null;
+ return _sdlConnection.getCurrentTransportType();
+ }
+
+ public boolean getIsConnected() {
+ if (_sdlConnection == null)
+ return false;
+ return _sdlConnection != null && _sdlConnection.getIsConnected();
+ }
+
+ public boolean isServiceProtected(SessionType sType) {
+ return encryptedServices.contains(sType);
+ }
+
+ @Override
+ public void onTransportDisconnected(String info) {
+ this.sessionListener.onTransportDisconnected(info);
+ }
+
+ @Override
+ public void onTransportDisconnected(String info, boolean availablePrimary, MultiplexTransportConfig transportConfig) {
+ this.sessionListener.onTransportDisconnected(info);
+ }
+
+ @Override
+ public void onTransportError(String info, Exception e) {
+ this.sessionListener.onTransportError(info, e);
+ }
+
+ @Override
+ public void onProtocolMessageReceived(ProtocolMessage msg) {
+ if (msg.getSessionType().equals(SessionType.CONTROL)) {
+ processControlService(msg);
+ return;
+ }
+
+ this.sessionListener.onProtocolMessageReceived(msg);
+ }
+
+ @Override
+ public void onHeartbeatTimedOut(byte sessionID) {
+ this.sessionListener.onHeartbeatTimedOut(sessionID);
+
+ }
+
+
+ @Override
+ public void onProtocolSessionStarted(SessionType sessionType,
+ byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) {
+ this.sessionId = sessionID;
+ lockScreenMan.setSessionID(sessionID);
+ if (isEncrypted)
+ encryptedServices.addIfAbsent(sessionType);
+ this.sessionListener.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID, isEncrypted);
+ if(serviceListeners != null && serviceListeners.containsKey(sessionType)){
+ CopyOnWriteArrayList<ISdlServiceListener> listeners = serviceListeners.get(sessionType);
+ for(ISdlServiceListener listener:listeners){
+ listener.onServiceStarted(this, sessionType, isEncrypted);
+ }
+ }
+ //if (version == 3)
+ initialiseSession();
+ if (sessionType.eq(SessionType.RPC)){
+ sessionHashId = hashID;
+ }
+ }
+
+ @Override
+ public void onProtocolSessionEnded(SessionType sessionType, byte sessionID,
+ String correlationID) {
+ this.sessionListener.onProtocolSessionEnded(sessionType, sessionID, correlationID);
+ if(serviceListeners != null && serviceListeners.containsKey(sessionType)){
+ CopyOnWriteArrayList<ISdlServiceListener> listeners = serviceListeners.get(sessionType);
+ for(ISdlServiceListener listener:listeners){
+ listener.onServiceEnded(this, sessionType);
+ }
+ }
+ encryptedServices.remove(sessionType);
+ }
+
+ @Override
+ public void onProtocolError(String info, Exception e) {
+ this.sessionListener.onProtocolError(info, e);
+ }
+
+ @Override
public void sendHeartbeat(IHeartbeatMonitor monitor) {
Log.d(TAG, "Asked to send heartbeat");
- if (sdlProtocol != null) {
- //FIXME sdlProtocol.sendHeartBeat(sessionId);
- }
+ if (_sdlConnection != null)
+ _sdlConnection.sendHeartbeat(this);
}
@Override
- public void heartbeatTimedOut(IHeartbeatMonitor monitor) {
+ public void heartbeatTimedOut(IHeartbeatMonitor monitor) {
+ if (_sdlConnection != null)
+ _sdlConnection._connectionListener.onHeartbeatTimedOut(this.sessionId);
close();
}
- public void onHeartbeatTimedOut(byte sessionId){
- //TODO
- }
-
- public void onProtocolSessionStartedNACKed(SessionType sessionType, byte sessionID, byte version, String correlationID, List<String> rejectedParams){
- onProtocolSessionNACKed(sessionType,sessionID,version,correlationID,rejectedParams);
- }
-
- @Override
- public void onProtocolSessionNACKed(SessionType sessionType, byte sessionID, byte version, String correlationID, List<String> rejectedParams) {
- this.sessionListener.onProtocolSessionStartedNACKed(sessionType,
- sessionID, version, correlationID, rejectedParams);
- if(serviceListeners != null && serviceListeners.containsKey(sessionType)){
- CopyOnWriteArrayList<ISdlServiceListener> listeners = serviceListeners.get(sessionType);
- for(ISdlServiceListener listener:listeners){
- listener.onServiceError(this, sessionType, "Start "+ sessionType.toString() +" Service NACK'ed");
- }
- }
- }
-
- @Override
- public void onProtocolSessionEndedNACKed(SessionType sessionType,
- byte sessionID, String correlationID) {
- this.sessionListener.onProtocolSessionEndedNACKed(sessionType, sessionID, correlationID);
- if(serviceListeners != null && serviceListeners.containsKey(sessionType)){
- CopyOnWriteArrayList<ISdlServiceListener> listeners = serviceListeners.get(sessionType);
- for(ISdlServiceListener listener:listeners){
- listener.onServiceError(this, sessionType, "End "+ sessionType.toString() +" Service NACK'ed");
- }
- }
- }
-
- @Override
- public void onProtocolHeartbeat(SessionType sessionType, byte sessionID) {
- //TODO
- }
-
- @Override
- public void onProtocolHeartbeatACK(SessionType sessionType, byte sessionID) {
- //TODO
- }
-
- @Override
- public void onProtocolServiceDataACK(SessionType sessionType, int dataSize, byte sessionID) {
- this.sessionListener.onProtocolServiceDataACK(sessionType, dataSize, sessionID);
- }
-
- @Override
- public void onResetOutgoingHeartbeat(SessionType sessionType, byte sessionID) {
- //TODO
- }
-
- @Override
- public void onResetIncomingHeartbeat(SessionType sessionType, byte sessionID) {
- //TODO
- }
-
- /* ***********************************************************************************************************************************************************************
- * ***************************************************************** Security Listener *********************************************************************************
- *************************************************************************************************************************************************************************/
-
-
- @Override
- public void onSecurityInitialized() {
-
- if (sdlProtocol != null && sdlSecurity != null)
- {
- List<SessionType> list = sdlSecurity.getServiceList();
-
- SessionType service;
- ListIterator<SessionType> iter = list.listIterator();
-
- while (iter.hasNext()) {
- service = iter.next();
-
- if (service != null)
- sdlProtocol.startService(service, getSessionId(), true);
-
- iter.remove();
- }
- }
- }
-
- @Deprecated
- public void clearConnection(){
- }
-
- @Deprecated
- public static void removeConnection(SdlConnection connection){
- }
-
- @Deprecated
- public void checkForOpenMultiplexConnection(SdlConnection connection){
- }
-
- public void addServiceListener(SessionType serviceType, ISdlServiceListener sdlServiceListener){
- if(serviceListeners == null){
- serviceListeners = new HashMap<>();
- }
- if(serviceType != null && sdlServiceListener != null){
- if(!serviceListeners.containsKey(serviceType)){
- serviceListeners.put(serviceType,new CopyOnWriteArrayList<ISdlServiceListener>());
- }
- serviceListeners.get(serviceType).add(sdlServiceListener);
- }
- }
-
- public boolean removeServiceListener(SessionType serviceType, ISdlServiceListener sdlServiceListener){
- if(serviceListeners!= null && serviceType != null && sdlServiceListener != null && serviceListeners.containsKey(serviceType)){
- return serviceListeners.get(serviceType).remove(sdlServiceListener);
- }
- return false;
- }
-
-
- public HashMap<SessionType, CopyOnWriteArrayList<ISdlServiceListener>> getServiceListeners(){
- return serviceListeners;
- }
-
- public void setDesiredVideoParams(VideoStreamingParameters params){
- this.desiredVideoParams = params;
- }
-
- /**
- * Returns the currently set desired video streaming parameters. If there haven't been any set,
- * the default options will be returned and set for this instance.
- * @return
- */
- public VideoStreamingParameters getDesiredVideoParams(){
- if(desiredVideoParams == null){
- desiredVideoParams = new VideoStreamingParameters();
- }
- return desiredVideoParams;
- }
-
- public void setAcceptedVideoParams(VideoStreamingParameters params){
- this.acceptedVideoParams = params;
- }
-
- @Override
- public void stopStream(SessionType serviceType) {
- if(SessionType.NAV.equals(serviceType)){
- stopVideoStream();
- }else if(SessionType.PCM.equals(serviceType)){
- stopAudioStream();
- }
-
- }
-
- public VideoStreamingParameters getAcceptedVideoParams(){
- return acceptedVideoParams;
- }
-
- private VideoStreamingProtocol getAcceptedProtocol() {
- // acquire default protocol (RAW)
- VideoStreamingProtocol protocol = new VideoStreamingParameters().getFormat().getProtocol();
-
- if (acceptedVideoParams != null) {
- VideoStreamingFormat format = acceptedVideoParams.getFormat();
- if (format != null && format.getProtocol() != null) {
- protocol = format.getProtocol();
- }
- }
-
- return protocol;
- }
-}
+ private static SdlConnection findTheProperConnection(BaseTransportConfig config) {
+ SdlConnection connection = null;
+
+ int minCount = 0;
+ for (SdlConnection c : shareConnections) {
+ if (c.getCurrentTransportType() == config.getTransportType()) {
+ if (minCount == 0 || minCount >= c.getRegisterCount()) {
+ connection = c;
+ minCount = c.getRegisterCount();
+ }
+ }
+ }
+
+ return connection;
+ }
+
+ @Override
+ public void onProtocolSessionStartedNACKed(SessionType sessionType,
+ byte sessionID, byte version, String correlationID, List<String> rejectedParams) {
+ this.sessionListener.onProtocolSessionStartedNACKed(sessionType,
+ sessionID, version, correlationID, rejectedParams);
+ if(serviceListeners != null && serviceListeners.containsKey(sessionType)){
+ CopyOnWriteArrayList<ISdlServiceListener> listeners = serviceListeners.get(sessionType);
+ for(ISdlServiceListener listener:listeners){
+ listener.onServiceError(this, sessionType, "Start "+ sessionType.toString() +" Service NACK'ed");
+ }
+ }
+ }
+
+ @Override
+ public void onProtocolSessionEndedNACKed(SessionType sessionType,
+ byte sessionID, String correlationID) {
+ this.sessionListener.onProtocolSessionEndedNACKed(sessionType, sessionID, correlationID);
+ if(serviceListeners != null && serviceListeners.containsKey(sessionType)){
+ CopyOnWriteArrayList<ISdlServiceListener> listeners = serviceListeners.get(sessionType);
+ for(ISdlServiceListener listener:listeners){
+ listener.onServiceError(this, sessionType, "End "+ sessionType.toString() +" Service NACK'ed");
+ }
+ }
+ }
+
+ @Override
+ public void onProtocolServiceDataACK(SessionType sessionType, int dataSize, byte sessionID) {
+ this.sessionListener.onProtocolServiceDataACK(sessionType, dataSize, sessionID);
+ }
+
+ @Override
+ public void onSecurityInitialized() {
+
+ if (_sdlConnection != null && sdlSecurity != null)
+ {
+ List<SessionType> list = sdlSecurity.getServiceList();
+
+ SessionType service;
+ ListIterator<SessionType> iter = list.listIterator();
+
+ while (iter.hasNext()) {
+ service = iter.next();
+
+ if (service != null)
+ _sdlConnection.startService(service, getSessionId(), true);
+
+ iter.remove();
+ }
+ }
+ }
+
+ public void clearConnection(){
+ _sdlConnection = null;
+ }
+
+ public void checkForOpenMultiplexConnection(SdlConnection connection){
+ removeConnection(connection);
+ connection.unregisterSession(this);
+ _sdlConnection = null;
+ for (SdlConnection c : shareConnections) {
+ if (c.getCurrentTransportType() == TransportType.MULTIPLEX) {
+ if(c.getIsConnected() || ((MultiplexTransport)c._transport).isPendingConnected()){
+ _sdlConnection = c;
+ try {
+ _sdlConnection.registerSession(this);//Handshake will start when register.
+ } catch (SdlException e) {
+ e.printStackTrace();
+ }
+ return;
+ }
+
+ }
+ }
+ }
+ public static boolean removeConnection(SdlConnection connection){
+ return shareConnections.remove(connection);
+ }
+
+ public void addServiceListener(SessionType serviceType, ISdlServiceListener sdlServiceListener){
+ if(serviceListeners == null){
+ serviceListeners = new HashMap<>();
+ }
+ if(serviceType != null && sdlServiceListener != null){
+ if(!serviceListeners.containsKey(serviceType)){
+ serviceListeners.put(serviceType,new CopyOnWriteArrayList<ISdlServiceListener>());
+ }
+ serviceListeners.get(serviceType).add(sdlServiceListener);
+ }
+ }
+
+ public boolean removeServiceListener(SessionType serviceType, ISdlServiceListener sdlServiceListener){
+ if(serviceListeners!= null && serviceType != null && sdlServiceListener != null && serviceListeners.containsKey(serviceType)){
+ return serviceListeners.get(serviceType).remove(sdlServiceListener);
+ }
+ return false;
+ }
+
+
+ public HashMap<SessionType, CopyOnWriteArrayList<ISdlServiceListener>> getServiceListeners(){
+ return serviceListeners;
+ }
+
+ public void setDesiredVideoParams(VideoStreamingParameters params){
+ this.desiredVideoParams = params;
+ }
+
+ /**
+ * Returns the currently set desired video streaming parameters. If there haven't been any set,
+ * the default options will be returned and set for this instance.
+ * @return
+ */
+ public VideoStreamingParameters getDesiredVideoParams(){
+ if(desiredVideoParams == null){
+ desiredVideoParams = new VideoStreamingParameters();
+ }
+ return desiredVideoParams;
+ }
+
+ public void setAcceptedVideoParams(VideoStreamingParameters params){
+ this.acceptedVideoParams = params;
+ }
+
+ public VideoStreamingParameters getAcceptedVideoParams(){
+ return acceptedVideoParams;
+ }
+
+ private VideoStreamingProtocol getAcceptedProtocol() {
+ // acquire default protocol (RAW)
+ VideoStreamingProtocol protocol = new VideoStreamingParameters().getFormat().getProtocol();
+
+ if (acceptedVideoParams != null) {
+ VideoStreamingFormat format = acceptedVideoParams.getFormat();
+ if (format != null && format.getProtocol() != null) {
+ protocol = format.getProtocol();
+ }
+ }
+
+ return protocol;
+ }
+
+} \ No newline at end of file
diff --git a/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession2.java b/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession2.java
new file mode 100644
index 000000000..6614fa1b7
--- /dev/null
+++ b/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession2.java
@@ -0,0 +1,265 @@
+// New version
+
+package com.smartdevicelink.SdlConnection;
+
+import android.os.Bundle;
+import android.util.Log;
+
+import com.smartdevicelink.exception.SdlException;
+import com.smartdevicelink.protocol.ISdlProtocol;
+import com.smartdevicelink.protocol.ProtocolMessage;
+import com.smartdevicelink.protocol.SdlPacket;
+import com.smartdevicelink.protocol.SdlProtocol;
+import com.smartdevicelink.protocol.enums.SessionType;
+import com.smartdevicelink.protocol.heartbeat.IHeartbeatMonitor;
+import com.smartdevicelink.proxy.interfaces.ISdlServiceListener;
+import com.smartdevicelink.transport.BaseTransportConfig;
+import com.smartdevicelink.transport.MultiplexTransportConfig;
+import com.smartdevicelink.transport.enums.TransportType;
+
+import java.util.List;
+import java.util.ListIterator;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+public class SdlSession2 extends SdlSession implements ISdlProtocol{
+ private static final String TAG = "SdlSession2";
+
+
+ protected SdlProtocol sdlProtocol;
+
+ @Deprecated
+ public static SdlSession2 createSession(byte wiproVersion, ISdlConnectionListener listener, BaseTransportConfig btConfig) {
+ return null;
+ }
+
+ public SdlSession2(ISdlConnectionListener listener, MultiplexTransportConfig config){
+ Log.d(TAG, "SdlSession created");
+ this.transportConfig = config;
+ this.sessionListener = listener;
+
+ this.sdlProtocol = new SdlProtocol(this,config);
+
+ }
+
+ @Deprecated
+ @Override
+ public SdlConnection getSdlConnection() {
+ return null;
+ }
+
+ @Override
+ public int getMtu(){
+ if(this.sdlProtocol!=null){
+ return this.sdlProtocol.getMtu();
+ }else{
+ return 0;
+ }
+ }
+
+ @Override
+ public long getMtu(SessionType type) {
+ if (this.sdlProtocol != null) {
+ return this.sdlProtocol.getMtu(type);
+ } else {
+ return 0;
+ }
+ }
+
+ public void close() {
+ if (sdlSecurity != null)
+ {
+ sdlSecurity.resetParams();
+ sdlSecurity.shutDown();
+ }
+ if(sdlProtocol != null){
+ sdlProtocol.endSession(sessionId, sessionHashId);
+ //FIXME add a shutdown to sdlProtocol.
+ //transportManager.close(sessionId);
+ }
+ }
+
+
+ @Override
+ public void startService (SessionType serviceType, byte sessionID, boolean isEncrypted) {
+ if (isEncrypted){
+ if (sdlSecurity != null){
+ List<SessionType> serviceList = sdlSecurity.getServiceList();
+ if (!serviceList.contains(serviceType))
+ serviceList.add(serviceType);
+
+ sdlSecurity.initialize();
+ }
+ return;
+ }
+ sdlProtocol.startService(serviceType, sessionID, isEncrypted);
+ }
+
+ @Override
+ public void endService (SessionType serviceType, byte sessionID) {
+ if (sdlProtocol == null) {
+ return;
+ }
+ sdlProtocol.endService(serviceType,sessionID);
+ }
+
+
+ public String getBroadcastComment(BaseTransportConfig myTransport) {
+ return "Multiplexing";
+ }
+
+
+ @Override
+ public void startSession() throws SdlException {
+ sdlProtocol.start();
+ }
+
+
+ @Override
+ public void sendMessage(ProtocolMessage msg) {
+ if (sdlProtocol == null){
+ return;
+ }
+ sdlProtocol.sendMessage(msg);
+ }
+
+ @Override
+ public TransportType getCurrentTransportType() {
+ return TransportType.MULTIPLEX;
+ }
+
+ @Override
+ public boolean getIsConnected() {
+ return sdlProtocol != null && sdlProtocol.isConnected();
+ }
+
+
+ public void shutdown(String info){
+ Log.d(TAG, "Shutdown - " + info);
+ this.sessionListener.onTransportDisconnected(info);
+
+ }
+
+ @Override
+ public void onTransportDisconnected(String info, boolean altTransportAvailable, MultiplexTransportConfig transportConfig) {
+ this.sessionListener.onTransportDisconnected(info, altTransportAvailable, (MultiplexTransportConfig)this.transportConfig);
+ }
+
+
+ /* ***********************************************************************************************************************************************************************
+ * ***************************************************************** IProtocol Listener ********************************************************************************
+ *************************************************************************************************************************************************************************/
+
+ @Override
+ public void onProtocolMessageBytesToSend(SdlPacket packet) {
+ //Log.d(TAG, "onProtocolMessageBytesToSend - " + packet.getTransportType());
+ sdlProtocol.sendPacket(packet);
+ }
+
+ @Override
+ public void sendHeartbeat(IHeartbeatMonitor monitor) {
+ Log.d(TAG, "Asked to send heartbeat");
+ if (sdlProtocol != null) {
+ //FIXME sdlProtocol.sendHeartBeat(sessionId);
+ }
+ }
+
+ @Override
+ public void heartbeatTimedOut(IHeartbeatMonitor monitor) {
+ close();
+ }
+
+ public void onHeartbeatTimedOut(byte sessionId){
+ //TODO
+ }
+
+ public void onProtocolSessionStartedNACKed(SessionType sessionType, byte sessionID, byte version, String correlationID, List<String> rejectedParams){
+ onProtocolSessionNACKed(sessionType,sessionID,version,correlationID,rejectedParams);
+ }
+
+ @Override
+ public void onProtocolSessionNACKed(SessionType sessionType, byte sessionID, byte version, String correlationID, List<String> rejectedParams) {
+ this.sessionListener.onProtocolSessionStartedNACKed(sessionType,
+ sessionID, version, correlationID, rejectedParams);
+ if(serviceListeners != null && serviceListeners.containsKey(sessionType)){
+ CopyOnWriteArrayList<ISdlServiceListener> listeners = serviceListeners.get(sessionType);
+ for(ISdlServiceListener listener:listeners){
+ listener.onServiceError(this, sessionType, "Start "+ sessionType.toString() +" Service NACK'ed");
+ }
+ }
+ }
+
+
+
+ @Override
+ public void onProtocolHeartbeat(SessionType sessionType, byte sessionID) {
+ //TODO
+ }
+
+ @Override
+ public void onProtocolHeartbeatACK(SessionType sessionType, byte sessionID) {
+ //TODO
+ }
+
+
+ @Override
+ public void onResetOutgoingHeartbeat(SessionType sessionType, byte sessionID) {
+ //TODO
+ }
+
+ @Override
+ public void onResetIncomingHeartbeat(SessionType sessionType, byte sessionID) {
+ //TODO
+ }
+
+ /* ***********************************************************************************************************************************************************************
+ * ***************************************************************** Security Listener *********************************************************************************
+ *************************************************************************************************************************************************************************/
+
+
+ @Override
+ public void onSecurityInitialized() {
+
+ if (sdlProtocol != null && sdlSecurity != null)
+ {
+ List<SessionType> list = sdlSecurity.getServiceList();
+
+ SessionType service;
+ ListIterator<SessionType> iter = list.listIterator();
+
+ while (iter.hasNext()) {
+ service = iter.next();
+
+ if (service != null)
+ sdlProtocol.startService(service, getSessionId(), true);
+
+ iter.remove();
+ }
+ }
+ }
+
+ @Deprecated
+ public void clearConnection(){
+ //TODO reset SdlProtocol
+ }
+
+ @Deprecated
+ public static boolean removeConnection(SdlConnection connection){
+ return false;
+ }
+
+ @Deprecated
+ @Override
+ public void checkForOpenMultiplexConnection(SdlConnection connection){
+ }
+
+ @Override
+ public void stopStream(SessionType serviceType) {
+ if(SessionType.NAV.equals(serviceType)){
+ stopVideoStream();
+ }else if(SessionType.PCM.equals(serviceType)){
+ stopAudioStream();
+ }
+
+ }
+
+}
diff --git a/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java b/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java
index 688e498f9..875a05074 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java
@@ -48,11 +48,6 @@ public abstract class AbstractProtocol {
public abstract void StartProtocolService(SessionType sessionType, byte sessionID, boolean isEncrypted);
- // This method notifies SDLCore that secondary transport is connected. SDLCore needs this to
- // identify which app is registering to use the secondary transport to pair up with the
- // app's session from the primary transport.
- public abstract void registerSecondaryTransport(byte sessionId, TransportType transportType);
-
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
@@ -163,7 +158,4 @@ public abstract class AbstractProtocol {
resetIncomingHeartbeat(sessionType, sessionID);
}
- protected void connectSecondaryTransport(byte sessionID, TransportType transportType, Bundle params) {
- _protocolListener.connectSecondaryTransport(sessionID, transportType, params);
- }
} // end-class
diff --git a/sdl_android/src/main/java/com/smartdevicelink/protocol/IProtocolListener.java b/sdl_android/src/main/java/com/smartdevicelink/protocol/IProtocolListener.java
index ac5a84b83..dd9a29f7e 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/protocol/IProtocolListener.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/protocol/IProtocolListener.java
@@ -45,6 +45,4 @@ public interface IProtocolListener {
// Called to indicate that a protocol error was detected in received data.
void onProtocolError(String info, Exception e);
- // Called when SDLCore has updated secondary transport info or secondary transport is unavailable
- void connectSecondaryTransport(byte sessionID, TransportType transportType, Bundle params);
} // end-interfCe
diff --git a/sdl_android/src/main/java/com/smartdevicelink/protocol/SdlProtocol.java b/sdl_android/src/main/java/com/smartdevicelink/protocol/SdlProtocol.java
index 3c6db59f2..8caeffb06 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/protocol/SdlProtocol.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/protocol/SdlProtocol.java
@@ -36,6 +36,7 @@ import java.util.Map;
public class SdlProtocol {
private static final String TAG ="SdlProtocol";
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.1.0");
@@ -1021,6 +1022,8 @@ public class SdlProtocol {
public void onTransportDisconnected(String info, TransportRecord disconnectedTransport, List<TransportRecord> connectedTransports) {
if (disconnectedTransport == null) {
Log.d(TAG, "onTransportDisconnected");
+ transportManager.close(iSdlProtocol.getSessionId());
+ iSdlProtocol.shutdown("No transports left connected");
return;
} else {
Log.d(TAG, "onTransportDisconnected - " + disconnectedTransport.getType().name());
diff --git a/sdl_android/src/main/java/com/smartdevicelink/protocol/WiProProtocol.java b/sdl_android/src/main/java/com/smartdevicelink/protocol/WiProProtocol.java
index 57f84590b..67ba2d19e 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/protocol/WiProProtocol.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/protocol/WiProProtocol.java
@@ -1,8 +1,5 @@
package com.smartdevicelink.protocol;
-import android.os.Bundle;
-import android.util.Log;
-
import com.smartdevicelink.SdlConnection.SdlConnection;
import com.smartdevicelink.SdlConnection.SdlSession;
import com.smartdevicelink.exception.SdlException;
@@ -18,27 +15,19 @@ 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.transport.TransportConstants;
-import com.smartdevicelink.transport.enums.TransportType;
-import com.smartdevicelink.transport.utl.TransportRecord;
import com.smartdevicelink.util.BitConverter;
import com.smartdevicelink.util.DebugTool;
import com.smartdevicelink.util.Version;
import java.io.ByteArrayOutputStream;
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
-import java.util.Map;
public class WiProProtocol extends AbstractProtocol {
- private static final String TAG ="SdlProtocol";
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.1.0");
+ public static final Version MAX_PROTOCOL_VERSION = new Version("5.0.0");
private Version protocolVersion = new Version("1.0.0");
byte _version = 1;
@@ -48,42 +37,20 @@ public class WiProProtocol extends AbstractProtocol {
public static final int V2_HEADER_SIZE = 12;
private static int HEADER_SIZE = 8;
private static int TLS_MAX_RECORD_SIZE = 16384;
- private static final int PRIMARY_TRANSPORT_ID = 1;
- private static final int SECONDARY_TRANSPORT_ID = 2;
int hashID = 0;
int messageID = 0;
-
SdlConnection sdlconn = null;
- WeakReference<SdlSession> sessionWeakReference;
- @SuppressWarnings("unused")
- private int _heartbeatSendInterval_ms = 0;
- @SuppressWarnings("unused")
- private int _heartbeatReceiveInterval_ms = 0;
-
+ @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>();
- private HashMap<SessionType, TransportType> activeTransports = new HashMap<SessionType,TransportType>();
- private List<TransportType> availableTransports = new ArrayList<>();
-
- public static final List<SessionType> HIGH_BANDWIDTH_SERVICES
- = Arrays.asList(SessionType.NAV, SessionType.PCM);
-
- List<TransportType> requestedPrimaryTransports;
- List<TransportType> supportedSecondaryTransports;
-
- /**
- * Holds the priority of transports for a specific service when that service can be started
- * on a primary or secondary transport.
- */
- Map<SessionType, List<Integer>> transportPriorityForServiceMap;
- boolean requiresHighBandwidth = false;
- Map<TransportType, Bundle> secondaryTransportParams;
- TransportType connectedPrimaryTransport;
- Map<TransportType, List<ISecondaryTransportListener>> secondaryTransportListeners = new HashMap<>();
// Hide no-arg ctor
private WiProProtocol() {
@@ -93,19 +60,16 @@ public class WiProProtocol extends AbstractProtocol {
public WiProProtocol(IProtocolListener protocolListener) {
super(protocolListener);
-
- if (protocolListener instanceof SdlSession){
- sessionWeakReference = new WeakReference<>((SdlSession)protocolListener);
- }else if (protocolListener instanceof SdlConnection){
+ 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
+ * @return the max transfer unit
*/
public int getMtu(){
return mtus.get(SessionType.RPC).intValue();
@@ -119,221 +83,6 @@ public class WiProProtocol extends AbstractProtocol {
return mtu;
}
- public TransportType getTransportForSession(SessionType type){
- return activeTransports.get(type);
- }
-
- /**
- * For logging purposes, prints active services on each connected transport
- */
- public void printActiveTransports(){
- StringBuilder activeTransportString = new StringBuilder();
- for(Map.Entry entry : activeTransports.entrySet()){
- String sessionString = null;
- if(entry.getKey().equals(SessionType.NAV)) {
- sessionString = "NAV";
- }else if(entry.getKey().equals(SessionType.PCM)) {
- sessionString = "PCM";
- }else if(entry.getKey().equals(SessionType.RPC)) {
- sessionString = "RPC";
- }
- if(sessionString != null){
- activeTransportString.append("Session: " + sessionString
- + " Transport: " + entry.getValue().toString() + "\n");
- }
- }
- Log.d(TAG, "Active transports --- \n" + activeTransportString.toString());
- }
-
- private void printSecondaryTransportDetails(List<String> secondary, List<Integer> audio, List<Integer> video){
- StringBuilder secondaryDetailsBldr = new StringBuilder();
- secondaryDetailsBldr.append("Checking secondary transport details \n");
-
- if(secondary != null){
- secondaryDetailsBldr.append("Supported secondary transports: ");
- for(String s : secondary){
- secondaryDetailsBldr.append(" ").append(s);
- }
- secondaryDetailsBldr.append("\n");
- }else{
- Log.d(TAG, "Supported secondary transports list is empty!");
- }
- if(audio != null){
- secondaryDetailsBldr.append("Supported audio transports: ");
- for(int a : audio){
- secondaryDetailsBldr.append(" ").append(a);
- }
- secondaryDetailsBldr.append("\n");
- }
- if(video != null){
- secondaryDetailsBldr.append("Supported video transports: ");
- for(int v : video){
- secondaryDetailsBldr.append(" ").append(v);
- }
- secondaryDetailsBldr.append("\n");
- }
-
- Log.d(TAG, secondaryDetailsBldr.toString());
- }
-
- public void setRequiresHighBandwidth(boolean requiresHighBandwidth){
- this.requiresHighBandwidth = requiresHighBandwidth;
- }
-
- public void setPrimaryTransports(List<TransportType> primaryTransports){
- this.requestedPrimaryTransports = primaryTransports;
- }
-
- public void setTransportPriorityForService(SessionType serviceType, List<Integer> order){
- if(transportPriorityForServiceMap == null){
- transportPriorityForServiceMap = new HashMap<>();
- }
- this.transportPriorityForServiceMap.put(serviceType, order);
- for(SessionType service : HIGH_BANDWIDTH_SERVICES){
- if (transportPriorityForServiceMap.get(service) != null
- && transportPriorityForServiceMap.get(service).contains(PRIMARY_TRANSPORT_ID)) {
- if(connectedPrimaryTransport != null) {
- activeTransports.put(service, connectedPrimaryTransport);
- }
- }
- }
- }
-
- /**
- * Handles when a secondary transport can be used to start services on or when the request as failed.
- * @param transportType the transport type that the event has taken place on
- * @param registered if the transport was successfully registered on
- */
- private void handleSecondaryTransportRegistration(TransportType transportType, boolean registered){
- if(registered) {
- //Session has been registered on secondary transport
- Log.d(TAG, transportType.toString() + " transport was registered!");
- if (supportedSecondaryTransports.contains(transportType)) {
- // If the transport type that is now available to be used it should be checked
- // against the list of services that might be able to be started on it
-
- for(SessionType secondaryService : HIGH_BANDWIDTH_SERVICES){
- if (transportPriorityForServiceMap.containsKey(secondaryService)) {
- // If this service type has extra information from the RPC StartServiceACK
- // parse through it to find which transport should be used to start this
- // specific service type
- for(int transportNum : transportPriorityForServiceMap.get(secondaryService)){
- if(transportNum == PRIMARY_TRANSPORT_ID){
- break; // Primary is favored for this service type, break out...
- }else if(transportNum == SECONDARY_TRANSPORT_ID){
- // The secondary transport can be used to start this service
- activeTransports.put(secondaryService, transportType);
- break;
- }
- }
- }
- }
- }
- }else{
- Log.d(TAG, transportType.toString() + " transport was NOT registered!");
- }
- //Notify any listeners for this secondary transport
- List<ISecondaryTransportListener> listenerList = secondaryTransportListeners.remove(transportType);
- if(listenerList != null){
- for(ISecondaryTransportListener listener : listenerList){
- if(registered) {
- listener.onConnectionSuccess();
- }else{
- listener.onConnectionFailure();
- }
- }
- }
- printActiveTransports();
- }
-
- public void onTransportsConnectedUpdate(List<TransportRecord> transports){
- //TODO error checking for no longer connected transports
- Log.d(TAG, "onTransportsConnectedUpdate: ");
- for(TransportRecord t : transports) {
- Log.d(TAG, t.toString());
- }
-
- //Temporary: this logic should all be changed to handle multiple transports of the same type
- ArrayList<TransportType> connectedTransports = new ArrayList<>();
- for(TransportRecord record: transports){
- connectedTransports.add(record.getType());
- }
-
- if(connectedPrimaryTransport != null && !connectedTransports.contains(connectedPrimaryTransport)){
- //The primary transport being used is no longer part of the connected transports
- //TODO Should we perform a callback to SdlSession to inform of disconnect?
- connectedPrimaryTransport = null;
- return;
- }
-
- if(activeTransports.get(SessionType.RPC) == null){
- //There is no currently active transport for the RPC service meaning no primary transport
- TransportType preferredPrimaryTransport = getPreferredTransport(requestedPrimaryTransports,transports);
- if(preferredPrimaryTransport != null) {
- Log.d(TAG, "Sending start service RPC - " + preferredPrimaryTransport.name());
- connectedPrimaryTransport = preferredPrimaryTransport;
- startService(SessionType.RPC, (byte) 0x00, false);
- }else{
- onTransportNotAccepted("No transports match requested primary transport");
- }
- return;
- }else if(requiresHighBandwidth){
- //If this app has a primary transport already but requires a high bandwidth transport
- //to properly function, it is now time to register over that transport to be used
- TransportType preferredSecondaryTransport = getPreferredTransport(supportedSecondaryTransports,transports);
- if(preferredSecondaryTransport != null) {
- SdlSession session = null;
- if(sessionWeakReference != null){
- session = sessionWeakReference.get();
- }
- if(session != null) {
- Log.d(TAG, "Registering secondary transport!");
- registerSecondaryTransport(session.getSessionId(), preferredSecondaryTransport);
- }else{
- Log.e(TAG, "Session was null");
- }
- return; // For now, only support registering one secondary transport
- }else{
- Log.d(TAG, "No supported secondary transport");
- }
-
- }
- }
-
- /**
- * Retrieves the perferred transport for the given connected transport
- * @param preferredList the list of perferred transports (primary or secondary)
- * @param connectedTransports the current list of connected transports
- * @return the preferred connected transport
- */
- private TransportType getPreferredTransport(List<TransportType> preferredList, List<TransportRecord> connectedTransports) {
- for (TransportType transportType : preferredList) {
- for(TransportRecord record: connectedTransports) {
- if (record.getType().equals(transportType)) {
- return transportType;
- }
- }
- }
- return null;
- }
-
- public TransportType getPreferredPrimaryTransport(List<TransportRecord> transports){
- return getPreferredTransport(requestedPrimaryTransports, transports);
-
- }
-
- public TransportType getConnectedPrimaryTransport(){
- return connectedPrimaryTransport;
- }
-
- private void onTransportNotAccepted(String info){
- if(sessionWeakReference != null) {
- SdlSession session = sessionWeakReference.get();
- if (session != null) {
- session.shutdown(info);
- }
- }
- }
/**
* Use getProtocolVersion() or getMajorVersionByte instead.<br>
@@ -360,34 +109,33 @@ public class WiProProtocol extends AbstractProtocol {
* @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) );
- }
- }
-
- @Deprecated
+ 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
@@ -400,98 +148,93 @@ public class WiProProtocol extends AbstractProtocol {
SdlPacket header = SdlPacketFactory.createStartSessionACK(sessionType, sessionID, 0x00, getMajorVersionByte());
handlePacketToSend(header);
} // end-method
-
+
public void EndProtocolSession(SessionType sessionType, byte sessionID, int hashId) {
- Log.d(TAG, "EndProtocolSession");
SdlPacket header;
- if (sessionType.equals(SessionType.RPC)) { // check for RPC session
- if(_version < 5){
- header = SdlPacketFactory.createEndSession(sessionType, sessionID, hashID, getMajorVersionByte(), BitConverter.intToByteArray(hashID));
- }else{
- header = SdlPacketFactory.createEndSession(sessionType, sessionID, hashID, getMajorVersionByte(), new byte[0]);
- header.putTag(ControlFrameTags.RPC.EndService.HASH_ID, hashID);
- }
- }else{ //Any other service type we don't include the hash id
+ if (sessionType.equals(SessionType.RPC)) { // check for RPC session
+ if(_version < 5){
+ header = SdlPacketFactory.createEndSession(sessionType, sessionID, hashID, getMajorVersionByte(), BitConverter.intToByteArray(hashID));
+ }else{
header = SdlPacketFactory.createEndSession(sessionType, sessionID, hashID, getMajorVersionByte(), new byte[0]);
+ header.putTag(ControlFrameTags.RPC.EndService.HASH_ID, 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) {
+ public void SendMessage(ProtocolMessage protocolMsg) {
protocolMsg.setRPCType((byte) 0x00); //always sending a request
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) {
+ 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 {
+ } 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);
- }
- }
+ 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 ((sessionWeakReference != null || sdlconn != null) && protocolMsg.getPayloadProtected()){
- SdlSession session = null;
- if(sessionWeakReference != null){
- session = sessionWeakReference.get();
- }else if (sdlconn != null){
- session = sdlconn.findSessionById(sessionID);
- }
- if(session == null){
- return;
- }
+ 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)
+ 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);
+
+ 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.",
+ 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();
@@ -507,32 +250,30 @@ public class WiProProtocol extends AbstractProtocol {
SdlPacket firstHeader = SdlPacketFactory.createMultiSendDataFirst(sessionType, sessionID, messageID, getMajorVersionByte(),firstFrameData,protocolMsg.getPayloadProtected());
firstHeader.setPriorityCoefficient(1+protocolMsg.priorityCoefficient);
- firstHeader.setTransportType(activeTransports.get(sessionType));
//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;
- }
+ ++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.setTransportType(activeTransports.get(sessionType));
consecHeader.setPriorityCoefficient(i+2+protocolMsg.priorityCoefficient);
handlePacketToSend(consecHeader);
currentOffset += bytesToWrite;
@@ -541,7 +282,6 @@ public class WiProProtocol extends AbstractProtocol {
messageID++;
SdlPacket header = SdlPacketFactory.createSingleSendData(sessionType, sessionID, data.length, messageID, getMajorVersionByte(),data, protocolMsg.getPayloadProtected());
header.setPriorityCoefficient(protocolMsg.priorityCoefficient);
- header.setTransportType(activeTransports.get(sessionType));
handlePacketToSend(header);
}
}
@@ -550,9 +290,9 @@ public class WiProProtocol extends AbstractProtocol {
public void handlePacketReceived(SdlPacket packet){
//Check for a version difference
if (getMajorVersionByte() == 1) {
- setVersion((byte)packet.version);
+ setVersion((byte)packet.version);
}
-
+
MessageFrameAssembler assembler = getFrameAssemblerForFrame(packet);
assembler.handleFrame(packet);
@@ -560,8 +300,8 @@ public class WiProProtocol extends AbstractProtocol {
}
-
-
+
+
protected MessageFrameAssembler getFrameAssemblerForFrame(SdlPacket packet) {
Integer iSessionId = Integer.valueOf(packet.getSessionId());
Byte bySessionId = iSessionId.byteValue();
@@ -571,13 +311,13 @@ public class WiProProtocol extends AbstractProtocol {
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
@@ -599,15 +339,15 @@ public class WiProProtocol extends AbstractProtocol {
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)
+ if (packet.getFrameType() == FrameType.Consecutive && packet.getFrameInfo() == 0x0)
{
ProtocolMessage message = new ProtocolMessage();
message.setPayloadProtected(packet.isEncrypted());
@@ -629,20 +369,20 @@ public class WiProProtocol extends AbstractProtocol {
} else{
message.setData(accumulator.toByteArray());
}
-
+
_assemblerForMessageID.remove(packet.getMessageId());
-
+
try {
handleProtocolMessageReceived(message);
} catch (Exception excp) {
DebugTool.logError(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);
@@ -651,71 +391,67 @@ public class WiProProtocol extends AbstractProtocol {
if(accumulator != null)
handleRemainingFrame(packet);
}
-
+
} // end-method
-
+
protected void handleFrame(SdlPacket packet) {
-
+
if (packet.getPayload() != null && packet.getDataSize() > 0 && packet.isEncrypted() )
{
- SdlSession session = null;
- if(sessionWeakReference != null){
- session = sessionWeakReference.get();
- }else if(sdlconn != null){
- session = sdlconn.findSessionById((byte)packet.getSessionId());
- }
+ if (sdlconn != null)
+ {
+ SdlSession session = sdlconn.findSessionById((byte)packet.getSessionId());
- if(session == null){
- return;
- }
+ if (session == null)
+ return;
- SdlSecurityBase sdlSec = session.getSdlSecurity();
- byte[] dataToRead = new byte[4096];
+ 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;
+ 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
- ) {
+ || 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 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) {
- Log.d(TAG, "Control frame received: /n" + packet.toString());
Integer frameTemp = Integer.valueOf(packet.getFrameInfo());
Byte frameInfo = frameTemp.byteValue();
-
- SessionType serviceType = SessionType.valueOf((byte)packet.getServiceType());
- if (frameInfo == FrameDataControlFrameType.Heartbeat.getValue()) {
- handleProtocolHeartbeat(packet);
- }
+ 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()) {
+ 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
@@ -740,106 +476,12 @@ public class WiProProtocol extends AbstractProtocol {
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) {
+ if(version!=null){
//At this point we have confirmed the negotiated version between the module and the proxy
- protocolVersion = new Version((String) version);
- }else{
- protocolVersion = new Version("5.0.0");
+ protocolVersion = new Version((String)version);
}
-
- //Check to make sure this is a transport we are willing to accept
- TransportType transportType = packet.getTransportType();
- if(transportType == null || !requestedPrimaryTransports.contains(transportType)){
- onTransportNotAccepted("Transport is not in requested primary transports");
- return;
- }
-
- boolean activeTransportsHandled = false;
-
- // This enables custom behavior based on protocol version specifics
- if (protocolVersion.isNewerThan(new Version("5.1.0")) >= 0) {
-
- if (activeTransports.get(SessionType.RPC) == null) { //Might be a better way to handle this
-
- // Add this transport to the available transport list
- availableTransports.add(transportType);
-
- ArrayList<String> secondary = (ArrayList<String>) packet.getTag(ControlFrameTags.RPC.StartServiceACK.SECONDARY_TRANSPORTS);
- ArrayList<Integer> audio = (ArrayList<Integer>) packet.getTag(ControlFrameTags.RPC.StartServiceACK.AUDIO_SERVICE_TRANSPORTS);
- ArrayList<Integer> video = (ArrayList<Integer>) packet.getTag(ControlFrameTags.RPC.StartServiceACK.VIDEO_SERVICE_TRANSPORTS);
-
- printSecondaryTransportDetails(secondary,audio,video);
-
- //Build out the supported secondary transports received from the
- // RPC start service ACK.
- supportedSecondaryTransports = new ArrayList<>();
-
- for (String s : secondary) {
- Log.d(TAG, "Secondary transports allowed by core: " + s);
- if(s.equals(TransportConstants.TCP_WIFI)){
- supportedSecondaryTransports.add(TransportType.TCP);
- }else if(s.equals(TransportConstants.AOA_USB)){
- supportedSecondaryTransports.add(TransportType.USB);
- }else if(s.equals(TransportConstants.SPP_BLUETOOTH)){
- supportedSecondaryTransports.add(TransportType.BLUETOOTH);
- }
- }
-
- setTransportPriorityForService(SessionType.PCM, audio);
- setTransportPriorityForService(SessionType.NAV, video);
-
- activeTransports.put(SessionType.RPC, transportType);
- activeTransports.put(SessionType.BULK_DATA, transportType);
- activeTransports.put(SessionType.CONTROL, transportType);
-
- if (secondary == null) {
- // If no secondary transports were attached we should assume
- // the Video and Audio services can be used on primary
- if (requiresHighBandwidth
- && TransportType.BLUETOOTH.equals(transportType)) {
- //transport can't support high bandwidth
- onTransportNotAccepted(transportType + " can't support high bandwidth requirement, and secondary transport not supported.");
- return;
- }
-
- activeTransports.put(SessionType.NAV, transportType);
- activeTransports.put(SessionType.PCM, transportType);
- }
-
- activeTransportsHandled = true;
-
- } else {
- Log.w(TAG, "Received a start service ack for RPC service while already active on a different transport.");
- return;
- }
- }
-
- //Version is either not included or lower than 5.1.0
- if(requiresHighBandwidth
- && TransportType.BLUETOOTH.equals(transportType)){
- //transport can't support high bandwidth
- onTransportNotAccepted(transportType + " can't support high bandwidth requirement, and secondary transport not supported in this protocol version: " + version.toString());
- return;
- }
- if(!activeTransportsHandled) {
- availableTransports.add(transportType);
-
- activeTransports.put(SessionType.RPC, transportType);
- activeTransports.put(SessionType.BULK_DATA, transportType);
- activeTransports.put(SessionType.CONTROL, transportType);
- activeTransports.put(SessionType.NAV, transportType);
- activeTransports.put(SessionType.PCM, transportType);
- }
-
-
}else if(serviceType.equals(SessionType.NAV)){
- SdlSession session = null;
- if(sessionWeakReference != null){
- session = sessionWeakReference.get();
- }else if(sdlconn != null){
- session = sdlconn.findSessionById((byte)packet.getSessionId());
- }
+ SdlSession session = sdlconn.findSessionById((byte) packet.sessionId);
if(session != null) {
ImageResolution acceptedResolution = new ImageResolution();
VideoStreamingFormat acceptedFormat = new VideoStreamingFormat();
@@ -853,22 +495,7 @@ public class WiProProtocol extends AbstractProtocol {
session.setAcceptedVideoParams(agreedVideoParams);
}
}
- }else{ //TODO check if we should set protocol version here
- TransportType transportType = packet.getTransportType();
- if(requiresHighBandwidth
- && TransportType.BLUETOOTH.equals(transportType)){
- //transport can't support high bandwidth
- onTransportNotAccepted(transportType + "can't support high bandwidth requirement, and secondary transport not supported in this protocol version");
- return;
- }
- //If version < 5 and transport is acceptable we need to just add these
- availableTransports.add(transportType);
- activeTransports.put(SessionType.RPC, transportType);
- activeTransports.put(SessionType.BULK_DATA, transportType);
- activeTransports.put(SessionType.CONTROL, transportType);
- activeTransports.put(SessionType.NAV, transportType);
- activeTransports.put(SessionType.PCM, transportType);
-
+ }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);
@@ -876,7 +503,7 @@ public class WiProProtocol extends AbstractProtocol {
}
}
handleProtocolSessionStarted(serviceType,(byte) packet.getSessionId(), getMajorVersionByte(), "", hashID, packet.isEncrypted());
- } else if (frameInfo == FrameDataControlFrameType.StartSessionNACK.getValue()) {
+ } else if (frameInfo == FrameDataControlFrameType.StartSessionNACK.getValue()) {
List<String> rejectedParams = null;
if(packet.version >= 5){
String rejectedTag = null;
@@ -922,36 +549,14 @@ public class WiProProtocol extends AbstractProtocol {
int serviceDataAckSize = BitConverter.intFromByteArray(packet.getPayload(), 0);
handleProtocolServiceDataACK(serviceType, serviceDataAckSize,(byte)packet.getSessionId ());
}
- } else if (frameInfo == FrameDataControlFrameType.RegisterSecondaryTransportACK.getValue()) {
- handleSecondaryTransportRegistration(packet.getTransportType(),true);
- } else if (frameInfo == FrameDataControlFrameType.RegisterSecondaryTransportNACK.getValue()) {
- String reason = (String) packet.getTag(ControlFrameTags.RPC.RegisterSecondaryTransportNAK.REASON);
- handleSecondaryTransportRegistration(packet.getTransportType(),false);
- } else if (frameInfo == FrameDataControlFrameType.TransportEventUpdate.getValue()) {
- // Get TCP params
- String ipAddr = (String) packet.getTag(ControlFrameTags.RPC.TransportEventUpdate.TCP_IP_ADDRESS);
- Integer port = (Integer) packet.getTag(ControlFrameTags.RPC.TransportEventUpdate.TCP_PORT);
-
- if(secondaryTransportParams == null){
- secondaryTransportParams = new HashMap<>();
- }
-
- if(ipAddr != null && port != null) {
- Bundle bundle = new Bundle();
- bundle.putString(ControlFrameTags.RPC.TransportEventUpdate.TCP_IP_ADDRESS, ipAddr);
- bundle.putInt(ControlFrameTags.RPC.TransportEventUpdate.TCP_PORT, port);
- bundle.putString(TransportConstants.TRANSPORT, TransportType.TCP.name());
- secondaryTransportParams.put(TransportType.TCP, bundle);
- }
-
}
- _assemblerForMessageID.remove(packet.getMessageId());
+ _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());
+ SessionType serviceType = SessionType.valueOf((byte)packet.getServiceType());
if (serviceType == SessionType.RPC) {
message.setMessageType(MessageType.RPC);
} else if (serviceType == SessionType.BULK_DATA) {
@@ -980,9 +585,9 @@ public class WiProProtocol extends AbstractProtocol {
} else {
message.setData(packet.payload);
}
-
+
_assemblerForMessageID.remove(packet.getMessageId());
-
+
try {
handleProtocolMessageReceived(message);
} catch (Exception ex) {
@@ -993,16 +598,10 @@ public class WiProProtocol extends AbstractProtocol {
} // end-class
@Override
- @Deprecated
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 = null;
- if(sessionWeakReference != null){
- videoSession = sessionWeakReference.get();
- }else if(sdlconn != null){
- videoSession = sdlconn.findSessionById(sessionID);
- }
+ SdlSession videoSession = sdlconn.findSessionById(sessionID);
if(videoSession != null){
ImageResolution desiredResolution = videoSession.getDesiredVideoParams().getResolution();
VideoStreamingFormat desiredFormat = videoSession.getDesiredVideoParams().getFormat();
@@ -1020,149 +619,37 @@ public class WiProProtocol extends AbstractProtocol {
}
@Override
- public void registerSecondaryTransport(byte sessionId, TransportType transportType) {
- SdlPacket header = SdlPacketFactory.createRegisterSecondaryTransport(sessionId, getMajorVersionByte());
- header.setTransportType(transportType);
- handlePacketToSend(header);
- }
-
- public void startService(SessionType serviceType, byte sessionID, boolean isEncrypted) {
- Log.d(TAG, "startService");
- final SdlPacket header = SdlPacketFactory.createStartSession(serviceType, 0x00, getMajorVersionByte(), sessionID, isEncrypted);
- if(SessionType.RPC.equals(serviceType)){
- if(connectedPrimaryTransport != null) {
- header.setTransportType(connectedPrimaryTransport);
- }
- //This is going to be our primary transport
- header.putTag(ControlFrameTags.RPC.StartService.PROTOCOL_VERSION, MAX_PROTOCOL_VERSION.toString());
- handlePacketToSend(header);
- return; // We don't need to go any further
- }else if(serviceType.equals(SessionType.NAV)){
- SdlSession videoSession = null;
- if(sessionWeakReference != null){
- videoSession = sessionWeakReference.get();
- }else if(sdlconn != null){
- 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());
- }
- }
- }
- if(transportPriorityForServiceMap == null
- || transportPriorityForServiceMap.get(serviceType) == null
- || transportPriorityForServiceMap.get(serviceType).isEmpty()){
- //If there is no transport priority for this service it can be assumed it's primary
- header.setTransportType(connectedPrimaryTransport);
- handlePacketToSend(header);
- return;
- }
- int transportPriority = transportPriorityForServiceMap.get(serviceType).get(0);
- if(transportPriority == PRIMARY_TRANSPORT_ID){
- // Primary is favored, and we're already connected...
- Log.d(TAG, "Starting service over primary.");
- header.setTransportType(connectedPrimaryTransport);
- handlePacketToSend(header);
- }else if(transportPriority == SECONDARY_TRANSPORT_ID) {
- for(TransportType secondaryTransportType : supportedSecondaryTransports) {
- // Secondary is favored
- Log.d(TAG, "Starting service over secondary.");
- if(activeTransports.get(serviceType).equals(secondaryTransportType)){
- // Transport is already active
- header.setTransportType(secondaryTransportType);
- handlePacketToSend(header);
- return;
- }
-
- //If the secondary transport isn't connected yet that will have to be performed first
-
- List<ISecondaryTransportListener> listenerList = secondaryTransportListeners.get(secondaryTransportType);
- if(listenerList == null){
- listenerList = new ArrayList<>();
- secondaryTransportListeners.put(secondaryTransportType, listenerList);
- }
-
- //Check to see if the primary transport can also be used as a backup
- final boolean primaryTransportBackup = transportPriorityForServiceMap.get(serviceType).contains(PRIMARY_TRANSPORT_ID);
-
- listenerList.add(new ISecondaryTransportListener() {
- @Override
- public void onConnectionSuccess() {
- handlePacketToSend(header);
- }
-
- @Override
- public void onConnectionFailure() {
- if(primaryTransportBackup) {
- // Primary is also supported as backup
- header.setTransportType(connectedPrimaryTransport);
- handlePacketToSend(header);
- }else{
- Log.d(TAG, "Failed to connect secondary transport, threw away StartService");
- }
- }
- });
-
- if(secondaryTransportParams.containsKey(secondaryTransportType)) {
- header.setTransportType(secondaryTransportType);
- connectSecondaryTransport(sessionID, secondaryTransportType, secondaryTransportParams.get(secondaryTransportType));
- }else{
- Log.w(TAG, "No params to connect to secondary transport");
- }
-
- }
- }
- }
-
- @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());
- heartbeat.setTransportType(activeTransports.get(sessionID));
- handlePacketToSend(heartbeat);
+ 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());
- heartbeat.setTransportType(activeTransports.get(sessionID));
- handlePacketToSend(heartbeat);
+ final SdlPacket heartbeat = SdlPacketFactory.createHeartbeatACK(SessionType.CONTROL, sessionID, getMajorVersionByte());
+ handlePacketToSend(heartbeat);
}
@Override
public void EndProtocolService(SessionType serviceType, byte sessionID) {
- Log.d(TAG, "End protocol service called: " + serviceType.getName());
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]);
- TransportType transportType = activeTransports.get(sessionID);
- if(transportType != null){
- header.setTransportType(transportType);
- handlePacketToSend(header);
- }else{
- Log.w(TAG, "Not sending end session packet because there is no session on that transport");
- }
+ handlePacketToSend(header);
}
}
-} // end-class
+} // end-class \ No newline at end of file
diff --git a/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java b/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java
index 31a6d81b4..4bcab0d4d 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java
@@ -21,6 +21,7 @@ import com.smartdevicelink.Dispatcher.ProxyMessageDispatcher;
import com.smartdevicelink.SdlConnection.ISdlConnectionListener;
import com.smartdevicelink.SdlConnection.SdlConnection;
import com.smartdevicelink.SdlConnection.SdlSession;
+import com.smartdevicelink.SdlConnection.SdlSession2;
import com.smartdevicelink.encoder.VirtualDisplayEncoder;
import com.smartdevicelink.exception.SdlException;
import com.smartdevicelink.exception.SdlExceptionCause;
@@ -1289,7 +1290,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
// Setup SdlConnection
synchronized(CONNECTION_REFERENCE_LOCK) {
if(_transportConfig.getTransportType().equals(TransportType.MULTIPLEX)){
- this.sdlSession = new SdlSession(_interfaceBroker,(MultiplexTransportConfig)_transportConfig);
+ this.sdlSession = new SdlSession2(_interfaceBroker,(MultiplexTransportConfig)_transportConfig);
}else{
//FIXME this won't actually work
this.sdlSession = SdlSession.createSession(_wiproVersion,_interfaceBroker, _transportConfig);
diff --git a/sdl_android/src/main/java/com/smartdevicelink/streaming/StreamPacketizer.java b/sdl_android/src/main/java/com/smartdevicelink/streaming/StreamPacketizer.java
index a1fec462f..24f8eb926 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/streaming/StreamPacketizer.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/streaming/StreamPacketizer.java
@@ -36,7 +36,6 @@ public class StreamPacketizer extends AbstractPacketizer implements IVideoStream
private static final int MAX_QUEUE_SIZE = 256 * 1024;
public SdlConnection sdlConnection = null; //TODO remove completely
- private AbstractProtocol protocol;
private Object mPauseLock;
private boolean mPaused;
private boolean isServiceProtected = false;
@@ -145,13 +144,10 @@ public class StreamPacketizer extends AbstractPacketizer implements IVideoStream
{
if(_session == null) {
if (sdlConnection != null) {
- protocol = sdlConnection.getWiProProtocol();
- protocol.EndProtocolService(_serviceType,_rpcSessionID);
- //sdlConnection.endService(_serviceType, _rpcSessionID);
+ sdlConnection.endService(_serviceType, _rpcSessionID);
}
}else{
_session.endService(_serviceType,_rpcSessionID);
- //protocol.EndProtocolService(_serviceType,_rpcSessionID);
}
@@ -173,9 +169,6 @@ public class StreamPacketizer extends AbstractPacketizer implements IVideoStream
}
}
- public void setProtocol(AbstractProtocol protocol){
- this.protocol = protocol;
- }
/**
* Called by the app.
*
diff --git a/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransport.java b/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransport.java
index c7cb0e59e..1df6920d9 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransport.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransport.java
@@ -12,6 +12,9 @@ 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 java.util.List;
public class MultiplexTransport extends SdlTransport{
private final static String TAG = "Multiplex Transport";
@@ -256,6 +259,10 @@ public class MultiplexTransport extends SdlTransport{
}
@Override
+ public void onHardwareDisconnected(TransportRecord transportRecord, List<TransportRecord> connected) {
+ onHardwareDisconnected(TransportType.BLUETOOTH);
+ }
+ @Override
public void onHardwareDisconnected(TransportType type) {
super.onHardwareDisconnected(type);
if(connected){
diff --git a/sdl_android/src/main/java/com/smartdevicelink/transport/TransportBroker.java b/sdl_android/src/main/java/com/smartdevicelink/transport/TransportBroker.java
index 3d6ca47de..e3b73593d 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/transport/TransportBroker.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/transport/TransportBroker.java
@@ -75,7 +75,7 @@ public class TransportBroker {
routerServiceMessenger = null;
registeredWithRouterService = false;
isBound = false;
- onHardwareDisconnected(null);
+ onHardwareDisconnected(null, null);
}
};
}
@@ -406,7 +406,7 @@ public class TransportBroker {
}
public void onHardwareDisconnected(TransportRecord record, List<TransportRecord> connectedTransports){
- routerServiceDisconnect();
+
}
private void routerServiceDisconnect(){
diff --git a/sdl_android/src/main/java/com/smartdevicelink/transport/TransportManager.java b/sdl_android/src/main/java/com/smartdevicelink/transport/TransportManager.java
index 52625411d..12a7182a5 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/transport/TransportManager.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/transport/TransportManager.java
@@ -186,10 +186,10 @@ public class TransportManager {
Log.d(TAG, "Transport disconnected");
}
- if(connectedTransports == null || connectedTransports.isEmpty()){
- //There are no more transports to use so we can unbind
- super.onHardwareDisconnected(record,connectedTransports);
- }
+// if(connectedTransports == null || connectedTransports.isEmpty()){
+// //There are no more transports to use so we can unbind
+// super.onHardwareDisconnected(record,connectedTransports);
+// }
synchronized (TRANSPORT_STATUS_LOCK){
TransportManager.this.transportStatus.remove(record);