Search in sources :

Example 1 with StatusCallback

use of org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback in project robovm by robovm.

the class AppLauncher method installInternal.

private void installInternal() throws Exception {
    try (LockdowndClient lockdowndClient = new LockdowndClient(device, getClass().getSimpleName(), true)) {
        final LibIMobileDeviceException[] ex = new LibIMobileDeviceException[1];
        final CountDownLatch countDownLatch = new CountDownLatch(1);
        LockdowndServiceDescriptor instproxyService = lockdowndClient.startService(InstallationProxyClient.SERVICE_NAME);
        try (InstallationProxyClient instClient = new InstallationProxyClient(device, instproxyService)) {
            instClient.upgrade("/PublicStaging/" + localAppPath.getName(), new Options().packageType(localAppPath.isDirectory() ? PackageType.Developer : null), new StatusCallback() {

                @Override
                public void progress(String status, int percentComplete) {
                    if (installStatusCallback != null) {
                        installStatusCallback.progress(status, percentComplete);
                    } else {
                        log("[%3d%%] %s", 50 + percentComplete / 2, status);
                    }
                }

                @Override
                public void success() {
                    try {
                        if (installStatusCallback != null) {
                            installStatusCallback.success();
                        } else {
                            log("[100%%] Installation complete");
                        }
                    } finally {
                        countDownLatch.countDown();
                    }
                }

                @Override
                public void error(String message) {
                    try {
                        ex[0] = new LibIMobileDeviceException(message);
                        if (installStatusCallback != null) {
                            installStatusCallback.error(message);
                        } else {
                            log("Error: %s", message);
                        }
                    } finally {
                        countDownLatch.countDown();
                    }
                }
            });
            countDownLatch.await();
        }
        if (ex[0] != null) {
            throw ex[0];
        }
    }
}
Also used : LibIMobileDeviceException(org.robovm.libimobiledevice.LibIMobileDeviceException) Options(org.robovm.libimobiledevice.InstallationProxyClient.Options) LockdowndServiceDescriptor(org.robovm.libimobiledevice.LockdowndServiceDescriptor) InstallationProxyClient(org.robovm.libimobiledevice.InstallationProxyClient) StatusCallback(org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback) NSString(com.dd.plist.NSString) CountDownLatch(java.util.concurrent.CountDownLatch) LockdowndClient(org.robovm.libimobiledevice.LockdowndClient)

Example 2 with StatusCallback

use of org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback in project robovm by robovm.

the class InstallationProxyClientTest method testUpgradeIPA.

//removed as test until it can be rewritten to re-sign the ipa
public void testUpgradeIPA() throws Exception {
    Path tmpDir = Files.createTempDirectory(getClass().getSimpleName());
    Files.copy(getClass().getResourceAsStream("/demo.ipa"), tmpDir.resolve("demo.ipa"));
    afcClient.upload(tmpDir.resolve("demo.ipa").toFile(), "/TestStaging", new UploadProgressCallback() {

        public void progress(File path, int percentComplete) {
            System.out.format("[%3d%%] Uploading %s\n", percentComplete, path);
        }

        public void success() {
            System.out.format("[100%%] Upload done\n");
        }

        public void error(String message) {
            System.out.format("Error: %s\n", message);
        }
    });
    final boolean[] success = new boolean[] { false };
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    client.upgrade("/TestStaging/demo.ipa", new Options(), new StatusCallback() {

        @Override
        public void progress(String status, int percentComplete) {
            System.out.format("[%3d%%] %s\n", percentComplete, status);
        }

        @Override
        public void success() {
            System.out.format("[100%%] Complete\n");
            success[0] = true;
            countDownLatch.countDown();
        }

        @Override
        public void error(String message) {
            System.out.println("Error: " + message);
            countDownLatch.countDown();
        }
    });
    countDownLatch.await(10, TimeUnit.SECONDS);
    assertTrue(success[0]);
}
Also used : Path(java.nio.file.Path) Options(org.robovm.libimobiledevice.InstallationProxyClient.Options) StatusCallback(org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback) UploadProgressCallback(org.robovm.libimobiledevice.AfcClient.UploadProgressCallback) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 3 with StatusCallback

use of org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback in project robovm by robovm.

the class IOSTarget method createIOSDevLauncher.

private Launcher createIOSDevLauncher(LaunchParameters launchParameters) throws IOException {
    IOSDeviceLaunchParameters deviceLaunchParameters = (IOSDeviceLaunchParameters) launchParameters;
    String deviceId = deviceLaunchParameters.getDeviceId();
    int forwardPort = deviceLaunchParameters.getForwardPort();
    AppLauncherCallback callback = deviceLaunchParameters.getAppPathCallback();
    if (deviceId == null) {
        String[] udids = IDevice.listUdids();
        if (udids.length == 0) {
            throw new RuntimeException("No devices connected");
        }
        if (udids.length > 1) {
            config.getLogger().warn("More than 1 device connected (%s). " + "Using %s.", Arrays.asList(udids), udids[0]);
        }
        deviceId = udids[0];
    }
    device = new IDevice(deviceId);
    OutputStream out = null;
    if (launchParameters.getStdoutFifo() != null) {
        out = new OpenOnWriteFileOutputStream(launchParameters.getStdoutFifo());
    } else {
        out = System.out;
    }
    Map<String, String> env = launchParameters.getEnvironment();
    if (env == null) {
        env = new HashMap<>();
    }
    AppLauncher launcher = new AppLauncher(device, getAppDir()) {

        protected void log(String s, Object... args) {
            config.getLogger().info(s, args);
        }
    }.stdout(out).closeOutOnExit(true).args(launchParameters.getArguments().toArray(new String[0])).env(env).forward(forwardPort).appLauncherCallback(callback).xcodePath(ToolchainUtil.findXcodePath()).uploadProgressCallback(new UploadProgressCallback() {

        boolean first = true;

        public void success() {
            config.getLogger().info("[100%%] Upload complete");
        }

        public void progress(File path, int percentComplete) {
            if (first) {
                config.getLogger().info("[  0%%] Beginning upload...");
            }
            first = false;
            config.getLogger().info("[%3d%%] Uploading %s...", percentComplete, path);
        }

        public void error(String message) {
        }
    }).installStatusCallback(new StatusCallback() {

        boolean first = true;

        public void success() {
            config.getLogger().info("[100%%] Install complete");
        }

        public void progress(String status, int percentComplete) {
            if (first) {
                config.getLogger().info("[  0%%] Beginning installation...");
            }
            first = false;
            config.getLogger().info("[%3d%%] %s", percentComplete, status);
        }

        public void error(String message) {
        }
    });
    return new AppLauncherProcess(config.getLogger(), launcher, launchParameters);
}
Also used : AppLauncherCallback(org.robovm.libimobiledevice.util.AppLauncherCallback) OutputStream(java.io.OutputStream) OpenOnWriteFileOutputStream(org.robovm.compiler.util.io.OpenOnWriteFileOutputStream) IDevice(org.robovm.libimobiledevice.IDevice) StatusCallback(org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback) NSString(com.dd.plist.NSString) NSObject(com.dd.plist.NSObject) UploadProgressCallback(org.robovm.libimobiledevice.AfcClient.UploadProgressCallback) OpenOnWriteFileOutputStream(org.robovm.compiler.util.io.OpenOnWriteFileOutputStream) AppLauncher(org.robovm.libimobiledevice.util.AppLauncher) File(java.io.File)

Example 4 with StatusCallback

use of org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback in project robovm by robovm.

the class InstallationProxyClientTest method testUpgradeAppBundle.

//removed as test until it can be rewritten to re-sign the ipa
public void testUpgradeAppBundle() throws Exception {
    Path tmpDir = Files.createTempDirectory(getClass().getSimpleName());
    Path ipaFile = tmpDir.resolve("demo.ipa");
    Files.copy(getClass().getResourceAsStream("/demo.ipa"), ipaFile);
    extractZip(ipaFile, tmpDir);
    Path appDir = tmpDir.resolve("Payload/demo.app");
    afcClient.upload(appDir.toFile(), "/TestStaging", new UploadProgressCallback() {

        public void progress(File path, int percentComplete) {
            System.out.format("[%3d%%] Uploading %s\n", percentComplete, path);
        }

        public void success() {
            System.out.format("[100%%] Upload done\n");
        }

        public void error(String message) {
            System.out.format("Error: %s\n", message);
        }
    });
    final boolean[] success = new boolean[] { false };
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    client.upgrade("/TestStaging/demo.app", new Options().packageType(PackageType.Developer), new StatusCallback() {

        @Override
        public void progress(String status, int percentComplete) {
            System.out.format("[%3d%%] %s\n", percentComplete, status);
        }

        @Override
        public void success() {
            System.out.format("[100%%] Complete\n");
            success[0] = true;
            countDownLatch.countDown();
        }

        @Override
        public void error(String message) {
            System.out.println("Error: " + message);
            countDownLatch.countDown();
        }
    });
    countDownLatch.await(10, TimeUnit.SECONDS);
    assertTrue(success[0]);
}
Also used : Path(java.nio.file.Path) Options(org.robovm.libimobiledevice.InstallationProxyClient.Options) StatusCallback(org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback) UploadProgressCallback(org.robovm.libimobiledevice.AfcClient.UploadProgressCallback) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 5 with StatusCallback

use of org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback in project robovm by robovm.

the class Callbacks method callInstproxyCallback.

static void callInstproxyCallback(String operation, byte[] statusPlistBin, int id) throws Exception {
    StatusCallback callback = null;
    synchronized (Callbacks.class) {
        callback = instProxyStatusCallbacks.get(id);
    }
    if (callback != null) {
        boolean done = false;
        try {
            NSDictionary dict = (NSDictionary) PropertyListParser.parse(statusPlistBin);
            NSObject status = dict.objectForKey("Status");
            NSObject percentComplete = dict.objectForKey("PercentComplete");
            NSObject error = dict.objectForKey("Error");
            if (error != null) {
                done = true;
                callback.error(error.toString());
            } else {
                if ("Complete".equals(status.toString())) {
                    done = true;
                    callback.success();
                } else {
                    callback.progress(status.toString(), ((NSNumber) percentComplete).intValue());
                }
            }
        } catch (Throwable t) {
            t.printStackTrace();
        } finally {
            if (done) {
                synchronized (Callbacks.class) {
                    instProxyStatusCallbacks.remove(id);
                }
            }
        }
    }
}
Also used : NSObject(com.dd.plist.NSObject) NSDictionary(com.dd.plist.NSDictionary) StatusCallback(org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback)

Aggregations

StatusCallback (org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback)5 File (java.io.File)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 UploadProgressCallback (org.robovm.libimobiledevice.AfcClient.UploadProgressCallback)3 Options (org.robovm.libimobiledevice.InstallationProxyClient.Options)3 NSObject (com.dd.plist.NSObject)2 NSString (com.dd.plist.NSString)2 Path (java.nio.file.Path)2 ZipFile (java.util.zip.ZipFile)2 NSDictionary (com.dd.plist.NSDictionary)1 OutputStream (java.io.OutputStream)1 OpenOnWriteFileOutputStream (org.robovm.compiler.util.io.OpenOnWriteFileOutputStream)1 IDevice (org.robovm.libimobiledevice.IDevice)1 InstallationProxyClient (org.robovm.libimobiledevice.InstallationProxyClient)1 LibIMobileDeviceException (org.robovm.libimobiledevice.LibIMobileDeviceException)1 LockdowndClient (org.robovm.libimobiledevice.LockdowndClient)1 LockdowndServiceDescriptor (org.robovm.libimobiledevice.LockdowndServiceDescriptor)1 AppLauncher (org.robovm.libimobiledevice.util.AppLauncher)1 AppLauncherCallback (org.robovm.libimobiledevice.util.AppLauncherCallback)1