diff options
author | Henigan <rheniga1@MGC12Z921DLVCG.fbpld77.ford.com> | 2021-09-15 14:53:35 -0400 |
---|---|---|
committer | Henigan <rheniga1@MGC12Z921DLVCG.fbpld77.ford.com> | 2021-09-15 14:53:35 -0400 |
commit | 8bb02720b4f398c707900e90337ff58998b1ec13 (patch) | |
tree | 675e5f6efdfcc52f49a6508ed6cd515f9f2b1c7b | |
parent | 01ca77089f040189683641db07263c81033bdbb5 (diff) | |
download | sdl_android-8bb02720b4f398c707900e90337ff58998b1ec13.tar.gz |
Update BT Permissions and Notification Behavior
3 files changed, 35 insertions, 9 deletions
diff --git a/android/hello_sdl_android/src/main/AndroidManifest.xml b/android/hello_sdl_android/src/main/AndroidManifest.xml index fe5485794..871a26c80 100755 --- a/android/hello_sdl_android/src/main/AndroidManifest.xml +++ b/android/hello_sdl_android/src/main/AndroidManifest.xml @@ -3,7 +3,12 @@ xmlns:tools="http://schemas.android.com/tools" package="com.sdl.hellosdlandroid"> - <uses-permission android:name="android.permission.BLUETOOTH" /> + <uses-permission android:name="android.permission.BLUETOOTH" + android:maxSdkVersion="30"/> + <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> + <uses-permission android:name="android.permission.BLUETOOTH_SCAN" + android:usesPermissionFlags="neverForLocation" + tools:targetApi="31" /> <uses-permission android:name="android.permission.INTERNET" /> <!-- Required to check if WiFi is enabled --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java index c6e9ce3ef..59daf2050 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java @@ -108,10 +108,13 @@ public class SdlService extends Service { NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager != null) { notificationManager.createNotificationChannel(channel); - Notification serviceNotification = new Notification.Builder(this, channel.getId()) + Notification.Builder builder = new Notification.Builder(this, channel.getId()) .setContentTitle("Connected through SDL") - .setSmallIcon(R.drawable.ic_sdl) - .build(); + .setSmallIcon(R.drawable.ic_sdl); + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + builder.setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE); + } + Notification serviceNotification = builder.build(); startForeground(FOREGROUND_SERVICE_ID, serviceNotification); } } diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java index 723c6f033..a35ebf5f1 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java @@ -1464,6 +1464,10 @@ public class SdlRouterService extends Service { builder = new Notification.Builder(this, SDL_NOTIFICATION_CHANNEL_ID); } + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + builder.setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE); + } + if (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)) { //If we are in debug mode, include what app has the router service open ComponentName name = new ComponentName(this, this.getClass()); builder.setContentTitle("SDL: " + name.getPackageName()); @@ -1534,12 +1538,22 @@ public class SdlRouterService extends Service { private void safeStartForeground(int id, Notification notification) { try { if (notification == null) { - //Try the NotificationCompat this time in case there was a previous error - NotificationCompat.Builder builder = - new NotificationCompat.Builder(this, SDL_NOTIFICATION_CHANNEL_ID) + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { + Notification.Builder builder = + new Notification.Builder(this, SDL_NOTIFICATION_CHANNEL_ID) .setContentTitle("SmartDeviceLink") - .setContentText("Service Running"); - notification = builder.build(); + .setContentText("Service Running") + .setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE); + notification = builder.build(); + } else { + //Try the NotificationCompat this time in case there was a previous error + NotificationCompat.Builder builder = + new NotificationCompat.Builder(this, SDL_NOTIFICATION_CHANNEL_ID) + .setContentTitle("SmartDeviceLink") + .setContentText("Service Running"); + + notification = builder.build(); + } } startForeground(id, notification); DebugTool.logInfo(TAG, "Entered the foreground - " + System.currentTimeMillis()); @@ -3758,6 +3772,10 @@ public class SdlRouterService extends Service { } else { builder = new Notification.Builder(getApplicationContext(), TransportConstants.SDL_ERROR_NOTIFICATION_CHANNEL_ID); } + + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + builder.setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE); + } ComponentName name = new ComponentName(this, this.getClass()); if (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)) { //If we are in debug mode, include what app has the router service open builder.setContentTitle("SDL: " + name.getPackageName()); |