Search in sources :

Example 1 with InstallationProxyClient

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

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

the class AppLauncher method getAppPath.

private String getAppPath(LockdowndClient lockdowndClient, String appId) throws IOException {
    LockdowndServiceDescriptor instService = lockdowndClient.startService(InstallationProxyClient.SERVICE_NAME);
    try (InstallationProxyClient instClient = new InstallationProxyClient(device, instService)) {
        NSArray apps = instClient.browse();
        for (int i = 0; i < apps.count(); i++) {
            NSDictionary appInfo = (NSDictionary) apps.objectAtIndex(i);
            NSString bundleId = (NSString) appInfo.objectForKey("CFBundleIdentifier");
            if (bundleId != null && appId.equals(bundleId.toString())) {
                NSString path = (NSString) appInfo.objectForKey("Path");
                NSDictionary entitlements = (NSDictionary) appInfo.objectForKey("Entitlements");
                if (entitlements == null || entitlements.objectForKey("get-task-allow") == null || !entitlements.objectForKey("get-task-allow").equals(new NSNumber(true))) {
                    throw new RuntimeException("App with id '" + appId + "' does not " + "have the 'get-task-allow' entitlement and cannot be debugged");
                }
                if (path == null) {
                    throw new RuntimeException("Path for app with id '" + appId + "' not found");
                }
                return path.toString();
            }
        }
        throw new RuntimeException("No app with id '" + appId + "' found on device");
    }
}
Also used : NSNumber(com.dd.plist.NSNumber) LockdowndServiceDescriptor(org.robovm.libimobiledevice.LockdowndServiceDescriptor) NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) InstallationProxyClient(org.robovm.libimobiledevice.InstallationProxyClient) NSString(com.dd.plist.NSString)

Aggregations

NSString (com.dd.plist.NSString)2 InstallationProxyClient (org.robovm.libimobiledevice.InstallationProxyClient)2 LockdowndServiceDescriptor (org.robovm.libimobiledevice.LockdowndServiceDescriptor)2 NSArray (com.dd.plist.NSArray)1 NSDictionary (com.dd.plist.NSDictionary)1 NSNumber (com.dd.plist.NSNumber)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Options (org.robovm.libimobiledevice.InstallationProxyClient.Options)1 StatusCallback (org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback)1 LibIMobileDeviceException (org.robovm.libimobiledevice.LibIMobileDeviceException)1 LockdowndClient (org.robovm.libimobiledevice.LockdowndClient)1