Search in sources :

Example 1 with StringArray

use of org.robovm.libimobiledevice.binding.StringArray in project robovm by robovm.

the class AfcClient method getDeviceInfo.

/**
     * Retrieves device information. The information returned is the device 
     * model as well as the free space, the total capacity and blocksize on the 
     * accessed disk partition.
     * 
     * @return the device info as key-value pairs. Possible keys are:
     * {@link #DEVICE_INFO_KEY_MODEL}, {@link #DEVICE_INFO_KEY_FS_FREE_BYTES},
     * {@link #DEVICE_INFO_KEY_FS_TOTAL_BYTES}, 
     * {@link #DEVICE_INFO_KEY_FS_BLOCK_SIZE}.
     */
public Map<String, String> getDeviceInfo() {
    StringArrayOut infosOut = new StringArrayOut();
    try {
        checkResult(LibIMobileDevice.afc_get_device_info(getRef(), infosOut));
        StringArray list = infosOut.getValue();
        Map<String, String> result = new TreeMap<String, String>();
        if (list != null) {
            int i = 0;
            while (true) {
                String key = list.get(i++);
                if (key == null) {
                    break;
                }
                String value = list.get(i++);
                if (value == null) {
                    break;
                }
                result.put(key, value);
            }
        }
        return result;
    } finally {
        LibIMobileDevice.delete_StringArray_values_z(infosOut.getValue());
        infosOut.delete();
    }
}
Also used : StringArray(org.robovm.libimobiledevice.binding.StringArray) StringArrayOut(org.robovm.libimobiledevice.binding.StringArrayOut) TreeMap(java.util.TreeMap)

Example 2 with StringArray

use of org.robovm.libimobiledevice.binding.StringArray in project robovm by robovm.

the class AfcClient method getFileInfo.

/**
     * Retrieves information for a specific file or directory.
     * 
     * @param path the path of the file or directory.
     * @return the file information as key-value pairs. Possible keys are:
     * {@link #FILE_INFO_KEY_ST_BIRTHTIME}, {@link #FILE_INFO_KEY_ST_BLOCKS},
     * {@link #FILE_INFO_KEY_ST_IFMT}, {@link #FILE_INFO_KEY_ST_MTIME},
     * {@link #FILE_INFO_KEY_ST_NLINK}, {@link #FILE_INFO_KEY_ST_SIZE}.
     */
public Map<String, String> getFileInfo(String path) {
    StringArrayOut infolistOut = new StringArrayOut();
    try {
        checkResult(LibIMobileDevice.afc_get_file_info(getRef(), path, infolistOut));
        StringArray list = infolistOut.getValue();
        Map<String, String> result = new TreeMap<String, String>();
        if (list != null) {
            int i = 0;
            while (true) {
                String key = list.get(i++);
                if (key == null) {
                    break;
                }
                String value = list.get(i++);
                if (value == null) {
                    break;
                }
                result.put(key, value);
            }
        }
        return result;
    } finally {
        LibIMobileDevice.delete_StringArray_values_z(infolistOut.getValue());
        infolistOut.delete();
    }
}
Also used : StringArray(org.robovm.libimobiledevice.binding.StringArray) StringArrayOut(org.robovm.libimobiledevice.binding.StringArrayOut) TreeMap(java.util.TreeMap)

Example 3 with StringArray

use of org.robovm.libimobiledevice.binding.StringArray in project robovm by robovm.

the class IDevice method listUdids.

/**
     * Lists UDIDs of currently available devices.
     * 
     * @return the UDIDs of the currently available devices.
     */
public static String[] listUdids() {
    StringArrayOut devicesOut = new StringArrayOut();
    IntOut countOut = new IntOut();
    try {
        checkResult(LibIMobileDevice.idevice_get_device_list(devicesOut, countOut));
        StringArray devices = devicesOut.getValue();
        int count = countOut.getValue();
        String[] udids = new String[count];
        for (int i = 0; i < count; i++) {
            udids[i] = devices.get(i);
        }
        return udids;
    } catch (LibIMobileDeviceException e) {
        if (e.getErrorCode() == IDeviceError.IDEVICE_E_NO_DEVICE.swigValue()) {
            // This happens when usbmuxd isn't running
            return new String[0];
        }
        throw e;
    } finally {
        devicesOut.delete();
        countOut.delete();
    }
}
Also used : StringArray(org.robovm.libimobiledevice.binding.StringArray) StringArrayOut(org.robovm.libimobiledevice.binding.StringArrayOut) IntOut(org.robovm.libimobiledevice.binding.IntOut)

Example 4 with StringArray

use of org.robovm.libimobiledevice.binding.StringArray in project robovm by robovm.

the class AfcClient method readDirectory.

/**
     * Returns a directory listing of the specified directory.
     *
     * @param dir the directory to list. Must be a fully-qualified path.
     * @return the list of files in the specified directory.
     */
public String[] readDirectory(String dir) {
    if (dir == null) {
        throw new NullPointerException("dir");
    }
    StringArrayOut listOut = new StringArrayOut();
    try {
        checkResult(LibIMobileDevice.afc_read_directory(getRef(), dir, listOut));
        StringArray list = listOut.getValue();
        ArrayList<String> result = new ArrayList<String>();
        if (list != null) {
            for (int i = 0; ; i++) {
                String s = list.get(i);
                if (s == null) {
                    break;
                }
                result.add(s);
            }
        }
        return result.toArray(new String[result.size()]);
    } finally {
        LibIMobileDevice.delete_StringArray_values_z(listOut.getValue());
        listOut.delete();
    }
}
Also used : StringArray(org.robovm.libimobiledevice.binding.StringArray) StringArrayOut(org.robovm.libimobiledevice.binding.StringArrayOut) ArrayList(java.util.ArrayList)

Aggregations

StringArray (org.robovm.libimobiledevice.binding.StringArray)4 StringArrayOut (org.robovm.libimobiledevice.binding.StringArrayOut)4 TreeMap (java.util.TreeMap)2 ArrayList (java.util.ArrayList)1 IntOut (org.robovm.libimobiledevice.binding.IntOut)1