Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/rs notification issue usb #1797

Merged
merged 4 commits into from
Mar 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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