Skip to content

Commit 6498858

Browse files
committed
Catch ForegroundServiceStartNotAllowedException in SdlBroadcastReceiver
1 parent ccf0af9 commit 6498858

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232

3333
package com.smartdevicelink.transport;
3434

35+
import android.annotation.SuppressLint;
3536
import android.app.ActivityManager;
3637
import android.app.ActivityManager.RunningServiceInfo;
38+
import android.app.ForegroundServiceStartNotAllowedException;
3739
import android.bluetooth.BluetoothAdapter;
3840
import android.bluetooth.BluetoothDevice;
3941
import android.bluetooth.BluetoothProfile;
@@ -284,6 +286,8 @@ private static void startRouterService(Context context, ComponentName componentN
284286

285287
} catch (SecurityException e) {
286288
DebugTool.logError(TAG, "Security exception, process is bad");
289+
} catch (@SuppressLint({"NewApi", "LocalSuppress"}) ForegroundServiceStartNotAllowedException e) {
290+
DebugTool.logError(TAG, "Not allowed to start service in Foreground");
287291
}
288292
}
289293

@@ -481,6 +485,8 @@ protected static void pingRouterService(Context context, String packageName, Str
481485
} catch (SecurityException e) {
482486
DebugTool.logError(TAG, "Security exception, process is bad");
483487
// This service could not be started
488+
} catch (@SuppressLint({"NewApi", "LocalSuppress"}) ForegroundServiceStartNotAllowedException e) {
489+
DebugTool.logError(TAG, "Not allowed to start service in Foreground");
484490
}
485491
}
486492

0 commit comments

Comments
 (0)