summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2016-10-07 13:54:12 -0400
committerJoey Grover <joeygrover@gmail.com>2016-10-07 13:54:12 -0400
commit880150a03e366b998f66e439176085df225ab919 (patch)
tree96618e64da0246aeccdd33295a2f3117121b2e6b
parent4666c663b6383316aa250e7785396e8061b3ce34 (diff)
parentfd29e92919b93c51c660ddf8aa08bd78a107dfd5 (diff)
downloadsdl_android-880150a03e366b998f66e439176085df225ab919.tar.gz
Merge branch 'develop' of https://github.com/smartdevicelink/sdl_android into feature/unit_tests
# Conflicts: # sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyALM.java
-rw-r--r--CHANGELOG.md16
-rw-r--r--HelloSdl/.settings/org.eclipse.jdt.core.prefs4
-rw-r--r--HelloSdl/AndroidManifest.xml50
-rw-r--r--HelloSdl/ic_launcher-web.pngbin37133 -> 0 bytes
-rw-r--r--HelloSdl/libs/android-support-v4.jarbin995624 -> 0 bytes
-rw-r--r--HelloSdl/lint.xml3
-rw-r--r--HelloSdl/proguard-project.txt20
-rw-r--r--HelloSdl/project.properties15
-rw-r--r--HelloSdl/res/drawable-hdpi/ic_launcher.pngbin5729 -> 0 bytes
-rw-r--r--HelloSdl/res/drawable-mdpi/ic_launcher.pngbin3022 -> 0 bytes
-rw-r--r--HelloSdl/res/drawable-xhdpi/ic_launcher.pngbin9073 -> 0 bytes
-rw-r--r--HelloSdl/res/drawable-xxhdpi/ic_launcher.pngbin17609 -> 0 bytes
-rw-r--r--HelloSdl/res/layout/activity_main.xml16
-rw-r--r--HelloSdl/res/menu/main.xml11
-rw-r--r--HelloSdl/res/values-w820dp/dimens.xml10
-rw-r--r--HelloSdl/res/values/dimens.xml7
-rw-r--r--HelloSdl/res/values/strings.xml8
-rw-r--r--HelloSdl/res/values/styles.xml20
-rw-r--r--HelloSdl/src/com/hellosdl/MainActivity.java42
-rw-r--r--HelloSdl/src/com/hellosdl/sdl/SdlReceiver.java24
-rw-r--r--HelloSdl/src/com/hellosdl/sdl/SdlRouterService.java8
-rw-r--r--HelloSdl/src/com/hellosdl/sdl/SdlService.java688
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/SdlConnection/ISdlConnectionListener.java4
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlConnection.java307
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlSession.java336
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/protocol/AbstractProtocol.java20
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/protocol/IProtocolListener.java8
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/protocol/ProtocolMessage.java11
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/protocol/SdlPacket.java40
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/protocol/SdlPacketFactory.java16
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/protocol/WiProProtocol.java155
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/proxy/RPCMessage.java4
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/proxy/RPCRequestFactory.java3
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/proxy/RPCStruct.java12
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyALM.java530
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyBase.java345
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyBuilder.java38
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/proxy/interfaces/IProxyListenerBase.java14
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/proxy/rpc/TouchEvent.java47
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/security/ISecurityInitializedListener.java5
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/security/SdlSecurityBase.java100
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/streaming/AbstractPacketizer.java21
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/streaming/StreamPacketizer.java26
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/streaming/StreamRPCPacketizer.java28
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/trace/SdlTrace.java2
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/BTTransport.java2
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/MultiplexBluetoothTransport.java7
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/MultiplexTransport.java18
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java12
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java130
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/SdlPsm.java7
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/SdlRouterService.java285
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/SdlRouterStatusProvider.java142
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/TransportBroker.java110
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/TransportConstants.java22
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/util/DebugTool.java82
56 files changed, 2124 insertions, 1707 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d0afe5b87..5639fb9aa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,12 +1,16 @@
-# 4.0.1 Release Notes
+# 4.1.0 Release Notes
### API New Features & Breaking Changes
- * Added ability to retrieve HMICapabilities and SystemSoftwareVersion from the proxy object.
+* Added multiplexing transport that gives the ability to share a single bluetooth RCOMM channel with many clients.
+* Added external security framework that allows OEM's to provide custom security libraries.
+* ProxyALM constructors have changed and old signatures been deprecated.
+* Changed TouchEvent method names to be more intuitive.
### Enhancements
- * Added RPC request callbacks. Developers can now set a listener object into any RPC request and recieve the response through it.
- * Added RPC notification listeners. Developers can now designate a listener for each notifcation type.
- * Added a correlation id generator. Id's can be generated through this class to avoid having to keep track between multiple classes.
+* Multiplexing will now be the default mode of transport
### Bug Fixes
- * Removed unused imports
+* Fixed issue with sending a stop session with an incorrect hash id
+* Fixed the library throwing away hybrid packets
+* Fixed http onSystemRequests to actually function correctly
+* Fixed a class cast exception in the BTTransport class
diff --git a/HelloSdl/.settings/org.eclipse.jdt.core.prefs b/HelloSdl/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index b080d2ddc..000000000
--- a/HelloSdl/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,4 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.source=1.6
diff --git a/HelloSdl/AndroidManifest.xml b/HelloSdl/AndroidManifest.xml
deleted file mode 100644
index d15dbe2a6..000000000
--- a/HelloSdl/AndroidManifest.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.hellosdl"
- android:versionCode="1"
- android:versionName="1.0" >
-
- <uses-sdk
- android:minSdkVersion="8"
- android:targetSdkVersion="19" />
-
- <uses-permission android:name="android.permission.BLUETOOTH" />
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
-
- <application
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name=".MainActivity"
- android:label="@string/app_name" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
-
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
-
-
- <service android:name=".sdl.SdlService" ></service>
-
- <service android:name=".sdl.SdlRouterService"
- android:exported="true"
- android:process="com.smartdevicelink.router"></service>
-
-
- <receiver android:name=".sdl.SdlReceiver" android:enabled="true" >
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- <action android:name="android.bluetooth.device.action.ACL_CONNECTED"/>
- <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
- <action android:name = "sdl.router.startservice"/>
- </intent-filter>
- </receiver>
-
-
- </application>
-
-</manifest>
diff --git a/HelloSdl/ic_launcher-web.png b/HelloSdl/ic_launcher-web.png
deleted file mode 100644
index 3e493438c..000000000
--- a/HelloSdl/ic_launcher-web.png
+++ /dev/null
Binary files differ
diff --git a/HelloSdl/libs/android-support-v4.jar b/HelloSdl/libs/android-support-v4.jar
deleted file mode 100644
index 4ebdaa9ed..000000000
--- a/HelloSdl/libs/android-support-v4.jar
+++ /dev/null
Binary files differ
diff --git a/HelloSdl/lint.xml b/HelloSdl/lint.xml
deleted file mode 100644
index ee0eead5b..000000000
--- a/HelloSdl/lint.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<lint>
-</lint> \ No newline at end of file
diff --git a/HelloSdl/proguard-project.txt b/HelloSdl/proguard-project.txt
deleted file mode 100644
index f2fe1559a..000000000
--- a/HelloSdl/proguard-project.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-# To enable ProGuard in your project, edit project.properties
-# to define the proguard.config property as described in that file.
-#
-# Add project specific ProGuard rules here.
-# By default, the flags in this file are appended to flags specified
-# in ${sdk.dir}/tools/proguard/proguard-android.txt
-# You can edit the include path and order by changing the ProGuard
-# include property in project.properties.
-#
-# For more details, see
-# http://developer.android.com/guide/developing/tools/proguard.html
-
-# Add any project specific keep options here:
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-# public *;
-#}
diff --git a/HelloSdl/project.properties b/HelloSdl/project.properties
deleted file mode 100644
index f76c1b9a4..000000000
--- a/HelloSdl/project.properties
+++ /dev/null
@@ -1,15 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system edit
-# "ant.properties", and override values to adapt the script to your
-# project structure.
-#
-# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
-#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
-
-# Project target.
-target=android-19
-android.library.reference.1=../sdl_android_lib
diff --git a/HelloSdl/res/drawable-hdpi/ic_launcher.png b/HelloSdl/res/drawable-hdpi/ic_launcher.png
deleted file mode 100644
index 903e3d12d..000000000
--- a/HelloSdl/res/drawable-hdpi/ic_launcher.png
+++ /dev/null
Binary files differ
diff --git a/HelloSdl/res/drawable-mdpi/ic_launcher.png b/HelloSdl/res/drawable-mdpi/ic_launcher.png
deleted file mode 100644
index 8415d3068..000000000
--- a/HelloSdl/res/drawable-mdpi/ic_launcher.png
+++ /dev/null
Binary files differ
diff --git a/HelloSdl/res/drawable-xhdpi/ic_launcher.png b/HelloSdl/res/drawable-xhdpi/ic_launcher.png
deleted file mode 100644
index 962976da1..000000000
--- a/HelloSdl/res/drawable-xhdpi/ic_launcher.png
+++ /dev/null
Binary files differ
diff --git a/HelloSdl/res/drawable-xxhdpi/ic_launcher.png b/HelloSdl/res/drawable-xxhdpi/ic_launcher.png
deleted file mode 100644
index f4c378997..000000000
--- a/HelloSdl/res/drawable-xxhdpi/ic_launcher.png
+++ /dev/null
Binary files differ
diff --git a/HelloSdl/res/layout/activity_main.xml b/HelloSdl/res/layout/activity_main.xml
deleted file mode 100644
index 5056c3b98..000000000
--- a/HelloSdl/res/layout/activity_main.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context="com.hellosdl.MainActivity" >
-
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/hello_world" />
-
-</RelativeLayout>
diff --git a/HelloSdl/res/menu/main.xml b/HelloSdl/res/menu/main.xml
deleted file mode 100644
index e3df24bab..000000000
--- a/HelloSdl/res/menu/main.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<menu xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- tools:context="com.hellosdl.MainActivity" >
-
- <item
- android:id="@+id/action_settings"
- android:orderInCategory="100"
- android:title="@string/action_settings"/>
-
-</menu>
diff --git a/HelloSdl/res/values-w820dp/dimens.xml b/HelloSdl/res/values-w820dp/dimens.xml
deleted file mode 100644
index f3e70203b..000000000
--- a/HelloSdl/res/values-w820dp/dimens.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-<resources>
-
- <!--
- Example customization of dimensions originally defined in res/values/dimens.xml
- (such as screen margins) for screens with more than 820dp of available width. This
- would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively).
- -->
- <dimen name="activity_horizontal_margin">64dp</dimen>
-
-</resources>
diff --git a/HelloSdl/res/values/dimens.xml b/HelloSdl/res/values/dimens.xml
deleted file mode 100644
index 55c1e5908..000000000
--- a/HelloSdl/res/values/dimens.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<resources>
-
- <!-- Default screen margins, per the Android Design guidelines. -->
- <dimen name="activity_horizontal_margin">16dp</dimen>
- <dimen name="activity_vertical_margin">16dp</dimen>
-
-</resources>
diff --git a/HelloSdl/res/values/strings.xml b/HelloSdl/res/values/strings.xml
deleted file mode 100644
index a7f78e961..000000000
--- a/HelloSdl/res/values/strings.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
-
- <string name="app_name">HelloSdl</string>
- <string name="hello_world">Hello Car!</string>
- <string name="action_settings">Settings</string>
-
-</resources>
diff --git a/HelloSdl/res/values/styles.xml b/HelloSdl/res/values/styles.xml
deleted file mode 100644
index 4d175139d..000000000
--- a/HelloSdl/res/values/styles.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<resources>
-
- <!--
- Base application theme, dependent on API level. This theme is replaced
- by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
- -->
- <style name="AppBaseTheme">
- <!--
- Theme customizations available in newer API levels can go in
- res/values-vXX/styles.xml, while customizations related to
- backward-compatibility can go here.
- -->
- </style>
-
- <!-- Application theme. -->
- <style name="AppTheme" parent="AppBaseTheme">
- <!-- All customizations that are NOT specific to a particular API-level can go here. -->
- </style>
-
-</resources>
diff --git a/HelloSdl/src/com/hellosdl/MainActivity.java b/HelloSdl/src/com/hellosdl/MainActivity.java
deleted file mode 100644
index da6b8ecaf..000000000
--- a/HelloSdl/src/com/hellosdl/MainActivity.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.hellosdl;
-
-import com.hellosdl.sdl.SdlReceiver;
-import com.hellosdl.sdl.SdlService;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
-
-public class MainActivity extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- if(SdlReceiver.isTransportConnected(getBaseContext())){
- Intent startIntent = new Intent(getBaseContext(), SdlService.class);
- startService(startIntent);
- }
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-}
diff --git a/HelloSdl/src/com/hellosdl/sdl/SdlReceiver.java b/HelloSdl/src/com/hellosdl/sdl/SdlReceiver.java
deleted file mode 100644
index 2162516f5..000000000
--- a/HelloSdl/src/com/hellosdl/sdl/SdlReceiver.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.hellosdl.sdl;
-
-
-
-import android.content.Context;
-import android.content.Intent;
-import android.util.Log;
-
-
-public class SdlReceiver extends com.smartdevicelink.transport.SdlBroadcastReceiver {
- private static final String TAG = "BCast Receiver";
-
- @Override
- public Class defineLocalSdlRouterClass() {
- return SdlRouterService.class;
- }
-
- @Override
- public void onSdlEnabled(Context context, Intent intent) {
- Log.e(TAG, "SDL Enabled");
- intent.setClass(context, SdlService.class);
- context.startService(intent);
- }
-}
diff --git a/HelloSdl/src/com/hellosdl/sdl/SdlRouterService.java b/HelloSdl/src/com/hellosdl/sdl/SdlRouterService.java
deleted file mode 100644
index b80d30c4e..000000000
--- a/HelloSdl/src/com/hellosdl/sdl/SdlRouterService.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.hellosdl.sdl;
-
-
-public class SdlRouterService extends com.smartdevicelink.transport.SdlRouterService {
-
-
-
-}
diff --git a/HelloSdl/src/com/hellosdl/sdl/SdlService.java b/HelloSdl/src/com/hellosdl/sdl/SdlService.java
deleted file mode 100644
index eba5bc780..000000000
--- a/HelloSdl/src/com/hellosdl/sdl/SdlService.java
+++ /dev/null
@@ -1,688 +0,0 @@
-package com.hellosdl.sdl;
-
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import android.app.Service;
-import android.content.Intent;
-import android.os.IBinder;
-import android.util.Log;
-
-import com.hellosdl.MainActivity;
-import com.hellosdl.R;
-import com.smartdevicelink.exception.SdlException;
-import com.smartdevicelink.proxy.SdlProxyALM;
-import com.smartdevicelink.proxy.callbacks.OnServiceEnded;
-import com.smartdevicelink.proxy.callbacks.OnServiceNACKed;
-import com.smartdevicelink.proxy.interfaces.IProxyListenerALM;
-import com.smartdevicelink.proxy.rpc.AddCommandResponse;
-import com.smartdevicelink.proxy.rpc.AddSubMenuResponse;
-import com.smartdevicelink.proxy.rpc.AlertManeuverResponse;
-import com.smartdevicelink.proxy.rpc.AlertResponse;
-import com.smartdevicelink.proxy.rpc.ChangeRegistrationResponse;
-import com.smartdevicelink.proxy.rpc.CreateInteractionChoiceSetResponse;
-import com.smartdevicelink.proxy.rpc.DeleteCommandResponse;
-import com.smartdevicelink.proxy.rpc.DeleteFileResponse;
-import com.smartdevicelink.proxy.rpc.DeleteInteractionChoiceSetResponse;
-import com.smartdevicelink.proxy.rpc.DeleteSubMenuResponse;
-import com.smartdevicelink.proxy.rpc.DiagnosticMessageResponse;
-import com.smartdevicelink.proxy.rpc.DialNumberResponse;
-import com.smartdevicelink.proxy.rpc.EndAudioPassThruResponse;
-import com.smartdevicelink.proxy.rpc.GenericResponse;
-import com.smartdevicelink.proxy.rpc.GetDTCsResponse;
-import com.smartdevicelink.proxy.rpc.GetVehicleDataResponse;
-import com.smartdevicelink.proxy.rpc.ListFilesResponse;
-import com.smartdevicelink.proxy.rpc.OnAudioPassThru;
-import com.smartdevicelink.proxy.rpc.OnButtonEvent;
-import com.smartdevicelink.proxy.rpc.OnButtonPress;
-import com.smartdevicelink.proxy.rpc.OnCommand;
-import com.smartdevicelink.proxy.rpc.OnDriverDistraction;
-import com.smartdevicelink.proxy.rpc.OnHMIStatus;
-import com.smartdevicelink.proxy.rpc.OnHashChange;
-import com.smartdevicelink.proxy.rpc.OnKeyboardInput;
-import com.smartdevicelink.proxy.rpc.OnLanguageChange;
-import com.smartdevicelink.proxy.rpc.OnLockScreenStatus;
-import com.smartdevicelink.proxy.rpc.OnPermissionsChange;
-import com.smartdevicelink.proxy.rpc.OnStreamRPC;
-import com.smartdevicelink.proxy.rpc.OnSystemRequest;
-import com.smartdevicelink.proxy.rpc.OnTBTClientState;
-import com.smartdevicelink.proxy.rpc.OnTouchEvent;
-import com.smartdevicelink.proxy.rpc.OnVehicleData;
-import com.smartdevicelink.proxy.rpc.PerformAudioPassThruResponse;
-import com.smartdevicelink.proxy.rpc.PerformInteractionResponse;
-import com.smartdevicelink.proxy.rpc.PutFile;
-import com.smartdevicelink.proxy.rpc.PutFileResponse;
-import com.smartdevicelink.proxy.rpc.ReadDIDResponse;
-import com.smartdevicelink.proxy.rpc.ResetGlobalPropertiesResponse;
-import com.smartdevicelink.proxy.rpc.ScrollableMessageResponse;
-import com.smartdevicelink.proxy.rpc.SendLocationResponse;
-import com.smartdevicelink.proxy.rpc.SetAppIconResponse;
-import com.smartdevicelink.proxy.rpc.SetDisplayLayoutResponse;
-import com.smartdevicelink.proxy.rpc.SetGlobalPropertiesResponse;
-import com.smartdevicelink.proxy.rpc.SetMediaClockTimerResponse;
-import com.smartdevicelink.proxy.rpc.ShowConstantTbtResponse;
-import com.smartdevicelink.proxy.rpc.ShowResponse;
-import com.smartdevicelink.proxy.rpc.SliderResponse;
-import com.smartdevicelink.proxy.rpc.SpeakResponse;
-import com.smartdevicelink.proxy.rpc.StreamRPCResponse;
-import com.smartdevicelink.proxy.rpc.SubscribeButtonResponse;
-import com.smartdevicelink.proxy.rpc.SubscribeVehicleDataResponse;
-import com.smartdevicelink.proxy.rpc.SystemRequestResponse;
-import com.smartdevicelink.proxy.rpc.UnsubscribeButtonResponse;
-import com.smartdevicelink.proxy.rpc.UnsubscribeVehicleDataResponse;
-import com.smartdevicelink.proxy.rpc.UpdateTurnListResponse;
-import com.smartdevicelink.proxy.rpc.enums.FileType;
-import com.smartdevicelink.proxy.rpc.enums.SdlDisconnectedReason;
-import com.smartdevicelink.proxy.rpc.enums.TextAlignment;
-import com.smartdevicelink.transport.MultiplexTransportConfig;
-import com.smartdevicelink.transport.TransportConstants;
-
-/**
- * While this class is just an extension off the base Android Service class, we hope in the future we can offer something
- * better that takes care of a lot of life cycle stuff.
- * <p>
- * For now this shows the most basic of operations to take when connecting via SDL
- * Here's what it covers
- * 1. Basic Sdl proxy life cycle
- * 2. Sending app icon
- * 3. When to launch activity and dealing with different HMI_STATUS's
- *
- *
- * @author Joey Grover
- *
- */
-public class SdlService extends Service implements IProxyListenerALM{
- private static final String TAG = "SdlService";
- private static final String APP_NAME = "Hello Car"; //TODO enter your own app name here
- private static final String APP_ID = "7331"; //TODO enter your own app id here
- private static final String ICON_SYNC_FILENAME = "icon.png";
- private static final String ICON_FILENAME_SUFFIX = ".png";
-
-
- // variable to create and call functions of the SdlProxy
- private SdlProxyALM proxy = null;
-
- // variable used to increment correlation ID for every request sent to a SDL system
- public int autoIncCorrId = 0;
-
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
-
-
-
- @Override
- public void onCreate() {
- super.onCreate();
- startProxy();
- }
-
-
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- if(proxy == null){
- startProxy();
- }else if (intent != null && intent.hasExtra(TransportConstants.FORCE_TRANSPORT_CONNECTED)){
- proxy.forceOnConnected();
- }
- return START_STICKY;
- }
-
- @Override
- public void onDestroy() {
- disposeSyncProxy();
- super.onDestroy();
- }
-
-
- /* ***********************************************************************************************************************************************************************
- * ******************************************************* Methods for SdlProxy Management *******************************************************************************
- *************************************************************************************************************************************************************************/
-
- public void startProxy() {
- if (proxy == null) {
- try {
- proxy = new SdlProxyALM(this, APP_NAME,
- true, APP_ID,
- new MultiplexTransportConfig(getBaseContext(), APP_ID));
-
- } catch (SdlException e) {
- e.printStackTrace();
- // error creating proxy, returned proxy = null
- if (proxy == null) {
- stopSelf();
- }
- }
- }
- }
-
- public void disposeSyncProxy() {
- if (proxy != null) {
- try {
- proxy.dispose();
- } catch (SdlException e) {
- e.printStackTrace();
- }
- proxy = null;
- }
- }
-
- /**
- * This will send the app icon over to the SDL system
- * @throws SdlException
- */
- private void sendIcon() throws SdlException {
- PutFile putFile = new PutFile();
- putFile.setFileType(FileType.GRAPHIC_PNG);
- putFile.setSdlFileName(ICON_SYNC_FILENAME);
- putFile.setCorrelationID(autoIncCorrId++);
- putFile.setBulkData(contentsOfResource(R.drawable.ic_launcher));
-
- proxy.sendRPCRequest(putFile);
- }
-
- /**
- * This is a convience method that will grab all the binary data from a resource
- * to be able to be sent to the SDL sytem
- * @param resource
- * @return
- */
- private byte[] contentsOfResource(int resource) {
- InputStream is = null;
- try {
- is = getResources().openRawResource(resource);
- ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());
- final int buffersize = 4096;
- final byte[] buffer = new byte[buffersize];
- int available = 0;
- while ((available = is.read(buffer)) >= 0) {
- os.write(buffer, 0, available);
- }
- return os.toByteArray();
- } catch (IOException e) {
- Log.w("SDL Service", "Can't read icon file", e);
- return null;
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
-
- /* ***********************************************************************************************************************************************************************
- * ******************************************************* Methods for IProxyListenerALM *******************************************************************************
- *************************************************************************************************************************************************************************/
-
- @Override
- public void onOnHMIStatus(OnHMIStatus notification) {
-
- switch(notification.getHmiLevel()) {
- case HMI_FULL:
- Log.i(TAG, "HMI_FULL");
- //When we get this notification it means we have main access to the SDL System
- Intent start = new Intent(this,MainActivity.class);
- start.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP + Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(start);
-
- if (notification.getFirstRun()) {
- // send welcome message if applicable
- try {
- proxy.show(APP_NAME + " this is the first", "show command", TextAlignment.CENTERED, autoIncCorrId++);
- }catch (SdlException e) {
- e.printStackTrace();
- }
-
- // TODO this is where the developer should send addcommands and subsribe to buttons
- }else { //If this isn't our first time receiving HMI_FULL
- try {
- proxy.show("SdlProxy is", "Alive", TextAlignment.CENTERED, autoIncCorrId++);
- } catch (SdlException e) {
- e.printStackTrace();
- }
- }
- break;
- case HMI_LIMITED:
- Log.i(TAG, "HMI_LIMITED");
- break;
- case HMI_BACKGROUND:
- Log.i(TAG, "HMI_BACKGROUND");
- break;
- case HMI_NONE:
- Log.i(TAG, "HMI_NONE");
- //Since the first HMI status sent to an app is HMI_NONE we take this as we have just established a connection and we want to send our icon
- if(notification.getFirstRun()){
- try {
- sendIcon();
- } catch (SdlException e) {
- e.printStackTrace();
- }
- }
- break;
- default:
- return;
- }
-
- }
-
-
- @Override
- public void onProxyClosed(String info, Exception e, SdlDisconnectedReason reason) {
- //After we are asked to close the proxy we should shut down our service
- stopSelf();
- }
-
-
- @Override
- public void onError(String info, Exception e) {
-
-
- }
-
-
- @Override
- public void onGenericResponse(GenericResponse response) {
-
-
- }
-
-
- @Override
- public void onOnCommand(OnCommand notification) {
-
-
- }
-
-
- @Override
- public void onAddCommandResponse(AddCommandResponse response) {
-
-
- }
-
-
- @Override
- public void onAddSubMenuResponse(AddSubMenuResponse response) {
-
-
- }
-
-
- @Override
- public void onCreateInteractionChoiceSetResponse(
- CreateInteractionChoiceSetResponse response) {
-
-
- }
-
-
- @Override
- public void onAlertResponse(AlertResponse response) {
-
-
- }
-
-
- @Override
- public void onDeleteCommandResponse(DeleteCommandResponse response) {
-
-
- }
-
-
- @Override
- public void onDeleteInteractionChoiceSetResponse(
- DeleteInteractionChoiceSetResponse response) {
-
-
- }
-
-
- @Override
- public void onDeleteSubMenuResponse(DeleteSubMenuResponse response) {
-
-
- }
-
-
- @Override
- public void onPerformInteractionResponse(PerformInteractionResponse response) {
-
-
- }
-
-
- @Override
- public void onResetGlobalPropertiesResponse(
- ResetGlobalPropertiesResponse response) {
-
-
- }
-
-
- @Override
- public void onSetGlobalPropertiesResponse(
- SetGlobalPropertiesResponse response) {
-
-
- }
-
-
- @Override
- public void onSetMediaClockTimerResponse(SetMediaClockTimerResponse response) {
-
-
- }
-
-
- @Override
- public void onShowResponse(ShowResponse response) {
-
-
- }
-
-
- @Override
- public void onSpeakResponse(SpeakResponse response) {
-
-
- }
-
-
- @Override
- public void onOnButtonEvent(OnButtonEvent notification) {
-
-
- }
-
-
- @Override
- public void onOnButtonPress(OnButtonPress notification) {
-
-
- }
-
-
- @Override
- public void onSubscribeButtonResponse(SubscribeButtonResponse response) {
-
-
- }
-
-
- @Override
- public void onUnsubscribeButtonResponse(UnsubscribeButtonResponse response) {
-
-
- }
-
-
- @Override
- public void onOnPermissionsChange(OnPermissionsChange notification) {
-
-
- }
-
-
- @Override
- public void onSubscribeVehicleDataResponse(
- SubscribeVehicleDataResponse response) {
-
-
- }
-
-
- @Override
- public void onUnsubscribeVehicleDataResponse(
- UnsubscribeVehicleDataResponse response) {
-
-
- }
-
-
- @Override
- public void onGetVehicleDataResponse(GetVehicleDataResponse response) {
-
-
- }
-
-
- @Override
- public void onOnVehicleData(OnVehicleData notification) {
-
-
- }
-
-
- @Override
- public void onPerformAudioPassThruResponse(
- PerformAudioPassThruResponse response) {
-
-
- }
-
-
- @Override
- public void onEndAudioPassThruResponse(EndAudioPassThruResponse response) {
-
-
- }
-
-
- @Override
- public void onOnAudioPassThru(OnAudioPassThru notification) {
-
-
- }
-
-
- @Override
- public void onPutFileResponse(PutFileResponse response) {
-
-
- }
-
-
- @Override
- public void onDeleteFileResponse(DeleteFileResponse response) {
-
-
- }
-
-
- @Override
- public void onListFilesResponse(ListFilesResponse response) {
-
-
- }
-
-
- @Override
- public void onSetAppIconResponse(SetAppIconResponse response) {
-
-
- }
-
-
- @Override
- public void onScrollableMessageResponse(ScrollableMessageResponse response) {
-
-
- }
-
-
- @Override
- public void onChangeRegistrationResponse(ChangeRegistrationResponse response) {
-
-
- }
-
-
- @Override
- public void onSetDisplayLayoutResponse(SetDisplayLayoutResponse response) {
-
-
- }
-
-
- @Override
- public void onOnLanguageChange(OnLanguageChange notification) {
-
-
- }
-
-
- @Override
- public void onOnHashChange(OnHashChange notification) {
-
-
- }
-
-
- @Override
- public void onSliderResponse(SliderResponse response) {
-
-
- }
-
-
- @Override
- public void onOnDriverDistraction(OnDriverDistraction notification) {
-
-
- }
-
-
- @Override
- public void onOnTBTClientState(OnTBTClientState notification) {
-
-
- }
-
-
- @Override
- public void onOnSystemRequest(OnSystemRequest notification) {
-
-
- }
-
-
- @Override
- public void onSystemRequestResponse(SystemRequestResponse response) {
-
- }
-
-
- @Override
- public void onOnKeyboardInput(OnKeyboardInput notification) {
-
- }
-
-
- @Override
- public void onOnTouchEvent(OnTouchEvent notification) {
-
- }
-
-
- @Override
- public void onDiagnosticMessageResponse(DiagnosticMessageResponse response) {
-
- }
-
-
- @Override
- public void onReadDIDResponse(ReadDIDResponse response) {
-
- }
-
-
- @Override
- public void onGetDTCsResponse(GetDTCsResponse response) {
-
- }
-
-
- @Override
- public void onOnLockScreenNotification(OnLockScreenStatus notification) {
-
- }
-
-
- @Override
- public void onOnStreamRPC(OnStreamRPC notification) {
- // TODO Auto-generated method stub
-
- }
-
-
- @Override
- public void onStreamRPCResponse(StreamRPCResponse response) {
- // TODO Auto-generated method stub
-
- }
-
-
- @Override
- public void onDialNumberResponse(DialNumberResponse response) {
- // TODO Auto-generated method stub
-
- }
-
-
- @Override
- public void onSendLocationResponse(SendLocationResponse response) {
- // TODO Auto-generated method stub
-
- }
-
-
- @Override
- public void onServiceEnded(OnServiceEnded serviceEnded) {
- // TODO Auto-generated method stub
-
- }
-
-
- @Override
- public void onServiceNACKed(OnServiceNACKed serviceNACKed) {
- // TODO Auto-generated method stub
-
- }
-
-
- @Override
- public void onShowConstantTbtResponse(ShowConstantTbtResponse response) {
- // TODO Auto-generated method stub
-
- }
-
-
- @Override
- public void onAlertManeuverResponse(AlertManeuverResponse response) {
- // TODO Auto-generated method stub
-
- }
-
-
- @Override
- public void onUpdateTurnListResponse(UpdateTurnListResponse response) {
- // TODO Auto-generated method stub
-
- }
-
-
- @Override
- public void onServiceDataACK() {
- // TODO Auto-generated method stub
-
- }
-
-}
diff --git a/sdl_android_lib/src/com/smartdevicelink/SdlConnection/ISdlConnectionListener.java b/sdl_android_lib/src/com/smartdevicelink/SdlConnection/ISdlConnectionListener.java
index 2f9eff800..f4b4c43d9 100644
--- a/sdl_android_lib/src/com/smartdevicelink/SdlConnection/ISdlConnectionListener.java
+++ b/sdl_android_lib/src/com/smartdevicelink/SdlConnection/ISdlConnectionListener.java
@@ -15,7 +15,7 @@ public interface ISdlConnectionListener {
byte sessionID, byte version, String correlationID);
public void onProtocolSessionStarted(SessionType sessionType,
- byte sessionID, byte version, String correlationID, int hashID);
+ byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted);
public void onProtocolSessionEnded(SessionType sessionType,
byte sessionID, String correlationID);
@@ -27,5 +27,5 @@ public interface ISdlConnectionListener {
public void onHeartbeatTimedOut(byte sessionID);
- public void onProtocolServiceDataACK(SessionType sessionType, byte sessionID);
+ public void onProtocolServiceDataACK(SessionType sessionType, int dataSize, byte sessionID);
}
diff --git a/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlConnection.java b/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlConnection.java
index 60d6e5362..c9a5c13f2 100644
--- a/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlConnection.java
+++ b/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlConnection.java
@@ -1,20 +1,11 @@
package com.smartdevicelink.SdlConnection;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
import java.util.concurrent.CopyOnWriteArrayList;
-import android.annotation.SuppressLint;
import android.content.ComponentName;
-import android.os.Build;
-import android.util.Log;
-import android.view.Surface;
+import android.util.Log;
-import com.smartdevicelink.encoder.SdlEncoder;
import com.smartdevicelink.exception.SdlException;
import com.smartdevicelink.protocol.AbstractProtocol;
import com.smartdevicelink.protocol.IProtocolListener;
@@ -22,14 +13,22 @@ import com.smartdevicelink.protocol.ProtocolMessage;
import com.smartdevicelink.protocol.SdlPacket;
import com.smartdevicelink.protocol.WiProProtocol;
import com.smartdevicelink.protocol.enums.SessionType;
-import com.smartdevicelink.proxy.RPCRequest;
-import com.smartdevicelink.streaming.IStreamListener;
-import com.smartdevicelink.streaming.StreamPacketizer;
-import com.smartdevicelink.streaming.StreamRPCPacketizer;
-import com.smartdevicelink.transport.*;
+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;
-public class SdlConnection implements IProtocolListener, ITransportListener, IStreamListener {
+public class SdlConnection implements IProtocolListener, ITransportListener {
private static final String TAG = "SdlConnection";
@@ -37,10 +36,7 @@ public class SdlConnection implements IProtocolListener, ITransportListener, ISt
AbstractProtocol _protocol = null;
ISdlConnectionListener _connectionListener = null;
- StreamRPCPacketizer mRPCPacketizer = null;
- StreamPacketizer mVideoPacketizer = null;
- StreamPacketizer mAudioPacketizer = null;
- SdlEncoder mSdlEncoder = null;
+
// Thread safety locks
static Object TRANSPORT_REFERENCE_LOCK = new Object();
@@ -106,7 +102,6 @@ public class SdlConnection implements IProtocolListener, ITransportListener, ISt
cachedMultiConfig.setService(null);
}
enableLegacyMode(true,TransportType.BLUETOOTH); //We will use legacy bluetooth connection for this attempt
- Log.d(TAG, "Legacy transport : " + legacyTransportRequest);
}
}
@@ -114,7 +109,6 @@ public class SdlConnection implements IProtocolListener, ITransportListener, ISt
(transportConfig.getTransportType() == TransportType.MULTIPLEX)){
_transport = new MultiplexTransport((MultiplexTransportConfig)transportConfig,this);
}else if(isLegacyModeEnabled() && legacyTransportRequest == TransportType.BLUETOOTH){
- Log.d(TAG, "Creating legacy bluetooth connection");
_transport = new BTTransport(this, true);
}else if(transportConfig.getTransportType() == TransportType.BLUETOOTH){
_transport = new BTTransport(this,((BTTransportConfig)transportConfig).getKeepSocketActive());
@@ -261,8 +255,8 @@ public class SdlConnection implements IProtocolListener, ITransportListener, ISt
@Override
public void onProtocolSessionStarted(SessionType sessionType,
- byte sessionID, byte version, String correlationID, int hashID) {
- _connectionListener.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID);
+ byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) {
+ _connectionListener.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID, isEncrypted);
}
@Override
@@ -292,201 +286,11 @@ public class SdlConnection implements IProtocolListener, ITransportListener, ISt
public TransportType getCurrentTransportType() {
return _transport.getTransportType();
}
- public void startStream(InputStream is, SessionType sType, byte rpcSessionID) throws IOException {
- if (sType.equals(SessionType.NAV))
- {
- mVideoPacketizer = new StreamPacketizer(this, is, sType, rpcSessionID);
- mVideoPacketizer.sdlConnection = this;
- mVideoPacketizer.start();
- }
- else if (sType.equals(SessionType.PCM))
- {
- mAudioPacketizer = new StreamPacketizer(this, is, sType, rpcSessionID);
- mAudioPacketizer.sdlConnection = this;
- mAudioPacketizer.start();
- }
- }
-
- @SuppressLint("NewApi") public OutputStream startStream(SessionType sType, byte rpcSessionID) throws IOException {
- OutputStream os = new PipedOutputStream();
- InputStream is = null;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
- is = new PipedInputStream((PipedOutputStream) os, BUFF_READ_SIZE);
- } else {
- is = new PipedInputStream((PipedOutputStream) os);
- }
- if (sType.equals(SessionType.NAV))
- {
- mVideoPacketizer = new StreamPacketizer(this, is, sType, rpcSessionID);
- mVideoPacketizer.sdlConnection = this;
- mVideoPacketizer.start();
- }
- else if (sType.equals(SessionType.PCM))
- {
- mAudioPacketizer = new StreamPacketizer(this, is, sType, rpcSessionID);
- mAudioPacketizer.sdlConnection = this;
- mAudioPacketizer.start();
- }
- else
- {
- os.close();
- is.close();
- return null;
- }
- return os;
- }
-
- 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);
- mRPCPacketizer.start();
- } catch (Exception e) {
- Log.e("SdlConnection", "Unable to start streaming:" + e.toString());
- }
- }
-
- public OutputStream startRPCStream(RPCRequest request, SessionType sType, byte rpcSessionID, byte wiproVersion) {
- try {
- OutputStream os = new PipedOutputStream();
- InputStream is = new PipedInputStream((PipedOutputStream) os);
- mRPCPacketizer = new StreamRPCPacketizer(null, this, is, request, sType, rpcSessionID, wiproVersion, 0);
- mRPCPacketizer.start();
- return os;
- } catch (Exception e) {
- Log.e("SdlConnection", "Unable to start streaming:" + e.toString());
- }
- return null;
- }
-
- public void pauseRPCStream()
- {
- if (mRPCPacketizer != null)
- {
- mRPCPacketizer.pause();
- }
- }
-
- public void resumeRPCStream()
- {
- if (mRPCPacketizer != null)
- {
- mRPCPacketizer.resume();
- }
- }
-
- public void stopRPCStream()
- {
- if (mRPCPacketizer != null)
- {
- mRPCPacketizer.stop();
- }
- }
-
- public boolean stopAudioStream()
- {
- if (mAudioPacketizer != null)
- {
- mAudioPacketizer.stop();
- return true;
- }
- return false;
- }
-
- public boolean stopVideoStream()
- {
- if (mVideoPacketizer != null)
- {
- mVideoPacketizer.stop();
- return true;
- }
- return false;
- }
-
- public boolean pauseAudioStream()
- {
- if (mAudioPacketizer != null)
- {
- mAudioPacketizer.pause();
- return true;
- }
- return false;
- }
-
- public boolean pauseVideoStream()
- {
- if (mVideoPacketizer != null)
- {
- mVideoPacketizer.pause();
- return true;
- }
- return false;
- }
-
- public boolean resumeAudioStream()
- {
- if (mAudioPacketizer != null)
- {
- mAudioPacketizer.resume();
- return true;
- }
- return false;
- }
-
- public boolean resumeVideoStream()
- {
- if (mVideoPacketizer != null)
- {
- mVideoPacketizer.resume();
- return true;
- }
- return false;
- }
-
- public Surface createOpenGLInputSurface(int frameRate, int iFrameInterval, int width,
- int height, int bitrate, SessionType sType, byte rpcSessionID) {
- try {
- PipedOutputStream stream = (PipedOutputStream) startStream(sType, rpcSessionID);
- if (stream == null) return null;
- mSdlEncoder = new SdlEncoder();
- mSdlEncoder.setFrameRate(frameRate);
- mSdlEncoder.setFrameInterval(iFrameInterval);
- mSdlEncoder.setFrameWidth(width);
- mSdlEncoder.setFrameHeight(height);
- mSdlEncoder.setBitrate(bitrate);
- mSdlEncoder.setOutputStream(stream);
- } catch (IOException e) {
- return null;
- }
- 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 startService (SessionType sessionType, byte sessionID) {
+ public void startService (SessionType sessionType, byte sessionID, boolean isEncrypted) {
synchronized(PROTOCOL_REFERENCE_LOCK){
if(_protocol != null){
- _protocol.StartProtocolService(sessionType, sessionID);
+ _protocol.StartProtocolService(sessionType, sessionID, isEncrypted);
}
}
}
@@ -524,7 +328,7 @@ public class SdlConnection implements IProtocolListener, ITransportListener, ISt
}
- private SdlSession findSessionById(byte id) {
+ public SdlSession findSessionById(byte id) {
for (SdlSession listener : listenerList) {
if (listener.getSessionId() == id) {
return listener;
@@ -556,7 +360,6 @@ public class SdlConnection implements IProtocolListener, ITransportListener, ISt
} catch (SdlException e) {
e.printStackTrace();
}
- ((MultiplexTransport)_transport).forceHardwareConnectEvent(TransportType.BLUETOOTH);
}
}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) {
@@ -594,17 +397,18 @@ public class SdlConnection implements IProtocolListener, ITransportListener, ISt
@Override
public void onProtocolSessionStarted(SessionType sessionType,
- byte sessionID, byte version, String correlationID, int hashID) {
+ 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);
+ session.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID, isEncrypted);
break;
}
}
- if (sessionType.equals(SessionType.NAV) || sessionType.equals(SessionType.PCM)){
+
+ if (sessionType.equals(SessionType.NAV) || sessionType.equals(SessionType.PCM) || isEncrypted){
SdlSession session = findSessionById(sessionID);
if (session != null) {
- session.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID);
+ session.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID, isEncrypted);
}
}
}
@@ -638,8 +442,8 @@ public class SdlConnection implements IProtocolListener, ITransportListener, ISt
public void onHeartbeatTimedOut(byte sessionID) {
SdlSession session = findSessionById(sessionID);
if (session != null) {
- session.onHeartbeatTimedOut(sessionID);
- }
+ session.onHeartbeatTimedOut(sessionID);
+ }
}
@Override
@@ -647,26 +451,17 @@ public class SdlConnection implements IProtocolListener, ITransportListener, ISt
SdlSession session = findSessionById(sessionID);
if (session != null) {
session.onProtocolSessionEndedNACKed(sessionType, sessionID, correlationID);
- }
+ }
}
@Override
- public void onProtocolServiceDataACK(SessionType sessionType,
- byte sessionID) {
- // TODO Auto-generated method stub
-
- }
-
- }
-
- @Override
- public void onProtocolServiceDataACK(SessionType sessionType,
- byte sessionID) {
+ public void onProtocolServiceDataACK(SessionType serviceType, int dataSize, byte sessionID) {
SdlSession session = findSessionById(sessionID);
if (session != null) {
- session.onProtocolServiceDataACK(sessionType, sessionID);
- }
- }
+ session.onProtocolServiceDataACK(serviceType, dataSize, sessionID);
+ }
+ }
+ }
public int getRegisterCount() {
return listenerList.size();
@@ -698,8 +493,8 @@ public class SdlConnection implements IProtocolListener, ITransportListener, ISt
}
}
- @Override
- public void onResetOutgoingHeartbeat(SessionType sessionType, byte sessionID){
+ @Override
+ public void onResetOutgoingHeartbeat(SessionType sessionType, byte sessionID){
SdlSession mySession = findSessionById(sessionID);
if (mySession == null) return;
@@ -732,20 +527,20 @@ public class SdlConnection implements IProtocolListener, ITransportListener, ISt
MultiplexTransport multi = ((MultiplexTransport)_transport);
MultiplexTransportConfig config = multi.getConfig();
ComponentName tempCompName = SdlBroadcastReceiver.consumeQueuedRouterService();
- //Log.d(TAG, "Consumed component name: " +tempCompName );
if(config.getService().equals(tempCompName)){ //If this is the same service that just connected that we are already looking at. Attempt to reconnect
- boolean forced = multi.forceHardwareConnectEvent(TransportType.BLUETOOTH);
-
- if(!forced && multi.isDisconnecting() ){ //If we aren't able to force a connection it means the
- //Log.d(TAG, "Recreating our multiplexing transport");
+ if(!multi.getIsConnected() && multi.isDisconnecting() ){ //If we aren't able to force a connection it means the
_transport = new MultiplexTransport(config,this);
- ((MultiplexTransport)_transport).forceHardwareConnectEvent(TransportType.BLUETOOTH);
- }//else{Log.w(TAG, "Guess we're just calling it a day");}
+ try {
+ startTransport();
+ } catch (SdlException e) {
+ e.printStackTrace();
+ }
+ }
}else if(tempCompName!=null){
//We have a conflicting service request
Log.w(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());
+ //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);
@@ -754,7 +549,6 @@ public class SdlConnection implements IProtocolListener, ITransportListener, ISt
} catch (SdlException e) {
e.printStackTrace();
}
- ((MultiplexTransport)_transport).forceHardwareConnectEvent(TransportType.BLUETOOTH);
}
}else if(_transport.getTransportType()==TransportType.BLUETOOTH
@@ -790,12 +584,15 @@ public class SdlConnection implements IProtocolListener, ITransportListener, ISt
}
}
-
-
@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/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlSession.java b/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlSession.java
index 7f1359963..09f029fca 100644
--- a/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlSession.java
+++ b/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlSession.java
@@ -1,25 +1,42 @@
package com.smartdevicelink.SdlConnection;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.util.List;
+import java.util.ListIterator;
import java.util.concurrent.CopyOnWriteArrayList;
+import android.annotation.SuppressLint;
+import android.os.Build;
import android.util.Log;
+import android.view.Surface;
+import com.smartdevicelink.encoder.SdlEncoder;
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.security.ISecurityInitializedListener;
+import com.smartdevicelink.security.SdlSecurityBase;
+import com.smartdevicelink.streaming.IStreamListener;
+import com.smartdevicelink.streaming.StreamPacketizer;
+import com.smartdevicelink.streaming.StreamRPCPacketizer;
import com.smartdevicelink.transport.BaseTransportConfig;
import com.smartdevicelink.transport.MultiplexTransport;
import com.smartdevicelink.transport.enums.TransportType;
-public class SdlSession implements ISdlConnectionListener, IHeartbeatMonitorListener {
+public class SdlSession implements ISdlConnectionListener, IHeartbeatMonitorListener, IStreamListener, ISecurityInitializedListener {
private static CopyOnWriteArrayList<SdlConnection> shareConnections = new CopyOnWriteArrayList<SdlConnection>();
+ private CopyOnWriteArrayList<SessionType> encryptedServices = new CopyOnWriteArrayList<SessionType>();
SdlConnection _sdlConnection = null;
private byte sessionId;
- @SuppressWarnings("unused")
private byte wiproProcolVer;
private ISdlConnectionListener sessionListener;
private BaseTransportConfig transportConfig;
@@ -27,10 +44,15 @@ public class SdlSession implements ISdlConnectionListener, IHeartbeatMonitorList
IHeartbeatMonitor _incomingHeartbeatMonitor = null;
private static final String TAG = "SdlSession";
private LockScreenManager lockScreenMan = new LockScreenManager();
+ private SdlSecurityBase sdlSecurity = null;
+ StreamRPCPacketizer mRPCPacketizer = null;
+ StreamPacketizer mVideoPacketizer = null;
+ StreamPacketizer mAudioPacketizer = null;
+ SdlEncoder mSdlEncoder = null;
+ private final static int BUFF_READ_SIZE = 1024;
private int sessionHashId = 0;
-
public static SdlSession createSession(byte wiproVersion, ISdlConnectionListener listener, BaseTransportConfig btConfig) {
SdlSession session = new SdlSession();
@@ -84,6 +106,12 @@ public class SdlSession implements ISdlConnectionListener, IHeartbeatMonitorList
}
public void close() {
+ if (sdlSecurity != null)
+ {
+ sdlSecurity.resetParams();
+ sdlSecurity.shutDown();
+ }
+
if (_sdlConnection != null) { //sessionId == 0 means session is not started.
_sdlConnection.unregisterSession(this);
@@ -95,6 +123,259 @@ public class SdlSession implements ISdlConnectionListener, IHeartbeatMonitorList
}
}
+ public void startStream(InputStream is, SessionType sType, byte rpcSessionID) throws IOException {
+ if (sType.equals(SessionType.NAV))
+ {
+ mVideoPacketizer = new StreamPacketizer(this, is, sType, rpcSessionID, this);
+ mVideoPacketizer.sdlConnection = this.getSdlConnection();
+ mVideoPacketizer.start();
+ }
+ else if (sType.equals(SessionType.PCM))
+ {
+ mAudioPacketizer = new StreamPacketizer(this, is, sType, rpcSessionID, this);
+ mAudioPacketizer.sdlConnection = this.getSdlConnection();
+ mAudioPacketizer.start();
+ }
+ }
+
+ @SuppressLint("NewApi")
+ public OutputStream startStream(SessionType sType, byte rpcSessionID) throws IOException {
+ OutputStream os = new PipedOutputStream();
+ InputStream is = null;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
+ is = new PipedInputStream((PipedOutputStream) os, BUFF_READ_SIZE);
+ } else {
+ is = new PipedInputStream((PipedOutputStream) os);
+ }
+ if (sType.equals(SessionType.NAV))
+ {
+ mVideoPacketizer = new StreamPacketizer(this, is, sType, rpcSessionID, this);
+ mVideoPacketizer.sdlConnection = this.getSdlConnection();
+ 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 void startRPCStream(InputStream is, RPCRequest request, SessionType sType, byte rpcSessionID, byte wiproVersion) {
+ try {
+ mRPCPacketizer = new StreamRPCPacketizer(null, this, is, request, sType, rpcSessionID, wiproVersion, 0, this);
+ mRPCPacketizer.start();
+ } catch (Exception e) {
+ Log.e("SdlConnection", "Unable to start streaming:" + e.toString());
+ }
+ }
+
+ public OutputStream startRPCStream(RPCRequest request, SessionType sType, byte rpcSessionID, byte wiproVersion) {
+ try {
+ OutputStream os = new PipedOutputStream();
+ InputStream is = new PipedInputStream((PipedOutputStream) os);
+ mRPCPacketizer = new StreamRPCPacketizer(null, this, is, request, sType, rpcSessionID, wiproVersion, 0, this);
+ mRPCPacketizer.start();
+ return os;
+ } catch (Exception e) {
+ Log.e("SdlConnection", "Unable to start streaming:" + e.toString());
+ }
+ return null;
+ }
+
+ public void pauseRPCStream()
+ {
+ if (mRPCPacketizer != null)
+ {
+ mRPCPacketizer.pause();
+ }
+ }
+
+ public void resumeRPCStream()
+ {
+ if (mRPCPacketizer != null)
+ {
+ mRPCPacketizer.resume();
+ }
+ }
+
+ public void stopRPCStream()
+ {
+ if (mRPCPacketizer != null)
+ {
+ mRPCPacketizer.stop();
+ }
+ }
+
+ public boolean stopAudioStream()
+ {
+ if (mAudioPacketizer != null)
+ {
+ mAudioPacketizer.stop();
+ return true;
+ }
+ return false;
+ }
+
+ public boolean stopVideoStream()
+ {
+ if (mVideoPacketizer != null)
+ {
+ mVideoPacketizer.stop();
+ return true;
+ }
+ return false;
+ }
+
+ public boolean pauseAudioStream()
+ {
+ if (mAudioPacketizer != null)
+ {
+ mAudioPacketizer.pause();
+ return true;
+ }
+ return false;
+ }
+
+ public boolean pauseVideoStream()
+ {
+ if (mVideoPacketizer != null)
+ {
+ mVideoPacketizer.pause();
+ return true;
+ }
+ return false;
+ }
+
+ public boolean resumeAudioStream()
+ {
+ if (mAudioPacketizer != null)
+ {
+ mAudioPacketizer.resume();
+ return true;
+ }
+ return false;
+ }
+
+ public boolean resumeVideoStream()
+ {
+ if (mVideoPacketizer != null)
+ {
+ mVideoPacketizer.resume();
+ return true;
+ }
+ return false;
+ }
+
+ public Surface createOpenGLInputSurface(int frameRate, int iFrameInterval, int width,
+ int height, int bitrate, SessionType sType, byte rpcSessionID) {
+ try {
+ PipedOutputStream stream = (PipedOutputStream) startStream(sType, rpcSessionID);
+ if (stream == null) return null;
+ mSdlEncoder = new SdlEncoder();
+ mSdlEncoder.setFrameRate(frameRate);
+ mSdlEncoder.setFrameInterval(iFrameInterval);
+ mSdlEncoder.setFrameWidth(width);
+ mSdlEncoder.setFrameHeight(height);
+ mSdlEncoder.setBitrate(bitrate);
+ mSdlEncoder.setOutputStream(stream);
+ } catch (IOException e) {
+ return null;
+ }
+ return mSdlEncoder.prepareEncoder();
+ }
+
+ public void startEncoder () {
+ if(mSdlEncoder != null) {
+ mSdlEncoder.startEncoder();
+ }
+ }
+
+ public void releaseEncoder() {
+ if(mSdlEncoder != null) {
+ mSdlEncoder.releaseEncoder();
+ }
+ }
+
+ public void drainEncoder(boolean endOfStream) {
+ if(mSdlEncoder != null) {
+ mSdlEncoder.drainEncoder(endOfStream);
+ }
+ }
+
+ @Override
+ public void sendStreamPacket(ProtocolMessage pm) {
+ sendMessage(pm);
+ }
+
+ public void setSdlSecurity(SdlSecurityBase sec) {
+ sdlSecurity = sec;
+ }
+
+ public SdlSecurityBase getSdlSecurity() {
+ return sdlSecurity;
+ }
+
+ public void startService (SessionType serviceType, byte sessionID, boolean isEncrypted) {
+ if (_sdlConnection == null)
+ return;
+
+ if (isEncrypted)
+ {
+ if (sdlSecurity != null)
+ {
+ List<SessionType> serviceList = sdlSecurity.getServiceList();
+ if (!serviceList.contains(serviceType))
+ serviceList.add(serviceType);
+
+ sdlSecurity.initialize();
+ }
+ return;
+ }
+ _sdlConnection.startService(serviceType, sessionID, isEncrypted);
+ }
+
+ public void endService (SessionType serviceType, byte sessionID) {
+ if (_sdlConnection == null)
+ return;
+ _sdlConnection.endService(serviceType, sessionID);
+ }
+
+ private void processControlService(ProtocolMessage msg) {
+ if (sdlSecurity == null)
+ return;
+ int ilen = msg.getData().length - 12;
+ byte[] data = new byte[ilen];
+ System.arraycopy(msg.getData(), 12, data, 0, ilen);
+
+ byte[] dataToRead = new byte[4096];
+
+ Integer iNumBytes = sdlSecurity.runHandshake(data, dataToRead);
+
+ if (iNumBytes == null || iNumBytes <= 0)
+ return;
+
+ byte[] returnBytes = new byte[iNumBytes];
+ System.arraycopy(dataToRead, 0, returnBytes, 0, iNumBytes);
+ ProtocolMessage protocolMessage = new ProtocolMessage();
+ protocolMessage.setSessionType(SessionType.CONTROL);
+ protocolMessage.setData(returnBytes);
+ protocolMessage.setFunctionID(0x01);
+ protocolMessage.setVersion(wiproProcolVer);
+ protocolMessage.setSessionID(getSessionId());
+
+ //sdlSecurity.hs();
+
+ sendMessage(protocolMessage);
+ }
+
public String getBroadcastComment(BaseTransportConfig myTransport) {
SdlConnection connection = null;
if (myTransport.shareConnection()) {
@@ -153,6 +434,10 @@ public class SdlSession implements ISdlConnectionListener, IHeartbeatMonitorList
return false;
return _sdlConnection != null && _sdlConnection.getIsConnected();
}
+
+ public boolean isServiceProtected(SessionType sType) {
+ return encryptedServices.contains(sType);
+ }
@Override
public void onTransportDisconnected(String info) {
@@ -166,6 +451,11 @@ public class SdlSession implements ISdlConnectionListener, IHeartbeatMonitorList
@Override
public void onProtocolMessageReceived(ProtocolMessage msg) {
+ if (msg.getSessionType().equals(SessionType.CONTROL)) {
+ processControlService(msg);
+ return;
+ }
+
this.sessionListener.onProtocolMessageReceived(msg);
}
@@ -178,10 +468,12 @@ public class SdlSession implements ISdlConnectionListener, IHeartbeatMonitorList
@Override
public void onProtocolSessionStarted(SessionType sessionType,
- byte sessionID, byte version, String correlationID, int hashID) {
+ byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) {
this.sessionId = sessionID;
lockScreenMan.setSessionID(sessionID);
- this.sessionListener.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID);
+ if (isEncrypted)
+ encryptedServices.addIfAbsent(sessionType);
+ this.sessionListener.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID, isEncrypted);
//if (version == 3)
initialiseSession();
if (sessionType.eq(SessionType.RPC)){
@@ -191,8 +483,9 @@ public class SdlSession implements ISdlConnectionListener, IHeartbeatMonitorList
@Override
public void onProtocolSessionEnded(SessionType sessionType, byte sessionID,
- String correlationID) {
+ String correlationID) {
this.sessionListener.onProtocolSessionEnded(sessionType, sessionID, correlationID);
+ encryptedServices.remove(sessionType);
}
@Override
@@ -230,13 +523,13 @@ public class SdlSession implements ISdlConnectionListener, IHeartbeatMonitorList
return connection;
}
- @Override
+ @Override
public void onProtocolSessionStartedNACKed(SessionType sessionType,
- byte sessionID, byte version, String correlationID) {
+ byte sessionID, byte version, String correlationID) {
this.sessionListener.onProtocolSessionStartedNACKed(sessionType, sessionID, version, correlationID);
}
- @Override
+ @Override
public void onProtocolSessionEndedNACKed(SessionType sessionType,
byte sessionID, String correlationID) {
this.sessionListener.onProtocolSessionEndedNACKed(sessionType, sessionID, correlationID);
@@ -244,8 +537,29 @@ public class SdlSession implements ISdlConnectionListener, IHeartbeatMonitorList
}
@Override
- public void onProtocolServiceDataACK(SessionType sessionType, byte sessionID) {
- this.sessionListener.onProtocolServiceDataACK(sessionType, sessionID);
+ public void onProtocolServiceDataACK(SessionType sessionType, int dataSize, byte sessionID) {
+ this.sessionListener.onProtocolServiceDataACK(sessionType, dataSize, sessionID);
+ }
+
+ @Override
+ public void onSecurityInitialized() {
+
+ if (_sdlConnection != null && sdlSecurity != null)
+ {
+ List<SessionType> list = sdlSecurity.getServiceList();
+
+ SessionType service;
+ ListIterator<SessionType> iter = list.listIterator();
+
+ while (iter.hasNext()) {
+ service = iter.next();
+
+ if (service != null)
+ _sdlConnection.startService(service, getSessionId(), true);
+
+ iter.remove();
+ }
+ }
}
public void clearConnection(){
diff --git a/sdl_android_lib/src/com/smartdevicelink/protocol/AbstractProtocol.java b/sdl_android_lib/src/com/smartdevicelink/protocol/AbstractProtocol.java
index bcc2e1df5..5cdf06e95 100644
--- a/sdl_android_lib/src/com/smartdevicelink/protocol/AbstractProtocol.java
+++ b/sdl_android_lib/src/com/smartdevicelink/protocol/AbstractProtocol.java
@@ -2,8 +2,6 @@ package com.smartdevicelink.protocol;
import com.smartdevicelink.protocol.WiProProtocol.MessageFrameAssembler;
import com.smartdevicelink.protocol.enums.SessionType;
-import com.smartdevicelink.trace.SdlTrace;
-import com.smartdevicelink.trace.enums.InterfaceActivityDirection;
public abstract class AbstractProtocol {
private static final String SDL_LIB_TRACE_KEY = "42baba60-eb57-11df-98cf-0800200c9a66";
@@ -40,14 +38,14 @@ public abstract class AbstractProtocol {
// session has been established.
public abstract void StartProtocolSession(SessionType sessionType);
- public abstract void StartProtocolService(SessionType sessionType, byte sessionID);
+ 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);
- public abstract void EndProtocolService(SessionType serviceType, byte sessionID);
// TODO REMOVE
// This method sets the interval at which heartbeat protocol messages will be
// sent to SDL.
@@ -68,7 +66,7 @@ public abstract class AbstractProtocol {
assembler.handleFrame(packet);
}
-
+
private synchronized void resetOutgoingHeartbeat(SessionType sessionType, byte sessionID) {
if (_protocolListener != null) {
_protocolListener.onResetOutgoingHeartbeat(sessionType,sessionID);
@@ -124,8 +122,8 @@ public abstract class AbstractProtocol {
// 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) {
- _protocolListener.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID);
+ byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) {
+ _protocolListener.onProtocolSessionStarted(sessionType, sessionID, version, correlationID, hashID, isEncrypted);
}
protected void handleProtocolSessionNACKed(SessionType sessionType,
@@ -137,16 +135,16 @@ public abstract class AbstractProtocol {
// 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) {
+ protected void handleProtocolHeartbeatACK(SessionType sessionType, byte sessionID) {
_protocolListener.onProtocolHeartbeatACK(sessionType, sessionID);
}
- protected void handleProtocolServiceDataACK(SessionType sessionType, byte sessionID) {
- _protocolListener.onProtocolServiceDataACK(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);
diff --git a/sdl_android_lib/src/com/smartdevicelink/protocol/IProtocolListener.java b/sdl_android_lib/src/com/smartdevicelink/protocol/IProtocolListener.java
index 47317a086..b54ff66c8 100644
--- a/sdl_android_lib/src/com/smartdevicelink/protocol/IProtocolListener.java
+++ b/sdl_android_lib/src/com/smartdevicelink/protocol/IProtocolListener.java
@@ -12,14 +12,14 @@ public interface IProtocolListener {
void onProtocolMessageReceived(ProtocolMessage msg);
// Called to indicate that a protocol session has been started (from either side)
- void onProtocolSessionStarted(SessionType sessionType, byte sessionID, byte version, String correlationID, int hashID);
+ void onProtocolSessionStarted(SessionType sessionType, byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted);
void onProtocolSessionNACKed(SessionType sessionType, byte sessionID, byte version, String correlationID);
// Called to indicate that a protocol session has ended (from either side)
- void onProtocolSessionEnded(SessionType sessionType, byte sessionID, String correlationID /*, String info, Exception ex*/);
+ void onProtocolSessionEnded(SessionType sessionType, byte sessionID, String correlationID /*, String info, Exception ex*/);
- void onProtocolSessionEndedNACKed(SessionType sessionType, byte sessionID, String correlationID /*, String info, Exception ex*/);
+ void onProtocolSessionEndedNACKed(SessionType sessionType, byte sessionID, String correlationID /*, String info, Exception ex*/);
void onProtocolHeartbeat(SessionType sessionType, byte sessionID);
@@ -28,7 +28,7 @@ public interface IProtocolListener {
*/
void onProtocolHeartbeatACK(SessionType sessionType, byte sessionID);
- void onProtocolServiceDataACK(SessionType sessionType, byte sessionID);
+ void onProtocolServiceDataACK(SessionType sessionType, int dataSize, byte sessionID);
void onResetOutgoingHeartbeat(SessionType sessionType, byte sessionID);
diff --git a/sdl_android_lib/src/com/smartdevicelink/protocol/ProtocolMessage.java b/sdl_android_lib/src/com/smartdevicelink/protocol/ProtocolMessage.java
index 5d0e0fc5d..99b34aff6 100644
--- a/sdl_android_lib/src/com/smartdevicelink/protocol/ProtocolMessage.java
+++ b/sdl_android_lib/src/com/smartdevicelink/protocol/ProtocolMessage.java
@@ -12,6 +12,8 @@ public class ProtocolMessage {
private int _functionID;
private int _correlationID;
private int _jsonSize;
+ private boolean payloadProtected = false;
+
int priorityCoefficient = 0;
private byte[] _data = null;
@@ -123,6 +125,15 @@ public class ProtocolMessage {
public void setJsonSize(int _jsonSize) {
this._jsonSize = _jsonSize;
}
+
+ public void setPayloadProtected(boolean bVal) {
+ payloadProtected = bVal;
+ }
+
+ public boolean getPayloadProtected() {
+ return payloadProtected;
+ }
+
/**
* Set the priority for this packet. The lower the number the higher the priority. <br>0 is the highest priority and the default.
* @param priority
diff --git a/sdl_android_lib/src/com/smartdevicelink/protocol/SdlPacket.java b/sdl_android_lib/src/com/smartdevicelink/protocol/SdlPacket.java
index f6a24d5e3..9c7a02852 100644
--- a/sdl_android_lib/src/com/smartdevicelink/protocol/SdlPacket.java
+++ b/sdl_android_lib/src/com/smartdevicelink/protocol/SdlPacket.java
@@ -13,7 +13,7 @@ public class SdlPacket implements Parcelable{
public static final int HEADER_SIZE = 12;
public static final int HEADER_SIZE_V1 = 8;//Backwards
- private static final int COMPRESSION_MASK = 0x08; //4th lowest bit
+ private static final int ENCRYPTION_MASK = 0x08; //4th lowest bit
public static final int FRAME_TYPE_CONTROL = 0x00;
public static final int FRAME_TYPE_SINGLE = 0x01;
@@ -56,7 +56,7 @@ public class SdlPacket implements Parcelable{
int version;
- boolean compression;
+ boolean encryption;
int frameType;
int serviceType;
int frameInfo;
@@ -66,11 +66,11 @@ public class SdlPacket implements Parcelable{
int priorityCoefficient;
byte[] payload = null;
- public SdlPacket(int version, boolean compression, int frameType,
+ public SdlPacket(int version, boolean encryption, int frameType,
int serviceType, int frameInfo, int sessionId,
int dataSize, int messageId, byte[] payload) {
this.version = version;
- this.compression = compression;
+ this.encryption = encryption;
this.frameType = frameType;
this.serviceType = serviceType;
this.frameInfo = frameInfo;
@@ -84,11 +84,11 @@ public class SdlPacket implements Parcelable{
}
}
- public SdlPacket(int version, boolean compression, int frameType,
+ public SdlPacket(int version, boolean encryption, int frameType,
int serviceType, int frameInfo, int sessionId,
int dataSize, int messageId, byte[] payload, int offset,int bytesToWrite) {
this.version = version;
- this.compression = compression;
+ this.encryption = encryption;
this.frameType = frameType;
this.serviceType = serviceType;
this.frameInfo = frameInfo;
@@ -114,7 +114,7 @@ public class SdlPacket implements Parcelable{
//Package only empty constructor
//TODO add defaults
this.version = 1;
- this.compression = false;
+ this.encryption = false;
this.frameType = -1; //This NEEDS to be set
this.serviceType = -1;
this.frameInfo = -1;
@@ -130,7 +130,7 @@ public class SdlPacket implements Parcelable{
*/
protected SdlPacket(SdlPacket packet){
this.version = packet.version;
- this.compression = packet.compression;
+ this.encryption = packet.encryption;
this.frameType = packet.frameType;
this.serviceType = packet.serviceType;
this.frameInfo = packet.frameInfo;
@@ -143,8 +143,8 @@ public class SdlPacket implements Parcelable{
return version;
}
- public boolean isCompression() {
- return compression;
+ public boolean isEncrypted() {
+ return encryption;
}
public FrameType getFrameType() {
@@ -186,7 +186,7 @@ public class SdlPacket implements Parcelable{
}
public byte[] constructPacket(){
- return constructPacket(version, compression, frameType,
+ return constructPacket(version, encryption, frameType,
serviceType, frameInfo, sessionId,
dataSize, messageId, payload);
}
@@ -206,7 +206,7 @@ public class SdlPacket implements Parcelable{
/**
* This method takes in the various components to the SDL packet structure and creates a new byte array that can be sent via the transport
* @param version
- * @param compression
+ * @param encryption
* @param frameType
* @param serviceType
* @param controlFrameInfo
@@ -216,7 +216,7 @@ public class SdlPacket implements Parcelable{
* @param payload
* @return
*/
- public static byte[] constructPacket(int version, boolean compression, int frameType,
+ public static byte[] constructPacket(int version, boolean encryption, int frameType,
int serviceType, int controlFrameInfo, int sessionId,
int dataSize, int messageId, byte[] payload){
ByteBuffer builder;
@@ -229,7 +229,7 @@ public class SdlPacket implements Parcelable{
break;
}
- builder.put((byte)((version<<4) + getCompressionBit(compression) + frameType));
+ builder.put((byte)((version<<4) + getEncryptionBit(encryption) + frameType));
builder.put((byte)serviceType);
builder.put((byte)controlFrameInfo);
builder.put((byte)sessionId);
@@ -254,9 +254,9 @@ public class SdlPacket implements Parcelable{
}
- public static int getCompressionBit(boolean compression){
- if(compression){
- return COMPRESSION_MASK;
+ public static int getEncryptionBit(boolean encryption){
+ if(encryption){
+ return ENCRYPTION_MASK;
}else{
return 0;
}
@@ -269,7 +269,7 @@ public class SdlPacket implements Parcelable{
StringBuilder builder = new StringBuilder();
builder.append("***** Sdl Packet ******");
builder.append( "\nVersion: " +version);
- builder.append( "\nCompression: " +compression);
+ builder.append( "\nEncryption: " +encryption);
builder.append( "\nFrameType: " +frameType);
builder.append( "\nServiceType: " +serviceType);
builder.append( "\nFrameInfo: " +frameInfo);
@@ -294,7 +294,7 @@ public class SdlPacket implements Parcelable{
//I think this is FIFO...right?
public SdlPacket(Parcel p) {
this.version = p.readInt();
- this.compression = (p.readInt() == 0) ? false : true;
+ this.encryption = (p.readInt() == 0) ? false : true;
this.frameType = p.readInt();
this.serviceType = p.readInt();
this.frameInfo = p.readInt();
@@ -318,7 +318,7 @@ public class SdlPacket implements Parcelable{
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(version);
- dest.writeInt(compression? 1 : 0);
+ dest.writeInt(encryption? 1 : 0);
dest.writeInt(frameType);
dest.writeInt(serviceType);
dest.writeInt(frameInfo);
diff --git a/sdl_android_lib/src/com/smartdevicelink/protocol/SdlPacketFactory.java b/sdl_android_lib/src/com/smartdevicelink/protocol/SdlPacketFactory.java
index 1fff2b1a2..5cc2807e8 100644
--- a/sdl_android_lib/src/com/smartdevicelink/protocol/SdlPacketFactory.java
+++ b/sdl_android_lib/src/com/smartdevicelink/protocol/SdlPacketFactory.java
@@ -10,8 +10,8 @@ public class SdlPacketFactory {
int serviceType, int frameInfo, int sessionId,
int dataSize, int messageId, byte[] payload) {
*/
- public static SdlPacket createStartSession(SessionType serviceType, int messageID, byte version, byte sessionID) {
- SdlPacket packet = new SdlPacket(version,false,SdlPacket.FRAME_TYPE_CONTROL,
+ public static SdlPacket createStartSession(SessionType serviceType, int messageID, byte version, byte sessionID, boolean encrypted) {
+ SdlPacket packet = new SdlPacket(version,encrypted,SdlPacket.FRAME_TYPE_CONTROL,
serviceType.getValue(),SdlPacket.FRAME_INFO_START_SERVICE,sessionID,
0,messageID,null);
@@ -54,26 +54,26 @@ public class SdlPacketFactory {
}
public static SdlPacket createSingleSendData(SessionType serviceType, byte sessionID,
- int dataLength, int messageID, byte version, byte[] payload) {
+ int dataLength, int messageID, byte version, byte[] payload, boolean encrypted) {
- return new SdlPacket(version,false,SdlPacket.FRAME_TYPE_SINGLE,
+ return new SdlPacket(version,encrypted,SdlPacket.FRAME_TYPE_SINGLE,
serviceType.getValue(),0,sessionID,
payload.length,messageID,payload);
}
public static SdlPacket createMultiSendDataFirst(SessionType serviceType, byte sessionID,
- int messageID, byte version, byte[] payload) {
+ int messageID, byte version, byte[] payload, boolean encrypted) {
- return new SdlPacket(version,false,SdlPacket.FRAME_TYPE_FIRST,
+ return new SdlPacket(version,encrypted,SdlPacket.FRAME_TYPE_FIRST,
serviceType.getValue(),0,sessionID,
8,messageID,payload);
}
public static SdlPacket createMultiSendDataRest(SessionType serviceType, byte sessionID,
- int dataLength, byte frameSequenceNumber, int messageID, byte version, byte[] payload,int offset,int length) {
+ int dataLength, byte frameSequenceNumber, int messageID, byte version, byte[] payload,int offset,int length, boolean encrypted) {
- return new SdlPacket(version,false,SdlPacket.FRAME_TYPE_CONSECUTIVE,
+ return new SdlPacket(version,encrypted,SdlPacket.FRAME_TYPE_CONSECUTIVE,
serviceType.getValue(),frameSequenceNumber,sessionID,
length,messageID,payload,offset,length);
}
diff --git a/sdl_android_lib/src/com/smartdevicelink/protocol/WiProProtocol.java b/sdl_android_lib/src/com/smartdevicelink/protocol/WiProProtocol.java
index 284f04574..885be58b3 100644
--- a/sdl_android_lib/src/com/smartdevicelink/protocol/WiProProtocol.java
+++ b/sdl_android_lib/src/com/smartdevicelink/protocol/WiProProtocol.java
@@ -3,8 +3,15 @@ package com.smartdevicelink.protocol;
import java.io.ByteArrayOutputStream;
import java.util.Hashtable;
-import com.smartdevicelink.exception.*;
-import com.smartdevicelink.protocol.enums.*;
+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.FrameDataControlFrameType;
+import com.smartdevicelink.protocol.enums.FrameType;
+import com.smartdevicelink.protocol.enums.MessageType;
+import com.smartdevicelink.protocol.enums.SessionType;
+import com.smartdevicelink.security.SdlSecurityBase;
import com.smartdevicelink.util.BitConverter;
import com.smartdevicelink.util.DebugTool;
@@ -19,7 +26,8 @@ public class WiProProtocol extends AbstractProtocol {
int hashID = 0;
int messageID = 0;
-
+ SdlConnection sdlconn = null;
+
@SuppressWarnings("unused")
private int _heartbeatSendInterval_ms = 0;
@SuppressWarnings("unused")
@@ -36,13 +44,18 @@ public class WiProProtocol extends AbstractProtocol {
public WiProProtocol(IProtocolListener protocolListener) {
super(protocolListener);
+
+ if (protocolListener instanceof SdlConnection)
+ {
+ sdlconn = (SdlConnection) protocolListener;
+ }
} // end-ctor
public byte getVersion() {
return this._version;
}
-
- public void setVersion(byte version) {
+
+ public void setVersion(byte version) {
if (version > 4) {
this._version = 4; //protect for future, proxy only supports v4 or lower
HEADER_SIZE = 12;
@@ -64,10 +77,10 @@ public class WiProProtocol extends AbstractProtocol {
HEADER_SIZE = 8;
MAX_DATA_SIZE = V1_V2_MTU_SIZE - HEADER_SIZE;
}
- }
+ }
public void StartProtocolSession(SessionType sessionType) {
- SdlPacket header = SdlPacketFactory.createStartSession(sessionType, 0x00, _version, (byte) 0x00);
+ SdlPacket header = SdlPacketFactory.createStartSession(sessionType, 0x00, _version, (byte) 0x00, false);
handlePacketToSend(header);
} // end-method
@@ -89,21 +102,56 @@ public class WiProProtocol extends AbstractProtocol {
byte[] data = null;
if (_version > 1 && sessionType != SessionType.NAV && sessionType != SessionType.PCM) {
- if (protocolMsg.getBulkData() != null) {
- data = new byte[12 + protocolMsg.getJsonSize() + protocolMsg.getBulkData().length];
+ 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()];
- BinaryFrameHeader binFrameHeader = new 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 = 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[4096];
+ 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) {
@@ -128,7 +176,8 @@ public class WiProProtocol extends AbstractProtocol {
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, _version,firstFrameData);
+
+ SdlPacket firstHeader = SdlPacketFactory.createMultiSendDataFirst(sessionType, sessionID, messageID, _version,firstFrameData,protocolMsg.getPayloadProtected());
firstHeader.setPriorityCoefficient(1+protocolMsg.priorityCoefficient);
//Send the first frame
handlePacketToSend(firstHeader);
@@ -153,28 +202,28 @@ public class WiProProtocol extends AbstractProtocol {
if (bytesToWrite > MAX_DATA_SIZE) {
bytesToWrite = MAX_DATA_SIZE;
}
- SdlPacket consecHeader = SdlPacketFactory.createMultiSendDataRest(sessionType, sessionID, bytesToWrite, frameSequenceNumber , messageID, _version,data, currentOffset, bytesToWrite);
+ SdlPacket consecHeader = SdlPacketFactory.createMultiSendDataRest(sessionType, sessionID, bytesToWrite, frameSequenceNumber , messageID, _version,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, _version,data);
+ SdlPacket header = SdlPacketFactory.createSingleSendData(sessionType, sessionID, data.length, messageID, _version,data, protocolMsg.getPayloadProtected());
header.setPriorityCoefficient(protocolMsg.priorityCoefficient);
handlePacketToSend(header);
}
}
}
- public void handlePacketReceived(SdlPacket packet){
+ public void handlePacketReceived(SdlPacket packet){
//Check for a version difference
if (_version == 1) {
setVersion((byte)packet.version);
}
-
+
MessageFrameAssembler assembler = getFrameAssemblerForFrame(packet);
- assembler.handleFrame(packet);
+ assembler.handleFrame(packet);
onResetIncomingHeartbeat(SessionType.valueOf((byte)packet.getServiceType()), (byte)packet.getSessionId());
@@ -183,10 +232,13 @@ public class WiProProtocol extends AbstractProtocol {
protected MessageFrameAssembler getFrameAssemblerForFrame(SdlPacket packet) {
- Hashtable<Integer, MessageFrameAssembler> hashSessionID = _assemblerForSessionID.get(packet.getSessionId());
+ 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((byte)packet.getSessionId(), hashSessionID);
+ _assemblerForSessionID.put(bySessionId, hashSessionID);
} // end-if
MessageFrameAssembler ret = (MessageFrameAssembler) _assemblerForMessageID.get(Integer.valueOf(packet.getMessageId()));
@@ -222,6 +274,7 @@ public class WiProProtocol extends AbstractProtocol {
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
@@ -262,6 +315,29 @@ public class WiProProtocol extends AbstractProtocol {
} // 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 {
@@ -284,7 +360,9 @@ public class WiProProtocol extends AbstractProtocol {
} // end-method
private void handleControlFrame(SdlPacket packet) {
- int frameInfo = packet.getFrameInfo();
+ Integer frameTemp = Integer.valueOf(packet.getFrameInfo());
+ Byte frameInfo = frameTemp.byteValue();
+
SessionType serviceType = SessionType.valueOf((byte)packet.getServiceType());
if (frameInfo == FrameDataControlFrameType.Heartbeat.getValue()) {
@@ -295,7 +373,7 @@ public class WiProProtocol extends AbstractProtocol {
}
else if (frameInfo == FrameDataControlFrameType.StartSession.getValue()) {
sendStartProtocolSessionACK(serviceType, (byte)packet.getSessionId());
- } else if (frameInfo == FrameDataControlFrameType.StartSessionACK.getValue()) {
+ } else if (frameInfo == FrameDataControlFrameType.StartSessionACK.getValue()) {
// Use this sessionID to create a message lock
Object messageLock = _messageLocks.get(packet.getSessionId());
if (messageLock == null) {
@@ -308,7 +386,7 @@ public class WiProProtocol extends AbstractProtocol {
hashID = BitConverter.intFromByteArray(packet.payload, 0);
}
}
- handleProtocolSessionStarted(serviceType,(byte) packet.getSessionId(), _version, "", hashID);
+ handleProtocolSessionStarted(serviceType,(byte) packet.getSessionId(), _version, "", hashID, packet.isEncrypted());
} else if (frameInfo == FrameDataControlFrameType.StartSessionNACK.getValue()) {
if (serviceType.eq(SessionType.NAV) || serviceType.eq(SessionType.PCM)) {
handleProtocolSessionNACKed(serviceType, (byte)packet.getSessionId(), _version, "");
@@ -326,23 +404,29 @@ public class WiProProtocol extends AbstractProtocol {
} else if (frameInfo == FrameDataControlFrameType.EndSessionNACK.getValue()) {
handleProtocolSessionEndedNACK(serviceType, (byte)packet.getSessionId(), "");
} else if (frameInfo == FrameDataControlFrameType.ServiceDataACK.getValue()) {
- handleProtocolServiceDataACK(serviceType, (byte)packet.getSessionId ());
+ 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);
+ 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
- if (_version > 1) {
+ boolean isControlService = message.getSessionType().equals(SessionType.CONTROL);
+ if (_version > 1&& !isControlService) {
BinaryFrameHeader binFrameHeader = BinaryFrameHeader.
parseBinaryHeader(packet.payload);
message.setVersion(_version);
@@ -371,8 +455,8 @@ public class WiProProtocol extends AbstractProtocol {
} // end-class
@Override
- public void StartProtocolService(SessionType sessionType, byte sessionID) {
- SdlPacket header = SdlPacketFactory.createStartSession(sessionType, 0x00, _version, sessionID);
+ public void StartProtocolService(SessionType sessionType, byte sessionID, boolean isEncrypted) {
+ SdlPacket header = SdlPacketFactory.createStartSession(sessionType, 0x00, _version, sessionID, isEncrypted);
handlePacketToSend(header);
}
@@ -392,7 +476,7 @@ public class WiProProtocol extends AbstractProtocol {
@Override
public void SendHeartBeat(byte sessionID) {
final SdlPacket heartbeat = SdlPacketFactory.createHeartbeat(SessionType.CONTROL, sessionID, _version);
- handlePacketToSend(heartbeat);
+ handlePacketToSend(heartbeat);
}
@Override
@@ -407,4 +491,5 @@ public class WiProProtocol extends AbstractProtocol {
handlePacketToSend(header);
}
-} // end-class \ No newline at end of file
+
+} // end-class
diff --git a/sdl_android_lib/src/com/smartdevicelink/proxy/RPCMessage.java b/sdl_android_lib/src/com/smartdevicelink/proxy/RPCMessage.java
index dc2d44ee1..9f3fbfbd9 100644
--- a/sdl_android_lib/src/com/smartdevicelink/proxy/RPCMessage.java
+++ b/sdl_android_lib/src/com/smartdevicelink/proxy/RPCMessage.java
@@ -2,7 +2,6 @@ package com.smartdevicelink.proxy;
import java.util.Hashtable;
-
public class RPCMessage extends RPCStruct {
public static final String KEY_REQUEST = "request";
public static final String KEY_RESPONSE = "response";
@@ -46,6 +45,9 @@ public class RPCMessage extends RPCStruct {
if (hasKey(hash.keySet(), RPCStruct.KEY_BULK_DATA)) {
setBulkData((byte[]) hash.get(RPCStruct.KEY_BULK_DATA));
}
+ if (hasKey(hash.keySet(), RPCStruct.KEY_PROTECTED)) {
+ setPayloadProtected((Boolean) hash.get(RPCStruct.KEY_PROTECTED));
+ }
}
protected String messageType;
diff --git a/sdl_android_lib/src/com/smartdevicelink/proxy/RPCRequestFactory.java b/sdl_android_lib/src/com/smartdevicelink/proxy/RPCRequestFactory.java
index dd8c49a23..e249839d5 100644
--- a/sdl_android_lib/src/com/smartdevicelink/proxy/RPCRequestFactory.java
+++ b/sdl_android_lib/src/com/smartdevicelink/proxy/RPCRequestFactory.java
@@ -562,7 +562,7 @@ public class RPCRequestFactory {
return putFile;
}
- public static PutFile buildPutFile(String sdlFileName, Long iOffset, Long iLength, FileType fileType, Boolean bPersistentFile, Boolean bSystemFile, Integer iCorrelationID) {
+ public static PutFile buildPutFile(String sdlFileName, Long iOffset, Long iLength, FileType fileType, Boolean bPersistentFile, Boolean bSystemFile, Boolean isPayloadProtected, Integer iCorrelationID) {
PutFile putFile = new PutFile();
putFile.setCorrelationID(iCorrelationID);
putFile.setSdlFileName(sdlFileName);
@@ -571,6 +571,7 @@ public class RPCRequestFactory {
putFile.setSystemFile(bSystemFile);
putFile.setOffset(iOffset);
putFile.setLength(iLength);
+ putFile.setPayloadProtected(isPayloadProtected);
return putFile;
}
diff --git a/sdl_android_lib/src/com/smartdevicelink/proxy/RPCStruct.java b/sdl_android_lib/src/com/smartdevicelink/proxy/RPCStruct.java
index 477bbdde4..4aea8e146 100644
--- a/sdl_android_lib/src/com/smartdevicelink/proxy/RPCStruct.java
+++ b/sdl_android_lib/src/com/smartdevicelink/proxy/RPCStruct.java
@@ -10,8 +10,10 @@ import com.smartdevicelink.marshal.JsonRPCMarshaller;
public class RPCStruct {
public static final String KEY_BULK_DATA = "bulkData";
-
+ public static final String KEY_PROTECTED = "protected";
+
private byte[] _bulkData = null;
+ private Boolean protectedPayload = false;
protected Hashtable<String, Object> store = null;
@@ -76,6 +78,14 @@ public class RPCStruct {
}
}
+ public void setPayloadProtected(Boolean bVal) {
+ protectedPayload = bVal;
+ }
+
+ public Boolean isPayloadProtected() {
+ return protectedPayload;
+ }
+
protected String getMessageTypeName(Set<String> keys) {
for (String key : keys) {
if (key == null) {
diff --git a/sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyALM.java b/sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyALM.java
index fa3f9e68c..2bdbdf82e 100644
--- a/sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyALM.java
+++ b/sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyALM.java
@@ -37,11 +37,41 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
private static final String SDL_LIB_TRACE_KEY = "42baba60-eb57-11df-98cf-0800200c9a66";
@SuppressWarnings("unused")
private static final String SDL_LIB_PRIVATE_TOKEN = "{DAE1A88C-6C16-4768-ACA5-6F1247EA01C2}";
+ /**
+ * @deprecated
+ * Constructor for the SdlProxy object, the proxy for communicating between the App and SDL
+ *
+ * Takes advantage of the advanced lifecycle management.
+ * @param listener - Reference to the object in the App listening to callbacks from SDL.
+ * @param appName - Name of the application displayed on SDL.
+ * @param isMediaApp - Indicates if the app is a media application.
+ */
+ @Deprecated
+ public SdlProxyALM(IProxyListenerALM listener, String appName, Boolean isMediaApp,
+ Language languageDesired, Language hmiDisplayLanguageDesired, String appID) throws SdlException {
+ super( listener,
+ /*sdl proxy configuration resources*/null,
+ /*enable advanced lifecycle management*/true,
+ appName,
+ /*TTS Name*/null,
+ /*ngn media app*/null,
+ /*vr synonyms*/null,
+ /*is media app*/isMediaApp,
+ /*sdlMsgVersion*/null,
+ /*language desired*/languageDesired,
+ /*HMI Display Language Desired*/hmiDisplayLanguageDesired,
+ /*App Type*/null,
+ /*App ID*/appID,
+ /*autoActivateID*/null,
+ /*callbackToUIThread*/ false,
+ new BTTransportConfig());
+ }
/**
* Constructor for the SdlProxy object, the proxy for communicating between the App and SDL
*
* Takes advantage of the advanced lifecycle management.
+ * @param context - Used to create a multiplexing transport config
* @param listener - Reference to the object in the App listening to callbacks from SDL.
* @param appName - Name of the application displayed on SDL.
* @param isMediaApp - Indicates if the app is a media application.
@@ -67,8 +97,8 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, appName, and isMediaApp.", SDL_LIB_TRACE_KEY);
}
-
/**
+ * @deprecated
* Constructor for the SdlProxy object, the proxy for communicating between the App and SDL.
*
* Takes advantage of the advanced lifecycle management.
@@ -85,6 +115,49 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
* @param autoActivateID - ID used to re-register previously registered application.
* @throws SdlException
*/
+ @Deprecated
+ public SdlProxyALM(IProxyListenerALM listener, String appName, String ngnMediaScreenAppName,
+ Vector<String> vrSynonyms, Boolean isMediaApp, SdlMsgVersion sdlMsgVersion,
+ Language languageDesired, Language hmiDisplayLanguageDesired, String appID,
+ String autoActivateID) throws SdlException {
+ super( listener,
+ /*sdl proxy configuration resources*/null,
+ /*enable advanced lifecycle management*/true,
+ appName,
+ /*TTS Name*/null,
+ ngnMediaScreenAppName,
+ vrSynonyms,
+ isMediaApp,
+ sdlMsgVersion,
+ languageDesired,
+ /*HMI Display Language Desired*/hmiDisplayLanguageDesired,
+ /*App Type*/null,
+ /*App ID*/appID,
+ autoActivateID,
+ /*callbackToUIThread*/ false,
+ new BTTransportConfig());
+
+ SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, appName, ngnMediaScreenAppName, " +
+ "vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, and autoActivateID.", SDL_LIB_TRACE_KEY);
+ }
+ /**
+ * Constructor for the SdlProxy object, the proxy for communicating between the App and SDL.
+ *
+ * Takes advantage of the advanced lifecycle management.
+ *
+ * @param context - Used to create a multiplexing transport config
+ * @param listener - Reference to the object in the App listening to callbacks from SDL.
+ * @param appName - Name of the application displayed on SDL.
+ * @param ngnMediaScreenAppName - Name of the application displayed on SDL for Navigation equipped
+ * vehicles. Limited to five characters.
+ * @param vrSynonyms - A vector of strings, all of which can be used as voice commands to
+ * @param isMediaApp - Indicates if the app is a media application.
+ * @param sdlMsgVersion - Indicates the version of SDL SmartDeviceLink Messages desired. Must be less than
+ * or equal to the version of SDL SmartDeviceLink running on the vehicle.
+ * @param languageDesired - Indicates the language desired for the SDL interface.
+ * @param autoActivateID - ID used to re-register previously registered application.
+ * @throws SdlException
+ */
public SdlProxyALM(Context context,IProxyListenerALM listener, String appName, String ngnMediaScreenAppName,
Vector<String> vrSynonyms, Boolean isMediaApp, SdlMsgVersion sdlMsgVersion,
Language languageDesired, Language hmiDisplayLanguageDesired, String appID,
@@ -109,8 +182,8 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, appName, ngnMediaScreenAppName, " +
"vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, and autoActivateID.", SDL_LIB_TRACE_KEY);
}
-
/**
+ * @deprecated
* Constructor for the SdlProxy object, the proxy for communicating between the App and SDL.
*
* Takes advantage of the advanced lifecycle management.
@@ -127,6 +200,49 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
* @param autoActivateID - ID used to re-register previously registered application.
* @throws SdlException
*/
+ @Deprecated
+ public SdlProxyALM(IProxyListenerALM listener, SdlProxyConfigurationResources sdlProxyConfigurationResources,
+ String appName, String ngnMediaScreenAppName, Vector<String> vrSynonyms,
+ Boolean isMediaApp, SdlMsgVersion sdlMsgVersion, Language languageDesired,
+ Language hmiDisplayLanguageDesired, String appID, String autoActivateID) throws SdlException {
+ super( listener,
+ sdlProxyConfigurationResources,
+ /*enable advanced lifecycle management*/true,
+ appName,
+ /*TTS Name*/null,
+ ngnMediaScreenAppName,
+ vrSynonyms,
+ isMediaApp,
+ sdlMsgVersion,
+ languageDesired,
+ /*HMI Display Language Desired*/hmiDisplayLanguageDesired,
+ /*App Type*/null,
+ /*App ID*/appID,
+ autoActivateID,
+ /*callbackToUIThread*/ false,
+ new BTTransportConfig());
+
+ SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, sdlProxyConfigurationResources, " +
+ "appName, ngnMediaScreenAppName, vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, and autoActivateID.", SDL_LIB_TRACE_KEY);
+ }
+ /**
+ * Constructor for the SdlProxy object, the proxy for communicating between the App and SDL.
+ *
+ * Takes advantage of the advanced lifecycle management.
+ *
+ * @param context - Used to create a multiplexing transport config
+ * @param listener - Reference to the object in the App listening to callbacks from SDL.
+ * @param appName - Name of the application displayed on SDL.
+ * @param ngnMediaScreenAppName - Name of the application displayed on SDL for Navigation equipped
+ * vehicles. Limited to five characters.
+ * @param vrSynonyms - A vector of strings, all of which can be used as voice commands to
+ * @param isMediaApp - Indicates if the app is a media application.
+ * @param sdlMsgVersion - Indicates the version of SDL SmartDeviceLink Messages desired. Must be less than
+ * or equal to the version of SDL SmartDeviceLink running on the vehicle.
+ * @param languageDesired - Indicates the language desired for the SDL interface.
+ * @param autoActivateID - ID used to re-register previously registered application.
+ * @throws SdlException
+ */
public SdlProxyALM(Context context,IProxyListenerALM listener, SdlProxyConfigurationResources sdlProxyConfigurationResources,
String appName, String ngnMediaScreenAppName, Vector<String> vrSynonyms,
Boolean isMediaApp, SdlMsgVersion sdlMsgVersion, Language languageDesired,
@@ -151,8 +267,8 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, sdlProxyConfigurationResources, " +
"appName, ngnMediaScreenAppName, vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, and autoActivateID.", SDL_LIB_TRACE_KEY);
}
-
/**
+ * @deprecated
* Constructor for the SdlProxy object, the proxy for communicating between the App and SDL.
*
* Takes advantage of the advanced lifecycle management.
@@ -170,6 +286,51 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
* @param callbackToUIThread - If true, all callbacks will occur on the UI thread.
* @throws SdlException
*/
+ @Deprecated
+ public SdlProxyALM(IProxyListenerALM listener, String appName, String ngnMediaScreenAppName,
+ Vector<String> vrSynonyms, Boolean isMediaApp, SdlMsgVersion sdlMsgVersion,
+ Language languageDesired, Language hmiDisplayLanguageDesired, String appID,
+ String autoActivateID, boolean callbackToUIThread) throws SdlException {
+ super( listener,
+ /*sdl proxy configuration resources*/null,
+ /*enable advanced lifecycle management*/true,
+ appName,
+ /*TTS Name*/null,
+ ngnMediaScreenAppName,
+ vrSynonyms,
+ isMediaApp,
+ sdlMsgVersion,
+ languageDesired,
+ /*HMI Display Language Desired*/hmiDisplayLanguageDesired,
+ /*App Type*/null,
+ /*App ID*/appID,
+ autoActivateID,
+ callbackToUIThread,
+ new BTTransportConfig());
+
+ SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, " +
+ "appName, ngnMediaScreenAppName, vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, autoActivateID, " +
+ "and callbackToUIThread", SDL_LIB_TRACE_KEY);
+ }
+ /**
+ * Constructor for the SdlProxy object, the proxy for communicating between the App and SDL.
+ *
+ * Takes advantage of the advanced lifecycle management.
+ *
+ * @param context - Used to create a multiplexing transport config
+ * @param listener - Reference to the object in the App listening to callbacks from SDL.
+ * @param appName - Name of the application displayed on SDL.
+ * @param ngnMediaScreenAppName - Name of the application displayed on SDL for Navigation equipped
+ * vehicles. Limited to five characters.
+ * @param vrSynonyms - A vector of strings, all of which can be used as voice commands to
+ * @param isMediaApp - Indicates if the app is a media application.
+ * @param sdlMsgVersion - Indicates the version of SDL SmartDeviceLink Messages desired. Must be less than
+ * or equal to the version of SDL SmartDeviceLink running on the vehicle.
+ * @param languageDesired - Indicates the language desired for the SDL interface.
+ * @param autoActivateID - ID used to re-register previously registered application.
+ * @param callbackToUIThread - If true, all callbacks will occur on the UI thread.
+ * @throws SdlException
+ */
public SdlProxyALM(Context context,IProxyListenerALM listener, String appName, String ngnMediaScreenAppName,
Vector<String> vrSynonyms, Boolean isMediaApp, SdlMsgVersion sdlMsgVersion,
Language languageDesired, Language hmiDisplayLanguageDesired, String appID,
@@ -195,12 +356,58 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
"appName, ngnMediaScreenAppName, vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, autoActivateID, " +
"and callbackToUIThread", SDL_LIB_TRACE_KEY);
}
-
+ /**
+ * @deprecated
+ * Constructor for the SdlProxy object, the proxy for communicating between the App and SDL.
+ *
+ * Takes advantage of the advanced lifecycle management.
+ *
+ * @param listener - Reference to the object in the App listening to callbacks from SDL.
+ * @param appName - Name of the application displayed on SDL.
+ * @param ngnMediaScreenAppName - Name of the application displayed on SDL for Navigation equipped
+ * vehicles. Limited to five characters.
+ * @param vrSynonyms - A vector of strings, all of which can be used as voice commands to
+ * @param isMediaApp - Indicates if the app is a media application.
+ * @param sdlMsgVersion - Indicates the version of SDL SmartDeviceLink Messages desired. Must be less than
+ * or equal to the version of SDL SmartDeviceLink running on the vehicle.
+ * @param languageDesired - Indicates the language desired for the SDL interface.
+ * @param autoActivateID - ID used to re-register previously registered application.
+ * @param callbackToUIThread - If true, all callbacks will occur on the UI thread.
+ * @throws SdlException
+ */
+ @Deprecated
+ public SdlProxyALM(IProxyListenerALM listener, SdlProxyConfigurationResources sdlProxyConfigurationResources,
+ String appName, String ngnMediaScreenAppName, Vector<String> vrSynonyms, Boolean isMediaApp,
+ SdlMsgVersion sdlMsgVersion, Language languageDesired, Language hmiDisplayLanguageDesired,
+ String appID, String autoActivateID,
+ boolean callbackToUIThread) throws SdlException {
+ super( listener,
+ sdlProxyConfigurationResources,
+ /*enable advanced lifecycle management*/true,
+ appName,
+ /*TTS Name*/null,
+ ngnMediaScreenAppName,
+ vrSynonyms,
+ isMediaApp,
+ sdlMsgVersion,
+ languageDesired,
+ /*HMI Display Language Desired*/hmiDisplayLanguageDesired,
+ /*App Type*/null,
+ /*App ID*/appID,
+ autoActivateID,
+ callbackToUIThread,
+ new BTTransportConfig());
+
+ SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, sdlProxyConfigurationResources, " +
+ "appName, ngnMediaScreenAppName, vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, autoActivateID, " +
+ "and callbackToUIThread", SDL_LIB_TRACE_KEY);
+ }
/**
* Constructor for the SdlProxy object, the proxy for communicating between the App and SDL.
*
* Takes advantage of the advanced lifecycle management.
*
+ * @param context - Used to create a multiplexing transport config
* @param listener - Reference to the object in the App listening to callbacks from SDL.
* @param appName - Name of the application displayed on SDL.
* @param ngnMediaScreenAppName - Name of the application displayed on SDL for Navigation equipped
@@ -241,6 +448,34 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
"and callbackToUIThread", SDL_LIB_TRACE_KEY);
}
+ @Deprecated
+ public SdlProxyALM(IProxyListenerALM listener, SdlProxyConfigurationResources sdlProxyConfigurationResources,
+ String appName, String ngnMediaScreenAppName, Vector<String> vrSynonyms, Boolean isMediaApp,
+ SdlMsgVersion sdlMsgVersion, Language languageDesired, Language hmiDisplayLanguageDesired,
+ String appID, String autoActivateID, boolean callbackToUIThread, boolean preRegister) throws SdlException {
+ super( listener,
+ sdlProxyConfigurationResources,
+ /*enable advanced lifecycle management*/true,
+ appName,
+ /*TTS Name*/null,
+ ngnMediaScreenAppName,
+ vrSynonyms,
+ isMediaApp,
+ sdlMsgVersion,
+ languageDesired,
+ /*HMI Display Language Desired*/hmiDisplayLanguageDesired,
+ /*App Type*/null,
+ /*App ID*/appID,
+ autoActivateID,
+ callbackToUIThread,
+ preRegister,
+ new BTTransportConfig());
+
+ SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, sdlProxyConfigurationResources, " +
+ "appName, ngnMediaScreenAppName, vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, autoActivateID, " +
+ "callbackToUIThread and version", SDL_LIB_TRACE_KEY);
+ }
+
public SdlProxyALM(Context context,IProxyListenerALM listener, SdlProxyConfigurationResources sdlProxyConfigurationResources,
String appName, String ngnMediaScreenAppName, Vector<String> vrSynonyms, Boolean isMediaApp,
SdlMsgVersion sdlMsgVersion, Language languageDesired, Language hmiDisplayLanguageDesired,
@@ -535,6 +770,7 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
}
/**
+ * @deprecated
* Constructor for the SdlProxy object, the proxy for communicating between the App and SDL via specified transport.
*
* Takes advantage of the advanced lifecycle management.
@@ -549,6 +785,47 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
* @param preRegister Flag that indicates that client should be pre-registred or not
* @throws SdlException
*/
+ @Deprecated
+ public SdlProxyALM(IProxyListenerALM listener, String appName, Boolean isMediaApp,Language languageDesired, Language hmiDisplayLanguageDesired,
+ String appID, boolean callbackToUIThread, boolean preRegister) throws SdlException
+ {
+ super( listener,
+ /*sdlProxyConfigurationResources*/null,
+ /*enable advanced lifecycle management*/true,
+ appName,
+ /*ttsName*/null,
+ /*ngnMediaScreenAppName*/null,
+ /*vrSynonyms*/null,
+ isMediaApp,
+ /*sdlMsgVersion*/null,
+ languageDesired,
+ hmiDisplayLanguageDesired,
+ /*App Type*/null,
+ /*App ID*/appID,
+ /*autoActivateID*/null,
+ callbackToUIThread,
+ preRegister,
+ new BTTransportConfig());
+
+ SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, " +
+ "appName, isMediaApp, languageDesired, hmiDisplayLanguageDesired" + "callbackToUIThread and version", SDL_LIB_TRACE_KEY);
+ }
+ /**
+ * Constructor for the SdlProxy object, the proxy for communicating between the App and SDL via specified transport.
+ *
+ * Takes advantage of the advanced lifecycle management.
+ *
+ * @param context - Used to create a multiplexing transport config
+ * @param listener Reference to the object in the App listening to callbacks from SDL.
+ * @param appName Name of the application displayed on SDL.
+ * @param isMediaApp Indicates if the app is a media application.
+ * @param languageDesired Indicates the language desired for the SDL interface.
+ * @param hmiDisplayLanguageDesired Desired language in HMI.
+ * @param appID Identifier of the client application.
+ * @param callbackToUIThread If true, all callbacks will occur on the UI thread.
+ * @param preRegister Flag that indicates that client should be pre-registred or not
+ * @throws SdlException
+ */
public SdlProxyALM(Context context,IProxyListenerALM listener, String appName, Boolean isMediaApp,Language languageDesired, Language hmiDisplayLanguageDesired,
String appID, boolean callbackToUIThread, boolean preRegister) throws SdlException
{
@@ -575,6 +852,7 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
}
/**
+ * @deprecated
* Constructor for the SdlProxy object, the proxy for communicating between the App and SDL via specified transport.
*
* Takes advantage of the advanced lifecycle management.
@@ -584,6 +862,42 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
* @param isMediaApp Indicates if the app is a media application.
* @param appID Identifier of the client application.
* @throws SdlException
+ */
+ @Deprecated
+ public SdlProxyALM(IProxyListenerALM listener, String appName, Boolean isMediaApp,String appID) throws SdlException {
+ super( listener,
+ /*sdlProxyConfigurationResources*/null,
+ /*enable advanced lifecycle management*/true,
+ appName,
+ /*ttsName*/null,
+ /*ngnMediaScreenAppName*/null,
+ /*vrSynonyms*/null,
+ isMediaApp,
+ /*sdlMsgVersion*/null,
+ /*languageDesired*/null,
+ /*hmiDisplayLanguageDesired*/null,
+ /*App Type*/null,
+ /*App ID*/appID,
+ /*autoActivateID*/null,
+ false,
+ false,
+ new BTTransportConfig());
+
+ SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, " +
+ "appName, isMediaApp, appID", SDL_LIB_TRACE_KEY);
+ }
+
+ /**
+ * Constructor for the SdlProxy object, the proxy for communicating between the App and SDL via specified transport.
+ *
+ * Takes advantage of the advanced lifecycle management.
+ *
+ * @param context - Used to create a multiplexing transport config
+ * @param listener Reference to the object in the App listening to callbacks from SDL.
+ * @param appName Name of the application displayed on SDL.
+ * @param isMediaApp Indicates if the app is a media application.
+ * @param appID Identifier of the client application.
+ * @throws SdlException
*/
public SdlProxyALM(Context context,IProxyListenerALM listener, String appName, Boolean isMediaApp,String appID) throws SdlException {
super( listener,
@@ -609,6 +923,7 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
}
/**
+ * @deprecated
* Constructor for the SdlProxy object, the proxy for communicating between the App and SDL via specified transport.
*
* Takes advantage of the advanced lifecycle management.
@@ -619,7 +934,8 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
* @param isMediaApp Indicates if the app is a media application.
* @param appID Identifier of the client application.
* @throws SdlException
- */
+ */
+ @Deprecated
public SdlProxyALM(IProxyListenerALM listener, SdlProxyConfigurationResources sdlProxyConfigurationResources, String appName, Boolean isMediaApp,String appID) throws SdlException {
super( listener,
sdlProxyConfigurationResources,
@@ -643,6 +959,42 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
"sdlProxyConfigurationResources, appName, isMediaApp, appID", SDL_LIB_TRACE_KEY);
}
+ /**
+ * Constructor for the SdlProxy object, the proxy for communicating between the App and SDL via specified transport.
+ *
+ * Takes advantage of the advanced lifecycle management.
+ *
+ * @param context - Used to create a multiplexing transport config
+ * @param listener Reference to the object in the App listening to callbacks from SDL.
+ * @param sdlProxyConfigurationResources Proxy configuration resources.
+ * @param appName Name of the application displayed on SDL.
+ * @param isMediaApp Indicates if the app is a media application.
+ * @param appID Identifier of the client application.
+ * @throws SdlException
+ */
+ public SdlProxyALM(Context context, IProxyListenerALM listener, SdlProxyConfigurationResources sdlProxyConfigurationResources, String appName, Boolean isMediaApp,String appID) throws SdlException {
+ super( listener,
+ sdlProxyConfigurationResources,
+ /*enable advanced lifecycle management*/true,
+ appName,
+ /*ttsName*/null,
+ /*ngnMediaScreenAppName*/null,
+ /*vrSynonyms*/null,
+ isMediaApp,
+ /*sdlMsgVersion*/null,
+ /*languageDesired*/null,
+ /*hmiDisplayLanguageDesired*/null,
+ /*App Type*/null,
+ /*App ID*/appID,
+ /*autoActivateID*/null,
+ false,
+ false,
+ new MultiplexTransportConfig(context,appID));
+
+ SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, " +
+ "sdlProxyConfigurationResources, appName, isMediaApp, appID", SDL_LIB_TRACE_KEY);
+ }
+
public SdlProxyALM(IProxyListenerALM listener, String appName, Boolean isMediaApp,String appID,BaseTransportConfig transportConfig) throws SdlException {
super( listener,
/*sdlProxyConfigurationResources*/null,
@@ -665,12 +1017,51 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, " +
"appName, isMediaApp, appID", SDL_LIB_TRACE_KEY);
}
-
+
+ /**
+ * @deprecated
+ * Constructor for the SdlProxy object, the proxy for communicating between the App and SDL via specified transport.
+ *
+ * Takes advantage of the advanced lifecycle management.
+ *
+ * @param listener Reference to the object in the App listening to callbacks from SDL.
+ * @param appName Name of the application displayed on SDL.
+ * @param isMediaApp Indicates if the app is a media application.
+ * @param appID Identifier of the client application.
+ * @param callbackToUIThread If true, all callbacks will occur on the UI thread.
+ * @param preRegister Flag that indicates that client should be pre-registred or not
+ * @throws SdlException
+ */
+ @Deprecated
+ public SdlProxyALM(IProxyListenerALM listener, String appName, Boolean isMediaApp,String appID,
+ boolean callbackToUIThread, boolean preRegister) throws SdlException {
+ super( listener,
+ /*sdlProxyConfigurationResources*/null,
+ /*enable advanced lifecycle management*/true,
+ appName,
+ /*ttsName*/null,
+ /*ngnMediaScreenAppName*/null,
+ /*vrSynonyms*/null,
+ isMediaApp,
+ /*sdlMsgVersion*/null,
+ /*languageDesired*/null,
+ /*hmiDisplayLanguageDesired*/null,
+ /*App Type*/null,
+ /*App ID*/appID,
+ /*autoActivateID*/null,
+ callbackToUIThread,
+ preRegister,
+ new BTTransportConfig());
+
+ SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, " +
+ "appName, isMediaApp, " + "callbackToUIThread and version", SDL_LIB_TRACE_KEY);
+ }
/**
* Constructor for the SdlProxy object, the proxy for communicating between the App and SDL via specified transport.
*
* Takes advantage of the advanced lifecycle management.
*
+ * @param context - Used to create a multiplexing transport config
* @param listener Reference to the object in the App listening to callbacks from SDL.
* @param appName Name of the application displayed on SDL.
* @param isMediaApp Indicates if the app is a media application.
@@ -754,7 +1145,8 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, sdlProxyConfigurationResources, " +
"appName, ngnMediaScreenAppName, vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, autoActivateID, " +
"callbackToUIThread and version", SDL_LIB_TRACE_KEY);
- }
+ }
+
public SdlProxyALM(Service appService, IProxyListenerALM listener, SdlProxyConfigurationResources sdlProxyConfigurationResources,
String appName, Vector<TTSChunk> ttsName, String ngnMediaScreenAppName, Vector<String> vrSynonyms, Boolean isMediaApp,
@@ -785,8 +1177,11 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
"appName, ngnMediaScreenAppName, vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, autoActivateID, " +
"callbackToUIThread and version", SDL_LIB_TRACE_KEY);
}
-
+
+
+
/**
+ * @deprecated
* Constructor for the SdlProxy object, the proxy for communicating between the App and SDL via specified transport.
*
* Takes advantage of the advanced lifecycle management.
@@ -809,6 +1204,57 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
* @param preRegister Flag that indicates that client should be pre-registred or not
* @throws SdlException
*/
+ @Deprecated
+ public SdlProxyALM(IProxyListenerALM listener, SdlProxyConfigurationResources sdlProxyConfigurationResources,
+ String appName, Vector<TTSChunk> ttsName, String ngnMediaScreenAppName, Vector<String> vrSynonyms, Boolean isMediaApp,
+ SdlMsgVersion sdlMsgVersion, Language languageDesired, Language hmiDisplayLanguageDesired,
+ String appID, String autoActivateID, boolean callbackToUIThread, boolean preRegister) throws SdlException {
+ super( listener,
+ sdlProxyConfigurationResources,
+ /*enable advanced lifecycle management*/true,
+ appName,
+ ttsName,
+ ngnMediaScreenAppName,
+ vrSynonyms,
+ isMediaApp,
+ sdlMsgVersion,
+ languageDesired,
+ /*HMI Display Language Desired*/hmiDisplayLanguageDesired,
+ /*App Type*/null,
+ /*App ID*/appID,
+ autoActivateID,
+ callbackToUIThread,
+ preRegister,
+ new BTTransportConfig());
+
+ SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, sdlProxyConfigurationResources, " +
+ "appName, ngnMediaScreenAppName, vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, autoActivateID, " +
+ "callbackToUIThread and version", SDL_LIB_TRACE_KEY);
+ }
+ /**
+ * Constructor for the SdlProxy object, the proxy for communicating between the App and SDL via specified transport.
+ *
+ * Takes advantage of the advanced lifecycle management.
+ *
+ * @param context - Used to create a multiplexing transport config
+ * @param listener Reference to the object in the App listening to callbacks from SDL.
+ * @param sdlProxyConfigurationResources Proxy configuration resources.
+ * @param appName Name of the application displayed on SDL.
+ * @param ttsName TTS name.
+ * @param ngnMediaScreenAppName Name of the application displayed on SDL for Navigation equipped
+ * vehicles. Limited to five characters.
+ * @param vrSynonyms A vector of strings, all of which can be used as voice commands too
+ * @param isMediaApp Indicates if the app is a media application.
+ * @param sdlMsgVersion Indicates the version of SDL SmartDeviceLink Messages desired. Must be less than
+ * or equal to the version of SDL SmartDeviceLink running on the vehicle.
+ * @param languageDesired Indicates the language desired for the SDL interface.
+ * @param hmiDisplayLanguageDesired Desired language in HMI.
+ * @param appID Identifier of the client application.
+ * @param autoActivateID ID used to re-register previously registered application.
+ * @param callbackToUIThread If true, all callbacks will occur on the UI thread.
+ * @param preRegister Flag that indicates that client should be pre-registred or not
+ * @throws SdlException
+ */
public SdlProxyALM(Context context,IProxyListenerALM listener, SdlProxyConfigurationResources sdlProxyConfigurationResources,
String appName, Vector<TTSChunk> ttsName, String ngnMediaScreenAppName, Vector<String> vrSynonyms, Boolean isMediaApp,
SdlMsgVersion sdlMsgVersion, Language languageDesired, Language hmiDisplayLanguageDesired,
@@ -836,6 +1282,7 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
"callbackToUIThread and version", SDL_LIB_TRACE_KEY);
}
+
/**
* Constructor for the SdlProxy object, the proxy for communicating between the App and SDL via specified transport.
*
@@ -887,8 +1334,8 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
"appName, ngnMediaScreenAppName, vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, autoActivateID, " +
"callbackToUIThread and version", SDL_LIB_TRACE_KEY);
}
-
/**
+ * @deprecated
* Constructor for the SdlProxy object, the proxy for communicating between the App and SDL via specified transport.
*
* Takes advantage of the advanced lifecycle management.
@@ -912,6 +1359,58 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
* @param preRegister Flag that indicates that client should be pre-registred or not
* @throws SdlException
*/
+ @Deprecated
+ public SdlProxyALM(IProxyListenerALM listener, SdlProxyConfigurationResources sdlProxyConfigurationResources,
+ String appName, Vector<TTSChunk> ttsName, String ngnMediaScreenAppName, Vector<String> vrSynonyms, Boolean isMediaApp,
+ SdlMsgVersion sdlMsgVersion, Language languageDesired, Language hmiDisplayLanguageDesired,
+ Vector<AppHMIType> appType, String appID, String autoActivateID, boolean callbackToUIThread, boolean preRegister) throws SdlException {
+ super( listener,
+ sdlProxyConfigurationResources,
+ /*enable advanced lifecycle management*/true,
+ appName,
+ ttsName,
+ ngnMediaScreenAppName,
+ vrSynonyms,
+ isMediaApp,
+ sdlMsgVersion,
+ languageDesired,
+ /*HMI Display Language Desired*/hmiDisplayLanguageDesired,
+ /*App Type*/appType,
+ /*App ID*/appID,
+ autoActivateID,
+ callbackToUIThread,
+ preRegister,
+ new BTTransportConfig());
+
+ SdlTrace.logProxyEvent("Application constructed SdlProxyALM (using legacy constructor for BT transport) instance passing in: IProxyListener, sdlProxyConfigurationResources, " +
+ "appName, ngnMediaScreenAppName, vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, appType, appID, autoActivateID, " +
+ "callbackToUIThread and version", SDL_LIB_TRACE_KEY);
+ }
+ /**
+ * Constructor for the SdlProxy object, the proxy for communicating between the App and SDL via specified transport.
+ *
+ * Takes advantage of the advanced lifecycle management.
+ *
+ * @param context - Used to create a multiplexing transport config
+ * @param listener Reference to the object in the App listening to callbacks from SDL.
+ * @param sdlProxyConfigurationResources Proxy configuration resources.
+ * @param appName Name of the application displayed on SDL.
+ * @param ttsName TTS name.
+ * @param ngnMediaScreenAppName Name of the application displayed on SDL for Navigation equipped
+ * vehicles. Limited to five characters.
+ * @param vrSynonyms A vector of strings, all of which can be used as voice commands too
+ * @param isMediaApp Indicates if the app is a media application.
+ * @param sdlMsgVersion Indicates the version of SDL SmartDeviceLink Messages desired. Must be less than
+ * or equal to the version of SDL SmartDeviceLink running on the vehicle.
+ * @param languageDesired Indicates the language desired for the SDL interface.
+ * @param hmiDisplayLanguageDesired Desired language in HMI.
+ * @param appType Type of application.
+ * @param appID Identifier of the client application.
+ * @param autoActivateID ID used to re-register previously registered application.
+ * @param callbackToUIThread If true, all callbacks will occur on the UI thread.
+ * @param preRegister Flag that indicates that client should be pre-registred or not
+ * @throws SdlException
+ */
public SdlProxyALM(Context context,IProxyListenerALM listener, SdlProxyConfigurationResources sdlProxyConfigurationResources,
String appName, Vector<TTSChunk> ttsName, String ngnMediaScreenAppName, Vector<String> vrSynonyms, Boolean isMediaApp,
SdlMsgVersion sdlMsgVersion, Language languageDesired, Language hmiDisplayLanguageDesired,
@@ -938,7 +1437,6 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
"appName, ngnMediaScreenAppName, vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, appType, appID, autoActivateID, " +
"callbackToUIThread and version", SDL_LIB_TRACE_KEY);
}
-
/**
* Constructor for the SdlProxy object, the proxy for communicating between the App and SDL via specified transport.
*
@@ -991,7 +1489,6 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
"appName, ngnMediaScreenAppName, vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, appType, appID, autoActivateID, " +
"callbackToUIThread and version", SDL_LIB_TRACE_KEY);
}
-
public SdlProxyALM(Service appService, IProxyListenerALM listener, SdlProxyConfigurationResources sdlProxyConfigurationResources,
String appName, Vector<TTSChunk> ttsName, String ngnMediaScreenAppName, Vector<String> vrSynonyms, Boolean isMediaApp,
SdlMsgVersion sdlMsgVersion, Language languageDesired, Language hmiDisplayLanguageDesired, Vector<AppHMIType> appType,
@@ -1022,7 +1519,6 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
"appName, ngnMediaScreenAppName, vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, appType, appID, autoActivateID, " +
"callbackToUIThread and version", SDL_LIB_TRACE_KEY);
}
-
/**
* Constructor for the SdlProxy object, the proxy for communicating between the App and SDL via specified transport.
*
@@ -1078,7 +1574,6 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
"appName, ngnMediaScreenAppName, vrSynonyms, isMediaApp, sdlMsgVersion, languageDesired, appType, appID, autoActivateID, " +
"callbackToUIThread and version", SDL_LIB_TRACE_KEY);
}
-
public SdlProxyALM(Service appService, IProxyListenerALM listener, SdlProxyConfigurationResources sdlProxyConfigurationResources,
String appName, Vector<TTSChunk> ttsName, String ngnMediaScreenAppName, Vector<String> vrSynonyms, Boolean isMediaApp,
SdlMsgVersion sdlMsgVersion, Language languageDesired, Language hmiDisplayLanguageDesired, Vector<AppHMIType> appType,
@@ -1199,6 +1694,8 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
return null;
}
+
+
/**
* Gets displayCapabilities set when application interface is registered.
@@ -1257,7 +1754,6 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
return _speechCapabilities;
}
-
/**
* Gets PrerecordedSpeech set when application interface is registered.
*
@@ -1277,7 +1773,6 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
return _prerecordedSpeech;
}
-
/**
* Gets sdlLanguage set when application interface is registered.
*
@@ -1443,5 +1938,6 @@ public class SdlProxyALM extends SdlProxyBase<IProxyListenerALM> {
throw new SdlException("SDL is not connected. Unable to get isResumeSuccess.", SdlExceptionCause.SDL_UNAVAILABLE);
}
return _bResumeSuccess;
- }
-} \ No newline at end of file
+ }
+
+}
diff --git a/sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyBase.java b/sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyBase.java
index b8a7a17f4..85bc6312b 100644
--- a/sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyBase.java
+++ b/sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyBase.java
@@ -87,6 +87,7 @@ import com.smartdevicelink.proxy.rpc.enums.VrCapabilities;
import com.smartdevicelink.proxy.rpc.listeners.OnPutFileUpdateListener;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener;
+import com.smartdevicelink.security.SdlSecurityBase;
import com.smartdevicelink.streaming.StreamRPCPacketizer;
import com.smartdevicelink.trace.SdlTrace;
import com.smartdevicelink.trace.TraceDeviceInfo;
@@ -101,6 +102,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
public static final String TAG = "SdlProxy";
private static final String SDL_LIB_TRACE_KEY = "42baba60-eb57-11df-98cf-0800200c9a66";
private static final int PROX_PROT_VER_ONE = 1;
+ private static final int RESPONSE_WAIT_TIME = 2000;
private SdlSession sdlSession = null;
private proxyListenerType _proxyListener = null;
@@ -124,7 +126,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
private Object APP_INTERFACE_REGISTERED_LOCK = new Object();
private int iFileCount = 0;
-
+
private boolean navServiceStartResponseReceived = false;
private boolean navServiceStartResponse = false;
private boolean pcmServiceStartResponseReceived = false;
@@ -133,6 +135,8 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
private boolean navServiceEndResponse = false;
private boolean pcmServiceEndResponseReceived = false;
private boolean pcmServiceEndResponse = false;
+ private boolean rpcProtectedResponseReceived = false;
+ private boolean rpcProtectedStartResponse = false;
// Device Info for logging
private TraceDeviceInfo _traceDeviceInterrogator = null;
@@ -166,10 +170,10 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
private SdlMsgVersion _sdlMsgVersionRequest = null;
private Vector<String> _vrSynonyms = null;
private boolean _bAppResumeEnabled = false;
- private OnSystemRequest lockScreenIconRequest = null;
+ private OnSystemRequest lockScreenIconRequest = null;
private TelephonyManager telephonyManager = null;
private DeviceInfo deviceInfo = null;
-
+
/**
* Contains current configuration for the transport that was selected during
* construction of this object
@@ -209,11 +213,12 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
protected String _systemSoftwareVersion = null;
protected List<Integer> _diagModes = null;
protected Boolean firstTimeFull = true;
- protected String _proxyVersionInfo = null;
- protected Boolean _bResumeSuccess = false;
+ protected String _proxyVersionInfo = null;
+ protected Boolean _bResumeSuccess = false;
+ protected List<Class<? extends SdlSecurityBase>> _secList = null;
private CopyOnWriteArrayList<IPutFileResponseListener> _putFileListenerList = new CopyOnWriteArrayList<IPutFileResponseListener>();
-
+
protected byte _wiproVersion = 1;
protected SparseArray<OnRPCResponseListener> rpcResponseListeners = null;
@@ -295,30 +300,38 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
@Override
public void onProtocolSessionStarted(SessionType sessionType,
- byte sessionID, byte version, String correlationID, int hashID) {
+ byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) {
Intent sendIntent = createBroadcastIntent();
updateBroadcastIntent(sendIntent, "FUNCTION_NAME", "onProtocolSessionStarted");
updateBroadcastIntent(sendIntent, "COMMENT1", "SessionID: " + sessionID);
updateBroadcastIntent(sendIntent, "COMMENT2", " ServiceType: " + sessionType.getName());
+ updateBroadcastIntent(sendIntent, "COMMENT3", " Encrypted: " + isEncrypted);
sendBroadcastIntent(sendIntent);
setWiProVersion(version);
if (sessionType.eq(SessionType.RPC)) {
- if ( (_transportConfig.getHeartBeatTimeout() != Integer.MAX_VALUE) && (version > 2))
- {
- HeartbeatMonitor outgoingHeartbeatMonitor = new HeartbeatMonitor();
- outgoingHeartbeatMonitor.setInterval(_transportConfig.getHeartBeatTimeout());
- sdlSession.setOutgoingHeartbeatMonitor(outgoingHeartbeatMonitor);
-
- HeartbeatMonitor incomingHeartbeatMonitor = new HeartbeatMonitor();
- incomingHeartbeatMonitor.setInterval(_transportConfig.getHeartBeatTimeout());
- sdlSession.setIncomingHeartbeatMonitor(incomingHeartbeatMonitor);
- }
-
- startRPCProtocolSession(sessionID, correlationID);
+ if (!isEncrypted)
+ {
+ if ( (_transportConfig.getHeartBeatTimeout() != Integer.MAX_VALUE) && (version > 2))
+ {
+ HeartbeatMonitor outgoingHeartbeatMonitor = new HeartbeatMonitor();
+ outgoingHeartbeatMonitor.setInterval(_transportConfig.getHeartBeatTimeout());
+ sdlSession.setOutgoingHeartbeatMonitor(outgoingHeartbeatMonitor);
+
+ HeartbeatMonitor incomingHeartbeatMonitor = new HeartbeatMonitor();
+ incomingHeartbeatMonitor.setInterval(_transportConfig.getHeartBeatTimeout());
+ sdlSession.setIncomingHeartbeatMonitor(incomingHeartbeatMonitor);
+ }
+
+ startRPCProtocolSession(sessionID, correlationID);
+ }
+ else
+ {
+ RPCProtectedServiceStarted();
+ }
} else if (sessionType.eq(SessionType.NAV)) {
NavServiceStarted();
} else if (sessionType.eq(SessionType.PCM)) {
@@ -408,7 +421,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
}
- @Override
+ @Override
public void onProtocolSessionEndedNACKed(SessionType sessionType,
byte sessionID, String correlationID) {
if (sessionType.eq(SessionType.NAV)) {
@@ -431,21 +444,21 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
AudioServiceEndedNACK();
}
- }
- public void onProtocolServiceDataACK(SessionType sessionType,
+ }
+ public void onProtocolServiceDataACK(SessionType sessionType, final int dataSize,
byte sessionID) {
if (_callbackToUIThread) {
// Run in UI thread
_mainUIHandler.post(new Runnable() {
@Override
public void run() {
- _proxyListener.onServiceDataACK();
+ _proxyListener.onServiceDataACK(dataSize);
}
});
} else {
- _proxyListener.onServiceDataACK();
+ _proxyListener.onServiceDataACK(dataSize);
}
- }
+ }
}
/**
@@ -750,6 +763,32 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
sendIntent.putExtra(sKey, iValue);
}
+ private Service getService()
+ {
+ Service myService = null;
+ if (_proxyListener != null && _proxyListener instanceof Service)
+ {
+ myService = (Service) _proxyListener;
+ }
+ else if (_appService != null)
+ {
+ myService = _appService;
+ }
+ if (myService != null)
+ {
+ try
+ {
+ return myService;
+ }
+ catch(Exception ex)
+ {
+ return null;
+ }
+
+ }
+ return null;
+ }
+
private void sendBroadcastIntent(Intent sendIntent)
{
Service myService = null;
@@ -1426,6 +1465,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
hash.put(RPCMessage.KEY_NOTIFICATION, hashTemp);
}
if (message.getBulkData() != null) hash.put(RPCStruct.KEY_BULK_DATA, message.getBulkData());
+ if (message.getPayloadProtected()) hash.put(RPCStruct.KEY_PROTECTED, true);
} else {
final Hashtable<String, Object> mhash = JsonRPCMarshaller.unmarshall(message.getData());
hash = mhash;
@@ -1609,6 +1649,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
pm.setMessageType(MessageType.RPC);
pm.setSessionType(SessionType.RPC);
pm.setFunctionID(FunctionID.getFunctionId(request.getFunctionName()));
+ pm.setPayloadProtected(request.isPayloadProtected());
if (request.getCorrelationID() == null)
{
//Log error here
@@ -1733,6 +1774,50 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
}
}
+ private void processRaiResponse(RegisterAppInterfaceResponse rai)
+ {
+ if (rai == null) return;
+
+ VehicleType vt = rai.getVehicleType();
+ if (vt == null) return;
+
+ String make = vt.getMake();
+ if (make == null) return;
+
+ if (_secList == null) return;
+
+ SdlSecurityBase sec = null;
+ Service svc = getService();
+ SdlSecurityBase.setAppService(svc);
+
+ for (Class<? extends SdlSecurityBase> cls : _secList)
+ {
+ try
+ {
+ sec = cls.newInstance();
+ }
+ catch (Exception e)
+ {
+ continue;
+ }
+
+ if ( (sec != null) && (sec.getMakeList() != null) )
+ {
+ if (sec.getMakeList().contains(make))
+ {
+ setSdlSecurity(sec);
+ if (sec != null)
+ {
+ sec.setAppId(_appID);
+ if (sdlSession != null)
+ sec.handleSdlSession(sdlSession);
+ }
+ return;
+ }
+ }
+ }
+ }
+
private void handleRPCMessage(Hashtable<String, Object> hash) {
RPCMessage rpcMsg = new RPCMessage(hash);
String functionName = rpcMsg.getFunctionName();
@@ -1752,6 +1837,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
if (msg.getSuccess()) {
_appInterfaceRegisterd = true;
}
+ processRaiResponse(msg);
Intent sendIntent = createBroadcastIntent();
updateBroadcastIntent(sendIntent, "RPC_NAME", FunctionID.REGISTER_APP_INTERFACE.toString());
@@ -1780,7 +1866,9 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
_audioPassThruCapabilities = msg.getAudioPassThruCapabilities();
_hmiCapabilities = msg.getHmiCapabilities();
_systemSoftwareVersion = msg.getSystemSoftwareVersion();
- _proxyVersionInfo = msg.getProxyVersionInfo();
+ _proxyVersionInfo = msg.getProxyVersionInfo();
+
+
if (_bAppResumeEnabled)
{
@@ -1915,7 +2003,8 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
if (msg.getSuccess()) {
_appInterfaceRegisterd = true;
}
-
+ processRaiResponse(msg);
+
//_autoActivateIdReturned = msg.getAutoActivateID();
/*Place holder for legacy support*/ _autoActivateIdReturned = "8675309";
_buttonCapabilities = msg.getButtonCapabilities();
@@ -3245,25 +3334,23 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
private RPCStreamController startRPCStream(String sLocalFile, PutFile request, SessionType sType, byte rpcSessionID, byte wiproVersion)
{
if (sdlSession == null) return null;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return null;
FileInputStream is = getFileInputStream(sLocalFile);
if (is == null) return null;
- Integer iSize = Integer.valueOf(getFileInputStreamSize(is).intValue());
- if (iSize == null)
+ Long lSize = getFileInputStreamSize(is);
+ if (lSize == null)
{
closeFileInputStream(is);
return null;
}
try {
- StreamRPCPacketizer rpcPacketizer = new StreamRPCPacketizer((SdlProxyBase<IProxyListenerBase>) this, sdlConn, is, request, sType, rpcSessionID, wiproVersion, iSize);
+ StreamRPCPacketizer rpcPacketizer = new StreamRPCPacketizer((SdlProxyBase<IProxyListenerBase>) this, sdlSession, is, request, sType, rpcSessionID, wiproVersion, lSize, sdlSession);
rpcPacketizer.start();
RPCStreamController streamController = new RPCStreamController(rpcPacketizer, request.getCorrelationID());
return streamController;
- } catch (Exception e) {
+ } catch (Exception e) {
Log.e("SyncConnection", "Unable to start streaming:" + e.toString());
return null;
}
@@ -3272,18 +3359,16 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
@SuppressWarnings("unchecked")
private RPCStreamController startRPCStream(InputStream is, PutFile request, SessionType sType, byte rpcSessionID, byte wiproVersion)
{
- if (sdlSession == null) return null;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return null;
- Long iSize = request.getLength();
+ if (sdlSession == null) return null;
+ Long lSize = request.getLength();
- if (request.getLength() == null)
+ if (lSize == null)
{
return null;
}
try {
- StreamRPCPacketizer rpcPacketizer = new StreamRPCPacketizer((SdlProxyBase<IProxyListenerBase>) this, sdlConn, is, request, sType, rpcSessionID, wiproVersion, iSize);
+ StreamRPCPacketizer rpcPacketizer = new StreamRPCPacketizer((SdlProxyBase<IProxyListenerBase>) this, sdlSession, is, request, sType, rpcSessionID, wiproVersion, lSize, sdlSession);
rpcPacketizer.start();
RPCStreamController streamController = new RPCStreamController(rpcPacketizer, request.getCorrelationID());
return streamController;
@@ -3295,15 +3380,11 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
private RPCStreamController startPutFileStream(String sPath, PutFile msg) {
if (sdlSession == null) return null;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return null;
return startRPCStream(sPath, msg, SessionType.RPC, sdlSession.getSessionId(), _wiproVersion);
}
private RPCStreamController startPutFileStream(InputStream is, PutFile msg) {
if (sdlSession == null) return null;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return null;
if (is == null) return null;
startRPCStream(is, msg, SessionType.RPC, sdlSession.getSessionId(), _wiproVersion);
return null;
@@ -3311,24 +3392,18 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
public boolean startRPCStream(InputStream is, RPCRequest msg) {
if (sdlSession == null) return false;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return false;
- sdlConn.startRPCStream(is, msg, SessionType.RPC, sdlSession.getSessionId(), _wiproVersion);
+ sdlSession.startRPCStream(is, msg, SessionType.RPC, sdlSession.getSessionId(), _wiproVersion);
return true;
}
public OutputStream startRPCStream(RPCRequest msg) {
if (sdlSession == null) return null;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return null;
- return sdlConn.startRPCStream(msg, SessionType.RPC, sdlSession.getSessionId(), _wiproVersion);
+ return sdlSession.startRPCStream(msg, SessionType.RPC, sdlSession.getSessionId(), _wiproVersion);
}
public void endRPCStream() {
if (sdlSession == null) return;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return;
- sdlConn.stopRPCStream();
+ sdlSession.stopRPCStream();
}
private class CallableMethod implements Callable<Void> {
@@ -3348,7 +3423,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
}
}
public FutureTask<Void> createFutureTask(CallableMethod callMethod){
- return new FutureTask<Void>(callMethod);
+ return new FutureTask<Void>(callMethod);
}
public ScheduledExecutorService createScheduler(){
return Executors.newSingleThreadScheduledExecutor();
@@ -3358,20 +3433,18 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
*Opens the video service (serviceType 11) and subsequently streams raw H264 video from an InputStream provided by the app
*@return true if service is opened successfully and stream is started, return false otherwise
*/
-
- public boolean startH264(InputStream is) {
+ public boolean startH264(InputStream is, boolean isEncrypted) {
if (sdlSession == null) return false;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return false;
-
+
navServiceStartResponseReceived = false;
navServiceStartResponse = false;
- sdlConn.startService(SessionType.NAV, sdlSession.getSessionId());
- FutureTask<Void> fTask = createFutureTask(new CallableMethod(2000));
+ sdlSession.startService(SessionType.NAV, sdlSession.getSessionId(), isEncrypted);
+
+ FutureTask<Void> fTask = createFutureTask(new CallableMethod(RESPONSE_WAIT_TIME));
ScheduledExecutorService scheduler = createScheduler();
- scheduler.execute(fTask);
+ scheduler.execute(fTask);
while (!navServiceStartResponseReceived && !fTask.isDone());
scheduler.shutdown();
@@ -3380,7 +3453,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
if (navServiceStartResponse) {
try {
- sdlConn.startStream(is, SessionType.NAV, sdlSession.getSessionId());
+ sdlSession.startStream(is, SessionType.NAV, sdlSession.getSessionId());
return true;
} catch (Exception e) {
return false;
@@ -3388,23 +3461,21 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
} else {
return false;
}
- }
+ }
/**
*Opens the video service (serviceType 11) and subsequently provides an OutputStream to the app to use for a raw H264 video stream
*@return OutputStream if service is opened successfully and stream is started, return null otherwise
- */
- public OutputStream startH264() {
+ */
+ public OutputStream startH264(boolean isEncrypted) {
if (sdlSession == null) return null;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return null;
navServiceStartResponseReceived = false;
navServiceStartResponse = false;
- sdlConn.startService(SessionType.NAV, sdlSession.getSessionId());
+ sdlSession.startService(SessionType.NAV, sdlSession.getSessionId(), isEncrypted);
- FutureTask<Void> fTask = createFutureTask(new CallableMethod(2000));
+ FutureTask<Void> fTask = createFutureTask(new CallableMethod(RESPONSE_WAIT_TIME));
ScheduledExecutorService scheduler = createScheduler();
scheduler.execute(fTask);
@@ -3415,7 +3486,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
if (navServiceStartResponse) {
try {
- return sdlConn.startStream(SessionType.NAV, sdlSession.getSessionId());
+ return sdlSession.startStream(SessionType.NAV, sdlSession.getSessionId());
} catch (Exception e) {
return null;
}
@@ -3430,14 +3501,12 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
*/
public boolean endH264() {
if (sdlSession == null) return false;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return false;
navServiceEndResponseReceived = false;
navServiceEndResponse = false;
- sdlConn.stopVideoStream();
+ sdlSession.stopVideoStream();
- FutureTask<Void> fTask = createFutureTask(new CallableMethod(2000));
+ FutureTask<Void> fTask = createFutureTask(new CallableMethod(RESPONSE_WAIT_TIME));
ScheduledExecutorService scheduler = createScheduler();
scheduler.execute(fTask);
@@ -3452,7 +3521,6 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
return false;
}
}
-
/**
*Pauses the stream for the opened audio service (serviceType 10)
*@return true if the audio service stream is paused successfully, return false otherwise
@@ -3460,9 +3528,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
public boolean pausePCM()
{
if (sdlSession == null) return false;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return false;
- return sdlConn.pauseAudioStream();
+ return sdlSession.pauseAudioStream();
}
/**
@@ -3472,9 +3538,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
public boolean pauseH264()
{
if (sdlSession == null) return false;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return false;
- return sdlConn.pauseVideoStream();
+ return sdlSession.pauseVideoStream();
}
/**
@@ -3484,9 +3548,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
public boolean resumePCM()
{
if (sdlSession == null) return false;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return false;
- return sdlConn.resumeAudioStream();
+ return sdlSession.resumeAudioStream();
}
/**
@@ -3496,9 +3558,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
public boolean resumeH264()
{
if (sdlSession == null) return false;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return false;
- return sdlConn.resumeVideoStream();
+ return sdlSession.resumeVideoStream();
}
@@ -3506,18 +3566,14 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
*Opens the audio service (serviceType 10) and subsequently streams raw PCM audio from an InputStream provided by the app
*@return true if service is opened successfully and stream is started, return false otherwise
*/
-
- public boolean startPCM(InputStream is) {
+ public boolean startPCM(InputStream is, boolean isEncrypted) {
if (sdlSession == null) return false;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return false;
-
+
pcmServiceStartResponseReceived = false;
pcmServiceStartResponse = false;
- sdlConn.startService(SessionType.PCM, sdlSession.getSessionId());
+ sdlSession.startService(SessionType.PCM, sdlSession.getSessionId(), isEncrypted);
- sdlConn.startService(SessionType.PCM, sdlSession.getSessionId());
- FutureTask<Void> fTask = createFutureTask(new CallableMethod(2000));
+ FutureTask<Void> fTask = createFutureTask(new CallableMethod(RESPONSE_WAIT_TIME));
ScheduledExecutorService scheduler = createScheduler();
scheduler.execute(fTask);
@@ -3528,7 +3584,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
if (pcmServiceStartResponse) {
try {
- sdlConn.startStream(is, SessionType.PCM, sdlSession.getSessionId());
+ sdlSession.startStream(is, SessionType.PCM, sdlSession.getSessionId());
return true;
} catch (Exception e) {
return false;
@@ -3542,15 +3598,14 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
*Opens the audio service (serviceType 10) and subsequently provides an OutputStream to the app
*@return OutputStream if service is opened successfully and stream is started, return null otherwise
*/
- public OutputStream startPCM() {
+ public OutputStream startPCM(boolean isEncrypted) {
if (sdlSession == null) return null;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return null;
pcmServiceStartResponseReceived = false;
pcmServiceStartResponse = false;
- sdlConn.startService(SessionType.PCM, sdlSession.getSessionId());
- FutureTask<Void> fTask = createFutureTask(new CallableMethod(2000));
+ sdlSession.startService(SessionType.PCM, sdlSession.getSessionId(), isEncrypted);
+
+ FutureTask<Void> fTask = createFutureTask(new CallableMethod(RESPONSE_WAIT_TIME));
ScheduledExecutorService scheduler = createScheduler();
scheduler.execute(fTask);
@@ -3561,7 +3616,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
if (pcmServiceStartResponse) {
try {
- return sdlConn.startStream(SessionType.PCM, sdlSession.getSessionId());
+ return sdlSession.startStream(SessionType.PCM, sdlSession.getSessionId());
} catch (Exception e) {
return null;
}
@@ -3581,9 +3636,9 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
pcmServiceEndResponseReceived = false;
pcmServiceEndResponse = false;
- sdlConn.stopAudioStream();
+ sdlSession.stopAudioStream();
- FutureTask<Void> fTask = createFutureTask(new CallableMethod(2000));
+ FutureTask<Void> fTask = createFutureTask(new CallableMethod(RESPONSE_WAIT_TIME));
ScheduledExecutorService scheduler = createScheduler();
scheduler.execute(fTask);
@@ -3609,7 +3664,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
*@return Surface if service is opened successfully and stream is started, return null otherwise
*/
public Surface createOpenGLInputSurface(int frameRate, int iFrameInterval, int width,
- int height, int bitrate) {
+ int height, int bitrate, boolean isEncrypted) {
if (sdlSession == null) return null;
SdlConnection sdlConn = sdlSession.getSdlConnection();
@@ -3617,9 +3672,9 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
navServiceStartResponseReceived = false;
navServiceStartResponse = false;
- sdlConn.startService(SessionType.NAV, sdlSession.getSessionId());
+ sdlSession.startService(SessionType.NAV, sdlSession.getSessionId(), isEncrypted);
- FutureTask<Void> fTask = createFutureTask(new CallableMethod(2000));
+ FutureTask<Void> fTask = createFutureTask(new CallableMethod(RESPONSE_WAIT_TIME));
ScheduledExecutorService scheduler = createScheduler();
scheduler.execute(fTask);
@@ -3629,7 +3684,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
fTask = null;
if (navServiceStartResponse) {
- return sdlConn.createOpenGLInputSurface(frameRate, iFrameInterval, width,
+ return sdlSession.createOpenGLInputSurface(frameRate, iFrameInterval, width,
height, bitrate, SessionType.NAV, sdlSession.getSessionId());
} else {
return null;
@@ -3644,7 +3699,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
SdlConnection sdlConn = sdlSession.getSdlConnection();
if (sdlConn == null) return;
- sdlConn.startEncoder();
+ sdlSession.startEncoder();
}
/**
@@ -3655,7 +3710,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
SdlConnection sdlConn = sdlSession.getSdlConnection();
if (sdlConn == null) return;
- sdlConn.releaseEncoder();
+ sdlSession.releaseEncoder();
}
/**
@@ -3666,8 +3721,8 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
SdlConnection sdlConn = sdlSession.getSdlConnection();
if (sdlConn == null) return;
- sdlConn.drainEncoder(endOfStream);
- }
+ sdlSession.drainEncoder(endOfStream);
+ }
private void NavServiceStarted() {
navServiceStartResponseReceived = true;
@@ -3683,7 +3738,11 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
pcmServiceStartResponseReceived = true;
pcmServiceStartResponse = true;
}
-
+
+ private void RPCProtectedServiceStarted() {
+ rpcProtectedResponseReceived = true;
+ rpcProtectedStartResponse = true;
+ }
private void AudioServiceStartedNACK() {
pcmServiceStartResponseReceived = true;
pcmServiceStartResponse = false;
@@ -3714,6 +3773,27 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
_appService = mService;
}
+ public boolean startProtectedRPCService() {
+ rpcProtectedResponseReceived = false;
+ rpcProtectedStartResponse = false;
+ sdlSession.startService(SessionType.RPC, sdlSession.getSessionId(), true);
+
+ FutureTask<Void> fTask = createFutureTask(new CallableMethod(RESPONSE_WAIT_TIME));
+ ScheduledExecutorService scheduler = createScheduler();
+ scheduler.execute(fTask);
+
+ while (!rpcProtectedResponseReceived && !fTask.isDone());
+ scheduler.shutdown();
+ scheduler = null;
+ fTask = null;
+
+ if (rpcProtectedStartResponse) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
public void getLockScreenIcon(final OnLockScreenIconDownloadedListener l){
if(lockScreenIconRequest == null){
l.onLockScreenIconDownloadError(new SdlException("This version of SDL core may not support lock screen icons.",
@@ -5070,8 +5150,8 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
* @throws SdlException
* @see {@link#putFileStream(String, Long, Long)}
*/
- @Deprecated
- public OutputStream putFileStream(String sdlFileName, Integer iOffset, Integer iLength) throws SdlException
+ @Deprecated
+ public OutputStream putFileStream(String sdlFileName, Integer iOffset, Integer iLength) throws SdlException
{
PutFile msg = RPCRequestFactory.buildPutFile(sdlFileName, iOffset, iLength);
return startRPCStream(msg);
@@ -5108,7 +5188,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
* @throws SdlException
* @see {@link#putFileStream(InputStream, String, Long, Long, FileType, Boolean, Boolean)}
*/
- @Deprecated
+ @Deprecated
public void putFileStream(InputStream is, String sdlFileName, Integer iOffset, Integer iLength, FileType fileType, Boolean bPersistentFile, Boolean bSystemFile) throws SdlException
{
PutFile msg = RPCRequestFactory.buildPutFile(sdlFileName, iOffset, iLength, fileType, bPersistentFile, bSystemFile);
@@ -5154,7 +5234,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
* @throws SdlException
* @see {@link#putFileStream(String, Long, Long, FileType, Boolean, Boolean)}
*/
- @Deprecated
+ @Deprecated
public OutputStream putFileStream(String sdlFileName, Integer iOffset, Integer iLength, FileType fileType, Boolean bPersistentFile, Boolean bSystemFile) throws SdlException
{
PutFile msg = RPCRequestFactory.buildPutFile(sdlFileName, iOffset, iLength, fileType, bPersistentFile, bSystemFile);
@@ -5200,7 +5280,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
* @throws SdlException
* @see {@link#putFileStream(String, String, Long, FileType, Boolean, Boolean, Integer)}
*/
- @Deprecated
+ @Deprecated
public RPCStreamController putFileStream(String sPath, String sdlFileName, Integer iOffset, FileType fileType, Boolean bPersistentFile, Boolean bSystemFile, Integer iCorrelationID) throws SdlException
{
PutFile msg = RPCRequestFactory.buildPutFile(sdlFileName, iOffset, 0, fileType, bPersistentFile, bSystemFile, iCorrelationID);
@@ -5229,8 +5309,8 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
* returned .
* @throws SdlException
*/
- public RPCStreamController putFileStream(String path, String fileName, Long offset, FileType fileType, Boolean isPersistentFile, Boolean isSystemFile, Integer correlationId,OnPutFileUpdateListener cb ) throws SdlException {
- PutFile msg = RPCRequestFactory.buildPutFile(fileName, offset, 0L, fileType, isPersistentFile, isSystemFile, correlationId);
+ public RPCStreamController putFileStream(String path, String fileName, Long offset, FileType fileType, Boolean isPersistentFile, Boolean isSystemFile, Boolean isPayloadProtected, Integer correlationId, OnPutFileUpdateListener cb ) throws SdlException {
+ PutFile msg = RPCRequestFactory.buildPutFile(fileName, offset, 0L, fileType, isPersistentFile, isSystemFile, isPayloadProtected, correlationId);
msg.setOnPutFileUpdateListener(cb);
return startPutFileStream(path,msg);
}
@@ -5251,7 +5331,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
* @throws SdlException
* @see {@link#putFileStream(InputStream, String, Long, Long, FileType, Boolean, Boolean, Integer)}
*/
- @Deprecated
+ @Deprecated
public RPCStreamController putFileStream(InputStream is, String sdlFileName, Integer iOffset, Integer iLength, FileType fileType, Boolean bPersistentFile, Boolean bSystemFile, Integer iCorrelationID) throws SdlException
{
PutFile msg = RPCRequestFactory.buildPutFile(sdlFileName, iOffset, iLength, fileType, bPersistentFile, bSystemFile, iCorrelationID);
@@ -5278,8 +5358,8 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
* RPCResponse.
* @throws SdlException
*/
- public RPCStreamController putFileStream(InputStream inputStream, String fileName, Long offset, Long length, FileType fileType, Boolean isPersistentFile, Boolean isSystemFile, Integer correlationId) throws SdlException {
- PutFile msg = RPCRequestFactory.buildPutFile(fileName, offset, length, fileType, isPersistentFile, isSystemFile, correlationId);
+ public RPCStreamController putFileStream(InputStream inputStream, String fileName, Long offset, Long length, FileType fileType, Boolean isPersistentFile, Boolean isSystemFile, Boolean isPayloadProtected, Integer correlationId) throws SdlException {
+ PutFile msg = RPCRequestFactory.buildPutFile(fileName, offset, length, fileType, isPersistentFile, isSystemFile, isPayloadProtected, correlationId);
return startPutFileStream(inputStream, msg);
}
@@ -5383,6 +5463,25 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
return sdlSession.getCurrentTransportType();
}
+ public void setSdlSecurityClassList(List<Class<? extends SdlSecurityBase>> list) {
+ _secList = list;
+ }
+
+ private void setSdlSecurity(SdlSecurityBase sec) {
+ if (sdlSession != null)
+ {
+ sdlSession.setSdlSecurity(sec);
+ }
+ }
+
+ public boolean isServiceTypeProtected(SessionType sType)
+ {
+ if (sdlSession == null)
+ return false;
+
+ return sdlSession.isServiceProtected(sType);
+ }
+
public IProxyListenerBase getProxyListener()
{
return _proxyListener;
diff --git a/sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyBuilder.java b/sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyBuilder.java
index 478b59db6..9e6921a61 100644
--- a/sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyBuilder.java
+++ b/sdl_android_lib/src/com/smartdevicelink/proxy/SdlProxyBuilder.java
@@ -1,5 +1,6 @@
package com.smartdevicelink.proxy;
+import java.util.List;
import java.util.Vector;
import com.smartdevicelink.exception.SdlException;
@@ -8,9 +9,13 @@ import com.smartdevicelink.proxy.rpc.SdlMsgVersion;
import com.smartdevicelink.proxy.rpc.TTSChunk;
import com.smartdevicelink.proxy.rpc.enums.AppHMIType;
import com.smartdevicelink.proxy.rpc.enums.Language;
+import com.smartdevicelink.security.SdlSecurityBase;
import com.smartdevicelink.transport.BTTransportConfig;
import com.smartdevicelink.transport.BaseTransportConfig;
+import com.smartdevicelink.transport.MultiplexTransportConfig;
+
import android.app.Service;
+import android.content.Context;
public class SdlProxyBuilder
{
@@ -34,7 +39,8 @@ public class SdlProxyBuilder
private boolean preRegister;
private String sAppResumeHash;
private BaseTransportConfig mTransport;
-
+ private List<Class<? extends SdlSecurityBase>> sdlSecList;
+
public static class Builder
{
// Required parameters
@@ -42,6 +48,7 @@ public class SdlProxyBuilder
private String appId;
private String appName;
private Boolean isMediaApp;
+ private Context context;
// Optional parameters - initialized to default values
private Service service = null;
@@ -57,16 +64,32 @@ public class SdlProxyBuilder
private boolean callbackToUIThread = false;
private boolean preRegister = false;
private String sAppResumeHash = null;
- private BaseTransportConfig mTransport = new BTTransportConfig();
-
+ private List<Class<? extends SdlSecurityBase>> sdlSecList = null;
+ private BaseTransportConfig mTransport; //Initialized in constructor
+
+ /**
+ * @deprecated Use Builder(IProxyListenerALM, String, String, Boolean, Context) instead
+ */
+ @Deprecated
public Builder(IProxyListenerALM listener, String appId, String appName, Boolean isMediaApp)
{
this.listener = listener;
this.appId = appId;
this.appName = appName;
this.isMediaApp = isMediaApp;
+ this.mTransport = new BTTransportConfig();
}
-
+
+ public Builder(IProxyListenerALM listener, String appId, String appName, Boolean isMediaApp, Context context)
+ {
+ this.listener = listener;
+ this.appId = appId;
+ this.appName = appName;
+ this.isMediaApp = isMediaApp;
+ this.context = context;
+ this.mTransport = new MultiplexTransportConfig(context, appId);
+ }
+
public Builder setService(Service val)
{ service = val; return this; }
public Builder setSdlProxyConfigurationResources(SdlProxyConfigurationResources val)
@@ -95,11 +118,15 @@ public class SdlProxyBuilder
{ sAppResumeHash = val; return this; }
public Builder setTransportType(BaseTransportConfig val)
{ mTransport = val; return this; }
+ public Builder setSdlSecurity(List<Class<? extends SdlSecurityBase>> val)
+ { sdlSecList = val; return this; }
public SdlProxyALM build() throws SdlException
{
SdlProxyBuilder obj = new SdlProxyBuilder(this);
- return new SdlProxyALM(obj.service,obj.listener,obj.sdlProxyConfigurationResources,obj.appName,obj.ttsChunks,obj.sShortAppName,obj.vrSynonyms,obj.isMediaApp,obj.sdlMessageVersion,obj.lang,obj.hmiLang,obj.vrAppHMITypes,obj.appId,obj.autoActivateID,obj.callbackToUIThread,obj.preRegister,obj.sAppResumeHash,obj.mTransport);
+ SdlProxyALM proxy = new SdlProxyALM(obj.service,obj.listener,obj.sdlProxyConfigurationResources,obj.appName,obj.ttsChunks,obj.sShortAppName,obj.vrSynonyms,obj.isMediaApp,obj.sdlMessageVersion,obj.lang,obj.hmiLang,obj.vrAppHMITypes,obj.appId,obj.autoActivateID,obj.callbackToUIThread,obj.preRegister,obj.sAppResumeHash,obj.mTransport);
+ proxy.setSdlSecurityClassList(obj.sdlSecList);
+ return proxy;
}
}
@@ -124,6 +151,7 @@ public class SdlProxyBuilder
preRegister = builder.preRegister;
sAppResumeHash = builder.sAppResumeHash;
mTransport = builder.mTransport;
+ sdlSecList = builder.sdlSecList;
}
}
diff --git a/sdl_android_lib/src/com/smartdevicelink/proxy/interfaces/IProxyListenerBase.java b/sdl_android_lib/src/com/smartdevicelink/proxy/interfaces/IProxyListenerBase.java
index 2f148ad30..1861b266b 100644
--- a/sdl_android_lib/src/com/smartdevicelink/proxy/interfaces/IProxyListenerBase.java
+++ b/sdl_android_lib/src/com/smartdevicelink/proxy/interfaces/IProxyListenerBase.java
@@ -84,14 +84,14 @@ public interface IProxyListenerBase {
*/
public void onProxyClosed(String info, Exception e, SdlDisconnectedReason reason);
- public void onServiceEnded(OnServiceEnded serviceEnded);
-
+ public void onServiceEnded(OnServiceEnded serviceEnded);
+
public void onServiceNACKed(OnServiceNACKed serviceNACKed);
-
+
public void onOnStreamRPC(OnStreamRPC notification);
public void onStreamRPCResponse(StreamRPCResponse response);
-
+
/**
* onProxyError() being called indicates that the SDL Proxy experenced an error.
*
@@ -317,12 +317,12 @@ public interface IProxyListenerBase {
public void onDialNumberResponse(DialNumberResponse response);
public void onSendLocationResponse(SendLocationResponse response);
-
+
public void onShowConstantTbtResponse(ShowConstantTbtResponse response);
public void onAlertManeuverResponse(AlertManeuverResponse response);
public void onUpdateTurnListResponse(UpdateTurnListResponse response);
-
- public void onServiceDataACK();
+
+ public void onServiceDataACK(int dataSize);
}
diff --git a/sdl_android_lib/src/com/smartdevicelink/proxy/rpc/TouchEvent.java b/sdl_android_lib/src/com/smartdevicelink/proxy/rpc/TouchEvent.java
index 8d13baa21..76e3c4207 100644
--- a/sdl_android_lib/src/com/smartdevicelink/proxy/rpc/TouchEvent.java
+++ b/sdl_android_lib/src/com/smartdevicelink/proxy/rpc/TouchEvent.java
@@ -84,8 +84,18 @@ public class TouchEvent extends RPCStruct {
return (Integer) store.get(KEY_ID);
}
- @SuppressWarnings("unchecked")
+ /**
+ * Use getTimestamps
+ * @deprecated 4.0.2
+ * @return
+ */
+ @Deprecated
public List<Long> getTs() {
+ return getTimestamps();
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Long> getTimestamps() {
if(store.get(KEY_TS) instanceof List<?>){
List<?> list = (List<?>)store.get(KEY_TS);
if(list != null && list.size()>0){
@@ -106,16 +116,35 @@ public class TouchEvent extends RPCStruct {
return null;
}
- public void setTs(List<Long> ts) {
- if (ts != null) {
+ public void setTimestamps(List<Long> ts){
+ if (ts != null) {
store.put(KEY_TS, ts);
} else {
store.remove(KEY_TS);
}
}
- @SuppressWarnings("unchecked")
+ /**
+ * Use setTimestamps.
+ * @deprecated 4.0.2
+ * @param ts
+ */
+ @Deprecated
+ public void setTs(List<Long> ts) {
+ setTimestamps(ts);
+ }
+
+ /**
+ * Use getTouchCoordinates
+ * @deprecated 4.0.2
+ * @return
+ */
+ @Deprecated
public List<TouchCoord> getC() {
+ return getTouchCoordinates();
+ }
+ @SuppressWarnings("unchecked")
+ public List<TouchCoord> getTouchCoordinates() {
if (store.get(KEY_C) instanceof List<?>) {
List<?> list = (List<?>)store.get(KEY_C);
if (list != null && list.size() > 0) {
@@ -134,7 +163,17 @@ public class TouchEvent extends RPCStruct {
return null;
}
+ /**
+ * Use setTouchCoordinates
+ * @deprecated 4.0.2
+ * @return
+ */
+ @Deprecated
public void setC( List<TouchCoord> c ) {
+ setTouchCoordinates(c);
+ }
+
+ public void setTouchCoordinates( List<TouchCoord> c ) {
if (c != null) {
store.put(KEY_C, c );
} else {
diff --git a/sdl_android_lib/src/com/smartdevicelink/security/ISecurityInitializedListener.java b/sdl_android_lib/src/com/smartdevicelink/security/ISecurityInitializedListener.java
new file mode 100644
index 000000000..f18152ed0
--- /dev/null
+++ b/sdl_android_lib/src/com/smartdevicelink/security/ISecurityInitializedListener.java
@@ -0,0 +1,5 @@
+package com.smartdevicelink.security;
+
+public interface ISecurityInitializedListener {
+ public void onSecurityInitialized();
+}
diff --git a/sdl_android_lib/src/com/smartdevicelink/security/SdlSecurityBase.java b/sdl_android_lib/src/com/smartdevicelink/security/SdlSecurityBase.java
new file mode 100644
index 000000000..8b7e6a12a
--- /dev/null
+++ b/sdl_android_lib/src/com/smartdevicelink/security/SdlSecurityBase.java
@@ -0,0 +1,100 @@
+package com.smartdevicelink.security;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.app.Service;
+
+import com.smartdevicelink.SdlConnection.SdlSession;
+import com.smartdevicelink.protocol.enums.SessionType;
+
+public abstract class SdlSecurityBase {
+
+ protected SdlSession session = null;
+ protected String appId = null;
+ protected List<String> makeList = null;
+ protected boolean isInitSuccess = false;
+ protected byte sessionId = 0;
+ protected static Service appService = null;
+ protected List<SessionType> startServiceList = new ArrayList<SessionType>();
+
+ public SdlSecurityBase() {
+ }
+
+ public abstract void initialize();
+
+ public abstract Integer runHandshake(byte[] inputData,byte[] outputData);
+
+ public abstract Integer encryptData(byte[] inputData,byte[] outputData);
+
+ public abstract Integer decryptData(byte[] inputData,byte[] outputData);
+
+ public abstract void shutDown();
+
+ public void resetParams() {
+ session = null;
+ appId = null;
+ isInitSuccess = false;
+ startServiceList.clear();
+ }
+
+ public List<SessionType> getServiceList() {
+ return startServiceList;
+ }
+
+ public void handleInitResult(boolean val) {
+ setInitSuccess(val);
+ session.onSecurityInitialized();
+ }
+
+ public void handleSdlSession(SdlSession val) {
+ if (val == null) return;
+
+ setSessionId(val.getSessionId());
+ setSdlSession(val);
+ }
+
+ private void setInitSuccess(boolean val) {
+ isInitSuccess = val;
+ }
+
+ public boolean getInitSuccess() {
+ return isInitSuccess;
+ }
+
+ private void setSessionId(byte val) {
+ sessionId = val;
+ }
+
+ public byte getSessionId() {
+ return sessionId;
+ }
+
+ private void setSdlSession(SdlSession val) {
+ session = val;
+ }
+
+ public String getAppId() {
+ return appId;
+ }
+
+ public void setAppId(String val) {
+ appId = val;
+ }
+
+ public static Service getAppService() {
+ return appService;
+ }
+
+ public static void setAppService(Service val) {
+ appService = val;
+ }
+
+ public List<String> getMakeList() {
+ return makeList;
+ }
+
+ public void setMakeList(List<String> val) {
+ makeList = val;
+ }
+}
diff --git a/sdl_android_lib/src/com/smartdevicelink/streaming/AbstractPacketizer.java b/sdl_android_lib/src/com/smartdevicelink/streaming/AbstractPacketizer.java
index 88a1dea81..b4ee3ed1f 100644
--- a/sdl_android_lib/src/com/smartdevicelink/streaming/AbstractPacketizer.java
+++ b/sdl_android_lib/src/com/smartdevicelink/streaming/AbstractPacketizer.java
@@ -3,6 +3,7 @@ package com.smartdevicelink.streaming;
import java.io.IOException;
import java.io.InputStream;
+import com.smartdevicelink.SdlConnection.SdlSession;
import com.smartdevicelink.protocol.enums.SessionType;
import com.smartdevicelink.proxy.RPCRequest;
@@ -12,9 +13,10 @@ abstract public class AbstractPacketizer {
private final static int BUFF_READ_SIZE = 1000000;
protected byte _rpcSessionID = 0;
- protected SessionType _session = null;
- protected InputStream is = null;
- protected byte[] buffer = new byte[BUFF_READ_SIZE];
+ protected SessionType _serviceType = null;
+ protected SdlSession _session = null;
+ protected InputStream is = null;
+ protected byte[] buffer = new byte[BUFF_READ_SIZE];
protected boolean upts = false;
protected RPCRequest _request = null;
protected byte _wiproVersion = 1;
@@ -22,20 +24,22 @@ abstract public class AbstractPacketizer {
//protected long ts = 0, intervalBetweenReports = 5000, delta = 0;
protected long intervalBetweenReports = 5000, delta = 0;
- public AbstractPacketizer(IStreamListener streamListener, InputStream is, SessionType sType, byte rpcSessionID) throws IOException {
+ public AbstractPacketizer(IStreamListener streamListener, InputStream is, SessionType sType, byte rpcSessionID, SdlSession session) throws IOException {
this._streamListener = streamListener;
this.is = is;
_rpcSessionID = rpcSessionID;
- _session = sType;
+ _serviceType = sType;
+ this._session = session;
}
- public AbstractPacketizer(IStreamListener streamListener, InputStream is, RPCRequest request, SessionType sType, byte rpcSessionID, byte wiproVersion) throws IOException {
+ public AbstractPacketizer(IStreamListener streamListener, InputStream is, RPCRequest request, SessionType sType, byte rpcSessionID, byte wiproVersion, SdlSession session) throws IOException {
this._streamListener = streamListener;
this.is = is;
_rpcSessionID = rpcSessionID;
- _session = sType;
+ _serviceType = sType;
_request = request;
_wiproVersion = wiproVersion;
+ this._session = session;
}
public abstract void start() throws IOException;
@@ -45,5 +49,4 @@ abstract public class AbstractPacketizer {
public abstract void pause();
public abstract void resume();
-
-}
+}
diff --git a/sdl_android_lib/src/com/smartdevicelink/streaming/StreamPacketizer.java b/sdl_android_lib/src/com/smartdevicelink/streaming/StreamPacketizer.java
index cd807fd8e..a05fb9c52 100644
--- a/sdl_android_lib/src/com/smartdevicelink/streaming/StreamPacketizer.java
+++ b/sdl_android_lib/src/com/smartdevicelink/streaming/StreamPacketizer.java
@@ -4,22 +4,28 @@ import java.io.IOException;
import java.io.InputStream;
import com.smartdevicelink.SdlConnection.SdlConnection;
+import com.smartdevicelink.SdlConnection.SdlSession;
import com.smartdevicelink.protocol.ProtocolMessage;
import com.smartdevicelink.protocol.enums.SessionType;
public class StreamPacketizer extends AbstractPacketizer implements Runnable{
- public final static String TAG = "StreamPacketizer";
- private Thread t = null;
+ public final static String TAG = "StreamPacketizer";
+
+ private Thread t = null;
+
+ private final static int BUFF_READ_SIZE = 1024;
public SdlConnection sdlConnection = null;
private Object mPauseLock;
private boolean mPaused;
-
- public StreamPacketizer(IStreamListener streamListener, InputStream is, SessionType sType, byte rpcSessionID) throws IOException {
- super(streamListener, is, sType, rpcSessionID);
+ private boolean isServiceProtected = false;
+
+ public StreamPacketizer(IStreamListener streamListener, InputStream is, SessionType sType, byte rpcSessionID, SdlSession session) throws IOException {
+ super(streamListener, is, sType, rpcSessionID, session);
mPauseLock = new Object();
mPaused = false;
+ isServiceProtected = _session.isServiceProtected(_serviceType);
}
public void start() throws IOException {
@@ -41,11 +47,10 @@ public class StreamPacketizer extends AbstractPacketizer implements Runnable{
public void run() {
int length;
-
try
{
while (t != null && !t.isInterrupted())
- {
+ {
synchronized(mPauseLock)
{
while (mPaused)
@@ -58,16 +63,17 @@ public class StreamPacketizer extends AbstractPacketizer implements Runnable{
}
}
- length = is.read(buffer, 0, 1488);
+ length = is.read(buffer, 0, BUFF_READ_SIZE);
if (length >= 0)
{
ProtocolMessage pm = new ProtocolMessage();
pm.setSessionID(_rpcSessionID);
- pm.setSessionType(_session);
+ pm.setSessionType(_serviceType);
pm.setFunctionID(0);
pm.setCorrID(0);
pm.setData(buffer, length);
+ pm.setPayloadProtected(isServiceProtected);
if (t != null && !t.isInterrupted())
_streamListener.sendStreamPacket(pm);
@@ -81,7 +87,7 @@ public class StreamPacketizer extends AbstractPacketizer implements Runnable{
{
if (sdlConnection != null)
{
- sdlConnection.endService(_session, _rpcSessionID);
+ sdlConnection.endService(_serviceType, _rpcSessionID);
}
}
diff --git a/sdl_android_lib/src/com/smartdevicelink/streaming/StreamRPCPacketizer.java b/sdl_android_lib/src/com/smartdevicelink/streaming/StreamRPCPacketizer.java
index ac9ebb379..2fc35a5a9 100644
--- a/sdl_android_lib/src/com/smartdevicelink/streaming/StreamRPCPacketizer.java
+++ b/sdl_android_lib/src/com/smartdevicelink/streaming/StreamRPCPacketizer.java
@@ -4,6 +4,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Hashtable;
+import com.smartdevicelink.SdlConnection.SdlSession;
+
import com.smartdevicelink.marshal.JsonRPCMarshaller;
import com.smartdevicelink.protocol.ProtocolMessage;
import com.smartdevicelink.protocol.enums.FunctionID;
@@ -31,18 +33,19 @@ public class StreamRPCPacketizer extends AbstractPacketizer implements IPutFileR
private String sFileName;
private SdlProxyBase<IProxyListenerBase> _proxy;
private IProxyListenerBase _proxyListener;
-
+
private Object mPauseLock;
private boolean mPaused;
-
- private OnPutFileUpdateListener callBack;
-
- public StreamRPCPacketizer(SdlProxyBase<IProxyListenerBase> proxy, IStreamListener streamListener, InputStream is, RPCRequest request, SessionType sType, byte rpcSessionID, byte wiproVersion, long iLength) throws IOException {
- super(streamListener, is, request, sType, rpcSessionID, wiproVersion);
- lFileSize = iLength;
+ private boolean isRPCProtected = false;
+ private OnPutFileUpdateListener callBack;
+
+ public StreamRPCPacketizer(SdlProxyBase<IProxyListenerBase> proxy, IStreamListener streamListener, InputStream is, RPCRequest request, SessionType sType, byte rpcSessionID, byte wiproVersion, long lLength, SdlSession session) throws IOException {
+ super(streamListener, is, request, sType, rpcSessionID, wiproVersion, session);
+ lFileSize = lLength;
iInitialCorrID = request.getCorrelationID();
mPauseLock = new Object();
mPaused = false;
+ isRPCProtected = request.isPayloadProtected();
if (proxy != null)
{
_proxy = proxy;
@@ -51,7 +54,7 @@ public class StreamRPCPacketizer extends AbstractPacketizer implements IPutFileR
}
if(_request.getFunctionName().equalsIgnoreCase(FunctionID.PUT_FILE.toString())){
callBack = ((PutFile)_request).getOnPutFileUpdateListener();
- }
+ }
}
@Override
@@ -142,6 +145,7 @@ public class StreamRPCPacketizer extends AbstractPacketizer implements IPutFileR
byte[] msgBytes;
ProtocolMessage pm;
OnStreamRPC notification;
+
// Moves the current Thread into the background
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
@@ -149,8 +153,9 @@ public class StreamRPCPacketizer extends AbstractPacketizer implements IPutFileR
int iCorrID = 0;
PutFile msg = (PutFile) _request;
- long iOffsetCounter = msg.getOffset();
sFileName = msg.getSdlFileName();
+ long iOffsetCounter = msg.getOffset();
+
int priorityCoefficient = 1;
if (lFileSize != 0)
@@ -203,7 +208,7 @@ public class StreamRPCPacketizer extends AbstractPacketizer implements IPutFileR
pm.setSessionID(_rpcSessionID);
pm.setMessageType(MessageType.RPC);
- pm.setSessionType(_session);
+ pm.setSessionType(_serviceType);
pm.setFunctionID(FunctionID.getFunctionId(msg.getFunctionName()));
if (buffer.length != length)
@@ -212,6 +217,7 @@ public class StreamRPCPacketizer extends AbstractPacketizer implements IPutFileR
pm.setBulkDataNoCopy(buffer);
pm.setCorrID(msg.getCorrelationID());
+ pm.setPayloadProtected(isRPCProtected);
priorityCoefficient++;
pm.setPriorityCoefficient(priorityCoefficient);
@@ -225,7 +231,7 @@ public class StreamRPCPacketizer extends AbstractPacketizer implements IPutFileR
msg.setOffset(iOffsetCounter);
iCorrID = msg.getCorrelationID() + 1;
msg.setCorrelationID(iCorrID);
-
+
_streamListener.sendStreamPacket(pm);
}
}
diff --git a/sdl_android_lib/src/com/smartdevicelink/trace/SdlTrace.java b/sdl_android_lib/src/com/smartdevicelink/trace/SdlTrace.java
index 93f8ca246..2d997b1c4 100644
--- a/sdl_android_lib/src/com/smartdevicelink/trace/SdlTrace.java
+++ b/sdl_android_lib/src/com/smartdevicelink/trace/SdlTrace.java
@@ -274,7 +274,7 @@ public class SdlTrace {
sb.append("<ver>");
sb.append(hdr.getVersion());
sb.append("</ver><cmp>");
- sb.append(hdr.isCompression());
+ sb.append(hdr.isEncrypted());
sb.append("</cmp><ft>");
sb.append(getProtocolFrameType(hdr.getFrameType()));
sb.append("</ft><st>");
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/BTTransport.java b/sdl_android_lib/src/com/smartdevicelink/transport/BTTransport.java
index e41c501e5..f64ff3668 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/BTTransport.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/BTTransport.java
@@ -187,7 +187,7 @@ public class BTTransport extends SdlTransport {
throw new SdlException("Bluetooth adapter must be on to instantiate a SdlProxy object.", SdlExceptionCause.BLUETOOTH_DISABLED);
}
- if(((SdlException) ex).getSdlExceptionCause() == SdlExceptionCause.BLUETOOTH_SOCKET_UNAVAILABLE) {
+ 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);
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexBluetoothTransport.java b/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexBluetoothTransport.java
index 08fe98586..95746b05a 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexBluetoothTransport.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexBluetoothTransport.java
@@ -49,7 +49,7 @@ public class MultiplexBluetoothTransport {
private static final String TAG = "Bluetooth Transport";
private static final UUID SERVER_UUID= new UUID(0x936DA01F9ABD4D9DL, 0x80C702AF85C822A8L);
// Name for the SDP record when creating server socket
- private static final String NAME_SECURE =" SdlProxy";// = "LIVIO_CONNECT";
+ private static final String NAME_SECURE =" SdlRouterService";
protected static final String SHARED_PREFS = "sdl.bluetoothprefs";
@@ -696,7 +696,7 @@ public class MultiplexBluetoothTransport {
//Log.d(TAG, "Creating a Connected - Write Thread");
mmSocket = socket;
OutputStream tmpOut = null;
- setName(" Livio Bluetooth Write Thread");
+ setName("SDL Router BT Write Thread");
// Get the BluetoothSocket input and output streams
try {
tmpOut = socket.getOutputStream();
@@ -731,7 +731,6 @@ public class MultiplexBluetoothTransport {
public synchronized void cancel() {
try {
- Log.d(TAG, "Calling Cancel in the write thread");
if(mmOutStream!=null){
mmOutStream.flush();
mmOutStream.close();
@@ -756,7 +755,7 @@ public class MultiplexBluetoothTransport {
//Log.d(TAG, "Creating a Connected - Read Thread");
mmSocket = socket;
InputStream tmpIn = null;
- setName(" Livio Bluetooth Read Thread");
+ setName("SDL Router BT Read Thread");
// Get the BluetoothSocket input and output streams
try {
tmpIn = socket.getInputStream();
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexTransport.java b/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexTransport.java
index 5556d9af1..39c401e1f 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexTransport.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexTransport.java
@@ -15,7 +15,7 @@ import com.smartdevicelink.transport.enums.TransportType;
public class MultiplexTransport extends SdlTransport{
private final static String TAG = "Multiplex Transport";
- private String sComment = "I'm_a_little_teapot";
+ private String sComment = "Multiplexing";
TransportBrokerThread brokerThread;
protected boolean isDisconnecting = false;
@@ -33,16 +33,6 @@ public class MultiplexTransport extends SdlTransport{
//brokerThread.start();
}
-
- public boolean forceHardwareConnectEvent(TransportType type){
- if(brokerThread!=null){
- brokerThread.onHardwareConnected(type);
- return true;
- }
- Log.w(TAG, "Transport broker thread was null, nothing to force connect. Are we disconnecting? " + isDisconnecting);
- return false;
-
- }
public boolean isDisconnecting(){
return this.isDisconnecting;
@@ -223,7 +213,7 @@ public class MultiplexTransport extends SdlTransport{
public void run() {
Looper.prepare();
- if(broker==null){Log.d("JOEY", "Starting broker");
+ if(broker==null){
synchronized(this){
initTransportBroker();
if(queueStart){
@@ -238,7 +228,6 @@ public class MultiplexTransport extends SdlTransport{
}
threadLooper = Looper.myLooper();
Looper.loop();
- Log.i(TAG, "Looper has finished. Thread should be sutting down");
}
@@ -252,9 +241,8 @@ public class MultiplexTransport extends SdlTransport{
Log.d(TAG, "On transport connected...");
if(!connected){
connected = true;
- Log.d(TAG, "Handling transport connected");
handleTransportConnected();
- }else{Log.d(TAG, "Already connected");}
+ }//else{Log.d(TAG, "Already connected");}
return true;
}else{
try{
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java b/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java
index 5809a19aa..3c5b71c5e 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java
@@ -35,7 +35,7 @@ import com.smartdevicelink.util.HttpRequestTask.HttpRequestTaskCallback;
*
*/
public class RouterServiceValidator {
- private static final String TAG = "PackageCheckUtl";
+ private static final String TAG = "RSVP";
public static final String ROUTER_SERVICE_PACKAGE = "com.sdl.router";
private static final String REQUEST_PREFIX = "https://woprjr.smartdevicelink.com/api/1/applications/queryTrustedRouters";
@@ -116,7 +116,7 @@ public class RouterServiceValidator {
}
}
- Log.d(TAG, "Checking app package: " + service.getClassName());
+ //Log.d(TAG, "Checking app package: " + service.getClassName());
packageName = this.appPackageForComponentName(service, pm);
@@ -328,10 +328,9 @@ public class RouterServiceValidator {
intent.setAction("sdl.router.startservice");
List<ResolveInfo> infoList = packageManager.queryBroadcastReceivers(intent, 0);
if(infoList!=null){
- Log.i(TAG, "Number of SDL apps: " + infoList.size());
String packageName;
for(ResolveInfo info : infoList){
- Log.i(TAG, "SDL apps: " + info.activityInfo.packageName);
+ //Log.i(TAG, "SDL apps: " + info.activityInfo.packageName);
packageName = info.activityInfo.packageName;
try {
apps.add(new SdlApp(packageName,packageManager.getPackageInfo(packageName,0).versionCode));
@@ -362,7 +361,6 @@ public class RouterServiceValidator {
}
if(!forceRefresh && (System.currentTimeMillis()-getTrustedAppListTimeStamp(context))<REFRESH_TRUSTED_APP_LIST_TIME){
- Log.d(TAG, "Don't need to get new list");
//Our list should still be ok for now so we will skip the request
pendingListRefresh = false;
return false;
@@ -393,15 +391,13 @@ public class RouterServiceValidator {
try {object.put(JSON_PUT_ARRAY_TAG, array);} catch (JSONException e) {e.printStackTrace();}
- Log.d(TAG, "Request of apps: " + object.toString());
-
if (cb == null) {
cb = new HttpRequestTaskCallback() {
@Override
public void httpCallComplete(String response) {
// Might want to check if this list is ok
- Log.d(TAG, "APPS! " + response);
+ //Log.d(TAG, "APPS! " + response);
setTrustedList(context, response);
pendingListRefresh = false;
}
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java b/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java
index 70589bc4a..a304191ff 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java
@@ -1,6 +1,8 @@
package com.smartdevicelink.transport;
import java.util.Locale;
+import java.util.Vector;
+import java.util.concurrent.ConcurrentLinkedQueue;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
@@ -9,8 +11,6 @@ import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;
public abstract class SdlBroadcastReceiver extends BroadcastReceiver{
@@ -29,7 +29,7 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{
public static final String TRANSPORT_GLOBAL_PREFS = "SdlTransportPrefs";
public static final String IS_TRANSPORT_CONNECTED = "isTransportConnected";
- public static ComponentName runningBluetoothServicePackage = null;
+ public static Vector<ComponentName> runningBluetoothServicePackage = null;
@SuppressWarnings("rawtypes")
private static Class localRouterClass;
@@ -72,15 +72,15 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{
String packageName = intent.getStringExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_APP_PACKAGE);
ComponentName componentName = intent.getParcelableExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_CMP_NAME);
if(componentName!=null){
- Log.v(TAG, "SDL enabled by router service from " + packageName + " compnent package " + componentName.getPackageName() + " - " + componentName.getClassName());
+ //Log.v(TAG, "SDL enabled by router service from " + packageName + " compnent package " + componentName.getPackageName() + " - " + componentName.getClassName());
RouterServiceValidator vlad = new RouterServiceValidator(context,componentName);
if(vlad.validate()){
- Log.d(TAG, "Router service trusted!");
+ //Log.d(TAG, "Router service trusted!");
queuedService = componentName;
intent.setAction("com.sdl.noaction"); //Replace what's there so we do go into some unintended loop
onSdlEnabled(context, intent);
}else{
- Log.e(TAG, "RouterService was not trusted. Ignoring intent from : "+ componentName.getClassName());
+ Log.w(TAG, "RouterService was not trusted. Ignoring intent from : "+ componentName.getClassName());
}
}
@@ -93,7 +93,6 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{
return;
}else if(intent.getBooleanExtra(TransportConstants.PING_ROUTER_SERVICE_EXTRA, false)){
//We were told to wake up our router services
- Log.d(TAG, "Starting router service off ping");
boolean altServiceWake = intent.getBooleanExtra(TransportConstants.BIND_REQUEST_TYPE_ALT_TRANSPORT, false);
didStart = wakeUpRouterService(context, false,altServiceWake );
@@ -113,7 +112,6 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{
return;
}else if(state == BluetoothAdapter.STATE_TURNING_ON){
//We started bluetooth, we should check for a new valid router list
- Log.d(TAG, "Attempting to get list of approved router services");
RouterServiceValidator.createTrustedListRequest(context,true);
}
}
@@ -121,7 +119,6 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{
if(localRouterClass!=null){ //If there is a supplied router service lets run some logic regarding starting one
if(!didStart){
- Log.d(TAG, "Waking up router service");
didStart = wakeUpRouterService(context, true,false);
}
@@ -138,10 +135,8 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{
}
private boolean wakeUpRouterService(Context context, boolean ping, boolean altTransportWake){
- Log.d(TAG, "Waking up router service");
if(!isRouterServiceRunning(context, ping)){
//If there isn't a service running we should try to start one
- Log.i(TAG, "Attempting to start an instance of the Router Service");
//The under class should have implemented this....
//So let's start up our service since no copy is running
@@ -152,18 +147,21 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{
context.startService(serviceIntent);
return true;
}else{
- Log.i(TAG, "An instance of the Router Service is already running");
- if(altTransportWake){
+ if(altTransportWake && runningBluetoothServicePackage!=null && runningBluetoothServicePackage.size()>0){
Intent serviceIntent = new Intent();
- serviceIntent.setComponent(runningBluetoothServicePackage);
serviceIntent.setAction(TransportConstants.BIND_REQUEST_TYPE_ALT_TRANSPORT);
- context.startService(serviceIntent);
+ //context.startService(serviceIntent);
+ for(ComponentName compName: runningBluetoothServicePackage){
+ serviceIntent.setComponent(compName);
+ context.startService(serviceIntent);
+
+ }
return true;
}
return false;
}
}
-
+
/**
* Determines if an instance of the Router Service is currently running on the device.
* @param context A context to access Android system services through.
@@ -175,52 +173,89 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{
Log.e(TAG, "Can't look for router service, context supplied was null");
return false;
}
- Log.d(TAG, "Looking for Service: "+ SDL_ROUTER_SERVICE_CLASS_NAME);
- ActivityManager manager = (ActivityManager) context.getSystemService("activity");
+ ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+ if(runningBluetoothServicePackage==null){
+ runningBluetoothServicePackage = new Vector<ComponentName>();
+ }else{
+ runningBluetoothServicePackage.clear();
+ }
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
//We will check to see if it contains this name, should be pretty specific
//Log.d(TAG, "Found Service: "+ service.service.getClassName());
if ((service.service.getClassName()).toLowerCase(Locale.US).contains(SDL_ROUTER_SERVICE_CLASS_NAME)) {
- runningBluetoothServicePackage = service.service; //Store which instance is running
+
+ runningBluetoothServicePackage.add(service.service); //Store which instance is running
if(pingService){
Intent intent = new Intent();
intent.setClassName(service.service.getPackageName(), service.service.getClassName());
intent.putExtra(TransportConstants.PING_ROUTER_SERVICE_EXTRA, pingService);
context.startService(intent);
}
- return true;
}
}
- return false;
+ return runningBluetoothServicePackage.size() > 0;
}
/**
+ * This call will reach out to all SDL related router services to check if they're connected. If a the router service is connected, it will react by pinging all clients. This receiver will then
+ * receive that ping and if the router service is trusted, the onSdlEnabled method will be called.
+ * @param context
+ */
+ public static void queryForConnectedService(Context context){
+ //Leverage existing call. Include ping bit
+ requestTransportStatus(context,null,true);
+ }
+ /**
* If a Router Service is running, this method determines if that service is connected to a device over some form of transport.
- * @param context A context to access Android system services through.
- * @return True if a transport connection is established, false otherwise.
+ * @param context A context to access Android system services through. If null is passed, this will always return false
+ * @param callback Use this callback to find out if the router service is connected or not.
*/
- public static boolean isTransportConnected(Context context){
- Log.d(TAG, "Checking to see if router service is transport connected");
- if(isRouterServiceRunning(context,false)){ //So there is a service up, let's see if it's connected
- Context con;
- try {
- con = context.createPackageContext(runningBluetoothServicePackage.getPackageName(), 0);
- if(con==null ){
- Log.w(TAG, "Unable to check for service connection. Returning false. "+runningBluetoothServicePackage);
- return false; // =( well that sucks.
- }
- SharedPreferences pref = con.getSharedPreferences(
- con.getPackageName()+TRANSPORT_GLOBAL_PREFS , 4);
- boolean connected = pref.getBoolean(IS_TRANSPORT_CONNECTED, false);
- // Log.w(TAG, "Is Connected? Returning " + connected);
- return connected;
- } catch (NameNotFoundException e) {
- e.printStackTrace();
- return false;
+ public static void requestTransportStatus(Context context, final SdlRouterStatusProvider.ConnectedStatusCallback callback){
+ requestTransportStatus(context,callback,false);
+ }
+
+ private static void requestTransportStatus(Context context, final SdlRouterStatusProvider.ConnectedStatusCallback callback, final boolean triggerRouterServicePing){
+ if(context == null){
+ if(callback!=null){
+ callback.onConnectionStatusUpdate(false, null,context);
}
+ return;
+ }
+ if(isRouterServiceRunning(context,false) && !runningBluetoothServicePackage.isEmpty()){ //So there is a service up, let's see if it's connected
+ final ConcurrentLinkedQueue<ComponentName> list = new ConcurrentLinkedQueue<ComponentName>(runningBluetoothServicePackage);
+ if(runningBluetoothServicePackage.size()>0){ //TODO for testing do this for all cases
+ final SdlRouterStatusProvider.ConnectedStatusCallback sdlBrCallback = new SdlRouterStatusProvider.ConnectedStatusCallback() {
+
+ @Override
+ public void onConnectionStatusUpdate(boolean connected, ComponentName service,Context context) {
+ if(!connected && !list.isEmpty()){
+ SdlRouterStatusProvider provider = new SdlRouterStatusProvider(context,list.poll(), this);
+ if(triggerRouterServicePing){provider.setFlags(TransportConstants.ROUTER_STATUS_FLAG_TRIGGER_PING); }
+ provider.checkIsConnected();
+ }else{
+ Log.d(TAG, service.getPackageName() + " is connected = " + connected);
+ if(callback!=null){
+ callback.onConnectionStatusUpdate(connected, service,context);
+ }
+ list.clear();
+ }
+ }
+ };
+ SdlRouterStatusProvider provider = new SdlRouterStatusProvider(context,list.poll(),sdlBrCallback);
+ if(triggerRouterServicePing){
+ provider.setFlags(TransportConstants.ROUTER_STATUS_FLAG_TRIGGER_PING);
+ }
+ provider.checkIsConnected();
+ }else{ //If only one service is running, just check that
+ SdlRouterStatusProvider provider = new SdlRouterStatusProvider(context,runningBluetoothServicePackage.get(0),callback);
+ if(triggerRouterServicePing){
+ provider.setFlags(TransportConstants.ROUTER_STATUS_FLAG_TRIGGER_PING);
+ }
+ provider.checkIsConnected();
+ }
}else{
Log.w(TAG, "Router service isn't running, returning false.");
if(BluetoothAdapter.getDefaultAdapter()!=null && BluetoothAdapter.getDefaultAdapter().isEnabled()){
@@ -229,10 +264,12 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{
serviceIntent.putExtra(TransportConstants.PING_ROUTER_SERVICE_EXTRA, true);
context.sendBroadcast(serviceIntent);
}
+ if(callback!=null){
+ callback.onConnectionStatusUpdate(false, null,context);
+ }
}
-
- return false;
}
+
public static ComponentName consumeQueuedRouterService(){
@@ -244,13 +281,12 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{
}
/**
- * We need to define this for local copy of the Sdl Bluetooth Service class.
- * It will be the main point of connection for Sdl Connected apps
+ * We need to define this for local copy of the Sdl Router Service class.
+ * It will be the main point of connection for Sdl enabled apps
* @return Return the local copy of SdlRouterService.class
* {@inheritDoc}
*/
- @SuppressWarnings("rawtypes")
- public abstract Class defineLocalSdlRouterClass();
+ public abstract Class<? extends SdlRouterService> defineLocalSdlRouterClass();
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/SdlPsm.java b/sdl_android_lib/src/com/smartdevicelink/transport/SdlPsm.java
index b04b4453b..d6a9840ae 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/SdlPsm.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/SdlPsm.java
@@ -195,14 +195,17 @@ public class SdlPsm{
if(dataLength==0){
return FINISHED_STATE; //We are done if we don't have any payload
}
- payload = new byte[dataLength];
+ try{
+ payload = new byte[dataLength];
+ }catch(OutOfMemoryError oom){
+ return ERROR_STATE;
+ }
dumpSize = dataLength;
return DATA_PUMP_STATE;
case DATA_PUMP_STATE:
payload[dataLength-dumpSize] = rawByte;
dumpSize--;
- //Log.trace(TAG,rawByte + " read. Data Length remaining: " + dumpSize);
//Do we have any more bytes to read in?
if(dumpSize>0){
return DATA_PUMP_STATE;
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/SdlRouterService.java b/sdl_android_lib/src/com/smartdevicelink/transport/SdlRouterService.java
index 1bb7f3d72..c6c511dc4 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/SdlRouterService.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/SdlRouterService.java
@@ -5,6 +5,7 @@ import static com.smartdevicelink.transport.TransportConstants.FORMED_PACKET_EXT
import static com.smartdevicelink.transport.TransportConstants.HARDWARE_DISCONNECTED;
import static com.smartdevicelink.transport.TransportConstants.SEND_PACKET_TO_APP_LOCATION_EXTRA_NAME;
+import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
@@ -20,6 +21,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import android.annotation.SuppressLint;
+import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.Notification;
@@ -40,6 +42,7 @@ import android.os.DeadObjectException;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder.DeathRecipient;
+import android.os.Build;
import android.os.Message;
import android.os.Messenger;
import android.os.Parcel;
@@ -102,7 +105,8 @@ public class SdlRouterService extends Service{
private static boolean connectAsClient = false;
private static boolean closing = false;
- private boolean isTarnsportConnected = false;
+ private boolean isTransportConnected = false;
+ private TransportType connectedTransportType = null;
private static Context currentContext = null;
private Handler versionCheckTimeOutHandler, altTransportTimerHandler;
@@ -290,16 +294,23 @@ public class SdlRouterService extends Service{
/**
* Target we publish for clients to send messages to RouterHandler.
*/
- final Messenger routerMessenger = new Messenger(new RouterHandler());
+ final Messenger routerMessenger = new Messenger(new RouterHandler(this));
/**
* Handler of incoming messages from clients.
*/
- class RouterHandler extends Handler {
+ static class RouterHandler extends Handler {
+ WeakReference<SdlRouterService> provider;
+
+ public RouterHandler(SdlRouterService provider){
+ this.provider = new WeakReference<SdlRouterService>(provider);
+ }
+
@Override
public void handleMessage(Message msg) {
final Bundle receivedBundle = msg.getData();
Bundle returnBundle;
+ final SdlRouterService service = this.provider.get();
switch (msg.what) {
case TransportConstants.ROUTER_REQUEST_BT_CLIENT_CONNECT:
@@ -308,19 +319,20 @@ public class SdlRouterService extends Service{
//Log.d(TAG,"Attempting to connect as bt client");
BluetoothDevice device = receivedBundle.getParcelable(BluetoothDevice.EXTRA_DEVICE);
connectAsClient = true;
- if(device==null || !bluetoothConnect(device)){
+ if(device==null || !service.bluetoothConnect(device)){
Log.e(TAG, "Unable to connect to bluetooth device");
connectAsClient = false;
}
}
//**************** We don't break here so we can let the app register as well
case TransportConstants.ROUTER_REGISTER_CLIENT: //msg.arg1 is appId
- pingClients();
+ //pingClients();
Message message = Message.obtain();
message.what = TransportConstants.ROUTER_REGISTER_CLIENT_RESPONSE;
+ message.arg1 = TransportConstants.REGISTRATION_RESPONSE_SUCESS;
long appId = receivedBundle.getLong(TransportConstants.APP_ID_EXTRA, -1);
if(appId<0 || msg.replyTo == null){
- Log.w(TAG, "Unable to requster app as no id or messenger was included");
+ Log.w(TAG, "Unable to register app as no id or messenger was included");
if(msg.replyTo!=null){
message.arg1 = TransportConstants.REGISTRATION_RESPONSE_DENIED_APP_ID_NOT_INCLUDED;
try {
@@ -331,7 +343,7 @@ public class SdlRouterService extends Service{
}
break;
}
- if(SdlRouterService.this.legacyModeEnabled){
+ if(service.legacyModeEnabled){
Log.w(TAG, "Unable to register app as legacy mode is enabled");
if(msg.replyTo!=null){
message.arg1 = TransportConstants.REGISTRATION_RESPONSE_DENIED_LEGACY_MODE_ENABLED;
@@ -344,48 +356,52 @@ public class SdlRouterService extends Service{
break;
}
- RegisteredApp app = new RegisteredApp(appId,msg.replyTo);
- synchronized(REGISTERED_APPS_LOCK){
+ RegisteredApp app = service.new RegisteredApp(appId,msg.replyTo);
+ synchronized(service.REGISTERED_APPS_LOCK){
RegisteredApp old = registeredApps.put(app.getAppId(), app);
if(old!=null){
Log.w(TAG, "Replacing already existing app with this app id");
- removeAllSessionsForApp(old, true);
+ service.removeAllSessionsForApp(old, true);
old.close();
}
}
- onAppRegistered(app);
-
+ service.onAppRegistered(app);
+
returnBundle = new Bundle();
-
- if(MultiplexBluetoothTransport.currentlyConnectedDevice!=null){
- returnBundle.putString(CONNECTED_DEVICE_STRING_EXTRA_NAME, MultiplexBluetoothTransport.currentlyConnectedDevice);
- }
- if(!returnBundle.isEmpty()){
- message.setData(returnBundle);
+ //Add params if connected
+ if(service.isTransportConnected){
+ returnBundle.putString(TransportConstants.HARDWARE_CONNECTED, service.connectedTransportType.name());
+ if(MultiplexBluetoothTransport.currentlyConnectedDevice!=null){
+ returnBundle.putString(CONNECTED_DEVICE_STRING_EXTRA_NAME, MultiplexBluetoothTransport.currentlyConnectedDevice);
+ }
}
+ //Add the version of this router service
+ returnBundle.putInt(TransportConstants.ROUTER_SERVICE_VERSION, SdlRouterService.ROUTER_SERVICE_VERSION_NUMBER);
+
+ message.setData(returnBundle);
+
int result = app.sendMessage(message);
if(result == RegisteredApp.SEND_MESSAGE_ERROR_MESSENGER_DEAD_OBJECT){
- synchronized(REGISTERED_APPS_LOCK){
+ synchronized(service.REGISTERED_APPS_LOCK){
registeredApps.remove(appId);
}
}
-
break;
case TransportConstants.ROUTER_UNREGISTER_CLIENT:
long appIdToUnregister = receivedBundle.getLong(TransportConstants.APP_ID_EXTRA, -1);
Log.i(TAG, "Unregistering client: " + appIdToUnregister);
RegisteredApp unregisteredApp = null;
- synchronized(REGISTERED_APPS_LOCK){
+ synchronized(service.REGISTERED_APPS_LOCK){
unregisteredApp = registeredApps.remove(appIdToUnregister);
}
Message response = Message.obtain();
response.what = TransportConstants.ROUTER_UNREGISTER_CLIENT_RESPONSE;
if(unregisteredApp == null){
response.arg1 = TransportConstants.UNREGISTRATION_RESPONSE_FAILED_APP_ID_NOT_FOUND;
- removeAllSessionsWithAppId(appIdToUnregister);
+ service.removeAllSessionsWithAppId(appIdToUnregister);
}else{
response.arg1 = TransportConstants.UNREGISTRATION_RESPONSE_SUCESS;
- removeAllSessionsForApp(unregisteredApp,false);
+ service.removeAllSessionsForApp(unregisteredApp,false);
}
Log.i(TAG, "Unregistering client response: " + response.arg1 );
try {
@@ -409,7 +425,7 @@ public class SdlRouterService extends Service{
Long buffAppId = receivedBundle.getLong(TransportConstants.APP_ID_EXTRA);
RegisteredApp buffApp = null;
if(buffAppId!=null){
- synchronized(REGISTERED_APPS_LOCK){
+ synchronized(service.REGISTERED_APPS_LOCK){
buffApp = registeredApps.get(buffAppId);
}
}
@@ -417,13 +433,13 @@ public class SdlRouterService extends Service{
if(buffApp !=null){
buffApp.handleIncommingClientMessage(receivedBundle);
}else{
- writeBytesToTransport(receivedBundle);
+ service.writeBytesToTransport(receivedBundle);
}
}
}
};
- if(packetExecuter!=null){
- packetExecuter.execute(packetRun);
+ if(service.packetExecuter!=null){
+ service.packetExecuter.execute(packetRun);
}
}
break;
@@ -432,7 +448,7 @@ public class SdlRouterService extends Service{
Message extraSessionResponse = Message.obtain();
extraSessionResponse.what = TransportConstants.ROUTER_REQUEST_NEW_SESSION_RESPONSE;
if(appIdRequesting>0){
- synchronized(REGISTERED_APPS_LOCK){
+ synchronized(service.REGISTERED_APPS_LOCK){
if(registeredApps!=null){
RegisteredApp appRequesting = registeredApps.get(appIdRequesting);
if(appRequesting!=null){
@@ -457,12 +473,12 @@ public class SdlRouterService extends Service{
case TransportConstants.ROUTER_REMOVE_SESSION:
long appIdWithSession = receivedBundle.getLong(TransportConstants.APP_ID_EXTRA, -1);
long sessionId = receivedBundle.getLong(TransportConstants.SESSION_ID_EXTRA, -1);
- removeSessionFromMap((int)sessionId);
+ service.removeSessionFromMap((int)sessionId);
Message removeSessionResponse = Message.obtain();
removeSessionResponse.what = TransportConstants.ROUTER_REMOVE_SESSION_RESPONSE;
if(appIdWithSession>0){
if(sessionId>=0){
- synchronized(REGISTERED_APPS_LOCK){
+ synchronized(service.REGISTERED_APPS_LOCK){
if(registeredApps!=null){
RegisteredApp appRequesting = registeredApps.get(appIdWithSession);
if(appRequesting!=null){
@@ -500,15 +516,23 @@ public class SdlRouterService extends Service{
/**
* Target we publish for alternative transport (USB) clients to send messages to RouterHandler.
*/
- final Messenger altTransportMessenger = new Messenger(new AltTransportHandler());
+ final Messenger altTransportMessenger = new Messenger(new AltTransportHandler(this));
/**
* Handler of incoming messages from an alternative transport (USB).
*/
- class AltTransportHandler extends Handler {
- ClassLoader loader = getClass().getClassLoader();
+ static class AltTransportHandler extends Handler {
+ ClassLoader loader;
+ WeakReference<SdlRouterService> provider;
+
+ public AltTransportHandler(SdlRouterService provider){
+ this.provider = new WeakReference<SdlRouterService>(provider);
+ loader = getClass().getClassLoader();
+ }
+
@Override
public void handleMessage(Message msg) {
+ SdlRouterService service = this.provider.get();
Bundle receivedBundle = msg.getData();
switch(msg.what){
case TransportConstants.HARDWARE_CONNECTION_EVENT:
@@ -518,9 +542,8 @@ public class SdlRouterService extends Service{
&& altTransportService.equals(msg.replyTo)){
//The same transport that was connected to the router service is now telling us it's disconnected. Let's inform clients and clear our saved messenger
altTransportService = null;
- storeConnectedStatus(false);
- onTransportDisconnected(TransportType.valueOf(receivedBundle.getString(TransportConstants.HARDWARE_DISCONNECTED)));
- shouldServiceRemainOpen(null); //this will close the service if bluetooth is not available
+ service.onTransportDisconnected(TransportType.valueOf(receivedBundle.getString(TransportConstants.HARDWARE_DISCONNECTED)));
+ service.shouldServiceRemainOpen(null); //this will close the service if bluetooth is not available
}
}else if(receivedBundle.containsKey(TransportConstants.HARDWARE_CONNECTED)){
Message retMsg = Message.obtain();
@@ -532,16 +555,15 @@ public class SdlRouterService extends Service{
}
altTransportService = msg.replyTo;
//Clear out the timer to make sure the service knows we're good to go
- if(altTransportTimerHandler!=null && altTransportTimerRunnable!=null){
- altTransportTimerHandler.removeCallbacks(altTransportTimerRunnable);
+ if(service.altTransportTimerHandler!=null && service.altTransportTimerRunnable!=null){
+ service.altTransportTimerHandler.removeCallbacks(service.altTransportTimerRunnable);
}
- altTransportTimerHandler = null;
- altTransportTimerRunnable = null;
+ service.altTransportTimerHandler = null;
+ service.altTransportTimerRunnable = null;
- storeConnectedStatus(true);
//Let the alt transport know they are good to go
retMsg.arg1 = TransportConstants.ROUTER_REGISTER_ALT_TRANSPORT_RESPONSE_SUCESS;
- onTransportConnected(TransportType.valueOf(receivedBundle.getString(TransportConstants.HARDWARE_CONNECTED)));
+ service.onTransportConnected(TransportType.valueOf(receivedBundle.getString(TransportConstants.HARDWARE_CONNECTED)));
}else{ //There seems to be some other transport connected
//Error
retMsg.arg1 = TransportConstants.ROUTER_REGISTER_ALT_TRANSPORT_ALREADY_CONNECTED;
@@ -560,7 +582,7 @@ public class SdlRouterService extends Service{
if(receivedBundle.containsKey(TransportConstants.FORMED_PACKET_EXTRA_NAME)){
SdlPacket packet = receivedBundle.getParcelable(TransportConstants.FORMED_PACKET_EXTRA_NAME);
if(packet!=null){
- onPacketRead(packet);
+ service.onPacketRead(packet);
}else{
Log.w(TAG, "Received null packet from alt transport service");
}
@@ -574,6 +596,51 @@ public class SdlRouterService extends Service{
}
};
+
+ /**
+ * Target we publish for alternative transport (USB) clients to send messages to RouterHandler.
+ */
+ final Messenger routerStatusMessenger = new Messenger(new RouterStatusHandler(this));
+
+ /**
+ * Handler of incoming messages from an alternative transport (USB).
+ */
+ static class RouterStatusHandler extends Handler {
+ WeakReference<SdlRouterService> provider;
+
+ public RouterStatusHandler(SdlRouterService provider){
+ this.provider = new WeakReference<SdlRouterService>(provider);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ SdlRouterService service = this.provider.get();
+ switch(msg.what){
+ case TransportConstants.ROUTER_STATUS_CONNECTED_STATE_REQUEST:
+ int flags = msg.arg1;
+ if(msg.replyTo!=null){
+ Message message = Message.obtain();
+ message.what = TransportConstants.ROUTER_STATUS_CONNECTED_STATE_RESPONSE;
+ message.arg1 = (service.isTransportConnected == true) ? 1 : 0;
+ try {
+ msg.replyTo.send(message);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+ if(service.isTransportConnected && ((TransportConstants.ROUTER_STATUS_FLAG_TRIGGER_PING & flags) == TransportConstants.ROUTER_STATUS_FLAG_TRIGGER_PING)){
+ if(service.pingIntent == null){
+ service.initPingIntent();
+ }
+ service.getBaseContext().sendBroadcast(service.pingIntent);
+ }
+ break;
+ default:
+ Log.w(TAG, "Unsopported request: " + msg.what);
+ break;
+ }
+ }
+ };
/* **************************************************************************************************************************************
*********************************************** Life Cycle **************************************************************
@@ -589,9 +656,13 @@ public class SdlRouterService extends Service{
}
String requestType = intent.getAction();//intent.getIntExtra(TransportConstants.ROUTER_BIND_REQUEST_TYPE_EXTRA, TransportConstants.BIND_REQUEST_TYPE_CLIENT);
if(TransportConstants.BIND_REQUEST_TYPE_ALT_TRANSPORT.equals(requestType)){
- return this.altTransportMessenger.getBinder();
+ if(0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)){ //Only allow alt transport in debug mode
+ return this.altTransportMessenger.getBinder();
+ }
}else if(TransportConstants.BIND_REQUEST_TYPE_CLIENT.equals(requestType)){
return this.routerMessenger.getBinder();
+ }else if(TransportConstants.BIND_REQUEST_TYPE_STATUS.equals(requestType)){
+ return this.routerStatusMessenger.getBinder();
}else{
Log.w(TAG, "Uknown bind request type");
}
@@ -689,7 +760,6 @@ public class SdlRouterService extends Service{
}
closing = false;
currentContext = getBaseContext();
- storeConnectedStatus(false);
startVersionCheck();
Log.i(TAG, "SDL Router Service has been created");
@@ -708,14 +778,11 @@ public class SdlRouterService extends Service{
}
public void startUpSequence(){
- IntentFilter stateChangeFilter = new IntentFilter("android.bluetooth.adapter.action.STATE_CHANGED");
- stateChangeFilter.addAction("android.bluetooth.device.action.CLASS_CHANGED");
- IntentFilter disconnectFilter1 = new IntentFilter("android.bluetooth.device.action.ACL_DISCONNECTED");
- IntentFilter disconnectFilter2 = new IntentFilter("android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED");
-
- registerReceiver(mListenForDisconnect,stateChangeFilter );
- registerReceiver(mListenForDisconnect,disconnectFilter1 );
- registerReceiver(mListenForDisconnect,disconnectFilter2 );
+ IntentFilter disconnectFilter = new IntentFilter("android.bluetooth.adapter.action.STATE_CHANGED");
+ disconnectFilter.addAction("android.bluetooth.device.action.CLASS_CHANGED");
+ disconnectFilter.addAction("android.bluetooth.device.action.ACL_DISCONNECTED");
+ disconnectFilter.addAction("android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED");
+ registerReceiver(mListenForDisconnect,disconnectFilter );
IntentFilter filter = new IntentFilter();
filter.addAction(REGISTER_WITH_ROUTER_ACTION);
@@ -945,7 +1012,6 @@ public class SdlRouterService extends Service{
*/
public void closeSelf(){
closing = true;
- storeConnectedStatus(false);
if(getBaseContext()!=null){
stopSelf();
}else{
@@ -957,13 +1023,11 @@ public class SdlRouterService extends Service{
Log.d(TAG, "Not starting own bluetooth during legacy mode");
return;
}
- Log.i(TAG, "Iniitializing Bluetooth Serial Class");
+ Log.i(TAG, "Iniitializing bluetooth transport");
//init serial service
if(mSerialService ==null){
- Log.d(TAG, "Local copy of BT Server is null");
mSerialService = MultiplexBluetoothTransport.getBluetoothSerialServerInstance();
if(mSerialService==null){
- Log.d(TAG, "Local copy of BT Server is still null and so is global");
mSerialService = MultiplexBluetoothTransport.getBluetoothSerialServerInstance(mHandlerBT);
}
}
@@ -978,7 +1042,7 @@ public class SdlRouterService extends Service{
}
public void onTransportConnected(final TransportType type){
- isTarnsportConnected = true;
+ isTransportConnected = true;
enterForeground();
if(packetWriteTaskMaster!=null){
packetWriteTaskMaster.close();
@@ -987,6 +1051,8 @@ public class SdlRouterService extends Service{
packetWriteTaskMaster = new PacketWriteTaskMaster();
packetWriteTaskMaster.start();
+ connectedTransportType = type;
+
Intent startService = new Intent();
startService.setAction(START_SERVICE_ACTION);
startService.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_EXTRA, true);
@@ -995,6 +1061,23 @@ public class SdlRouterService extends Service{
startService.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_CMP_NAME, new ComponentName(this, this.getClass()));
sendBroadcast(startService);
//HARDWARE_CONNECTED
+ if(!(registeredApps== null || registeredApps.isEmpty())){
+ //If we have clients
+ notifyClients(createHardwareConnectedMessage(type));
+ }
+ }
+
+ private Message createHardwareConnectedMessage(final TransportType type){
+ Message message = Message.obtain();
+ message.what = TransportConstants.HARDWARE_CONNECTION_EVENT;
+ Bundle bundle = new Bundle();
+ bundle.putString(TransportConstants.HARDWARE_CONNECTED, type.name());
+ if(MultiplexBluetoothTransport.currentlyConnectedDevice!=null){
+ bundle.putString(CONNECTED_DEVICE_STRING_EXTRA_NAME, MultiplexBluetoothTransport.currentlyConnectedDevice);
+ }
+ message.setData(bundle);
+ return message;
+
}
public void onTransportDisconnected(TransportType type){
@@ -1002,8 +1085,8 @@ public class SdlRouterService extends Service{
return;
}
Log.e(TAG, "Notifying client service of hardware disconnect.");
-
- isTarnsportConnected = false;
+ connectedTransportType = null;
+ isTransportConnected = false;
stopClientPings();
exitForeground();//Leave our foreground state as we don't have a connection anymore
@@ -1015,7 +1098,6 @@ public class SdlRouterService extends Service{
cachedModuleVersion = -1; //Reset our cached version
if(registeredApps== null || registeredApps.isEmpty()){
- Log.w(TAG, "No clients to notify. Sending global notification.");
Intent unregisterIntent = new Intent();
unregisterIntent.putExtra(HARDWARE_DISCONNECTED, type.name());
unregisterIntent.putExtra(TransportConstants.ENABLE_LEGACY_MODE_EXTRA, legacyModeEnabled);
@@ -1074,20 +1156,17 @@ public class SdlRouterService extends Service{
case MESSAGE_STATE_CHANGE:
switch (msg.arg1) {
case MultiplexBluetoothTransport.STATE_CONNECTED:
- storeConnectedStatus(true);
onTransportConnected(TransportType.BLUETOOTH);
break;
case MultiplexBluetoothTransport.STATE_CONNECTING:
// Currently attempting to connect - update UI?
break;
case MultiplexBluetoothTransport.STATE_LISTEN:
- storeConnectedStatus(false);
break;
case MultiplexBluetoothTransport.STATE_NONE:
// We've just lost the connection
- storeConnectedStatus(false);
- if(!connectAsClient && !closing){
- if(!legacyModeEnabled){
+ if(!connectAsClient ){
+ if(!legacyModeEnabled && !closing){
initBluetoothSerialService();
}
onTransportDisconnected(TransportType.BLUETOOTH);
@@ -1120,7 +1199,7 @@ public class SdlRouterService extends Service{
int offset = bundle.getInt(TransportConstants.BYTES_TO_SEND_EXTRA_OFFSET, 0); //If nothing, start at the begining of the array
int count = bundle.getInt(TransportConstants.BYTES_TO_SEND_EXTRA_COUNT, packet.length); //In case there isn't anything just send the whole packet.
if(packet!=null){
- mSerialService.write(packet,offset,count); Log.i(TAG, "Wrote out bytes");
+ mSerialService.write(packet,offset,count);
return true;
}
return false;
@@ -1136,7 +1215,7 @@ public class SdlRouterService extends Service{
private boolean manuallyWriteBytes(byte[] bytes, int offset, int count){
if(mSerialService !=null && mSerialService.getState()==MultiplexBluetoothTransport.STATE_CONNECTED){
if(bytes!=null){
- mSerialService.write(bytes,offset,count);Log.i(TAG, "Wrote out bytes manually");
+ mSerialService.write(bytes,offset,count);
return true;
}
return false;
@@ -1156,7 +1235,6 @@ public class SdlRouterService extends Service{
*/
private boolean sendThroughAltTransport(Bundle bundle){
if(altTransportService!=null){
- Log.d(TAG, "Sending packet through alt transport");
Message msg = Message.obtain();
msg.what = TransportConstants.ROUTER_SEND_PACKET;
msg.setData(bundle);
@@ -1180,7 +1258,6 @@ public class SdlRouterService extends Service{
*/
private boolean sendThroughAltTransport(byte[] bytes, int offset, int count){
if(altTransportService!=null){
- Log.d(TAG, "Sending packet through alt transport");
Message msg = Message.obtain();
msg.what = TransportConstants.ROUTER_SEND_PACKET;
Bundle bundle = new Bundle();
@@ -1258,7 +1335,7 @@ public class SdlRouterService extends Service{
//Log.w(TAG, "Packet too big for IPC buffer. Breaking apart and then sending to client.");
//We need to churn through the packet payload and send it in chunks
byte[] bytes = packet.getPayload();
- SdlPacket copyPacket = new SdlPacket(packet.getVersion(),packet.isCompression(),
+ SdlPacket copyPacket = new SdlPacket(packet.getVersion(),packet.isEncrypted(),
(int)packet.getFrameType().getValue(),
packet.getServiceType(),packet.getFrameInfo(), session,
(int)packet.getDataSize(),packet.getMessageId(),null);
@@ -1266,7 +1343,7 @@ public class SdlRouterService extends Service{
bundle.putParcelable(FORMED_PACKET_EXTRA_NAME, copyPacket);
bundle.putInt(TransportConstants.BYTES_TO_SEND_FLAGS, TransportConstants.BYTES_TO_SEND_FLAG_SDL_PACKET_INCLUDED);
message.setData(bundle);
- Log.d(TAG, "First packet before sending: " + message.getData().toString());
+ //Log.d(TAG, "First packet before sending: " + message.getData().toString());
if(!sendPacketMessageToClient(app, message, version)){
Log.w(TAG, "Error sending first message of split packet to client " + app.appId);
return false;
@@ -1280,7 +1357,7 @@ public class SdlRouterService extends Service{
return false;
}
}
- Log.i(TAG, "Large packet finished being sent");
+ //Log.i(TAG, "Large packet finished being sent");
}
}else{ //If we can't find a session for this packet we just drop the packet
@@ -1423,17 +1500,6 @@ public class SdlRouterService extends Service{
//**************************************************************************************************************************************
//********************************************************* PREFERENCES ****************************************************************
//**************************************************************************************************************************************
-
- @SuppressLint("WorldReadableFiles")
- @SuppressWarnings("deprecation")
- private void storeConnectedStatus(boolean isConnected){
- SharedPreferences prefs = getApplicationContext().getSharedPreferences(getApplicationContext().getPackageName()+SdlBroadcastReceiver.TRANSPORT_GLOBAL_PREFS,
- Context.MODE_WORLD_READABLE);
- SharedPreferences.Editor editor = prefs.edit();
- editor.putBoolean(SdlBroadcastReceiver.IS_TRANSPORT_CONNECTED, isConnected);
- editor.commit();
- }
-
/**
* This method will set the last known bluetooth connection method that worked with this phone.
* This helps speed up the process of connecting
@@ -1506,8 +1572,8 @@ public class SdlRouterService extends Service{
LocalRouterService newestServiceReceived = getLocalBluetoothServiceComapre();
LocalRouterService self = getLocalRouterService(); //We can send in null here, because it should have already been created
- Log.v(TAG, "Self service info " + self);
- Log.v(TAG, "Newest compare to service info " + newestServiceReceived);
+ //Log.v(TAG, "Self service info " + self);
+ //Log.v(TAG, "Newest compare to service info " + newestServiceReceived);
if(newestServiceReceived!=null && self.isNewer(newestServiceReceived)){
Log.d(TAG, "There is a newer version of the Router Service, starting it up");
closing = true;
@@ -1573,14 +1639,15 @@ public class SdlRouterService extends Service{
}
}
+ @TargetApi(Build.VERSION_CODES.HONEYCOMB)
private boolean removeAllSessionsWithAppId(long appId){
synchronized(SESSION_LOCK){
if(sessionMap!=null){
SparseArray<Long> iter = sessionMap.clone();
int size = iter.size();
for(int i = 0; i<size; i++){
- Log.d(TAG, "Investigating session " +iter.keyAt(i));
- Log.d(TAG, "App id is: " + iter.valueAt(i));
+ //Log.d(TAG, "Investigating session " +iter.keyAt(i));
+ //Log.d(TAG, "App id is: " + iter.valueAt(i));
if(((Long)iter.valueAt(i)).compareTo(appId) == 0){
sessionHashIdMap.remove(iter.keyAt(i));
sessionMap.removeAt(i);
@@ -1599,8 +1666,8 @@ public class SdlRouterService extends Service{
Vector<Long> sessions = app.getSessionIds();
int size = sessions.size(), sessionId;
for(int i=0; i<size;i++){
- Log.d(TAG, "Investigating session " +sessions.get(i).intValue());
- Log.d(TAG, "App id is: " + sessionMap.get(sessions.get(i).intValue()));
+ //Log.d(TAG, "Investigating session " +sessions.get(i).intValue());
+ //Log.d(TAG, "App id is: " + sessionMap.get(sessions.get(i).intValue()));
sessionId = sessions.get(i).intValue();
removeSessionFromMap(sessionId);
if(cleanModule){
@@ -1642,7 +1709,7 @@ public class SdlRouterService extends Service{
}
}
}
- Log.d(TAG, sessionId + " session returning App Id: " + appId);
+ //Log.d(TAG, sessionId + " session returning App Id: " + appId);
return appId;
}
}
@@ -1751,7 +1818,7 @@ public class SdlRouterService extends Service{
peekTask = app.peekNextTask();
if(peekTask!=null){
peekWeight = peekTask.getWeight(currentTime);
- Log.v(TAG, "App " + app.appId +" has a task with weight "+ peekWeight);
+ //Log.v(TAG, "App " + app.appId +" has a task with weight "+ peekWeight);
if(peekWeight>currentPriority){
if(app.queuePaused){
app.notIt();//Reset the timer
@@ -1772,9 +1839,18 @@ public class SdlRouterService extends Service{
return null;
}
+ private void initPingIntent(){
+ pingIntent = new Intent();
+ pingIntent.setAction(START_SERVICE_ACTION);
+ pingIntent.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_EXTRA, true);
+ pingIntent.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_APP_PACKAGE, getBaseContext().getPackageName());
+ pingIntent.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_CMP_NAME, new ComponentName(SdlRouterService.this, SdlRouterService.this.getClass()));
+ pingIntent.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_PING, true);
+ }
+
private void startClientPings(){
synchronized(this){
- if(!isTarnsportConnected){ //If we aren't connected, bail
+ if(!isTransportConnected){ //If we aren't connected, bail
return;
}
if(isPingingClients){
@@ -1801,12 +1877,7 @@ public class SdlRouterService extends Service{
return;
}
if(pingIntent == null){
- pingIntent = new Intent();
- pingIntent.setAction(START_SERVICE_ACTION);
- pingIntent.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_EXTRA, true);
- pingIntent.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_APP_PACKAGE, getBaseContext().getPackageName());
- pingIntent.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_CMP_NAME, new ComponentName(SdlRouterService.this, SdlRouterService.this.getClass()));
- pingIntent.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_PING, true);
+ initPingIntent();
}
getBaseContext().sendBroadcast(pingIntent);
synchronized(PING_COUNT_LOCK){
@@ -2041,7 +2112,7 @@ public class SdlRouterService extends Service{
public boolean handleIncommingClientMessage(final Bundle receivedBundle){
int flags = receivedBundle.getInt(TransportConstants.BYTES_TO_SEND_FLAGS, TransportConstants.BYTES_TO_SEND_FLAG_NONE);
- Log.d(TAG, "Flags received: " + flags);
+ //Log.d(TAG, "Flags received: " + flags);
if(flags!=TransportConstants.BYTES_TO_SEND_FLAG_NONE){
byte[] packet = receivedBundle.getByteArray(TransportConstants.BYTES_TO_SEND_EXTRA_NAME);
if(flags == TransportConstants.BYTES_TO_SEND_FLAG_LARGE_PACKET_START){
@@ -2158,12 +2229,18 @@ public class SdlRouterService extends Service{
if(messenger!=null){
if(deathNote == null){
deathNote = new DeathRecipient(){
+ final Object deathLock = new Object();
@Override
public void binderDied() {
- Log.w(TAG, "Binder died");
- removeAllSessionsForApp(RegisteredApp.this,true);
- removeAppFromMap(RegisteredApp.this);
- startClientPings();
+ synchronized(deathLock){
+ Log.w(TAG, "Binder died for app " + RegisteredApp.this.appId);
+ if(messenger!=null && messenger.getBinder()!=null){
+ messenger.getBinder().unlinkToDeath(this, 0);
+ }
+ removeAllSessionsForApp(RegisteredApp.this,true);
+ removeAppFromMap(RegisteredApp.this);
+ startClientPings();
+ }
}
};
}
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/SdlRouterStatusProvider.java b/sdl_android_lib/src/com/smartdevicelink/transport/SdlRouterStatusProvider.java
new file mode 100644
index 000000000..7daad4760
--- /dev/null
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/SdlRouterStatusProvider.java
@@ -0,0 +1,142 @@
+package com.smartdevicelink.transport;
+
+import java.lang.ref.WeakReference;
+
+import android.annotation.SuppressLint;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.Messenger;
+import android.os.RemoteException;
+import android.util.Log;
+
+public class SdlRouterStatusProvider {
+
+ private static final String TAG = "SdlRouterStateProvider";
+
+ private Context context = null;
+ private boolean isBound = false;
+ ConnectedStatusCallback cb = null;
+ Messenger routerServiceMessenger = null;
+ private ComponentName routerService = null;
+ private int flags = 0;
+
+ final Messenger clientMessenger;
+
+ private ServiceConnection routerConnection= new ServiceConnection() {
+
+ public void onServiceConnected(ComponentName className, IBinder service) {
+ Log.d(TAG, "Bound to service " + className.toString());
+ routerServiceMessenger = new Messenger(service);
+ isBound = true;
+ //So we just established our connection
+ //Register with router service
+ Message msg = Message.obtain();
+ msg.what = TransportConstants.ROUTER_STATUS_CONNECTED_STATE_REQUEST;
+ msg.arg1 = flags;
+ msg.replyTo = clientMessenger;
+ try {
+ routerServiceMessenger.send(msg);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ if(cb!=null){
+ cb.onConnectionStatusUpdate(false, routerService, context);
+ }
+ }
+ }
+
+ public void onServiceDisconnected(ComponentName className) {
+ Log.d(TAG, "UN-Bound from service " + className.getClassName());
+ routerServiceMessenger = null;
+ isBound = false;
+ }
+ };
+
+ public SdlRouterStatusProvider(Context context, ComponentName service, ConnectedStatusCallback callback){
+ if(context == null || service == null || callback == null){
+ throw new IllegalStateException("Supplied params are not correct. Context == null? "+ (context==null) + " ComponentName == null? " + (service == null) + " ConnectedStatusListener == null? " + callback);
+ }
+ this.context = context;
+ this.routerService = service;
+ this.cb = callback;
+ this.clientMessenger = new Messenger(new ClientHandler(this));
+
+ }
+ public void setFlags(int flags){
+ this.flags = flags;
+ }
+ public void checkIsConnected(){
+ if(!bindToService()){
+ //We are unable to bind to service
+ cb.onConnectionStatusUpdate(false, routerService, context);
+ unBindFromService();
+ }
+ }
+
+ public void cancel(){
+ if(isBound){
+ unBindFromService();
+ }
+ }
+
+ private boolean bindToService(){
+ if(isBound){
+ return true;
+ }
+ Intent bindingIntent = new Intent();
+ bindingIntent.setClassName(this.routerService.getPackageName(), this.routerService.getClassName());//This sets an explicit intent
+ //Quickly make sure it's just up and running
+ context.startService(bindingIntent);
+ bindingIntent.setAction( TransportConstants.BIND_REQUEST_TYPE_STATUS);
+ return context.bindService(bindingIntent, routerConnection, Context.BIND_AUTO_CREATE);
+ }
+
+ private void unBindFromService(){
+ try{
+ if(context!=null && routerConnection!=null){
+ context.unbindService(routerConnection);
+ }else{
+ Log.w(TAG, "Unable to unbind from router service, context was null");
+ }
+
+ }catch(IllegalArgumentException e){
+ //This is ok
+ }
+ }
+
+ private void handleRouterStatusConnectedResponse(int connectedStatus){
+ if(cb!=null){
+ cb.onConnectionStatusUpdate(connectedStatus == 1, routerService,context);
+ }
+ unBindFromService();
+ routerServiceMessenger =null;
+ }
+
+ static class ClientHandler extends Handler {
+ WeakReference<SdlRouterStatusProvider> provider;
+
+ public ClientHandler(SdlRouterStatusProvider provider){
+ this.provider = new WeakReference<SdlRouterStatusProvider>(provider);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case TransportConstants.ROUTER_STATUS_CONNECTED_STATE_RESPONSE:
+ provider.get().handleRouterStatusConnectedResponse(msg.arg1);
+ break;
+ default:
+ break;
+ }
+ }
+ };
+
+ public interface ConnectedStatusCallback{
+ public void onConnectionStatusUpdate(boolean connected, ComponentName service, Context context);
+ }
+
+}
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/TransportBroker.java b/sdl_android_lib/src/com/smartdevicelink/transport/TransportBroker.java
index 613c857d9..aa5f35c3f 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/TransportBroker.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/TransportBroker.java
@@ -1,5 +1,6 @@
package com.smartdevicelink.transport;
+import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
@@ -40,7 +41,7 @@ public class TransportBroker {
private TransportType queuedOnTransportConnect = null;
Messenger routerServiceMessenger = null;
- final Messenger clientMessenger = new Messenger(new ClientHandler());
+ final Messenger clientMessenger;
boolean isBound = false, registeredWithRouterService = false;
private String routerPackage = null, routerClassName = null;
@@ -65,7 +66,7 @@ public class TransportBroker {
}
public void onServiceDisconnected(ComponentName className) {
- Log.d(TAG, "UN-Bound from service " + className.getClassName());
+ Log.d(TAG, "Unbound from service " + className.getClassName());
routerServiceMessenger = null;
registeredWithRouterService = false;
isBound = false;
@@ -125,12 +126,20 @@ public class TransportBroker {
/**
* Handler of incoming messages from service.
*/
- @SuppressLint("HandlerLeak")
- class ClientHandler extends Handler {
- ClassLoader loader = getClass().getClassLoader();
+ static class ClientHandler extends Handler {
+ ClassLoader loader;
+ WeakReference<TransportBroker> provider;
+
+ public ClientHandler(TransportBroker provider){
+ this.provider = new WeakReference<TransportBroker>(provider);
+ loader = getClass().getClassLoader();
+ }
@Override
public void handleMessage(Message msg) {
-
+ TransportBroker broker = provider.get();
+ if(broker == null){
+ Log.e(TAG, "Broker object null, unable to process message");
+ }
Bundle bundle = msg.getData();
if(bundle!=null){
@@ -143,8 +152,7 @@ public class TransportBroker {
if(bundle !=null
&& bundle.containsKey(TransportConstants.ENABLE_LEGACY_MODE_EXTRA)){
boolean enableLegacy = bundle.getBoolean(TransportConstants.ENABLE_LEGACY_MODE_EXTRA, false);
- Log.d(TAG, "Setting legacy mode: " +enableLegacy );
- enableLegacyMode(enableLegacy);
+ broker.enableLegacyMode(enableLegacy);
}
//Find out what message we have and what to do with it
@@ -153,27 +161,29 @@ public class TransportBroker {
switch(msg.arg1){
case TransportConstants.REGISTRATION_RESPONSE_SUCESS:
// yay! we have been registered. Now what?
- registeredWithRouterService = true;
- if(bundle!=null && bundle.containsKey(TransportConstants.CONNECTED_DEVICE_STRING_EXTRA_NAME)){
- //Keep track if we actually get this
- }
- if(queuedOnTransportConnect!=null){
- onHardwareConnected(queuedOnTransportConnect);
- queuedOnTransportConnect = null;
- }else if(SdlBroadcastReceiver.isTransportConnected(getContext())){
- onHardwareConnected(null); //FIXME to include type
- }
+ broker.registeredWithRouterService = true;
+ if(bundle !=null){
+ if(bundle.containsKey(TransportConstants.HARDWARE_CONNECTED)){
+ if(bundle.containsKey(TransportConstants.CONNECTED_DEVICE_STRING_EXTRA_NAME)){
+ //Keep track if we actually get this
+ }
+ broker.onHardwareConnected(TransportType.valueOf(bundle.getString(TransportConstants.HARDWARE_CONNECTED)));
+ }
+ /*if(bundle.containsKey(TransportConstants.ROUTER_SERVICE_VERSION)){
+ //Keep track if we actually get this
+ }*/
+ }
break;
case TransportConstants.REGISTRATION_RESPONSE_DENIED_LEGACY_MODE_ENABLED:
Log.d(TAG, "Denied registration because router is in legacy mode" );
- registeredWithRouterService = false;
- enableLegacyMode(true);
+ broker.registeredWithRouterService = false;
+ broker.enableLegacyMode(true);
//We call this so we can start the process of legacy connection
//onHardwareDisconnected(TransportType.BLUETOOTH);
- onLegacyModeEnabled();
+ broker.onLegacyModeEnabled();
break;
default:
- registeredWithRouterService = false;
+ broker.registeredWithRouterService = false;
Log.w(TAG, "Registration denied from router service. Reason - " + msg.arg1);
break;
};
@@ -199,38 +209,36 @@ public class TransportBroker {
Parcelable packet = bundle.getParcelable(TransportConstants.FORMED_PACKET_EXTRA_NAME);
if(flags == TransportConstants.BYTES_TO_SEND_FLAG_NONE){
- if(packet!=null){ Log.i(TAG, "received packet to process "+ packet.toString());
- onPacketReceived(packet);
+ if(packet!=null){ //Log.i(TAG, "received packet to process "+ packet.toString());
+ broker.onPacketReceived(packet);
}else{
Log.w(TAG, "Received null packet from router service, not passing along");
}
}else if(flags == TransportConstants.BYTES_TO_SEND_FLAG_SDL_PACKET_INCLUDED){
- Log.i(TAG, "Starting a buffered split packet");
- bufferedPacket = (SdlPacket) packet;
- if(bufferedPayloadAssembler !=null){
- bufferedPayloadAssembler.close();
- bufferedPayloadAssembler = null;
+ broker.bufferedPacket = (SdlPacket) packet;
+ if(broker.bufferedPayloadAssembler !=null){
+ broker.bufferedPayloadAssembler.close();
+ broker.bufferedPayloadAssembler = null;
}
- bufferedPayloadAssembler = new ByteAraryMessageAssembler();
- bufferedPayloadAssembler.init();
+ broker.bufferedPayloadAssembler = new ByteAraryMessageAssembler();
+ broker.bufferedPayloadAssembler.init();
}
}else if(bundle.containsKey(TransportConstants.BYTES_TO_SEND_EXTRA_NAME)){
//This should contain the payload
- if(bufferedPayloadAssembler!=null){
+ if(broker.bufferedPayloadAssembler!=null){
byte[] chunk = bundle.getByteArray(TransportConstants.BYTES_TO_SEND_EXTRA_NAME);
- if(!bufferedPayloadAssembler.handleMessage(flags, chunk)){
+ if(!broker.bufferedPayloadAssembler.handleMessage(flags, chunk)){
//If there was a problem
Log.e(TAG, "Error handling bytes for split packet");
}
- if(bufferedPayloadAssembler.isFinished()){
- bufferedPacket.setPayload(bufferedPayloadAssembler.getBytes());
+ if(broker.bufferedPayloadAssembler.isFinished()){
+ broker.bufferedPacket.setPayload(broker.bufferedPayloadAssembler.getBytes());
- bufferedPayloadAssembler.close();
- bufferedPayloadAssembler = null;
- Log.i(TAG, "Split packet finished from router service = " + bufferedPacket.toString());
- onPacketReceived(bufferedPacket);
- bufferedPacket = null;
+ broker.bufferedPayloadAssembler.close();
+ broker.bufferedPayloadAssembler = null;
+ broker.onPacketReceived(broker.bufferedPacket);
+ broker.bufferedPacket = null;
}
}
//}
@@ -244,15 +252,18 @@ public class TransportBroker {
//We should shut down, so call
Log.d(TAG, "Hardware disconnected");
if(isLegacyModeEnabled()){
- onLegacyModeEnabled();
+ broker.onLegacyModeEnabled();
}else{
- onHardwareDisconnected(TransportType.valueOf(bundle.getString(TransportConstants.HARDWARE_DISCONNECTED)));
+ broker.onHardwareDisconnected(TransportType.valueOf(bundle.getString(TransportConstants.HARDWARE_DISCONNECTED)));
}
break;
}
if(bundle.containsKey(TransportConstants.HARDWARE_CONNECTED)){
- onHardwareConnected(TransportType.valueOf(bundle.getString(TransportConstants.HARDWARE_CONNECTED)));
+ if(bundle!=null && bundle.containsKey(TransportConstants.CONNECTED_DEVICE_STRING_EXTRA_NAME)){
+ //Keep track if we actually get this
+ }
+ broker.onHardwareConnected(TransportType.valueOf(bundle.getString(TransportConstants.HARDWARE_CONNECTED)));
break;
}
break;
@@ -273,6 +284,7 @@ public class TransportBroker {
@SuppressLint("SimpleDateFormat")
public TransportBroker(Context context, String appId, ComponentName service){
synchronized(INIT_LOCK){
+ clientMessenger = new Messenger(new ClientHandler(this));
initRouterConnection();
//So the user should have set the AppId, lets define where the intents need to be sent
SimpleDateFormat s = new SimpleDateFormat("hhmmssss"); //So we have a time stamp of the event
@@ -296,7 +308,7 @@ public class TransportBroker {
* This beings the initial connection with the router service.
*/
public boolean start(){
- Log.d(TAG, "Starting up transport broker for " + whereToReply);
+ //Log.d(TAG, "Starting up transport broker for " + whereToReply);
synchronized(INIT_LOCK){
if(currentContext==null){
throw new IllegalStateException("This instance can't be started since it's local reference of context is null. Ensure when suppling a context to the TransportBroker that it is valid");
@@ -314,7 +326,6 @@ public class TransportBroker {
}
public void resetSession(){
- Log.d(TAG, "RESETING transport broker for " + whereToReply);
synchronized(INIT_LOCK){
unregisterWithRouterService();
routerServiceMessenger = null;
@@ -326,7 +337,7 @@ public class TransportBroker {
* This method will end our communication with the router service.
*/
public void stop(){
- Log.d(TAG, "STOPPING transport broker for " + whereToReply);
+ //Log.d(TAG, "STOPPING transport broker for " + whereToReply);
synchronized(INIT_LOCK){
unregisterWithRouterService();
unBindFromRouterService();
@@ -359,7 +370,7 @@ public class TransportBroker {
}
public void onHardwareDisconnected(TransportType type){
- synchronized(INIT_LOCK){Log.d(TAG, "onHardwareDisconnect");
+ synchronized(INIT_LOCK){
unBindFromRouterService();
routerServiceMessenger = null;
routerConnection = null;
@@ -392,12 +403,11 @@ public class TransportBroker {
* @return
*/
private boolean isRouterServiceRunning(Context context){
- Log.d(TAG,whereToReply + " checking if a bluetooth service is running");
if(context==null){
return false;
}
- ActivityManager manager = (ActivityManager) context.getSystemService("activity");
+ ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
//We will check to see if it contains this name, should be pretty specific
if ((service.service.getClassName()).toLowerCase(Locale.US).contains(SdlBroadcastReceiver.SDL_ROUTER_SERVICE_CLASS_NAME)) {
@@ -440,7 +450,7 @@ public class TransportBroker {
sendMessageToRouterService(message);
return true;
}else{ //Message is too big for IPC transaction
- Log.w(TAG, "Message too big for single IPC transaction. Breaking apart. Size - " + bytes.length);
+ //Log.w(TAG, "Message too big for single IPC transaction. Breaking apart. Size - " + bytes.length);
ByteArrayMessageSpliter splitter = new ByteArrayMessageSpliter(appId,TransportConstants.ROUTER_SEND_PACKET,bytes,packet.getPrioirtyCoefficient() );
while(splitter.isActive()){
sendMessageToRouterService(splitter.nextMessage());
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/TransportConstants.java b/sdl_android_lib/src/com/smartdevicelink/transport/TransportConstants.java
index 00b7e54b0..612b5775a 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/TransportConstants.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/TransportConstants.java
@@ -11,10 +11,6 @@ package com.smartdevicelink.transport;
public class TransportConstants {
public static final String START_ROUTER_SERVICE_ACTION ="sdl.router.startservice";
- public static final String UNREGISTER_WITH_ROUTER_ACTION = "com.sdl.android.unregister";
- public static final String SEND_PACKET_ACTION = "com.sdl.android.sendpacket";
- public static final String SEND__GLOBAL_PACKET_ACTION = "com.sdl.android.sendglobalpacket";
-
public static final String BIND_LOCATION_PACKAGE_NAME_EXTRA = "BIND_LOCATION_PACKAGE_NAME_EXTRA";
public static final String BIND_LOCATION_CLASS_NAME_EXTRA = "BIND_LOCATION_CLASS_NAME_EXTRA";
@@ -38,10 +34,6 @@ public class TransportConstants {
public static final String APP_ID_EXTRA = "app.id";
public static final String SESSION_ID_EXTRA = "session.id";
- public static final String LOG_BASIC_DEBUG_BOOLEAN_EXTRA = "basicDebugBool";
- public static final String LOG_TRACE_BT_DEBUG_BOOLEAN_EXTRA = "btTraceBool";
-
-
public static final String ENABLE_LEGACY_MODE_EXTRA = "ENABLE_LEGACY_MODE_EXTRA";
public static final String HARDWARE_DISCONNECTED = "hardware.disconect";
@@ -53,6 +45,7 @@ public class TransportConstants {
public static final String BIND_REQUEST_TYPE_CLIENT = "BIND_REQUEST_TYPE_CLIENT";
public static final String BIND_REQUEST_TYPE_ALT_TRANSPORT = "BIND_REQUEST_TYPE_ALT_TRANSPORT";
+ public static final String BIND_REQUEST_TYPE_STATUS = "BIND_REQUEST_TYPE_STATUS";
public static final String PING_ROUTER_SERVICE_EXTRA = "ping.router.service";
@@ -189,7 +182,20 @@ public class TransportConstants {
public static final int PACKET_SENDING_ERROR_NOT_CONNECTED = 0x01;
public static final int PACKET_SENDING_ERROR_UKNOWN = 0xFF;
+ public static final String ROUTER_SERVICE_VERSION = "router_service_version";
+
+ /**
+ * Status binder
+ */
+ public static final int ROUTER_STATUS_CONNECTED_STATE_REQUEST = 0x01;
+ public static final int ROUTER_STATUS_CONNECTED_STATE_RESPONSE = 0x02;
+ /**
+ * This flag when used to check router status will trigger the router service in sending out a ping that if it is connected to a device
+ */
+ public static final int ROUTER_STATUS_FLAG_TRIGGER_PING = 0x02;
+
+
diff --git a/sdl_android_lib/src/com/smartdevicelink/util/DebugTool.java b/sdl_android_lib/src/com/smartdevicelink/util/DebugTool.java
index 3b73b007c..716d96c59 100644
--- a/sdl_android_lib/src/com/smartdevicelink/util/DebugTool.java
+++ b/sdl_android_lib/src/com/smartdevicelink/util/DebugTool.java
@@ -1,10 +1,20 @@
package com.smartdevicelink.util;
+import java.util.Hashtable;
import java.util.Vector;
import android.util.Log;
import com.smartdevicelink.exception.SdlException;
+import com.smartdevicelink.marshal.JsonRPCMarshaller;
+import com.smartdevicelink.protocol.BinaryFrameHeader;
+import com.smartdevicelink.protocol.ProtocolMessage;
+import com.smartdevicelink.protocol.SdlPacket;
+import com.smartdevicelink.protocol.enums.FunctionID;
+import com.smartdevicelink.protocol.enums.MessageType;
+import com.smartdevicelink.protocol.enums.SessionType;
+import com.smartdevicelink.proxy.RPCMessage;
+import com.smartdevicelink.proxy.RPCStruct;
import com.smartdevicelink.proxy.Version;
import com.smartdevicelink.transport.SiphonServer;
@@ -267,4 +277,76 @@ public class DebugTool {
} // end-catch
}
}
+
+ /**
+ * Debug method to try to extract the RPC hash from the packet payload. Should only be used while debugging, not in production.
+ * Currently it will only handle single frame RPCs
+ * @param packet to inspect
+ * @return The Hashtable to be used to construct an RPC
+ */
+ public static Hashtable<String, Object> getRPCHash(SdlPacket packet){
+ if(packet == null ||
+ packet.getFrameType().getValue() != SdlPacket.FRAME_TYPE_SINGLE ||
+ packet.getServiceType()!=SdlPacket.SERVICE_TYPE_RPC){
+ Log.w("Debug", "Unable to get hash");
+ return null;
+ }
+ int version = packet.getVersion();
+
+ ProtocolMessage message = new ProtocolMessage();
+ 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
+ if (version > 1) {
+ BinaryFrameHeader binFrameHeader = BinaryFrameHeader.
+ parseBinaryHeader(packet.getPayload());
+ message.setVersion((byte) version);
+ 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.getPayload());
+ }
+ Hashtable<String, Object> hash = new Hashtable<String, Object>();
+ if (packet.getVersion() > 1) {
+ Hashtable<String, Object> hashTemp = new Hashtable<String, Object>();
+
+ hashTemp.put(RPCMessage.KEY_CORRELATION_ID, message.getCorrID());
+ if (message.getJsonSize() > 0) {
+ final Hashtable<String, Object> mhash = JsonRPCMarshaller.unmarshall(message.getData());
+ hashTemp.put(RPCMessage.KEY_PARAMETERS, mhash);
+ }
+
+ String functionName = FunctionID.getFunctionName(message.getFunctionID());
+ if (functionName != null) {
+ hashTemp.put(RPCMessage.KEY_FUNCTION_NAME, functionName);
+ } else {
+ return null;
+ }
+ if (message.getRPCType() == 0x00) {
+ hash.put(RPCMessage.KEY_REQUEST, hashTemp);
+ } else if (message.getRPCType() == 0x01) {
+ hash.put(RPCMessage.KEY_RESPONSE, hashTemp);
+ } else if (message.getRPCType() == 0x02) {
+ hash.put(RPCMessage.KEY_NOTIFICATION, hashTemp);
+ }
+ if (message.getBulkData() != null) hash.put(RPCStruct.KEY_BULK_DATA, message.getBulkData());
+ } else {
+ final Hashtable<String, Object> mhash = JsonRPCMarshaller.unmarshall(message.getData());
+ hash = mhash;
+ }
+ return hash;
+ }
}