diff options
author | NicoleYarroch <nicole@livio.io> | 2019-04-15 13:57:44 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2019-04-15 13:57:44 -0400 |
commit | 7b8396f2823d1503d32d6f8832a32dd44f4be037 (patch) | |
tree | 83cb7350c6fbec1944b45bdcf2b31db706be3519 | |
parent | 6ce0eae0a9a73e9cbd535c3d49c29352e6494ba1 (diff) | |
download | sdl_ios-bugfix/issue_1224_audio_service_stopped_in_background.tar.gz |
Removed `currentAppState` logic from Audio Managerbugfix/issue_1224_audio_service_stopped_in_background
PCM audio can now stream in background
* SDLStreamingAudioLifecycleManager no longer monitors the `currentAppState` as audio can stream when app is backgrounded
* Removed logic setting the `currentAppState`
* Updated SDLStreamingAudioLifecycleManager test cases
3 files changed, 3 insertions, 58 deletions
diff --git a/SmartDeviceLink/SDLStreamingAudioLifecycleManager.h b/SmartDeviceLink/SDLStreamingAudioLifecycleManager.h index 3b9fdfae3..0ec3cc5bf 100644 --- a/SmartDeviceLink/SDLStreamingAudioLifecycleManager.h +++ b/SmartDeviceLink/SDLStreamingAudioLifecycleManager.h @@ -31,7 +31,6 @@ NS_ASSUME_NONNULL_BEGIN @property (strong, nonatomic, readonly) SDLAudioStreamManagerState *currentAudioStreamState; @property (strong, nonatomic, readonly) SDLStateMachine *appStateMachine; -@property (strong, nonatomic, readonly) SDLAppState *currentAppState; @property (copy, nonatomic, nullable) SDLHMILevel hmiLevel; diff --git a/SmartDeviceLink/SDLStreamingAudioLifecycleManager.m b/SmartDeviceLink/SDLStreamingAudioLifecycleManager.m index 3a2404ca9..cabf367cc 100644 --- a/SmartDeviceLink/SDLStreamingAudioLifecycleManager.m +++ b/SmartDeviceLink/SDLStreamingAudioLifecycleManager.m @@ -32,7 +32,6 @@ NS_ASSUME_NONNULL_BEGIN @interface SDLStreamingAudioLifecycleManager() -@property (strong, nonatomic, readwrite) SDLStateMachine *appStateMachine; @property (strong, nonatomic, readwrite) SDLStateMachine *audioStreamStateMachine; @property (assign, nonatomic, readonly, getter=isHmiStateAudioStreamCapable) BOOL hmiStateAudioStreamCapable; @@ -66,27 +65,11 @@ NS_ASSUME_NONNULL_BEGIN } _secureMakes = [tempMakeArray copy]; - SDLAppState *initialState = SDLAppStateInactive; - switch ([[UIApplication sharedApplication] applicationState]) { - case UIApplicationStateActive: { - initialState = SDLAppStateActive; - } break; - case UIApplicationStateInactive: // fallthrough - case UIApplicationStateBackground: { - initialState = SDLAppStateInactive; - } break; - default: break; - } - - _appStateMachine = [[SDLStateMachine alloc] initWithTarget:self initialState:initialState states:[self.class sdl_appStateTransitionDictionary]]; _audioStreamStateMachine = [[SDLStateMachine alloc] initWithTarget:self initialState:SDLAudioStreamManagerStateStopped states:[self.class sdl_audioStreamingStateTransitionDictionary]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_didReceiveRegisterAppInterfaceResponse:) name:SDLDidReceiveRegisterAppInterfaceResponse object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_hmiLevelDidChange:) name:SDLDidChangeHMIStatusNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_appStateDidUpdate:) name:UIApplicationDidBecomeActiveNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_appStateDidUpdate:) name:UIApplicationWillResignActiveNotification object:nil]; - return self; } @@ -132,46 +115,11 @@ NS_ASSUME_NONNULL_BEGIN return [self.audioStreamStateMachine isCurrentState:SDLAudioStreamManagerStateReady]; } -- (SDLAppState *)currentAppState { - return self.appStateMachine.currentState; -} - - (SDLAudioStreamManagerState *)currentAudioStreamState { return self.audioStreamStateMachine.currentState; } -#pragma mark - State Machines -#pragma mark App State -+ (NSDictionary<SDLState *, SDLAllowableStateTransitions *> *)sdl_appStateTransitionDictionary { - return @{ - // Will go from Inactive to Active if coming from a Phone Call. - // Will go from Inactive to IsRegainingActive if coming from Background. - SDLAppStateInactive : @[SDLAppStateActive], - SDLAppStateActive : @[SDLAppStateInactive] - }; -} - -- (void)sdl_appStateDidUpdate:(NSNotification*)notification { - if (notification.name == UIApplicationWillResignActiveNotification) { - [self.appStateMachine transitionToState:SDLAppStateInactive]; - } else if (notification.name == UIApplicationDidBecomeActiveNotification) { - [self.appStateMachine transitionToState:SDLAppStateActive]; - } -} - -- (void)didEnterStateAppInactive { - SDLLogD(@"App became inactive"); - [self sdl_stopAudioSession]; -} - -// Per Apple's guidelines: https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StrategiesforHandlingAppStateTransitions/StrategiesforHandlingAppStateTransitions.html -// We should be waiting to start any OpenGL drawing until UIApplicationDidBecomeActive is called. -- (void)didEnterStateAppActive { - SDLLogD(@"App became active"); - [self sdl_startAudioSession]; -} - -#pragma mark Audio +#pragma mark - State Machine + (NSDictionary<SDLState *, SDLAllowableStateTransitions *> *)sdl_audioStreamingStateTransitionDictionary { return @{ SDLAudioStreamManagerStateStopped : @[SDLAudioStreamManagerStateStarting], diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingAudioLifecycleManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingAudioLifecycleManagerSpec.m index af2317ca9..dd445714e 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingAudioLifecycleManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingAudioLifecycleManagerSpec.m @@ -46,7 +46,6 @@ describe(@"the streaming audio manager", ^{ expect(@(streamingLifecycleManager.isAudioConnected)).to(equal(@NO)); expect(@(streamingLifecycleManager.isAudioEncrypted)).to(equal(@NO)); expect(@(streamingLifecycleManager.requestedEncryptionType)).to(equal(@(SDLStreamingEncryptionFlagNone))); - expect(streamingLifecycleManager.currentAppState).to(equal(SDLAppStateActive)); expect(streamingLifecycleManager.currentAudioStreamState).to(equal(SDLAudioStreamManagerStateStopped)); }); @@ -67,7 +66,6 @@ describe(@"the streaming audio manager", ^{ expect(@(streamingLifecycleManager.isStreamingSupported)).to(equal(@NO)); expect(@(streamingLifecycleManager.isAudioConnected)).to(equal(@NO)); expect(@(streamingLifecycleManager.isAudioEncrypted)).to(equal(@NO)); - expect(streamingLifecycleManager.currentAppState).to(equal(SDLAppStateActive)); expect(streamingLifecycleManager.currentAudioStreamState).to(match(SDLAudioStreamManagerStateStopped)); }); @@ -196,8 +194,8 @@ describe(@"the streaming audio manager", ^{ [streamingLifecycleManager.appStateMachine setToState:SDLAppStateInactive fromOldState:nil callEnterTransition:YES]; }); - it(@"should suspend the video stream", ^{ - expect(streamingLifecycleManager.currentAudioStreamState).to(equal(SDLAudioStreamManagerStateShuttingDown)); + it(@"should not close the stream", ^{ + expect(streamingLifecycleManager.currentAudioStreamState).to(equal(SDLAudioStreamManagerStateReady)); }); }); }); |