Skip to content

Commit 410d2c0

Browse files
committed
Merge branch 'hotfix/issue_357' of https://github.com/smartdevicelink/sdl_android into develop
# Conflicts: # sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java
2 parents 4d99bfd + 0c6d17c commit 410d2c0

File tree

2 files changed

+69
-48
lines changed

2 files changed

+69
-48
lines changed

sdl_android_lib/src/com/smartdevicelink/transport/RouterServiceValidator.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ public boolean validate(){
128128
}
129129
}//No running service found. Might need to attempt to start one
130130
//TODO spin up a known good router service
131-
132-
if(context.getPackageName().equalsIgnoreCase(packageName)){
133-
Log.d(TAG, "It's our router service running, so time to shut it down");
134-
Intent intent = new Intent();
135-
intent.setComponent(service);
136-
try{context.stopService(intent);}catch(Exception e){}
137-
}
138131
wakeUpRouterServices();
139132
return false;
140133
}
@@ -352,17 +345,28 @@ private static List<SdlApp> findAllSdlApps(Context context){
352345
* @param context
353346
*/
354347
public static boolean createTrustedListRequest(final Context context, boolean forceRefresh){
355-
return createTrustedListRequest(context,forceRefresh,null);
348+
return createTrustedListRequest(context,forceRefresh,null,null);
349+
}
350+
public static boolean createTrustedListRequest(final Context context, boolean forceRefresh, TrustedListCallback listCallback){Log.d(TAG,"Checking to make sure we have a list");
351+
return createTrustedListRequest(context,forceRefresh,null,listCallback);
356352
}
357353

354+
@Deprecated
358355
protected static boolean createTrustedListRequest(final Context context, boolean forceRefresh,HttpRequestTask.HttpRequestTaskCallback cb ){
356+
return createTrustedListRequest(context,forceRefresh,cb,null);
357+
}
358+
359+
protected static boolean createTrustedListRequest(final Context context, boolean forceRefresh,HttpRequestTask.HttpRequestTaskCallback cb, final TrustedListCallback listCallback ){
359360
if(context == null){
360361
return false;
361362
}
362363

363364
if(!forceRefresh && (System.currentTimeMillis()-getTrustedAppListTimeStamp(context))<REFRESH_TRUSTED_APP_LIST_TIME){
364365
//Our list should still be ok for now so we will skip the request
365366
pendingListRefresh = false;
367+
if(listCallback!=null){
368+
listCallback.onListObtained(true);
369+
}
366370
return false;
367371
}
368372

@@ -400,13 +404,15 @@ public void httpCallComplete(String response) {
400404
//Log.d(TAG, "APPS! " + response);
401405
setTrustedList(context, response);
402406
pendingListRefresh = false;
407+
if(listCallback!=null){listCallback.onListObtained(true);}
403408
}
404409

405410
@Override
406411
public void httpFailure(int statusCode) {
407412
Log.e(TAG, "Error while requesting trusted app list: "
408413
+ statusCode);
409414
pendingListRefresh = false;
415+
if(listCallback!=null){listCallback.onListObtained(false);}
410416
}
411417
};
412418
}
@@ -565,7 +571,12 @@ public static boolean isTrustedStore(String packageString){
565571
}
566572

567573
}
568-
569-
574+
/**
575+
* This interface is used as a callback to know when we have either obtained a list or at least returned from our attempt.
576+
*
577+
*/
578+
public static interface TrustedListCallback{
579+
public void onListObtained(boolean successful);
580+
}
570581

571582
}

sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.concurrent.ConcurrentLinkedQueue;
66

77
import com.smartdevicelink.util.AndroidTools;
8+
import com.smartdevicelink.transport.RouterServiceValidator.TrustedListCallback;
89

910
import android.app.ActivityManager;
1011
import android.app.ActivityManager.RunningServiceInfo;
@@ -80,18 +81,27 @@ public void onReceive(Context context, Intent intent) {
8081
if(intent.hasExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_EXTRA)){
8182
if(intent.getBooleanExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_EXTRA, false)){
8283
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);
8485
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+
95105

96106
}
97107

@@ -234,37 +244,37 @@ private static void requestTransportStatus(Context context, final SdlRouterStatu
234244
}
235245
if(isRouterServiceRunning(context,false) && !runningBluetoothServicePackage.isEmpty()){ //So there is a service up, let's see if it's connected
236246
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() {
253248

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();
254261
}
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+
265263
}
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);
267268
}
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+
268278
}else{
269279
Log.w(TAG, "Router service isn't running, returning false.");
270280
if(BluetoothAdapter.getDefaultAdapter()!=null && BluetoothAdapter.getDefaultAdapter().isEnabled()){

0 commit comments

Comments
 (0)