From a413c24b453b421f5a6dd0ebc8714362d4902d99 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 25 May 2022 15:57:17 -0700 Subject: [PATCH] =?UTF-8?q?[AltServer]=20Fixes=20incorrect=20=E2=80=9CDeve?= =?UTF-8?q?loper=20Disk=20incompatible=20with=20[OS=20version]=E2=80=9D=20?= =?UTF-8?q?error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously we assumed that if there was an error installing the developer disk, it was incompatible with the device’s iOS version. Howevever, sometimes an iOS device needs to be rebooted before it can successfully mount a developer disk. We now explicitly check for the latter scenario, and present a different error message asking the user to reboot their device if that’s the case. --- AltServer/Devices/ALTDeviceManager.mm | 55 ++++++++++++++++++--------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/AltServer/Devices/ALTDeviceManager.mm b/AltServer/Devices/ALTDeviceManager.mm index ef6bedc7..a7d6aff7 100644 --- a/AltServer/Devices/ALTDeviceManager.mm +++ b/AltServer/Devices/ALTDeviceManager.mm @@ -1198,29 +1198,36 @@ NSNotificationName const ALTDeviceManagerDeviceDidDisconnectNotification = @"ALT { return finish([NSError errorWithMobileImageMounterError:err device:altDevice]); } - - if (result) + + plist_t errorDescriptionNode = plist_dict_get_item(result, "DetailedError"); + if (errorDescriptionNode != NULL) { - plist_free(result); - } - - // Verify the installed developer disk is compatible with altDevice's operating system version. - ALTDebugConnection *testConnection = [[ALTDebugConnection alloc] initWithDevice:altDevice]; - [testConnection connectWithCompletionHandler:^(BOOL success, NSError * _Nullable error) { - [testConnection disconnect]; + char *errorDescription = NULL; + plist_get_string_val(errorDescriptionNode, &errorDescription); - if (success) + NSString *nsErrorDescription = @(errorDescription); + plist_free(result); + + NSError *returnError = nil; + + if ([nsErrorDescription containsString:@"Failed to verify"]) { - // Connection succeeded, so we assume the developer disk is compatible. - finish(nil); + // iOS device needs to be rebooted in order to mount disk to /Developer. + NSString *recoverySuggestion = [NSString stringWithFormat:NSLocalizedString(@"Please reboot %@ and try again.", @""), altDevice.name]; + + // ALTServerErrorUnderlyingError uses its underlying error's failure reason as its error description (if one exists), + // so assign our recovery suggestion to NSLocalizedFailureReasonErrorKey to make sure it's always displayed on client. + NSError *underlyingError = [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorUnknown userInfo:@{NSLocalizedFailureReasonErrorKey: recoverySuggestion}]; + + returnError = [NSError errorWithDomain:AltServerErrorDomain code:ALTServerErrorUnderlyingError userInfo:@{NSUnderlyingErrorKey: underlyingError}]; } - else if ([error.domain isEqualToString:AltServerConnectionErrorDomain] && error.code == ALTServerConnectionErrorUnknown) + else { - // Connection failed with .unknown error code, so we assume the developer disk is NOT compatible. + // Installation failed, so we assume the developer disk is NOT compatible with this iOS version. + NSMutableDictionary *userInfo = [@{ ALTOperatingSystemVersionErrorKey: NSStringFromOperatingSystemVersion(altDevice.osVersion), NSFilePathErrorKey: diskURL.path, - NSUnderlyingErrorKey: error, } mutableCopy]; NSString *osName = ALTOperatingSystemNameForDeviceType(altDevice.type); @@ -1229,8 +1236,22 @@ NSNotificationName const ALTDeviceManagerDeviceDidDisconnectNotification = @"ALT userInfo[ALTOperatingSystemNameErrorKey] = osName; } - NSError *returnError = [NSError errorWithDomain:AltServerErrorDomain code:ALTServerErrorIncompatibleDeveloperDisk userInfo:userInfo]; - finish(returnError); + returnError = [NSError errorWithDomain:AltServerErrorDomain code:ALTServerErrorIncompatibleDeveloperDisk userInfo:userInfo]; + } + + return finish(returnError); + } + + plist_free(result); + + // Verify that the developer disk has been successfully installed. + ALTDebugConnection *testConnection = [[ALTDebugConnection alloc] initWithDevice:altDevice]; + [testConnection connectWithCompletionHandler:^(BOOL success, NSError * _Nullable error) { + [testConnection disconnect]; + + if (success) + { + finish(nil); } else {