Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,12 @@ private static boolean isBluetoothConnected() {
return false;
}

private static void handleStartServiceException(Exception e) {
/**
* Convenience method to log details on the specific exception that occurred while attempting to
* start a foreground service.
* @param e the exception that occurred
*/
protected static void handleStartServiceException(Exception e) {
if (e instanceof SecurityException) {
DebugTool.logError(TAG, "Security exception, process is bad");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,21 @@ private boolean bindToService() {
} else {
bindingIntent.putExtra(FOREGROUND_EXTRA, true);
SdlBroadcastReceiver.setForegroundExceptionHandler(); //Prevent ANR in case the OS takes too long to start the service
context.startForegroundService(bindingIntent);
try {
context.startForegroundService(bindingIntent);
} catch (SecurityException | IllegalStateException e) {
SdlBroadcastReceiver.handleStartServiceException(e);
}

}
bindingIntent.setAction(TransportConstants.BIND_REQUEST_TYPE_STATUS);
return context.bindService(bindingIntent, routerConnection, Context.BIND_AUTO_CREATE);
boolean didBind = false;
try {
didBind = context.bindService(bindingIntent, routerConnection, Context.BIND_AUTO_CREATE);
} catch (SecurityException | IllegalStateException e) {
SdlBroadcastReceiver.handleStartServiceException(e);
}
return didBind;
}

private void unBindFromService() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ public void onUsbTransferUpdate(boolean success) {

}

} catch (SecurityException e) {
DebugTool.logError(TAG, "Security exception, process is bad");
} catch (SecurityException | IllegalStateException e) {
SdlBroadcastReceiver.handleStartServiceException(e);
}
} else {
if (usbAccessory != null) {
Expand Down