summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlapinskijw <jlapinski.dev@gmail.com>2020-06-03 16:39:23 -0400
committerlapinskijw <jlapinski.dev@gmail.com>2020-06-03 16:39:23 -0400
commite253ff993dc0b23d1efe9909caf6364309431b34 (patch)
treeb8510100fa014880aa2605de732696dedade09e4
parent40cf42944867e60798c4e67969fca3ee58883fd5 (diff)
downloadsdl_ios-e253ff993dc0b23d1efe9909caf6364309431b34.tar.gz
implemented newly created methods and replaced deprecrated method calls internally in permissions manager
-rw-r--r--Example Apps/Example Swift/ProxyManager.swift11
-rw-r--r--SmartDeviceLink/SDLPermissionManager.h2
-rw-r--r--SmartDeviceLink/SDLPermissionManager.m48
3 files changed, 54 insertions, 7 deletions
diff --git a/Example Apps/Example Swift/ProxyManager.swift b/Example Apps/Example Swift/ProxyManager.swift
index 4238251bf..8d48bfe39 100644
--- a/Example Apps/Example Swift/ProxyManager.swift
+++ b/Example Apps/Example Swift/ProxyManager.swift
@@ -139,7 +139,16 @@ private extension ProxyManager {
self.vehicleDataManager = VehicleDataManager(sdlManager: self.sdlManager, refreshUIHandler: self.refreshUIHandler)
self.performInteractionManager = PerformInteractionManager(sdlManager: self.sdlManager)
- RPCPermissionsManager.setupPermissionsCallbacks(with: self.sdlManager)
+// RPCPermissionsManager.setupPermissionsCallbacks(with: self.sdlManager)
+ let permissionsManager = self.sdlManager.permissionManager
+// permissionsManager.subscribe(toRPCs: [SDLRPCFunctionName.addCommand], groupType: .allAllowed) { (dict, status) in
+// print("SUBSCRIBE TO RPCS CALLED")
+// }
+
+ permissionsManager.addObserver(forRPCs: ["PerformInteraction"], groupType: .allAllowed) { (dict, status) in
+ print("AddOBSERVER TO RPCS CALLED")
+ print("STATUS IS \(dict["PerformInteraction"])")
+ }
SDLLog.d("SDL file manager storage: \(self.sdlManager.fileManager.bytesAvailable / 1024 / 1024) mb")
})
diff --git a/SmartDeviceLink/SDLPermissionManager.h b/SmartDeviceLink/SDLPermissionManager.h
index 9ed9f3aa9..0f111d2c6 100644
--- a/SmartDeviceLink/SDLPermissionManager.h
+++ b/SmartDeviceLink/SDLPermissionManager.h
@@ -119,7 +119,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return An identifier that can be passed to removeObserverForIdentifer: to remove the observer
*/
-- (SDLPermissionObserverIdentifier)subscribeToRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames groupType:(SDLPermissionGroupType)groupType withHandler:(SDLPermissionsChangedHandler)handler;
+- (SDLPermissionObserverIdentifier)subscribeToRPCs:(NSArray<SDLRPCFunctionName> *)rpcNames groupType:(SDLPermissionGroupType)groupType withHandler:(SDLPermissionsChangedHandler)handler;
/**
* Remove every current observer
diff --git a/SmartDeviceLink/SDLPermissionManager.m b/SmartDeviceLink/SDLPermissionManager.m
index c56919d6b..02269d765 100644
--- a/SmartDeviceLink/SDLPermissionManager.m
+++ b/SmartDeviceLink/SDLPermissionManager.m
@@ -74,6 +74,16 @@ NS_ASSUME_NONNULL_BEGIN
return [item.hmiPermissions.allowed containsObject:self.currentHMILevel];
}
+- (BOOL)isRPCNameAllowed:(SDLRPCFunctionName)rpcName {
+ if (self.permissions[rpcName] == nil || self.currentHMILevel == nil) {
+ return NO;
+ }
+
+ // to do
+ SDLPermissionItem *item = self.permissions[rpcName];
+ return [item.hmiPermissions.allowed containsObject:self.currentHMILevel];
+}
+
- (SDLPermissionGroupStatus)groupStatusOfRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames {
if (self.currentHMILevel == nil) {
return SDLPermissionGroupStatusUnknown;
@@ -82,6 +92,15 @@ NS_ASSUME_NONNULL_BEGIN
return [self.class sdl_groupStatusOfRPCs:rpcNames withPermissions:[self.permissions copy] hmiLevel:self.currentHMILevel];
}
+- (SDLPermissionGroupStatus)groupStatusOfRPCNames:(NSArray<SDLRPCFunctionName> *)rpcNames {
+ if (self.currentHMILevel == nil) {
+ return SDLPermissionGroupStatusUnknown;
+ }
+
+ // to do double check this
+ 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 {
// If we don't have an HMI level, then just say everything is disallowed
if (hmiLevel == nil) {
@@ -132,6 +151,17 @@ NS_ASSUME_NONNULL_BEGIN
return [permissionAllowedDict copy];
}
+- (NSDictionary<SDLPermissionRPCName,NSNumber *> *)statusOfRPCNames:(NSArray<SDLRPCFunctionName> *)rpcNames {
+ NSMutableDictionary<SDLPermissionRPCName, NSNumber *> *permissionAllowedDict = [NSMutableDictionary dictionary];
+ // to do
+ for (NSString *rpcName in rpcNames) {
+ BOOL allowed = [self isRPCNameAllowed:rpcName];
+ permissionAllowedDict[rpcName] = @(allowed);
+ }
+
+ return [permissionAllowedDict copy];
+}
+
#pragma mark - Permissions observers
@@ -149,7 +179,7 @@ NS_ASSUME_NONNULL_BEGIN
return filter.identifier;
}
-- (SDLPermissionObserverIdentifier)subscribeToRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames groupType:(SDLPermissionGroupType)groupType withHandler:(SDLPermissionsChangedHandler)handler {
+- (SDLPermissionObserverIdentifier)subscribeToRPCs:(NSArray<SDLRPCFunctionName> *)rpcNames groupType:(SDLPermissionGroupType)groupType withHandler:(SDLPermissionsChangedHandler)handler {
SDLPermissionFilter *filter = [SDLPermissionFilter filterWithRPCNames:rpcNames groupType:groupType observer:handler];
// Store the filter for later use
@@ -159,8 +189,8 @@ NS_ASSUME_NONNULL_BEGIN
}
- (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 statusOfRPCNames:filter.rpcNames];
filter.handler(allowedDict, permissionStatus);
}
@@ -212,7 +242,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) {
@@ -322,7 +352,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]);
}
}
@@ -383,6 +413,14 @@ NS_ASSUME_NONNULL_BEGIN
return NO;
}
+- (BOOL)rpcNameRequiresEncryption:(SDLRPCFunctionName)rpcName {
+ // to do
+ if (self.permissions[rpcName].requireEncryption != nil) {
+ return self.permissions[rpcName].requireEncryption.boolValue;
+ }
+ return NO;
+}
+
@end
NS_ASSUME_NONNULL_END