Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep File Manager from Error State on disallowed #1455

Merged
merged 11 commits into from Oct 24, 2019
8 changes: 7 additions & 1 deletion SmartDeviceLink/SDLFileManager.m
Expand Up @@ -179,8 +179,13 @@ - (void)didEnterStateFetchingInitialList {
BLOCK_RETURN;
}

// If there was an error, we'll pass the error to the startup handler and cancel out
// If there was an error, we'll pass the error to the startup handler and cancel out other then in case of DISALLOWED
justingluck93 marked this conversation as resolved.
Show resolved Hide resolved
if (error != nil) {
// In the case we are DISALLOWED we still want to transition to a ready state
justingluck93 marked this conversation as resolved.
Show resolved Hide resolved
if([error.userInfo[@"resultCode"] isEqualToEnum:SDLResultDisallowed]) {
[weakSelf.stateMachine transitionToState:SDLFileManagerStateReady];
BLOCK_RETURN;
}
[weakSelf.stateMachine transitionToState:SDLFileManagerStateStartupError];
BLOCK_RETURN;
}
Expand All @@ -202,6 +207,7 @@ - (void)didEnterStateReady {

- (void)sdl_listRemoteFilesWithCompletionHandler:(SDLFileManagerListFilesCompletionHandler)handler {
__weak typeof(self) weakSelf = self;

joeljfischer marked this conversation as resolved.
Show resolved Hide resolved
SDLListFilesOperation *listOperation = [[SDLListFilesOperation alloc] initWithConnectionManager:self.connectionManager completionHandler:^(BOOL success, NSUInteger bytesAvailable, NSArray<NSString *> *_Nonnull fileNames, NSError *_Nullable error) {
joeljfischer marked this conversation as resolved.
Show resolved Hide resolved
if (error != nil || !success) {
handler(success, bytesAvailable, fileNames, error);
Expand Down
10 changes: 9 additions & 1 deletion SmartDeviceLink/SDLListFilesOperation.m
Expand Up @@ -59,7 +59,15 @@ - (void)sdl_listFiles {
NSUInteger bytesAvailable = listFilesResponse.spaceAvailable != nil ? listFilesResponse.spaceAvailable.unsignedIntegerValue : 2000000000;

if (weakSelf.completionHandler != nil) {
weakSelf.completionHandler(success, bytesAvailable, fileNames, error);
if([response.resultCode isEqualToEnum:SDLResultDisallowed]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, just always set the resultCode into the error if an error exists.

NSMutableDictionary *results = [error.userInfo mutableCopy];
results[@"resultCode"] = SDLResultDisallowed;
NSError *resultError = [NSError errorWithDomain:error.domain code:error.code userInfo:results];
weakSelf.completionHandler(success, bytesAvailable, fileNames, resultError);
}
else {
joeljfischer marked this conversation as resolved.
Show resolved Hide resolved
weakSelf.completionHandler(success, bytesAvailable, fileNames, error);
}
}

[weakSelf finishOperation];
Expand Down