Skip to content

Commit

Permalink
Merge pull request #793 from smartdevicelink/bug/issue_789_filemanage…
Browse files Browse the repository at this point in the history
…r_state_error

Fix a crash on disconnects during a ListFiles response sent by the FileManager
  • Loading branch information
joeljfischer authored Nov 22, 2017
2 parents 58f6e20 + 24242dd commit 74b8a79
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
5 changes: 5 additions & 0 deletions SmartDeviceLink/SDLFileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ - (void)didEnterStateShutdown {
- (void)didEnterStateFetchingInitialList {
__weak typeof(self) weakSelf = self;
[self sdl_listRemoteFilesWithCompletionHandler:^(BOOL success, NSUInteger bytesAvailable, NSArray<NSString *> *_Nonnull fileNames, NSError *_Nullable error) {
// If we've already shut down by this point, just stay in the shutdown state
if ([weakSelf.stateMachine.currentState isEqualToString:SDLFileManagerStateShutdown]) {
BLOCK_RETURN;
}

// If there was an error, we'll pass the error to the startup handler and cancel out
if (error != nil) {
[weakSelf.stateMachine transitionToState:SDLFileManagerStateStartupError];
Expand Down
25 changes: 24 additions & 1 deletion SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ @interface SDLFileManager ()
expect(testFileManager.currentState).to(match(SDLFileManagerStateFetchingInitialList));
});

describe(@"after receiving a ListFiles response", ^{
describe(@"after going to the shutdown state and receiving a ListFiles response", ^{
__block SDLListFilesResponse *testListFilesResponse = nil;
__block NSSet<NSString *> *testInitialFileNames = nil;

Expand All @@ -94,10 +94,33 @@ @interface SDLFileManager ()
testListFilesResponse.spaceAvailable = @(initialSpaceAvailable);
testListFilesResponse.filenames = [NSArray arrayWithArray:[testInitialFileNames allObjects]];

[testFileManager stop];
[testConnectionManager respondToLastRequestWithResponse:testListFilesResponse];
});

it(@"should remain in the stopped state after receiving the response if disconnected", ^{

expect(testFileManager.currentState).toEventually(match(SDLFileManagerStateShutdown));
});
});

describe(@"after receiving a ListFiles response", ^{
__block SDLListFilesResponse *testListFilesResponse = nil;
__block NSSet<NSString *> *testInitialFileNames = nil;

beforeEach(^{
testInitialFileNames = [NSSet setWithArray:@[@"testFile1", @"testFile2", @"testFile3"]];

testListFilesResponse = [[SDLListFilesResponse alloc] init];
testListFilesResponse.success = @YES;
testListFilesResponse.spaceAvailable = @(initialSpaceAvailable);
testListFilesResponse.filenames = [NSArray arrayWithArray:[testInitialFileNames allObjects]];
[testConnectionManager respondToLastRequestWithResponse:testListFilesResponse];
});

it(@"the file manager should be in the correct state", ^{
[testConnectionManager respondToLastRequestWithResponse:testListFilesResponse];

expect(testFileManager.currentState).toEventually(match(SDLFileManagerStateReady));
expect(testFileManager.remoteFileNames).toEventually(equal(testInitialFileNames));
expect(@(testFileManager.bytesAvailable)).toEventually(equal(@(initialSpaceAvailable)));
Expand Down
7 changes: 4 additions & 3 deletions SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
#import <OCMock/OCMock.h>

#import "SDLFocusableItemLocator.h"
#import "SDLSendHapticData.h"
#import "SDLHapticRect.h"
#import "SDLLifecycleManager.h"
#import "SDLManager.h"
#import "SDLRectangle.h"
#import "SDLSendHapticData.h"
#import "SDLTouchCoord.h"
#import "SDLTouchEvent.h"
#import "SDLTouch.h"
#import "SDLRectangle.h"
#import "SDLLifecycleManager.h"

BOOL compareRectangle(SDLRectangle *sdlRectangle, CGRect cgRect)
{
Expand Down

0 comments on commit 74b8a79

Please sign in to comment.