Skip to content

Commit

Permalink
Merge branch 'hotfix/issue_357' of https://github.com/smartdevicelink…
Browse files Browse the repository at this point in the history
…/sdl_android into develop

# Conflicts:
#	sdl_android_lib/src/com/smartdevicelink/transport/SdlBroadcastReceiver.java
  • Loading branch information
joeygrover committed Nov 10, 2016
2 parents 4d99bfd + 0c6d17c commit 410d2c0
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,6 @@ public boolean validate(){
}
}//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;
}
Expand Down Expand Up @@ -352,17 +345,28 @@ private static List<SdlApp> findAllSdlApps(Context context){
* @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;
}

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;
}

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

@Override
public void httpFailure(int statusCode) {
Log.e(TAG, "Error while requesting trusted app list: "
+ statusCode);
pendingListRefresh = false;
if(listCallback!=null){listCallback.onListObtained(false);}
}
};
}
Expand Down Expand Up @@ -565,7 +571,12 @@ public static boolean isTrustedStore(String packageString){
}

}


/**
* 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand Down Expand Up @@ -80,18 +81,27 @@ public void onReceive(Context context, Intent intent) {
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());
}
}

});


}

Expand Down Expand Up @@ -234,37 +244,37 @@ private static void requestTransportStatus(Context context, final SdlRouterStatu
}
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()){
Expand Down

0 comments on commit 410d2c0

Please sign in to comment.