Search in sources :

Example 61 with FileDescriptor

use of java.io.FileDescriptor in project android_frameworks_base by ParanoidAndroid.

the class BackupHelperDispatcher method performBackup.

public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) throws IOException {
    // First, do the helpers that we've already done, since they're already in the state
    // file.
    int err;
    Header header = new Header();
    TreeMap<String, BackupHelper> helpers = (TreeMap<String, BackupHelper>) mHelpers.clone();
    FileDescriptor oldStateFD = null;
    FileDescriptor newStateFD = newState.getFileDescriptor();
    if (oldState != null) {
        oldStateFD = oldState.getFileDescriptor();
        while ((err = readHeader_native(header, oldStateFD)) >= 0) {
            if (err == 0) {
                BackupHelper helper = helpers.get(header.keyPrefix);
                Log.d(TAG, "handling existing helper '" + header.keyPrefix + "' " + helper);
                if (helper != null) {
                    doOneBackup(oldState, data, newState, header, helper);
                    helpers.remove(header.keyPrefix);
                } else {
                    skipChunk_native(oldStateFD, header.chunkSize);
                }
            }
        }
    }
    // Then go through and do the rest that we haven't done.
    for (Map.Entry<String, BackupHelper> entry : helpers.entrySet()) {
        header.keyPrefix = entry.getKey();
        Log.d(TAG, "handling new helper '" + header.keyPrefix + "'");
        BackupHelper helper = entry.getValue();
        doOneBackup(oldState, data, newState, header, helper);
    }
}
Also used : TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor)

Example 62 with FileDescriptor

use of java.io.FileDescriptor in project android_frameworks_base by ParanoidAndroid.

the class FileBackupHelperBase method performBackup_checked.

/**
     * Check the parameters so the native code doesn't have to throw all the exceptions
     * since it's easier to do that from Java.
     */
static void performBackup_checked(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState, String[] files, String[] keys) {
    if (files.length == 0) {
        return;
    }
    // files must be all absolute paths
    for (String f : files) {
        if (f.charAt(0) != '/') {
            throw new RuntimeException("files must have all absolute paths: " + f);
        }
    }
    // the length of files and keys must be the same
    if (files.length != keys.length) {
        throw new RuntimeException("files.length=" + files.length + " keys.length=" + keys.length);
    }
    // oldStateFd can be null
    FileDescriptor oldStateFd = oldState != null ? oldState.getFileDescriptor() : null;
    FileDescriptor newStateFd = newState.getFileDescriptor();
    if (newStateFd == null) {
        throw new NullPointerException();
    }
    int err = performBackup_native(oldStateFd, data.mBackupWriter, newStateFd, files, keys);
    if (err != 0) {
        // TODO: more here
        throw new RuntimeException("Backup failed 0x" + Integer.toHexString(err));
    }
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor)

Example 63 with FileDescriptor

use of java.io.FileDescriptor in project android_frameworks_base by ParanoidAndroid.

the class ParcelFileDescriptor method open.

/**
     * Create a new ParcelFileDescriptor accessing a given file.
     *
     * @param file The file to be opened.
     * @param mode The desired access mode, must be one of
     * {@link #MODE_READ_ONLY}, {@link #MODE_WRITE_ONLY}, or
     * {@link #MODE_READ_WRITE}; may also be any combination of
     * {@link #MODE_CREATE}, {@link #MODE_TRUNCATE},
     * {@link #MODE_WORLD_READABLE}, and {@link #MODE_WORLD_WRITEABLE}.
     *
     * @return Returns a new ParcelFileDescriptor pointing to the given
     * file.
     *
     * @throws FileNotFoundException Throws FileNotFoundException if the given
     * file does not exist or can not be opened with the requested mode.
     */
public static ParcelFileDescriptor open(File file, int mode) throws FileNotFoundException {
    String path = file.getPath();
    if ((mode & MODE_READ_WRITE) == 0) {
        throw new IllegalArgumentException("Must specify MODE_READ_ONLY, MODE_WRITE_ONLY, or MODE_READ_WRITE");
    }
    FileDescriptor fd = Parcel.openFileDescriptor(path, mode);
    return fd != null ? new ParcelFileDescriptor(fd) : null;
}
Also used : FileDescriptor(java.io.FileDescriptor)

Example 64 with FileDescriptor

use of java.io.FileDescriptor in project android_frameworks_base by ParanoidAndroid.

the class DrmManagerClient method getOriginalMimeType.

/**
     * Retrieves the MIME type embedded in the original content.
     *
     * @param path Path to the rights-protected content.
     *
     * @return The MIME type of the original content, such as <code>video/mpeg</code>.
     */
public String getOriginalMimeType(String path) {
    if (null == path || path.equals("")) {
        throw new IllegalArgumentException("Given path should be non null");
    }
    String mime = null;
    FileInputStream is = null;
    try {
        FileDescriptor fd = null;
        File file = new File(path);
        if (file.exists()) {
            is = new FileInputStream(file);
            fd = is.getFD();
        }
        mime = _getOriginalMimeType(mUniqueId, path, fd);
    } catch (IOException ioe) {
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            }
        }
    }
    return mime;
}
Also used : IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) FileDescriptor(java.io.FileDescriptor)

Example 65 with FileDescriptor

use of java.io.FileDescriptor in project android_frameworks_base by ParanoidAndroid.

the class MediaPlayer method setDataSource.

private void setDataSource(String path, String[] keys, String[] values) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
    disableProxyListener();
    final Uri uri = Uri.parse(path);
    if ("file".equals(uri.getScheme())) {
        path = uri.getPath();
    }
    final File file = new File(path);
    if (file.exists()) {
        FileInputStream is = new FileInputStream(file);
        FileDescriptor fd = is.getFD();
        setDataSource(fd);
        is.close();
    } else {
        _setDataSource(path, keys, values);
    }
}
Also used : Uri(android.net.Uri) File(java.io.File) FileInputStream(java.io.FileInputStream) AssetFileDescriptor(android.content.res.AssetFileDescriptor) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor)

Aggregations

FileDescriptor (java.io.FileDescriptor)363 IOException (java.io.IOException)162 ParcelFileDescriptor (android.os.ParcelFileDescriptor)95 ErrnoException (android.system.ErrnoException)95 FileInputStream (java.io.FileInputStream)83 File (java.io.File)51 AssetFileDescriptor (android.content.res.AssetFileDescriptor)37 FileOutputStream (java.io.FileOutputStream)35 Bitmap (android.graphics.Bitmap)30 LocalSocket (android.net.LocalSocket)26 FileNotFoundException (java.io.FileNotFoundException)26 SmallTest (android.test.suitebuilder.annotation.SmallTest)17 InputStream (java.io.InputStream)16 Socket (java.net.Socket)14 ErrnoException (libcore.io.ErrnoException)14 Test (org.junit.Test)14 ServerSocket (java.net.ServerSocket)13 SSLHandshakeCallbacks (org.conscrypt.NativeCrypto.SSLHandshakeCallbacks)13 RemoteException (android.os.RemoteException)12 BitmapFactory (android.graphics.BitmapFactory)11