use of org.robovm.libimobiledevice.MobileImageMounterClient in project robovm by robovm.
the class AppLauncher method mountDeveloperImage.
private void mountDeveloperImage(LockdowndClient lockdowndClient) throws Exception {
// Find the DeveloperDiskImage.dmg path that best matches the current device. Here's what
// the paths look like:
// Platforms/iPhoneOS.platform/DeviceSupport/5.0/DeveloperDiskImage.dmg
// Platforms/iPhoneOS.platform/DeviceSupport/6.0/DeveloperDiskImage.dmg
// Platforms/iPhoneOS.platform/DeviceSupport/6.1/DeveloperDiskImage.dmg
// Platforms/iPhoneOS.platform/DeviceSupport/7.0/DeveloperDiskImage.dmg
// Platforms/iPhoneOS.platform/DeviceSupport/7.0 (11A465)/DeveloperDiskImage.dmg
// Platforms/iPhoneOS.platform/DeviceSupport/7.0.3 (11B508)/DeveloperDiskImage.dmg
// E.g. 7.0.2
String productVersion = lockdowndClient.getValue(null, "ProductVersion").toString();
// E.g. 11B508
String buildVersion = lockdowndClient.getValue(null, "BuildVersion").toString();
File deviceSupport = new File(getXcodePath(), "Platforms/iPhoneOS.platform/DeviceSupport");
log("Looking up developer disk image for iOS version %s (%s) in %s", productVersion, buildVersion, deviceSupport);
File devImage = findDeveloperImage(deviceSupport, productVersion, buildVersion);
File devImageSig = new File(devImage.getParentFile(), devImage.getName() + ".signature");
byte[] devImageSigBytes = Files.readAllBytes(devImageSig.toPath());
LockdowndServiceDescriptor mimService = lockdowndClient.startService(MobileImageMounterClient.SERVICE_NAME);
try (MobileImageMounterClient mimClient = new MobileImageMounterClient(device, mimService)) {
log("Copying developer disk image %s to device", devImage);
int majorVersion = Integer.parseInt(getProductVersionParts(productVersion)[0]);
if (majorVersion >= 7) {
// Use new upload method
mimClient.uploadImage(devImage, null, devImageSigBytes);
} else {
LockdowndServiceDescriptor afcService = lockdowndClient.startService(AfcClient.SERVICE_NAME);
try (AfcClient afcClient = new AfcClient(device, afcService)) {
afcClient.makeDirectory("/PublicStaging");
afcClient.fileCopy(devImage, "/PublicStaging/staging.dimage");
}
}
log("Mounting developer disk image");
NSDictionary result = mimClient.mountImage("/PublicStaging/staging.dimage", devImageSigBytes, null);
NSString status = (NSString) result.objectForKey("Status");
if (status == null || !"Complete".equals(status.toString())) {
throw new IOException("Failed to mount " + devImage.getAbsolutePath() + " on the device.");
}
}
}
Aggregations