diff options
author | Joey Grover <joeygrover@gmail.com> | 2016-11-10 15:57:04 -0500 |
---|---|---|
committer | Joey Grover <joeygrover@gmail.com> | 2016-11-10 15:57:04 -0500 |
commit | 410d2c0a2d5137e8dba6b6ccc473efcf0da3c7b5 (patch) | |
tree | a0ad0371730f27ad76d76dca4a8be4f01f08ae34 | |
parent | 4d99bfd6770e8e8f85e29a98674fa4052722e22d (diff) | |
parent | 0c6d17c76d712b2225d905d9615181cf43f99644 (diff) | |
download | sdl_android-release/4.2.0-rc1.tar.gz |
Merge branch 'hotfix/issue_357' of https://github.com/smartdevicelink/sdl_android into developrelease/4.2.0-rc1
# Conflicts:
# sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java
-rw-r--r-- | sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java | 31 | ||||
-rw-r--r-- | sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java | 86 |
2 files changed, 69 insertions, 48 deletions
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java b/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java index 3c5b71c5e..5c7027180 100644 --- a/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java +++ b/sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java @@ -128,13 +128,6 @@ public class RouterServiceValidator { } }//No running service found. Might need to attempt to start one //TODO spin up a known good router service - - if(context.getPackageName().equalsIgnoreCase(packageName)){ - Log.d(TAG, "It's our router service running, so time to shut it down"); - Intent intent = new Intent(); - intent.setComponent(service); - try{context.stopService(intent);}catch(Exception e){} - } wakeUpRouterServices(); return false; } @@ -352,10 +345,18 @@ public class RouterServiceValidator { * @param context */ public static boolean createTrustedListRequest(final Context context, boolean forceRefresh){ - return createTrustedListRequest(context,forceRefresh,null); + return createTrustedListRequest(context,forceRefresh,null,null); + } + public static boolean createTrustedListRequest(final Context context, boolean forceRefresh, TrustedListCallback listCallback){Log.d(TAG,"Checking to make sure we have a list"); + return createTrustedListRequest(context,forceRefresh,null,listCallback); } + @Deprecated protected static boolean createTrustedListRequest(final Context context, boolean forceRefresh,HttpRequestTask.HttpRequestTaskCallback cb ){ + return createTrustedListRequest(context,forceRefresh,cb,null); + } + + protected static boolean createTrustedListRequest(final Context context, boolean forceRefresh,HttpRequestTask.HttpRequestTaskCallback cb, final TrustedListCallback listCallback ){ if(context == null){ return false; } @@ -363,6 +364,9 @@ public class RouterServiceValidator { if(!forceRefresh && (System.currentTimeMillis()-getTrustedAppListTimeStamp(context))<REFRESH_TRUSTED_APP_LIST_TIME){ //Our list should still be ok for now so we will skip the request pendingListRefresh = false; + if(listCallback!=null){ + listCallback.onListObtained(true); + } return false; } @@ -400,6 +404,7 @@ public class RouterServiceValidator { //Log.d(TAG, "APPS! " + response); setTrustedList(context, response); pendingListRefresh = false; + if(listCallback!=null){listCallback.onListObtained(true);} } @Override @@ -407,6 +412,7 @@ public class RouterServiceValidator { Log.e(TAG, "Error while requesting trusted app list: " + statusCode); pendingListRefresh = false; + if(listCallback!=null){listCallback.onListObtained(false);} } }; } @@ -565,7 +571,12 @@ public class RouterServiceValidator { } } - - + /** + * This interface is used as a callback to know when we have either obtained a list or at least returned from our attempt. + * + */ + public static interface TrustedListCallback{ + public void onListObtained(boolean successful); + } } diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java b/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java index e915a960d..c83699505 100644 --- a/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java +++ b/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java @@ -5,6 +5,7 @@ import java.util.Vector; import java.util.concurrent.ConcurrentLinkedQueue; import com.smartdevicelink.util.AndroidTools; +import com.smartdevicelink.transport.RouterServiceValidator.TrustedListCallback; import android.app.ActivityManager; import android.app.ActivityManager.RunningServiceInfo; @@ -80,18 +81,27 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{ if(intent.hasExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_EXTRA)){ if(intent.getBooleanExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_EXTRA, false)){ String packageName = intent.getStringExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_APP_PACKAGE); - ComponentName componentName = intent.getParcelableExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_CMP_NAME); + final 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()); - RouterServiceValidator vlad = new RouterServiceValidator(context,componentName); - if(vlad.validate()){ - //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.w(TAG, "RouterService was not trusted. Ignoring intent from : "+ componentName.getClassName()); - } + final Intent finalIntent = intent; + final Context finalContext = context; + RouterServiceValidator.createTrustedListRequest(context, false, new TrustedListCallback(){ + @Override + public void onListObtained(boolean successful) { + //Log.v(TAG, "SDL enabled by router service from " + packageName + " compnent package " + componentName.getPackageName() + " - " + componentName.getClassName()); + 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()); + } + } + + }); + } @@ -234,37 +244,37 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{ } 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(); - } + 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(); + }; + final SdlRouterStatusProvider provider = new SdlRouterStatusProvider(context,list.poll(),sdlBrCallback); + if(triggerRouterServicePing){ + provider.setFlags(TransportConstants.ROUTER_STATUS_FLAG_TRIGGER_PING); } + //Lets ensure we have a current list of trusted router services + RouterServiceValidator.createTrustedListRequest(context, false, new TrustedListCallback(){ + @Override + public void onListObtained(boolean successful) { + //This will kick off our check of router services + provider.checkIsConnected(); + } + }); + }else{ Log.w(TAG, "Router service isn't running, returning false."); if(BluetoothAdapter.getDefaultAdapter()!=null && BluetoothAdapter.getDefaultAdapter().isEnabled()){ |