Skip to content

Commit

Permalink
Bugfix/rs notification issue usb (#1797)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

Co-authored-by: Julian Kast <[email protected]>
  • Loading branch information
joeygrover and JulianKast authored Mar 28, 2022
1 parent 4784a4b commit a624a06
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1633,9 +1633,9 @@ private void exitForeground() {
if (isForeground && !isPrimaryTransportConnected()) { //Ensure that the service is in the foreground and no longer connected to a transport
DebugTool.logInfo(TAG, "SdlRouterService to exit foreground");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
this.stopForeground(Service.STOP_FOREGROUND_DETACH);
this.stopForeground(Service.STOP_FOREGROUND_REMOVE);
} else {
stopForeground(false);
stopForeground(true);
}
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
Expand Down Expand Up @@ -1758,7 +1758,7 @@ public boolean shouldServiceRemainOpen(Intent intent) {

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

if (getBaseContext() != null) {
stopSelf();
Expand Down Expand Up @@ -1980,6 +1980,12 @@ public void onTransportDisconnected(TransportRecord record) {
usbSessionMap.clear();
}
}
//In case the USB connection has ended before the timer expired, we should stop it
if (altTransportTimerHandler != null && altTransportTimerRunnable != null) {
altTransportTimerHandler.removeCallbacks(altTransportTimerRunnable);
altTransportTimerHandler = null;
altTransportTimerRunnable = null;
}
break;
case TCP:
if (tcpTransport != null) {
Expand Down Expand Up @@ -2631,6 +2637,11 @@ private void startAltTransportTimer() {
if (Looper.myLooper() == null) {
Looper.prepare();
}

if (altTransportTimerHandler != null && altTransportTimerRunnable != null) {
altTransportTimerHandler.removeCallbacks(altTransportTimerRunnable);
}

altTransportTimerHandler = new Handler(Looper.myLooper());
altTransportTimerRunnable = new Runnable() {
public void run() {
Expand Down

0 comments on commit a624a06

Please sign in to comment.