From 555d0a705f5e33093f973fd71fd459afbed3551b Mon Sep 17 00:00:00 2001 From: Austin Kirk Date: Wed, 8 Feb 2017 16:01:42 -0500 Subject: Creating pingRouterService method Now we can call this in isRouterServiceRunning() so we can iterate through all running services even if one throws a SecurityException --- .../transport/SdlBroadcastReceiver.java | 31 +++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java b/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java index e32aeff94..d398caaab 100644 --- a/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java +++ b/sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java @@ -200,15 +200,7 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{ 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); - try { - context.startService(intent); - }catch (SecurityException e){ - Log.e(TAG, "Security exception, process is bad"); - return false; // Let's exit, we can't start the service - } + pingRouterService(context, service.service.getPackageName(), service.service.getClassName()); } } } @@ -217,6 +209,27 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{ } + /** + * Attempts to ping a running router service + * @param context A context to access Android system services through. + * @param packageName Package name for service to ping + * @param className Class name for service to ping + */ + protected static void pingRouterService(Context context, String packageName, String className){ + if(context == null || packageName == null || className == null){ + return; + } + try{ + Intent intent = new Intent(); + intent.setClassName(packageName, className); + intent.putExtra(TransportConstants.PING_ROUTER_SERVICE_EXTRA, true); + context.startService(intent); + }catch(SecurityException e){ + Log.e(TAG, "Security exception, process is bad"); + // This service could not be started + } + } + /** * 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. -- cgit v1.2.1