From 336d983c05f9dd884d8f281a8c6eefaa1b3a7d59 Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Wed, 7 Dec 2016 13:23:59 -0500 Subject: [PATCH 1/8] Remove call to RSVP server during bluetooth state change --- .../transport/SdlBroadcastReceiver.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java b/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java index fa243c5855..3de3d5a673 100644 --- a/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java +++ b/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java @@ -22,7 +22,6 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{ private static final String BOOT_COMPLETE = "android.intent.action.BOOT_COMPLETED"; private static final String ACL_CONNECTED = "android.bluetooth.device.action.ACL_CONNECTED"; - private static final String STATE_CHANGED = "android.bluetooth.adapter.action.STATE_CHANGED" ; protected static final String SDL_ROUTER_SERVICE_CLASS_NAME = "sdlrouterservice"; @@ -58,7 +57,6 @@ public void onReceive(Context context, Intent intent) { if(!(action.equalsIgnoreCase(BOOT_COMPLETE) || action.equalsIgnoreCase(ACL_CONNECTED) - || action.equalsIgnoreCase(STATE_CHANGED) || action.equalsIgnoreCase(USBTransport.ACTION_USB_ACCESSORY_ATTACHED) || action.equalsIgnoreCase(TransportConstants.START_ROUTER_SERVICE_ACTION))){ //We don't want anything else here if the child class called super and has different intent filters @@ -120,20 +118,6 @@ public void onListObtained(boolean successful) { } - if (intent.getAction().contains("android.bluetooth.adapter.action.STATE_CHANGED")){ - int state = intent.getIntExtra("android.bluetooth.adapter.extra.STATE",-1); - if (state == BluetoothAdapter.STATE_OFF || - state == BluetoothAdapter.STATE_TURNING_OFF ){ - //onProtocolDisabled(context); - //Let's let the service that is running manage what to do for this - //If we were to do it here, for every instance of this BR it would send - //an intent to stop service, where it's only one that is needed. - return; - }else if(state == BluetoothAdapter.STATE_TURNING_ON){ - //We started bluetooth, we should check for a new valid router list - RouterServiceValidator.createTrustedListRequest(context,true); - } - } if(localRouterClass!=null){ //If there is a supplied router service lets run some logic regarding starting one From 6548e6a0445adfba855ac3c5b092cf6590c977be Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Wed, 7 Dec 2016 15:31:52 -0500 Subject: [PATCH 2/8] Change RSVP cache list timeout from 24 hours to a week --- .../com/smartdevicelink/transport/RouterServiceValidator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java b/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java index 5c70271802..36e04e9e8a 100644 --- a/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java +++ b/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java @@ -51,7 +51,7 @@ public class RouterServiceValidator { private static final String JSON_APP_VERSION_TAG = "version"; - private static final long REFRESH_TRUSTED_APP_LIST_TIME = 3600000 * 24; // 24 hours in ms + private static final long REFRESH_TRUSTED_APP_LIST_TIME = 3600000 * 24 * 7; // A week in ms private static final String SDL = "sdl"; private static final String SDL_PACKAGE_LIST = "sdl_package_list"; From 0f1136f8f0e9c38c94cfb85c31db81789d66697d Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Wed, 7 Dec 2016 15:46:01 -0500 Subject: [PATCH 3/8] No longer ignore an SDL enabled intent from untrusted router service. Include boolean if trusted or not --- .../transport/SdlBroadcastReceiver.java | 14 ++++++-------- .../transport/TransportConstants.java | 2 ++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java b/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java index 3de3d5a673..85352ec3f1 100644 --- a/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java +++ b/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java @@ -87,15 +87,13 @@ public void onReceive(Context context, Intent intent) { @Override public void onListObtained(boolean successful) { //Log.v(TAG, "SDL enabled by router service from " + packageName + " compnent package " + componentName.getPackageName() + " - " + componentName.getClassName()); + //List obtained. Let's start our service + queuedService = componentName; + finalIntent.setAction("com.sdl.noaction"); //Replace what's there so we do go into some unintended loop + //Validate the router service so the service knows if this is a trusted router service RouterServiceValidator vlad = new RouterServiceValidator(finalContext,componentName); - if(vlad.validate()){ - //Log.d(TAG, "Router service trusted!"); - queuedService = componentName; - finalIntent.setAction("com.sdl.noaction"); //Replace what's there so we do go into some unintended loop - onSdlEnabled(finalContext, finalIntent); - }else{ - Log.w(TAG, "RouterService was not trusted. Ignoring intent from : "+ componentName.getClassName()); - } + finalIntent.putExtra(TransportConstants.ROUTER_SERVICE_VALIDATED, vlad.validate()); + onSdlEnabled(finalContext, finalIntent); } }); diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/TransportConstants.java b/sdl_android_lib/src/com/smartdevicelink/transport/TransportConstants.java index 612b5775a4..3e3421af9c 100644 --- a/sdl_android_lib/src/com/smartdevicelink/transport/TransportConstants.java +++ b/sdl_android_lib/src/com/smartdevicelink/transport/TransportConstants.java @@ -27,6 +27,8 @@ public class TransportConstants { public static final String START_ROUTER_SERVICE_SDL_ENABLED_CMP_NAME = "component_name"; public static final String START_ROUTER_SERVICE_SDL_ENABLED_PING = "ping"; public static final String FORCE_TRANSPORT_CONNECTED = "force_connect"; //This is legacy, do not refactor this. + public static final String ROUTER_SERVICE_VALIDATED = "router_service_validated"; + public static final String REPLY_TO_INTENT_EXTRA = "ReplyAddress"; public static final String CONNECT_AS_CLIENT_BOOLEAN_EXTRA = "connectAsClient"; From b2a58e6c7bc6353a2e80a10638531eeebb170b50 Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Wed, 7 Dec 2016 16:50:10 -0500 Subject: [PATCH 4/8] Update default router list with extra OEM companion app and unit tests to reflect. --- .../com/smartdevicelink/transport/RouterServiceValidator.java | 2 +- sdl_android_tests/AndroidManifest.xml | 2 +- .../src/com/smartdevicelink/transport/RSVTestCase.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java b/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java index 36e04e9e8a..e2ac95a5f6 100644 --- a/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java +++ b/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java @@ -40,7 +40,7 @@ public class RouterServiceValidator { private static final String REQUEST_PREFIX = "https://woprjr.smartdevicelink.com/api/1/applications/queryTrustedRouters"; - private static final String DEFAULT_APP_LIST = "{\"response\": {\"com.livio.sdl\" : { \"versionBlacklist\":[] }, \"com.lexus.tcapp\" : { \"versionBlacklist\":[] }, \"com.toyota.tcapp\" : { \"versionBlacklist\": [] } , \"com.sdl.router\":{\"versionBlacklist\": [] } }}"; + private static final String DEFAULT_APP_LIST = "{\"response\": {\"com.livio.sdl\" : { \"versionBlacklist\":[] }, \"com.lexus.tcapp\" : { \"versionBlacklist\":[] }, \"com.toyota.tcapp\" : { \"versionBlacklist\": [] } , \"com.sdl.router\":{\"versionBlacklist\": [] },\"com.ford.fordpass\" : { \"versionBlacklist\":[] } }}"; private static final String JSON_RESPONSE_OBJECT_TAG = "response"; diff --git a/sdl_android_tests/AndroidManifest.xml b/sdl_android_tests/AndroidManifest.xml index 85ad00245b..87a9fc7c38 100644 --- a/sdl_android_tests/AndroidManifest.xml +++ b/sdl_android_tests/AndroidManifest.xml @@ -15,7 +15,7 @@ + android:targetPackage="com.smartdevicelink.test" /> Date: Wed, 7 Dec 2016 18:34:28 -0500 Subject: [PATCH 5/8] Added ability to save last reqest sent to RSVP server. If we are not facing a cached list timeout but our request info is different than what was cached, we will perform the request. --- .../transport/RouterServiceValidator.java | 58 +++++++++++++++---- .../transport/RSVTestCase.java | 38 ++++++++++++ 2 files changed, 85 insertions(+), 11 deletions(-) diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java b/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java index e2ac95a5f6..081fb01c87 100644 --- a/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java +++ b/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java @@ -1,6 +1,8 @@ package com.smartdevicelink.transport; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Locale; @@ -56,7 +58,9 @@ public class RouterServiceValidator { private static final String SDL = "sdl"; private static final String SDL_PACKAGE_LIST = "sdl_package_list"; private static final String SDL_PACKAGE_LIST_TIMESTAMP = "sdl_package_list_timestamp"; + private static final String SDL_LAST_REQUEST = "sdl_last_request"; + //Flags to aid in debugging and production checks public static final int FLAG_DEBUG_NONE = 0x00; public static final int FLAG_DEBUG_PACKAGE_CHECK = 0x01; @@ -320,6 +324,13 @@ private static List findAllSdlApps(Context context){ Intent intent = new Intent(); intent.setAction("sdl.router.startservice"); List infoList = packageManager.queryBroadcastReceivers(intent, 0); + //We want to sort our list so that we know it's the same everytime + Collections.sort(infoList,new Comparator() { + @Override + public int compare(ResolveInfo lhs, ResolveInfo rhs) { + return lhs.activityInfo.packageName.compareTo(rhs.activityInfo.packageName); + } + }); if(infoList!=null){ String packageName; for(ResolveInfo info : infoList){ @@ -361,15 +372,6 @@ protected static boolean createTrustedListRequest(final Context context, boolean return false; } - if(!forceRefresh && (System.currentTimeMillis()-getTrustedAppListTimeStamp(context)) apps = findAllSdlApps(context); - JSONObject object = new JSONObject(); + final JSONObject object = new JSONObject(); JSONArray array = new JSONArray(); JSONObject jsonApp; @@ -395,6 +397,19 @@ protected static boolean createTrustedListRequest(final Context context, boolean try {object.put(JSON_PUT_ARRAY_TAG, array);} catch (JSONException e) {e.printStackTrace();} + if(!forceRefresh && (System.currentTimeMillis()-getTrustedAppListTimeStamp(context)) Date: Thu, 8 Dec 2016 15:46:29 -0500 Subject: [PATCH 6/8] Added RSVP check during force connect to ensure not discconting legacy if not trusted --- .../SdlConnection/SdlConnection.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlConnection.java b/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlConnection.java index c9a5c13f2d..3c51b9e7e6 100644 --- a/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlConnection.java +++ b/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlConnection.java @@ -556,12 +556,19 @@ public void forceHardwareConnectEvent(TransportType type){ if(cachedMultiConfig!=null){ //We are in legacy mode, but just received a force connect. The router service should never be pointing us here if we are truely in legacy mode ComponentName tempCompName = SdlBroadcastReceiver.consumeQueuedRouterService(); - cachedMultiConfig.setService(tempCompName); - //We are not connected yet so we should be able to close down - _transport.disconnect(); //This will force us into the + RouterServiceValidator vlad = new RouterServiceValidator(cachedMultiConfig.getContext(),tempCompName); + if(vlad.validate()){ + cachedMultiConfig.setService(tempCompName); + //We are not connected yet so we should be able to close down + _transport.disconnect(); //This will force us into the + }else{ + //Log.d(TAG, "Router service not trusted during force connect. Ignoring."); + return; + } }else{ - Log.i(TAG, "No cached multiplexing config, transport error being called"); - _transport.disconnect(); + //Log.i(TAG, "No cached multiplexing config, ignoring"); + //_transport.disconnect(); + return; } Log.w(TAG, "Using own transport, but not connected. Attempting to join multiplexing"); }else{ From 490fe10a51198a7b2c57cb33f7c98c52a8ddff8b Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Fri, 9 Dec 2016 12:33:09 -0500 Subject: [PATCH 7/8] Revert removal of STATE_CHANGED in action filter --- .../src/com/smartdevicelink/transport/SdlBroadcastReceiver.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java b/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java index 85352ec3f1..6c43937ce4 100644 --- a/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java +++ b/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java @@ -22,6 +22,7 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{ private static final String BOOT_COMPLETE = "android.intent.action.BOOT_COMPLETED"; private static final String ACL_CONNECTED = "android.bluetooth.device.action.ACL_CONNECTED"; + private static final String STATE_CHANGED = "android.bluetooth.adapter.action.STATE_CHANGED" ; protected static final String SDL_ROUTER_SERVICE_CLASS_NAME = "sdlrouterservice"; @@ -57,6 +58,7 @@ public void onReceive(Context context, Intent intent) { if(!(action.equalsIgnoreCase(BOOT_COMPLETE) || action.equalsIgnoreCase(ACL_CONNECTED) + || action.equalsIgnoreCase(STATE_CHANGED) || action.equalsIgnoreCase(USBTransport.ACTION_USB_ACCESSORY_ATTACHED) || action.equalsIgnoreCase(TransportConstants.START_ROUTER_SERVICE_ACTION))){ //We don't want anything else here if the child class called super and has different intent filters From 082c4cd2b664060e99937ccf6b4086aa8b02e38a Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Fri, 9 Dec 2016 14:10:37 -0500 Subject: [PATCH 8/8] Revert removal of if statment to check what state is received --- .../transport/SdlBroadcastReceiver.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java b/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java index 6c43937ce4..17bb3fd540 100644 --- a/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java +++ b/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java @@ -118,7 +118,18 @@ public void onListObtained(boolean successful) { } - + if (intent.getAction().contains("android.bluetooth.adapter.action.STATE_CHANGED")){ + int state = intent.getIntExtra("android.bluetooth.adapter.extra.STATE",-1); + if (state == BluetoothAdapter.STATE_OFF || + state == BluetoothAdapter.STATE_TURNING_OFF){ + //onProtocolDisabled(context); + //Let's let the service that is running manage what to do for this + //If we were to do it here, for every instance of this BR it would send + //an intent to stop service, where it's only one that is needed. + return; + } + } + if(localRouterClass!=null){ //If there is a supplied router service lets run some logic regarding starting one if(!didStart){