diff options
Diffstat (limited to 'android')
3 files changed, 20 insertions, 5 deletions
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java index 73d1fe2dc..936989f5c 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java @@ -600,7 +600,12 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver { 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; diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterStatusProvider.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterStatusProvider.java index b90a55684..078fe104c 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterStatusProvider.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterStatusProvider.java @@ -136,11 +136,21 @@ public class SdlRouterStatusProvider { } 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() { diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBAccessoryAttachmentActivity.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBAccessoryAttachmentActivity.java index 22ee5d1db..7bb2f753b 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBAccessoryAttachmentActivity.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/USBAccessoryAttachmentActivity.java @@ -202,8 +202,8 @@ public class USBAccessoryAttachmentActivity extends Activity { }
- } catch (SecurityException e) {
- DebugTool.logError(TAG, "Security exception, process is bad");
+ } catch (SecurityException | IllegalStateException e) {
+ SdlBroadcastReceiver.handleStartServiceException(e);
}
} else {
if (usbAccessory != null) {
|