summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlapinskijw <jlapinski.dev@gmail.com>2020-06-02 15:41:19 -0400
committerlapinskijw <jlapinski.dev@gmail.com>2020-06-02 15:41:19 -0400
commit43084914c4b15a2fe95aea9548d650a4edcca2d9 (patch)
tree6069a2e5cc80cd44f8b3d4f183d5dbc9cf490e64
parent3255217b32bf0bd5213fb0684b2ba6e9ef859db0 (diff)
downloadsdl_ios-43084914c4b15a2fe95aea9548d650a4edcca2d9.tar.gz
added new observer method to align behavior with Java team
-rw-r--r--SmartDeviceLink/SDLPermissionManager.h15
-rw-r--r--SmartDeviceLink/SDLPermissionManager.m9
2 files changed, 24 insertions, 0 deletions
diff --git a/SmartDeviceLink/SDLPermissionManager.h b/SmartDeviceLink/SDLPermissionManager.h
index 78866fc90..804803714 100644
--- a/SmartDeviceLink/SDLPermissionManager.h
+++ b/SmartDeviceLink/SDLPermissionManager.h
@@ -79,6 +79,21 @@ NS_ASSUME_NONNULL_BEGIN
- (SDLPermissionObserverIdentifier)addObserverForRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames groupType:(SDLPermissionGroupType)groupType withHandler:(SDLPermissionsChangedHandler)handler;
/**
+* Add an observer for specified RPC names, with a callback that will be called whenever the value changes. Unlike addObserverForRPCs:groupType:withHandler:, the callback will not return immediately with the current status and will wait for the permissions changes specified in the groupType param.
+*
+* @warning This block will be captured by the SDLPermissionsManager, be sure to use [weakself/strongself](http://www.logicsector.com/ios/avoiding-objc-retain-cycles-with-weakself-and-strongself-the-easy-way/) if you are referencing self within your observer block.
+*
+* @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)addStrictObserverForRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames groupType:(SDLPermissionGroupType)groupType withHandler:(SDLPermissionsChangedHandler)handler;
+
+/**
* Remove every current observer
*/
- (void)removeAllObservers;
diff --git a/SmartDeviceLink/SDLPermissionManager.m b/SmartDeviceLink/SDLPermissionManager.m
index cdb08e135..bedf9e266 100644
--- a/SmartDeviceLink/SDLPermissionManager.m
+++ b/SmartDeviceLink/SDLPermissionManager.m
@@ -149,6 +149,15 @@ NS_ASSUME_NONNULL_BEGIN
return filter.identifier;
}
+- (SDLPermissionObserverIdentifier)addStrictObserverForRPCs:(NSArray<SDLPermissionRPCName> *)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];
+
+ return filter.identifier;
+}
+
- (void)sdl_callFilterObserver:(SDLPermissionFilter *)filter {
SDLPermissionGroupStatus permissionStatus = [self groupStatusOfRPCs:filter.rpcNames];
NSDictionary<SDLPermissionRPCName, NSNumber *> *allowedDict = [self statusOfRPCs:filter.rpcNames];