diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2020-03-04 14:05:11 -0500 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2020-03-04 14:05:11 -0500 |
commit | a19da1adacc89e3b6cd8e2df4858a5edaceaa87b (patch) | |
tree | 759ee8d27aab9ac95b3c8bd1fa437c406424fe28 | |
parent | 72a4e96b366c7e1e3e1f35ec4bb75b6eb7531a6d (diff) | |
download | sdl_ios-a19da1adacc89e3b6cd8e2df4858a5edaceaa87b.tar.gz |
Fixes to soft button manager and tests
* If we don't have soft button capabilities, suspend the transaction queue
-rw-r--r-- | SmartDeviceLink/SDLSoftButtonManager.m | 43 | ||||
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m | 60 |
2 files changed, 73 insertions, 30 deletions
diff --git a/SmartDeviceLink/SDLSoftButtonManager.m b/SmartDeviceLink/SDLSoftButtonManager.m index a8dd84629..6a676bf14 100644 --- a/SmartDeviceLink/SDLSoftButtonManager.m +++ b/SmartDeviceLink/SDLSoftButtonManager.m @@ -100,12 +100,21 @@ NS_ASSUME_NONNULL_BEGIN return queue; } +- (void)sdl_updateTransactionQueueSuspended { + if (self.windowCapability.softButtonCapabilities == nil || self.windowCapability.softButtonCapabilities.count == 0 || [self.currentLevel isEqualToEnum:SDLHMILevelNone]) { + self.transactionQueue.suspended = YES; + } else { + self.transactionQueue.suspended = NO; + } +} + #pragma mark - Sending Soft Buttons - (void)setSoftButtonObjects:(NSArray<SDLSoftButtonObject *> *)softButtonObjects { // Only update if something changed. This prevents, for example, an empty array being reset if (_softButtonObjects == softButtonObjects) { + SDLLogD(@"Set soft button objects are equivalent to existing soft button objects, skipping..."); return; } @@ -128,7 +137,8 @@ NS_ASSUME_NONNULL_BEGIN _softButtonObjects = softButtonObjects; - SDLSoftButtonReplaceOperation *op = [[SDLSoftButtonReplaceOperation alloc] initWithConnectionManager:self.connectionManager fileManager:self.fileManager capabilities:self.windowCapability.softButtonCapabilities.firstObject softButtonObjects:_softButtonObjects mainField1:self.currentMainField1]; + // We assume that all soft button capabilities are the same, so we only need to send one + SDLSoftButtonReplaceOperation *op = [[SDLSoftButtonReplaceOperation alloc] initWithConnectionManager:self.connectionManager fileManager:self.fileManager capabilities:self.windowCapability.softButtonCapabilities[0] softButtonObjects:_softButtonObjects mainField1:self.currentMainField1]; if (self.isBatchingUpdates) { [self.batchQueue removeAllObjects]; @@ -194,14 +204,26 @@ NS_ASSUME_NONNULL_BEGIN } } - -#pragma mark - RPC Responses +#pragma mark - Observers - (void)sdl_displayCapabilityDidUpdate:(SDLSystemCapability *)systemCapability { - self.windowCapability = self.systemCapabilityManager.defaultMainWindowCapability; + NSArray<SDLDisplayCapability *> *capabilities = systemCapability.displayCapabilities; + if (capabilities == nil || capabilities.count == 0) { + self.windowCapability = nil; + } else { + SDLDisplayCapability *mainDisplay = capabilities[0]; + for (SDLWindowCapability *windowCapability in mainDisplay.windowCapabilities) { + NSUInteger currentWindowID = windowCapability.windowID != nil ? windowCapability.windowID.unsignedIntegerValue : SDLPredefinedWindowsDefaultWindow; + if (currentWindowID == SDLPredefinedWindowsDefaultWindow) { + self.windowCapability = windowCapability; + } + } + } + + [self sdl_updateTransactionQueueSuspended]; // Auto-send an updated Show to account for changes to the capabilities - if (self.softButtonObjects.count > 0) { + if (self.softButtonObjects.count > 0 && self.windowCapability.softButtonCapabilities != nil) { SDLSoftButtonReplaceOperation *op = [[SDLSoftButtonReplaceOperation alloc] initWithConnectionManager:self.connectionManager fileManager:self.fileManager capabilities:self.windowCapability.softButtonCapabilities.firstObject softButtonObjects:self.softButtonObjects mainField1:self.currentMainField1]; [self.transactionQueue addOperation:op]; } @@ -213,17 +235,10 @@ NS_ASSUME_NONNULL_BEGIN if (hmiStatus.windowID != nil && hmiStatus.windowID.integerValue != SDLPredefinedWindowsDefaultWindow) { return; } - - SDLHMILevel oldHMILevel = self.currentLevel; - if (![oldHMILevel isEqualToEnum:hmiStatus.hmiLevel]) { - if ([hmiStatus.hmiLevel isEqualToEnum:SDLHMILevelNone]) { - self.transactionQueue.suspended = YES; - } else { - self.transactionQueue.suspended = NO; - } - } self.currentLevel = hmiStatus.hmiLevel; + + [self sdl_updateTransactionQueueSuspended]; } @end diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m index 6534b49df..27fdb99e6 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m @@ -4,9 +4,13 @@ #import "SDLArtwork.h" #import "SDLDisplayCapabilities.h" +#import "SDLDisplayCapability.h" #import "SDLFileManager.h" #import "SDLHMILevel.h" #import "SDLImage.h" +#import "SDLNotificationConstants.h" +#import "SDLOnHMIStatus.h" +#import "SDLRPCNotificationNotification.h" #import "SDLShow.h" #import "SDLSoftButton.h" #import "SDLSoftButtonCapabilities.h" @@ -15,7 +19,9 @@ #import "SDLSoftButtonReplaceOperation.h" #import "SDLSoftButtonState.h" #import "SDLSoftButtonTransitionOperation.h" +#import "SDLSystemCapability.h" #import "SDLSystemCapabilityManager.h" +#import "SDLWindowCapability.h" #import "TestConnectionManager.h" @interface SDLSoftButtonObject() @@ -34,11 +40,14 @@ @property (strong, nonatomic) NSOperationQueue *transactionQueue; -@property (strong, nonatomic, nullable, readonly) SDLWindowCapability *windowCapability; +@property (strong, nonatomic, nullable, readwrite) SDLWindowCapability *windowCapability; @property (copy, nonatomic, nullable) SDLHMILevel currentLevel; @property (strong, nonatomic) NSMutableArray<SDLAsynchronousOperation *> *batchQueue; +- (void)sdl_hmiStatusNotification:(SDLRPCNotificationNotification *)notification; +- (void)sdl_displayCapabilityDidUpdate:(SDLSystemCapability *)systemCapability; + @end QuickSpecBegin(SDLSoftButtonManagerSpec) @@ -75,8 +84,20 @@ describe(@"a soft button manager", ^{ testManager = [[SDLSoftButtonManager alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager systemCapabilityManager:testSystemCapabilityManager]; [testManager start]; - expect(testManager.currentLevel).to(beNil()); - testManager.currentLevel = SDLHMILevelFull; + SDLOnHMIStatus *status = [[SDLOnHMIStatus alloc] init]; + status.hmiLevel = SDLHMILevelFull; + [testManager sdl_hmiStatusNotification:[[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeHMIStatusNotification object:nil rpcNotification:status]]; + + SDLSoftButtonCapabilities *softButtonCapabilities = [[SDLSoftButtonCapabilities alloc] init]; + softButtonCapabilities.imageSupported = @YES; + softButtonCapabilities.textSupported = @YES; + softButtonCapabilities.longPressAvailable = @YES; + softButtonCapabilities.shortPressAvailable = @YES; + + SDLWindowCapability *windowCapability = [[SDLWindowCapability alloc] init]; + windowCapability.softButtonCapabilities = @[softButtonCapabilities]; + SDLDisplayCapability *displayCapability = [[SDLDisplayCapability alloc] initWithDisplayName:@"TEST" windowTypeSupported:nil windowCapabilities:@[windowCapability]]; + [testManager sdl_displayCapabilityDidUpdate:[[SDLSystemCapability alloc] initWithDisplayCapabilities:@[displayCapability]]]; }); it(@"should instantiate correctly", ^{ @@ -85,13 +106,21 @@ describe(@"a soft button manager", ^{ expect(testManager.softButtonObjects).to(beEmpty()); expect(testManager.currentMainField1).to(beNil()); - expect(testManager.windowCapability).to(beNil()); expect(testManager.transactionQueue).toNot(beNil()); + expect(testManager.transactionQueue.isSuspended).to(beFalse()); + expect(testManager.windowCapability).toNot(beNil()); + expect(testManager.currentLevel).to(equal(SDLHMILevelFull)); + + // These are set up earlier for future tests and therefore won't be nil +// expect(testManager.windowCapability).to(beNil()); +// expect(testManager.currentLevel).to(beNil()); }); context(@"when in HMI NONE", ^{ beforeEach(^{ - testManager.currentLevel = SDLHMILevelNone; + SDLOnHMIStatus *status = [[SDLOnHMIStatus alloc] init]; + status.hmiLevel = SDLHMILevelNone; + [testManager sdl_hmiStatusNotification:[[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeHMIStatusNotification object:nil rpcNotification:status]]; testObject1 = [[SDLSoftButtonObject alloc] initWithName:@"name1" states:@[object1State1, object1State2] initialStateName:object1State1Name handler:nil]; testObject2 = [[SDLSoftButtonObject alloc] initWithName:@"name2" state:object2State1 handler:nil]; @@ -105,19 +134,16 @@ describe(@"a soft button manager", ^{ }); }); - context(@"when no HMI level has been received", ^{ + context(@"when there are no soft button capabilities", ^{ beforeEach(^{ - testManager.currentLevel = nil; - - testObject1 = [[SDLSoftButtonObject alloc] initWithName:@"name1" states:@[object1State1, object1State2] initialStateName:object1State1Name handler:nil]; - testObject2 = [[SDLSoftButtonObject alloc] initWithName:@"name2" state:object2State1 handler:nil]; - - testManager.softButtonObjects = @[testObject1, testObject2]; + SDLWindowCapability *windowCapability = [[SDLWindowCapability alloc] init]; + SDLDisplayCapability *displayCapability = [[SDLDisplayCapability alloc] initWithDisplayName:@"TEST" windowTypeSupported:nil windowCapabilities:@[windowCapability]]; + [testManager sdl_displayCapabilityDidUpdate:[[SDLSystemCapability alloc] initWithDisplayCapabilities:@[displayCapability]]]; }); - it(@"should set the soft buttons, but not update", ^{ - expect(testManager.softButtonObjects).toNot(beEmpty()); - expect(testManager.transactionQueue.suspended).to(beTrue()); + it(@"should set the buttons but have the queue suspended", ^{ + expect(testManager.softButtonObjects).toNot(beNil()); + expect(testManager.transactionQueue.isSuspended).to(beTrue()); }); }); @@ -183,7 +209,9 @@ describe(@"a soft button manager", ^{ context(@"when the HMI level is now NONE", ^{ beforeEach(^{ - testManager.currentLevel = SDLHMILevelNone; + SDLOnHMIStatus *status = [[SDLOnHMIStatus alloc] init]; + status.hmiLevel = SDLHMILevelNone; + [testManager sdl_hmiStatusNotification:[[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeHMIStatusNotification object:nil rpcNotification:status]]; }); it(@"should not transition buttons", ^{ |