Search in sources :

Example 1 with LockdowndClient

use of org.robovm.libimobiledevice.LockdowndClient 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 LockdowndClient

use of org.robovm.libimobiledevice.LockdowndClient in project robovm by robovm.

the class AppLauncher method launchInternal.

private int launchInternal() throws Exception {
    install();
    int lockedRetriesLeft = launchOnLockedRetries;
    while (true) {
        IDeviceConnection conn = null;
        String appPath = null;
        try (LockdowndClient lockdowndClient = new LockdowndClient(device, getClass().getSimpleName(), true)) {
            appPath = getAppPath(lockdowndClient, appId);
            // E.g. 7.0.2
            String productVersion = lockdowndClient.getValue(null, "ProductVersion").toString();
            // E.g. 11B508
            String buildVersion = lockdowndClient.getValue(null, "BuildVersion").toString();
            if (appLauncherCallback != null) {
                appLauncherCallback.setAppLaunchInfo(new AppLauncherInfo(device, appPath, productVersion, buildVersion));
            }
            LockdowndServiceDescriptor debugService = null;
            try {
                debugService = lockdowndClient.startService(DEBUG_SERVER_SERVICE_NAME);
            } catch (LibIMobileDeviceException e) {
                if (e.getErrorCode() == LockdowndError.LOCKDOWN_E_INVALID_SERVICE.swigValue()) {
                    // This happens when the developer image hasn't been mounted.
                    // Mount and try again.
                    mountDeveloperImage(lockdowndClient);
                    debugService = lockdowndClient.startService(DEBUG_SERVER_SERVICE_NAME);
                } else {
                    throw e;
                }
            }
            conn = device.connect(debugService.getPort());
            log("Debug server port: " + debugService.getPort());
            if (localPort != -1) {
                String exe = ((NSDictionary) PropertyListParser.parse(new File(localAppPath, "Info.plist"))).objectForKey("CFBundleExecutable").toString();
                log("launchios \"" + new File(localAppPath, exe).getAbsolutePath() + "\" \"" + appPath + "\" " + localPort);
                StringBuilder argsString = new StringBuilder();
                for (String arg : args) {
                    if (argsString.length() > 0) {
                        argsString.append(' ');
                    }
                    argsString.append(arg);
                }
                log("process launch -- " + argsString);
            }
        }
        if (lockedRetriesLeft == launchOnLockedRetries) {
            // First try
            log("Remote app path: " + appPath);
            log("Launching app...");
        } else {
            log("Launching app (retry %d of %d)...", (launchOnLockedRetries - lockedRetriesLeft), launchOnLockedRetries);
        }
        try {
            // otherwise perform port forwarding and stdout piping
            if (localPort == -1) {
                return pipeStdOut(conn, appPath);
            } else {
                return forward(conn, appPath);
            }
        } catch (RuntimeException e) {
            if (!e.getMessage().contains("Locked") || lockedRetriesLeft == 0) {
                throw e;
            }
            lockedRetriesLeft--;
            log("Device locked. Retrying launch in %d seconds...", secondsBetweenLaunchOnLockedRetries);
            Thread.sleep(secondsBetweenLaunchOnLockedRetries * 1000);
        } finally {
            conn.dispose();
        }
    }
}
Also used : LibIMobileDeviceException(org.robovm.libimobiledevice.LibIMobileDeviceException) IDeviceConnection(org.robovm.libimobiledevice.IDeviceConnection) AppLauncherInfo(org.robovm.libimobiledevice.util.AppLauncherCallback.AppLauncherInfo) LockdowndServiceDescriptor(org.robovm.libimobiledevice.LockdowndServiceDescriptor) NSString(com.dd.plist.NSString) LockdowndClient(org.robovm.libimobiledevice.LockdowndClient) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 3 with LockdowndClient

use of org.robovm.libimobiledevice.LockdowndClient in project robovm by robovm.

the class AppLauncher method install.

public void install() throws IOException {
    if (!installed) {
        try (LockdowndClient lockdowndClient = new LockdowndClient(device, getClass().getSimpleName(), true)) {
            uploadInternal();
            if (uploadProgressCallback == null) {
                log("[ 50%%] Upload done. Installing app...");
            }
            installInternal();
            installed = true;
        } catch (IOException e) {
            throw e;
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException();
        }
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) LockdowndClient(org.robovm.libimobiledevice.LockdowndClient) TimeoutException(java.util.concurrent.TimeoutException) InterruptedIOException(java.io.InterruptedIOException) LibIMobileDeviceException(org.robovm.libimobiledevice.LibIMobileDeviceException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

LibIMobileDeviceException (org.robovm.libimobiledevice.LibIMobileDeviceException)3 LockdowndClient (org.robovm.libimobiledevice.LockdowndClient)3 NSString (com.dd.plist.NSString)2 LockdowndServiceDescriptor (org.robovm.libimobiledevice.LockdowndServiceDescriptor)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeoutException (java.util.concurrent.TimeoutException)1 ZipFile (java.util.zip.ZipFile)1 IDeviceConnection (org.robovm.libimobiledevice.IDeviceConnection)1 InstallationProxyClient (org.robovm.libimobiledevice.InstallationProxyClient)1 Options (org.robovm.libimobiledevice.InstallationProxyClient.Options)1 StatusCallback (org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback)1 AppLauncherInfo (org.robovm.libimobiledevice.util.AppLauncherCallback.AppLauncherInfo)1