|  | 
| 5 | 5 | import java.util.concurrent.ConcurrentLinkedQueue; | 
| 6 | 6 | 
 | 
| 7 | 7 | import com.smartdevicelink.util.AndroidTools; | 
|  | 8 | +import com.smartdevicelink.transport.RouterServiceValidator.TrustedListCallback; | 
| 8 | 9 | 
 | 
| 9 | 10 | import android.app.ActivityManager; | 
| 10 | 11 | import android.app.ActivityManager.RunningServiceInfo; | 
| @@ -80,18 +81,27 @@ public void onReceive(Context context, Intent intent) { | 
| 80 | 81 | 			if(intent.hasExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_EXTRA)){	 | 
| 81 | 82 | 				if(intent.getBooleanExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_EXTRA, false)){ | 
| 82 | 83 | 					String packageName = intent.getStringExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_APP_PACKAGE); | 
| 83 |  | -					ComponentName componentName = intent.getParcelableExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_CMP_NAME); | 
|  | 84 | +					final ComponentName componentName = intent.getParcelableExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_CMP_NAME); | 
| 84 | 85 | 					if(componentName!=null){ | 
| 85 |  | -						//Log.v(TAG, "SDL enabled by router service from " + packageName + " compnent package " + componentName.getPackageName()  + " - " + componentName.getClassName()); | 
| 86 |  | -						RouterServiceValidator vlad = new RouterServiceValidator(context,componentName); | 
| 87 |  | -						if(vlad.validate()){ | 
| 88 |  | -							//Log.d(TAG, "Router service trusted!"); | 
| 89 |  | -							queuedService = componentName; | 
| 90 |  | -							intent.setAction("com.sdl.noaction"); //Replace what's there so we do go into some unintended loop | 
| 91 |  | -							onSdlEnabled(context, intent); | 
| 92 |  | -						}else{ | 
| 93 |  | -							Log.w(TAG, "RouterService was not trusted. Ignoring intent from : "+ componentName.getClassName()); | 
| 94 |  | -						} | 
|  | 86 | +						final Intent finalIntent = intent; | 
|  | 87 | +						final Context finalContext = context; | 
|  | 88 | +						RouterServiceValidator.createTrustedListRequest(context, false, new TrustedListCallback(){ | 
|  | 89 | +							@Override | 
|  | 90 | +							public void onListObtained(boolean successful) { | 
|  | 91 | +								//Log.v(TAG, "SDL enabled by router service from " + packageName + " compnent package " + componentName.getPackageName()  + " - " + componentName.getClassName()); | 
|  | 92 | +								RouterServiceValidator vlad = new RouterServiceValidator(finalContext,componentName); | 
|  | 93 | +								if(vlad.validate()){ | 
|  | 94 | +									//Log.d(TAG, "Router service trusted!"); | 
|  | 95 | +									queuedService = componentName; | 
|  | 96 | +									finalIntent.setAction("com.sdl.noaction"); //Replace what's there so we do go into some unintended loop | 
|  | 97 | +									onSdlEnabled(finalContext, finalIntent); | 
|  | 98 | +								}else{ | 
|  | 99 | +									Log.w(TAG, "RouterService was not trusted. Ignoring intent from : "+ componentName.getClassName()); | 
|  | 100 | +								} | 
|  | 101 | +							} | 
|  | 102 | +							 | 
|  | 103 | +						}); | 
|  | 104 | +						 | 
| 95 | 105 | 
 | 
| 96 | 106 | 					} | 
| 97 | 107 | 
 | 
| @@ -234,37 +244,37 @@ private static void requestTransportStatus(Context context, final SdlRouterStatu | 
| 234 | 244 | 		} | 
| 235 | 245 | 		if(isRouterServiceRunning(context,false) && !runningBluetoothServicePackage.isEmpty()){	//So there is a service up, let's see if it's connected | 
| 236 | 246 | 			final ConcurrentLinkedQueue<ComponentName> list = new ConcurrentLinkedQueue<ComponentName>(runningBluetoothServicePackage); | 
| 237 |  | -			if(runningBluetoothServicePackage.size()>0){ //TODO for testing do this for all cases | 
| 238 |  | -				final SdlRouterStatusProvider.ConnectedStatusCallback sdlBrCallback = new SdlRouterStatusProvider.ConnectedStatusCallback() {	 | 
| 239 |  | -					 | 
| 240 |  | -					@Override | 
| 241 |  | -					public void onConnectionStatusUpdate(boolean connected, ComponentName service,Context context) { | 
| 242 |  | -						if(!connected && !list.isEmpty()){ | 
| 243 |  | -							SdlRouterStatusProvider provider = new SdlRouterStatusProvider(context,list.poll(), this); | 
| 244 |  | -							if(triggerRouterServicePing){provider.setFlags(TransportConstants.ROUTER_STATUS_FLAG_TRIGGER_PING);	} | 
| 245 |  | -							provider.checkIsConnected(); | 
| 246 |  | -						}else{ | 
| 247 |  | -							Log.d(TAG, service.getPackageName() + " is connected = " + connected); | 
| 248 |  | -							if(callback!=null){ | 
| 249 |  | -								callback.onConnectionStatusUpdate(connected, service,context); | 
| 250 |  | -							} | 
| 251 |  | -							list.clear(); | 
| 252 |  | -						} | 
|  | 247 | +			final SdlRouterStatusProvider.ConnectedStatusCallback sdlBrCallback = new SdlRouterStatusProvider.ConnectedStatusCallback() {	 | 
| 253 | 248 | 
 | 
|  | 249 | +				@Override | 
|  | 250 | +				public void onConnectionStatusUpdate(boolean connected, ComponentName service,Context context) { | 
|  | 251 | +					if(!connected && !list.isEmpty()){ | 
|  | 252 | +						SdlRouterStatusProvider provider = new SdlRouterStatusProvider(context,list.poll(), this); | 
|  | 253 | +						if(triggerRouterServicePing){provider.setFlags(TransportConstants.ROUTER_STATUS_FLAG_TRIGGER_PING);	} | 
|  | 254 | +						provider.checkIsConnected(); | 
|  | 255 | +					}else{ | 
|  | 256 | +						Log.d(TAG, service.getPackageName() + " is connected = " + connected); | 
|  | 257 | +						if(callback!=null){ | 
|  | 258 | +							callback.onConnectionStatusUpdate(connected, service,context); | 
|  | 259 | +						} | 
|  | 260 | +						list.clear(); | 
| 254 | 261 | 					} | 
| 255 |  | -				}; | 
| 256 |  | -				SdlRouterStatusProvider provider = new SdlRouterStatusProvider(context,list.poll(),sdlBrCallback); | 
| 257 |  | -				if(triggerRouterServicePing){ | 
| 258 |  | -					provider.setFlags(TransportConstants.ROUTER_STATUS_FLAG_TRIGGER_PING); | 
| 259 |  | -				} | 
| 260 |  | -				provider.checkIsConnected(); | 
| 261 |  | -			}else{ //If only one service is running, just check that | 
| 262 |  | -				SdlRouterStatusProvider provider = new SdlRouterStatusProvider(context,runningBluetoothServicePackage.get(0),callback); | 
| 263 |  | -				if(triggerRouterServicePing){ | 
| 264 |  | -					provider.setFlags(TransportConstants.ROUTER_STATUS_FLAG_TRIGGER_PING); | 
|  | 262 | + | 
| 265 | 263 | 				} | 
| 266 |  | -				provider.checkIsConnected(); | 
|  | 264 | +			}; | 
|  | 265 | +			final SdlRouterStatusProvider provider = new SdlRouterStatusProvider(context,list.poll(),sdlBrCallback); | 
|  | 266 | +			if(triggerRouterServicePing){ | 
|  | 267 | +				provider.setFlags(TransportConstants.ROUTER_STATUS_FLAG_TRIGGER_PING); | 
| 267 | 268 | 			} | 
|  | 269 | +			//Lets ensure we have a current list of trusted router services | 
|  | 270 | +			RouterServiceValidator.createTrustedListRequest(context, false, new TrustedListCallback(){ | 
|  | 271 | +				@Override | 
|  | 272 | +				public void onListObtained(boolean successful) { | 
|  | 273 | +					//This will kick off our check of router services | 
|  | 274 | +					provider.checkIsConnected(); | 
|  | 275 | +				} | 
|  | 276 | +			}); | 
|  | 277 | +				 | 
| 268 | 278 | 		}else{ | 
| 269 | 279 | 			Log.w(TAG, "Router service isn't running, returning false."); | 
| 270 | 280 | 			if(BluetoothAdapter.getDefaultAdapter()!=null && BluetoothAdapter.getDefaultAdapter().isEnabled()){ | 
|  | 
0 commit comments