summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2016-11-01 14:13:33 -0400
committerJoel Fischer <joeljfischer@gmail.com>2016-11-01 14:13:33 -0400
commit0fffcc41092e7899b4e5721ce31f6fb396174422 (patch)
tree55565820d70813beaa29c9250eb90f235004b440
parent53c4942669885557722d9b8baa51b6703016b2c7 (diff)
downloadsdl_ios-0fffcc41092e7899b4e5721ce31f6fb396174422.tar.gz
Update the example app to log out example permissions
* Change Permission manager to remove some `*`s
-rw-r--r--SmartDeviceLink/SDLPermissionConstants.h6
-rw-r--r--SmartDeviceLink/SDLPermissionFilter.h8
-rw-r--r--SmartDeviceLink/SDLPermissionFilter.m6
-rw-r--r--SmartDeviceLink/SDLPermissionManager.h10
-rw-r--r--SmartDeviceLink/SDLPermissionManager.m20
-rw-r--r--SmartDeviceLink_Example/Classes/ProxyManager.m26
6 files changed, 51 insertions, 25 deletions
diff --git a/SmartDeviceLink/SDLPermissionConstants.h b/SmartDeviceLink/SDLPermissionConstants.h
index d5e0250b0..80a123132 100644
--- a/SmartDeviceLink/SDLPermissionConstants.h
+++ b/SmartDeviceLink/SDLPermissionConstants.h
@@ -12,8 +12,8 @@
NS_ASSUME_NONNULL_BEGIN
-typedef NSString SDLPermissionRPCName;
-typedef NSUUID SDLPermissionObserverIdentifier;
+typedef NSString * SDLPermissionRPCName;
+typedef NSUUID * SDLPermissionObserverIdentifier;
/**
* A permission group type which will be used to tell the system what type of changes you want to be notified about for the group.
@@ -57,6 +57,6 @@ typedef NS_ENUM(NSUInteger, SDLPermissionGroupStatus) {
* @param change A dictionary of permission changes containing <key(String): 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 (^SDLPermissionsChangedHandler)(NSDictionary<SDLPermissionRPCName *, NSNumber<SDLBool> *> *_Nonnull change, SDLPermissionGroupStatus status);
+typedef void (^SDLPermissionsChangedHandler)(NSDictionary<SDLPermissionRPCName, NSNumber<SDLBool> *> *_Nonnull change, SDLPermissionGroupStatus status);
NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/SDLPermissionFilter.h b/SmartDeviceLink/SDLPermissionFilter.h
index 56c7de185..1a89cb876 100644
--- a/SmartDeviceLink/SDLPermissionFilter.h
+++ b/SmartDeviceLink/SDLPermissionFilter.h
@@ -18,12 +18,12 @@ NS_ASSUME_NONNULL_BEGIN
/**
* An identifier for the permission filter to allow it to be removed at a later time.
*/
-@property (copy, nonatomic, readonly) SDLPermissionObserverIdentifier *identifier;
+@property (copy, nonatomic, readonly) SDLPermissionObserverIdentifier identifier;
/**
* All of the RPC names in this filter group.
*/
-@property (copy, nonatomic, readonly) NSArray<SDLPermissionRPCName *> *rpcNames;
+@property (copy, nonatomic, readonly) NSArray<SDLPermissionRPCName> *rpcNames;
/**
* The type of this filter group.
@@ -44,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return An instance of `SDLPermissionFilter`.
*/
-- (instancetype)initWithRPCNames:(NSArray<SDLPermissionRPCName *> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionsChangedHandler)handler NS_DESIGNATED_INITIALIZER;
+- (instancetype)initWithRPCNames:(NSArray<SDLPermissionRPCName> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionsChangedHandler)handler NS_DESIGNATED_INITIALIZER;
/**
* Create a new permission filter group.
@@ -55,7 +55,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return An instance of `SDLPermissionFilter`.
*/
-+ (instancetype)filterWithRPCNames:(NSArray<SDLPermissionRPCName *> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionsChangedHandler)handler;
++ (instancetype)filterWithRPCNames:(NSArray<SDLPermissionRPCName> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionsChangedHandler)handler;
/**
* Whether the current filter is equivalent with another filter or not.
diff --git a/SmartDeviceLink/SDLPermissionFilter.m b/SmartDeviceLink/SDLPermissionFilter.m
index 24ad0ff59..0d142b3a3 100644
--- a/SmartDeviceLink/SDLPermissionFilter.m
+++ b/SmartDeviceLink/SDLPermissionFilter.m
@@ -19,11 +19,11 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init {
return [self initWithRPCNames:@[]
groupType:SDLPermissionGroupTypeAny
- observer:^(NSDictionary<SDLPermissionRPCName *, NSNumber<SDLBool> *> *_Nonnull change, SDLPermissionGroupStatus status){
+ observer:^(NSDictionary<SDLPermissionRPCName, NSNumber<SDLBool> *> *_Nonnull change, SDLPermissionGroupStatus status){
}];
}
-- (instancetype)initWithRPCNames:(NSArray<SDLPermissionRPCName *> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionsChangedHandler)observer {
+- (instancetype)initWithRPCNames:(NSArray<SDLPermissionRPCName> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionsChangedHandler)observer {
self = [super init];
if (!self) {
return nil;
@@ -37,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-+ (instancetype)filterWithRPCNames:(NSArray<SDLPermissionRPCName *> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionsChangedHandler)observer {
++ (instancetype)filterWithRPCNames:(NSArray<SDLPermissionRPCName> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionsChangedHandler)observer {
return [[self alloc] initWithRPCNames:rpcNames groupType:groupType observer:observer];
}
diff --git a/SmartDeviceLink/SDLPermissionManager.h b/SmartDeviceLink/SDLPermissionManager.h
index 78d851f84..5aea0c81d 100644
--- a/SmartDeviceLink/SDLPermissionManager.h
+++ b/SmartDeviceLink/SDLPermissionManager.h
@@ -37,7 +37,7 @@ 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;
/**
* Determine if all RPCs are allowed for the current HMI level
@@ -46,7 +46,7 @@ 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;
/**
* 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
@@ -55,7 +55,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return A dictionary specifying if the passed in RPC names are currently allowed or not
*/
-- (NSDictionary<SDLPermissionRPCName *, NSNumber<SDLBool> *> *)statusOfRPCs:(NSArray<SDLPermissionRPCName *> *)rpcNames;
+- (NSDictionary<SDLPermissionRPCName, NSNumber<SDLBool> *> *)statusOfRPCs:(NSArray<SDLPermissionRPCName> *)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.
@@ -70,7 +70,7 @@ 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;
/**
* Remove every current observer
@@ -82,7 +82,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @param identifier The identifier specifying which observer to remove
*/
-- (void)removeObserverForIdentifier:(SDLPermissionObserverIdentifier *)identifier;
+- (void)removeObserverForIdentifier:(SDLPermissionObserverIdentifier)identifier;
@end
diff --git a/SmartDeviceLink/SDLPermissionManager.m b/SmartDeviceLink/SDLPermissionManager.m
index 5939738ff..a6898ee55 100644
--- a/SmartDeviceLink/SDLPermissionManager.m
+++ b/SmartDeviceLink/SDLPermissionManager.m
@@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLPermissionManager ()
-@property (copy, nonatomic) NSMutableDictionary<SDLPermissionRPCName *, SDLPermissionItem *> *permissions;
+@property (copy, nonatomic) NSMutableDictionary<SDLPermissionRPCName, SDLPermissionItem *> *permissions;
@property (copy, nonatomic) NSMutableArray<SDLPermissionFilter *> *filters;
@property (copy, nonatomic, nullable) SDLHMILevel *currentHMILevel;
@@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
}
_currentHMILevel = nil;
- _permissions = [NSMutableDictionary<SDLPermissionRPCName *, SDLPermissionItem *> dictionary];
+ _permissions = [NSMutableDictionary<SDLPermissionRPCName, SDLPermissionItem *> dictionary];
_filters = [NSMutableArray<SDLPermissionFilter *> array];
// Set up SDL status notifications
@@ -71,7 +71,7 @@ NS_ASSUME_NONNULL_BEGIN
return [item.hmiPermissions.allowed containsObject:self.currentHMILevel];
}
-- (SDLPermissionGroupStatus)groupStatusOfRPCs:(NSArray<SDLPermissionRPCName *> *)rpcNames {
+- (SDLPermissionGroupStatus)groupStatusOfRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames {
if (self.currentHMILevel == nil) {
return SDLPermissionGroupStatusUnknown;
}
@@ -79,7 +79,7 @@ NS_ASSUME_NONNULL_BEGIN
return [self.class sdl_groupStatusOfRPCs:rpcNames withPermissions:[self.permissions copy] hmiLevel:self.currentHMILevel];
}
-+ (SDLPermissionGroupStatus)sdl_groupStatusOfRPCs:(NSArray<SDLPermissionRPCName *> *)rpcNames withPermissions:(NSDictionary<SDLPermissionRPCName *, SDLPermissionItem *> *)permissions hmiLevel:(SDLHMILevel *)hmiLevel {
++ (SDLPermissionGroupStatus)sdl_groupStatusOfRPCs:(NSArray<SDLPermissionRPCName> *)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;
@@ -118,8 +118,8 @@ NS_ASSUME_NONNULL_BEGIN
}
}
-- (NSDictionary<SDLPermissionRPCName *, NSNumber<SDLBool> *> *)statusOfRPCs:(NSArray<SDLPermissionRPCName *> *)rpcNames {
- NSMutableDictionary<SDLPermissionRPCName *, NSNumber<SDLBool> *> *permissionAllowedDict = [NSMutableDictionary dictionary];
+- (NSDictionary<SDLPermissionRPCName, NSNumber<SDLBool> *> *)statusOfRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames {
+ NSMutableDictionary<SDLPermissionRPCName, NSNumber<SDLBool> *> *permissionAllowedDict = [NSMutableDictionary dictionary];
for (NSString *rpcName in rpcNames) {
BOOL allowed = [self isRPCAllowed:rpcName];
@@ -134,7 +134,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark Add Observers
-- (SDLPermissionObserverIdentifier *)addObserverForRPCs:(NSArray<SDLPermissionRPCName *> *)rpcNames groupType:(SDLPermissionGroupType)groupType withHandler:(nonnull SDLPermissionsChangedHandler)handler {
+- (SDLPermissionObserverIdentifier)addObserverForRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames groupType:(SDLPermissionGroupType)groupType withHandler:(nonnull SDLPermissionsChangedHandler)handler {
SDLPermissionFilter *filter = [SDLPermissionFilter filterWithRPCNames:rpcNames groupType:groupType observer:handler];
// Store the filter for later use
@@ -148,7 +148,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)sdl_callFilterObserver:(SDLPermissionFilter *)filter {
SDLPermissionGroupStatus permissionStatus = [self groupStatusOfRPCs:filter.rpcNames];
- NSDictionary<SDLPermissionRPCName *, NSNumber<SDLBool> *> *allowedDict = [self statusOfRPCs:filter.rpcNames];
+ NSDictionary<SDLPermissionRPCName, NSNumber<SDLBool> *> *allowedDict = [self statusOfRPCs:filter.rpcNames];
filter.handler(allowedDict, permissionStatus);
}
@@ -159,7 +159,7 @@ NS_ASSUME_NONNULL_BEGIN
[self.filters removeAllObjects];
}
-- (void)removeObserverForIdentifier:(SDLPermissionObserverIdentifier *)identifier {
+- (void)removeObserverForIdentifier:(SDLPermissionObserverIdentifier)identifier {
NSArray<SDLPermissionFilter *> *filters = [self.filters copy];
for (int i = 0; i < filters.count; i++) {
@@ -189,7 +189,7 @@ NS_ASSUME_NONNULL_BEGIN
NSArray<SDLPermissionFilter *> *modifiedFilters = [self.class sdl_filterPermissionChangesForFilters:currentFilters updatedPermissions:newPermissionItems];
// We need the old group status and new group status for all allowed filters so we know if they should be called
- NSDictionary<SDLPermissionObserverIdentifier *, NSNumber<SDLInt> *> *allAllowedFiltersWithOldStatus = [self sdl_currentStatusForFilters:modifiedFilters];
+ NSDictionary<SDLPermissionObserverIdentifier, NSNumber<SDLInt> *> *allAllowedFiltersWithOldStatus = [self sdl_currentStatusForFilters:modifiedFilters];
// Set the updated permissions on our stored permissions object
for (SDLPermissionItem *item in newPermissionItems) {
diff --git a/SmartDeviceLink_Example/Classes/ProxyManager.m b/SmartDeviceLink_Example/Classes/ProxyManager.m
index 6b39f88dc..55dbe2a3a 100644
--- a/SmartDeviceLink_Example/Classes/ProxyManager.m
+++ b/SmartDeviceLink_Example/Classes/ProxyManager.m
@@ -97,6 +97,8 @@ NS_ASSUME_NONNULL_BEGIN
} else {
[weakSelf sdlex_updateProxyState:ProxyStateConnected];
}
+
+ [self setupPermissionsCallbacks];
if ([weakSelf.sdlManager.hmiLevel isEqualToEnum:[SDLHMILevel FULL]]) {
[weakSelf showInitialData];
@@ -123,6 +125,30 @@ NS_ASSUME_NONNULL_BEGIN
[self.sdlManager sendRequest:show];
}
+- (void)setupPermissionsCallbacks {
+ // This will tell you whether or not you can use the Show RPC right at this moment
+ BOOL isAvailable = [self.sdlManager.permissionManager isRPCAllowed:@"Show"];
+ NSLog(@"Show is allowed? %@", @(isAvailable));
+
+ // This will set up a block that will tell you whether or not you can use none, all, or some of the RPCs specified, and notifies you when those permissions change
+ SDLPermissionObserverIdentifier observerId = [self.sdlManager.permissionManager addObserverForRPCs:@[@"Show", @"Alert"] groupType:SDLPermissionGroupTypeAllAllowed withHandler:^(NSDictionary<SDLPermissionRPCName, NSNumber<SDLBool> *> * _Nonnull change, SDLPermissionGroupStatus status) {
+ NSLog(@"Show changed permission to status: %@, dict: %@", @(status), change);
+ }];
+ // The above block will be called immediately, this will then remove the block from being called any more
+ [self.sdlManager.permissionManager removeObserverForIdentifier:observerId];
+
+ // This will give us the current status of the group of RPCs, as if we had set up an observer, except these are one-shot calls
+ NSArray *rpcGroup =@[@"AddCommand", @"PerformInteraction"];
+ SDLPermissionGroupStatus commandPICSStatus = [self.sdlManager.permissionManager groupStatusOfRPCs:rpcGroup];
+ NSDictionary *commandPICSStatusDict = [self.sdlManager.permissionManager statusOfRPCs:rpcGroup];
+ NSLog(@"Command / PICS status: %@, dict: %@", @(commandPICSStatus), commandPICSStatusDict);
+
+ // This will set up a long-term observer for the RPC group and will tell us when the status of any specified RPC changes (due to the `SDLPermissionGroupTypeAny`) option.
+ [self.sdlManager.permissionManager addObserverForRPCs:rpcGroup groupType:SDLPermissionGroupTypeAny withHandler:^(NSDictionary<SDLPermissionRPCName, NSNumber<SDLBool> *> * _Nonnull change, SDLPermissionGroupStatus status) {
+ NSLog(@"Command / PICS changed permission to status: %@, dict: %@", @(status), change);
+ }];
+}
+
+ (SDLLifecycleConfiguration *)setLifecycleConfigurationPropertiesOnConfiguration:(SDLLifecycleConfiguration *)config {
SDLArtwork *appIconArt = [SDLArtwork persistentArtworkWithImage:[UIImage imageNamed:@"AppIcon60x60@2x"] name:@"AppIcon" asImageFormat:SDLArtworkImageFormatPNG];