Search in sources :

Example 1 with AfcClient

use of org.robovm.libimobiledevice.AfcClient 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.");
        }
    }
}
Also used : AfcClient(org.robovm.libimobiledevice.AfcClient) LockdowndServiceDescriptor(org.robovm.libimobiledevice.LockdowndServiceDescriptor) MobileImageMounterClient(org.robovm.libimobiledevice.MobileImageMounterClient) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File) NSString(com.dd.plist.NSString)

Aggregations

NSDictionary (com.dd.plist.NSDictionary)1 NSString (com.dd.plist.NSString)1 File (java.io.File)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 ZipFile (java.util.zip.ZipFile)1 AfcClient (org.robovm.libimobiledevice.AfcClient)1 LockdowndServiceDescriptor (org.robovm.libimobiledevice.LockdowndServiceDescriptor)1 MobileImageMounterClient (org.robovm.libimobiledevice.MobileImageMounterClient)1