Skip to content

Commit a624a06

Browse files
Bugfix/rs notification issue usb (#1797)
* Fix RS exit foreground params * Refactor to call extiForeground for every close() In the RS * Fix altTransport timer issues preventing RS close * Fix incorrect spacing PR #1797 Co-authored-by: Julian Kast <Julian.kast@livio.io> Co-authored-by: Julian Kast <Julian.kast@livio.io>
1 parent 4784a4b commit a624a06

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,9 +1633,9 @@ private void exitForeground() {
16331633
if (isForeground && !isPrimaryTransportConnected()) { //Ensure that the service is in the foreground and no longer connected to a transport
16341634
DebugTool.logInfo(TAG, "SdlRouterService to exit foreground");
16351635
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
1636-
this.stopForeground(Service.STOP_FOREGROUND_DETACH);
1636+
this.stopForeground(Service.STOP_FOREGROUND_REMOVE);
16371637
} else {
1638-
stopForeground(false);
1638+
stopForeground(true);
16391639
}
16401640
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
16411641
if (notificationManager != null) {
@@ -1758,7 +1758,7 @@ public boolean shouldServiceRemainOpen(Intent intent) {
17581758

17591759
} else if (intent != null && TransportConstants.BIND_REQUEST_TYPE_ALT_TRANSPORT.equals(intent.getAction())) {
17601760
DebugTool.logInfo(TAG, "Received start intent with alt transport request.");
1761-
startAltTransportTimer();
1761+
startAltTransportTimer(); //This timer is started to allow the router service to stay open while it waits for the USB transfer to take place
17621762
return true;
17631763
} else if (!bluetoothAvailable()) {//If bluetooth isn't on...there's nothing to see here
17641764
//Bluetooth is off, we should shut down
@@ -1780,8 +1780,8 @@ public void closeSelf() {
17801780
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !hasCalledStartForeground) {
17811781
//This must be called before stopping self
17821782
safeStartForeground(FOREGROUND_SERVICE_ID, null);
1783-
exitForeground();
17841783
}
1784+
exitForeground();
17851785

17861786
if (getBaseContext() != null) {
17871787
stopSelf();
@@ -1980,6 +1980,12 @@ public void onTransportDisconnected(TransportRecord record) {
19801980
usbSessionMap.clear();
19811981
}
19821982
}
1983+
//In case the USB connection has ended before the timer expired, we should stop it
1984+
if (altTransportTimerHandler != null && altTransportTimerRunnable != null) {
1985+
altTransportTimerHandler.removeCallbacks(altTransportTimerRunnable);
1986+
altTransportTimerHandler = null;
1987+
altTransportTimerRunnable = null;
1988+
}
19831989
break;
19841990
case TCP:
19851991
if (tcpTransport != null) {
@@ -2631,6 +2637,11 @@ private void startAltTransportTimer() {
26312637
if (Looper.myLooper() == null) {
26322638
Looper.prepare();
26332639
}
2640+
2641+
if (altTransportTimerHandler != null && altTransportTimerRunnable != null) {
2642+
altTransportTimerHandler.removeCallbacks(altTransportTimerRunnable);
2643+
}
2644+
26342645
altTransportTimerHandler = new Handler(Looper.myLooper());
26352646
altTransportTimerRunnable = new Runnable() {
26362647
public void run() {

0 commit comments

Comments
 (0)