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

Delay shutting down secondary transport when device app is backgrounded #1617

Merged

Conversation

NicoleYarroch
Copy link
Contributor

@NicoleYarroch NicoleYarroch commented Apr 3, 2020

Fixes #1560

This PR is ready for review.

Risk

This PR makes no API changes.

Testing Plan

  • I have verified that I have not introduced new warnings in this PR (or explain why below)
  • I have run the unit tests with this PR
  • I have tested this PR against Core and verified behavior (if applicable, if not applicable, explain why below).

Unit Tests

Unit tests were added to the SecondaryTransportManagerSpec.

Core Tests

Tests were performed with a video streaming app using a TCP secondary transport. Tests were considered successful:

  1. If the background task did not expire before the app was foregrounded then video resumed and audio continued without interruption.
  2. If the the background task expired while the app was backgrounded, then when the app was brought back to the foreground video and audio resumed.
Tests Performed
  1. Put app on device in the background and brought app on device back to foreground before background task expired.
  2. Put app on device in the background and brought app on device back to foreground after the background task expired.
  3. Put app on device in the background and then locked the device. Unlocked the device before the background task expired and foregrounded the app.
  4. Put app on device in the background and then locked the device. Waited for the background task to expire. Unlocked the device and foregrounded the app.
  5. Put app on device in the background and then locked the device. Waited for the background task to expire. Attempted to launch the SDL app while the device was still locked, the attempting to connect alert shows up. Unlocked the device and foregrounded the app.
  6. Locked the device while the app on the device was still in foreground. Unlocked the device.
  7. Put app on device in background, opened another SDL video streaming app, then switched back to the app and brought it back to the foreground.

Core version / branch / commit hash / module tested against: SYNC 4 (20016_DEVTEST)
HMI name / version / branch / commit hash / module tested against: SYNC 4 (20016_DEVTEST)

Summary

When the app on the device is backgrounded the secondary transport is now closed when the background task expires instead of immediately. This improves user experience by:

  1. Avoiding a reconnect delay if the user backgrounds the app and then foregrounds the app within the time the background task is kept alive (~1 minute).
  2. Showing the videoStreamBackgroundString when the app on the device is backgrounded. Previously the warning message was either flashed for a moment or not shown all.

In order to ensure that the video, audio and tcp transports are all shutdown before the background task is ended, I moved calling the videoServiceEndedCompletionHandler and the audioServiceEndedCompletionHandler from the stop service ACK and NAK handler methods to the stopped state of the SDLStreamingVideoLifecycleManager and SDLStreamingAudioLifecycleManager to ensure that both managers' properties get reset before the background task ends when the app is backgrounded. This also reduced duplicate code since both the ACK/NAK handlers transition to the stopped state anyways.

Changelog

Enhancements
  • When the app on the device is backgrounded the secondary transport is now closed when the background task expires instead of immediately.

CLA

The secondary transport now only shuts down when the background task expires.
@NicoleYarroch NicoleYarroch added best practice Not a defect but something that should be improved anyway transport-secondary Relating to the secondary transport labels Apr 3, 2020
@NicoleYarroch NicoleYarroch self-assigned this Apr 3, 2020
@NicoleYarroch NicoleYarroch added this to In progress in v6.6.0 via automation Apr 3, 2020
Added background task ended tests to secondary transport manager unit tests
@NicoleYarroch NicoleYarroch changed the title WIP: Delay shutting down secondary transport when device app is backgrounded Delay shutting down secondary transport when device app is backgrounded Apr 6, 2020
SmartDeviceLink/SDLBackgroundTaskManager.m Outdated Show resolved Hide resolved
SmartDeviceLink/SDLBackgroundTaskManager.m Outdated Show resolved Hide resolved
SmartDeviceLink/SDLBackgroundTaskManager.m Outdated Show resolved Hide resolved
SmartDeviceLink/SDLSecondaryTransportManager.m Outdated Show resolved Hide resolved
SmartDeviceLink/SDLSecondaryTransportManager.m Outdated Show resolved Hide resolved
SmartDeviceLink/SDLSecondaryTransportManager.m Outdated Show resolved Hide resolved
SmartDeviceLink/SDLSecondaryTransportManager.m Outdated Show resolved Hide resolved
SmartDeviceLink/SDLSecondaryTransportManager.m Outdated Show resolved Hide resolved
v6.6.0 automation moved this from In progress to Waiting for Review Apr 7, 2020
NicoleYarroch and others added 4 commits April 8, 2020 07:45
Co-Authored-By: Joel Fischer <joeljfischer@gmail.com>
The secondary transport background task is now only destroyed after cleanup finishes
@NicoleYarroch NicoleYarroch marked this pull request as draft April 9, 2020 16:57
@NicoleYarroch NicoleYarroch marked this pull request as ready for review April 9, 2020 17:32
Copy link
Contributor

@joeljfischer joeljfischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing, I saw a few more issues:

  1. I consistently saw a background task ended that was unknown:
2020-04-14 14:44:03.388147-0400 SDL Example[1175:377941] Can't end BackgroundTask: no background task exists with identifier 3 (0x3), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.

It doesn't seem to be causing an issue, but it does make me a bit suspicious.

SmartDeviceLink/SDLBackgroundTaskManager.h Outdated Show resolved Hide resolved
SmartDeviceLink/SDLBackgroundTaskManager.h Show resolved Hide resolved
SmartDeviceLink/SDLBackgroundTaskManager.m Outdated Show resolved Hide resolved
SmartDeviceLink/SDLBackgroundTaskManager.m Outdated Show resolved Hide resolved
SmartDeviceLink/SDLSecondaryTransportManager.m Outdated Show resolved Hide resolved
NicoleYarroch and others added 5 commits April 14, 2020 15:07
@NicoleYarroch
Copy link
Contributor Author

While testing, I saw a few more issues:

  1. I consistently saw a background task ended that was unknown:
2020-04-14 14:44:03.388147-0400 SDL Example[1175:377941] Can't end BackgroundTask: no background task exists with identifier 3 (0x3), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.

It doesn't seem to be causing an issue, but it does make me a bit suspicious.

I saw the same notifications and it seems to be a known iOS 13 issue. I created an empty single-view Swift app and I get the exact same log Can't end BackgroundTask: no background task exists with identifier 2 (0x2), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug. every time I foreground the app after backgrounding it.

Copy link
Contributor

@joeljfischer joeljfischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see the remaining request for comment addition.

v6.6.0 automation moved this from Waiting for Review to Reviewer approved Apr 15, 2020
@joeljfischer joeljfischer merged commit 5e01d37 into develop Apr 15, 2020
v6.6.0 automation moved this from Reviewer approved to Done Apr 15, 2020
@joeljfischer joeljfischer deleted the bugfix/issue_1560_delay_shutting_down_secondary_transport branch April 15, 2020 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
best practice Not a defect but something that should be improved anyway transport-secondary Relating to the secondary transport
Projects
No open projects
v6.6.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants