-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix/issue 392 #409
Bugfix/issue 392 #409
Conversation
context.startService(intent); | ||
}catch (SecurityException e){ | ||
Log.e(TAG, "Process is bad"); | ||
android.os.Process.killProcess(android.os.Process.myPid()); // Let's exit, we can't start our service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to do this. Killing myPid process will actually kill the entire app. We just want to fail silently here, add a return statement there instead.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we actually can't just return false blindly here. If you take a look at the return statement after this for loop you can see we need to actually return something meaningful. I'd move the ping code into a separate method with the try/catch so that we can continue through the loop and return something meaningful.
Something like this:
protected 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){
}
}
Now we can call this in isRouterServiceRunning() so we can iterate through all running services even if one throws a SecurityException
-Protecting against SecurityException found in issue #392