[AltServer] Ignores incompatible cached developer disks

Fixes issue where AltServer would always use cached developer disk, even if it isn’t compatible with the device’s operating system version.
This commit is contained in:
Riley Testut
2022-03-01 16:03:03 -08:00
parent 23516d0466
commit 37b00d670b
6 changed files with 124 additions and 25 deletions

View File

@@ -217,8 +217,17 @@ extension ALTDeviceManager
ALTDeviceManager.shared.installDeveloperDiskImage(at: diskFileURL, signatureURL: signatureFileURL, to: device) { (success, error) in
switch Result(success, error)
{
case .failure(let error): completionHandler(.failure(error))
case .success: completionHandler(.success(()))
case .failure(let error as ALTServerError) where error.code == .incompatibleDeveloperDisk:
developerDiskManager.setDeveloperDiskCompatible(false, with: device)
completionHandler(.failure(error))
case .failure(let error):
// Don't mark developer disk as incompatible because it probably failed for a different reason.
completionHandler(.failure(error))
case .success:
developerDiskManager.setDeveloperDiskCompatible(true, with: device)
completionHandler(.success(()))
}
}
}

View File

@@ -1204,7 +1204,38 @@ NSNotificationName const ALTDeviceManagerDeviceDidDisconnectNotification = @"ALT
plist_free(result);
}
finish(nil);
// 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];
if (success)
{
// Connection succeeded, so we assume the developer disk is compatible.
finish(nil);
}
else if ([error.domain isEqualToString:AltServerConnectionErrorDomain] && error.code == ALTServerConnectionErrorUnknown)
{
// Connection failed with .unknown error code, so we assume the developer disk is NOT compatible.
NSMutableDictionary *userInfo = [@{
ALTOperatingSystemVersionErrorKey: NSStringFromOperatingSystemVersion(altDevice.osVersion),
NSUnderlyingErrorKey: error,
} mutableCopy];
NSString *osName = ALTOperatingSystemNameForDeviceType(altDevice.type);
if (osName != nil)
{
userInfo[ALTOperatingSystemNameErrorKey] = osName;
}
NSError *returnError = [NSError errorWithDomain:AltServerErrorDomain code:ALTServerErrorIncompatibleDeveloperDisk userInfo:userInfo];
finish(returnError);
}
else
{
finish(error);
}
}];
});
}