summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Gluck <justin.gluck@livio.io>2020-02-04 14:37:11 -0500
committerJustin Gluck <justin.gluck@livio.io>2020-02-04 14:37:11 -0500
commitd04c9c8ff88eb4bff609766908ec70f882e8d891 (patch)
tree96ad3ff3f988063cecc7af4b22ee5b56c15d1b53
parent5fd19255bac278dc268cc602ed4bf219df106db0 (diff)
downloadsdl_ios-d04c9c8ff88eb4bff609766908ec70f882e8d891.tar.gz
setting a new bool to wait till the app is full to connect the secondary transport to save battery life.
-rw-r--r--SmartDeviceLink/SDLLifecycleManager.m11
-rw-r--r--SmartDeviceLink/SDLSecondaryTransportManager.m29
2 files changed, 31 insertions, 9 deletions
diff --git a/SmartDeviceLink/SDLLifecycleManager.m b/SmartDeviceLink/SDLLifecycleManager.m
index 53f2059ac..dfe18d397 100644
--- a/SmartDeviceLink/SDLLifecycleManager.m
+++ b/SmartDeviceLink/SDLLifecycleManager.m
@@ -161,7 +161,7 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask
// Notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(transportDidConnect) name:SDLTransportDidConnect object:_notificationDispatcher];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(transportDidDisconnect) name:SDLTransportDidDisconnect object:_notificationDispatcher];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hmiStatusDidChange:) name:SDLDidChangeHMIStatusNotification object:_notificationDispatcher];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hmiStatusDidChange:) name:SDLDidChangeHMIStatusNotification object: _notificationDispatcher];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(remoteHardwareDidUnregister:) name:SDLDidReceiveAppUnregisteredNotification object:_notificationDispatcher];
_backgroundTaskManager = [[SDLBackgroundTaskManager alloc] initWithBackgroundTaskName: BackgroundTaskTransportName];
@@ -244,8 +244,13 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask
} else if (self.configuration.lifecycleConfig.allowedSecondaryTransports == SDLSecondaryTransportsNone) {
self.proxy = [SDLProxy iapProxyWithListener:self.notificationDispatcher secondaryTransportManager:nil encryptionLifecycleManager:self.encryptionLifecycleManager];
} else {
- // We reuse our queue to run secondary transport manager's state machine
- self.secondaryTransportManager = [[SDLSecondaryTransportManager alloc] initWithStreamingProtocolDelegate:self serialQueue:self.lifecycleQueue];
+ if([self.configuration.lifecycleConfig.appType isEqualToEnum:SDLAppHMITypeNavigation] ||
+ [self.configuration.lifecycleConfig.appType isEqualToEnum:SDLAppHMITypeProjection] ||
+ [self.configuration.lifecycleConfig.additionalAppTypes containsObject:SDLAppHMITypeNavigation] ||
+ [self.configuration.lifecycleConfig.additionalAppTypes containsObject:SDLAppHMITypeProjection]) {
+ // We reuse our queue to run secondary transport manager's state machine
+ self.secondaryTransportManager = [[SDLSecondaryTransportManager alloc] initWithStreamingProtocolDelegate:self serialQueue:self.lifecycleQueue];
+ }
self.proxy = [SDLProxy iapProxyWithListener:self.notificationDispatcher secondaryTransportManager:self.secondaryTransportManager encryptionLifecycleManager:self.encryptionLifecycleManager];
}
#pragma clang diagnostic pop
diff --git a/SmartDeviceLink/SDLSecondaryTransportManager.m b/SmartDeviceLink/SDLSecondaryTransportManager.m
index 860abcbaf..3bb74c25d 100644
--- a/SmartDeviceLink/SDLSecondaryTransportManager.m
+++ b/SmartDeviceLink/SDLSecondaryTransportManager.m
@@ -16,9 +16,11 @@
#import "SDLControlFramePayloadTransportEventUpdate.h"
#import "SDLIAPTransport.h"
#import "SDLLogMacros.h"
+#import "SDLOnHMIStatus.h"
#import "SDLProtocol.h"
#import "SDLProtocolHeader.h"
#import "SDLNotificationConstants.h"
+#import "SDLRPCNotificationNotification.h"
#import "SDLSecondaryTransportPrimaryProtocolHandler.h"
#import "SDLStateMachine.h"
#import "SDLTCPTransport.h"
@@ -98,6 +100,8 @@ static const int TCPPortUnspecified = -1;
// App is ready to set security manager to secondary protocol
@property (assign, nonatomic, getter=isAppReady) BOOL appReady;
+@property (assign, nonatomic) BOOL shouldOpenConnection;
+
@end
@implementation SDLSecondaryTransportManager
@@ -123,7 +127,8 @@ static const int TCPPortUnspecified = -1;
_tcpPort = TCPPortUnspecified;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBecomeReady) name:SDLDidBecomeReady object:nil];
-
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_hmiStatusDidChange:) name:SDLDidChangeHMIStatusNotification object:nil];
+
return self;
}
@@ -229,8 +234,8 @@ static const int TCPPortUnspecified = -1;
}
- (void)didEnterStateConfigured {
- if ((self.secondaryTransportType == SDLSecondaryTransportTypeTCP && [self sdl_isTCPReady] && self.isAppReady)
- || (self.secondaryTransportType == SDLSecondaryTransportTypeIAP && self.isAppReady)) {
+ if ((self.secondaryTransportType == SDLSecondaryTransportTypeTCP && [self sdl_isTCPReady] && self.isAppReady && self.shouldOpenConnection)
+ || (self.secondaryTransportType == SDLSecondaryTransportTypeIAP && self.isAppReady && self.shouldOpenConnection)) {
[self.stateMachine transitionToState:SDLSecondaryTransportStateConnecting];
}
}
@@ -372,7 +377,7 @@ static const int TCPPortUnspecified = -1;
return;
}
- if ([self.stateMachine isCurrentState:SDLSecondaryTransportStateConfigured] && [self sdl_isTCPReady] && self.isAppReady) {
+ if ([self.stateMachine isCurrentState:SDLSecondaryTransportStateConfigured] && [self sdl_isTCPReady] && self.isAppReady && self.shouldOpenConnection) {
[self.stateMachine transitionToState:SDLSecondaryTransportStateConnecting];
} else if ([self sdl_isTransportOpened]) {
// Disconnect current transport. If the IP address is available then we will reconnect immediately.
@@ -656,7 +661,7 @@ static const int TCPPortUnspecified = -1;
}
} else if (notification.name == UIApplicationDidBecomeActiveNotification) {
if (([self.stateMachine isCurrentState:SDLSecondaryTransportStateConfigured])
- && self.secondaryTransportType == SDLSecondaryTransportTypeTCP && [self sdl_isTCPReady] && self.isAppReady) {
+ && self.secondaryTransportType == SDLSecondaryTransportTypeTCP && [self sdl_isTCPReady] && self.isAppReady && self.shouldOpenConnection) {
SDLLogD(@"Resuming TCP transport since the app becomes foreground");
[self.stateMachine transitionToState:SDLSecondaryTransportStateConnecting];
}
@@ -715,12 +720,24 @@ static const int TCPPortUnspecified = -1;
- (void)appDidBecomeReady {
self.appReady = YES;
- if (([self.stateMachine.currentState isEqualToString:SDLSecondaryTransportStateConfigured] && self.tcpPort != SDLControlFrameInt32NotFound && self.ipAddress != nil)
+ if (([self.stateMachine.currentState isEqualToString:SDLSecondaryTransportStateConfigured] && self.tcpPort != SDLControlFrameInt32NotFound && self.ipAddress != nil && self.shouldOpenConnection)
|| self.secondaryTransportType == SDLSecondaryTransportTypeIAP) {
[self.stateMachine transitionToState:SDLSecondaryTransportStateConnecting];
}
}
+- (void)sdl_hmiStatusDidChange:(SDLRPCNotificationNotification *)notification {
+ if (![notification isNotificationMemberOfClass:[SDLOnHMIStatus class]]) {
+ return;
+ }
+
+ SDLOnHMIStatus *hmiStatusNotification = notification.notification;
+ if(![hmiStatusNotification.hmiLevel isEqualToEnum:SDLHMILevelNone]) {
+ self.shouldOpenConnection = true;
+ [self.stateMachine transitionToState:SDLSecondaryTransportStateConfigured];
+ }
+}
+
@end
NS_ASSUME_NONNULL_END