summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilal Alsharifi <bilal.alsharifi@gmail.com>2020-08-05 15:41:53 -0400
committerBilal Alsharifi <bilal.alsharifi@gmail.com>2020-08-05 15:41:53 -0400
commit0fdd7dac8a56804c3beab0fd9433a889b26afe71 (patch)
tree4365ea5bf19cd0d487fe723d6eb7042670731fbe
parent401ca6c181749892faf69a340f80d43d29043da2 (diff)
parent10e0b5398b848508e6a55c75c7a4c7f95907a9f4 (diff)
downloadsdl_android-0fdd7dac8a56804c3beab0fd9433a889b26afe71.tar.gz
Merge branch 'develop' into feature/managers_refactor
-rw-r--r--android/sdl_android/build.gradle1
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/SdlConnection/SdlConnectionTest.java210
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/protocol/SdlProtocolTests.java34
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/protocol/WiProProtocolTests.java403
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/SdlConnection/SdlSessionTests.java8
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/TestValues.java2
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java25
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/RPCStructTests.java28
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DriverDistractionCapabilityTest.java65
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMICapabilitiesTests.java20
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SystemCapabilityTests.java23
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemCapabilityTypeTests.java6
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddSubmenuTests.java16
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/security/SdlSecurityBaseTest.java9
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/AbstractPacketizerTests.java14
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/StreamPacketizerTests.java13
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/StreamRPCPacketizerTests.java10
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/video/RTPH264PacketizerTest.java23
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/transport/SdlPsmTests.java4
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java56
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/TransportBrokerTest.java2
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlConnection.java661
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java1173
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession2.java364
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java7
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java195
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/protocol/WiProProtocol.java696
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java81
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/streaming/StreamPacketizer.java10
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/BTTransport.java586
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransport.java343
-rw-r--r--base/src/main/java/com/smartdevicelink/SdlConnection/BaseSdlSession.java (renamed from base/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java)103
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java2
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseSystemCapabilityManager.java2
-rw-r--r--base/src/main/java/com/smartdevicelink/proxy/RPCStruct.java5
-rw-r--r--base/src/main/java/com/smartdevicelink/proxy/rpc/AddSubMenu.java39
-rw-r--r--base/src/main/java/com/smartdevicelink/proxy/rpc/DriverDistractionCapability.java122
-rw-r--r--base/src/main/java/com/smartdevicelink/proxy/rpc/HMICapabilities.java32
-rw-r--r--base/src/main/java/com/smartdevicelink/proxy/rpc/SystemCapability.java14
-rw-r--r--base/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java35
l---------baseAndroid/src/main/java/com/smartdevicelink/SdlConnection/BaseSdlSession.java1
-rw-r--r--javaSE/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java130
42 files changed, 1017 insertions, 4556 deletions
diff --git a/android/sdl_android/build.gradle b/android/sdl_android/build.gradle
index e55054278..c600dd6dd 100644
--- a/android/sdl_android/build.gradle
+++ b/android/sdl_android/build.gradle
@@ -62,6 +62,7 @@ dependencies {
})
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.9.0'
+ androidTestImplementation 'org.mockito:mockito-core:2.9.0'
androidTestImplementation 'org.mockito:mockito-android:2.9.0'
api 'com.android.support:support-annotations:28.0.0'
api "android.arch.lifecycle:extensions:1.1.1"
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/SdlConnection/SdlConnectionTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/SdlConnection/SdlConnectionTest.java
deleted file mode 100644
index fa3f334e6..000000000
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/SdlConnection/SdlConnectionTest.java
+++ /dev/null
@@ -1,210 +0,0 @@
-package com.smartdevicelink.SdlConnection;
-
-import android.support.test.runner.AndroidJUnit4;
-
-import com.smartdevicelink.test.SdlUnitTestContants;
-import com.smartdevicelink.test.util.DeviceUtil;
-import com.smartdevicelink.transport.BTTransportConfig;
-import com.smartdevicelink.transport.BaseTransportConfig;
-import com.smartdevicelink.transport.MultiplexTransportConfig;
-import com.smartdevicelink.transport.RouterServiceValidator;
-import com.smartdevicelink.transport.USBTransportConfig;
-import com.smartdevicelink.transport.enums.TransportType;
-
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.MethodSorters;
-
-import static android.support.test.InstrumentationRegistry.getTargetContext;
-import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertFalse;
-import static junit.framework.TestCase.assertNotNull;
-import static junit.framework.TestCase.assertNull;
-import static junit.framework.TestCase.assertTrue;
-
-
-@RunWith(AndroidJUnit4.class)
-@FixMethodOrder(MethodSorters.JVM)
-public class SdlConnectionTest {
-
- private static final String TAG = "SdlConnection Tests";
-
- @Test
- public void testForceConnectEvent(){
- SdlConnection.enableLegacyMode(false, null);
- assertNull(SdlConnectionTestClass.cachedMultiConfig);
-
- RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext());
- rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_PERFORM_ALL_CHECKS);
- MultiplexTransportConfig config = new MultiplexTransportConfig(getTargetContext(),SdlUnitTestContants.TEST_APP_ID);
- SdlConnectionTestClass connection = new SdlConnectionTestClass(config,rsvp);
- assertNotNull(SdlConnectionTestClass.cachedMultiConfig);
-
- assertTrue(SdlConnectionTestClass.isLegacyModeEnabled());
-
- assertEquals(TransportType.BLUETOOTH, connection.getCurrentTransportType());
-
- assertNotNull(SdlConnectionTestClass.cachedMultiConfig);
-
- connection.forceHardwareConnectEvent(TransportType.MULTIPLEX);
- assertFalse(connection.connected);
-
- SdlConnectionTestClass.cachedMultiConfig.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_OFF);
-
- if(!DeviceUtil.isEmulator()) { // Cannot perform MBT operations in emulator
- assertNotNull(SdlConnectionTestClass.cachedMultiConfig.getService());
- assertEquals(TransportType.MULTIPLEX, connection.getCurrentTransportType());
- }
-
- // Test for handling of null service
- MultiplexTransportConfig null_service_config = new MultiplexTransportConfig(getTargetContext(),SdlUnitTestContants.TEST_APP_ID);
- null_service_config.setService(null);
- SdlConnectionTestClass null_service_connection = new SdlConnectionTestClass(null_service_config, null);
- Exception exception = null;
- try{
- null_service_connection.forceHardwareConnectEvent(TransportType.MULTIPLEX);
- }catch(NullPointerException e){
- exception = e;
- }
-
- assertNull(exception); // Failed, unhandled NPE
- }
-
- @Test
- public void testMultiplexConstructor(){
- SdlConnection.enableLegacyMode(false, null);
- RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext());
- rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_NONE);
- MultiplexTransportConfig config = new MultiplexTransportConfig(getTargetContext(),SdlUnitTestContants.TEST_APP_ID);
- SdlConnection connection = new SdlConnection(config,rsvp);
- if(DeviceUtil.isEmulator()){ // Cannot perform MBT operations in emulator
- assertEquals(TransportType.BLUETOOTH, connection.getCurrentTransportType());
- }else{
- assertEquals(TransportType.MULTIPLEX, connection.getCurrentTransportType());
- }
- }
-
- @Test
- public void testMultiplexConstructorInsalledFrom(){
- SdlConnection.enableLegacyMode(false, null);
- RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext());
- rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_INSTALLED_FROM_CHECK);
- MultiplexTransportConfig config = new MultiplexTransportConfig(getTargetContext(),SdlUnitTestContants.TEST_APP_ID);
- SdlConnection connection = new SdlConnection(config,rsvp);
- boolean didValidate = rsvp.validate();
- if(didValidate){
- assertEquals(TransportType.MULTIPLEX, connection.getCurrentTransportType());
- }else{
- assertEquals(TransportType.BLUETOOTH, connection.getCurrentTransportType());
-
- }
- }
-
- @Test
- public void testMultiplexConstructorTrustedPackage(){
- SdlConnection.enableLegacyMode(false, null);
- RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext());
- rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_PACKAGE_CHECK);
- MultiplexTransportConfig config = new MultiplexTransportConfig(getTargetContext(),SdlUnitTestContants.TEST_APP_ID);
- SdlConnection connection = new SdlConnection(config,rsvp);
- boolean didValidate = rsvp.validate();
- if(didValidate){
- assertEquals(TransportType.MULTIPLEX, connection.getCurrentTransportType());
- }else{
- assertEquals(TransportType.BLUETOOTH, connection.getCurrentTransportType());
-
- }
- }
-
- @Test
- public void testMultiplexConstructorTrustedPackageAndVersion(){
- SdlConnection.enableLegacyMode(false, null);
- RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext());
- rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_VERSION_CHECK);
- MultiplexTransportConfig config = new MultiplexTransportConfig(getTargetContext(),SdlUnitTestContants.TEST_APP_ID);
- SdlConnection connection = new SdlConnection(config,rsvp);
- boolean didValidate = rsvp.validate();
- if(didValidate){
- assertEquals(TransportType.MULTIPLEX, connection.getCurrentTransportType());
- }else{
- assertEquals(TransportType.BLUETOOTH, connection.getCurrentTransportType());
-
- }
- }
-
- @Test
- public void testMultiplexConstructorAllFlags(){
- SdlConnection.enableLegacyMode(false, null);
- RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext());
- rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_PERFORM_ALL_CHECKS);
- MultiplexTransportConfig config = new MultiplexTransportConfig(getTargetContext(),SdlUnitTestContants.TEST_APP_ID);
- SdlConnection connection = new SdlConnection(config,rsvp);
- boolean didValidate = rsvp.validate();
- if(didValidate){
- assertEquals(TransportType.MULTIPLEX, connection.getCurrentTransportType());
- }else{
- assertEquals(TransportType.BLUETOOTH, connection.getCurrentTransportType());
-
- }
- }
-
- @Test
- public void testBluetoothConstructor(){
- SdlConnection.enableLegacyMode(false, null);
- BTTransportConfig btConfig = new BTTransportConfig(true);
- SdlConnection connection = new SdlConnection(btConfig);
- assertEquals(TransportType.BLUETOOTH, connection.getCurrentTransportType());
- }
-
- @Test
- public void testUsbConstructor(){
- SdlConnection.enableLegacyMode(false, null);
- USBTransportConfig btConfig = new USBTransportConfig(getTargetContext());
- SdlConnection connection = new SdlConnection(btConfig,null);
- assertFalse(SdlConnection.isLegacyModeEnabled());
- assertEquals(TransportType.USB, connection.getCurrentTransportType());
-
- SdlConnection connection2 = new SdlConnection(btConfig);
- assertEquals(TransportType.USB, connection2.getCurrentTransportType());
- }
-
- protected class SdlConnectionTestClass extends SdlConnection{
- protected boolean connected = false;
- public SdlConnectionTestClass(BaseTransportConfig transportConfig) {
- super(transportConfig);
- }
-
- protected SdlConnectionTestClass(BaseTransportConfig transportConfig,RouterServiceValidator rsvp){
- super(transportConfig,rsvp);
- }
-
- @Override
- public void onTransportConnected() {
- super.onTransportConnected();
- connected = true;
- }
-
- @Override
- public void onTransportDisconnected(String info) {
- connected = false;
- //Grab a currently running router service
- RouterServiceValidator rsvp2 = new RouterServiceValidator(getTargetContext());
- rsvp2.setFlags(RouterServiceValidator.FLAG_DEBUG_NONE);
- assertTrue(rsvp2.validate());
- assertNotNull(rsvp2.getService());
- SdlConnectionTestClass.cachedMultiConfig.setService(rsvp2.getService());
- super.onTransportDisconnected(info);
- }
-
- @Override
- public void onTransportError(String info, Exception e) {
- connected = false;
- super.onTransportError(info, e);
- }
-
-
-
- }
-
-}
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/protocol/SdlProtocolTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/protocol/SdlProtocolTests.java
index be04ce1f0..f77d65b9d 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/protocol/SdlProtocolTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/protocol/SdlProtocolTests.java
@@ -3,7 +3,6 @@ package com.smartdevicelink.protocol;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log;
-import com.smartdevicelink.SdlConnection.SdlConnection;
import com.smartdevicelink.protocol.enums.SessionType;
import com.smartdevicelink.security.SdlSecurityBase;
import com.smartdevicelink.streaming.video.VideoStreamingParameters;
@@ -357,37 +356,4 @@ public class SdlProtocolTests {
}
- protected class SdlConnectionTestClass extends SdlConnection {
- protected boolean connected = false;
- public SdlConnectionTestClass(BaseTransportConfig transportConfig) {
- super(transportConfig);
- }
-
- protected SdlConnectionTestClass(BaseTransportConfig transportConfig,RouterServiceValidator rsvp){
- super(transportConfig,rsvp);
- }
-
- @Override
- public void onTransportConnected() {
- super.onTransportConnected();
- connected = true;
- }
-
- @Override
- public void onTransportDisconnected(String info) {
- connected = false;
- //Grab a currently running router service
- RouterServiceValidator rsvp2 = new RouterServiceValidator(getContext());
- rsvp2.setFlags(RouterServiceValidator.FLAG_DEBUG_NONE);
- assertTrue(rsvp2.validate());
- assertNotNull(rsvp2.getService());
- super.onTransportDisconnected(info);
- }
-
- @Override
- public void onTransportError(String info, Exception e) {
- connected = false;
- super.onTransportError(info, e);
- }
- }
} \ No newline at end of file
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/protocol/WiProProtocolTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/protocol/WiProProtocolTests.java
deleted file mode 100644
index 21892632a..000000000
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/protocol/WiProProtocolTests.java
+++ /dev/null
@@ -1,403 +0,0 @@
-package com.smartdevicelink.protocol;
-
-import android.support.test.runner.AndroidJUnit4;
-import android.util.Log;
-
-import com.smartdevicelink.SdlConnection.SdlConnection;
-import com.smartdevicelink.protocol.WiProProtocol.MessageFrameAssembler;
-import com.smartdevicelink.protocol.enums.SessionType;
-import com.smartdevicelink.test.SampleRpc;
-import com.smartdevicelink.test.SdlUnitTestContants;
-import com.smartdevicelink.transport.BaseTransportConfig;
-import com.smartdevicelink.transport.MultiplexTransportConfig;
-import com.smartdevicelink.transport.RouterServiceValidator;
-
-import junit.framework.Assert;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.io.ByteArrayOutputStream;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertFalse;
-import static junit.framework.TestCase.assertNotNull;
-import static junit.framework.TestCase.assertNull;
-import static android.support.test.InstrumentationRegistry.getContext;
-import static junit.framework.TestCase.assertTrue;
-
-/**
- * This is a unit test class for the SmartDeviceLink library project class :
- * {@link com.smartdevicelink.protocol.BinaryFrameHeader}
- */
-@RunWith(AndroidJUnit4.class)
-public class WiProProtocolTests {
-
- int max_int = 2147483647;
- byte[] payload;
- MultiplexTransportConfig config;
- SdlConnectionTestClass connection;
- WiProProtocol protocol;
-
- IProtocolListener defaultListener = new IProtocolListener(){
- @Override
- public void onProtocolMessageBytesToSend(SdlPacket packet) {}
- @Override
- public void onProtocolMessageReceived(ProtocolMessage msg) {}
- @Override
- public void onProtocolSessionStarted(SessionType sessionType,byte sessionID, byte version, String correlationID, int hashID,boolean isEncrypted){}
- @Override
- public void onProtocolSessionNACKed(SessionType sessionType,byte sessionID, byte version, String correlationID, List<String> rejectedParams) {}
- @Override
- public void onProtocolSessionEnded(SessionType sessionType,byte sessionID, String correlationID) {}
- @Override
- public void onProtocolSessionEndedNACKed(SessionType sessionType,byte sessionID, String correlationID) {}
- @Override
- public void onProtocolHeartbeat(SessionType sessionType, byte sessionID) {}
- @Override
- public void onProtocolHeartbeatACK(SessionType sessionType,byte sessionID) {}
- @Override
- public void onProtocolServiceDataACK(SessionType sessionType,int dataSize, byte sessionID) {}
- @Override
- public void onResetOutgoingHeartbeat(SessionType sessionType,byte sessionID) {}
- @Override
- public void onResetIncomingHeartbeat(SessionType sessionType,byte sessionID) {}
- @Override
- public void onProtocolError(String info, Exception e) {}
-
- };
- public static class DidReceiveListener implements IProtocolListener{
- boolean didReceive = false;
-
- public void reset(){
- didReceive = false;
- }
- public boolean didReceive(){
- return didReceive;
- }
- @Override
- public void onProtocolMessageBytesToSend(SdlPacket packet) {}
- @Override
- public void onProtocolMessageReceived(ProtocolMessage msg) {
- didReceive = true;
- Log.d("DidReceiveListener", "RPC Type: " + msg.getRPCType());
- Log.d("DidReceiveListener", "Function Id: " + msg.getFunctionID());
- Log.d("DidReceiveListener", "JSON Size: " + msg.getJsonSize());
- }
- @Override
- public void onProtocolSessionStarted(SessionType sessionType,byte sessionID, byte version, String correlationID, int hashID,boolean isEncrypted){}
- @Override
- public void onProtocolSessionNACKed(SessionType sessionType,byte sessionID, byte version, String correlationID, List<String> rejectedParams) {}
- @Override
- public void onProtocolSessionEnded(SessionType sessionType,byte sessionID, String correlationID) {}
- @Override
- public void onProtocolSessionEndedNACKed(SessionType sessionType,byte sessionID, String correlationID) {}
- @Override
- public void onProtocolHeartbeat(SessionType sessionType, byte sessionID) {}
- @Override
- public void onProtocolHeartbeatACK(SessionType sessionType,byte sessionID) {}
- @Override
- public void onProtocolServiceDataACK(SessionType sessionType,int dataSize, byte sessionID) {}
- @Override
- public void onResetOutgoingHeartbeat(SessionType sessionType,byte sessionID) {}
- @Override
- public void onResetIncomingHeartbeat(SessionType sessionType,byte sessionID) {}
- @Override
- public void onProtocolError(String info, Exception e) {}
- };
- DidReceiveListener onProtocolMessageReceivedListener = new DidReceiveListener();
-
- @Test
- public void testBase(){
- WiProProtocol wiProProtocol = new WiProProtocol(defaultListener);
-
- }
-
- @Test
- public void testVersion(){
- WiProProtocol wiProProtocol = new WiProProtocol(defaultListener);
-
- wiProProtocol.setVersion((byte)0x01);
- assertEquals((byte)0x01,wiProProtocol.getVersion());
-
- wiProProtocol = new WiProProtocol(defaultListener);
- wiProProtocol.setVersion((byte)0x02);
- assertEquals((byte)0x02,wiProProtocol.getVersion());
-
- wiProProtocol = new WiProProtocol(defaultListener);
- wiProProtocol.setVersion((byte)0x03);
- assertEquals((byte)0x03,wiProProtocol.getVersion());
-
- wiProProtocol = new WiProProtocol(defaultListener);
- wiProProtocol.setVersion((byte)0x04);
- assertEquals((byte)0x04,wiProProtocol.getVersion());
-
- wiProProtocol = new WiProProtocol(defaultListener);
- wiProProtocol.setVersion((byte)0x05);
- assertEquals((byte)0x05,wiProProtocol.getVersion());
-
- //If we get newer than 5, it should fall back to 5
- wiProProtocol = new WiProProtocol(defaultListener);
- wiProProtocol.setVersion((byte)0x06);
- assertEquals((byte)0x05,wiProProtocol.getVersion());
-
- //Is this right?
- wiProProtocol = new WiProProtocol(defaultListener);
- wiProProtocol.setVersion((byte)0x00);
- assertEquals((byte)0x01,wiProProtocol.getVersion());
- }
-
- @Test
- public void testMtu(){
- WiProProtocol wiProProtocol = new WiProProtocol(defaultListener);
-
- wiProProtocol.setVersion((byte)0x01);
-
- try{
- assertEquals(wiProProtocol.getMtu(), 1500-8);
-
- //Version 2
- wiProProtocol.setVersion((byte)0x02);
- assertEquals(wiProProtocol.getMtu(), 1500-12);
-
- //Version 3
- wiProProtocol.setVersion((byte)0x03);
- assertEquals(wiProProtocol.getMtu(), 131072);
-
- //Version 4
- wiProProtocol.setVersion((byte)0x04);
- assertEquals(wiProProtocol.getMtu(), 131072);
-
- //Version 5
- wiProProtocol.setVersion((byte)0x05);
- assertEquals(wiProProtocol.getMtu(), 131072);
-
- //Version 5+
- wiProProtocol.setVersion((byte)0x06);
- assertEquals(wiProProtocol.getMtu(), 131072);
-
- }catch(Exception e){
- Assert.fail("Exceptin during reflection");
- }
-
- }
-
- @Test
- public void testHandleFrame(){
- SampleRpc sampleRpc = new SampleRpc(4);
- WiProProtocol wiProProtocol = new WiProProtocol(defaultListener);
- MessageFrameAssembler assembler = wiProProtocol.new MessageFrameAssembler();
- try{
- assembler.handleFrame(sampleRpc.toSdlPacket());
- }catch(Exception e){
- Assert.fail("Exceptin during handleFrame - " + e.toString());
- }
- }
-
- @Test
- public void testHandleFrameCorrupt(){
- SampleRpc sampleRpc = new SampleRpc(4);
- BinaryFrameHeader header = sampleRpc.getBinaryFrameHeader(true);
- header.setJsonSize(Integer.MAX_VALUE);
- sampleRpc.setBinaryFrameHeader(header);
- WiProProtocol wiProProtocol = new WiProProtocol(defaultListener);
- MessageFrameAssembler assembler = wiProProtocol.new MessageFrameAssembler();
- try{
- assembler.handleFrame(sampleRpc.toSdlPacket());
- }catch(Exception e){
- Assert.fail("Exceptin during handleFrame - " + e.toString());
- }
- }
-
- @Test
- public void testHandleSingleFrameMessageFrame(){
- SampleRpc sampleRpc = new SampleRpc(4);
- WiProProtocol wiProProtocol = new WiProProtocol(defaultListener);
- MessageFrameAssembler assembler = wiProProtocol.new MessageFrameAssembler();
-
-
- try{
- Method method = assembler.getClass().getDeclaredMethod ("handleSingleFrameMessageFrame", SdlPacket.class);
- method.setAccessible(true);
- method.invoke (assembler, sampleRpc.toSdlPacket());
- }catch(Exception e){
- Assert.fail("Exceptin during handleSingleFrameMessageFrame - " + e.toString());
- }
- }
-
- @Test
- public void testHandleSingleFrameMessageFrameCorruptBfh(){
- SampleRpc sampleRpc = new SampleRpc(4);
-
- //Create a corrupted header
- BinaryFrameHeader header = sampleRpc.getBinaryFrameHeader(true);
- header.setJsonSize(5);
- header.setJsonData(new byte[5]);
- header.setJsonSize(Integer.MAX_VALUE);
- sampleRpc.setBinaryFrameHeader(header);
-
- SdlPacket packet = sampleRpc.toSdlPacket();
-
- BinaryFrameHeader binFrameHeader = BinaryFrameHeader.parseBinaryHeader(packet.payload);
- assertNull(binFrameHeader);
-
- WiProProtocol wiProProtocol = new WiProProtocol(onProtocolMessageReceivedListener);
-
-
- wiProProtocol.handlePacketReceived(packet);
- assertFalse(onProtocolMessageReceivedListener.didReceive());
-
- onProtocolMessageReceivedListener.reset();
- MessageFrameAssembler assembler =wiProProtocol.getFrameAssemblerForFrame(packet);// wiProProtocol.new MessageFrameAssembler();
- assertNotNull(assembler);
- assembler.handleFrame(packet);
- assertFalse(onProtocolMessageReceivedListener.didReceive());
-
- try{
- Method method = assembler.getClass().getDeclaredMethod("handleSingleFrameMessageFrame", SdlPacket.class);
- method.setAccessible(true);
- method.invoke (assembler, sampleRpc.toSdlPacket());
- }catch(Exception e){
- Assert.fail("Exceptin during handleSingleFrameMessageFrame - " + e.toString());
- }
- }
-
-
- @Before
- public void setUp(){
- config = new MultiplexTransportConfig(getContext(),SdlUnitTestContants.TEST_APP_ID);
- connection = new SdlConnectionTestClass(config, null);
- protocol = new WiProProtocol(connection);
- }
-
- @Test
- public void testNormalCase(){
- setUp();
- payload = new byte[]{0x00,0x02,0x05,0x01,0x01,0x01,0x05,0x00};
- byte sessionID = 1, version = 1;
- int messageID = 1;
- boolean encrypted = false;
- SdlPacket sdlPacket = SdlPacketFactory.createMultiSendDataFirst(SessionType.RPC, sessionID, messageID, version, payload, encrypted);
- MessageFrameAssembler assembler = protocol.getFrameAssemblerForFrame(sdlPacket);
-
- assertNotNull(assembler);
-
- OutOfMemoryError oom_error = null;
- NullPointerException np_exception = null;
- try{
- assembler.handleMultiFrameMessageFrame(sdlPacket);
- }catch(OutOfMemoryError e){
- oom_error = e;
- }catch(NullPointerException z){
- np_exception = z;
- }catch(Exception e){
- e.printStackTrace();
- assertNotNull(null);
- }
-
- assertNull(np_exception);
- assertNull(oom_error);
-
- payload = new byte[23534];
- sdlPacket = SdlPacketFactory.createMultiSendDataRest(SessionType.RPC, sessionID, payload.length, (byte) 3, messageID, version, payload, 0, 1500, encrypted);
- assembler = protocol.getFrameAssemblerForFrame(sdlPacket);
- try{
- assembler.handleMultiFrameMessageFrame(sdlPacket);
- }catch(OutOfMemoryError e){
- oom_error = e;
- }catch(NullPointerException z){
- np_exception = z;
- }catch(Exception e){
- assertNotNull(null);
- }
-
- assertNull(np_exception);
- assertNull(oom_error);
- }
-
- @Test
- public void testOverallocatingAccumulator(){
- setUp();
- ByteArrayOutputStream builder = new ByteArrayOutputStream();
- for(int i = 0; i < 8; i++){
- builder.write(0x0F);
- }
- payload = builder.toByteArray();
- byte sessionID = 1, version = 1;
- int messageID = 1;
- boolean encrypted = false;
- SdlPacket sdlPacket = SdlPacketFactory.createMultiSendDataFirst(SessionType.RPC, sessionID, messageID, version, payload, encrypted);
- MessageFrameAssembler assembler = protocol.getFrameAssemblerForFrame(sdlPacket);
-
- OutOfMemoryError oom_error = null;
- NullPointerException np_exception = null;
- try{
- assembler.handleMultiFrameMessageFrame(sdlPacket);
- }catch(OutOfMemoryError e){
- oom_error = e;
- }catch(NullPointerException z){
- np_exception = z;
- }catch(Exception e){
- assertNotNull(null);
- }
-
- assertNull(np_exception);
- assertNull(oom_error);
-
- payload = new byte[23534];
- sdlPacket = SdlPacketFactory.createMultiSendDataRest(SessionType.RPC, sessionID, payload.length, (byte) 3, messageID, version, payload, 0, 1500, encrypted);
- assembler = protocol.getFrameAssemblerForFrame(sdlPacket);
-
- try{
- assembler.handleMultiFrameMessageFrame(sdlPacket);
- }catch(OutOfMemoryError e){
- oom_error = e;
- }catch(NullPointerException z){
- np_exception = z;
- }catch(Exception e){
- assertNotNull(null);
- }
-
- assertNull(np_exception);
- assertNull(oom_error);
-
- }
-
- protected class SdlConnectionTestClass extends SdlConnection{
- protected boolean connected = false;
- public SdlConnectionTestClass(BaseTransportConfig transportConfig) {
- super(transportConfig);
- }
-
- protected SdlConnectionTestClass(BaseTransportConfig transportConfig,RouterServiceValidator rsvp){
- super(transportConfig,rsvp);
- }
-
- @Override
- public void onTransportConnected() {
- super.onTransportConnected();
- connected = true;
- }
-
- @Override
- public void onTransportDisconnected(String info) {
- connected = false;
- //Grab a currently running router service
- RouterServiceValidator rsvp2 = new RouterServiceValidator(getContext());
- rsvp2.setFlags(RouterServiceValidator.FLAG_DEBUG_NONE);
- assertTrue(rsvp2.validate());
- assertNotNull(rsvp2.getService());
- SdlConnectionTestClass.cachedMultiConfig.setService(rsvp2.getService());
- super.onTransportDisconnected(info);
- }
-
- @Override
- public void onTransportError(String info, Exception e) {
- connected = false;
- super.onTransportError(info, e);
- }
- }
-}
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/SdlConnection/SdlSessionTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/SdlConnection/SdlSessionTests.java
index 982be84e8..11d2dbb7d 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/SdlConnection/SdlSessionTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/SdlConnection/SdlSessionTests.java
@@ -3,10 +3,15 @@ package com.smartdevicelink.test.SdlConnection;
import com.smartdevicelink.SdlConnection.SdlSession;
import com.smartdevicelink.protocol.enums.SessionType;
import com.smartdevicelink.proxy.interfaces.ISdlServiceListener;
+import com.smartdevicelink.test.streaming.MockInterfaceBroker;
+import com.smartdevicelink.transport.MultiplexTransportConfig;
import com.smartdevicelink.transport.TCPTransportConfig;
import junit.framework.TestCase;
+import static android.support.test.InstrumentationRegistry.getTargetContext;
+import static org.mockito.Mockito.mock;
+
/**
* This is a unit test class for the SmartDeviceLink library project class :
* {@link com.smartdevicelink.SdlConnection.SdlSession}
@@ -14,7 +19,7 @@ import junit.framework.TestCase;
public class SdlSessionTests extends TestCase {
public void testServiceListeners(){
- SdlSession session = SdlSession.createSession((byte)5,null, new TCPTransportConfig(8080,"",false));
+ SdlSession session = new SdlSession(new MockInterfaceBroker(), new MultiplexTransportConfig(getTargetContext(),"19216801"));
ISdlServiceListener test = new ISdlServiceListener() {
@Override
public void onServiceStarted(SdlSession session, SessionType type, boolean isEncrypted) {
@@ -33,6 +38,7 @@ public class SdlSessionTests extends TestCase {
};
session.addServiceListener(SessionType.RPC, test);
+ assertNotNull(session.getServiceListeners());
assertTrue(session.removeServiceListener(SessionType.RPC, test));
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/TestValues.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/TestValues.java
index f5cc9827d..37cae48f4 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/TestValues.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/TestValues.java
@@ -37,6 +37,7 @@ import com.smartdevicelink.proxy.rpc.DateTime;
import com.smartdevicelink.proxy.rpc.DeviceInfo;
import com.smartdevicelink.proxy.rpc.DisplayCapabilities;
import com.smartdevicelink.proxy.rpc.DisplayCapability;
+import com.smartdevicelink.proxy.rpc.DriverDistractionCapability;
import com.smartdevicelink.proxy.rpc.EqualizerSettings;
import com.smartdevicelink.proxy.rpc.Grid;
import com.smartdevicelink.proxy.rpc.HMICapabilities;
@@ -339,6 +340,7 @@ public class TestValues {
public static final AppInterfaceUnregisteredReason GENERAL_APPINTERFACEUNREGISTEREDREASON = AppInterfaceUnregisteredReason.BLUETOOTH_OFF;
public static final SystemCapabilityType GENERAL_SYSTEMCAPABILITYTYPE = SystemCapabilityType.NAVIGATION;
public static final NavigationCapability GENERAL_NAVIGATIONCAPABILITY = new NavigationCapability();
+ public static final DriverDistractionCapability GENERAL_DRIVERDISTRACTIONCAPABILITY = new DriverDistractionCapability();
public static final PhoneCapability GENERAL_PHONECAPABILITY = new PhoneCapability();
public static final RemoteControlCapabilities GENERAL_REMOTECONTROLCAPABILITIES = new RemoteControlCapabilities();
public static final SystemCapability GENERAL_SYSTEMCAPABILITY = new SystemCapability();
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java
index cbc79c9f1..69d32c33d 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java
@@ -1319,6 +1319,31 @@ public class Validator{
return true;
}
+ public static boolean validateDriverDistractionCapability(DriverDistractionCapability driverDistractionCapability1, DriverDistractionCapability driverDistractionCapability2) {
+ if (driverDistractionCapability1 == null) {
+ return (driverDistractionCapability1 == null);
+ }
+ if (driverDistractionCapability2 == null) {
+ return (driverDistractionCapability2 == null);
+ }
+
+ if (driverDistractionCapability1.getMenuLength() != driverDistractionCapability2.getMenuLength()) {
+ log("validateDriverDistractionCapability",
+ "menuLength " + driverDistractionCapability1.getMenuLength() + " didn't match menuLength " + driverDistractionCapability2.getMenuLength()
+ + ".");
+ return false;
+ }
+
+ if (driverDistractionCapability1.getSubMenuDepth() != driverDistractionCapability2.getSubMenuDepth()) {
+ log("validateDriverDistractionCapability",
+ "subMenuDepth " + driverDistractionCapability1.getSubMenuDepth() + " didn't match subMenuDepth " + driverDistractionCapability2.getSubMenuDepth()
+ + ".");
+ return false;
+ }
+
+ return true;
+ }
+
public static boolean validatePhoneCapability(PhoneCapability phoneCapability1, PhoneCapability phoneCapability2){
if(phoneCapability1 == null){
return ( phoneCapability2 == null );
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/RPCStructTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/RPCStructTests.java
index a61c9558e..5542719ba 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/RPCStructTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/RPCStructTests.java
@@ -155,4 +155,32 @@ public class RPCStructTests extends TestCase {
testStruct.setValue(invalidKey, TestValues.GENERAL_STRING);
assertNull(testStruct.getObject(Integer.class, invalidKey));
}
+
+ public void testGetFloat() {
+ Hashtable <String, Object> map = new Hashtable<>();
+ String key = "test";
+ Double value = 42.00;
+ map.put(key, value);
+ RPCStruct rpcStruct = new RPCStruct(map);
+ try {
+ Float value2 = rpcStruct.getFloat(key);
+ assertTrue(value2 - value < 0.1);
+ } catch (ClassCastException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ public void testGetDouble() {
+ Hashtable <String, Object> map = new Hashtable<>();
+ String key = "test";
+ Integer value = 42;
+ map.put(key, value);
+ RPCStruct rpcStruct = new RPCStruct(map);
+ try {
+ Double value2 = rpcStruct.getDouble(key);
+ assertTrue(value2 - value < 0.1);
+ } catch (ClassCastException e) {
+ fail(e.getMessage());
+ }
+ }
}
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DriverDistractionCapabilityTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DriverDistractionCapabilityTest.java
new file mode 100644
index 000000000..2e98296a1
--- /dev/null
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DriverDistractionCapabilityTest.java
@@ -0,0 +1,65 @@
+package com.smartdevicelink.test.rpc.datatypes;
+
+import com.smartdevicelink.proxy.rpc.DriverDistractionCapability;
+import com.smartdevicelink.test.JsonUtils;
+import com.smartdevicelink.test.TestValues;
+import junit.framework.TestCase;
+import org.json.JSONException;
+import org.json.JSONObject;
+import java.util.Iterator;
+
+/**
+ * This is a unit test class for the SmartDeviceLink library project class :
+ * {@link com.smartdevicelink.proxy.rpc.DriverDistractionCapability}
+ */
+public class DriverDistractionCapabilityTest extends TestCase {
+
+ private DriverDistractionCapability msg;
+
+ @Override
+ public void setUp() {
+ msg = new DriverDistractionCapability();
+ msg.setMenuLength(TestValues.GENERAL_INT);
+ msg.setSubMenuDepth(TestValues.GENERAL_INT);
+ }
+
+ /**
+ * Tests the expected values of the RPC message.
+ */
+ public void testRpcValues() {
+ // Test Values
+ int menuLength = msg.getMenuLength();
+ int subMenuDepth = msg.getSubMenuDepth();
+
+ // Valid Tests
+ assertEquals(TestValues.MATCH, TestValues.GENERAL_INT, menuLength);
+ assertEquals(TestValues.MATCH, TestValues.GENERAL_INT, subMenuDepth);
+
+ // Invalid/Null Tests
+ DriverDistractionCapability msg = new DriverDistractionCapability();
+ assertNotNull(TestValues.NOT_NULL, msg);
+
+ assertNull(TestValues.NULL, msg.getMenuLength());
+ assertNull(TestValues.NULL, msg.getSubMenuDepth());
+ }
+
+ public void testJson() {
+ JSONObject reference = new JSONObject();
+
+ try {
+ reference.put(DriverDistractionCapability.KEY_MENU_LENGTH, TestValues.GENERAL_INT);
+ reference.put(DriverDistractionCapability.KEY_SUB_MENU_DEPTH, TestValues.GENERAL_INT);
+
+ JSONObject underTest = msg.serializeJSON();
+ assertEquals(TestValues.MATCH, reference.length(), underTest.length());
+
+ Iterator<?> iterator = reference.keys();
+ while(iterator.hasNext()){
+ String key = (String) iterator.next();
+ assertEquals(TestValues.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
+ }
+ } catch (JSONException e) {
+ fail(TestValues.JSON_FAIL);
+ }
+ }
+}
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMICapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMICapabilitiesTests.java
index 87c83cb74..40c873285 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMICapabilitiesTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMICapabilitiesTests.java
@@ -9,6 +9,7 @@ import junit.framework.TestCase;
import org.json.JSONException;
import org.json.JSONObject;
+import static com.smartdevicelink.proxy.rpc.HMICapabilities.KEY_DRIVER_DISTRACTION;
import static com.smartdevicelink.proxy.rpc.HMICapabilities.KEY_NAVIGATION;
import static com.smartdevicelink.proxy.rpc.HMICapabilities.KEY_PHONE_CALL;
import static com.smartdevicelink.proxy.rpc.HMICapabilities.KEY_VIDEO_STREAMING;
@@ -22,7 +23,8 @@ public class HMICapabilitiesTests extends TestCase {
msg.setNavigationAvilable(TestValues.GENERAL_BOOLEAN);
msg.setPhoneCallAvilable(TestValues.GENERAL_BOOLEAN);
- msg.setVideoStreamingAvailable(TestValues.GENERAL_BOOLEAN);
+ msg.setVideoStreamingAvailable(TestValues.GENERAL_BOOLEAN);
+ msg.setDriverDistraction(TestValues.GENERAL_BOOLEAN);
}
/**
@@ -32,12 +34,14 @@ public class HMICapabilitiesTests extends TestCase {
// Test Values
Boolean navAvail = msg.isNavigationAvailable();
Boolean phoneAvail = msg.isPhoneCallAvailable();
- Boolean vidStreamAvail = msg.isVideoStreamingAvailable();
+ Boolean vidStreamAvail = msg.isVideoStreamingAvailable();
+ Boolean driverDistractionAvail = msg.isDriverDistractionAvailable();
// Valid Tests
assertEquals(TestValues.MATCH, (Boolean) TestValues.GENERAL_BOOLEAN, navAvail);
assertEquals(TestValues.MATCH, (Boolean) TestValues.GENERAL_BOOLEAN, phoneAvail);
assertEquals(TestValues.MATCH, (Boolean) TestValues.GENERAL_BOOLEAN, vidStreamAvail);
+ assertEquals(TestValues.MATCH, (Boolean) TestValues.GENERAL_BOOLEAN, driverDistractionAvail);
// Invalid/Null Tests
HMICapabilities msg = new HMICapabilities();
@@ -45,7 +49,9 @@ public class HMICapabilitiesTests extends TestCase {
assertFalse(msg.isNavigationAvailable());
assertFalse(msg.isPhoneCallAvailable());
- assertFalse(msg.isVideoStreamingAvailable());
+ assertFalse(msg.isVideoStreamingAvailable());
+ assertFalse(msg.isDriverDistractionAvailable());
+
}
public void testJson(){
@@ -54,7 +60,8 @@ public class HMICapabilitiesTests extends TestCase {
try{
reference.put(KEY_NAVIGATION, TestValues.GENERAL_BOOLEAN);
reference.put(HMICapabilities.KEY_PHONE_CALL, TestValues.GENERAL_BOOLEAN);
- reference.put(HMICapabilities.KEY_VIDEO_STREAMING, TestValues.GENERAL_BOOLEAN);
+ reference.put(HMICapabilities.KEY_VIDEO_STREAMING, TestValues.GENERAL_BOOLEAN);
+ reference.put(KEY_DRIVER_DISTRACTION, TestValues.GENERAL_BOOLEAN);
JSONObject underTest = msg.serializeJSON();
assertEquals(TestValues.MATCH, reference.length(), underTest.length());
@@ -65,8 +72,11 @@ public class HMICapabilitiesTests extends TestCase {
assertEquals(TestValues.MATCH, JsonUtils.readStringListFromJsonObject(reference, KEY_PHONE_CALL),
JsonUtils.readStringListFromJsonObject(underTest, KEY_PHONE_CALL));
- assertEquals(TestValues.MATCH, JsonUtils.readStringListFromJsonObject(reference, KEY_VIDEO_STREAMING),
+ assertEquals(TestValues.MATCH, JsonUtils.readStringListFromJsonObject(reference, KEY_VIDEO_STREAMING),
JsonUtils.readStringListFromJsonObject(underTest, KEY_VIDEO_STREAMING));
+ assertEquals(TestValues.MATCH, JsonUtils.readStringFromJsonObject(reference, KEY_DRIVER_DISTRACTION),
+ JsonUtils.readStringFromJsonObject(underTest, KEY_DRIVER_DISTRACTION));
+
} catch(JSONException e){
fail(TestValues.JSON_FAIL);
}
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SystemCapabilityTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SystemCapabilityTests.java
index 0a02b6543..4ba99dda0 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SystemCapabilityTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SystemCapabilityTests.java
@@ -5,6 +5,8 @@ import android.util.Log;
import com.smartdevicelink.marshal.JsonRPCMarshaller;
import com.smartdevicelink.proxy.rpc.AppServicesCapabilities;
import com.smartdevicelink.proxy.rpc.DisplayCapability;
+import com.smartdevicelink.proxy.rpc.DriverDistractionCapability;
+import com.smartdevicelink.proxy.rpc.HMICapabilities;
import com.smartdevicelink.proxy.rpc.NavigationCapability;
import com.smartdevicelink.proxy.rpc.PhoneCapability;
import com.smartdevicelink.proxy.rpc.RemoteControlCapabilities;
@@ -42,6 +44,8 @@ public class SystemCapabilityTests extends TestCase {
msg.setCapabilityForType(SystemCapabilityType.REMOTE_CONTROL, TestValues.GENERAL_REMOTECONTROLCAPABILITIES);
msg.setCapabilityForType(SystemCapabilityType.APP_SERVICES, TestValues.GENERAL_APP_SERVICE_CAPABILITIES);
msg.setCapabilityForType(SystemCapabilityType.DISPLAYS, TestValues.GENERAL_DISPLAYCAPABILITY_LIST);
+ msg.setCapabilityForType(SystemCapabilityType.DRIVER_DISTRACTION, TestValues.GENERAL_DRIVERDISTRACTIONCAPABILITY);
+
}
/**
@@ -55,6 +59,7 @@ public class SystemCapabilityTests extends TestCase {
RemoteControlCapabilities testRemoteControlCapabilities = (RemoteControlCapabilities) msg.getCapabilityForType(SystemCapabilityType.REMOTE_CONTROL);
AppServicesCapabilities testAppServicesCapabilities = (AppServicesCapabilities) msg.getCapabilityForType(SystemCapabilityType.APP_SERVICES);
List<DisplayCapability> displayCapabilities = (List<DisplayCapability>) msg.getCapabilityForType(SystemCapabilityType.DISPLAYS);
+ DriverDistractionCapability testDriverDistractionCapability = (DriverDistractionCapability) msg.getCapabilityForType(SystemCapabilityType.DRIVER_DISTRACTION);
// Valid Tests
assertEquals(TestValues.MATCH, TestValues.GENERAL_SYSTEMCAPABILITYTYPE, testType);
@@ -62,6 +67,8 @@ public class SystemCapabilityTests extends TestCase {
assertTrue(TestValues.TRUE, Validator.validatePhoneCapability(TestValues.GENERAL_PHONECAPABILITY, testPhoneCapability));
assertTrue(TestValues.TRUE, Validator.validateRemoteControlCapabilities(TestValues.GENERAL_REMOTECONTROLCAPABILITIES, testRemoteControlCapabilities));
assertTrue(TestValues.TRUE, Validator.validateAppServiceCapabilities(TestValues.GENERAL_APP_SERVICE_CAPABILITIES, testAppServicesCapabilities));
+ assertTrue(TestValues.TRUE, Validator.validateDriverDistractionCapability(TestValues.GENERAL_DRIVERDISTRACTIONCAPABILITY, testDriverDistractionCapability));
+
for(int i = 0; i < TestValues.GENERAL_DISPLAYCAPABILITY_LIST.size(); i++){
assertTrue(TestValues.TRUE, Validator.validateDisplayCapability(TestValues.GENERAL_DISPLAYCAPABILITY_LIST.get(i), displayCapabilities.get(i)));
@@ -77,6 +84,13 @@ public class SystemCapabilityTests extends TestCase {
assertNull(TestValues.NULL, msg.getCapabilityForType(SystemCapabilityType.REMOTE_CONTROL));
assertNull(TestValues.NULL, msg.getCapabilityForType(SystemCapabilityType.APP_SERVICES));
assertNull(TestValues.NULL, msg.getCapabilityForType(SystemCapabilityType.DISPLAYS));
+ assertNull(TestValues.NULL, msg.getCapabilityForType(SystemCapabilityType.DRIVER_DISTRACTION));
+
+ // Testing Setting an HMICapability as a SystemCapability
+ HMICapabilities hmiCapabilities = new HMICapabilities();
+ msg.setCapabilityForType(SystemCapabilityType.HMI, hmiCapabilities);
+ assertNull(TestValues.NULL, msg.getCapabilityForType(SystemCapabilityType.HMI));
+
}
public void testJson() {
@@ -89,6 +103,7 @@ public class SystemCapabilityTests extends TestCase {
reference.put(SystemCapability.KEY_REMOTE_CONTROL_CAPABILITY, JsonRPCMarshaller.serializeHashtable(TestValues.GENERAL_REMOTECONTROLCAPABILITIES.getStore()));
reference.put(SystemCapability.KEY_APP_SERVICES_CAPABILITIES, JsonRPCMarshaller.serializeHashtable(TestValues.GENERAL_APP_SERVICE_CAPABILITIES.getStore()));
reference.put(SystemCapability.KEY_DISPLAY_CAPABILITIES, TestValues.JSON_DISPLAYCAPABILITY_LIST);
+ reference.put(SystemCapability.KEY_DRIVER_DISTRACTION_CAPABILITY, JsonRPCMarshaller.serializeHashtable(TestValues.GENERAL_DRIVERDISTRACTIONCAPABILITY.getStore()));
JSONObject underTest = msg.serializeJSON();
assertEquals(TestValues.MATCH, reference.length(), underTest.length());
@@ -133,7 +148,13 @@ public class SystemCapabilityTests extends TestCase {
Hashtable<String, Object> hashTest= JsonRPCMarshaller.deserializeJSONObject(underTestArray.getJSONObject(i));
assertTrue(TestValues.TRUE, Validator.validateDisplayCapability(new DisplayCapability(hashReference), new DisplayCapability(hashTest)));
}
- } else{
+ } else if (key.equals(SystemCapability.KEY_DRIVER_DISTRACTION_CAPABILITY)) {
+ JSONObject objectEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key);
+ JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key);
+ Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(objectEquals);
+ Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals);
+ assertTrue(TestValues.TRUE, Validator.validateDriverDistractionCapability(new DriverDistractionCapability(hashReference), new DriverDistractionCapability(hashTest)));
+ } else {
assertEquals(TestValues.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
}
}
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemCapabilityTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemCapabilityTypeTests.java
index f453cb985..94617493c 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemCapabilityTypeTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemCapabilityTypeTests.java
@@ -54,6 +54,8 @@ public class SystemCapabilityTypeTests extends TestCase {
SystemCapabilityType enumPrerecordedSpeech = SystemCapabilityType.valueForString(example);
example = "DISPLAYS";
SystemCapabilityType enumDisplays = SystemCapabilityType.valueForString(example);
+ example = "DRIVER_DISTRACTION";
+ SystemCapabilityType enumDriverDistraction = SystemCapabilityType.valueForString(example);
assertNotNull("NAVIGATION returned null", enumNavigation);
assertNotNull("PHONE_CALL returned null", enumPhoneCall);
@@ -73,6 +75,8 @@ public class SystemCapabilityTypeTests extends TestCase {
assertNotNull("SEAT_LOCATION return null", enumSeatLocation);
assertNotNull("PRERECORDED_SPEECH", enumPrerecordedSpeech);
assertNotNull("DISPLAYS", enumDisplays);
+ assertNotNull("DRIVER_DISTRACTION", enumDriverDistraction);
+
}
/**
@@ -128,6 +132,8 @@ public class SystemCapabilityTypeTests extends TestCase {
enumTestList.add(SystemCapabilityType.SEAT_LOCATION);
enumTestList.add(SystemCapabilityType.PRERECORDED_SPEECH);
enumTestList.add(SystemCapabilityType.DISPLAYS);
+ enumTestList.add(SystemCapabilityType.DRIVER_DISTRACTION);
+
assertTrue("Enum value list does not match enum class list",
enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList));
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddSubmenuTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddSubmenuTests.java
index da2bbfab8..1885f8c9b 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddSubmenuTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddSubmenuTests.java
@@ -40,6 +40,7 @@ public class AddSubmenuTests extends BaseRpcTests{
msg.setPosition(TestValues.GENERAL_INT);
msg.setMenuIcon(TestValues.GENERAL_IMAGE);
msg.setMenuLayout(TestValues.GENERAL_MENU_LAYOUT);
+ msg.setParentID(TestValues.GENERAL_MENU_MAX_ID);
return msg;
}
@@ -64,6 +65,7 @@ public class AddSubmenuTests extends BaseRpcTests{
result.put(AddSubMenu.KEY_POSITION, TestValues.GENERAL_INT);
result.put(AddSubMenu.KEY_MENU_ICON, TestValues.JSON_IMAGE);
result.put(AddSubMenu.KEY_MENU_LAYOUT, TestValues.GENERAL_MENU_LAYOUT);
+ result.put(AddSubMenu.KEY_PARENT_ID, TestValues.GENERAL_MENU_MAX_ID);
}catch(JSONException e){
fail(TestValues.JSON_FAIL);
}
@@ -77,11 +79,12 @@ public class AddSubmenuTests extends BaseRpcTests{
@Test
public void testRpcValues () {
// Test Values
- int testMenuId = ( (AddSubMenu) msg ).getMenuID();
- int testPosition = ( (AddSubMenu) msg ).getPosition();
- String testMenuName = ( (AddSubMenu) msg ).getMenuName();
- Image testMenuIcon = ( (AddSubMenu) msg ).getMenuIcon();
- MenuLayout testMenuLayout = ( (AddSubMenu) msg ).getMenuLayout();
+ int testMenuId = ((AddSubMenu) msg).getMenuID();
+ int testPosition = ((AddSubMenu) msg).getPosition();
+ String testMenuName = ((AddSubMenu) msg).getMenuName();
+ Image testMenuIcon = ((AddSubMenu) msg).getMenuIcon();
+ MenuLayout testMenuLayout = ((AddSubMenu) msg).getMenuLayout();
+ int testParentID = ((AddSubMenu) msg).getParentID();
// Valid Tests
assertEquals("Menu ID didn't match input menu ID.", TestValues.GENERAL_INT, testMenuId);
@@ -89,6 +92,7 @@ public class AddSubmenuTests extends BaseRpcTests{
assertEquals("Position didn't match input position.", TestValues.GENERAL_INT, testPosition);
assertTrue("Menu icon didn't match input icon.", Validator.validateImage(TestValues.GENERAL_IMAGE, testMenuIcon));
assertEquals("Menu layout didn't match input menu layout.", TestValues.GENERAL_MENU_LAYOUT, testMenuLayout);
+ assertEquals("Parent ID didn't match input Parent ID.", TestValues.GENERAL_MENU_MAX_ID, testParentID);
// Invalid/Null Tests
@@ -101,6 +105,7 @@ public class AddSubmenuTests extends BaseRpcTests{
assertNull(TestValues.NULL, msg.getPosition());
assertNull(TestValues.NULL, msg.getMenuIcon());
assertNull(TestValues.NULL, msg.getMenuLayout());
+ assertNull(TestValues.NULL, msg.getParentID());
}
/**
@@ -128,6 +133,7 @@ public class AddSubmenuTests extends BaseRpcTests{
assertEquals(TestValues.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, AddSubMenu.KEY_POSITION), cmd.getPosition());
assertEquals(TestValues.MATCH, JsonUtils.readStringFromJsonObject(parameters, AddSubMenu.KEY_MENU_NAME), cmd.getMenuName());
assertEquals(TestValues.MATCH, JsonUtils.readObjectFromJsonObject(parameters, AddSubMenu.KEY_MENU_LAYOUT), cmd.getMenuLayout());
+ assertEquals(TestValues.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, AddSubMenu.KEY_PARENT_ID), cmd.getParentID());
JSONObject menuIcon = JsonUtils.readJsonObjectFromJsonObject(parameters, AddSubMenu.KEY_MENU_ICON);
Image referenceMenuIcon = new Image(JsonRPCMarshaller.deserializeJSONObject(menuIcon));
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/security/SdlSecurityBaseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/security/SdlSecurityBaseTest.java
index 1a089daa0..685b8cbf5 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/security/SdlSecurityBaseTest.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/security/SdlSecurityBaseTest.java
@@ -10,6 +10,8 @@ import com.smartdevicelink.security.SdlSecurityBase;
import com.smartdevicelink.test.TestValues;
import com.smartdevicelink.transport.BTTransportConfig;
import com.smartdevicelink.transport.BaseTransportConfig;
+import com.smartdevicelink.transport.MultiplexTransportConfig;
+import com.smartdevicelink.transport.TCPTransportConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -17,6 +19,7 @@ import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.List;
+import static android.support.test.InstrumentationRegistry.getTargetContext;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
@@ -139,11 +142,11 @@ public class SdlSecurityBaseTest {
byte testWiproVersion = (byte) 0x0B;
boolean testInitResult = true;
MockInterfaceBroker interfaceBroker = new MockInterfaceBroker();
- BaseTransportConfig transportConfig = new BTTransportConfig(true);
+ MultiplexTransportConfig transportConfig = new MultiplexTransportConfig(getTargetContext(),"19216801");
MockSdlSecurityBase mockSdlSecurityBase = new MockSdlSecurityBase();
- SdlSession testSdlSession = SdlSession.createSession(testWiproVersion,interfaceBroker, transportConfig);
-
+ SdlSession testSdlSession = new SdlSession(interfaceBroker, transportConfig);
+
assertNotNull(TestValues.NOT_NULL, mockSdlSecurityBase);
assertNotNull(TestValues.NOT_NULL, testSdlSession);
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/AbstractPacketizerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/AbstractPacketizerTests.java
index b4167bef5..f487ac927 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/AbstractPacketizerTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/AbstractPacketizerTests.java
@@ -7,6 +7,8 @@ import com.smartdevicelink.streaming.IStreamListener;
import com.smartdevicelink.test.TestValues;
import com.smartdevicelink.transport.BTTransportConfig;
import com.smartdevicelink.transport.BaseTransportConfig;
+import com.smartdevicelink.transport.MultiplexTransportConfig;
+import com.smartdevicelink.util.Version;
import junit.framework.TestCase;
@@ -15,6 +17,8 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import static android.support.test.InstrumentationRegistry.getTargetContext;
+
/**
* This is a unit test class for the SmartDeviceLink library project class :
* {@link com.smartdevicelink.streaming.AbstractPacketizer}
@@ -23,8 +27,8 @@ public class AbstractPacketizerTests extends TestCase {
/**
* This is a unit test for the following methods :
- * {@link com.smartdevicelink.streaming.AbstractPacketizer#AbstractPacketizer(IStreamListener, InputStream, SessionType, byte)}
- * {@link com.smartdevicelink.streaming.AbstractPacketizer#AbstractPacketizer(IStreamListener, InputStream, RPCRequest, SessionType, byte, byte)}
+ * {@link com.smartdevicelink.streaming.AbstractPacketizer#AbstractPacketizer(IStreamListener, InputStream, RPCRequest, SessionType, byte, Version, SdlSession)}
+ * {@link com.smartdevicelink.streaming.AbstractPacketizer#AbstractPacketizer(IStreamListener, InputStream, RPCRequest, SessionType, byte, Version, SdlSession)}
*/
public void testConstructors () {
@@ -41,9 +45,9 @@ public class AbstractPacketizerTests extends TestCase {
IStreamListener testListener = new MockStreamListener();
try {
testInputStream = new BufferedInputStream(new ByteArrayInputStream("sdl streaming test".getBytes()));
- MockInterfaceBroker _interfaceBroker = new MockInterfaceBroker();
- BaseTransportConfig _transportConfig = new BTTransportConfig(true);
- testSdlSession = SdlSession.createSession(testWiproVersion,_interfaceBroker, _transportConfig);
+ MockInterfaceBroker interfaceBroker = new MockInterfaceBroker();
+ MultiplexTransportConfig transportConfig = new MultiplexTransportConfig(getTargetContext(),"19216801");
+ testSdlSession = new SdlSession(interfaceBroker, transportConfig);
testPacketizer1 = new MockPacketizer(testListener, testInputStream, testSessionType, testSessionId, testSdlSession);
testPacketizer2 = new MockPacketizer(null, null, null, testSessionId, testSdlSession);
testPacketizer3 = new MockPacketizer(testListener, testInputStream, testRpcRequest, testSessionType, testSessionId, testWiproVersion, testSdlSession);
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/StreamPacketizerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/StreamPacketizerTests.java
index e7a367d0e..fdfcce8cf 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/StreamPacketizerTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/StreamPacketizerTests.java
@@ -9,6 +9,7 @@ import com.smartdevicelink.streaming.StreamPacketizer;
import com.smartdevicelink.test.TestValues;
import com.smartdevicelink.transport.BTTransportConfig;
import com.smartdevicelink.transport.BaseTransportConfig;
+import com.smartdevicelink.transport.MultiplexTransportConfig;
import junit.framework.TestCase;
@@ -20,6 +21,8 @@ import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Arrays;
+import static android.support.test.InstrumentationRegistry.getTargetContext;
+
/**
* This is a unit test class for the SmartDeviceLink library project class :
* {@link com.smartdevicelink.streaming.StreamPacketizer}
@@ -117,7 +120,7 @@ public class StreamPacketizerTests extends TestCase {
/**
* This is a unit test for the following methods :
- * {@link com.smartdevicelink.streaming.StreamPacketizer#StreamPacketizer(IStreamListener, InputStream, SessionType, byte)}
+ * {@link com.smartdevicelink.streaming.StreamPacketizer#StreamPacketizer(IStreamListener, InputStream, SessionType, byte, SdlSession)}
*/
public void testConstructor () {
@@ -127,9 +130,9 @@ public class StreamPacketizerTests extends TestCase {
InputStream testInputStream = null;
byte testWiproVersion = (byte) 0x0B;
IStreamListener testListener = new MockStreamListener();
- MockInterfaceBroker _interfaceBroker = new MockInterfaceBroker();
- BaseTransportConfig _transportConfig = new BTTransportConfig(true);
- SdlSession testSdlSession = SdlSession.createSession(testWiproVersion,_interfaceBroker, _transportConfig);
+ MockInterfaceBroker interfaceBroker = new MockInterfaceBroker();
+ MultiplexTransportConfig transportConfig = new MultiplexTransportConfig(getTargetContext(),"19216801");
+ SdlSession testSdlSession = new SdlSession(interfaceBroker, transportConfig);
try {
testInputStream = new BufferedInputStream(new ByteArrayInputStream("sdl streaming test".getBytes()));
StreamPacketizer testStreamPacketizer = new StreamPacketizer(testListener, testInputStream, testSessionType, testSessionId, testSdlSession);
@@ -411,7 +414,7 @@ public class StreamPacketizerTests extends TestCase {
private SdlSession createTestSession() {
- return SdlSession.createSession(WIPRO_VERSION, new MockInterfaceBroker(), new BTTransportConfig(true));
+ return new SdlSession(new MockInterfaceBroker(), new MultiplexTransportConfig(getTargetContext(),"19216801"));
}
private class StreamReceiver implements IStreamListener {
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/StreamRPCPacketizerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/StreamRPCPacketizerTests.java
index 30a97a09a..638d3f636 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/StreamRPCPacketizerTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/StreamRPCPacketizerTests.java
@@ -9,6 +9,7 @@ import com.smartdevicelink.streaming.StreamRPCPacketizer;
import com.smartdevicelink.test.TestValues;
import com.smartdevicelink.transport.BTTransportConfig;
import com.smartdevicelink.transport.BaseTransportConfig;
+import com.smartdevicelink.transport.MultiplexTransportConfig;
import junit.framework.TestCase;
@@ -17,6 +18,8 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import static android.support.test.InstrumentationRegistry.getTargetContext;
+
/**
* This is a unit test class for the SmartDeviceLink library project class :
* {@link com.smartdevicelink.streaming.StreamRPCPacketizer}
@@ -37,10 +40,9 @@ public class StreamRPCPacketizerTests extends TestCase {
InputStream testInputStream = null;
IStreamListener testListener = new MockStreamListener();
- byte testWiproVersion = (byte) 0x0B;
- MockInterfaceBroker _interfaceBroker = new MockInterfaceBroker();
- BaseTransportConfig _transportConfig = new BTTransportConfig(true);
- SdlSession testSdlSession = SdlSession.createSession(testWiproVersion,_interfaceBroker, _transportConfig);
+ MockInterfaceBroker interfaceBroker = new MockInterfaceBroker();
+ MultiplexTransportConfig transportConfig = new MultiplexTransportConfig(getTargetContext(),"19216801");
+ SdlSession testSdlSession = new SdlSession(interfaceBroker, transportConfig);
try {
testInputStream = new BufferedInputStream(new ByteArrayInputStream("sdl streaming test".getBytes()));
StreamRPCPacketizer testStreamRpcPacketizer = new StreamRPCPacketizer(null, testListener, testInputStream, testRequest, testSessionType, testSessionId, testWV, testWV, testSdlSession);
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/video/RTPH264PacketizerTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/video/RTPH264PacketizerTest.java
index 7090ba8e8..b2b863490 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/video/RTPH264PacketizerTest.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/video/RTPH264PacketizerTest.java
@@ -30,6 +30,9 @@
package com.smartdevicelink.test.streaming.video;
+
+import android.support.test.runner.AndroidJUnit4;
+
import com.smartdevicelink.SdlConnection.SdlSession;
import com.smartdevicelink.protocol.ProtocolMessage;
import com.smartdevicelink.protocol.enums.SessionType;
@@ -37,20 +40,26 @@ import com.smartdevicelink.proxy.interfaces.IVideoStreamListener;
import com.smartdevicelink.streaming.IStreamListener;
import com.smartdevicelink.streaming.video.RTPH264Packetizer;
import com.smartdevicelink.test.streaming.MockInterfaceBroker;
-import com.smartdevicelink.transport.BTTransportConfig;
+import com.smartdevicelink.transport.MultiplexTransportConfig;
import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import static android.support.test.InstrumentationRegistry.getTargetContext;
+
/**
* This class includes a unit test for {@link RTPH264Packetizer}.
*
* @author Sho Amano
*/
+@RunWith(AndroidJUnit4.class)
public class RTPH264PacketizerTest extends TestCase {
private static final int FRAME_LENGTH_LEN = 2;
@@ -145,6 +154,7 @@ public class RTPH264PacketizerTest extends TestCase {
/**
* Test for creating Single Frame RTP packets from H.264 byte stream
*/
+ @Test
public void testSingleFrames() {
StreamVerifier verifier = new StreamVerifier(SAMPLE_STREAM);
SdlSession session = createTestSession();
@@ -174,6 +184,7 @@ public class RTPH264PacketizerTest extends TestCase {
/**
* Test for creating Single Frame RTP packets then splitting into multiple SDL frames
*/
+ @Test
public void testSingleFramesIntoMultipleMessages() {
StreamVerifier verifier = new StreamVerifier(SAMPLE_STREAM);
SdlSession session = createTestSession();
@@ -228,6 +239,7 @@ public class RTPH264PacketizerTest extends TestCase {
/**
* Test for creating Fragmentation Units from H.264 byte stream
*/
+ @Test
public void testFragmentationUnits() {
ByteStreamNALUnit[] stream = new ByteStreamNALUnit[] {
SAMPLE_STREAM[0], SAMPLE_STREAM[1], null, null, null, SAMPLE_STREAM[5]
@@ -278,6 +290,7 @@ public class RTPH264PacketizerTest extends TestCase {
/**
* Test for RTP sequence number gets wrap-around correctly
*/
+ @Test
public void testSequenceNumWrapAround() {
ByteStreamNALUnit[] stream = new ByteStreamNALUnit[70000];
for (int i = 0; i < stream.length; i++) {
@@ -312,6 +325,7 @@ public class RTPH264PacketizerTest extends TestCase {
/**
* Test for {@link RTPH264Packetizer#setPayloadType(byte)}
*/
+ @Test
public void testSetPayloadType() {
byte pt = (byte)123;
StreamVerifier verifier = new StreamVerifier(SAMPLE_STREAM, pt);
@@ -343,6 +357,7 @@ public class RTPH264PacketizerTest extends TestCase {
/**
* Test for {@link RTPH264Packetizer#setSSRC(int)}
*/
+ @Test
public void testSetSSRC() {
int ssrc = 0xFEDCBA98;
StreamVerifier verifier = new StreamVerifier(SAMPLE_STREAM);
@@ -376,6 +391,7 @@ public class RTPH264PacketizerTest extends TestCase {
* Test for {@link RTPH264Packetizer#pause()} and
* {@link RTPH264Packetizer#resume()}
*/
+ @Test
public void testPauseResume() {
int index = 0;
// split SAMPLE_STREAM into three parts
@@ -446,6 +462,7 @@ public class RTPH264PacketizerTest extends TestCase {
/**
* Test for {@link RTPH264Packetizer#sendFrame(byte[], int, int, long)}
*/
+ @Test
public void testSendFrameInterfaceWithArray() {
StreamVerifier verifier = new StreamVerifier(SAMPLE_STREAM);
SdlSession session = createTestSession();
@@ -475,6 +492,7 @@ public class RTPH264PacketizerTest extends TestCase {
/**
* Test for {@link RTPH264Packetizer#sendFrame(ByteBuffer, long)}
*/
+ @Test
public void testSendFrameInterfaceWithByteBuffer() {
StreamVerifier verifier = new StreamVerifier(SAMPLE_STREAM);
SdlSession session = createTestSession();
@@ -505,6 +523,7 @@ public class RTPH264PacketizerTest extends TestCase {
* Test for {@link RTPH264Packetizer#sendFrame(ByteBuffer, long)}
* with direct ByteBuffer
*/
+ @Test
public void testSendFrameInterfaceWithDirectByteBuffer() {
StreamVerifier verifier = new StreamVerifier(SAMPLE_STREAM);
SdlSession session = createTestSession();
@@ -532,7 +551,7 @@ public class RTPH264PacketizerTest extends TestCase {
}
private SdlSession createTestSession() {
- return SdlSession.createSession(WIPRO_VERSION, new MockInterfaceBroker(), new BTTransportConfig(true));
+ return new SdlSession(new MockInterfaceBroker(), new MultiplexTransportConfig(getTargetContext(), "41146"));
}
private class StreamVerifier implements IStreamListener {
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/transport/SdlPsmTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/transport/SdlPsmTests.java
index cca9171c8..c382d656c 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/transport/SdlPsmTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/transport/SdlPsmTests.java
@@ -3,7 +3,7 @@ package com.smartdevicelink.test.transport;
import android.util.Log;
import com.smartdevicelink.protocol.SdlPacket;
-import com.smartdevicelink.protocol.WiProProtocol;
+import com.smartdevicelink.protocol.SdlProtocol;
import com.smartdevicelink.test.TestValues;
import com.smartdevicelink.transport.SdlPsm;
@@ -18,7 +18,7 @@ import java.lang.reflect.Method;
*/
public class SdlPsmTests extends TestCase {
private static final String TAG = "SdlPsmTests";
- private static final int MAX_DATA_LENGTH = WiProProtocol.V1_V2_MTU_SIZE - WiProProtocol.V1_HEADER_SIZE;
+ private static final int MAX_DATA_LENGTH = SdlProtocol.V1_V2_MTU_SIZE - SdlProtocol.V1_HEADER_SIZE;
SdlPsm sdlPsm;
Field frameType, dataLength, version, controlFrameInfo;
Method transitionOnInput;
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java
index 192f3aa3c..a67e9dff7 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java
@@ -7,10 +7,6 @@ import android.os.Message;
import android.support.test.runner.AndroidJUnit4;
import com.smartdevicelink.protocol.SdlPacket;
-import com.smartdevicelink.test.SdlUnitTestContants;
-import com.smartdevicelink.transport.enums.TransportType;
-
-import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -19,14 +15,11 @@ import org.junit.runner.RunWith;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
-import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.assertTrue;
@RunWith(AndroidJUnit4.class)
public class MultiplexTransportTest {
- private static final int TIMEOUT = 2000;
-
RouterServiceValidator rsvp;
ITransportListener transportListener;
@@ -58,55 +51,24 @@ public class MultiplexTransportTest {
};
}
-
- @Test
- public void testThreadRecoverability(){
- MultiplexTransportConfig config = new MultiplexTransportConfig(getTargetContext(),SdlUnitTestContants.TEST_APP_ID);
- // public MultiplexTransport(MultiplexTransportConfig transportConfig, final ITransportListener transportListener){
- MultiplexTransport trans = new MultiplexTransport(config,transportListener);
-
- assertTrue(trans.brokerThread.isAlive());
- if(trans.brokerThread.broker==null){
- synchronized(trans.brokerThread){
- try {
- trans.brokerThread.wait(TIMEOUT);;
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
-
- assertNotNull(trans.brokerThread.broker);
- //Force this to true so we can test thread
- trans.brokerThread.connected = true;
- trans.brokerThread.broker.onHardwareDisconnected(TransportType.BLUETOOTH);
-
- assertNull(trans.brokerThread);
-
- trans = new MultiplexTransport(config,transportListener);
- assertTrue(trans.brokerThread.isAlive());
-
- // Send a null config object in the constructor and expect an IllegalArgumentException
- try {
- trans = new MultiplexTransport(null, transportListener);
- } catch (IllegalArgumentException e) {
- assertEquals("Null transportConfig in MultiplexTransport constructor", e.getMessage());
- } catch (NullPointerException e) {
- Assert.fail("NPE in MultiplexTransport constructor");
- }
- }
-
// test for setting error state.
@Test
public void testSetState() {
- final Bundle bundle = new Bundle();
MultiplexBluetoothTransport btTransport = new MultiplexBluetoothTransport(new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message message) {
- assertTrue(message.getData().equals(bundle));
+ assertNotNull(message);
+ if (message.arg1 == MultiplexBaseTransport.STATE_ERROR) {
+ assertNotNull(message.getData());
+ assertEquals(MultiplexBaseTransport.REASON_SPP_ERROR, message.getData().getByte(MultiplexBaseTransport.ERROR_REASON_KEY));
+ } else {
+ //It will first listen before the error state
+ assertEquals(MultiplexBaseTransport.STATE_LISTEN, message.arg1);
+ }
}
});
btTransport.start();
+ final Bundle bundle = new Bundle();
bundle.putByte(MultiplexBaseTransport.ERROR_REASON_KEY, MultiplexBaseTransport.REASON_SPP_ERROR);
btTransport.setState(MultiplexBaseTransport.STATE_ERROR, bundle);
}
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/TransportBrokerTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/TransportBrokerTest.java
index d74501313..332f3eda4 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/TransportBrokerTest.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/TransportBrokerTest.java
@@ -20,7 +20,7 @@ import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertTrue;
@RunWith(AndroidJUnit4.class)
-public class TransportBrokerTest {
+public class TransportBrokerTest { //FIXME this test class needs to be fixed. At this point these tests are not helpful
RouterServiceValidator rsvp;
// public TransportBrokerThread(Context context, String appId, ComponentName service){
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlConnection.java b/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlConnection.java
deleted file mode 100644
index cdba04757..000000000
--- a/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlConnection.java
+++ /dev/null
@@ -1,661 +0,0 @@
-/*
- * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.smartdevicelink.SdlConnection;
-
-
-import android.content.ComponentName;
-
-import com.smartdevicelink.exception.SdlException;
-import com.smartdevicelink.protocol.AbstractProtocol;
-import com.smartdevicelink.protocol.IProtocolListener;
-import com.smartdevicelink.protocol.ProtocolMessage;
-import com.smartdevicelink.protocol.SdlPacket;
-import com.smartdevicelink.protocol.WiProProtocol;
-import com.smartdevicelink.protocol.enums.SessionType;
-import com.smartdevicelink.transport.BTTransport;
-import com.smartdevicelink.transport.BTTransportConfig;
-import com.smartdevicelink.transport.BaseTransportConfig;
-import com.smartdevicelink.transport.ITransportListener;
-import com.smartdevicelink.transport.MultiplexTransport;
-import com.smartdevicelink.transport.MultiplexTransportConfig;
-import com.smartdevicelink.transport.RouterServiceValidator;
-import com.smartdevicelink.transport.SdlBroadcastReceiver;
-import com.smartdevicelink.transport.SdlTransport;
-import com.smartdevicelink.transport.TCPTransport;
-import com.smartdevicelink.transport.TCPTransportConfig;
-import com.smartdevicelink.transport.USBTransport;
-import com.smartdevicelink.transport.USBTransportConfig;
-import com.smartdevicelink.transport.enums.TransportType;
-import com.smartdevicelink.util.DebugTool;
-
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-@Deprecated
-public class SdlConnection implements IProtocolListener, ITransportListener {
-
- private static final String TAG = "SdlConnection";
-
- SdlTransport _transport = null;
- AbstractProtocol _protocol = null;
- ISdlConnectionListener _connectionListener = null;
-
-
-
- // Thread safety locks
- static Object TRANSPORT_REFERENCE_LOCK = new Object();
- Object PROTOCOL_REFERENCE_LOCK = new Object();
-
- private Object SESSION_LOCK = new Object();
- private CopyOnWriteArrayList<SdlSession> listenerList = new CopyOnWriteArrayList<SdlSession>();
- private static TransportType legacyTransportRequest = null;
- private final static int BUFF_READ_SIZE = 1000000;
- protected static MultiplexTransportConfig cachedMultiConfig = null;
-
- /**
- * Constructor.
- *
- * @param transportConfig Transport configuration for this connection.
- */
- public SdlConnection(BaseTransportConfig transportConfig) {
- RouterServiceValidator vlad = null;
- //Let's check if we can even do multiplexing
- if(transportConfig.getTransportType() == TransportType.MULTIPLEX){
- ComponentName tempCompName = SdlBroadcastReceiver.consumeQueuedRouterService();
- MultiplexTransportConfig multiConfig = (MultiplexTransportConfig)transportConfig;
- if(tempCompName!=null){
- vlad =new RouterServiceValidator(multiConfig.getContext(),tempCompName);
- }else{
- vlad =new RouterServiceValidator(multiConfig.getContext());
- }
- //vlad.setFlags(RouterServiceValidator.FLAG_DEBUG_VERSION_CHECK);
- vlad.setSecurityLevel(multiConfig.getSecurityLevel());
- }
- constructor(transportConfig,vlad);
- }
- //For unit tests
- protected SdlConnection(BaseTransportConfig transportConfig,RouterServiceValidator rsvp){
- constructor(transportConfig,rsvp);
- }
-
- private void constructor(BaseTransportConfig transportConfig,RouterServiceValidator rsvp){
- _connectionListener = new InternalMsgDispatcher();
-
- // Initialize the transport
- synchronized(TRANSPORT_REFERENCE_LOCK) {
- // Ensure transport is null
- if (_transport != null) {
- if (_transport.getIsConnected()) {
- _transport.disconnect();
- }
- _transport = null;
- }
-
- //Let's check if we can even do multiplexing
- if(!isLegacyModeEnabled() &&
- rsvp!= null &&
- transportConfig.getTransportType() == TransportType.MULTIPLEX){
- //rsvp = new RouterServiceValidator(((MultiplexTransportConfig)transportConfig).getContext());
- //vlad.setFlags(RouterServiceValidator.FLAG_DEBUG_VERSION_CHECK);
- if(rsvp.validate()){
- DebugTool.logWarning(TAG, "SDL Router service is valid; attempting to connect");
- ((MultiplexTransportConfig)transportConfig).setService(rsvp.getService());//Let thes the transport broker know which service to connect to
- }else{
- DebugTool.logWarning(TAG, "SDL Router service isn't trusted. Enabling legacy bluetooth connection.");
- if(cachedMultiConfig == null){
- cachedMultiConfig = (MultiplexTransportConfig) transportConfig;
- cachedMultiConfig.setService(null);
- }
- enableLegacyMode(true,TransportType.BLUETOOTH); //We will use legacy bluetooth connection for this attempt
- }
- }
-
- if(!isLegacyModeEnabled() && //Make sure legacy mode is not enabled
- (transportConfig.getTransportType() == TransportType.MULTIPLEX)){
- _transport = new MultiplexTransport((MultiplexTransportConfig)transportConfig,this);
- }else if(isLegacyModeEnabled() && legacyTransportRequest == TransportType.BLUETOOTH){
- _transport = new BTTransport(this, true);
- }else if(transportConfig.getTransportType() == TransportType.BLUETOOTH){
- _transport = new BTTransport(this,((BTTransportConfig)transportConfig).getKeepSocketActive());
- }
- else if (transportConfig.getTransportType() == TransportType.TCP)
- {
- _transport = new TCPTransport((TCPTransportConfig) transportConfig, this);
- } else if (transportConfig.getTransportType() == TransportType.USB) {
- _transport = new USBTransport((USBTransportConfig) transportConfig, this);
- }
- }
-
- // Initialize the protocol
- synchronized(PROTOCOL_REFERENCE_LOCK) {
- // Ensure protocol is null
- if (_protocol != null) {
- _protocol = null;
- }
-
- _protocol = new WiProProtocol(this);
- }
- }
-
- public AbstractProtocol getWiProProtocol(){
- return _protocol;
- }
-
-
-
-
- private void closeConnection(boolean willRecycle, byte rpcSessionID, int sessionHashId) {
- synchronized(PROTOCOL_REFERENCE_LOCK) {
-
- if (_protocol != null) {
- // If transport is still connected, sent EndProtocolSessionMessage
- if (_transport != null && _transport.getIsConnected()) {
- _protocol.EndProtocolSession(SessionType.RPC, rpcSessionID, sessionHashId);
- }
- if (willRecycle) {
- _protocol = null;
- }
- } // end-if
- }
- synchronized (TRANSPORT_REFERENCE_LOCK) {
- if (willRecycle) {
- if (_transport != null) {
- _transport.disconnect();
- }
- _transport = null;
- }
- }
- }
-
-
- public void startTransport() throws SdlException {
- _transport.openConnection();
- }
-
- public Boolean getIsConnected() {
-
- // If _transport is null, then it can't be connected
- if (_transport == null) {
- return false;
- }
-
- return _transport.getIsConnected();
- }
-
- public String getBroadcastComment() {
-
- if (_transport == null) {
- return "";
- }
-
- return _transport.getBroadcastComment();
- }
-
- public void sendMessage(ProtocolMessage msg) {
- if(_protocol != null)
- _protocol.SendMessage(msg);
- }
-
- void startHandShake() {
- synchronized(PROTOCOL_REFERENCE_LOCK){
- if(_protocol != null){
- _protocol.StartProtocolSession(SessionType.RPC);
- }
- }
- }
-
- @Override
- public void onTransportPacketReceived(SdlPacket packet) {
- // Send bytes to protocol to be interpreted
- synchronized(PROTOCOL_REFERENCE_LOCK) {
- if (_protocol != null) {
- _protocol.handlePacketReceived(packet);
- }
- }
- }
-
- @Override
- public void onTransportConnected() {
- synchronized(PROTOCOL_REFERENCE_LOCK){
- if(_protocol != null){
- boolean shouldRequestSession = _transport !=null && _transport.getTransportType()== TransportType.MULTIPLEX;
- for (SdlSession s : listenerList) {
- if (s.getSessionId() == 0) {
- if(shouldRequestSession){
- ((MultiplexTransport)_transport).requestNewSession();
- }
- startHandShake();
- }
- }
- }
- }
- }
-
- @Override
- public void onTransportDisconnected(String info) {
- // Pass directly to connection listener
- _connectionListener.onTransportDisconnected(info);
- }
-
- @Override
- public void onTransportError(String info, Exception e) {
- // Pass directly to connection listener
- _connectionListener.onTransportError(info, e);
- }
-
- @Override
- public void onProtocolMessageBytesToSend(SdlPacket packet) {
- // Protocol has packaged bytes to send, pass to transport for transmission
- synchronized(TRANSPORT_REFERENCE_LOCK) {
- if (_transport != null) {
- _transport.sendBytes(packet);
- }
- }
- }
-
- @Override
- public void onProtocolMessageReceived(ProtocolMessage msg) {
- _connectionListener.onProtocolMessageReceived(msg);
- }
-
- @Override
- public void onProtocolSessionStarted(SessionType sessionType,
- byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) {
- _connectionListener.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID, isEncrypted);
- }
-
- @Override
- public void onProtocolSessionNACKed(SessionType sessionType,
- byte sessionID, byte version, String correlationID, List<String> rejectedParams) {
- _connectionListener.onProtocolSessionStartedNACKed(sessionType,
- sessionID, version, correlationID, rejectedParams);
- }
-
- @Override
- public void onProtocolSessionEnded(SessionType sessionType, byte sessionID,
- String correlationID) {
- _connectionListener.onProtocolSessionEnded(sessionType, sessionID, correlationID);
- }
-
- @Override
- public void onProtocolError(String info, Exception e) {
- _connectionListener.onProtocolError(info, e);
- }
-
-
- /**
- * Gets type of transport currently used by this connection.
- *
- * @return One of TransportType enumeration values.
- *
- * @see TransportType
- */
- public TransportType getCurrentTransportType() {
- return _transport.getTransportType();
- }
-
- public void startService (SessionType sessionType, byte sessionID, boolean isEncrypted) {
- synchronized(PROTOCOL_REFERENCE_LOCK){
- if(_protocol != null){
- _protocol.StartProtocolService(sessionType, sessionID, isEncrypted);
- }
- }
- }
-
- public void endService (SessionType sessionType, byte sessionID) {
- synchronized(PROTOCOL_REFERENCE_LOCK){
- if(_protocol != null){
- _protocol.EndProtocolService(sessionType, sessionID);
- }
- }
- }
- void registerSession(SdlSession registerListener) throws SdlException {
- boolean didAdd = listenerList.addIfAbsent(registerListener);
- if (!this.getIsConnected()) {
- this.startTransport();
- } else {
- if(didAdd && _transport !=null && _transport.getTransportType()== TransportType.MULTIPLEX){ //If we're connected we can request the extra session now
- ((MultiplexTransport)_transport).requestNewSession();
- }
- this.startHandShake();
- }
- }
-
- public void sendHeartbeat(SdlSession mySession) {
- if(_protocol != null && mySession != null)
- _protocol.SendHeartBeat(mySession.getSessionId());
- }
-
- public void unregisterSession(SdlSession registerListener) {
- boolean didRemove = listenerList.remove(registerListener);
- if(didRemove && _transport !=null && _transport.getTransportType()== TransportType.MULTIPLEX){ //If we're connected we can request the extra session now
- ((MultiplexTransport)_transport).removeSession(registerListener.getSessionId());
- }
- closeConnection(listenerList.size() == 0, registerListener.getSessionId(), registerListener.getSessionHashId());
- }
-
-
- public SdlSession findSessionById(byte id) {
- for (SdlSession listener : listenerList) {
- if (listener.getSessionId() == id) {
- return listener;
- }
- }
- return null;
- }
-
- public void onAuthTokenReceived(String authToken, byte sessionID) {
- if(this._connectionListener != null){
- this._connectionListener.onAuthTokenReceived(authToken,sessionID);
- }
- }
-
- private class InternalMsgDispatcher implements ISdlConnectionListener {
-
- @Override
- public void onTransportDisconnected(String info) {
- for (SdlSession session : listenerList) {
- session.onTransportDisconnected(info);
- }
- if(cachedMultiConfig!=null ){
- if(cachedMultiConfig.getService()!=null){
- synchronized(TRANSPORT_REFERENCE_LOCK) {
- // Ensure transport is null
- if (_transport != null) {
- if (_transport.getIsConnected()) {
- _transport.disconnect();
- }
- _transport = null;
- }
- _transport = new MultiplexTransport(cachedMultiConfig, SdlConnection.this);
- try {
- startTransport();
- } catch (SdlException e) {
- e.printStackTrace();
- }
- }
- }else{ //The service must be null or already consumed. Let's see if we can find the connection that consumed it
- for (SdlSession session : listenerList) {
- session.checkForOpenMultiplexConnection(SdlConnection.this);;
- }
- }
- }
- }
-
- @Override
- public void onTransportDisconnected(String info, boolean availablePrimary, BaseTransportConfig transportConfig) {
- onTransportDisconnected(info);
- }
-
- @Override
- public void onTransportError(String info, Exception e) {
- //If there's an error with the transport we want to make sure we clear out any reference to it held by the static list in sessions
- SdlSession.removeConnection(SdlConnection.this);
- //If we are erroring out to go into legacy mode, lets cache our multiplexing
- if(isLegacyModeEnabled() && _transport!=null && TransportType.MULTIPLEX.equals(_transport.getTransportType())){
- MultiplexTransport multi = ((MultiplexTransport)_transport);
- cachedMultiConfig = multi.getConfig();
- cachedMultiConfig.setService(null); //Make sure we're clearning this out
- }else{
- cachedMultiConfig = null; //It should now be consumed
- }
- for (SdlSession session : listenerList) {
- session.onTransportError(info, e);
- }
-
- }
-
- @Override
- public void onProtocolMessageReceived(ProtocolMessage msg) {
- SdlSession session = findSessionById(msg.getSessionID());
- if (session != null) {
- session.onProtocolMessageReceived(msg);
- }
- }
-
- @Override
- public void onProtocolSessionStarted(SessionType sessionType,
- byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) {
- for (SdlSession session : listenerList) {
- if (session.getSessionId() == 0) {
- session.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID, isEncrypted);
- break;
- }
- }
-
- if (sessionType.equals(SessionType.NAV) || sessionType.equals(SessionType.PCM) || isEncrypted){
- SdlSession session = findSessionById(sessionID);
- if (session != null) {
- session.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID, isEncrypted);
- }
- }
- }
-
- @Override
- public void onProtocolSessionEnded(SessionType sessionType,
- byte sessionID, String correlationID) {
- SdlSession session = findSessionById(sessionID);
- if (session != null) {
- session.onProtocolSessionEnded(sessionType, sessionID, correlationID);
- }
- }
-
- @Override
- public void onProtocolError(String info, Exception e) {
- for (SdlSession session : listenerList) {
- session.onProtocolError(info, e);
- }
- }
-
- @Override
- public void onProtocolSessionStartedNACKed(SessionType sessionType,
- byte sessionID, byte version, String correlationID, List<String> rejectedParams) {
- SdlSession session = findSessionById(sessionID);
- if (session != null) {
- session.onProtocolSessionStartedNACKed(sessionType,
- sessionID, version, correlationID, rejectedParams);
- }
- }
-
- @Override
- public void onHeartbeatTimedOut(byte sessionID) {
- SdlSession session = findSessionById(sessionID);
- if (session != null) {
- session.onHeartbeatTimedOut(sessionID);
- }
- }
-
- @Override
- public void onProtocolSessionEndedNACKed(SessionType sessionType, byte sessionID, String correlationID) {
- SdlSession session = findSessionById(sessionID);
- if (session != null) {
- session.onProtocolSessionEndedNACKed(sessionType, sessionID, correlationID);
- }
- }
-
- @Override
- public void onProtocolServiceDataACK(SessionType serviceType, int dataSize, byte sessionID) {
- SdlSession session = findSessionById(sessionID);
- if (session != null) {
- session.onProtocolServiceDataACK(serviceType, dataSize, sessionID);
- }
- }
-
- @Override
- public void onAuthTokenReceived(String authToken, byte sessionID) {
- SdlSession session = findSessionById(sessionID);
- if (session != null) {
- session.onAuthTokenReceived(authToken,sessionID);
- }
- }
- }
-
- public int getRegisterCount() {
- return listenerList.size();
- }
-
- @Override
- public void onProtocolHeartbeat(SessionType sessionType, byte sessionID) {
- SdlSession mySession = findSessionById(sessionID);
- if (mySession == null) return;
-
- if (mySession._outgoingHeartbeatMonitor != null) {
- mySession._outgoingHeartbeatMonitor.heartbeatReceived();
- }
- if (mySession._incomingHeartbeatMonitor != null) {
- mySession._incomingHeartbeatMonitor.heartbeatReceived();
- }
- }
-
- @Override
- public void onProtocolHeartbeatACK(SessionType sessionType, byte sessionID) {
- SdlSession mySession = findSessionById(sessionID);
- if (mySession == null) return;
-
- if (mySession._outgoingHeartbeatMonitor != null) {
- mySession._outgoingHeartbeatMonitor.heartbeatACKReceived();
- }
- if (mySession._incomingHeartbeatMonitor != null) {
- mySession._incomingHeartbeatMonitor.heartbeatACKReceived();
- }
- }
-
- @Override
- public void onResetOutgoingHeartbeat(SessionType sessionType, byte sessionID){
-
- SdlSession mySession = findSessionById(sessionID);
- if (mySession == null) return;
-
- if (mySession._outgoingHeartbeatMonitor != null) {
- mySession._outgoingHeartbeatMonitor.notifyTransportActivity();
- }
- }
-
- @Override
- public void onResetIncomingHeartbeat(SessionType sessionType, byte sessionID){
-
- SdlSession mySession = findSessionById(sessionID);
- if (mySession == null) return;
-
- if (mySession._incomingHeartbeatMonitor != null) {
- mySession._incomingHeartbeatMonitor.notifyTransportActivity();
- }
- }
-
- public void forceHardwareConnectEvent(TransportType type){
- if(_transport == null){
- DebugTool.logWarning(TAG, "Unable to force connect, transport was null!");
- return;
- }
- if(isLegacyModeEnabled()){//We know we should no longer be in legacy mode for future connections, so lets clear out that flag
- enableLegacyMode(false,null);
- }
- if(_transport!=null && (_transport.getTransportType()==TransportType.MULTIPLEX)){ //This is only valid for the multiplex connection
- MultiplexTransport multi = ((MultiplexTransport)_transport);
- MultiplexTransportConfig config = multi.getConfig();
- ComponentName tempCompName = SdlBroadcastReceiver.consumeQueuedRouterService();
- if(config.getService() != null && config.getService().equals(tempCompName)){ //If this is the same service that just connected that we are already looking at. Attempt to reconnect
- if(!multi.getIsConnected() && multi.isDisconnecting() ){ //If we aren't able to force a connection it means the
- _transport = new MultiplexTransport(config,this);
- try {
- startTransport();
- } catch (SdlException e) {
- e.printStackTrace();
- }
- }
- }else if(tempCompName!=null){
- //We have a conflicting service request
- DebugTool.logWarning(TAG, "Conflicting services. Disconnecting from current and connecting to new");
- //Log.w(TAG, "Old service " + config.getService().toShortString());
- //Log.w(TAG, "New Serivce " + tempCompName.toString());
- multi.disconnect();
- config.setService(tempCompName);
- _transport = new MultiplexTransport(config,this);
- try {
- startTransport();
- } catch (SdlException e) {
- e.printStackTrace();
- }
-
- }
- }else if(_transport.getTransportType()==TransportType.BLUETOOTH
- && !_transport.getIsConnected()){
- if(cachedMultiConfig!=null){
- //We are in legacy mode, but just received a force connect. The router service should never be pointing us here if we are truely in legacy mode
- ComponentName tempCompName = SdlBroadcastReceiver.consumeQueuedRouterService();
- RouterServiceValidator vlad = new RouterServiceValidator(cachedMultiConfig.getContext(),tempCompName);
- if(vlad.validate()){
- cachedMultiConfig.setService(tempCompName);
- //We are not connected yet so we should be able to close down
- _transport.disconnect(); //This will force us into the
- }else{
- //Log.d(TAG, "Router service not trusted during force connect. Ignoring.");
- return;
- }
- }else{
- //Log.i(TAG, "No cached multiplexing config, ignoring");
- //_transport.disconnect();
- return;
- }
- DebugTool.logWarning(TAG, "Using own transport, but not connected. Attempting to join multiplexing");
- }else{
- DebugTool.logWarning(TAG, "Currently in legacy mode connected to own transport service. Nothing will take place on trnasport cycle");
- }
- }
-
- public static void enableLegacyMode(boolean enable, TransportType type){
- synchronized(TRANSPORT_REFERENCE_LOCK) {
- if(enable){
- legacyTransportRequest = type;
- }else{
- legacyTransportRequest = null;
- }
- }
- }
- public static boolean isLegacyModeEnabled(){
- synchronized(TRANSPORT_REFERENCE_LOCK) {
- return (legacyTransportRequest!=null);
- }
- }
-
- @Override
- public void onProtocolSessionEndedNACKed(SessionType sessionType,
- byte sessionID, String correlationID) {
- _connectionListener.onProtocolSessionEndedNACKed(sessionType, sessionID, correlationID);
-
- }
-
- @Override
- public void onProtocolServiceDataACK(SessionType serviceType, int dataSize, byte sessionID) {
- _connectionListener.onProtocolServiceDataACK(serviceType, dataSize, sessionID);
- }
-}
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java b/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java
index 91cde0e3c..3c5c063c7 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,832 +1,341 @@
-/*
- * 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.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 = new PipedInputStream((PipedOutputStream) os, BUFF_READ_SIZE);
- 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) 2017-2020 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.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.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.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.concurrent.CopyOnWriteArrayList;
+
+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) {
+ 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) {
+ 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..49e25b242 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);
+ this.session = new SdlSession(sdlConnectionListener, (TCPTransportConfig) _transportConfig);
} else {
- this.session = SdlSession.createSession((byte) getProtocolVersion().getMajor(), sdlConnectionListener, _transportConfig);
+ DebugTool.logError(TAG,"Unable to create session for transport type");
}
}
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java b/android/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java
deleted file mode 100644
index 6b4a2b467..000000000
--- a/android/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.smartdevicelink.protocol;
-
-
-import com.smartdevicelink.protocol.WiProProtocol.MessageFrameAssembler;
-import com.smartdevicelink.protocol.enums.SessionType;
-
-import java.util.List;
-
-/**
- * @see SdlProtocol
- */
-@Deprecated
-public abstract class AbstractProtocol {
- private static final String SDL_LIB_TRACE_KEY = "42baba60-eb57-11df-98cf-0800200c9a66";
-
- private IProtocolListener _protocolListener = null;
- //protected IProtocolListener ProtocolListener() { return _protocolListener; }
-
- // Lock to ensure all frames are sent uninterupted
- private Object _frameLock = new Object();
-
- // Caller must provide a non-null IProtocolListener interface reference.
- public AbstractProtocol(IProtocolListener protocolListener) {
- if (protocolListener == null) {
- throw new IllegalArgumentException("Provided protocol listener interface reference is null");
- } // end-if
-
- _protocolListener = protocolListener;
- } // end-ctor
-
-
- // This method receives a protocol message (e.g. RPC, BULK, etc.) and processes
- // it for transmission over the transport. The results of this processing will
- // be sent to the onProtocolMessageBytesToSend() method on protocol listener
- // interface. Note that the ProtocolMessage itself contains information
- // about the type of message (e.g. RPC, BULK, etc.) and the protocol session
- // over which to send the message, etc.
- public abstract void SendMessage(ProtocolMessage msg);
-
- public abstract int getMtu();
- public abstract long getMtu(SessionType type);
-
- public abstract void handlePacketReceived(SdlPacket packet);
-
- // This method starts a protocol session. A corresponding call to the protocol
- // listener onProtocolSessionStarted() method will be made when the protocol
- // session has been established.
- public abstract void StartProtocolSession(SessionType sessionType);
-
- public abstract void StartProtocolService(SessionType sessionType, byte sessionID, boolean isEncrypted);
-
- public abstract void EndProtocolService(SessionType serviceType, byte sessionID);
- // This method ends a protocol session. A corresponding call to the protocol
- // listener onProtocolSessionEnded() method will be made when the protocol
- // session has ended.
- public abstract void EndProtocolSession(SessionType sessionType, byte sessionID, int hashID);
-
- // TODO REMOVE
- // This method sets the interval at which heartbeat protocol messages will be
- // sent to SDL.
- public abstract void SetHeartbeatSendInterval(int heartbeatSendInterval_ms);
-
- // This method sets the interval at which heartbeat protocol messages are
- // expected to be received from SDL.
- public abstract void SetHeartbeatReceiveInterval(int heartbeatReceiveInterval_ms);
-
- public abstract void SendHeartBeat(byte sessionID);
-
- public abstract void SendHeartBeatACK(byte sessionID);
-
- // This method is called whenever the protocol receives a complete frame
- protected void handleProtocolFrameReceived(SdlPacket packet, MessageFrameAssembler assembler) {
- //FIXME SdlTrace.logProtocolEvent(InterfaceActivityDirection.Receive, header, data,
- // 0, packet.dataSize, SDL_LIB_TRACE_KEY);
-
- assembler.handleFrame(packet);
- }
-
- private synchronized void resetOutgoingHeartbeat(SessionType sessionType, byte sessionID) {
- if (_protocolListener != null) {
- _protocolListener.onResetOutgoingHeartbeat(sessionType,sessionID);
- }
- }
-
- private synchronized void resetIncomingHeartbeat(SessionType sessionType, byte sessionID) {
- if (_protocolListener != null) {
- _protocolListener.onResetIncomingHeartbeat(sessionType,sessionID);
- }
- }
-
- // This method is called whenever a protocol has an entire frame to send
- /**
- * SdlPacket should have included payload at this point.
- * @param header
- */
- protected void handlePacketToSend(SdlPacket header) {
- //FIXME SdlTrace.logProtocolEvent(InterfaceActivityDirection.Transmit, header, data,
- // offset, length, SDL_LIB_TRACE_KEY);
- if(header == null){
- return;
- }
-
- resetOutgoingHeartbeat(SessionType.valueOf((byte)header.getServiceType()), (byte)header.getSessionId());
-
- synchronized(_frameLock) {
-
- //byte[] frameHeader = header.constructPacket();
- _protocolListener.onProtocolMessageBytesToSend(header);
-
- }
- }
-
-
- // This method handles received protocol messages.
- protected void handleProtocolMessageReceived(ProtocolMessage message) {
- _protocolListener.onProtocolMessageReceived(message);
- }
-
- // This method handles the end of a protocol session. A callback is
- // sent to the protocol listener.
- protected void handleProtocolSessionEndedNACK(SessionType sessionType,
- byte sessionID, String correlationID) {
- _protocolListener.onProtocolSessionEndedNACKed(sessionType, sessionID, correlationID);
- }
-
- // This method handles the end of a protocol session. A callback is
- // sent to the protocol listener.
- protected void handleProtocolSessionEnded(SessionType sessionType,
- byte sessionID, String correlationID) {
- _protocolListener.onProtocolSessionEnded(sessionType, sessionID, correlationID);
- }
-
- // This method handles the startup of a protocol session. A callback is sent
- // to the protocol listener.
- protected void handleProtocolSessionStarted(SessionType sessionType,
- byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) {
- _protocolListener.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID, isEncrypted);
- }
-
- protected void handleProtocolSessionNACKed(SessionType sessionType,
- byte sessionID, byte version, String correlationID, List<String> rejectedParams) {
- _protocolListener.onProtocolSessionNACKed(sessionType, sessionID, version, correlationID, rejectedParams);
- }
-
- // This method handles protocol errors. A callback is sent to the protocol
- // listener.
- protected void handleProtocolError(String string, Exception ex) {
- _protocolListener.onProtocolError(string, ex);
- }
- protected void handleProtocolHeartbeat(SessionType sessionType, byte sessionID) {
- SendHeartBeatACK(sessionID);
- _protocolListener.onProtocolHeartbeat(sessionType, sessionID);
- }
- protected void handleProtocolHeartbeatACK(SessionType sessionType, byte sessionID) {
- _protocolListener.onProtocolHeartbeatACK(sessionType, sessionID);
- }
- protected void handleProtocolServiceDataACK(SessionType sessionType, int dataSize, byte sessionID) {
- _protocolListener.onProtocolServiceDataACK(sessionType, dataSize, sessionID);
- }
- protected void onResetIncomingHeartbeat(SessionType sessionType, byte sessionID) {
- resetIncomingHeartbeat(sessionType, sessionID);
- }
-
-} // end-class
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/protocol/WiProProtocol.java b/android/sdl_android/src/main/java/com/smartdevicelink/protocol/WiProProtocol.java
deleted file mode 100644
index ad887929a..000000000
--- a/android/sdl_android/src/main/java/com/smartdevicelink/protocol/WiProProtocol.java
+++ /dev/null
@@ -1,696 +0,0 @@
-/*
- * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.smartdevicelink.protocol;
-
-import com.smartdevicelink.SdlConnection.SdlConnection;
-import com.smartdevicelink.SdlConnection.SdlSession;
-import com.smartdevicelink.exception.SdlException;
-import com.smartdevicelink.exception.SdlExceptionCause;
-import com.smartdevicelink.protocol.enums.ControlFrameTags;
-import com.smartdevicelink.protocol.enums.FrameDataControlFrameType;
-import com.smartdevicelink.protocol.enums.FrameType;
-import com.smartdevicelink.protocol.enums.MessageType;
-import com.smartdevicelink.protocol.enums.SessionType;
-import com.smartdevicelink.proxy.rpc.ImageResolution;
-import com.smartdevicelink.proxy.rpc.VideoStreamingFormat;
-import com.smartdevicelink.proxy.rpc.enums.VideoStreamingCodec;
-import com.smartdevicelink.proxy.rpc.enums.VideoStreamingProtocol;
-import com.smartdevicelink.security.SdlSecurityBase;
-import com.smartdevicelink.streaming.video.VideoStreamingParameters;
-import com.smartdevicelink.util.BitConverter;
-import com.smartdevicelink.util.DebugTool;
-import com.smartdevicelink.util.Version;
-
-import java.io.ByteArrayOutputStream;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-
-/**
- * @see SdlProtocol
- */
-@Deprecated
-public class WiProProtocol extends AbstractProtocol {
- private static final String TAG = "WiProProtocol";
- private final static String FailurePropagating_Msg = "Failure propagating ";
- //If increasing MAX PROTOCOL VERSION major version, make sure to alter it in SdlPsm
- public static final Version MAX_PROTOCOL_VERSION = new Version("5.0.0");
- private Version protocolVersion = new Version("1.0.0");
- byte _version = 1;
-
- public static final int V1_V2_MTU_SIZE = 1500;
- public static final int V3_V4_MTU_SIZE = 131072;
- public static final int V1_HEADER_SIZE = 8;
- public static final int V2_HEADER_SIZE = 12;
- private static int HEADER_SIZE = 8;
- private static int TLS_MAX_RECORD_SIZE = 16384;
-
- int hashID = 0;
- int messageID = 0;
- SdlConnection sdlconn = null;
-
- @SuppressWarnings("unused")
- private int _heartbeatSendInterval_ms = 0;
- @SuppressWarnings("unused")
- private int _heartbeatReceiveInterval_ms = 0;
-
- Hashtable<Integer, MessageFrameAssembler> _assemblerForMessageID = new Hashtable<Integer, MessageFrameAssembler>();
- Hashtable<Byte, Hashtable<Integer, MessageFrameAssembler>> _assemblerForSessionID = new Hashtable<Byte, Hashtable<Integer, MessageFrameAssembler>>();
- Hashtable<Byte, Object> _messageLocks = new Hashtable<Byte, Object>();
- private HashMap<SessionType, Long> mtus = new HashMap<SessionType,Long>();
-
- // Hide no-arg ctor
- private WiProProtocol() {
- super(null);
- } // end-ctor
-
-
- public WiProProtocol(IProtocolListener protocolListener) {
- super(protocolListener);
-
- if (protocolListener instanceof SdlConnection)
- {
- sdlconn = (SdlConnection) protocolListener;
- }
- mtus.put(SessionType.RPC, new Long(V1_V2_MTU_SIZE - HEADER_SIZE));
- } // end-ctor
-
- /**
- * Retrieves the max payload size for a packet to be sent to the module
- * @return the max transfer unit
- */
- public int getMtu(){
- return mtus.get(SessionType.RPC).intValue();
- }
-
- public long getMtu(SessionType type){
- Long mtu = mtus.get(type);
- if(mtu == null){
- mtu = mtus.get(SessionType.RPC);
- }
- return mtu;
- }
-
-
- /**
- * Use getProtocolVersion() or getMajorVersionByte instead.<br>
- * Returns the Major version of the currently used protocol version
- */
- @Deprecated
- public byte getVersion() {
- return getMajorVersionByte();
- }
-
- public Version getProtocolVersion(){
- return this.protocolVersion;
- }
- public byte getMajorVersionByte(){
- if(_version == 1){
- _version = new Integer(this.protocolVersion.getMajor()).byteValue();
- }
- return _version;
-
- }
-
- /**
- * This method will set the major protocol version that we should use. It will also set the default MTU based on version.
- * @param version
- */
- public void setVersion(byte version) {
- if (version > 5) {
- this.protocolVersion = new Version("5.0.0"); //protect for future, proxy only supports v5 or lower
- HEADER_SIZE = 12;
- mtus.put(SessionType.RPC,new Long(V3_V4_MTU_SIZE) );
- } else if (version == 5) {
- this.protocolVersion = new Version("5.0.0");
- HEADER_SIZE = 12;
- mtus.put(SessionType.RPC,new Long(V3_V4_MTU_SIZE) );
- }else if (version == 4) {
- this.protocolVersion = new Version("4.0.0");
- HEADER_SIZE = 12;
- mtus.put(SessionType.RPC,new Long(V3_V4_MTU_SIZE) ); //versions 4 supports 128k MTU
- } else if (version == 3) {
- this.protocolVersion = new Version("3.0.0");
- HEADER_SIZE = 12;
- mtus.put(SessionType.RPC,new Long(V3_V4_MTU_SIZE) ); //versions 3 supports 128k MTU
- } else if (version == 2) {
- this.protocolVersion = new Version("2.0.0");
- HEADER_SIZE = 12;
- mtus.put(SessionType.RPC,new Long(V1_V2_MTU_SIZE - HEADER_SIZE) );
- } else if (version == 1){
- this.protocolVersion = new Version("1.0.0");
- HEADER_SIZE = 8;
- mtus.put(SessionType.RPC,new Long(V1_V2_MTU_SIZE - HEADER_SIZE) );
- }
- }
-
- public void StartProtocolSession(SessionType sessionType) {
- SdlPacket header = SdlPacketFactory.createStartSession(sessionType, 0x00, getMajorVersionByte(), (byte) 0x00, false);
- if(sessionType.equals(SessionType.RPC)){ // check for RPC session
- header.putTag(ControlFrameTags.RPC.StartService.PROTOCOL_VERSION, MAX_PROTOCOL_VERSION.toString());
- }
- handlePacketToSend(header);
- } // end-method
-
- private void sendStartProtocolSessionACK(SessionType sessionType, byte sessionID) {
- SdlPacket header = SdlPacketFactory.createStartSessionACK(sessionType, sessionID, 0x00, getMajorVersionByte());
- handlePacketToSend(header);
- } // end-method
-
- public void EndProtocolSession(SessionType sessionType, byte sessionID, int hashId) {
- SdlPacket header;
- if (sessionType.equals(SessionType.RPC)) { // check for RPC session
- header = SdlPacketFactory.createEndSession(sessionType, sessionID, hashID, getMajorVersionByte(), hashID);
- }else{ //Any other service type we don't include the hash id
- header = SdlPacketFactory.createEndSession(sessionType, sessionID, hashID, getMajorVersionByte(), new byte[0]);
- }
- handlePacketToSend(header);
-
- } // end-method
-
- public void SendMessage(ProtocolMessage protocolMsg) {
- SessionType sessionType = protocolMsg.getSessionType();
- byte sessionID = protocolMsg.getSessionID();
-
- byte[] data = null;
- if (protocolVersion.getMajor() > 1 && sessionType != SessionType.NAV && sessionType != SessionType.PCM) {
- if (sessionType.eq(SessionType.CONTROL)) {
- final byte[] secureData = protocolMsg.getData().clone();
- data = new byte[HEADER_SIZE + secureData.length];
-
- final BinaryFrameHeader binFrameHeader =
- SdlPacketFactory.createBinaryFrameHeader(protocolMsg.getRPCType(),protocolMsg.getFunctionID(), protocolMsg.getCorrID(), 0);
- System.arraycopy(binFrameHeader.assembleHeaderBytes(), 0, data, 0, HEADER_SIZE);
- System.arraycopy(secureData, 0, data,HEADER_SIZE, secureData.length);
- }
- else if (protocolMsg.getBulkData() != null) {
- data = new byte[12 + protocolMsg.getJsonSize() + protocolMsg.getBulkData().length];
- sessionType = SessionType.BULK_DATA;
- } else {
- data = new byte[12 + protocolMsg.getJsonSize()];
- }
- if (!sessionType.eq(SessionType.CONTROL)) {
- BinaryFrameHeader binFrameHeader = SdlPacketFactory.createBinaryFrameHeader(protocolMsg.getRPCType(), protocolMsg.getFunctionID(), protocolMsg.getCorrID(), protocolMsg.getJsonSize());
- System.arraycopy(binFrameHeader.assembleHeaderBytes(), 0, data, 0, 12);
- System.arraycopy(protocolMsg.getData(), 0, data, 12, protocolMsg.getJsonSize());
- if (protocolMsg.getBulkData() != null) {
- System.arraycopy(protocolMsg.getBulkData(), 0, data, 12 + protocolMsg.getJsonSize(), protocolMsg.getBulkData().length);
- }
- }
- } else {
- data = protocolMsg.getData();
- }
-
- if (sdlconn != null && protocolMsg.getPayloadProtected())
- {
- if (data != null && data.length > 0) {
- SdlSession session = sdlconn.findSessionById(sessionID);
-
- if (session == null)
- return;
-
- byte[] dataToRead = new byte[TLS_MAX_RECORD_SIZE];
- SdlSecurityBase sdlSec = session.getSdlSecurity();
- if (sdlSec == null)
- return;
-
- Integer iNumBytes = sdlSec.encryptData(data, dataToRead);
- if ((iNumBytes == null) || (iNumBytes <= 0))
- return;
-
- byte[] encryptedData = new byte[iNumBytes];
- System.arraycopy(dataToRead, 0, encryptedData, 0, iNumBytes);
- data = encryptedData;
- }
- }
-
- // Get the message lock for this protocol session
- Object messageLock = _messageLocks.get(sessionID);
- if (messageLock == null) {
- handleProtocolError("Error sending protocol message to SDL.",
- new SdlException("Attempt to send protocol message prior to startSession ACK.", SdlExceptionCause.SDL_UNAVAILABLE));
- return;
- }
-
- synchronized(messageLock) {
- if (data.length > getMtu(sessionType)) {
-
- messageID++;
-
- // Assemble first frame.
- Long mtu = getMtu(sessionType);
- int frameCount = new Long(data.length / mtu).intValue();
- if (data.length % mtu > 0) {
- frameCount++;
- }
- //byte[] firstFrameData = new byte[HEADER_SIZE];
- byte[] firstFrameData = new byte[8];
- // First four bytes are data size.
- System.arraycopy(BitConverter.intToByteArray(data.length), 0, firstFrameData, 0, 4);
- // Second four bytes are frame count.
- System.arraycopy(BitConverter.intToByteArray(frameCount), 0, firstFrameData, 4, 4);
-
- SdlPacket firstHeader = SdlPacketFactory.createMultiSendDataFirst(sessionType, sessionID, messageID, getMajorVersionByte(),firstFrameData,protocolMsg.getPayloadProtected());
- firstHeader.setPriorityCoefficient(1+protocolMsg.priorityCoefficient);
- //Send the first frame
- handlePacketToSend(firstHeader);
-
- int currentOffset = 0;
- byte frameSequenceNumber = 0;
-
- for (int i = 0; i < frameCount; i++) {
- if (i < (frameCount - 1)) {
- ++frameSequenceNumber;
- if (frameSequenceNumber ==
- SdlPacket.FRAME_INFO_FINAL_CONNESCUTIVE_FRAME) {
- // we can't use 0x00 as frameSequenceNumber, because
- // it's reserved for the last frame
- ++frameSequenceNumber;
- }
- } else {
- frameSequenceNumber = SdlPacket.FRAME_INFO_FINAL_CONNESCUTIVE_FRAME;
- } // end-if
-
- int bytesToWrite = data.length - currentOffset;
- if (bytesToWrite > mtu) {
- bytesToWrite = mtu.intValue();
- }
- SdlPacket consecHeader = SdlPacketFactory.createMultiSendDataRest(sessionType, sessionID, bytesToWrite, frameSequenceNumber , messageID, getMajorVersionByte(),data, currentOffset, bytesToWrite, protocolMsg.getPayloadProtected());
- consecHeader.setPriorityCoefficient(i+2+protocolMsg.priorityCoefficient);
- handlePacketToSend(consecHeader);
- currentOffset += bytesToWrite;
- }
- } else {
- messageID++;
- SdlPacket header = SdlPacketFactory.createSingleSendData(sessionType, sessionID, data.length, messageID, getMajorVersionByte(),data, protocolMsg.getPayloadProtected());
- header.setPriorityCoefficient(protocolMsg.priorityCoefficient);
- handlePacketToSend(header);
- }
- }
- }
-
- public void handlePacketReceived(SdlPacket packet){
- //Check for a version difference
- if (getMajorVersionByte() == 1) {
- setVersion((byte)packet.version);
- }
-
- MessageFrameAssembler assembler = getFrameAssemblerForFrame(packet);
- assembler.handleFrame(packet);
-
- onResetIncomingHeartbeat(SessionType.valueOf((byte)packet.getServiceType()), (byte)packet.getSessionId());
-
- }
-
-
-
- protected MessageFrameAssembler getFrameAssemblerForFrame(SdlPacket packet) {
- Integer iSessionId = Integer.valueOf(packet.getSessionId());
- Byte bySessionId = iSessionId.byteValue();
-
- Hashtable<Integer, MessageFrameAssembler> hashSessionID = _assemblerForSessionID.get(bySessionId);
- if (hashSessionID == null) {
- hashSessionID = new Hashtable<Integer, MessageFrameAssembler>();
- _assemblerForSessionID.put(bySessionId, hashSessionID);
- } // end-if
-
- MessageFrameAssembler ret = (MessageFrameAssembler) _assemblerForMessageID.get(Integer.valueOf(packet.getMessageId()));
- if (ret == null) {
- ret = new MessageFrameAssembler();
- _assemblerForMessageID.put(Integer.valueOf(packet.getMessageId()), ret);
- } // end-if
-
- return ret;
- } // end-method
-
- protected class MessageFrameAssembler {
- protected boolean hasFirstFrame = false;
- protected ByteArrayOutputStream accumulator = null;
- protected int totalSize = 0;
- protected int framesRemaining = 0;
-
- protected void handleFirstDataFrame(SdlPacket packet) {
- //The message is new, so let's figure out how big it is.
- hasFirstFrame = true;
- totalSize = BitConverter.intFromByteArray(packet.payload, 0) - HEADER_SIZE;
- framesRemaining = BitConverter.intFromByteArray(packet.payload, 4);
- try {
- accumulator = new ByteArrayOutputStream(totalSize);
- }catch(OutOfMemoryError e){
- DebugTool.logError(TAG, "OutOfMemory error", e); //Garbled bits were received
- accumulator = null;
- }
- }
-
- protected void handleRemainingFrame(SdlPacket packet) {
- accumulator.write(packet.payload, 0, (int)packet.getDataSize());
- notifyIfFinished(packet);
- }
-
- protected void notifyIfFinished(SdlPacket packet) {
- //if (framesRemaining == 0) {
- if (packet.getFrameType() == FrameType.Consecutive && packet.getFrameInfo() == 0x0)
- {
- ProtocolMessage message = new ProtocolMessage();
- message.setPayloadProtected(packet.isEncrypted());
- message.setSessionType(SessionType.valueOf((byte)packet.getServiceType()));
- message.setSessionID((byte)packet.getSessionId());
- //If it is WiPro 2.0 it must have binary header
- if (protocolVersion.getMajor() > 1) {
- BinaryFrameHeader binFrameHeader = BinaryFrameHeader.
- parseBinaryHeader(accumulator.toByteArray());
- if(binFrameHeader == null) {
- return;
- }
- message.setVersion(getMajorVersionByte());
- message.setRPCType(binFrameHeader.getRPCType());
- message.setFunctionID(binFrameHeader.getFunctionID());
- message.setCorrID(binFrameHeader.getCorrID());
- if (binFrameHeader.getJsonSize() > 0) message.setData(binFrameHeader.getJsonData());
- if (binFrameHeader.getBulkData() != null) message.setBulkData(binFrameHeader.getBulkData());
- } else{
- message.setData(accumulator.toByteArray());
- }
-
- _assemblerForMessageID.remove(packet.getMessageId());
-
- try {
- handleProtocolMessageReceived(message);
- } catch (Exception excp) {
- DebugTool.logError(TAG, FailurePropagating_Msg + "onProtocolMessageReceived: " + excp.toString(), excp);
- } // end-catch
-
- hasFirstFrame = false;
- accumulator = null;
- } // end-if
- } // end-method
-
- protected void handleMultiFrameMessageFrame(SdlPacket packet) {
- if (packet.getFrameType() == FrameType.First){
- handleFirstDataFrame(packet);
- }
- else{
- if(accumulator != null)
- handleRemainingFrame(packet);
- }
-
- } // end-method
-
- protected void handleFrame(SdlPacket packet) {
-
- if (packet.getPayload() != null && packet.getDataSize() > 0 && packet.isEncrypted() )
- {
- if (sdlconn != null)
- {
- SdlSession session = sdlconn.findSessionById((byte)packet.getSessionId());
-
- if (session == null)
- return;
-
- SdlSecurityBase sdlSec = session.getSdlSecurity();
- byte[] dataToRead = new byte[4096];
-
- Integer iNumBytes = sdlSec.decryptData(packet.getPayload(), dataToRead);
- if ((iNumBytes == null) || (iNumBytes <= 0))
- return;
-
- byte[] decryptedData = new byte[iNumBytes];
- System.arraycopy(dataToRead, 0, decryptedData, 0, iNumBytes);
- packet.payload = decryptedData;
- }
- }
-
- if (packet.getFrameType().equals(FrameType.Control)) {
- handleControlFrame(packet);
- } else {
- // Must be a form of data frame (single, first, consecutive, etc.)
- if ( packet.getFrameType() == FrameType.First
- || packet.getFrameType() == FrameType.Consecutive
- ) {
- handleMultiFrameMessageFrame(packet);
- } else {
- handleSingleFrameMessageFrame(packet);
- }
- } // end-if
- } // end-method
-
- private void handleProtocolHeartbeatACK(SdlPacket packet) {
- WiProProtocol.this.handleProtocolHeartbeatACK(SessionType.valueOf((byte)packet.getServiceType()),(byte)packet.getSessionId());
- } // end-method
- private void handleProtocolHeartbeat(SdlPacket packet) {
- WiProProtocol.this.handleProtocolHeartbeat(SessionType.valueOf((byte)packet.getServiceType()),(byte)packet.getSessionId());
- } // end-method
-
- private void handleControlFrame(SdlPacket packet) {
- Integer frameTemp = Integer.valueOf(packet.getFrameInfo());
- Byte frameInfo = frameTemp.byteValue();
-
- SessionType serviceType = SessionType.valueOf((byte)packet.getServiceType());
-
- if (frameInfo == FrameDataControlFrameType.Heartbeat.getValue()) {
- handleProtocolHeartbeat(packet);
- }
- if (frameInfo == FrameDataControlFrameType.HeartbeatACK.getValue()) {
- handleProtocolHeartbeatACK(packet);
- }
- else if (frameInfo == FrameDataControlFrameType.StartSession.getValue()) {
- sendStartProtocolSessionACK(serviceType, (byte)packet.getSessionId());
- } else if (frameInfo == FrameDataControlFrameType.StartSessionACK.getValue()) {
- // Use this sessionID to create a message lock
- Object messageLock = _messageLocks.get(packet.getSessionId());
- if (messageLock == null) {
- messageLock = new Object();
- _messageLocks.put((byte)packet.getSessionId(), messageLock);
- }
- if(packet.version >= 5){
- String mtuTag = null;
- if(serviceType.equals(SessionType.RPC)){
- mtuTag = ControlFrameTags.RPC.StartServiceACK.MTU;
- }else if(serviceType.equals(SessionType.PCM)){
- mtuTag = ControlFrameTags.Audio.StartServiceACK.MTU;
- }else if(serviceType.equals(SessionType.NAV)){
- mtuTag = ControlFrameTags.Video.StartServiceACK.MTU;
- }
- Object mtu = packet.getTag(mtuTag);
- if(mtu!=null){
- mtus.put(serviceType,(Long) packet.getTag(mtuTag));
- }
- if(serviceType.equals(SessionType.RPC)){
- hashID = (Integer) packet.getTag(ControlFrameTags.RPC.StartServiceACK.HASH_ID);
- Object version = packet.getTag(ControlFrameTags.RPC.StartServiceACK.PROTOCOL_VERSION);
- if(version!=null){
- //At this point we have confirmed the negotiated version between the module and the proxy
- protocolVersion = new Version((String)version);
- }
- }else if(serviceType.equals(SessionType.NAV)){
- SdlSession session = sdlconn.findSessionById((byte) packet.sessionId);
- if(session != null) {
- ImageResolution acceptedResolution = new ImageResolution();
- VideoStreamingFormat acceptedFormat = new VideoStreamingFormat();
- acceptedResolution.setResolutionHeight((Integer) packet.getTag(ControlFrameTags.Video.StartServiceACK.HEIGHT));
- acceptedResolution.setResolutionWidth((Integer) packet.getTag(ControlFrameTags.Video.StartServiceACK.WIDTH));
- acceptedFormat.setCodec(VideoStreamingCodec.valueForString((String) packet.getTag(ControlFrameTags.Video.StartServiceACK.VIDEO_CODEC)));
- acceptedFormat.setProtocol(VideoStreamingProtocol.valueForString((String) packet.getTag(ControlFrameTags.Video.StartServiceACK.VIDEO_PROTOCOL)));
- VideoStreamingParameters agreedVideoParams = session.getDesiredVideoParams();
- agreedVideoParams.setResolution(acceptedResolution);
- agreedVideoParams.setFormat(acceptedFormat);
- session.setAcceptedVideoParams(agreedVideoParams);
- }
- }
- }else{
- if (protocolVersion.getMajor() > 1){
- if (packet.payload!= null && packet.dataSize == 4){ //hashid will be 4 bytes in length
- hashID = BitConverter.intFromByteArray(packet.payload, 0);
- }
- }
- }
- handleProtocolSessionStarted(serviceType,(byte) packet.getSessionId(), getMajorVersionByte(), "", hashID, packet.isEncrypted());
-
- if(serviceType.equals(SessionType.RPC)
- && protocolVersion.isNewerThan(new Version(5,2,0)) >= 0){
- // This has to be done after the session has been established because
- // SdlConnection is just setup that way
- String authToken = (String)packet.getTag(ControlFrameTags.RPC.StartServiceACK.AUTH_TOKEN);
- if(authToken != null){
- sdlconn.onAuthTokenReceived(authToken, (byte)packet.getSessionId());
- }
- }
- } else if (frameInfo == FrameDataControlFrameType.StartSessionNACK.getValue()) {
- List<String> rejectedParams = null;
- if(packet.version >= 5){
- String rejectedTag = null;
- if(serviceType.equals(SessionType.RPC)){
- rejectedTag = ControlFrameTags.RPC.StartServiceNAK.REJECTED_PARAMS;
- }else if(serviceType.equals(SessionType.PCM)){
- rejectedTag = ControlFrameTags.Audio.StartServiceNAK.REJECTED_PARAMS;
- }else if(serviceType.equals(SessionType.NAV)){
- rejectedTag = ControlFrameTags.Video.StartServiceNAK.REJECTED_PARAMS;
- }
- rejectedParams = (List<String>) packet.getTag(rejectedTag);
- }
- if (serviceType.eq(SessionType.NAV) || serviceType.eq(SessionType.PCM)) {
- handleProtocolSessionNACKed(serviceType, (byte)packet.getSessionId(), getMajorVersionByte(), "", rejectedParams);
- } else {
- handleProtocolError("Got StartSessionNACK for protocol sessionID=" + packet.getSessionId(), null);
- }
- } else if (frameInfo == FrameDataControlFrameType.EndSession.getValue()) {
- if (protocolVersion.getMajor() > 1) {
- handleProtocolSessionEnded(serviceType, (byte)packet.getSessionId(), "");
- } else {
- handleProtocolSessionEnded(serviceType, (byte)packet.getSessionId(), "");
- }
- } else if (frameInfo == FrameDataControlFrameType.EndSessionACK.getValue()) {
- handleProtocolSessionEnded(serviceType, (byte)packet.getSessionId(), "");
- } else if (frameInfo == FrameDataControlFrameType.EndSessionNACK.getValue()) {
- if(packet.version >= 5){
- String rejectedTag = null;
- if(serviceType.equals(SessionType.RPC)){
- rejectedTag = ControlFrameTags.RPC.EndServiceNAK.REJECTED_PARAMS;
- }else if(serviceType.equals(SessionType.PCM)){
- rejectedTag = ControlFrameTags.Audio.EndServiceNAK.REJECTED_PARAMS;
- }else if(serviceType.equals(SessionType.NAV)){
- rejectedTag = ControlFrameTags.Video.EndServiceNAK.REJECTED_PARAMS;
- }
- List<String> rejectedParams = (List<String>) packet.getTag(rejectedTag);
- // TODO: Pass these back
- }
- handleProtocolSessionEndedNACK(serviceType, (byte)packet.getSessionId(), "");
- } else if (frameInfo == FrameDataControlFrameType.ServiceDataACK.getValue()) {
- if (packet.getPayload() != null && packet.getDataSize() == 4) //service data ack will be 4 bytes in length
- {
- int serviceDataAckSize = BitConverter.intFromByteArray(packet.getPayload(), 0);
- handleProtocolServiceDataACK(serviceType, serviceDataAckSize,(byte)packet.getSessionId ());
- }
- }
- _assemblerForMessageID.remove(packet.getMessageId());
- } // end-method
-
- private void handleSingleFrameMessageFrame(SdlPacket packet) {
- ProtocolMessage message = new ProtocolMessage();
- message.setPayloadProtected(packet.isEncrypted());
- SessionType serviceType = SessionType.valueOf((byte)packet.getServiceType());
- if (serviceType == SessionType.RPC) {
- message.setMessageType(MessageType.RPC);
- } else if (serviceType == SessionType.BULK_DATA) {
- message.setMessageType(MessageType.BULK);
- } // end-if
- message.setSessionType(serviceType);
- message.setSessionID((byte)packet.getSessionId());
- //If it is WiPro 2.0 it must have binary header
- boolean isControlService = message.getSessionType().equals(SessionType.CONTROL);
- if (protocolVersion.getMajor() > 1 && !isControlService) {
- BinaryFrameHeader binFrameHeader = BinaryFrameHeader.
- parseBinaryHeader(packet.payload);
- if(binFrameHeader == null) {
- return;
- }
- message.setVersion(getMajorVersionByte());
- message.setRPCType(binFrameHeader.getRPCType());
- message.setFunctionID(binFrameHeader.getFunctionID());
- message.setCorrID(binFrameHeader.getCorrID());
- if (binFrameHeader.getJsonSize() > 0){
- message.setData(binFrameHeader.getJsonData());
- }
- if (binFrameHeader.getBulkData() != null){
- message.setBulkData(binFrameHeader.getBulkData());
- }
- } else {
- message.setData(packet.payload);
- }
-
- _assemblerForMessageID.remove(packet.getMessageId());
-
- try {
- handleProtocolMessageReceived(message);
- } catch (Exception ex) {
- DebugTool.logError(TAG,FailurePropagating_Msg + "onProtocolMessageReceived: " + ex.toString(), ex);
- handleProtocolError(FailurePropagating_Msg + "onProtocolMessageReceived: ", ex);
- } // end-catch
- } // end-method
- } // end-class
-
- @Override
- public void StartProtocolService(SessionType sessionType, byte sessionID, boolean isEncrypted) {
- SdlPacket header = SdlPacketFactory.createStartSession(sessionType, 0x00, getMajorVersionByte(), sessionID, isEncrypted);
- if(sessionType.equals(SessionType.NAV)){
- SdlSession videoSession = sdlconn.findSessionById(sessionID);
- if(videoSession != null){
- ImageResolution desiredResolution = videoSession.getDesiredVideoParams().getResolution();
- VideoStreamingFormat desiredFormat = videoSession.getDesiredVideoParams().getFormat();
- if(desiredResolution != null){
- header.putTag(ControlFrameTags.Video.StartService.WIDTH, desiredResolution.getResolutionWidth());
- header.putTag(ControlFrameTags.Video.StartService.HEIGHT, desiredResolution.getResolutionHeight());
- }
- if(desiredFormat != null){
- header.putTag(ControlFrameTags.Video.StartService.VIDEO_CODEC, desiredFormat.getCodec().toString());
- header.putTag(ControlFrameTags.Video.StartService.VIDEO_PROTOCOL, desiredFormat.getProtocol().toString());
- }
- }
- }
- handlePacketToSend(header);
- }
-
- @Override
- public void SetHeartbeatSendInterval(int heartbeatSendInterval_ms) {
- _heartbeatSendInterval_ms = heartbeatSendInterval_ms;
-
- }
-
- @Override
- public void SetHeartbeatReceiveInterval(int heartbeatReceiveInterval_ms) {
- _heartbeatReceiveInterval_ms = heartbeatReceiveInterval_ms;
-
- }
-
- @Override
- public void SendHeartBeat(byte sessionID) {
- final SdlPacket heartbeat = SdlPacketFactory.createHeartbeat(SessionType.CONTROL, sessionID, getMajorVersionByte());
- handlePacketToSend(heartbeat);
- }
-
- @Override
- public void SendHeartBeatACK(byte sessionID) {
- final SdlPacket heartbeat = SdlPacketFactory.createHeartbeatACK(SessionType.CONTROL, sessionID, getMajorVersionByte());
- handlePacketToSend(heartbeat);
- }
-
- @Override
- public void EndProtocolService(SessionType serviceType, byte sessionID) {
- if(serviceType.equals(SessionType.RPC)){ //RPC session will close all other sessions so we want to make sure we use the correct EndProtocolSession method
- EndProtocolSession(serviceType,sessionID,hashID);
- }else {
- SdlPacket header = SdlPacketFactory.createEndSession(serviceType, sessionID, hashID, getMajorVersionByte(), new byte[0]);
- handlePacketToSend(header);
- }
- }
-
-} // end-class \ No newline at end of file
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java b/android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java
index 348e6d89f..7c9915456 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;
@@ -149,6 +148,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;
@@ -620,7 +620,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{
@@ -679,11 +679,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();
@@ -1646,11 +1646,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"));
}
}
@@ -1684,7 +1684,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;
@@ -4054,7 +4054,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);
@@ -4075,13 +4075,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())) {
@@ -4111,7 +4111,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);
@@ -4121,13 +4121,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())) {
@@ -5018,7 +5018,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) {
@@ -5039,7 +5039,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) {
@@ -5062,18 +5062,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> {
@@ -5152,7 +5152,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;
@@ -5200,7 +5200,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;
}
@@ -5282,7 +5282,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;
@@ -5315,7 +5315,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;
}
@@ -5380,7 +5381,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;
}
@@ -5417,7 +5418,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();
@@ -5436,7 +5437,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
*/
@SuppressWarnings("unused")
public boolean pauseVideoStream() {
- return sdlSession != null && sdlSession.pauseVideoStream();
+ return false;//sdlSession != null && sdlSession.pauseVideoStream();
}
/**
@@ -5445,7 +5446,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
*/
@SuppressWarnings("unused")
public boolean resumeVideoStream() {
- return sdlSession != null && sdlSession.resumeVideoStream();
+ return false;//sdlSession != null && sdlSession.resumeVideoStream();
}
/**
@@ -5476,8 +5477,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;
}
@@ -5626,7 +5627,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
public void startEncoder () {
if (sdlSession == null || !sdlSession.getIsConnected()) return;
- sdlSession.startEncoder();
+ //sdlSession.startEncoder();
}
/**
@@ -5636,7 +5637,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
public void releaseEncoder() {
if (sdlSession == null || !sdlSession.getIsConnected()) return;
- sdlSession.releaseEncoder();
+ //sdlSession.releaseEncoder();
}
/**
@@ -5646,7 +5647,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(){
@@ -5727,7 +5728,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();
@@ -5755,7 +5756,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();
@@ -5774,7 +5775,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
*/
@SuppressWarnings("unused")
public boolean pauseAudioStream() {
- return sdlSession != null && sdlSession.pauseAudioStream();
+ return false;//sdlSession != null && sdlSession.pauseAudioStream();
}
/**
@@ -5783,7 +5784,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() {
@@ -5868,7 +5869,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
@@ -5877,7 +5878,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);
}
}
@@ -8409,7 +8410,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/android/sdl_android/src/main/java/com/smartdevicelink/streaming/StreamPacketizer.java b/android/sdl_android/src/main/java/com/smartdevicelink/streaming/StreamPacketizer.java
index 38164270b..db02be687 100644
--- a/android/sdl_android/src/main/java/com/smartdevicelink/streaming/StreamPacketizer.java
+++ b/android/sdl_android/src/main/java/com/smartdevicelink/streaming/StreamPacketizer.java
@@ -31,7 +31,6 @@
*/
package com.smartdevicelink.streaming;
-import com.smartdevicelink.SdlConnection.SdlConnection;
import com.smartdevicelink.SdlConnection.SdlSession;
import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.protocol.ProtocolMessage;
@@ -66,7 +65,6 @@ public class StreamPacketizer extends AbstractPacketizer implements IVideoStream
// a limit of the buffer size, we avoid buffer overflows when underlying transport is too slow.
private static final int MAX_QUEUE_SIZE = 256 * 1024;
- public SdlConnection sdlConnection = null; //TODO remove completely
private Object mPauseLock;
private boolean mPaused;
private boolean isServiceProtected = false;
@@ -185,13 +183,7 @@ public class StreamPacketizer extends AbstractPacketizer implements IVideoStream
}
finally
{
- if(_session == null) {
- if (sdlConnection != null) {
- sdlConnection.endService(_serviceType, _rpcSessionID);
- }
- }else{
- _session.endService(_serviceType,_rpcSessionID);
- }
+ _session.endService(_serviceType, _rpcSessionID);
}
}
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/BTTransport.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/BTTransport.java
deleted file mode 100644
index f86a3f062..000000000
--- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/BTTransport.java
+++ /dev/null
@@ -1,586 +0,0 @@
-/*
- * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.smartdevicelink.transport;
-
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothServerSocket;
-import android.bluetooth.BluetoothSocket;
-import android.os.Build;
-import android.os.Build.VERSION;
-
-import com.smartdevicelink.SdlConnection.SdlConnection;
-import com.smartdevicelink.exception.SdlException;
-import com.smartdevicelink.exception.SdlExceptionCause;
-import com.smartdevicelink.protocol.SdlPacket;
-import com.smartdevicelink.trace.SdlTrace;
-import com.smartdevicelink.trace.enums.InterfaceActivityDirection;
-import com.smartdevicelink.transport.enums.TransportType;
-import com.smartdevicelink.util.DebugTool;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.reflect.Field;
-import java.util.UUID;
-
-/**
- * Bluetooth Transport Implementation. This transport advertises its existence to SDL by publishing an SDP record and waiting for an incoming connection from SDL. Connection is verified by checking for the SDL UUID. For more detailed information please refer to the <a href="#bluetoothTransport">Bluetooth Transport Guide</a>.
- *
- */
-@Deprecated
-public class BTTransport extends SdlTransport {
- private static final String TAG = "BTTransport";
- //936DA01F9ABD4D9D80C702AF85C822A8
- private final static UUID SDL_V4_MOBILE_APPLICATION_SVC_CLASS = new UUID(0x936DA01F9ABD4D9DL, 0x80C702AF85C822A8L);
-
- private static final String SDL_LIB_TRACE_KEY = "42baba60-eb57-11df-98cf-0800200c9a66";
-
- private static final int READ_BUFFER_SIZE = 4096;
-
- private BluetoothAdapter _adapter = null;
- private BluetoothSocket _activeSocket = null;
- private UUID _listeningServiceUUID = SDL_V4_MOBILE_APPLICATION_SVC_CLASS;
- private BluetoothAdapterMonitor _bluetoothAdapterMonitor = null;
- private TransportReaderThread _transportReader = null;
- private OutputStream _output = null;
- private BluetoothServerSocket _serverSocket = null;
-
- private String sComment = "";
- private boolean bKeepSocketActive = true;
-
- // Boolean to monitor if the transport is in a disconnecting state
- private boolean _disconnecting = false;
-
- private final Object DISCONNECT_LOCK = new Object();
-
- public BTTransport(ITransportListener transportListener) {
- super(transportListener);
- } // end-ctor
-
- public BTTransport(ITransportListener transportListener, boolean bKeepSocket) {
- super(transportListener);
- bKeepSocketActive = bKeepSocket;
- } // end-ctor
-
- @Deprecated
- public BluetoothSocket getBTSocket(BluetoothServerSocket bsSocket){
-
- if(bsSocket == null || Build.VERSION.SDK_INT > Build.VERSION_CODES.O) { //Reflection is no longer allowed on SDK classes)
- return null;
- }
-
- Field[] f = bsSocket.getClass().getDeclaredFields();
-
- @SuppressWarnings("unused")
- int channel = -1;
-
- BluetoothSocket mySocket = null;
-
- for (Field field : f) {
- if(field.getName().equals("mSocket")){
- field.setAccessible(true);
- try {
-
- mySocket = (BluetoothSocket) field.get(bsSocket);
- return mySocket;
- //channel = field.getInt(bsSocket);
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- field.setAccessible(false);
- }
- }
-
- return null;
- }
-
- @Deprecated
- public int getChannel(BluetoothSocket bsSocket){
-
- int channel = -1;
- if (bsSocket == null || Build.VERSION.SDK_INT > Build.VERSION_CODES.O){ //Reflection is no longer allowed on SDK classes
- return channel;
- }
-
- Field[] f = bsSocket.getClass().getDeclaredFields();
-
- for (Field field : f) {
- if(field.getName().equals("mPort")){
- field.setAccessible(true);
- try {
-
-
- channel = field.getInt(bsSocket);
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- field.setAccessible(false);
- }
- }
-
- return channel;
- }
-
-
- /* private BluetoothServerSocket getBluetoothServerSocket() throws IOException {
- BluetoothServerSocket tmp;
-
- BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
-
-
- try {
- // compatibility with pre SDK 10 devices
- Method listener = mBluetoothAdapter.getClass().getMethod(
- "listenUsingRfcommWithServiceRecord", String.class, UUID.class);
- tmp = (BluetoothServerSocket) listener.invoke(mBluetoothAdapter, "SdlProxy", _listeningServiceUUID);
-
- } catch (NoSuchMethodException e) {
-
- throw new IOException(e);
- } catch (InvocationTargetException e) {
- throw new IOException(e);
- } catch (IllegalAccessException e) {
- throw new IOException(e);
- }
-
- return tmp;
- }*/
-
-
- public void openConnection () throws SdlException {
- if (_serverSocket != null) {
- return;
- }
-
- // Get the device's default Bluetooth Adapter
- _adapter = BluetoothAdapter.getDefaultAdapter();
-
-
- // Test if Adapter exists
- if (_adapter == null) {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("No Bluetooth adapter found. Bluetooth adapter must exist to communicate with SDL.", SdlExceptionCause.BLUETOOTH_ADAPTER_NULL);
- }
-
- // Test if Bluetooth is enabled
- try {
- if (!_adapter.isEnabled()) {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Bluetooth adapter must be enabled to instantiate a SdlProxy object.", SdlExceptionCause.BLUETOOTH_DISABLED);
- }
- } catch (SecurityException e) {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Insufficient permissions to interact with the Bluetooth Adapter.", SdlExceptionCause.PERMISSION_DENIED);
- }
-
- // Start BluetoothAdapterMonitor to ensure the Bluetooth Adapter continues to be enabled
- _bluetoothAdapterMonitor = new BluetoothAdapterMonitor(_adapter);
-
- try {
- _serverSocket = _adapter.listenUsingRfcommWithServiceRecord("SdlProxy", _listeningServiceUUID);
- BluetoothSocket mySock = getBTSocket(_serverSocket);
- int iSocket = getChannel(mySock);
-
- sComment = "Accepting Connections on SDP Server Port Number: " + iSocket + "\r\n";
- sComment += "Keep Server Socket Open: " + bKeepSocketActive;
- if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O && iSocket < 0)
- {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Could not open connection to SDL.", SdlExceptionCause.BLUETOOTH_SOCKET_UNAVAILABLE);
- }
- } catch (IOException e) {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Could not open connection to SDL.", SdlExceptionCause.BLUETOOTH_SOCKET_UNAVAILABLE);
-
- } catch (Exception ex) {
-
- // Test to determine if the bluetooth has been disabled since last check
- if (!_adapter.isEnabled()) {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Bluetooth adapter must be on to instantiate a SdlProxy object.", SdlExceptionCause.BLUETOOTH_DISABLED);
- }
-
- if(ex instanceof SdlException && ((SdlException) ex).getSdlExceptionCause() == SdlExceptionCause.BLUETOOTH_SOCKET_UNAVAILABLE) {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Could not open connection to SDL.", SdlExceptionCause.BLUETOOTH_SOCKET_UNAVAILABLE);
-
- }
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Could not open connection to SDL.", ex, SdlExceptionCause.SDL_CONNECTION_FAILED);
- }
-
- // Test to ensure serverSocket is not null
- if (_serverSocket == null) {
- SdlConnection.enableLegacyMode(false, null);
- throw new SdlException("Could not open connection to SDL.", SdlExceptionCause.SDL_CONNECTION_FAILED);
- }
-
- SdlTrace.logTransportEvent("BTTransport: listening for incoming connect to service ID " + _listeningServiceUUID, null, InterfaceActivityDirection.Receive, null, 0, SDL_LIB_TRACE_KEY);
-
- // Setup transportReader thread
- _transportReader = new TransportReaderThread();
- _transportReader.setName("TransportReader");
- _transportReader.setDaemon(true);
- _transportReader.start();
-
- // Initialize the SiphonServer
- if (SiphonServer.getSiphonEnabledStatus()) {
- SiphonServer.init();
- }
-
- } // end-method
-
- public void disconnect() {
- disconnect(null, null);
- }
-
- /**
- * Destroys the transport between SDL and the mobile app
- *
- * @param msg
- * @param ex
- */
- private void disconnect(String msg, Exception ex) {
- synchronized(DISCONNECT_LOCK) {
- // If already disconnecting, return
- if (_disconnecting) {
- // No need to recursively call
- return;
- }
- _disconnecting = true;
- }
-
- String disconnectMsg = (msg == null ? "" : msg);
- if (ex != null) {
- disconnectMsg += ", " + ex.toString();
- } // end-if
-
- SdlTrace.logTransportEvent("BTTransport.disconnect: " + disconnectMsg, null, InterfaceActivityDirection.Transmit, null, 0, SDL_LIB_TRACE_KEY);
-
- try {
- if (_transportReader != null) {
- _transportReader.halt();
- _transportReader = null;
- }
- } catch (Exception e) {
- DebugTool.logError(TAG, "Failed to stop transport reader thread.", e);
- } // end-catch
-
- try {
- if (_bluetoothAdapterMonitor != null) {
- _bluetoothAdapterMonitor.halt();
- _bluetoothAdapterMonitor = null;
- }
- } catch (Exception e) {
- DebugTool.logError(TAG, "Failed to stop adapter monitor thread.", e);
- }
-
- try {
- if (_serverSocket != null) {
- _serverSocket.close();
- _serverSocket = null;
- }
- } catch (Exception e) {
- DebugTool.logError(TAG, "Failed to close serverSocket", e);
- } // end-catch
-
- try {
- if (_activeSocket != null) {
- _activeSocket.close();
- _activeSocket = null;
- }
- } catch (Exception e) {
- DebugTool.logError(TAG, "Failed to close activeSocket", e);
- } // end-catch
-
-
-
- try {
- if (_output != null) {
- _output.close();
- _output = null;
- }
- } catch (Exception e) {
- DebugTool.logError(TAG, "Failed to close output stream", e);
- } // end-catch
-
- if (ex == null) {
- // This disconnect was not caused by an error, notify the proxy that
- // the trasport has been disconnected.
- handleTransportDisconnected(msg);
- } else {
- // This disconnect was caused by an error, notify the proxy
- // that there was a transport error.
- handleTransportError(msg, ex);
- }
- _disconnecting = false;
- } // end-method
-
-
- /**
- * Sends data over the transport. Takes a byte array and transmits data provided starting at the
- * offset and of the provided length to fragment transmission.
- */
- public boolean sendBytesOverTransport(SdlPacket packet) {
- boolean sendResult = false;
- try {
- byte[] msgBytes = packet.constructPacket();
- _output.write(msgBytes, 0, msgBytes.length);
- sendResult = true;
- } catch (Exception ex) {
- DebugTool.logError(TAG, "Error writing to Bluetooth socket: " + ex.toString(), ex);
- handleTransportError("Error writing to Bluetooth socket:", ex);
- sendResult = false;
- } // end-catch
- return sendResult;
- } // end-method
-
-
-
- private class TransportReaderThread extends Thread {
- private Boolean isHalted = false;
- SdlPsm psm;
- int bytesRead = 0;
- byte[] buffer = new byte[READ_BUFFER_SIZE];
- byte currentByte = -1;
- boolean stateProgress = false;
-
- private InputStream _input = null;
-
-
- public TransportReaderThread(){
- psm = new SdlPsm();
- }
- public void halt() {
- isHalted = true;
- }
-
- private void acceptConnection() {
- SdlTrace.logTransportEvent("BTTransport: Waiting for incoming RFCOMM connect", "", InterfaceActivityDirection.Receive, null, 0, SDL_LIB_TRACE_KEY);
-
- try {
- // Blocks thread until connection established.
- _activeSocket = _serverSocket.accept();
-
- // If halted after serverSocket.accept(), then return immediately
- if (isHalted) {
- return;
- }
-
- // Log info of the connected device
- BluetoothDevice btDevice = _activeSocket.getRemoteDevice();
- String btDeviceInfoXml = SdlTrace.getBTDeviceInfo(btDevice);
- SdlTrace.logTransportEvent("BTTransport: RFCOMM Connection Accepted", btDeviceInfoXml, InterfaceActivityDirection.Receive, null, 0, SDL_LIB_TRACE_KEY);
-
- _output = _activeSocket.getOutputStream();
- _input = _activeSocket.getInputStream();
-
- handleTransportConnected();
-
- } catch (Exception e) {
- if (!isHalted) {
- // Only call disconnect if the thread has not been halted
- clearInputStream();
- // Check to see if Bluetooth was disabled
- if (_adapter != null && !_adapter.isEnabled()) {
- disconnect("Bluetooth Adapater has been disabled.", new SdlException("Bluetooth adapter must be enabled to instantiate a SdlProxy object.", e, SdlExceptionCause.BLUETOOTH_DISABLED));
- } else {
- disconnect("Failed to accept connection", e);
- }
- }
- } finally {
-
- if (!bKeepSocketActive && _serverSocket != null && !isHalted && (VERSION.SDK_INT > 0x00000010 /*VERSION_CODES.JELLY_BEAN*/) ) {
- try {
- _serverSocket.close();
- } catch (IOException e) {
- //do nothing
- }
- _serverSocket = null;
- }
- }
- }
-
- private void readFromTransport() {
- try {
- try {
- bytesRead = _input.read(buffer);
- } catch (Exception e) {
- if (!isHalted) {
- // Only call disconnect if the thread has not been halted
- clearInputStream();
- // Check to see if Bluetooth was disabled
- if (_adapter != null && !_adapter.isEnabled()) {
- disconnect("Bluetooth Adapater has been disabled.", new SdlException("Bluetooth adapter must be enabled to instantiate a SdlProxy object.", e, SdlExceptionCause.BLUETOOTH_DISABLED));
- } else {
- disconnect("Failed to read from Bluetooth transport.", e);
- }
- }
- return;
- } // end-catch
-
- for (int i = 0; i < bytesRead; i++) {
- currentByte = buffer[i];
- stateProgress = psm.handleByte(currentByte);
- if(!stateProgress){//We are trying to weed through the bad packet info until we get something
- //Log.w(TAG, "Packet State Machine did not move forward from state - "+ psm.getState()+". PSM being Reset.");
- psm.reset();
- if(currentByte == -1){ //If we read a -1 and the psm didn't move forward, then there is a problem
- if (!isHalted) {
- // Only call disconnect if the thread has not been halted
- DebugTool.logError(TAG, "End of stream reached!");
- disconnect("End of stream reached.", null);
- }
- }
- }
- if(psm.getState() == SdlPsm.FINISHED_STATE){
- //Log.d(TAG, "Packet formed, sending off");
- handleReceivedPacket((SdlPacket)psm.getFormedPacket());
- //We put a trace statement in the message read so we can avoid all the extra bytes
- psm.reset();
- }
- }
-
- } catch (Exception excp) {
- if (!isHalted) {
- // Only call disconnect if the thread has not been halted
- clearInputStream();
- String errString = "Failure in BTTransport reader thread: " + excp.toString();
- DebugTool.logError(TAG, errString, excp);
- disconnect(errString, excp);
- }
- return;
- } // end-catch
- } // end-method
-
- private void clearInputStream(){
- try {
- if (_input != null) {
- _input.close();
- _input = null;
- }
- } catch (Exception e) {
- DebugTool.logError(TAG, "Failed to close input stream", e);
- } // end-catch
- }
-
- public void run() {
- // acceptConnection blocks until the connection has been accepted
- acceptConnection();
- psm.reset();
- while (!isHalted) {
- readFromTransport();
- }
- }
- }
-
- private class BluetoothAdapterMonitor {
- private boolean _isHalted = false;
- private BluetoothAdapter _bluetoothAdapter = null;
- private final String THREAD_NAME = "BluetoothAdapterMonitor";
- private Thread _bluetoothAdapterMonitorThread = null;
-
- public BluetoothAdapterMonitor(BluetoothAdapter bluetoothAdapter) {
- if (bluetoothAdapter == null) {
- throw new IllegalArgumentException("BluetoothAdapter cannot be null.");
- }
-
- // Set the bluetooth adapter
- _bluetoothAdapter = bluetoothAdapter;
-
- _bluetoothAdapterMonitorThread = new Thread(new Runnable() {
- @Override
- public void run() {
- while (!_isHalted) {
- checkIfBluetoothAdapterDisabled();
- try {
- Thread.sleep(15000);
- } catch (InterruptedException e) {
- // Break if interrupted
- break;
- }
- }
- }
- });
- _bluetoothAdapterMonitorThread.setName(THREAD_NAME);
- _bluetoothAdapterMonitorThread.setDaemon(true);
- _bluetoothAdapterMonitorThread.start();
- }
-
- private void checkIfBluetoothAdapterDisabled() {
- if (_bluetoothAdapter != null && !_bluetoothAdapter.isEnabled()) {
- // Bluetooth adapter has been disabled, disconnect the transport
- disconnect("Bluetooth adapter has been disabled.",
- new SdlException("Bluetooth adapter must be enabled to instantiate a SdlProxy object.", SdlExceptionCause.BLUETOOTH_DISABLED));
- }
- }
-
- public void halt() {
- _isHalted = true;
- _bluetoothAdapterMonitorThread.interrupt();
- }
- }
-
- /**
- * Overridden abstract method which returns specific type of this transport.
- *
- * @return Constant value - TransportType.BLUETOOTH.
- *
- * @see TransportType
- */
- public TransportType getTransportType() {
- return TransportType.BLUETOOTH;
- }
-
- @Override
- public String getBroadcastComment() {
- return sComment;
- }
-
- @Override
- protected void handleTransportDisconnected(String info) {
- SdlConnection.enableLegacyMode(false, null);
- super.handleTransportDisconnected(info);
- }
-
- @Override
- protected void handleTransportError(String message, Exception ex) {
- SdlConnection.enableLegacyMode(false, null);
- super.handleTransportError(message, ex);
- }
-
-} // end-class
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransport.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransport.java
deleted file mode 100644
index 0bacd3a2f..000000000
--- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransport.java
+++ /dev/null
@@ -1,343 +0,0 @@
-/*
- * Copyright (c) 2018 Livio, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the Livio Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package com.smartdevicelink.transport;
-
-import android.annotation.SuppressLint;
-import android.content.ComponentName;
-import android.content.Context;
-import android.os.Build;
-import android.os.Looper;
-import android.os.Parcelable;
-
-import com.smartdevicelink.SdlConnection.SdlConnection;
-import com.smartdevicelink.exception.SdlException;
-import com.smartdevicelink.protocol.SdlPacket;
-import com.smartdevicelink.transport.enums.TransportType;
-import com.smartdevicelink.transport.utl.TransportRecord;
-import com.smartdevicelink.util.DebugTool;
-
-import java.util.List;
-
-@Deprecated
-public class MultiplexTransport extends SdlTransport{
- private final static String TAG = "Multiplex Transport";
- private String sComment = "Multiplexing";
-
- TransportBrokerThread brokerThread;
- protected boolean isDisconnecting = false;
- MultiplexTransportConfig transportConfig;
- public MultiplexTransport(MultiplexTransportConfig transportConfig, final ITransportListener transportListener){
- super(transportListener);
- if(transportConfig == null){
- this.handleTransportError("Transport config was null", null);
- throw new IllegalArgumentException("Null transportConfig in MultiplexTransport constructor");
- }
- this.transportConfig = transportConfig;
- brokerThread = new TransportBrokerThread(transportConfig.context, transportConfig.appId, transportConfig.service);
- brokerThread.start();
- isDisconnecting = false;
- //brokerThread.initTransportBroker();
- //brokerThread.start();
-
- }
-
- public boolean isDisconnecting(){
- return this.isDisconnecting;
- }
- /**
- * Returns the config that was used to create this transport
- * @return
- */
- public MultiplexTransportConfig getConfig(){
- return this.transportConfig;
- }
-
- public boolean requestNewSession(){
- if(brokerThread!=null){
- brokerThread.requestNewSession();
- return true;
- }
- return false;
- }
-
- public void removeSession(long sessionId){
- if(brokerThread!=null){
- brokerThread.removeSession(sessionId);
- }
- }
-
- /**
- * Overridden abstract method which returns specific type of this transport.
- *
- * @return Constant value - TransportType.BLUETOOTH.
- * @see TransportType
- */
- public TransportType getTransportType() {
- return TransportType.MULTIPLEX;
- }
-
- @Override
- public String getBroadcastComment() {
- return sComment;
- }
-
- @Override
- protected boolean sendBytesOverTransport(SdlPacket packet) {
- if(brokerThread!=null){
- brokerThread.sendPacket(packet);
- return true;
- }
- return false; //Sure why not.
- }
-
- @Override
- public void openConnection() throws SdlException {
- DebugTool.logInfo(TAG, "Open connection");
- if(brokerThread!=null){
- brokerThread.startConnection();
- }//else should log out
-
- }
-
- @Override
- public void disconnect() {
- if(isDisconnecting){
- return;
- }
- DebugTool.logInfo(TAG, "Close connection");
- this.isDisconnecting= true;
- if(brokerThread!= null){
- brokerThread.cancel();
- brokerThread = null;
- }
- handleTransportDisconnected(TransportType.MULTIPLEX.name());
- isDisconnecting = false;
-
- }
-
-
-
- @Override
- protected void handleTransportError(String message, Exception ex) {
- if(brokerThread!=null){
- brokerThread.cancel();
- //brokerThread.interrupt();
- brokerThread = null;
- }
- super.handleTransportError(message, ex);
- }
-
-
- public boolean isPendingConnected(){
- if(brokerThread!=null){
- return brokerThread.queueStart;
- }
- return false;
- }
- /**
- * This thread will handle the broker transaction with the router service.
- *
- */
- protected class TransportBrokerThread extends Thread{
- boolean connected = false; //This helps clear up double on hardware connects
- TransportBroker broker;
- boolean queueStart = false;
- final Context context;
- final String appId;
- final ComponentName service;
- Looper threadLooper = null;
- /**
- * Thread will automatically start to prepare its looper.
- * @param context
- * @param appId
- */
- public TransportBrokerThread(Context context, String appId, ComponentName service){
- //this.start();
- super();
- this.context = context;
- this.appId = appId;
- this.service = service;
- //initTransportBroker(context, appId);
- }
-
- public void startConnection(){
- synchronized(this){
- connected = false;
- if(broker!=null){
- try{
- broker.start();
- }catch(Exception e){
- handleTransportError("Error starting transport", e);
- }
- }else{
- queueStart = true;
- }
- }
- }
-
- @SuppressLint("NewApi")
- public synchronized void cancel(){
- if(broker!=null){
- broker.stop();
- broker = null;
- }
- connected = false;
- if(threadLooper !=null){
- if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN_MR2){
- threadLooper.quitSafely();
- }else{
- threadLooper.quit();
- }
- threadLooper = null;
- }
- //this.interrupt();
-
- }
-
- public void onHardwareConnected(TransportType type){
- if(broker!=null){
- broker.onHardwareConnected(type);
- }else{
- queueStart = true;
- }
- }
-
- public void sendPacket(SdlPacket packet){
- broker.sendPacketToRouterService(packet);
- }
-
- public void requestNewSession(){
- if(broker!=null){
- broker.requestNewSession();
- }
- }
- public void removeSession(long sessionId){
- if(broker!=null){
- broker.removeSession(sessionId);
- }
- }
- @Override
- public void run() {
- Looper.prepare();
-
- if(broker==null){
- synchronized(this){
- initTransportBroker();
- if(queueStart){
- try{
- broker.start();
- }catch(Exception e){
- handleTransportError("Error starting transport", e);
- }
- }
- this.notify();
- }
- }
- threadLooper = Looper.myLooper();
- Looper.loop();
-
- }
-
- public void initTransportBroker(){
-
- broker = new TransportBroker(context, appId, service){
-
- @Override
- public boolean onHardwareConnected(TransportType type) {
- if(super.onHardwareConnected(type)){
- DebugTool.logInfo(TAG, "On transport connected...");
- if(!connected){
- connected = true;
- handleTransportConnected();
- }//else{Log.d(TAG, "Already connected");}
- return true;
- }else{
- try{
- this.start();
- }catch(Exception e){
- handleTransportError("Error starting transport", e);
- }
- }
- return false;
- }
-
- @Override
- public void onHardwareDisconnected(TransportRecord transportRecord, List<TransportRecord> connected) {
- onHardwareDisconnected(TransportType.BLUETOOTH);
- }
- @Override
- public void onHardwareDisconnected(TransportType type) {
- super.onHardwareDisconnected(type);
- if(connected){
- DebugTool.logInfo(TAG, "Handling disconnect");
- connected = false;
- SdlConnection.enableLegacyMode(isLegacyModeEnabled(), TransportType.BLUETOOTH);
- if(isLegacyModeEnabled()){
- DebugTool.logInfo(TAG, "Handle transport disconnect, legacy mode enabled");
- this.stop();
- isDisconnecting = true;
- //handleTransportDisconnected("");
- handleTransportError("",null); //This seems wrong, but it works
- }else{
- DebugTool.logInfo(TAG, "Handle transport Error");
- isDisconnecting = true;
- handleTransportError("",null); //This seems wrong, but it works
- }
- }
- }
-
- @Override
- public void onLegacyModeEnabled() {
- super.onLegacyModeEnabled();
- SdlConnection.enableLegacyMode(isLegacyModeEnabled(), TransportType.BLUETOOTH);
- if(isLegacyModeEnabled()){
- DebugTool.logInfo(TAG, "Handle on legacy mode enabled");
- this.stop();
- isDisconnecting = true;
- //handleTransportDisconnected("");
- handleTransportError("",null); //This seems wrong, but it works
- }
- }
-
- @Override
- public void onPacketReceived(Parcelable packet) {
- if(packet!=null){
- SdlPacket sdlPacket = (SdlPacket)packet;
- handleReceivedPacket(sdlPacket);
- }
- }
- };
- }
-
- }
-}
diff --git a/base/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java b/base/src/main/java/com/smartdevicelink/SdlConnection/BaseSdlSession.java
index fb82bd8a2..7bd7edb01 100644
--- a/base/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java
+++ b/base/src/main/java/com/smartdevicelink/SdlConnection/BaseSdlSession.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019 Livio, Inc.
+ * Copyright (c) 2020 Livio, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -32,13 +32,12 @@
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.SdlProtocolBase;
import com.smartdevicelink.protocol.enums.SessionType;
-import com.smartdevicelink.protocol.SdlProtocol;
import com.smartdevicelink.proxy.interfaces.ISdlServiceListener;
import com.smartdevicelink.proxy.rpc.VideoStreamingFormat;
import com.smartdevicelink.proxy.rpc.enums.VideoStreamingProtocol;
@@ -55,31 +54,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 +114,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 +261,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 +360,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 +423,5 @@ public class SdlSession implements ISdlProtocol, ISdlConnectionListener, ISecuri
-} \ No newline at end of file
+
+}
diff --git a/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java b/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java
index 13a494a73..765944492 100644
--- a/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java
@@ -104,7 +104,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
abstract class BaseLifecycleManager {
static final String TAG = "Lifecycle Manager";
- public static final Version MAX_SUPPORTED_RPC_VERSION = new Version(6, 0, 0);
+ public static final Version MAX_SUPPORTED_RPC_VERSION = new Version(7, 0, 0);
// Protected Correlation IDs
private final int REGISTER_APP_INTERFACE_CORRELATION_ID = 65529,
diff --git a/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseSystemCapabilityManager.java b/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseSystemCapabilityManager.java
index 1ae30f538..a86f716fd 100644
--- a/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseSystemCapabilityManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseSystemCapabilityManager.java
@@ -429,6 +429,8 @@ abstract class BaseSystemCapabilityManager {
return hmiCapabilities.isDisplaysCapabilityAvailable();
case SEAT_LOCATION:
return hmiCapabilities.isSeatLocationAvailable();
+ case DRIVER_DISTRACTION:
+ return hmiCapabilities.isDriverDistractionAvailable();
default:
return false;
}
diff --git a/base/src/main/java/com/smartdevicelink/proxy/RPCStruct.java b/base/src/main/java/com/smartdevicelink/proxy/RPCStruct.java
index 69c3e2bc0..5eb293ba2 100644
--- a/base/src/main/java/com/smartdevicelink/proxy/RPCStruct.java
+++ b/base/src/main/java/com/smartdevicelink/proxy/RPCStruct.java
@@ -32,6 +32,7 @@
package com.smartdevicelink.proxy;
import com.smartdevicelink.marshal.JsonRPCMarshaller;
+import com.smartdevicelink.util.SdlDataTypeConverter;
import com.smartdevicelink.util.Version;
import org.json.JSONException;
@@ -345,11 +346,11 @@ public class RPCStruct {
}
public Double getDouble(String key) {
- return (Double) store.get(key);
+ return SdlDataTypeConverter.objectToDouble(store.get(key));
}
public Float getFloat(String key) {
- return (Float) store.get(key);
+ return SdlDataTypeConverter.objectToFloat(store.get(key));
}
public Boolean getBoolean(String key) { return (Boolean) store.get(key); }
diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/AddSubMenu.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/AddSubMenu.java
index e2bd7e675..7d54aebe2 100644
--- a/base/src/main/java/com/smartdevicelink/proxy/rpc/AddSubMenu.java
+++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/AddSubMenu.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
+ * Copyright (c) 2017 - 2020, SmartDeviceLink Consortium, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -13,9 +13,9 @@
* 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.
+ * 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
@@ -98,6 +98,14 @@ import java.util.Hashtable;
* <td></td>
* <td>SmartDeviceLink 6.0</td>
* </tr>
+ * <tr>
+ * <td>parentID</td>
+ * <td>Integer</td>
+ * <td>unique ID of the sub menu, the command will be added to. If not provided or 0, it will be provided to the top level of the in application menu.</td>
+ * <td>N</td>
+ * <td>Min Value: 0 <p>Max Value: 2000000000</p> </td>
+ * <td>SmartDeviceLink 7.0.0</td>
+ * </tr>
* </table>
* <b>Response</b>
* <p>Indicates that the corresponding request either failed or succeeded. If the response returns with a SUCCESS result code, this means the SubMenu was added to the Command Menu successfully</p>
@@ -116,6 +124,7 @@ public class AddSubMenu extends RPCRequest {
public static final String KEY_MENU_ID = "menuID";
public static final String KEY_MENU_ICON = "menuIcon";
public static final String KEY_MENU_LAYOUT = "menuLayout";
+ public static final String KEY_PARENT_ID = "parentID";
/**
* Constructs a new AddSubMenu object
@@ -250,4 +259,26 @@ public class AddSubMenu extends RPCRequest {
public MenuLayout getMenuLayout() {
return (MenuLayout) getObject(MenuLayout.class, KEY_MENU_LAYOUT);
}
+
+ /**
+ * Sets the parentID.
+ *
+ * @param parentID unique ID of the sub menu, the command will be added to. If not provided or 0, it will be
+ * provided to the top level of the in application menu.
+ * @since SmartDeviceLink 7.0.0
+ */
+ public void setParentID(Integer parentID) {
+ setParameters(KEY_PARENT_ID, parentID);
+ }
+
+ /**
+ * Gets the parentID.
+ *
+ * @return Integer unique ID of the sub menu, the command will be added to. If not provided or 0, it will be
+ * provided to the top level of the in application menu.
+ * @since SmartDeviceLink 7.0.0
+ */
+ public Integer getParentID() {
+ return getInteger(KEY_PARENT_ID);
+ }
}
diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/DriverDistractionCapability.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/DriverDistractionCapability.java
new file mode 100644
index 000000000..c09a77f46
--- /dev/null
+++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/DriverDistractionCapability.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2017 - 2020, 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.proxy.rpc;
+
+import com.smartdevicelink.proxy.RPCStruct;
+
+import java.util.Hashtable;
+
+/**
+ *
+ * <p><b>Parameter List</b></p>
+ *
+ * <table border="1" rules="all">
+ * <tr>
+ * <th>Param Name</th>
+ * <th>Type</th>
+ * <th>Description</th>
+ * <th>Required</th>
+ * <th>Version Available</th>
+ * </tr>
+ * <tr>
+ * <td>menuLength</td>
+ * <td>Integer</td>
+ * <td>The number of items allowed in a Choice Set or Command menu while the driver is distracted</td>
+ * <td>N</td>
+ * <td></td>
+ * </tr>
+ * <tr>
+ * <td>subMenuDepth</td>
+ * <td>Integer</td>
+ * <td>The depth of submenus allowed when the driver is distracted. e.g. 3 == top level menu ->submenu -> submenu; 1 == top level menu only</td>
+ * <td>N</td>
+ * <td></td>
+ * </tr>
+ * </table>
+ * @since SmartDeviceLink 7.0.0
+ */
+public class DriverDistractionCapability extends RPCStruct {
+ public static final String KEY_MENU_LENGTH = "menuLength";
+ public static final String KEY_SUB_MENU_DEPTH = "subMenuDepth";
+
+ /**
+ * Constructs a new DriverDistractionCapability object
+ */
+ public DriverDistractionCapability() { }
+
+ /**
+ * Constructs a new DriverDistractionCapability object indicated by the Hashtable parameter
+ *
+ * @param hash The Hashtable to use
+ */
+ public DriverDistractionCapability(Hashtable<String, Object> hash) {
+ super(hash);
+ }
+
+ /**
+ * Sets the menuLength.
+ *
+ * @param menuLength The number of items allowed in a Choice Set or Command menu while the driver is distracted
+ */
+ public void setMenuLength(Integer menuLength) {
+ setValue(KEY_MENU_LENGTH, menuLength);
+ }
+
+ /**
+ * Gets the menuLength.
+ *
+ * @return Integer The number of items allowed in a Choice Set or Command menu while the driver is distracted
+ */
+ public Integer getMenuLength() {
+ return getInteger(KEY_MENU_LENGTH);
+ }
+
+ /**
+ * Sets the subMenuDepth.
+ *
+ * @param subMenuDepth The depth of submenus allowed when the driver is distracted. e.g. 3 == top level menu ->
+ * submenu -> submenu; 1 == top level menu only
+ */
+ public void setSubMenuDepth(Integer subMenuDepth) {
+ setValue(KEY_SUB_MENU_DEPTH, subMenuDepth);
+ }
+
+ /**
+ * Gets the subMenuDepth.
+ *
+ * @return Integer The depth of submenus allowed when the driver is distracted. e.g. 3 == top level menu ->
+ * submenu -> submenu; 1 == top level menu only
+ */
+ public Integer getSubMenuDepth() {
+ return getInteger(KEY_SUB_MENU_DEPTH);
+ }
+}
diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/HMICapabilities.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/HMICapabilities.java
index d7a8c9001..f1b3c4821 100644
--- a/base/src/main/java/com/smartdevicelink/proxy/rpc/HMICapabilities.java
+++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/HMICapabilities.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
+ * Copyright (c) 2017 - 2020, SmartDeviceLink Consortium, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -13,9 +13,9 @@
* 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.
+ * 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
@@ -43,6 +43,7 @@ public class HMICapabilities extends RPCStruct{
public static final String KEY_APP_SERVICES = "appServices";
public static final String KEY_DISPLAYS = "displays";
public static final String KEY_SEAT_LOCATION = "seatLocation";
+ public static final String KEY_DRIVER_DISTRACTION = "driverDistraction";
public HMICapabilities() { }
@@ -134,4 +135,27 @@ public class HMICapabilities extends RPCStruct{
setValue(KEY_SEAT_LOCATION, available);
}
+ /**
+ * Sets the driverDistraction.
+ *
+ * @param driverDistraction Availability of driver distraction capability. True: Available, False: Not Available
+ * @since SmartDeviceLink 7.0.0
+ */
+ public void setDriverDistraction(Boolean driverDistraction) {
+ setValue(KEY_DRIVER_DISTRACTION, driverDistraction);
+ }
+
+ /**
+ * Gets the driverDistraction.
+ *
+ * @return Boolean Availability of driver distraction capability. True: Available, False: Not Available
+ * @since SmartDeviceLink 7.0.0
+ */
+ public Boolean isDriverDistractionAvailable() {
+ Object available = getValue(KEY_DRIVER_DISTRACTION);
+ if (available == null) {
+ return false;
+ }
+ return (Boolean) available;
+ }
}
diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/SystemCapability.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/SystemCapability.java
index 73634c17b..314b6d0cc 100644
--- a/base/src/main/java/com/smartdevicelink/proxy/rpc/SystemCapability.java
+++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/SystemCapability.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
+ * Copyright (c) 2017 - 2020, SmartDeviceLink Consortium, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -13,9 +13,9 @@
* 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.
+ * 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
@@ -51,6 +51,8 @@ public class SystemCapability extends RPCStruct {
public static final String KEY_APP_SERVICES_CAPABILITIES = "appServicesCapabilities";
public static final String KEY_SEAT_LOCATION_CAPABILITY = "seatLocationCapability";
public static final String KEY_DISPLAY_CAPABILITIES = "displayCapabilities";
+ public static final String KEY_DRIVER_DISTRACTION_CAPABILITY = "driverDistractionCapability";
+
public SystemCapability(){}
public SystemCapability(Hashtable<String, Object> hash) {
@@ -98,6 +100,8 @@ public class SystemCapability extends RPCStruct {
return getObject(SeatLocationCapability.class, KEY_SEAT_LOCATION_CAPABILITY);
} else if (type.equals(SystemCapabilityType.DISPLAYS)) {
return getObject(DisplayCapability.class, KEY_DISPLAY_CAPABILITIES);
+ } else if (type.equals(SystemCapabilityType.DRIVER_DISTRACTION)) {
+ return getObject(DriverDistractionCapability.class, KEY_DRIVER_DISTRACTION_CAPABILITY);
} else {
return null;
}
@@ -120,6 +124,8 @@ public class SystemCapability extends RPCStruct {
setValue(KEY_SEAT_LOCATION_CAPABILITY, capability);
} else if (type.equals(SystemCapabilityType.DISPLAYS)) {
setValue(KEY_DISPLAY_CAPABILITIES, capability);
+ } else if (type.equals(SystemCapabilityType.DRIVER_DISTRACTION)) {
+ setValue(KEY_DRIVER_DISTRACTION_CAPABILITY, capability);
} else {
return;
}
diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java
index 758a33905..775781000 100644
--- a/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java
+++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
+ * Copyright (c) 2017 - 2020, SmartDeviceLink Consortium, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -13,9 +13,9 @@
* 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.
+ * 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
@@ -155,6 +155,13 @@ package com.smartdevicelink.proxy.rpc.enums;
* <td align=center>N</td>
* <td>Available Asynchronously, Call is synchronous <strong>after</strong> initial call</strong></td>
* </tr>
+ * <tr>
+ * <td>DRIVER_DISTRACTION</td>
+ * <d>DriverDistractionCapability</td>
+ * <td>Returns DRIVER_DISTRACTION</td>
+ * <td align=center>N</td>
+ * <td><strong>Since 7.0</strong> Describes capabilities when the driver is distracted</td>
+ * </tr>
* </table>
*
*/
@@ -552,6 +559,26 @@ public enum SystemCapabilityType {
*/
SEAT_LOCATION (true),
+ /**
+ * <table border="1" rules="all">
+ * <tr>
+ * <th>Enum Name</th>
+ * <th>Return Type</th>
+ * <th>Description</th>
+ * <th>Requires Async?</th>
+ * <th>Notes</th>
+ * </tr>
+ * <tr>
+ * <td>DRIVER_DISTRACTION</td>
+ * <td>DriverDistractionCapability</td>
+ * <td>Returns DRIVER_DISTRACTION</td>
+ * <td align=center>N</td>
+ * <td><strong>Since 7.0</strong> Describes capabilities when the driver is distracted</td>
+ * </tr>
+ * </table>
+ */
+ DRIVER_DISTRACTION(true);
+
;
boolean IS_QUERYABLE;
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..98150b218
--- /dev/null
+++ b/javaSE/src/main/java/com/smartdevicelink/SdlConnection/SdlSession.java
@@ -0,0 +1,130 @@
+/*
+ * 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.SdlProtocol;
+import com.smartdevicelink.protocol.SdlProtocolBase;
+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);
+ }
+
+ @Override
+ protected SdlProtocolBase getSdlProtocolImplementation() {
+ return new SdlProtocol(this, transportConfig);
+ }
+
+
+ @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");
+ }
+ }
+ }
+} \ No newline at end of file