diff options
-rw-r--r-- | SmartDeviceLink/SDLLifecycleManager.m | 21 | ||||
-rw-r--r-- | SmartDeviceLink/SDLPermissionManager.h | 10 | ||||
-rw-r--r-- | SmartDeviceLink/SDLPermissionManager.m | 17 | ||||
-rw-r--r-- | SmartDeviceLink/SDLProxy.m | 13 |
4 files changed, 39 insertions, 22 deletions
diff --git a/SmartDeviceLink/SDLLifecycleManager.m b/SmartDeviceLink/SDLLifecycleManager.m index cbf8d1a60..48bc466f9 100644 --- a/SmartDeviceLink/SDLLifecycleManager.m +++ b/SmartDeviceLink/SDLLifecycleManager.m @@ -141,7 +141,7 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask // Managers _fileManager = [[SDLFileManager alloc] initWithConnectionManager:self configuration:_configuration.fileManagerConfig]; - _permissionManager = [[SDLPermissionManager alloc] init]; + _permissionManager = [SDLPermissionManager sharedInstance]; _lockScreenManager = [[SDLLockScreenManager alloc] initWithConfiguration:_configuration.lockScreenConfig notificationDispatcher:_notificationDispatcher presenter:[[SDLLockScreenPresenter alloc] init]]; _screenManager = [[SDLScreenManager alloc] initWithConnectionManager:self fileManager:_fileManager]; _systemCapabilityManager = [[SDLSystemCapabilityManager alloc] initWithConnectionManager:self]; @@ -330,7 +330,7 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask // Send the request and depending on the response, post the notification __weak typeof(self) weakSelf = self; [self sdl_sendRequest:regRequest - requiresEncryption: [self sdl_requestRequiresEncryption:regRequest] + requiresEncryption: [self.permissionManager requestRequiresEncryption:regRequest] withResponseHandler:^(__kindof SDLRPCRequest *_Nullable request, __kindof SDLRPCResponse *_Nullable response, NSError *_Nullable error) { // If the success BOOL is NO or we received an error at this point, we failed. Call the ready handler and transition to the DISCONNECTED state. if (error != nil || ![response.success boolValue]) { @@ -525,7 +525,7 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask __weak typeof(self) weakSelf = self; [self sdl_sendRequest:unregisterRequest - requiresEncryption:[self sdl_requestRequiresEncryption:unregisterRequest] + requiresEncryption:[self.permissionManager requestRequiresEncryption:unregisterRequest] withResponseHandler:^(__kindof SDLRPCRequest *_Nullable request, __kindof SDLRPCResponse *_Nullable response, NSError *_Nullable error) { if (error != nil || ![response.success boolValue]) { SDLLogE(@"SDL Error unregistering, we are going to hard disconnect: %@, response: %@", error, response); @@ -562,7 +562,7 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask setAppIcon.syncFileName = appIcon.name; [self sdl_sendRequest:setAppIcon - requiresEncryption:[self sdl_requestRequiresEncryption:setAppIcon] + requiresEncryption:[self.permissionManager requestRequiresEncryption:setAppIcon] withResponseHandler:^(__kindof SDLRPCRequest *_Nullable request, __kindof SDLRPCResponse *_Nullable response, NSError *_Nullable error) { if (error != nil) { SDLLogW(@"Error setting up app icon: %@", error); @@ -633,7 +633,7 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask } dispatch_async(_lifecycleQueue, ^{ - [self sdl_sendRequest:rpc requiresEncryption:[self sdl_requestRequiresEncryption:rpc] withResponseHandler:nil]; + [self sdl_sendRequest:rpc requiresEncryption:[self.permissionManager requestRequiresEncryption:rpc] withResponseHandler:nil]; }); } @@ -648,7 +648,7 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask } dispatch_async(_lifecycleQueue, ^{ - if ([self sdl_requestRequiresEncryption:request] || encryption) { + if ([self.permissionManager requestRequiresEncryption:request] || encryption) { [self sdl_sendRequest:request requiresEncryption:YES withResponseHandler:handler]; } else { [self sdl_sendRequest:request requiresEncryption:NO withResponseHandler:handler]; @@ -659,7 +659,7 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask // Managers need to avoid state checking. Part of <SDLConnectionManagerType>. - (void)sendConnectionManagerRequest:(__kindof SDLRPCMessage *)request withResponseHandler:(nullable SDLResponseHandler)handler { dispatch_async(_lifecycleQueue, ^{ - [self sdl_sendRequest:request requiresEncryption:[self sdl_requestRequiresEncryption:request] withResponseHandler:handler]; + [self sdl_sendRequest:request requiresEncryption:[self.permissionManager requestRequiresEncryption:request] withResponseHandler:handler]; }); } @@ -740,13 +740,6 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask return self.proxy.protocol.authToken; } -- (BOOL)sdl_requestRequiresEncryption:(__kindof SDLRPCMessage *)request { - if (self.permissionManager.permissions[request.name].requireEncryption != nil) { - return self.permissionManager.permissions[request.name].requireEncryption.boolValue; - } - return NO; -} - #pragma mark SDL notification observers - (void)transportDidConnect { diff --git a/SmartDeviceLink/SDLPermissionManager.h b/SmartDeviceLink/SDLPermissionManager.h index 37bceeadf..ea3eae22d 100644 --- a/SmartDeviceLink/SDLPermissionManager.h +++ b/SmartDeviceLink/SDLPermissionManager.h @@ -10,6 +10,7 @@ #import "SDLHMILevel.h" #import "SDLPermissionConstants.h" +#import "SDLRPCMessage.h" @class SDLPermissionItem; @@ -19,6 +20,11 @@ NS_ASSUME_NONNULL_BEGIN @interface SDLPermissionManager : NSObject /** + * Shared instance of the manager. This method is used internally. + */ ++ (instancetype)sharedInstance; + +/** * Start the manager with a completion block that will be called when startup completes. This is used internally. To use an SDLPermissionManager, you should use the manager found on `SDLManager`. * * @param completionHandler The block to be called when the manager's setup is complete. @@ -90,9 +96,9 @@ NS_ASSUME_NONNULL_BEGIN @property (assign, nonatomic, readonly) BOOL requiresEncryption; /** - * Dictionary of RPC names and their permissions. + * Check whether or not an RPC needs encryption */ -@property (strong, nonatomic, readonly) NSMutableDictionary<SDLPermissionRPCName, SDLPermissionItem *> *permissions; +- (BOOL)requestRequiresEncryption:(__kindof SDLRPCMessage *)request; @end diff --git a/SmartDeviceLink/SDLPermissionManager.m b/SmartDeviceLink/SDLPermissionManager.m index d896753eb..beca8aedb 100644 --- a/SmartDeviceLink/SDLPermissionManager.m +++ b/SmartDeviceLink/SDLPermissionManager.m @@ -34,6 +34,15 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Lifecycle ++ (instancetype)sharedInstance { + static SDLPermissionManager *sharedInstace = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedInstace = [[SDLPermissionManager alloc] init]; + }); + return sharedInstace; +} + - (instancetype)init { self = [super init]; if (!self) { @@ -354,6 +363,14 @@ NS_ASSUME_NONNULL_BEGIN return [modifiedPermissions copy]; } + +- (BOOL)requestRequiresEncryption:(__kindof SDLRPCMessage *)request { + if (self.permissions[request.name].requireEncryption != nil) { + return self.permissions[request.name].requireEncryption.boolValue; + } + return NO; +} + @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink/SDLProxy.m b/SmartDeviceLink/SDLProxy.m index 366b3634d..6dada79b8 100644 --- a/SmartDeviceLink/SDLProxy.m +++ b/SmartDeviceLink/SDLProxy.m @@ -39,6 +39,7 @@ #import "SDLUnsubscribeButton.h" #import "SDLVehicleType.h" #import "SDLVersion.h" +#import "SDLPermissionManager.h" #import "SDLRPCParameterNames.h" #import "SDLRPCFunctionNames.h" @@ -174,7 +175,7 @@ static float DefaultConnectionTimeout = 45.0; } SDLLogD(@"Mobile UIApplication state changed, sending to remote system: %@", HMIStatusRPC.hmiLevel); - [self sendRPC:HMIStatusRPC withEncryption:NO]; + [self sendRPC:HMIStatusRPC withEncryption:[[SDLPermissionManager sharedInstance] requestRequiresEncryption:HMIStatusRPC]]; } #pragma mark - Accessors @@ -703,7 +704,7 @@ static float DefaultConnectionTimeout = 45.0; } // Send the RPC Request - [strongSelf sendRPC:request withEncryption:NO]; + [strongSelf sendRPC:request withEncryption:[[SDLPermissionManager sharedInstance] requestRequiresEncryption:request]]; }]; } @@ -738,7 +739,7 @@ static float DefaultConnectionTimeout = 45.0; SDLSystemRequest *iconURLSystemRequest = [[SDLSystemRequest alloc] initWithType:SDLRequestTypeIconURL fileName:request.url]; iconURLSystemRequest.bulkData = data; - [strongSelf sendRPC:iconURLSystemRequest withEncryption:NO]; + [strongSelf sendRPC:iconURLSystemRequest withEncryption:[[SDLPermissionManager sharedInstance] requestRequiresEncryption:iconURLSystemRequest]]; }]; } @@ -774,7 +775,7 @@ static float DefaultConnectionTimeout = 45.0; putFile.bulkData = data; // Send RPC Request - [strongSelf sendRPC:putFile withEncryption:NO]; + [strongSelf sendRPC:putFile withEncryption:[[SDLPermissionManager sharedInstance] requestRequiresEncryption:putFile]]; }]; } @@ -959,7 +960,7 @@ static float DefaultConnectionTimeout = 45.0; request.correlationID = [NSNumber numberWithInt:PoliciesCorrelationId]; request.data = [responseDictionary objectForKey:@"data"]; - [self sendRPC:request withEncryption:NO]; + [self sendRPC:request withEncryption:[[SDLPermissionManager sharedInstance] requestRequiresEncryption:request]]; } } @@ -992,7 +993,7 @@ static float DefaultConnectionTimeout = 45.0; [putFileRPCRequest setLength:[NSNumber numberWithUnsignedInteger:(NSUInteger)nBytesRead]]; [putFileRPCRequest setBulkData:data]; - [self sendRPC:putFileRPCRequest withEncryption:NO]; + [self sendRPC:putFileRPCRequest withEncryption:[[SDLPermissionManager sharedInstance] requestRequiresEncryption:putFileRPCRequest]]; } break; |