|
69 | 69 | import android.os.ParcelFileDescriptor; |
70 | 70 | import android.os.Parcelable; |
71 | 71 | import android.os.RemoteException; |
| 72 | +import android.service.notification.StatusBarNotification; |
72 | 73 | import android.support.annotation.NonNull; |
73 | 74 | import android.support.v4.app.NotificationCompat; |
74 | 75 | import android.util.Log; |
@@ -138,7 +139,7 @@ public class SdlRouterService extends Service{ |
138 | 139 | /** |
139 | 140 | * <b> NOTE: DO NOT MODIFY THIS UNLESS YOU KNOW WHAT YOU'RE DOING.</b> |
140 | 141 | */ |
141 | | - protected static final int ROUTER_SERVICE_VERSION_NUMBER = 10; |
| 142 | + protected static final int ROUTER_SERVICE_VERSION_NUMBER = 11; |
142 | 143 |
|
143 | 144 | private static final String ROUTER_SERVICE_PROCESS = "com.smartdevicelink.router"; |
144 | 145 |
|
@@ -1443,8 +1444,9 @@ private void enterForeground(String content, long chronometerLength, boolean ong |
1443 | 1444 | PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); |
1444 | 1445 | builder.setContentIntent(pendingIntent); |
1445 | 1446 |
|
1446 | | - if(chronometerLength > 0 && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| 1447 | + if(chronometerLength > (FOREGROUND_TIMEOUT/1000) && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
1447 | 1448 | //The countdown method is only available in SDKs >= 24 |
| 1449 | + // Only add countdown if it is over the min timeout |
1448 | 1450 | builder.setWhen(chronometerLength + System.currentTimeMillis()); |
1449 | 1451 | builder.setUsesChronometer(true); |
1450 | 1452 | builder.setChronometerCountDown(true); |
@@ -1516,6 +1518,27 @@ private void exitForeground(){ |
1516 | 1518 | synchronized (NOTIFICATION_LOCK) { |
1517 | 1519 | if (isForeground && !isPrimaryTransportConnected()) { //Ensure that the service is in the foreground and no longer connected to a transport |
1518 | 1520 | this.stopForeground(true); |
| 1521 | + NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); |
| 1522 | + if (notificationManager!= null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| 1523 | + try { |
| 1524 | + boolean notificationHasDisplayed = false; |
| 1525 | + StatusBarNotification[] notifications = notificationManager.getActiveNotifications(); |
| 1526 | + for (StatusBarNotification notification : notifications) { |
| 1527 | + if(notification != null && FOREGROUND_SERVICE_ID == notification.getId()){ |
| 1528 | + DebugTool.logInfo("Service notification is being displayed"); |
| 1529 | + notificationHasDisplayed = true; |
| 1530 | + break; |
| 1531 | + } |
| 1532 | + } |
| 1533 | + if (notificationHasDisplayed) { |
| 1534 | + notificationManager.deleteNotificationChannel(SDL_NOTIFICATION_CHANNEL_ID); |
| 1535 | + } |
| 1536 | + //else leave the notification channel alone to avoid deleting it before the |
| 1537 | + //foreground service notification has a chance to be displayed. |
| 1538 | + } catch (Exception e){ |
| 1539 | + DebugTool.logError("Issue when deleting notification channel", e); |
| 1540 | + } |
| 1541 | + } |
1519 | 1542 | isForeground = false; |
1520 | 1543 | } |
1521 | 1544 | } |
|
0 commit comments