summaryrefslogtreecommitdiff
path: root/android/sdl_android/src/main
diff options
context:
space:
mode:
authorBilal Alsharifi <599206+bilal-alsharifi@users.noreply.github.com>2020-04-03 09:32:26 -0400
committerGitHub <noreply@github.com>2020-04-03 09:32:26 -0400
commit9a1be39909d8f52cb090801cae09459d577a4acc (patch)
treecd28a009ecaa4f9d63ffe40da3b69c4d96eedb37 /android/sdl_android/src/main
parentd82ddd8e81d02b4db137dc9fc39d5cd3b8aa87c2 (diff)
parentcd2cd7e5aeb7882cd4a6530c178885158e27c35e (diff)
downloadsdl_android-9a1be39909d8f52cb090801cae09459d577a4acc.tar.gz
Merge pull request #1311 from smartdevicelink/bugfix/router_service_notification
Refactor router service's exitForeground logic
Diffstat (limited to 'android/sdl_android/src/main')
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java28
1 files changed, 12 insertions, 16 deletions
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 bd86f86c2..3313fd0f3 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
@@ -1344,6 +1344,7 @@ public class SdlRouterService extends Service{
// If this is the first time the service has ever connected to this device we want
// to ensure we have a record of it
setSDLConnectedStatus(address, false);
+ return FOREGROUND_TIMEOUT;
}
}
// If this is a new device or hasn't connected through SDL we want to limit the exposure
@@ -1517,26 +1518,21 @@ public class SdlRouterService extends Service{
private void exitForeground(){
synchronized (NOTIFICATION_LOCK) {
if (isForeground && !isPrimaryTransportConnected()) { //Ensure that the service is in the foreground and no longer connected to a transport
- this.stopForeground(true);
+ DebugTool.logInfo("SdlRouterService to exit foreground");
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ this.stopForeground(Service.STOP_FOREGROUND_DETACH);
+ }else{
+ stopForeground(false);
+ }
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
- if (notificationManager!= null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ if (notificationManager!= null){
try {
- boolean notificationHasDisplayed = false;
- StatusBarNotification[] notifications = notificationManager.getActiveNotifications();
- for (StatusBarNotification notification : notifications) {
- if(notification != null && FOREGROUND_SERVICE_ID == notification.getId()){
- DebugTool.logInfo("Service notification is being displayed");
- notificationHasDisplayed = true;
- break;
- }
- }
- if (notificationHasDisplayed) {
+ notificationManager.cancelAll();
+ if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationManager.deleteNotificationChannel(SDL_NOTIFICATION_CHANNEL_ID);
}
- //else leave the notification channel alone to avoid deleting it before the
- //foreground service notification has a chance to be displayed.
- } catch (Exception e){
- DebugTool.logError("Issue when deleting notification channel", e);
+ } catch (Exception e) {
+ DebugTool.logError("Issue when removing notification and channel", e);
}
}
isForeground = false;