summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2020-07-08 14:33:52 -0400
committerJoel Fischer <joeljfischer@gmail.com>2020-07-08 14:33:52 -0400
commiteb8a991078f0b0accd6fc807a2a5ec42f29aac45 (patch)
tree9c73cb58eee5cfab596574aa3ebb727dc47d7a41
parent7e0953e80b94b950d10380240fd5e17be9e6239c (diff)
downloadsdl_ios-eb8a991078f0b0accd6fc807a2a5ec42f29aac45.tar.gz
* Add additional documentation to the permission element parameterPermissions param * Fix some internal methods receiving mutable dictionaries when they should be receiving immutable dictionaries * Fix public SDLRPCPermissionStatus method using a private SDLRPCParameterName enum * Fix SDLRPCPermissionStatus initializer implementation not matching the declaration * Update SDLRPCPermissionStatus description
-rw-r--r--Example Apps/Example Swift/RPCPermissionsManager.swift34
-rw-r--r--SmartDeviceLink/SDLPermissionElement.h2
-rw-r--r--SmartDeviceLink/SDLPermissionManager.m6
-rw-r--r--SmartDeviceLink/SDLRPCPermissionStatus.h2
-rw-r--r--SmartDeviceLink/SDLRPCPermissionStatus.m4
5 files changed, 24 insertions, 24 deletions
diff --git a/Example Apps/Example Swift/RPCPermissionsManager.swift b/Example Apps/Example Swift/RPCPermissionsManager.swift
index 5bae10572..9a320247a 100644
--- a/Example Apps/Example Swift/RPCPermissionsManager.swift
+++ b/Example Apps/Example Swift/RPCPermissionsManager.swift
@@ -24,19 +24,19 @@ class RPCPermissionsManager {
let createInteractionPermissionElement = SDLPermissionElement(rpcName: SDLRPCFunctionName.createInteractionChoiceSet, parameterPermissions: nil)
let performInteractionPermissionElement = SDLPermissionElement(rpcName: SDLRPCFunctionName.performInteraction, parameterPermissions: nil)
let menuRPCPermissions = [addCommandPermissionElement, createInteractionPermissionElement, performInteractionPermissionElement]
- _ = checkCurrentGroupPermissions(with: manager, rpcNames: menuRPCNames)
+ _ = checkCurrentGroupPermissions(with: manager, permissionElements: menuRPCPermissions)
// Set up an observer for permissions changes to media template releated RPCs. Since the `groupType` is set to all allowed, this block is called when the group permissions changes from all allowed. This block is called immediately when created.
let setMediaClockPermissionElement = SDLPermissionElement(rpcName: SDLRPCFunctionName.setMediaClockTimer, parameterPermissions: nil)
let subscribeButtonPermissionElement = SDLPermissionElement(rpcName: SDLRPCFunctionName.subscribeButton, parameterPermissions: nil)
let mediaTemplatePermissions = [setMediaClockPermissionElement, subscribeButtonPermissionElement]
- let allAllowedObserverId = subscribeGroupPermissions(with: manager, rpcNames: mediaTemplateRPCs, groupType: .allAllowed)
+ let allAllowedObserverId = subscribeGroupPermissions(with: manager, permissionElements: mediaTemplatePermissions, groupType: .allAllowed)
// Stop observing permissions changes for the media template releated RPCs
unsubscribeGroupPermissions(with: manager, observerId: allAllowedObserverId)
// Sets up a block for observing permission changes for a group of RPCs. Since the `groupType` is set to any, this block is called when the permission status changes for any of the RPCs being observed. This block is called immediately when created.
- _ = subscribeGroupPermissions(with: manager, rpcNames: mediaTemplateRPCs, groupType: .any)
+ _ = subscribeGroupPermissions(with: manager, permissionElements: mediaTemplatePermissions, groupType: .any)
}
/// Checks if the `DialNumber` RPC is allowed
@@ -58,7 +58,7 @@ private extension RPCPermissionsManager {
/// - Returns: true if allowed, false if not
class func checkCurrentPermission(with manager: SDLManager, rpcName: SDLRPCFunctionName) -> Bool {
let isRPCAllowed = manager.permissionManager.isRPCNameAllowed(rpcName)
- logRPCPermission(rpcName: rpcName, isRPCAllowed: isRPCAllowed)
+ SDLLog.d("\(rpcName.rawValue.rawValue) RPC can be sent to SDL Core? \(isRPCAllowed ? "YES" : "NO")")
return isRPCAllowed
}
@@ -66,10 +66,10 @@ private extension RPCPermissionsManager {
///
/// - Parameter manager: The SDL Manager
/// - Returns: The rpc names, the group permission status and the permission status for each rpc in the group
- class func checkCurrentGroupPermissions(with manager: SDLManager, rpcNames: [SDLPermissionElement]) -> SDLPermissionGroupStatus {
- let groupPermissionStatus = manager.permissionManager.groupStatus(ofRPCNames: rpcNames)
- let individualPermissionStatuses = manager.permissionManager.statuses(ofRPCNames: rpcNames)
- logRPCGroupPermissions(rpcNames: rpcNames, groupPermissionStatus: groupPermissionStatus, individualPermissionStatuses: individualPermissionStatuses)
+ class func checkCurrentGroupPermissions(with manager: SDLManager, permissionElements: [SDLPermissionElement]) -> SDLPermissionGroupStatus {
+ let groupPermissionStatus = manager.permissionManager.groupStatus(ofRPCPermissions: permissionElements)
+ let individualPermissionStatuses = manager.permissionManager.statuses(ofRPCPermissions: permissionElements)
+ logRPCGroupPermissions(permissionElements: permissionElements, groupPermissionStatus: groupPermissionStatus, individualPermissionStatuses: individualPermissionStatuses)
return groupPermissionStatus
}
@@ -79,9 +79,9 @@ private extension RPCPermissionsManager {
/// - manager: The SDL Manager
/// - groupType: The type of changes to get notified about
/// - Returns: A unique id assigned to observer. Use the id to unsubscribe to notifications
- class func subscribeGroupPermissions(with manager: SDLManager, rpcNames: [SDLPermissionElement], groupType: SDLPermissionGroupType) -> UUID {
- let permissionAllAllowedObserverId = manager.permissionManager.subscribe(toRPCNames: rpcNames, groupType: groupType, withHandler: { (individualStatuses, groupStatus) in
- self.logRPCGroupPermissions(rpcNames: rpcNames, groupPermissionStatus: groupStatus, individualPermissionStatuses: individualStatuses)
+ class func subscribeGroupPermissions(with manager: SDLManager, permissionElements: [SDLPermissionElement], groupType: SDLPermissionGroupType) -> UUID {
+ let permissionAllAllowedObserverId = manager.permissionManager.subscribe(toRPCPermissions: permissionElements, groupType: groupType, withHandler: { (individualStatuses, groupStatus) in
+ self.logRPCGroupPermissions(permissionElements: permissionElements, groupPermissionStatus: groupStatus, individualPermissionStatuses: individualStatuses)
})
return permissionAllAllowedObserverId
@@ -105,8 +105,8 @@ private extension RPCPermissionsManager {
/// - Parameters:
/// - rpcName: The name of the RPC
/// - isRPCAllowed: The permission status for the RPC
- class func logRPCPermission(rpcName: SDLRPCFunctionName, isRPCAllowed: Bool) {
- SDLLog.d("\(rpcName.rawValue.rawValue) RPC can be sent to SDL Core? \(isRPCAllowed ? "yes" : "no")")
+ class func logRPCPermission(status: SDLRPCPermissionStatus) {
+ SDLLog.d("\(status.rpcName.rawValue.rawValue) RPC can be sent to SDL Core? \(status.isRPCAllowed ? "YES" : "NO"), parameters: \(status.rpcParameters ?? [:])")
}
/// Logs permissions for a group of RPCs
@@ -115,10 +115,10 @@ private extension RPCPermissionsManager {
/// - rpcNames: The names of the RPCs
/// - groupPermissionStatus: The permission status for all RPCs in the group
/// - individualPermissionStatuses: The permission status for each of the RPCs in the group
- class func logRPCGroupPermissions(rpcNames: [SDLPermissionElement], groupPermissionStatus: SDLPermissionGroupStatus, individualPermissionStatuses: [SDLRPCFunctionName:SDLRPCPermissionStatus]) {
- SDLLog.d("The group status for \(rpcNames.map { $0.rpcName.rawValue } ) has changed to: \(groupPermissionStatus.rawValue)")
- for (rpcName, rpcAllowed) in individualPermissionStatuses {
- logRPCPermission(rpcName: rpcName, isRPCAllowed: rpcAllowed.isRPCAllowed)
+ class func logRPCGroupPermissions(permissionElements: [SDLPermissionElement], groupPermissionStatus: SDLPermissionGroupStatus, individualPermissionStatuses: [SDLRPCFunctionName: SDLRPCPermissionStatus]) {
+ SDLLog.d("The group status for \(permissionElements.map { $0.rpcName.rawValue } ) has changed to: \(groupPermissionStatus.rawValue)")
+ for (_, status) in individualPermissionStatuses {
+ logRPCPermission(status: status)
}
}
}
diff --git a/SmartDeviceLink/SDLPermissionElement.h b/SmartDeviceLink/SDLPermissionElement.h
index 7ab2d3b52..5f3ca5c23 100644
--- a/SmartDeviceLink/SDLPermissionElement.h
+++ b/SmartDeviceLink/SDLPermissionElement.h
@@ -30,7 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
* Creates a new permission element.
*
* @param rpcName The name of the RPC.
- * @param parameterPermissions An array parameters for the RPC.
+ * @param parameterPermissions An array parameters for the RPC that should be checked if they are allowed. Note that not all head units may provide this data. If no parameter data is received, we assume that the parameter is not allowed.
*
* @return An instance of `SDLPermissionElement`.
*/
diff --git a/SmartDeviceLink/SDLPermissionManager.m b/SmartDeviceLink/SDLPermissionManager.m
index d91beb6b7..aa9f14bf0 100644
--- a/SmartDeviceLink/SDLPermissionManager.m
+++ b/SmartDeviceLink/SDLPermissionManager.m
@@ -74,7 +74,7 @@ NS_ASSUME_NONNULL_BEGIN
return [self.class isRPCNameAllowed:rpcName permissions:self.permissions hmiLevel:self.currentHMILevel];
}
-+ (BOOL)isRPCNameAllowed:(SDLRPCFunctionName)rpcName permissions:(NSMutableDictionary<SDLPermissionRPCName, SDLPermissionItem *> *)permissions hmiLevel:(SDLHMILevel)hmiLevel {
++ (BOOL)isRPCNameAllowed:(SDLRPCFunctionName)rpcName permissions:(NSDictionary<SDLPermissionRPCName, SDLPermissionItem *> *)permissions hmiLevel:(SDLHMILevel)hmiLevel {
if (permissions[rpcName] == nil || hmiLevel == nil) {
return NO;
}
@@ -95,7 +95,7 @@ NS_ASSUME_NONNULL_BEGIN
return [self.class sdl_groupStatusOfRPCPermissions:rpcNames withPermissions:[self.permissions copy] hmiLevel:self.currentHMILevel];
}
-+ (SDLPermissionGroupStatus)sdl_groupStatusOfRPCPermissions:(NSArray<SDLPermissionElement *> *)rpcNames withPermissions:(NSMutableDictionary<SDLPermissionRPCName, SDLPermissionItem *> *)permissions hmiLevel:(SDLHMILevel)hmiLevel {
++ (SDLPermissionGroupStatus)sdl_groupStatusOfRPCPermissions:(NSArray<SDLPermissionElement *> *)rpcNames withPermissions:(NSDictionary<SDLPermissionRPCName, SDLPermissionItem *> *)permissions hmiLevel:(SDLHMILevel)hmiLevel {
// If we don't have an HMI level, then just say everything is disallowed
if (hmiLevel == nil) {
return SDLPermissionGroupStatusUnknown;
@@ -477,7 +477,7 @@ NS_ASSUME_NONNULL_BEGIN
return [self.class sdl_isPermissionParameterAllowed:rpcName parameter:parameter permissionItems:self.permissions hmiLevel:self.currentHMILevel];
}
-+ (BOOL)sdl_isPermissionParameterAllowed:(SDLRPCFunctionName)rpcName parameter:(NSString *)parameter permissionItems:(NSMutableDictionary<SDLPermissionRPCName, SDLPermissionItem *> *)permissionItems hmiLevel:(SDLHMILevel)hmiLevel {
++ (BOOL)sdl_isPermissionParameterAllowed:(SDLRPCFunctionName)rpcName parameter:(NSString *)parameter permissionItems:(NSDictionary<SDLPermissionRPCName, SDLPermissionItem *> *)permissionItems hmiLevel:(SDLHMILevel)hmiLevel {
SDLPermissionItem *permissionItem = permissionItems[rpcName];
if (permissionItem == nil || ![self isRPCNameAllowed:rpcName permissions:permissionItems hmiLevel:hmiLevel] || permissionItem.parameterPermissions == nil || permissionItem.parameterPermissions.allowed == nil) {
return NO;
diff --git a/SmartDeviceLink/SDLRPCPermissionStatus.h b/SmartDeviceLink/SDLRPCPermissionStatus.h
index d672f5207..34a6ad8e1 100644
--- a/SmartDeviceLink/SDLRPCPermissionStatus.h
+++ b/SmartDeviceLink/SDLRPCPermissionStatus.h
@@ -30,7 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Holds a dictionary of RPC parameters and objects of an NSNumber<BOOL> specifying if that RPC parameter is currently allowed
*/
-@property (strong, nonatomic, nullable, readonly) NSDictionary<SDLRPCParameterName, NSNumber *> *rpcParameters;
+@property (strong, nonatomic, nullable, readonly) NSDictionary<NSString *, NSNumber *> *rpcParameters;
/**
* Initializes a SDLRPCPermissionStatus object.
diff --git a/SmartDeviceLink/SDLRPCPermissionStatus.m b/SmartDeviceLink/SDLRPCPermissionStatus.m
index eb3f3950b..892edefdb 100644
--- a/SmartDeviceLink/SDLRPCPermissionStatus.m
+++ b/SmartDeviceLink/SDLRPCPermissionStatus.m
@@ -10,7 +10,7 @@
@implementation SDLRPCPermissionStatus
-- (instancetype)initWithRPCName:(SDLRPCFunctionName)rpcName isRPCAllowed:(BOOL)isRPCAllowed rpcParameters:(nullable NSMutableDictionary<NSString *,NSNumber *> *)rpcParameters {
+- (instancetype)initWithRPCName:(SDLRPCFunctionName)rpcName isRPCAllowed:(BOOL)isRPCAllowed rpcParameters:(nullable NSDictionary<NSString *,NSNumber *> *)rpcParameters {
self = [super init];
if (!self) { return nil; }
@@ -24,7 +24,7 @@
#pragma mark - Description
- (NSString *)description {
- return [NSString stringWithFormat:@"RPC name: %@, allowed: %@, RPC parameters %@", self.rpcName, (self.isRPCAllowed ? @"YES" : @"NO"), self.rpcParameters];
+ return [NSString stringWithFormat:@"RPC Permission status, RPC name: %@, allowed: %@, RPC parameters %@", self.rpcName, (self.isRPCAllowed ? @"YES" : @"NO"), self.rpcParameters];
}
@end