summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2020-06-12 10:22:35 -0400
committerGitHub <noreply@github.com>2020-06-12 10:22:35 -0400
commit5b5939a2b5c72176220e09d4243354e617efcab0 (patch)
tree59a9319954881dc2dc8a9667a253f5584b358518
parent7f033d7fe8d88e41de530c10d70c5f83b82a9309 (diff)
parent7f86e6966f2fa227bddc439c3711467b91160115 (diff)
downloadsdl_ios-5b5939a2b5c72176220e09d4243354e617efcab0.tar.gz
Merge pull request #1677 from smartdevicelink/bugfix/issue-1667-permission-manager-method-alignment
Bugfix/issue 1667 permission manager method alignment
-rw-r--r--Example Apps/Example ObjC/RPCPermissionsManager.m20
-rw-r--r--Example Apps/Example ObjC/VehicleDataManager.m3
-rw-r--r--Example Apps/Example Swift/RPCPermissionsManager.swift32
-rw-r--r--Example Apps/Example Swift/VehicleDataManager.swift2
-rw-r--r--SmartDeviceLink/SDLPermissionConstants.h9
-rw-r--r--SmartDeviceLink/SDLPermissionManager.h56
-rw-r--r--SmartDeviceLink/SDLPermissionManager.m45
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLPermissionsManagerSpec.m659
8 files changed, 584 insertions, 242 deletions
diff --git a/Example Apps/Example ObjC/RPCPermissionsManager.m b/Example Apps/Example ObjC/RPCPermissionsManager.m
index dc5cf6dfc..d79bde3e2 100644
--- a/Example Apps/Example ObjC/RPCPermissionsManager.m
+++ b/Example Apps/Example ObjC/RPCPermissionsManager.m
@@ -24,11 +24,11 @@ NS_ASSUME_NONNULL_BEGIN
[self sdlex_checkCurrentPermissionWithManager:manager rpcName:showRPCName];
// Checks if all the RPCs need to create menus are allowed right at this moment
- NSArray<NSString *> *menuRPCNames = @[@"AddCommand", @"CreateInteractionChoiceSet", @"PerformInteraction"];
+ NSArray<SDLRPCFunctionName> *menuRPCNames = @[SDLRPCFunctionNameAddCommand, SDLRPCFunctionNameCreateInteractionChoiceSet, SDLRPCFunctionNamePerformInteraction];
[self sdlex_checkCurrentGroupPermissionsWithManager:manager rpcNames:menuRPCNames];
// 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.
- NSArray<NSString *> *mediaTemplateRPCs = @[@"SetMediaClockTimer", @"SubscribeButton"];
+ NSArray<SDLRPCFunctionName> *mediaTemplateRPCs = @[SDLRPCFunctionNameSetMediaClockTimer, SDLRPCFunctionNameSubscribeButton];
SDLPermissionObserverIdentifier allAllowedObserverId = [self sdlex_subscribeGroupPermissionsWithManager:manager rpcNames:mediaTemplateRPCs groupType:SDLPermissionGroupTypeAllAllowed];
// Stop observing permissions changes for the media template releated RPCs
@@ -46,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (BOOL)isDialNumberRPCAllowedWithManager:(SDLManager *)manager {
SDLLogD(@"Checking if app has permission to dial a number");
- return [self sdlex_checkCurrentPermissionWithManager:manager rpcName:@"DialNumber"];
+ return [self sdlex_checkCurrentPermissionWithManager:manager rpcName:SDLRPCFunctionNameDialNumber];
}
#pragma mark - Check Permissions
@@ -60,8 +60,8 @@ NS_ASSUME_NONNULL_BEGIN
* @param rpcName The name of the RPC
* @return True if the RPC can be sent to Core right now, false if not
*/
-+ (BOOL)sdlex_checkCurrentPermissionWithManager:(SDLManager *)manager rpcName:(NSString *)rpcName {
- BOOL isRPCAllowed = [manager.permissionManager isRPCAllowed:rpcName];
++ (BOOL)sdlex_checkCurrentPermissionWithManager:(SDLManager *)manager rpcName:(SDLRPCFunctionName)rpcName {
+ BOOL isRPCAllowed = [manager.permissionManager isRPCNameAllowed:rpcName];
[self sdlex_logRPCPermission:rpcName isRPCAllowed:isRPCAllowed];
return isRPCAllowed;
}
@@ -73,9 +73,9 @@ NS_ASSUME_NONNULL_BEGIN
* @param rpcNames The names of the RPCs
* @return The current permission status for all the RPCs in the group
*/
-+ (SDLPermissionGroupStatus)sdlex_checkCurrentGroupPermissionsWithManager:(SDLManager *)manager rpcNames:(NSArray<NSString *> *)rpcNames {
- SDLPermissionGroupStatus groupPermissionStatus = [manager.permissionManager groupStatusOfRPCs:rpcNames];
- NSDictionary<NSString *, NSNumber *> *individualPermissionStatuses = [manager.permissionManager statusOfRPCs:rpcNames];
++ (SDLPermissionGroupStatus)sdlex_checkCurrentGroupPermissionsWithManager:(SDLManager *)manager rpcNames:(NSArray<SDLRPCFunctionName> *)rpcNames {
+ SDLPermissionGroupStatus groupPermissionStatus = [manager.permissionManager groupStatusOfRPCNames:rpcNames];
+ NSDictionary<NSString *, NSNumber *> *individualPermissionStatuses = [manager.permissionManager statusesOfRPCNames:rpcNames];
[self sdlex_logRPCGroupPermissions:rpcNames groupPermissionStatus:groupPermissionStatus individualPermissionStatuses:individualPermissionStatuses];
return groupPermissionStatus;
}
@@ -90,8 +90,8 @@ NS_ASSUME_NONNULL_BEGIN
* @param groupType The type of changes you want to be notified about for the group
* @return A unique identifier for the subscription. This can be used to later to unsubscribe from the notifications.
*/
-+ (SDLPermissionObserverIdentifier)sdlex_subscribeGroupPermissionsWithManager:(SDLManager *)manager rpcNames:(NSArray<NSString *> *)rpcNames groupType:(SDLPermissionGroupType)groupType {
- SDLPermissionObserverIdentifier observerId = [manager.permissionManager addObserverForRPCs:rpcNames groupType:groupType withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber<SDLBool> *> * _Nonnull change, SDLPermissionGroupStatus status) {
++ (SDLPermissionObserverIdentifier)sdlex_subscribeGroupPermissionsWithManager:(SDLManager *)manager rpcNames:(NSArray<SDLRPCFunctionName> *)rpcNames groupType:(SDLPermissionGroupType)groupType {
+ SDLPermissionObserverIdentifier observerId = [manager.permissionManager subscribeToRPCNames:rpcNames groupType:groupType withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber<SDLBool> *> * _Nonnull change, SDLPermissionGroupStatus status) {
[self sdlex_logRPCGroupPermissions:rpcNames groupPermissionStatus:status individualPermissionStatuses:change];
}];
return observerId;
diff --git a/Example Apps/Example ObjC/VehicleDataManager.m b/Example Apps/Example ObjC/VehicleDataManager.m
index d4e9a1066..5c2d3bac2 100644
--- a/Example Apps/Example ObjC/VehicleDataManager.m
+++ b/Example Apps/Example ObjC/VehicleDataManager.m
@@ -8,6 +8,7 @@
#import "AlertManager.h"
#import "AppConstants.h"
+#import "SDLRPCFunctionNames.h"
#import "SmartDeviceLink.h"
#import "TextValidator.h"
#import "VehicleDataManager.h"
@@ -136,7 +137,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (void)getAllVehicleDataWithManager:(SDLManager *)manager triggerSource:(SDLTriggerSource)triggerSource vehicleDataType:(NSString *)vehicleDataType {
SDLLogD(@"Checking if app has permission to access vehicle data...");
- if (![manager.permissionManager isRPCAllowed:@"GetVehicleData"]) {
+ if (![manager.permissionManager isRPCNameAllowed:SDLRPCFunctionNameGetVehicleData]) {
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"This app does not have the required permissions to access vehicle data" textField2:nil iconName:nil]];
return;
}
diff --git a/Example Apps/Example Swift/RPCPermissionsManager.swift b/Example Apps/Example Swift/RPCPermissionsManager.swift
index 72cdb8019..1efcbe129 100644
--- a/Example Apps/Example Swift/RPCPermissionsManager.swift
+++ b/Example Apps/Example Swift/RPCPermissionsManager.swift
@@ -16,15 +16,15 @@ class RPCPermissionsManager {
/// - Parameter manager: The SDL Manager
class func setupPermissionsCallbacks(with manager: SDLManager) {
// Checks if the `SDLShow` RPC is allowed right at this moment
- let showRPCName = "Show"
+ let showRPCName = SDLRPCFunctionName.show
_ = checkCurrentPermission(with: manager, rpcName: showRPCName)
// Checks if all the RPCs need to create menus are allowed right at this moment
- let menuRPCNames = ["AddCommand", "CreateInteractionChoiceSet", "PerformInteraction"]
+ let menuRPCNames = [SDLRPCFunctionName.addCommand, SDLRPCFunctionName.createInteractionChoiceSet, SDLRPCFunctionName.performInteraction]
_ = checkCurrentGroupPermissions(with: manager, rpcNames: menuRPCNames)
// 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 mediaTemplateRPCs = ["SetMediaClockTimer", "SubscribeButton"]
+ let mediaTemplateRPCs = [SDLRPCFunctionName.setMediaClockTimer, SDLRPCFunctionName.subscribeButton]
let allAllowedObserverId = subscribeGroupPermissions(with: manager, rpcNames: mediaTemplateRPCs, groupType: .allAllowed)
// Stop observing permissions changes for the media template releated RPCs
@@ -40,7 +40,7 @@ class RPCPermissionsManager {
/// - Returns: True if allowed, false if not
class func isDialNumberRPCAllowed(with manager: SDLManager) -> Bool {
SDLLog.d("Checking if app has permission to dial a number")
- return checkCurrentPermission(with: manager, rpcName: "DialNumber")
+ return checkCurrentPermission(with: manager, rpcName: SDLRPCFunctionName.dialNumber)
}
}
@@ -51,8 +51,8 @@ private extension RPCPermissionsManager {
///
/// - Parameter manager: The SDL Manager
/// - Returns: true if allowed, false if not
- class func checkCurrentPermission(with manager: SDLManager, rpcName: String) -> Bool {
- let isRPCAllowed = manager.permissionManager.isRPCAllowed(rpcName)
+ class func checkCurrentPermission(with manager: SDLManager, rpcName: SDLRPCFunctionName) -> Bool {
+ let isRPCAllowed = manager.permissionManager.isRPCNameAllowed(rpcName)
logRPCPermission(rpcName: rpcName, isRPCAllowed: isRPCAllowed)
return isRPCAllowed
}
@@ -61,9 +61,9 @@ 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: [String]) -> SDLPermissionGroupStatus {
- let groupPermissionStatus = manager.permissionManager.groupStatus(ofRPCs: rpcNames)
- let individualPermissionStatuses = manager.permissionManager.status(ofRPCs: rpcNames)
+ class func checkCurrentGroupPermissions(with manager: SDLManager, rpcNames: [SDLRPCFunctionName]) -> SDLPermissionGroupStatus {
+ let groupPermissionStatus = manager.permissionManager.groupStatus(ofRPCNames: rpcNames)
+ let individualPermissionStatuses = manager.permissionManager.statuses(ofRPCNames: rpcNames)
logRPCGroupPermissions(rpcNames: rpcNames, groupPermissionStatus: groupPermissionStatus, individualPermissionStatuses: individualPermissionStatuses)
return groupPermissionStatus
}
@@ -74,8 +74,8 @@ 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: [String], groupType: SDLPermissionGroupType) -> UUID {
- let permissionAllAllowedObserverId = manager.permissionManager.addObserver(forRPCs: rpcNames, groupType: groupType, withHandler: { (individualStatuses, groupStatus) in
+ class func subscribeGroupPermissions(with manager: SDLManager, rpcNames: [SDLRPCFunctionName], groupType: SDLPermissionGroupType) -> UUID {
+ let permissionAllAllowedObserverId = manager.permissionManager.subscribe(toRPCNames: rpcNames, groupType: groupType, withHandler: { (individualStatuses, groupStatus) in
self.logRPCGroupPermissions(rpcNames: rpcNames, groupPermissionStatus: groupStatus, individualPermissionStatuses: individualStatuses)
})
@@ -100,8 +100,8 @@ private extension RPCPermissionsManager {
/// - Parameters:
/// - rpcName: The name of the RPC
/// - isRPCAllowed: The permission status for the RPC
- class func logRPCPermission(rpcName: String, isRPCAllowed: Bool) {
- SDLLog.d("\(rpcName) RPC can be sent to SDL Core? \(isRPCAllowed ? "yes" : "no")")
+ class func logRPCPermission(rpcName: SDLRPCFunctionName, isRPCAllowed: Bool) {
+ SDLLog.d("\(rpcName.rawValue.rawValue) RPC can be sent to SDL Core? \(isRPCAllowed ? "yes" : "no")")
}
/// Logs permissions for a group of RPCs
@@ -110,10 +110,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: [String], groupPermissionStatus: SDLPermissionGroupStatus, individualPermissionStatuses: [String:NSNumber]) {
- SDLLog.d("The group status for \(rpcNames) has changed to: \(groupPermissionStatus)")
+ class func logRPCGroupPermissions(rpcNames: [SDLRPCFunctionName], groupPermissionStatus: SDLPermissionGroupStatus, individualPermissionStatuses: [SDLRPCFunctionName:NSNumber]) {
+ SDLLog.d("The group status for \(rpcNames.map { $0.rawValue.rawValue } ) has changed to: \(groupPermissionStatus.rawValue)")
for (rpcName, rpcAllowed) in individualPermissionStatuses {
- logRPCPermission(rpcName: rpcName as String, isRPCAllowed: rpcAllowed.boolValue)
+ logRPCPermission(rpcName: rpcName, isRPCAllowed: rpcAllowed.boolValue)
}
}
}
diff --git a/Example Apps/Example Swift/VehicleDataManager.swift b/Example Apps/Example Swift/VehicleDataManager.swift
index 34ac4352c..c0f6e59dc 100644
--- a/Example Apps/Example Swift/VehicleDataManager.swift
+++ b/Example Apps/Example Swift/VehicleDataManager.swift
@@ -232,7 +232,7 @@ extension VehicleDataManager {
class func hasPermissionToAccessVehicleData(with manager: SDLManager) -> Bool {
SDLLog.d("Checking if app has permission to access vehicle data...")
- guard manager.permissionManager.isRPCAllowed("GetVehicleData") else {
+ guard manager.permissionManager.isRPCNameAllowed(SDLRPCFunctionName.getVehicleData) else {
let alert = AlertManager.alertWithMessageAndCloseButton("This app does not have the required permissions to access vehicle data")
manager.send(request: alert)
return false
diff --git a/SmartDeviceLink/SDLPermissionConstants.h b/SmartDeviceLink/SDLPermissionConstants.h
index ea36738cc..05b528bfd 100644
--- a/SmartDeviceLink/SDLPermissionConstants.h
+++ b/SmartDeviceLink/SDLPermissionConstants.h
@@ -9,6 +9,7 @@
#import <Foundation/Foundation.h>
#import "NSNumber+NumberType.h"
+#import "SDLRPCFunctionNames.h"
NS_ASSUME_NONNULL_BEGIN
@@ -66,4 +67,12 @@ typedef NS_ENUM(NSUInteger, SDLPermissionGroupStatus) {
*/
typedef void (^SDLPermissionsChangedHandler)(NSDictionary<SDLPermissionRPCName, NSNumber *> *_Nonnull change, SDLPermissionGroupStatus status);
+/**
+ * The SDLObservedPermissionsChangedHandler is a block that is passed in to subscribeToRPCNames:groupType:withHandler: that will be stored and called when specified permissions change.
+ *
+ * @param change A dictionary of permission changes containing <key(SDLRPCFunctionName): RPC Name, object(BOOL): YES if the RPC is allowed, NO if it is not allowed>
+ * @param status The change made to all of the RPCs in the changedDict. Allowed, if all RPCs are now allowed, Disallowed if all RPCs are now disallowed, or Mixed if some are allowed, and some are disallowed
+ */
+typedef void (^SDLSubscribedPermissionsChangedHandler)(NSDictionary<SDLRPCFunctionName, NSNumber *> *_Nonnull change, SDLPermissionGroupStatus status);
+
NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/SDLPermissionManager.h b/SmartDeviceLink/SDLPermissionManager.h
index 6adfa7cf7..873bf23c7 100644
--- a/SmartDeviceLink/SDLPermissionManager.h
+++ b/SmartDeviceLink/SDLPermissionManager.h
@@ -10,6 +10,7 @@
#import "SDLHMILevel.h"
#import "SDLPermissionConstants.h"
+#import "SDLRPCFunctionNames.h"
@class SDLPermissionItem;
@class SDLRPCMessage;
@@ -43,7 +44,16 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return YES if the RPC is allowed at the current HMI level, NO if not
*/
-- (BOOL)isRPCAllowed:(SDLPermissionRPCName)rpcName;
+- (BOOL)isRPCAllowed:(SDLPermissionRPCName)rpcName __deprecated_msg(("Use isRPCNameAllowed: instead"));
+
+/**
+ * Determine if an individual RPC is allowed for the current HMI level
+ *
+ * @param rpcName The name of the RPC to be tested, for example, SDLRPCFunctionNameShow
+ *
+ * @return YES if the RPC is allowed at the current HMI level, NO if not
+ */
+- (BOOL)isRPCNameAllowed:(SDLRPCFunctionName)rpcName;
/**
* Determine if all RPCs are allowed for the current HMI level
@@ -52,7 +62,16 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return AllAllowed if all of the permissions are allowed, AllDisallowed if all the permissions are disallowed, Any if some are allowed, and some are disallowed
*/
-- (SDLPermissionGroupStatus)groupStatusOfRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames;
+- (SDLPermissionGroupStatus)groupStatusOfRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames __deprecated_msg(("Use groupStatusOfRPCNames: instead"));
+
+/**
+ * Determine if all RPCs are allowed for the current HMI level
+ *
+ * @param rpcNames The RPCs to check
+ *
+ * @return AllAllowed if all of the permissions are allowed, AllDisallowed if all the permissions are disallowed, Any if some are allowed, and some are disallowed
+*/
+- (SDLPermissionGroupStatus)groupStatusOfRPCNames:(NSArray<SDLRPCFunctionName> *)rpcNames;
/**
* Retrieve a dictionary with keys that are the passed in RPC names, and objects of an NSNumber<BOOL> specifying if that RPC is currently allowed
@@ -61,7 +80,16 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return A dictionary specifying if the passed in RPC names are currently allowed or not
*/
-- (NSDictionary<SDLPermissionRPCName, NSNumber *> *)statusOfRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames;
+- (NSDictionary<SDLPermissionRPCName, NSNumber *> *)statusOfRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames __deprecated_msg(("Use statusesOfRPCNames: instead"));
+
+/**
+ * Retrieve a dictionary with keys that are the passed in RPC names, and objects of an NSNumber<BOOL> specifying if that RPC is currently allowed
+ *
+ * @param rpcNames An array of RPC names to check
+ *
+ * @return A dictionary specifying if the passed in RPC names are currently allowed or not
+*/
+- (NSDictionary<SDLRPCFunctionName, NSNumber *> *)statusesOfRPCNames:(NSArray<SDLRPCFunctionName> *)rpcNames;
/**
* Add an observer for specified RPC names, with a callback that will be called whenever the value changes, as well as immediately with the current status.
@@ -76,7 +104,20 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return An identifier that can be passed to removeObserverForIdentifer: to remove the observer
*/
-- (SDLPermissionObserverIdentifier)addObserverForRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames groupType:(SDLPermissionGroupType)groupType withHandler:(SDLPermissionsChangedHandler)handler;
+- (SDLPermissionObserverIdentifier)addObserverForRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames groupType:(SDLPermissionGroupType)groupType withHandler:(SDLPermissionsChangedHandler)handler __deprecated_msg(("Use subscribeToRPCNames:groupType:withHandler: instead"));
+
+/**
+ * Subscribe to specified RPC names, with a callback that will be called whenever the value changes. Unlike addObserverForRPCs:groupType:withHandler:, the callback will only return immediately if the groupType is set to SDLPermissionGroupTypeAny or if the groupType is set to SDLPermissionGroupTypeAllAllowed and all RPCs in the rpcNames parameter are allowed.
+ *
+ * @warning The observer may be called before this method returns, do not attempt to remove the observer from within the observer. That could send `nil` to removeObserverForIdentifier:. If you want functionality like that, call groupStatusOfRPCs: instead.
+ *
+ * @param rpcNames The RPCs to be observed
+ * @param groupType Affects the times that the observer block will be called. If Any, any change to any RPC in rpcNames will cause the observer block to be called. If AllAllowed, the block will be called when: 1. Every RPC in rpcNames becomes allowed 2. The group of rpcNames goes from all being allowed to some or all being disallowed.
+ * @param handler The block that will be called whenever permissions change.
+ *
+ * @return An identifier that can be passed to removeObserverForIdentifer: to remove the observer
+ */
+- (SDLPermissionObserverIdentifier)subscribeToRPCNames:(NSArray<SDLRPCFunctionName> *)rpcNames groupType:(SDLPermissionGroupType)groupType withHandler:(SDLSubscribedPermissionsChangedHandler)handler;
/**
* Remove every current observer
@@ -94,7 +135,12 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Check whether or not an RPC needs encryption.
*/
-- (BOOL)rpcRequiresEncryption:(SDLPermissionRPCName)rpcName;
+- (BOOL)rpcRequiresEncryption:(SDLPermissionRPCName)rpcName __deprecated_msg(("Use rpcNameRequiresEncryption: instead"));
+
+/**
+ * Check whether or not an RPC needs encryption.
+ */
+- (BOOL)rpcNameRequiresEncryption:(SDLRPCFunctionName)rpcName;
@end
diff --git a/SmartDeviceLink/SDLPermissionManager.m b/SmartDeviceLink/SDLPermissionManager.m
index cdb08e135..310dca0b2 100644
--- a/SmartDeviceLink/SDLPermissionManager.m
+++ b/SmartDeviceLink/SDLPermissionManager.m
@@ -66,6 +66,10 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Permissions available
- (BOOL)isRPCAllowed:(NSString *)rpcName {
+ return [self isRPCNameAllowed:rpcName];
+}
+
+- (BOOL)isRPCNameAllowed:(SDLRPCFunctionName)rpcName {
if (self.permissions[rpcName] == nil || self.currentHMILevel == nil) {
return NO;
}
@@ -75,6 +79,10 @@ NS_ASSUME_NONNULL_BEGIN
}
- (SDLPermissionGroupStatus)groupStatusOfRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames {
+ return [self groupStatusOfRPCNames:rpcNames];
+}
+
+- (SDLPermissionGroupStatus)groupStatusOfRPCNames:(NSArray<SDLRPCFunctionName> *)rpcNames {
if (self.currentHMILevel == nil) {
return SDLPermissionGroupStatusUnknown;
}
@@ -122,10 +130,14 @@ NS_ASSUME_NONNULL_BEGIN
}
- (NSDictionary<SDLPermissionRPCName, NSNumber *> *)statusOfRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames {
- NSMutableDictionary<SDLPermissionRPCName, NSNumber *> *permissionAllowedDict = [NSMutableDictionary dictionary];
+ return [self statusesOfRPCNames:rpcNames];
+}
- for (NSString *rpcName in rpcNames) {
- BOOL allowed = [self isRPCAllowed:rpcName];
+- (NSDictionary<SDLRPCFunctionName,NSNumber *> *)statusesOfRPCNames:(NSArray<SDLRPCFunctionName> *)rpcNames {
+ NSMutableDictionary<SDLRPCFunctionName, NSNumber *> *permissionAllowedDict = [NSMutableDictionary dictionary];
+
+ for (SDLRPCFunctionName rpcName in rpcNames) {
+ BOOL allowed = [self isRPCNameAllowed:rpcName];
permissionAllowedDict[rpcName] = @(allowed);
}
@@ -149,9 +161,24 @@ NS_ASSUME_NONNULL_BEGIN
return filter.identifier;
}
+- (SDLPermissionObserverIdentifier)subscribeToRPCNames:(NSArray<SDLRPCFunctionName> *)rpcNames groupType:(SDLPermissionGroupType)groupType withHandler:(SDLPermissionsChangedHandler)handler {
+ SDLPermissionFilter *filter = [SDLPermissionFilter filterWithRPCNames:rpcNames groupType:groupType observer:handler];
+
+ // Store the filter for later use
+ [self.filters addObject:filter];
+
+ // Check permission status and group type to see if we need to call handler immediately after setting the observer
+ SDLPermissionGroupStatus permissionStatus = [self groupStatusOfRPCNames:filter.rpcNames];
+ if ((groupType == SDLPermissionGroupTypeAny) || (groupType == SDLPermissionGroupTypeAllAllowed && permissionStatus == SDLPermissionGroupStatusAllowed)) {
+ [self sdl_callFilterObserver:filter];
+ }
+
+ return filter.identifier;
+}
+
- (void)sdl_callFilterObserver:(SDLPermissionFilter *)filter {
- SDLPermissionGroupStatus permissionStatus = [self groupStatusOfRPCs:filter.rpcNames];
- NSDictionary<SDLPermissionRPCName, NSNumber *> *allowedDict = [self statusOfRPCs:filter.rpcNames];
+ SDLPermissionGroupStatus permissionStatus = [self groupStatusOfRPCNames:filter.rpcNames];
+ NSDictionary<SDLPermissionRPCName, NSNumber *> *allowedDict = [self statusesOfRPCNames:filter.rpcNames];
filter.handler(allowedDict, permissionStatus);
}
@@ -203,7 +230,7 @@ NS_ASSUME_NONNULL_BEGIN
for (SDLPermissionFilter *filter in modifiedFilters) {
if (filter.groupType == SDLPermissionGroupTypeAllAllowed) {
SDLPermissionGroupStatus oldStatus = [allAllowedFiltersWithOldStatus[filter.identifier] unsignedIntegerValue];
- SDLPermissionGroupStatus newStatus = [self groupStatusOfRPCs:filter.rpcNames];
+ SDLPermissionGroupStatus newStatus = [self groupStatusOfRPCNames:filter.rpcNames];
// We've already eliminated the case where the permissions could stay the same, so if the permissions changed *to* allowed or *away* from allowed, we need to call the observer.
if (newStatus == SDLPermissionGroupStatusAllowed || oldStatus == SDLPermissionGroupStatusAllowed) {
@@ -313,7 +340,7 @@ NS_ASSUME_NONNULL_BEGIN
NSMutableDictionary<SDLPermissionFilter *, NSNumber<SDLInt> *> *filtersWithStatus = [NSMutableDictionary dictionary];
for (SDLPermissionFilter *filter in filters) {
if (filter.groupType == SDLPermissionGroupTypeAllAllowed) {
- filtersWithStatus[filter.identifier] = @([self groupStatusOfRPCs:filter.rpcNames]);
+ filtersWithStatus[filter.identifier] = @([self groupStatusOfRPCNames:filter.rpcNames]);
}
}
@@ -368,6 +395,10 @@ NS_ASSUME_NONNULL_BEGIN
}
- (BOOL)rpcRequiresEncryption:(SDLPermissionRPCName)rpcName {
+ return [self rpcNameRequiresEncryption:rpcName];
+}
+
+- (BOOL)rpcNameRequiresEncryption:(SDLRPCFunctionName)rpcName {
if (self.permissions[rpcName].requireEncryption != nil) {
return self.permissions[rpcName].requireEncryption.boolValue;
}
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionsManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionsManagerSpec.m
index eaf657595..bee6548c2 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionsManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionsManagerSpec.m
@@ -11,6 +11,7 @@
#import "SDLPermissionFilter.h"
#import "SDLPermissionItem.h"
#import "SDLPermissionManager.h"
+#import "SDLRPCFunctionNames.h"
#import "SDLRPCNotificationNotification.h"
#import "SDLRPCResponseNotification.h"
@@ -133,56 +134,122 @@ describe(@"SDLPermissionsManager", ^{
describe(@"checking if a permission is allowed", ^{
__block NSString *someRPCName = nil;
+ __block SDLRPCFunctionName someRPCFunctionName = nil;
__block BOOL testResultBOOL = NO;
-
+
context(@"when no permissions exist", ^{
- beforeEach(^{
- someRPCName = @"some rpc name";
-
- testResultBOOL = [testPermissionsManager isRPCAllowed:someRPCName];
+ context(@"deprecated isRPCAllowed: method", ^{
+ beforeEach(^{
+ someRPCName = @"some rpc name";
+
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ testResultBOOL = [testPermissionsManager isRPCAllowed:someRPCName];
+ #pragma clang diagnostic pop
+ });
+
+ it(@"should not be allowed", ^{
+ expect(testResultBOOL).to(beFalse());
+ });
});
-
- it(@"should not be allowed", ^{
- expect(@(testResultBOOL)).to(equal(@NO));
+
+ context(@"isRPCNameAllowed: method", ^{
+ beforeEach(^{
+ someRPCFunctionName = @"SomeRPCFunctionName";
+ testResultBOOL = [testPermissionsManager isRPCNameAllowed:someRPCName];
+ });
+
+ it(@"should not be allowed", ^{
+ expect(testResultBOOL).to(beFalse());
+ });
});
});
context(@"when permissions exist but no HMI level", ^{
- beforeEach(^{
- [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
-
- testResultBOOL = [testPermissionsManager isRPCAllowed:testRPCNameAllAllowed];
- });
-
- it(@"should not be allowed", ^{
- expect(@(testResultBOOL)).to(equal(@NO));
- });
- });
-
- context(@"when permissions exist", ^{
- context(@"and the permission is allowed", ^{
+ context(@"deprecated isRPCAllowed: method", ^{
beforeEach(^{
- [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
[[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
-
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
testResultBOOL = [testPermissionsManager isRPCAllowed:testRPCNameAllAllowed];
+ #pragma clang diagnostic pop
});
-
- it(@"should be allowed", ^{
- expect(@(testResultBOOL)).to(equal(@YES));
+
+ it(@"should not be allowed", ^{
+ expect(testResultBOOL).to(beFalse());
});
});
-
- context(@"and the permission is denied", ^{
+
+ context(@"isRPCNameAllowed: method", ^{
beforeEach(^{
- [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
[[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
-
- testResultBOOL = [testPermissionsManager isRPCAllowed:testRPCNameAllDisallowed];
+ testResultBOOL = [testPermissionsManager isRPCNameAllowed:someRPCName];
+ });
+
+ it(@"should not be allowed", ^{
+ expect(testResultBOOL).to(beFalse());
+ });
+ });
+ });
+
+ context(@"when permissions exist", ^{
+ context(@"deprecated isRPCAllowed: method", ^{
+ context(@"and the permission is allowed", ^{
+ beforeEach(^{
+ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
+ [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ testResultBOOL = [testPermissionsManager isRPCAllowed:testRPCNameAllAllowed];
+ #pragma clang diagnostic pop
+ });
+
+ it(@"should be allowed", ^{
+ expect(testResultBOOL).to(beTrue());
+ });
+ });
+
+ context(@"and the permission is denied", ^{
+ beforeEach(^{
+ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
+ [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ testResultBOOL = [testPermissionsManager isRPCAllowed:testRPCNameAllDisallowed];
+ #pragma clang diagnostic pop
+ });
+
+ it(@"should be denied", ^{
+ expect(testResultBOOL).to(beFalse());
+ });
});
-
- it(@"should be denied", ^{
- expect(@(testResultBOOL)).to(equal(@NO));
+ });
+
+ context(@"isRPCNameAllowed: method", ^{
+ context(@"and the permission is allowed", ^{
+ beforeEach(^{
+ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
+ [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
+
+ testResultBOOL = [testPermissionsManager isRPCNameAllowed:testRPCNameAllAllowed];
+ });
+
+ it(@"should be allowed", ^{
+ expect(testResultBOOL).to(beTrue());
+ });
+ });
+
+ context(@"and the permission is denied", ^{
+ beforeEach(^{
+ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
+ [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
+
+ testResultBOOL = [testPermissionsManager isRPCNameAllowed:testRPCNameAllDisallowed];
+ });
+
+ it(@"should be denied", ^{
+ expect(testResultBOOL).to(beFalse());
+ });
});
});
});
@@ -192,103 +259,204 @@ describe(@"SDLPermissionsManager", ^{
__block SDLPermissionGroupStatus testResultStatus = SDLPermissionGroupStatusUnknown;
context(@"with no permissions data", ^{
- beforeEach(^{
- testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]];
+ context(@"deprecated groupStatusOfRPCs: method", ^{
+ beforeEach(^{
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]];
+ #pragma clang diagnostic pop
+ });
+
+ it(@"should return unknown", ^{
+ expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusUnknown)));
+ });
});
-
- it(@"should return unknown", ^{
- expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusUnknown)));
+
+ context(@"groupStatusOfRPCNames: method", ^{
+ beforeEach(^{
+ testResultStatus = [testPermissionsManager groupStatusOfRPCNames:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]];
+ });
+
+ it(@"should return unknown", ^{
+ expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusUnknown)));
+ });
});
});
context(@"for an all allowed group", ^{
- beforeEach(^{
- [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
- [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
-
- testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameAllAllowed, testRPCNameFullLimitedAllowed]];
+ context(@"deprecated groupStatusOfRPCs: method", ^{
+ beforeEach(^{
+ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
+ [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameAllAllowed, testRPCNameFullLimitedAllowed]];
+ #pragma clang diagnostic pop
+ });
+
+ it(@"should return allowed", ^{
+ expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusAllowed)));
+ });
});
-
- it(@"should return mixed", ^{
- expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusAllowed)));
+
+ context(@"groupStatusOfRPCNames: method", ^{
+ beforeEach(^{
+ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
+ [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
+
+ testResultStatus = [testPermissionsManager groupStatusOfRPCNames:@[testRPCNameAllAllowed, testRPCNameFullLimitedAllowed]];
+ });
+
+ it(@"should return allowed", ^{
+ expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusAllowed)));
+ });
});
});
context(@"for an all disallowed group", ^{
- beforeEach(^{
- [[NSNotificationCenter defaultCenter] postNotification:backgroundHMINotification];
- [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
-
- testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameFullLimitedAllowed, testRPCNameAllDisallowed]];
+ context(@"deprecated groupStatusOfRPCs: method", ^{
+ beforeEach(^{
+ [[NSNotificationCenter defaultCenter] postNotification:backgroundHMINotification];
+ [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameFullLimitedAllowed, testRPCNameAllDisallowed]];
+ #pragma clang diagnostic pop
+ });
+
+ it(@"should return disallowed", ^{
+ expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusDisallowed)));
+ });
});
-
- it(@"should return mixed", ^{
- expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusDisallowed)));
+
+ context(@"groupStatusOfRPCNames: method", ^{
+ beforeEach(^{
+ [[NSNotificationCenter defaultCenter] postNotification:backgroundHMINotification];
+ [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
+
+ testResultStatus = [testPermissionsManager groupStatusOfRPCNames:@[testRPCNameFullLimitedAllowed, testRPCNameAllDisallowed]];
+ });
+
+ it(@"should return disallowed", ^{
+ expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusDisallowed)));
+ });
});
});
context(@"for a mixed group", ^{
- beforeEach(^{
- [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
- [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
-
- testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]];
+ context(@"deprecated groupStatusOfRPCs: method", ^{
+ beforeEach(^{
+ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
+ [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]];
+ #pragma clang diagnostic pop
+ });
+
+ it(@"should return mixed", ^{
+ expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusMixed)));
+ });
});
-
- it(@"should return mixed", ^{
- expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusMixed)));
+
+ context(@"groupStatusOfRPCNames: method", ^{
+ beforeEach(^{
+ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
+ [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
+
+ testResultStatus = [testPermissionsManager groupStatusOfRPCNames:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]];
+ });
+
+ it(@"should return mixed", ^{
+ expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusMixed)));
+ });
});
});
});
describe(@"checking the status of RPCs", ^{
__block NSDictionary<SDLPermissionRPCName, NSNumber *> *testResultPermissionStatusDict = nil;
-
context(@"with no permissions data", ^{
- beforeEach(^{
- testResultPermissionStatusDict = [testPermissionsManager statusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]];
+ context(@"deprecated statusOfRPCs: method", ^{
+ beforeEach(^{
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ testResultPermissionStatusDict = [testPermissionsManager statusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]];
+ #pragma clang diagnostic pop
+ });
+
+ it(@"should return correct permission statuses", ^{
+ expect(testResultPermissionStatusDict[testRPCNameAllAllowed]).to(equal(@NO));
+ expect(testResultPermissionStatusDict[testRPCNameAllDisallowed]).to(equal(@NO));
+ });
});
-
- it(@"should return correct permission statuses", ^{
- expect(testResultPermissionStatusDict[testRPCNameAllAllowed]).to(equal(@NO));
- expect(testResultPermissionStatusDict[testRPCNameAllDisallowed]).to(equal(@NO));
+
+ context(@"statusesOfRPCNames: method", ^{
+ beforeEach(^{
+ testResultPermissionStatusDict = [testPermissionsManager statusesOfRPCNames:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]];
+ });
+
+ it(@"should return correct permission statuses", ^{
+ expect(testResultPermissionStatusDict[testRPCNameAllAllowed]).to(equal(@NO));
+ expect(testResultPermissionStatusDict[testRPCNameAllDisallowed]).to(equal(@NO));
+ });
});
});
context(@"with permissions data", ^{
- beforeEach(^{
- [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
- [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
-
- testResultPermissionStatusDict = [testPermissionsManager statusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]];
+ context(@"deprecated statusOfRPCs: method", ^{
+ beforeEach(^{
+ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
+ [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ testResultPermissionStatusDict = [testPermissionsManager statusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]];
+ #pragma clang diagnostic pop
+ });
+
+ it(@"should return correct permission statuses", ^{
+ expect(testResultPermissionStatusDict[testRPCNameAllAllowed]).to(equal(@YES));
+ expect(testResultPermissionStatusDict[testRPCNameAllDisallowed]).to(equal(@NO));
+ });
});
-
- it(@"should return correct permission statuses", ^{
- expect(testResultPermissionStatusDict[testRPCNameAllAllowed]).to(equal(@YES));
- expect(testResultPermissionStatusDict[testRPCNameAllDisallowed]).to(equal(@NO));
+
+ context(@"statusesOfRPCNames: method", ^{
+ beforeEach(^{
+ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
+ [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
+
+ testResultPermissionStatusDict = [testPermissionsManager statusesOfRPCNames:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]];
+ });
+
+ it(@"should return correct permission statuses", ^{
+ expect(testResultPermissionStatusDict[testRPCNameAllAllowed]).to(equal(@YES));
+ expect(testResultPermissionStatusDict[testRPCNameAllDisallowed]).to(equal(@NO));
+ });
});
});
});
-
+
describe(@"adding and using observers", ^{
describe(@"adding new observers", ^{
context(@"when no data is present", ^{
__block BOOL testObserverCalled = NO;
__block SDLPermissionGroupStatus testObserverStatus = SDLPermissionGroupStatusUnknown;
__block NSDictionary<SDLPermissionRPCName,NSNumber *> *testObserverChangeDict = nil;
-
+
beforeEach(^{
testObserverCalled = NO;
testObserverStatus = SDLPermissionGroupStatusUnknown;
testObserverChangeDict = nil;
-
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
[testPermissionsManager addObserverForRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed] groupType:SDLPermissionGroupTypeAny withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull change, SDLPermissionGroupStatus status) {
testObserverChangeDict = change;
testObserverStatus = status;
testObserverCalled = YES;
}];
+ #pragma clang diagnostic pop
});
-
+
it(@"should return correct permission statuses", ^{
expect(@(testObserverCalled)).to(equal(@YES));
expect(@(testObserverStatus)).to(equal(@(SDLPermissionGroupStatusUnknown)));
@@ -296,30 +464,33 @@ describe(@"SDLPermissionsManager", ^{
expect(testObserverChangeDict[testRPCNameAllDisallowed]).to(equal(@NO));
});
});
-
+
context(@"when data is already present", ^{
__block NSInteger numberOfTimesObserverCalled = 0;
__block NSDictionary<SDLPermissionRPCName,NSNumber *> *testObserverBlockChangedDict = nil;
__block SDLPermissionGroupStatus testObserverReturnStatus = SDLPermissionGroupStatusUnknown;
-
+
context(@"to match an ANY observer", ^{
beforeEach(^{
// Reset vars
numberOfTimesObserverCalled = 0;
-
+
// Post the notification before setting the observer to make sure data is already present
// HMI Full & Limited allowed
[[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
[[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
-
+
// This should be called twice, once for each RPC being observed. It should be called immediately since data should already be present
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
[testPermissionsManager addObserverForRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed] groupType:SDLPermissionGroupTypeAny withHandler:^(NSDictionary<SDLPermissionRPCName, NSNumber *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
testObserverBlockChangedDict = changedDict;
testObserverReturnStatus = status;
}];
+ #pragma clang diagnostic pop
});
-
+
it(@"should call the observer with proper status", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@1));
expect(testObserverBlockChangedDict[testRPCNameAllAllowed]).to(equal(@YES));
@@ -328,25 +499,28 @@ describe(@"SDLPermissionsManager", ^{
expect(@(testObserverReturnStatus)).to(equal(@(SDLPermissionGroupStatusMixed)));
});
});
-
+
context(@"to match an all allowed observer", ^{
beforeEach(^{
// Reset vars
numberOfTimesObserverCalled = 0;
-
+
// Post the notification before setting the observer to make sure data is already present
// HMI Full & Limited allowed, hmi level LIMITED
[[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
[[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
-
+
// This should be called twice, once for each RPC being observed. It should be called immediately since data should already be present
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
[testPermissionsManager addObserverForRPCs:@[testRPCNameAllAllowed, testRPCNameFullLimitedAllowed] groupType:SDLPermissionGroupTypeAllAllowed withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull change, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
testObserverBlockChangedDict = change;
testObserverReturnStatus = status;
}];
+ #pragma clang diagnostic pop
});
-
+
it(@"should call the observer with proper status", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@1));
expect(testObserverBlockChangedDict[testRPCNameAllAllowed]).to(equal(@YES));
@@ -355,24 +529,27 @@ describe(@"SDLPermissionsManager", ^{
expect(@(testObserverReturnStatus)).to(equal(@(SDLPermissionGroupStatusAllowed)));
});
});
-
+
context(@"that does not match an all allowed observer", ^{
beforeEach(^{
// Reset vars
numberOfTimesObserverCalled = 0;
-
+
// Post the notification before setting the observer to make sure data is already present
// HMI Full & Limited allowed, hmi level NONE
[[NSNotificationCenter defaultCenter] postNotification:noneHMINotification];
[[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
-
+
// This should be called twice, once for each RPC being observed. It should be called immediately since data should already be present
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
[testPermissionsManager addObserverForRPCs:@[testRPCNameAllDisallowed, testRPCNameFullLimitedAllowed] groupType:SDLPermissionGroupTypeAllAllowed withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull change, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
testObserverReturnStatus = status;
}];
+ #pragma clang diagnostic pop
});
-
+
it(@"should call the observer with status Disallowed", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@1));
expect(@(testObserverReturnStatus)).to(equal(@(SDLPermissionGroupStatusDisallowed)));
@@ -380,74 +557,116 @@ describe(@"SDLPermissionsManager", ^{
});
});
});
-
+
+ describe(@"adding a new observer with subscribeToRPCNames:groupType:Handler", ^{
+ context(@"when no data is present", ^{
+ __block BOOL testObserverCalled = NO;
+
+ beforeEach(^{
+ testObserverCalled = NO;
+ [testPermissionsManager subscribeToRPCNames:@[testRPCNameAllAllowed, testRPCNameAllDisallowed] groupType:SDLPermissionGroupTypeAny withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull change, SDLPermissionGroupStatus status) {
+ testObserverCalled = YES;
+ }];
+ });
+
+ it(@"should be called", ^{
+ expect(testObserverCalled).to(beTrue());
+ });
+ });
+
+ context(@"when data is present", ^{
+ __block BOOL testObserverCalled = NO;
+
+ beforeEach(^{
+ testObserverCalled = NO;
+
+ // Post the notification before setting the observer to make sure data is already present
+ // HMI Full & Limited allowed
+ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
+ [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
+
+ // This should not be called even with data currently present, the handler will only be called when an permissions update occurs after the RPC is subscribed to
+ [testPermissionsManager subscribeToRPCNames:@[testRPCNameAllAllowed, testRPCNameAllDisallowed] groupType:SDLPermissionGroupTypeAny withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull change, SDLPermissionGroupStatus status) {
+ testObserverCalled = YES;
+ }];
+ });
+
+ it(@"should be called", ^{
+ expect(@(testObserverCalled)).to(beTrue());
+ });
+ });
+ });
+
context(@"updating an observer with new permission data", ^{
__block NSInteger numberOfTimesObserverCalled = 0;
-
+
__block SDLOnPermissionsChange *testPermissionChangeUpdate = nil;
__block SDLPermissionItem *testPermissionUpdated = nil;
__block NSMutableArray<NSDictionary<SDLPermissionRPCName,NSNumber*> *> *changeDicts = nil;
__block NSMutableArray<NSNumber<SDLUInt> *> *testStatuses = nil;
-
+
context(@"to match an ANY observer", ^{
beforeEach(^{
// Reset vars
numberOfTimesObserverCalled = 0;
changeDicts = [NSMutableArray array];
testStatuses = [NSMutableArray array];
-
+
// Post the notification before setting the observer to make sure data is already present
// HMI Full & Limited allowed, hmi level LIMITED
[[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
[[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
-
+
// Set an observer that should be called immediately for the preexisting data, then called again when new data is sent
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
[testPermissionsManager addObserverForRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed] groupType:SDLPermissionGroupTypeAny withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
[changeDicts addObject:changedDict];
}];
-
+ #pragma clang diagnostic pop
+
// Create a permission update disallowing our current HMI level for the observed permission
SDLParameterPermissions *testParameterPermissions = [[SDLParameterPermissions alloc] init];
SDLHMIPermissions *testHMIPermissionsUpdated = [[SDLHMIPermissions alloc] init];
testHMIPermissionsUpdated.allowed = @[SDLHMILevelBackground, SDLHMILevelFull];
testHMIPermissionsUpdated.userDisallowed = @[SDLHMILevelLimited, SDLHMILevelNone];
-
+
testPermissionUpdated = [[SDLPermissionItem alloc] init];
testPermissionUpdated.rpcName = testRPCNameAllAllowed;
testPermissionUpdated.hmiPermissions = testHMIPermissionsUpdated;
testPermissionUpdated.parameterPermissions = testParameterPermissions;
-
+
testPermissionChangeUpdate = [[SDLOnPermissionsChange alloc] init];
testPermissionChangeUpdate.permissionItem = [NSArray arrayWithObject:testPermissionUpdated];
-
+
// Send the permission update
SDLRPCNotificationNotification *updatedNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangePermissionsNotification object:nil rpcNotification:testPermissionChangeUpdate];
[[NSNotificationCenter defaultCenter] postNotification:updatedNotification];
});
-
+
it(@"should call the observer twice", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@2));
});
-
+
it(@"should have proper data in the first change dict", ^{
expect(changeDicts[0].allKeys).to(contain(testRPCNameAllAllowed));
expect(changeDicts[0].allKeys).to(contain(testRPCNameAllDisallowed));
-
+
NSNumber<SDLBool> *allAllowed = changeDicts[0][testRPCNameAllAllowed];
expect(allAllowed).to(equal(@YES));
-
+
NSNumber<SDLBool> *allDisallowed = changeDicts[0][testRPCNameAllDisallowed];
expect(allDisallowed).to(equal(@NO));
});
-
+
it(@"should have the proper data in the second change dict", ^{
expect(changeDicts[1].allKeys).to(contain(testRPCNameAllAllowed));
expect(changeDicts[1].allKeys).to(contain(testRPCNameAllDisallowed));
-
+
NSNumber<SDLBool> *allAllowed = changeDicts[1][testRPCNameAllAllowed];
expect(allAllowed).to(equal(@NO));
-
+
NSNumber<SDLBool> *allDisallowed = changeDicts[1][testRPCNameAllDisallowed];
expect(allDisallowed).to(equal(@NO));
});
@@ -483,188 +702,200 @@ describe(@"SDLPermissionsManager", ^{
});
});
});
-
+
context(@"to match an all allowed observer", ^{
beforeEach(^{
// Reset vars
numberOfTimesObserverCalled = 0;
changeDicts = [NSMutableArray array];
testStatuses = [NSMutableArray array];
-
+
// Post the notification before setting the observer to make sure data is already present
// HMI Full & Limited allowed, hmi level BACKGROUND
[[NSNotificationCenter defaultCenter] postNotification:backgroundHMINotification];
[[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
});
-
+
context(@"so that it becomes All Allowed", ^{
beforeEach(^{
// Set an observer that should be called immediately for the preexisting data, then called again when new data is sent
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
[testPermissionsManager addObserverForRPCs:@[testRPCNameAllDisallowed, testRPCNameFullLimitedBackgroundAllowed] groupType:SDLPermissionGroupTypeAllAllowed withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull change, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
[changeDicts addObject:change];
[testStatuses addObject:@(status)];
}];
-
+ #pragma clang diagnostic pop
+
// Create a permission update allowing our current HMI level for the observed permission
SDLParameterPermissions *testParameterPermissions = [[SDLParameterPermissions alloc] init];
SDLHMIPermissions *testHMIPermissionsUpdated = [[SDLHMIPermissions alloc] init];
testHMIPermissionsUpdated.allowed = @[SDLHMILevelLimited, SDLHMILevelNone, SDLHMILevelBackground, SDLHMILevelFull];
testHMIPermissionsUpdated.userDisallowed = @[];
-
+
testPermissionUpdated = [[SDLPermissionItem alloc] init];
testPermissionUpdated.rpcName = testRPCNameAllDisallowed;
testPermissionUpdated.hmiPermissions = testHMIPermissionsUpdated;
testPermissionUpdated.parameterPermissions = testParameterPermissions;
-
+
testPermissionChangeUpdate = [[SDLOnPermissionsChange alloc] init];
testPermissionChangeUpdate.permissionItem = [NSArray arrayWithObject:testPermissionUpdated];
-
+
// Send the permission update
SDLRPCNotificationNotification *updatedNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangePermissionsNotification object:nil rpcNotification:testPermissionChangeUpdate];
[[NSNotificationCenter defaultCenter] postNotification:updatedNotification];
});
-
+
it(@"should call the observer twice", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@2));
});
-
+
it(@"should have proper data in the first change dict", ^{
expect(changeDicts[0].allKeys).to(haveCount(@2));
expect(testStatuses[0]).to(equal(@(SDLPermissionGroupStatusMixed)));
});
-
+
it(@"should have the proper data in the second change dict", ^{
expect(changeDicts[1].allKeys).to(haveCount(@2));
expect(testStatuses[1]).to(equal(@(SDLPermissionGroupStatusAllowed)));
});
});
-
+
context(@"so that it goes from All Allowed to mixed", ^{
beforeEach(^{
// Set an observer that should be called immediately for the preexisting data, then called again when new data is sent
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
[testPermissionsManager addObserverForRPCs:@[testRPCNameAllAllowed] groupType:SDLPermissionGroupTypeAllAllowed withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull change, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
[changeDicts addObject:change];
[testStatuses addObject:@(status)];
}];
-
+ #pragma clang diagnostic pop
+
// Create a permission update disallowing our current HMI level for the observed permission
SDLParameterPermissions *testParameterPermissions = [[SDLParameterPermissions alloc] init];
SDLHMIPermissions *testHMIPermissionsUpdated = [[SDLHMIPermissions alloc] init];
testHMIPermissionsUpdated.allowed = @[];
testHMIPermissionsUpdated.userDisallowed = @[SDLHMILevelBackground, SDLHMILevelFull, SDLHMILevelLimited, SDLHMILevelNone];
-
+
testPermissionUpdated = [[SDLPermissionItem alloc] init];
testPermissionUpdated.rpcName = testRPCNameAllAllowed;
testPermissionUpdated.hmiPermissions = testHMIPermissionsUpdated;
testPermissionUpdated.parameterPermissions = testParameterPermissions;
-
+
testPermissionChangeUpdate = [[SDLOnPermissionsChange alloc] init];
testPermissionChangeUpdate.permissionItem = [NSArray arrayWithObject:testPermissionUpdated];
-
+
// Send the permission update
SDLRPCNotificationNotification *updatedNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangePermissionsNotification object:nil rpcNotification:testPermissionChangeUpdate];
[[NSNotificationCenter defaultCenter] postNotification:updatedNotification];
});
-
+
it(@"should call the observer twice", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@2));
});
-
+
it(@"should have proper data in the first change dict", ^{
expect(testStatuses[0]).to(equal(@(SDLPermissionGroupStatusAllowed)));
expect(changeDicts[0].allKeys).to(contain(testRPCNameAllAllowed));
-
+
NSNumber<SDLBool> *isAllowed = changeDicts[0][testRPCNameAllAllowed];
expect(isAllowed).to(equal(@YES));
});
-
+
it(@"should have the proper data in the second change dict", ^{
expect(testStatuses[1]).to(equal(@(SDLPermissionGroupStatusDisallowed)));
expect(changeDicts[1].allKeys).to(contain(testRPCNameAllAllowed));
-
+
NSNumber<SDLBool> *isAllowed = changeDicts[1][testRPCNameAllAllowed];
expect(isAllowed).to(equal(@NO));
});
});
});
-
+
context(@"to not match an all allowed observer", ^{
beforeEach(^{
// Reset vars
numberOfTimesObserverCalled = 0;
changeDicts = [NSMutableArray array];
testStatuses = [NSMutableArray array];
-
+
// Post the notification before setting the observer to make sure data is already present
// HMI Full & Limited allowed, hmi level BACKGROUND
[[NSNotificationCenter defaultCenter] postNotification:backgroundHMINotification];
[[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
});
-
+
context(@"from mixed to disallowed", ^{
beforeEach(^{
// Set an observer that should be called immediately for the preexisting data, then called again when new data is sent
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
[testPermissionsManager addObserverForRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed] groupType:SDLPermissionGroupTypeAllAllowed withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull change, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
[changeDicts addObject:change];
[testStatuses addObject:@(status)];
}];
-
+ #pragma clang diagnostic pop
+
// Create a permission update disallowing our current HMI level for the observed permission
SDLParameterPermissions *testParameterPermissions = [[SDLParameterPermissions alloc] init];
SDLHMIPermissions *testHMIPermissionsUpdated = [[SDLHMIPermissions alloc] init];
testHMIPermissionsUpdated.allowed = @[];
testHMIPermissionsUpdated.userDisallowed = @[SDLHMILevelBackground, SDLHMILevelFull, SDLHMILevelLimited, SDLHMILevelNone];
-
+
testPermissionUpdated = [[SDLPermissionItem alloc] init];
testPermissionUpdated.rpcName = testRPCNameAllAllowed;
testPermissionUpdated.hmiPermissions = testHMIPermissionsUpdated;
testPermissionUpdated.parameterPermissions = testParameterPermissions;
-
+
testPermissionChangeUpdate = [[SDLOnPermissionsChange alloc] init];
testPermissionChangeUpdate.permissionItem = [NSArray arrayWithObject:testPermissionUpdated];
-
+
// Send the permission update
SDLRPCNotificationNotification *updatedNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangePermissionsNotification object:nil rpcNotification:testPermissionChangeUpdate];
[[NSNotificationCenter defaultCenter] postNotification:updatedNotification];
});
-
+
it(@"should call the observer with a mixed status", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@1));
expect(testStatuses[0]).to(equal(@(SDLPermissionGroupStatusMixed)));
});
});
-
+
context(@"from disallowed to mixed", ^{
beforeEach(^{
// Set an observer that should be called immediately for the preexisting data, then called again when new data is sent
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
[testPermissionsManager addObserverForRPCs:@[testRPCNameFullLimitedAllowed, testRPCNameAllDisallowed] groupType:SDLPermissionGroupTypeAllAllowed withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull change, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
[changeDicts addObject:change];
[testStatuses addObject:@(status)];
}];
-
+ #pragma clang diagnostic pop
+
// Create a permission update disallowing our current HMI level for the observed permission
SDLParameterPermissions *testParameterPermissions = [[SDLParameterPermissions alloc] init];
SDLHMIPermissions *testHMIPermissionsUpdated = [[SDLHMIPermissions alloc] init];
testHMIPermissionsUpdated.allowed = @[SDLHMILevelLimited, SDLHMILevelBackground];
testHMIPermissionsUpdated.userDisallowed = @[SDLHMILevelFull, SDLHMILevelNone];
-
+
testPermissionUpdated = [[SDLPermissionItem alloc] init];
testPermissionUpdated.rpcName = testRPCNameAllAllowed;
testPermissionUpdated.hmiPermissions = testHMIPermissionsUpdated;
testPermissionUpdated.parameterPermissions = testParameterPermissions;
-
+
testPermissionChangeUpdate = [[SDLOnPermissionsChange alloc] init];
testPermissionChangeUpdate.permissionItem = [NSArray arrayWithObject:testPermissionUpdated];
-
+
// Send the permission update
SDLRPCNotificationNotification *updatedNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangePermissionsNotification object:nil rpcNotification:testPermissionChangeUpdate];
[[NSNotificationCenter defaultCenter] postNotification:updatedNotification];
});
-
+
it(@"should call the observer", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@1));
expect(testStatuses[0]).to(equal(@(SDLPermissionGroupStatusDisallowed)));
@@ -672,173 +903,188 @@ describe(@"SDLPermissionsManager", ^{
});
});
});
-
+
context(@"updating an observer with a new HMI level", ^{
__block NSInteger numberOfTimesObserverCalled = 0;
__block NSMutableArray<NSDictionary<SDLPermissionRPCName,NSNumber *> *> *changeDicts = nil;
__block NSMutableArray<NSNumber<SDLUInt> *> *testStatuses = nil;
-
+
context(@"to match an ANY observer", ^{
beforeEach(^{
// Reset vars
numberOfTimesObserverCalled = 0;
changeDicts = [NSMutableArray array];
testStatuses = [NSMutableArray array];
-
+
// Post the notification before setting the observer to make sure data is already present
// HMI Full & Limited allowed, hmi level BACKGROUND
[[NSNotificationCenter defaultCenter] postNotification:backgroundHMINotification];
[[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
-
+
// Set an observer that should be called immediately for the preexisting data, then called again when new data is sent
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
[testPermissionsManager addObserverForRPCs:@[testRPCNameAllAllowed, testRPCNameFullLimitedAllowed] groupType:SDLPermissionGroupTypeAny withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
[changeDicts addObject:changedDict];
[testStatuses addObject:@(status)];
}];
-
+ #pragma clang diagnostic pop
+
// Upgrade the HMI level to LIMITED
[[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
});
-
+
it(@"should call the observer twice", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@2));
});
-
+
it(@"should have proper data in the first change dict", ^{
NSNumber<SDLBool> *allAllowed = changeDicts[0][testRPCNameAllAllowed];
expect(allAllowed).to(equal(@YES));
-
+
NSNumber<SDLBool> *fullLimitedAllowed = changeDicts[0][testRPCNameFullLimitedAllowed];
expect(fullLimitedAllowed).to(equal(@NO));
-
+
expect(testStatuses[0]).to(equal(@(SDLPermissionGroupStatusMixed)));
});
-
+
it(@"should have the proper data in the second change dict", ^{
NSNumber<SDLBool> *allAllowed = changeDicts[1][testRPCNameAllAllowed];
expect(allAllowed).to(equal(@YES));
-
+
NSNumber<SDLBool> *fullLimitedAllowed = changeDicts[1][testRPCNameFullLimitedAllowed];
expect(fullLimitedAllowed).to(equal(@YES));
-
+
expect(testStatuses[1]).to(equal(@(SDLPermissionGroupStatusAllowed)));
});
});
-
+
context(@"to match an all allowed observer", ^{
beforeEach(^{
// Reset vars
numberOfTimesObserverCalled = 0;
changeDicts = [NSMutableArray array];
testStatuses = [NSMutableArray array];
-
+
// Post the notification before setting the observer to make sure data is already present
// HMI Full & Limited allowed, hmi level BACKGROUND
[[NSNotificationCenter defaultCenter] postNotification:backgroundHMINotification];
[[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
});
-
+
context(@"so that it becomes All Allowed", ^{
beforeEach(^{
// Set an observer that should be called immediately for the preexisting data, then called again when new data is sent
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
[testPermissionsManager addObserverForRPCs:@[testRPCNameFullLimitedAllowed] groupType:SDLPermissionGroupTypeAllAllowed withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
[changeDicts addObject:changedDict];
[testStatuses addObject:@(status)];
}];
-
+ #pragma clang diagnostic pop
+
[[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
});
-
+
it(@"should call the observer", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@2));
-
+
expect(testStatuses[0]).to(equal(@(SDLPermissionGroupStatusDisallowed)));
expect(testStatuses[1]).to(equal(@(SDLPermissionGroupStatusAllowed)));
});
});
-
+
context(@"so that it goes from All Allowed to at least some disallowed", ^{
beforeEach(^{
// Set an observer that should be called immediately for the preexisting data, then called again when new data is sent
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
[testPermissionsManager addObserverForRPCs:@[testRPCNameFullLimitedBackgroundAllowed] groupType:SDLPermissionGroupTypeAllAllowed withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
[changeDicts addObject:changedDict];
[testStatuses addObject:@(status)];
}];
-
+ #pragma clang diagnostic pop
+
[[NSNotificationCenter defaultCenter] postNotification:noneHMINotification];
});
-
+
it(@"should call the observer twice", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@2));
});
-
+
it(@"should have proper data in the first change dict", ^{
expect(changeDicts[0].allKeys).to(contain(testRPCNameFullLimitedBackgroundAllowed));
-
+
NSNumber<SDLBool> *isAllowed = changeDicts[0][testRPCNameFullLimitedBackgroundAllowed];
expect(isAllowed).to(equal(@YES));
-
+
expect(testStatuses[0]).to(equal(@(SDLPermissionGroupStatusAllowed)));
});
-
+
it(@"should have the proper data in the second change dict", ^{
expect(changeDicts[1].allKeys).to(contain(testRPCNameFullLimitedBackgroundAllowed));
-
+
NSNumber<SDLBool> *isAllowed = changeDicts[1][testRPCNameFullLimitedBackgroundAllowed];
expect(isAllowed).to(equal(@NO));
-
+
expect(testStatuses[1]).to(equal(@(SDLPermissionGroupStatusDisallowed)));
});
});
});
-
+
context(@"to not match an all allowed observer", ^{
beforeEach(^{
// Reset vars
numberOfTimesObserverCalled = 0;
changeDicts = [NSMutableArray array];
testStatuses = [NSMutableArray array];
-
+
// Post the notification before setting the observer to make sure data is already present
// HMI Full & Limited allowed, hmi level BACKGROUND
[[NSNotificationCenter defaultCenter] postNotification:backgroundHMINotification];
[[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
});
-
+
context(@"that goes from disallowed to mixed", ^{
beforeEach(^{
// Set an observer that should be called immediately for the preexisting data, then called again when new data is sent
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
[testPermissionsManager addObserverForRPCs:@[testRPCNameFullLimitedAllowed, testRPCNameAllDisallowed] groupType:SDLPermissionGroupTypeAllAllowed withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
[changeDicts addObject:changedDict];
[testStatuses addObject:@(status)];
}];
-
+ #pragma clang diagnostic pop
+
[[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
});
-
+
it(@"should call the observer", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@1));
-
+
expect(testStatuses[0]).to(equal(@(SDLPermissionGroupStatusDisallowed)));
});
});
-
+
context(@"that goes from mixed to disallowed", ^{
beforeEach(^{
// Set an observer that should be called immediately for the preexisting data, then called again when new data is sent
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
[testPermissionsManager addObserverForRPCs:@[testRPCNameFullLimitedAllowed, testRPCNameFullLimitedBackgroundAllowed] groupType:SDLPermissionGroupTypeAllAllowed withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
[changeDicts addObject:changedDict];
[testStatuses addObject:@(status)];
}];
-
+ #pragma clang diagnostic pop
+
[[NSNotificationCenter defaultCenter] postNotification:noneHMINotification];
});
-
+
it(@"should call the observer", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@1));
expect(testStatuses[0]).to(equal(@(SDLPermissionGroupStatusMixed)));
@@ -847,86 +1093,95 @@ describe(@"SDLPermissionsManager", ^{
});
});
});
-
+
describe(@"removing observers", ^{
context(@"removing the only observer", ^{
__block NSInteger numberOfTimesObserverCalled = 0;
-
+
beforeEach(^{
// Reset vars
numberOfTimesObserverCalled = 0;
-
+
// Add two observers
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSUUID *observerId = [testPermissionsManager addObserverForRPCs:@[testRPCNameAllAllowed, testRPCNameFullLimitedAllowed] groupType:SDLPermissionGroupTypeAny withHandler:^(NSDictionary<SDLPermissionRPCName, NSNumber *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
}];
-
+ #pragma clang diagnostic pop
+
// Remove one observer
[testPermissionsManager removeObserverForIdentifier:observerId];
-
+
// Post a notification
[[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
[[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
});
-
+
it(@"should only call the observer once", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@1));
});
});
-
+
context(@"removing a single observer and leaving one remaining", ^{
__block NSUInteger numberOfTimesObserverCalled = 0;
-
+
beforeEach(^{
// Reset vars
numberOfTimesObserverCalled = 0;
-
+
// Add two observers
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSUUID *testRemovedObserverId = [testPermissionsManager addObserverForRPCs:@[testRPCNameAllAllowed, testRPCNameFullLimitedAllowed] groupType:SDLPermissionGroupTypeAny withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
}];
-
+
[testPermissionsManager addObserverForRPCs:@[testRPCNameAllAllowed, testRPCNameFullLimitedAllowed] groupType:SDLPermissionGroupTypeAny withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
}];
-
+ #pragma clang diagnostic pop
+
// Remove one observer
[testPermissionsManager removeObserverForIdentifier:testRemovedObserverId];
-
+
// Post a notification
[[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
[[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
});
-
+
it(@"should call three observers", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@3));
});
});
-
+
context(@"removing all observers", ^{
__block NSInteger numberOfTimesObserverCalled = 0;
-
+
beforeEach(^{
// Reset vars
numberOfTimesObserverCalled = 0;
-
+
// Add two observers
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
[testPermissionsManager addObserverForRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed] groupType:SDLPermissionGroupTypeAny withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
}];
-
+
[testPermissionsManager addObserverForRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed] groupType:SDLPermissionGroupTypeAny withHandler:^(NSDictionary<SDLPermissionRPCName,NSNumber *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {
numberOfTimesObserverCalled++;
}];
-
+ #pragma clang diagnostic pop
+
// Remove all observers
[testPermissionsManager removeAllObservers];
-
+
// Add some permissions
[[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification];
[[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification];
});
-
+
it(@"should not call the observer", ^{
expect(@(numberOfTimesObserverCalled)).to(equal(@2));
});