diff options
author | Joey Grover <joeygrover@gmail.com> | 2020-07-21 11:57:43 -0400 |
---|---|---|
committer | Joey Grover <joeygrover@gmail.com> | 2020-07-21 11:57:43 -0400 |
commit | 9d24a0e87d83b3544a4fd4bb208bec32479e322c (patch) | |
tree | c2c84f4db865a9f5c38d7dc1c3002de3f3ba3cc2 | |
parent | 82b7a3d7295fc3fc1791ff44bb98589df4f6b11b (diff) | |
download | sdl_android-9d24a0e87d83b3544a4fd4bb208bec32479e322c.tar.gz |
Refactor SdlSession2 into SdlSession with base
-rw-r--r-- | android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java | 1177 | ||||
-rw-r--r-- | android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession2.java | 364 | ||||
-rw-r--r-- | android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java | 9 | ||||
-rw-r--r-- | android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java | 81 | ||||
-rw-r--r-- | base/src/main/java/com/smartdevicelink/SdlConnection/BaseSdlSession.java (renamed from base/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java) | 134 | ||||
l--------- | baseAndroid/src/main/java/com/smartdevicelink/SdlConnection/BaseSdlSession.java | 1 | ||||
-rw-r--r-- | javaSE/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java | 124 |
7 files changed, 533 insertions, 1357 deletions
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java b/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java index 86488cca0..317003c32 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java @@ -1,838 +1,339 @@ -/*
- * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.smartdevicelink.SdlConnection;
-
-import android.annotation.SuppressLint;
-import android.os.Build;
-import android.view.Surface;
-
-import com.smartdevicelink.encoder.SdlEncoder;
-import com.smartdevicelink.encoder.VirtualDisplayEncoder;
-import com.smartdevicelink.exception.SdlException;
-import com.smartdevicelink.protocol.ProtocolMessage;
-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.ISdlServiceListener;
-import com.smartdevicelink.proxy.interfaces.IVideoStreamListener;
-import com.smartdevicelink.proxy.rpc.VideoStreamingFormat;
-import com.smartdevicelink.proxy.rpc.enums.VideoStreamingProtocol;
-import com.smartdevicelink.security.ISecurityInitializedListener;
-import com.smartdevicelink.security.SdlSecurityBase;
-import com.smartdevicelink.streaming.AbstractPacketizer;
-import com.smartdevicelink.streaming.IStreamListener;
-import com.smartdevicelink.streaming.StreamPacketizer;
-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.enums.TransportType;
-import com.smartdevicelink.util.DebugTool;
-import com.smartdevicelink.util.Version;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-@Deprecated
-public class SdlSession implements ISdlConnectionListener, IHeartbeatMonitorListener, IStreamListener, ISecurityInitializedListener {
-
- private static final String TAG = "SdlSession";
-
- protected final static int BUFF_READ_SIZE = 1024;
-
- private static CopyOnWriteArrayList<SdlConnection> shareConnections = new CopyOnWriteArrayList<SdlConnection>();
-
- private byte wiproProcolVer;
-
- protected BaseTransportConfig transportConfig;
- protected ISdlConnectionListener sessionListener;
- protected LockScreenManager lockScreenMan = new LockScreenManager();
- protected SdlSecurityBase sdlSecurity = null;
- protected VideoStreamingParameters desiredVideoParams = null;
- protected VideoStreamingParameters acceptedVideoParams = null;
-
- protected byte sessionId;
- protected int sessionHashId = 0;
- protected HashMap<SessionType, CopyOnWriteArrayList<ISdlServiceListener>> serviceListeners;
- protected CopyOnWriteArrayList<SessionType> encryptedServices = new CopyOnWriteArrayList<SessionType>();
-
-
- SdlConnection _sdlConnection = null;
-
- IHeartbeatMonitor _outgoingHeartbeatMonitor = null;
- IHeartbeatMonitor _incomingHeartbeatMonitor = null;
-
- StreamRPCPacketizer mRPCPacketizer = null;
- AbstractPacketizer mVideoPacketizer = null;
- StreamPacketizer mAudioPacketizer = null;
- SdlEncoder mSdlEncoder = null;
- VirtualDisplayEncoder virtualDisplayEncoder = null;
- boolean sdlSecurityInitializing = false;
-
- public static SdlSession createSession(byte wiproVersion, ISdlConnectionListener listener, BaseTransportConfig btConfig) {
-
- 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 IHeartbeatMonitor getOutgoingHeartbeatMonitor() {
- return _outgoingHeartbeatMonitor;
- }
-
- public IHeartbeatMonitor getIncomingHeartbeatMonitor() {
- return _incomingHeartbeatMonitor;
- }
-
- 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;
- }
-
- 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 resetSession(){
-
- }
-
- 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.sdlConnection = this.getSdlConnection();
- mVideoPacketizer = packetizer;
- mVideoPacketizer.start();
- }
- else if (sType.equals(SessionType.PCM))
- {
- 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.sdlConnection = this.getSdlConnection();
- mVideoPacketizer = packetizer;
- mVideoPacketizer.start();
- }
- else if (sType.equals(SessionType.PCM))
- {
- 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.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:
- DebugTool.logError(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;
- }
- }
-
- @Deprecated
- 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) {
- DebugTool.logError(TAG, "Unable to start streaming:" + e.toString());
- }
- }
-
- @Deprecated
- 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) {
- DebugTool.logError(TAG, "Unable to start streaming:" + e.toString());
- }
- return null;
- }
-
- @Deprecated
- public void pauseRPCStream()
- {
- if (mRPCPacketizer != null)
- {
- mRPCPacketizer.pause();
- }
- }
-
- @Deprecated
- public void resumeRPCStream()
- {
- if (mRPCPacketizer != null)
- {
- mRPCPacketizer.resume();
- }
- }
-
- @Deprecated
- 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);
-
- if (!sdlSecurityInitializing) {
- sdlSecurityInitializing = true;
- 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();
- }
- if (_incomingHeartbeatMonitor != null) {
- _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, BaseTransportConfig 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 (sessionType.eq(SessionType.RPC)){
- sessionHashId = hashID;
- wiproProcolVer = version;
- }
- 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();
-
- }
-
- @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) {
- DebugTool.logInfo(TAG, "Asked to send heartbeat");
- if (_sdlConnection != null)
- _sdlConnection.sendHeartbeat(this);
- }
-
- @Override
- public void heartbeatTimedOut(IHeartbeatMonitor monitor) {
- if (_sdlConnection != null)
- _sdlConnection._connectionListener.onHeartbeatTimedOut(this.sessionId);
- close();
- }
-
- 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 onAuthTokenReceived(String authToken, byte sessionId) {
- this.sessionListener.onAuthTokenReceived(authToken, 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;
- }
-
- public Version getProtocolVersion(){
- //Since this session version never supported a minor protocol version this should be fine
- return new Version(wiproProcolVer,0,0);
- }
-
- /**
- * Check to see if a transport is available to start/use the supplied service.
- * @param sessionType the session that should be checked for transport availability
- * @return true if there is either a supported
- * transport currently connected or a transport is
- * available to connect with for the supplied service type.
- * <br>false if there is no
- * transport connected to support the service type in question and
- * no possibility in the foreseeable future.
- */
- public boolean isTransportForServiceAvailable(SessionType sessionType){
- return _sdlConnection!= null
- && _sdlConnection._transport!= null
- && _sdlConnection._transport.getIsConnected()
- && ((sessionType == SessionType.RPC || sessionType == SessionType.CONTROL || sessionType == SessionType.BULK_DATA ) //If this is a service that can run on any transport just return true
- || (_sdlConnection._transport.getTransportType() == TransportType.USB || _sdlConnection._transport.getTransportType() == TransportType.TCP));
- }
-
-
-}
\ No newline at end of file +/* + * Copyright (c) 2018 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.SdlConnection; + +import android.content.Context; + +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.SdlProtocolBase; +import com.smartdevicelink.protocol.enums.SessionType; +import com.smartdevicelink.protocol.heartbeat.IHeartbeatMonitor; +import com.smartdevicelink.proxy.interfaces.IAudioStreamListener; +import com.smartdevicelink.proxy.interfaces.ISdlServiceListener; +import com.smartdevicelink.proxy.interfaces.IVideoStreamListener; +import com.smartdevicelink.proxy.rpc.VideoStreamingFormat; +import com.smartdevicelink.proxy.rpc.enums.VideoStreamingProtocol; +import com.smartdevicelink.streaming.AbstractPacketizer; +import com.smartdevicelink.streaming.IStreamListener; +import com.smartdevicelink.streaming.StreamPacketizer; +import com.smartdevicelink.streaming.video.RTPH264Packetizer; +import com.smartdevicelink.streaming.video.VideoStreamingParameters; +import com.smartdevicelink.transport.BaseTransportConfig; +import com.smartdevicelink.transport.MultiplexTransportConfig; +import com.smartdevicelink.transport.TCPTransportConfig; +import com.smartdevicelink.transport.enums.TransportType; +import com.smartdevicelink.util.DebugTool; +import com.smartdevicelink.util.MediaStreamingStatus; +import com.smartdevicelink.util.Version; + +import java.io.IOException; +import java.lang.ref.WeakReference; +import java.util.List; +import java.util.ListIterator; +import java.util.concurrent.CopyOnWriteArrayList; + +@SuppressWarnings({"WeakerAccess", "deprecation"}) +public class SdlSession extends BaseSdlSession { + private static final String TAG = "SdlSession"; + + WeakReference<Context> contextWeakReference; + MediaStreamingStatus mediaStreamingStatus; + boolean requiresAudioSupport = false; + + public SdlSession(ISdlConnectionListener listener, MultiplexTransportConfig config){ + super(listener,config); + this.transportConfig = config; + if(config != null){ + contextWeakReference = new WeakReference<>(config.getContext()); + this.requiresAudioSupport = Boolean.TRUE.equals(config.requiresAudioSupport()); //handle null case + + } + this.sessionListener = listener; + + } + + public SdlSession(ISdlConnectionListener listener, TCPTransportConfig config){ //TODO is it better to have two constructors or make it take BaseTransportConfig? + super(listener, config); + this.transportConfig = config; + this.sessionListener = listener; + } + + protected SdlProtocolBase getSdlProtocolImplementation(){ + if(transportConfig instanceof MultiplexTransportConfig) { + return new SdlProtocol(this, (MultiplexTransportConfig)transportConfig); + } else if(transportConfig instanceof TCPTransportConfig) { + return new SdlProtocol(this, (TCPTransportConfig)transportConfig); + } + + return null; + } + + boolean isAudioRequirementMet(){ + if(mediaStreamingStatus == null && contextWeakReference!= null && contextWeakReference.get() != null){ + mediaStreamingStatus = new MediaStreamingStatus(contextWeakReference.get(), new MediaStreamingStatus.Callback() { + @Override + public void onAudioNoLongerAvailable() { + close(); + shutdown("Audio output no longer available"); + } + }); + } + + // If requiresAudioSupport is false, or a supported audio output device is available + return !requiresAudioSupport || mediaStreamingStatus.isAudioOutputAvailable(); + + } + + + @SuppressWarnings("RedundantThrows") + @Override + public void startSession() throws SdlException { + if(!isAudioRequirementMet()){ + shutdown("Audio output not available"); + return; + } + + sdlProtocol.start(); + } + + @Override + public TransportType getCurrentTransportType() { + return TransportType.MULTIPLEX; + } + + @Override + public void shutdown(String info){ + DebugTool.logInfo(TAG, "Shutdown - " + info); + if(mediaStreamingStatus != null) { + mediaStreamingStatus.clear(); + } + super.shutdown(info); + + } + + /** + * Get the current protocol version used by this session + * @return Version that represents the Protocol version being used + */ + @Override + public Version getProtocolVersion(){ + if(sdlProtocol!=null){ + return sdlProtocol.getProtocolVersion(); + } + return new Version(1,0,0); + } + + + /* *********************************************************************************************************************************************************************** + * ***************************************************************** IProtocol Listener ******************************************************************************** + *************************************************************************************************************************************************************************/ + + @Override + public void onProtocolMessageBytesToSend(SdlPacket packet) { + //Log.d(TAG, "onProtocolMessageBytesToSend - " + packet.getTransportType()); + sdlProtocol.sendPacket(packet); + } + + @Override + public void onProtocolSessionStarted(SessionType sessionType, + byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) { + + DebugTool.logInfo(TAG, "Protocol session started"); + + this.sessionId = sessionID; + if (sessionType.eq(SessionType.RPC)){ + sessionHashId = hashID; + } + 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); + } + } + + } + + 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); + if(listeners != null) { + for (ISdlServiceListener listener : listeners) { + listener.onServiceError(this, sessionType, "Start " + sessionType.toString() + " Service NAKed"); + } + } + } + } + @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 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"); + } + } + } + + /* Not supported methods from IProtocolListener */ + @Override + public void onHeartbeatTimedOut(byte sessionId){ /* Not supported */} + @Override + public void onAuthTokenReceived(String authToken, byte sessionID){/* Do nothing */ } + + /* *********************************************************************************************************************************************************************** + * ***************************************************************** Fix after initial refactor ********************************************************************************* + *************************************************************************************************************************************************************************/ + //FIXME there is a lot of spaghetti code here that needs to be addressed. For first refactor the + // the goal is to only refactor SdlSession. Another PR should be opened to fix all the packetizer + // classes and method calls. + + //FIXME Move this logic to the related streaming manager + private AbstractPacketizer videoPacketizer; + private StreamPacketizer audioPacketizer; + + IStreamListener streamListener = new IStreamListener() { + @Override + public void sendStreamPacket(ProtocolMessage pm) { + sendMessage(pm); + } + }; + + private VideoStreamingProtocol getAcceptedProtocol() { + if (acceptedVideoParams != null) { + VideoStreamingFormat format = acceptedVideoParams.getFormat(); + if (format != null && format.getProtocol() != null) { + return format.getProtocol(); + } + } + //Returns default protocol if none are found + return new VideoStreamingParameters().getFormat().getProtocol(); + + } + + public IVideoStreamListener startVideoStream() { + VideoStreamingProtocol protocol = getAcceptedProtocol(); + try { + switch (protocol) { + case RAW: { + videoPacketizer = new StreamPacketizer(streamListener, null, SessionType.NAV, this.sessionId, this); + videoPacketizer.start(); + return (IVideoStreamListener)videoPacketizer; + } + case RTP: { + //FIXME why is this not an extension of StreamPacketizer? + videoPacketizer = new RTPH264Packetizer(streamListener, SessionType.NAV, this.sessionId, this); + videoPacketizer.start(); + return (IVideoStreamListener)videoPacketizer; + } + default: + DebugTool.logError(TAG, "Protocol " + protocol + " is not supported."); + return null; + } + } catch (IOException e) { + return null; + } + } + + public IAudioStreamListener startAudioStream() { + try { + audioPacketizer = new StreamPacketizer(streamListener, null, SessionType.PCM, this.sessionId, this); + audioPacketizer.start(); + return audioPacketizer; + } catch (IOException e) { + return null; + } + + } + @Override + public void stopStream(SessionType serviceType) { + if(SessionType.NAV.equals(serviceType)){ + stopVideoStream(); + }else if(SessionType.PCM.equals(serviceType)){ + stopAudioStream(); + } + // Notify any listeners of the service being ended + if(serviceListeners != null && serviceListeners.containsKey(serviceType)){ + CopyOnWriteArrayList<ISdlServiceListener> listeners = serviceListeners.get(serviceType); + if (listeners != null && listeners.size() > 0) { + for (ISdlServiceListener listener : listeners) { + listener.onServiceEnded(this, serviceType); + } + } + } + } + + + public boolean stopVideoStream() { + if (videoPacketizer != null) { + videoPacketizer.stop(); + return true; + } + return false; + } + + public boolean stopAudioStream() { + if (audioPacketizer != null) { + audioPacketizer.stop(); + return true; + } + return false; + } + +} diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession2.java b/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession2.java deleted file mode 100644 index 44bb1fbfc..000000000 --- a/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession2.java +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright (c) 2018 Livio, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Livio Inc. nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -package com.smartdevicelink.SdlConnection; - -import android.content.Context; - -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.TCPTransportConfig; -import com.smartdevicelink.transport.enums.TransportType; -import com.smartdevicelink.util.DebugTool; -import com.smartdevicelink.util.MediaStreamingStatus; -import com.smartdevicelink.util.Version; - -import java.lang.ref.WeakReference; -import java.util.List; -import java.util.ListIterator; -import java.util.concurrent.CopyOnWriteArrayList; - -@SuppressWarnings({"WeakerAccess", "deprecation"}) -public class SdlSession2 extends SdlSession implements ISdlProtocol{ - private static final String TAG = "SdlSession2"; - - - final protected SdlProtocol sdlProtocol; - WeakReference<Context> contextWeakReference; - MediaStreamingStatus mediaStreamingStatus; - boolean requiresAudioSupport = false; - - @SuppressWarnings("SameReturnValue") - @Deprecated - public static SdlSession2 createSession(byte protocolVersion, ISdlConnectionListener listener, BaseTransportConfig btConfig) { - return null; - } - - public SdlSession2(ISdlConnectionListener listener, MultiplexTransportConfig config){ - this.transportConfig = config; - if(config != null){ - contextWeakReference = new WeakReference<>(config.getContext()); - this.requiresAudioSupport = Boolean.TRUE.equals(config.requiresAudioSupport()); //handle null case - - } - this.sessionListener = listener; - this.sdlProtocol = new SdlProtocol(this,config); - - } - - public SdlSession2(ISdlConnectionListener listener, TCPTransportConfig config){ //TODO is it better to have two constructors or make it take BaseTransportConfig? - this.transportConfig = config; - this.sessionListener = listener; - this.sdlProtocol = new SdlProtocol(this,config); - } - - boolean isAudioRequirementMet(){ - if(mediaStreamingStatus == null && contextWeakReference!= null && contextWeakReference.get() != null){ - mediaStreamingStatus = new MediaStreamingStatus(contextWeakReference.get(), new MediaStreamingStatus.Callback() { - @Override - public void onAudioNoLongerAvailable() { - close(); - shutdown("Audio output no longer available"); - } - }); - } - - // If requiresAudioSupport is false, or a supported audio output device is available - return !requiresAudioSupport || mediaStreamingStatus.isAudioOutputAvailable(); - - } - - @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); - } - } - - @Override - public void resetSession (){ - sdlProtocol.resetSession(); - } - - @SuppressWarnings("ConstantConditions") - @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); - - if (!sdlSecurityInitializing) { - sdlSecurityInitializing = true; - 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"; - } - - - @SuppressWarnings("RedundantThrows") - @Override - public void startSession() throws SdlException { - if(!isAudioRequirementMet()){ - shutdown("Audio output not available"); - return; - } - - 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){ - DebugTool.logInfo(TAG, "Shutdown - " + info); - if(mediaStreamingStatus != null) { - mediaStreamingStatus.clear(); - } - this.sessionListener.onTransportDisconnected(info); - - } - - @Override - public void onTransportDisconnected(String info, boolean altTransportAvailable, BaseTransportConfig transportConfig) { - this.sessionListener.onTransportDisconnected(info, altTransportAvailable, this.transportConfig); - } - - /** - * Get the current protocol version used by this session - * @return Version that represents the Protocol version being used - */ - @Override - public Version getProtocolVersion(){ - if(sdlProtocol!=null){ - return sdlProtocol.getProtocolVersion(); - } - return new Version(1,0,0); - } - - - /* *********************************************************************************************************************************************************************** - * ***************************************************************** IProtocol Listener ******************************************************************************** - *************************************************************************************************************************************************************************/ - - @Override - public void onProtocolMessageBytesToSend(SdlPacket packet) { - //Log.d(TAG, "onProtocolMessageBytesToSend - " + packet.getTransportType()); - sdlProtocol.sendPacket(packet); - } - - - 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); - if(listeners != null) { - for (ISdlServiceListener listener : listeners) { - listener.onServiceError(this, sessionType, "Start " + sessionType.toString() + " Service NAKed"); - } - } - } - } - - /* Not supported methods from IProtocolListener */ - @Override - public void sendHeartbeat(IHeartbeatMonitor monitor) {/* Not supported */ } - @Override - public void heartbeatTimedOut(IHeartbeatMonitor monitor) {/* Not supported */} - @Override - public void onHeartbeatTimedOut(byte sessionId){ /* Not supported */} - @Override - public void onProtocolHeartbeat(SessionType sessionType, byte sessionID) { /* Not supported */} - @Override - public void onProtocolHeartbeatACK(SessionType sessionType, byte sessionID) {/* Not supported */} - @Override - public void onResetOutgoingHeartbeat(SessionType sessionType, byte sessionID) {/* Not supported */} - @Override - public void onResetIncomingHeartbeat(SessionType sessionType, byte sessionID) {/* Not supported */} - @Override - public void onAuthTokenReceived(String authToken, byte sessionID){/* Do nothing */ } - - /* *********************************************************************************************************************************************************************** - * ***************************************************************** 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(); - } - } - } - - @Override - public void stopStream(SessionType serviceType) { - if(SessionType.NAV.equals(serviceType)){ - stopVideoStream(); - }else if(SessionType.PCM.equals(serviceType)){ - stopAudioStream(); - } - // Notify any listeners of the service being ended - if(serviceListeners != null && serviceListeners.containsKey(serviceType)){ - CopyOnWriteArrayList<ISdlServiceListener> listeners = serviceListeners.get(serviceType); - if (listeners != null && listeners.size() > 0) { - for (ISdlServiceListener listener : listeners) { - listener.onServiceEnded(this, serviceType); - } - } - } - } - - @Override - public void onAuthTokenReceived(String authToken) { - sessionListener.onAuthTokenReceived(authToken,sessionId); - } - - /** - * Check to see if a transport is available to start/use the supplied service. - * @param sessionType the session that should be checked for transport availability - * @return true if there is either a supported - * transport currently connected or a transport is - * available to connect with for the supplied service type. - * <br>false if there is no - * transport connected to support the service type in question and - * no possibility in the foreseeable future. - */ - @Override - public boolean isTransportForServiceAvailable(SessionType sessionType){ - return sdlProtocol!=null && sdlProtocol.isTransportForServiceAvailable(sessionType); - } - - - @Override - @Deprecated - public void clearConnection(){/* Not supported */} - - @SuppressWarnings("SameReturnValue") - @Deprecated - public static boolean removeConnection(SdlConnection connection){/* Not supported */ return false;} - - @Deprecated - @Override - public void checkForOpenMultiplexConnection(SdlConnection connection){/* Not supported */} - - -} diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java index 021e5d49a..b60c9041d 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java @@ -37,7 +37,6 @@ import android.content.Context; import android.support.annotation.RestrictTo; import com.smartdevicelink.SdlConnection.SdlSession; -import com.smartdevicelink.SdlConnection.SdlSession2; import com.smartdevicelink.exception.SdlException; import com.smartdevicelink.exception.SdlExceptionCause; import com.smartdevicelink.protocol.enums.SessionType; @@ -94,11 +93,11 @@ public class LifecycleManager extends BaseLifecycleManager { } if (_transportConfig != null && _transportConfig.getTransportType().equals(TransportType.MULTIPLEX)) { - this.session = new SdlSession2(sdlConnectionListener, (MultiplexTransportConfig) _transportConfig); + this.session = new SdlSession(sdlConnectionListener, (MultiplexTransportConfig) _transportConfig); } else if (_transportConfig != null && _transportConfig.getTransportType().equals(TransportType.TCP)) { - this.session = new SdlSession2(sdlConnectionListener, (TCPTransportConfig) _transportConfig); - } else { - this.session = SdlSession.createSession((byte) getProtocolVersion().getMajor(), sdlConnectionListener, _transportConfig); + this.session = new SdlSession(sdlConnectionListener, (TCPTransportConfig) _transportConfig); + }else{ + DebugTool.logError(TAG,"Unable to create session for transport type"); } } diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java b/android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java index b3d6df61d..c96c84202 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java @@ -40,6 +40,7 @@ import android.os.Build; import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
+import android.os.TransactionTooLargeException;
import android.support.annotation.NonNull;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
@@ -54,9 +55,7 @@ import com.smartdevicelink.BuildConfig; import com.smartdevicelink.Dispatcher.IDispatchingStrategy;
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;
@@ -148,6 +147,7 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
+import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -619,7 +619,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> if (_advancedLifecycleManagementEnabled) {
// Cycle the proxy
- if(SdlConnection.isLegacyModeEnabled()){ //FIXME
+ if(false){ //FIXME
cycleProxy(SdlDisconnectedReason.LEGACY_BLUETOOTH_MODE_ENABLED);
}else{
@@ -678,11 +678,11 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> {
HeartbeatMonitor outgoingHeartbeatMonitor = new HeartbeatMonitor();
outgoingHeartbeatMonitor.setInterval(_transportConfig.getHeartBeatTimeout());
- sdlSession.setOutgoingHeartbeatMonitor(outgoingHeartbeatMonitor);
+ //sdlSession.setOutgoingHeartbeatMonitor(outgoingHeartbeatMonitor);
HeartbeatMonitor incomingHeartbeatMonitor = new HeartbeatMonitor();
incomingHeartbeatMonitor.setInterval(_transportConfig.getHeartBeatTimeout());
- sdlSession.setIncomingHeartbeatMonitor(incomingHeartbeatMonitor);
+ //sdlSession.setIncomingHeartbeatMonitor(incomingHeartbeatMonitor);
}
startRPCProtocolSession();
@@ -1645,11 +1645,11 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> }
if (_transportConfig != null && _transportConfig.getTransportType().equals(TransportType.MULTIPLEX)) {
- this.sdlSession = new SdlSession2(_interfaceBroker, (MultiplexTransportConfig) _transportConfig);
+ this.sdlSession = new SdlSession(_interfaceBroker, (MultiplexTransportConfig) _transportConfig);
}else if(_transportConfig != null &&_transportConfig.getTransportType().equals(TransportType.TCP)){
- this.sdlSession = new SdlSession2(_interfaceBroker, (TCPTransportConfig) _transportConfig);
+ this.sdlSession = new SdlSession(_interfaceBroker, (TCPTransportConfig) _transportConfig);
}else {
- this.sdlSession = SdlSession.createSession((byte)getProtocolVersion().getMajor(),_interfaceBroker, _transportConfig);
+ throw new SdlException(new UnsupportedOperationException("Unable to create session with supplied transport config"));
}
}
@@ -1683,7 +1683,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> {
if (sdlSession == null || _transportConfig == null) return;
- String sTransComment = sdlSession.getBroadcastComment(_transportConfig);
+ String sTransComment = "no";//sdlSession.getBroadcastComment(_transportConfig);
if (sTransComment == null || sTransComment.equals("")) return;
@@ -4053,7 +4053,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> //setup lockscreeninfo
if (sdlSession != null)
{
- sdlSession.getLockScreenMan().setHMILevel(msg.getHmiLevel());
+ //sdlSession.getLockScreenMan().setHMILevel(msg.getHmiLevel());
}
msg.setFirstRun(firstTimeFull);
@@ -4074,13 +4074,13 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> @Override
public void run() {
_proxyListener.onOnHMIStatus(msg);
- _proxyListener.onOnLockScreenNotification(sdlSession.getLockScreenMan().getLockObj());
+ //_proxyListener.onOnLockScreenNotification(sdlSession.getLockScreenMan().getLockObj());
onRPCNotificationReceived(msg);
}
});
} else {
_proxyListener.onOnHMIStatus(msg);
- _proxyListener.onOnLockScreenNotification(sdlSession.getLockScreenMan().getLockObj());
+ //_proxyListener.onOnLockScreenNotification(sdlSession.getLockScreenMan().getLockObj());
onRPCNotificationReceived(msg);
}
} else if (functionName.equals(FunctionID.ON_COMMAND.toString())) {
@@ -4110,7 +4110,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> if (sdlSession != null)
{
DriverDistractionState drDist = msg.getState();
- sdlSession.getLockScreenMan().setDriverDistStatus(drDist == DriverDistractionState.DD_ON);
+ //sdlSession.getLockScreenMan().setDriverDistStatus(drDist == DriverDistractionState.DD_ON);
}
msg.format(rpcSpecVersion, true);
@@ -4120,13 +4120,13 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> @Override
public void run() {
_proxyListener.onOnDriverDistraction(msg);
- _proxyListener.onOnLockScreenNotification(sdlSession.getLockScreenMan().getLockObj());
+ //_proxyListener.onOnLockScreenNotification(sdlSession.getLockScreenMan().getLockObj());
onRPCNotificationReceived(msg);
}
});
} else {
_proxyListener.onOnDriverDistraction(msg);
- _proxyListener.onOnLockScreenNotification(sdlSession.getLockScreenMan().getLockObj());
+ //_proxyListener.onOnLockScreenNotification(sdlSession.getLockScreenMan().getLockObj());
onRPCNotificationReceived(msg);
}
} else if (functionName.equals(FunctionID.ON_ENCODED_SYNC_P_DATA.toString())) {
@@ -5017,7 +5017,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> }
try {
- StreamRPCPacketizer rpcPacketizer = new StreamRPCPacketizer((SdlProxyBase<IProxyListenerBase>) this, sdlSession, is, request, sType, rpcSessionID, protocolVersion, rpcSpecVersion, lSize, sdlSession);
+ StreamRPCPacketizer rpcPacketizer = null;//new StreamRPCPacketizer((SdlProxyBase<IProxyListenerBase>) this, sdlSession, is, request, sType, rpcSessionID, protocolVersion, rpcSpecVersion, lSize, sdlSession);
rpcPacketizer.start();
return new RPCStreamController(rpcPacketizer, request.getCorrelationID());
} catch (Exception e) {
@@ -5038,7 +5038,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> }
try {
- StreamRPCPacketizer rpcPacketizer = new StreamRPCPacketizer((SdlProxyBase<IProxyListenerBase>) this, sdlSession, is, request, sType, rpcSessionID, protocolVersion, rpcSpecVersion, lSize, sdlSession);
+ StreamRPCPacketizer rpcPacketizer = null;//new StreamRPCPacketizer((SdlProxyBase<IProxyListenerBase>) this, sdlSession, is, request, sType, rpcSessionID, protocolVersion, rpcSpecVersion, lSize, sdlSession);
rpcPacketizer.start();
return new RPCStreamController(rpcPacketizer, request.getCorrelationID());
} catch (Exception e) {
@@ -5061,18 +5061,18 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> @SuppressWarnings("UnusedReturnValue")
public boolean startRPCStream(InputStream is, RPCRequest msg) {
if (sdlSession == null) return false;
- sdlSession.startRPCStream(is, msg, SessionType.RPC, sdlSession.getSessionId(), (byte)getProtocolVersion().getMajor());
+ //sdlSession.startRPCStream(is, msg, SessionType.RPC, sdlSession.getSessionId(), (byte)getProtocolVersion().getMajor());
return true;
}
public OutputStream startRPCStream(RPCRequest msg) {
if (sdlSession == null) return null;
- return sdlSession.startRPCStream(msg, SessionType.RPC, sdlSession.getSessionId(), (byte)getProtocolVersion().getMajor());
+ return null;//sdlSession.startRPCStream(msg, SessionType.RPC, sdlSession.getSessionId(), (byte)getProtocolVersion().getMajor());
}
public void endRPCStream() {
if (sdlSession == null) return;
- sdlSession.stopRPCStream();
+ //sdlSession.stopRPCStream();
}
private class CallableMethod implements Callable<Void> {
@@ -5151,7 +5151,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> if (navServiceStartResponse) {
try {
- sdlSession.startStream(is, SessionType.NAV, sdlSession.getSessionId());
+ //sdlSession.startStream(is, SessionType.NAV, sdlSession.getSessionId());
return true;
} catch (Exception e) {
return false;
@@ -5199,7 +5199,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> if (navServiceStartResponse) {
try {
- return sdlSession.startStream(SessionType.NAV, sdlSession.getSessionId());
+ return null;//sdlSession.startStream(SessionType.NAV, sdlSession.getSessionId());
} catch (Exception e) {
return null;
}
@@ -5281,7 +5281,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> if (pcmServiceStartResponse) {
try {
- sdlSession.startStream(is, SessionType.PCM, sdlSession.getSessionId());
+ //sdlSession.startStream(is, SessionType.PCM, sdlSession.getSessionId());
return true;
} catch (Exception e) {
return false;
@@ -5314,7 +5314,8 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> if (pcmServiceStartResponse) {
try {
- return sdlSession.startStream(SessionType.PCM, sdlSession.getSessionId());
+ return null;
+ //return sdlSession.startStream(SessionType.PCM, sdlSession.getSessionId());
} catch (Exception e) {
return null;
}
@@ -5379,7 +5380,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> VideoStreamingParameters acceptedParams = tryStartVideoStream(isEncrypted, parameters);
if (acceptedParams != null) {
- return sdlSession.startVideoStream();
+ return null;// sdlSession.startVideoStream();
} else {
return null;
}
@@ -5416,7 +5417,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> navServiceEndResponseReceived = false;
navServiceEndResponse = false;
- sdlSession.stopVideoStream();
+ //sdlSession.stopVideoStream();
FutureTask<Void> fTask = createFutureTask(new CallableMethod(RESPONSE_WAIT_TIME));
ScheduledExecutorService scheduler = createScheduler();
@@ -5435,7 +5436,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> */
@SuppressWarnings("unused")
public boolean pauseVideoStream() {
- return sdlSession != null && sdlSession.pauseVideoStream();
+ return false;//sdlSession != null && sdlSession.pauseVideoStream();
}
/**
@@ -5444,7 +5445,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> */
@SuppressWarnings("unused")
public boolean resumeVideoStream() {
- return sdlSession != null && sdlSession.resumeVideoStream();
+ return false;//sdlSession != null && sdlSession.resumeVideoStream();
}
/**
@@ -5475,8 +5476,8 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> VideoStreamingParameters acceptedParams = tryStartVideoStream(isEncrypted, desired);
if (acceptedParams != null) {
- return sdlSession.createOpenGLInputSurface(frameRate, iFrameInterval, width,
- height, bitrate, SessionType.NAV, sdlSession.getSessionId());
+ return null;//sdlSession.createOpenGLInputSurface(frameRate, iFrameInterval, width,
+ //height, bitrate, SessionType.NAV, sdlSession.getSessionId());
} else {
return null;
}
@@ -5625,7 +5626,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> public void startEncoder () {
if (sdlSession == null || !sdlSession.getIsConnected()) return;
- sdlSession.startEncoder();
+ //sdlSession.startEncoder();
}
/**
@@ -5635,7 +5636,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> public void releaseEncoder() {
if (sdlSession == null || !sdlSession.getIsConnected()) return;
- sdlSession.releaseEncoder();
+ //sdlSession.releaseEncoder();
}
/**
@@ -5645,7 +5646,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> public void drainEncoder(boolean endOfStream) {
if (sdlSession == null || !sdlSession.getIsConnected()) return;
- sdlSession.drainEncoder(endOfStream);
+ //sdlSession.drainEncoder(endOfStream);
}
private void addNavListener(){
@@ -5726,7 +5727,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> if (pcmServiceStartResponse) {
DebugTool.logInfo(TAG, "StartService for audio succeeded");
- return sdlSession.startAudioStream();
+ return null;//sdlSession.startAudioStream();
} else {
if (pcmServiceStartRejectedParams != null) {
StringBuilder builder = new StringBuilder();
@@ -5754,7 +5755,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> pcmServiceEndResponseReceived = false;
pcmServiceEndResponse = false;
- sdlSession.stopAudioStream();
+ //sdlSession.stopAudioStream();
FutureTask<Void> fTask = createFutureTask(new CallableMethod(RESPONSE_WAIT_TIME));
ScheduledExecutorService scheduler = createScheduler();
@@ -5773,7 +5774,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> */
@SuppressWarnings("unused")
public boolean pauseAudioStream() {
- return sdlSession != null && sdlSession.pauseAudioStream();
+ return false;//sdlSession != null && sdlSession.pauseAudioStream();
}
/**
@@ -5782,7 +5783,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> */
@SuppressWarnings("unused")
public boolean resumeAudioStream() {
- return sdlSession != null && sdlSession.resumeAudioStream();
+ return false;//sdlSession != null && sdlSession.resumeAudioStream();
}
private void NavServiceStarted() {
@@ -5867,7 +5868,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> return;
}
- LockScreenManager lockMan = sdlSession.getLockScreenMan();
+ LockScreenManager lockMan = null;//sdlSession.getLockScreenMan();
Bitmap bitmap = lockMan.getLockScreenIcon();
// read bitmap if it was already downloaded so we don't have to download it every time
@@ -5876,7 +5877,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> }
else{
String url = lockScreenIconRequest.getUrl().replaceFirst("http://", "https://");
- sdlSession.getLockScreenMan().downloadLockScreenIcon(url, l);
+ //sdlSession.getLockScreenMan().downloadLockScreenIcon(url, l);
}
}
@@ -8408,7 +8409,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> private void startStream(VideoStreamingParameters parameters, boolean encrypted){
//Start the service first
//streamListener = startVideoStream(encrypted,parameters);d
- streamListener = sdlSession.startVideoStream();
+ //streamListener = sdlSession.startVideoStream();
if(streamListener == null){
DebugTool.logError(TAG, "Error starting video service");
return;
diff --git a/base/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java b/base/src/main/java/com/smartdevicelink/SdlConnection/BaseSdlSession.java index fb82bd8a2..6ed74b241 100644 --- a/base/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java +++ b/base/src/main/java/com/smartdevicelink/SdlConnection/BaseSdlSession.java @@ -1,44 +1,12 @@ -/* - * Copyright (c) 2019 Livio, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Livio Inc. nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - package com.smartdevicelink.SdlConnection; - import com.smartdevicelink.exception.SdlException; import com.smartdevicelink.protocol.ISdlProtocol; import com.smartdevicelink.protocol.ProtocolMessage; import com.smartdevicelink.protocol.SdlPacket; -import com.smartdevicelink.protocol.enums.SessionType; import com.smartdevicelink.protocol.SdlProtocol; +import com.smartdevicelink.protocol.SdlProtocolBase; +import com.smartdevicelink.protocol.enums.SessionType; import com.smartdevicelink.proxy.interfaces.ISdlServiceListener; import com.smartdevicelink.proxy.rpc.VideoStreamingFormat; import com.smartdevicelink.proxy.rpc.enums.VideoStreamingProtocol; @@ -55,31 +23,33 @@ import java.util.List; import java.util.ListIterator; import java.util.concurrent.CopyOnWriteArrayList; -public class SdlSession implements ISdlProtocol, ISdlConnectionListener, ISecurityInitializedListener { +public abstract class BaseSdlSession implements ISdlProtocol, ISdlConnectionListener, ISecurityInitializedListener { private static final String TAG = "SdlSession"; - final protected SdlProtocol sdlProtocol; + final protected SdlProtocolBase sdlProtocol; protected BaseTransportConfig transportConfig; protected ISdlConnectionListener sessionListener; - protected SdlSecurityBase sdlSecurity = null; - protected VideoStreamingParameters desiredVideoParams = null; - protected VideoStreamingParameters acceptedVideoParams = null; + protected SdlSecurityBase sdlSecurity = null; + protected VideoStreamingParameters desiredVideoParams = null; + protected VideoStreamingParameters acceptedVideoParams = null; - protected byte sessionId; - protected int sessionHashId = 0; - protected HashMap<SessionType, CopyOnWriteArrayList<ISdlServiceListener>> serviceListeners; - protected CopyOnWriteArrayList<SessionType> encryptedServices = new CopyOnWriteArrayList<SessionType>(); + protected byte sessionId; + protected int sessionHashId = 0; + protected HashMap<SessionType, CopyOnWriteArrayList<ISdlServiceListener>> serviceListeners; + protected CopyOnWriteArrayList<SessionType> encryptedServices = new CopyOnWriteArrayList<SessionType>(); + boolean sdlSecurityInitializing = false; - public SdlSession(ISdlConnectionListener listener, BaseTransportConfig config){ + public BaseSdlSession(ISdlConnectionListener listener, BaseTransportConfig config){ this.transportConfig = config; this.sessionListener = listener; - this.sdlProtocol = new SdlProtocol(this,config); + this.sdlProtocol = getSdlProtocolImplementation(); } + protected abstract SdlProtocolBase getSdlProtocolImplementation(); public int getMtu(){ if(this.sdlProtocol!=null){ @@ -113,12 +83,16 @@ public class SdlSession implements ISdlProtocol, ISdlConnectionListener, ISecuri if (isEncrypted){ if (sdlSecurity != null){ List<SessionType> serviceList = sdlSecurity.getServiceList(); - if (!serviceList.contains(serviceType)) + if (!serviceList.contains(serviceType)) { serviceList.add(serviceType); + } - sdlSecurity.initialize(); + if (!sdlSecurityInitializing) { + sdlSecurityInitializing = true; + sdlSecurity.initialize(); + return; + } } - return; } sdlProtocol.startService(serviceType, sessionID, isEncrypted); } @@ -256,63 +230,12 @@ public class SdlSession implements ISdlProtocol, ISdlConnectionListener, ISecuri } - - @Override - public void onProtocolSessionStarted(SessionType sessionType, - byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) { - - DebugTool.logInfo(TAG, "Protocol session started"); - - this.sessionId = sessionID; - if (sessionType.eq(SessionType.RPC)){ - sessionHashId = hashID; - } - 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); - } - } - - } - - @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); DebugTool.logError(TAG,"on protocol error", e); } - - - - @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); @@ -406,16 +329,6 @@ public class SdlSession implements ISdlProtocol, ISdlConnectionListener, ISecuri onProtocolSessionNACKed(sessionType,sessionID,version,correlationID,rejectedParams); } - 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 NAKed"); - } - } - } @Override public void onAuthTokenReceived(String authToken) { this.sessionListener.onAuthTokenReceived(authToken, sessionId); @@ -479,4 +392,5 @@ public class SdlSession implements ISdlProtocol, ISdlConnectionListener, ISecuri -}
\ No newline at end of file + +} diff --git a/baseAndroid/src/main/java/com/smartdevicelink/SdlConnection/BaseSdlSession.java b/baseAndroid/src/main/java/com/smartdevicelink/SdlConnection/BaseSdlSession.java new file mode 120000 index 000000000..0bc868029 --- /dev/null +++ b/baseAndroid/src/main/java/com/smartdevicelink/SdlConnection/BaseSdlSession.java @@ -0,0 +1 @@ +../../../../../../../base/src/main/java/com/smartdevicelink/SdlConnection/BaseSdlSession.java
\ No newline at end of file diff --git a/javaSE/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java b/javaSE/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java new file mode 100644 index 000000000..fe76743d7 --- /dev/null +++ b/javaSE/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.SdlConnection; + + +import com.smartdevicelink.protocol.enums.SessionType; +import com.smartdevicelink.proxy.interfaces.ISdlServiceListener; +import com.smartdevicelink.transport.BaseTransportConfig; +import com.smartdevicelink.util.DebugTool; + +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +public class SdlSession extends BaseSdlSession { + + private static final String TAG = "SdlSession"; + + + public SdlSession(ISdlConnectionListener listener, BaseTransportConfig config){ + super(listener,config); + //FIXME this class needs to move to JavaSE only + } + + + @Override + public void onProtocolSessionStarted(SessionType sessionType, + byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) { + + DebugTool.logInfo(TAG, "Protocol session started"); + + this.sessionId = sessionID; + if (sessionType.eq(SessionType.RPC)){ + sessionHashId = hashID; + } + 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); + } + } + + } + + @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 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"); + } + } + } + + + + + + /* *********************************************************************************************************************************************************************** + * ***************************************************************** IProtocol Listener ******************************************************************************** + *************************************************************************************************************************************************************************/ + + 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 NAKed"); + } + } + } /* *********************************************************************************************************************************************************************** + * ***************************************************************** Security Listener ********************************************************************************* + *************************************************************************************************************************************************************************/ + +}
\ No newline at end of file |