Search in sources :

Example 61 with ParcelFileDescriptor

use of android.os.ParcelFileDescriptor in project XobotOS by xamarin.

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 ParcelFileDescriptor

use of android.os.ParcelFileDescriptor in project XobotOS by xamarin.

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 ParcelFileDescriptor

use of android.os.ParcelFileDescriptor in project XobotOS by xamarin.

the class WallpaperManager method setStream.

/**
     * Change the current system wallpaper to a specific byte stream.  The
     * give InputStream is copied into persistent storage and will now be
     * used as the wallpaper.  Currently it must be either a JPEG or PNG
     * image.  On success, the intent {@link Intent#ACTION_WALLPAPER_CHANGED}
     * is broadcast.
     *
     * @param data A stream containing the raw data to install as a wallpaper.
     *
     * @throws IOException If an error occurs reverting to the default
     * wallpaper.
     */
public void setStream(InputStream data) throws IOException {
    try {
        ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null);
        if (fd == null) {
            return;
        }
        FileOutputStream fos = null;
        try {
            fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
            setWallpaper(data, fos);
        } finally {
            if (fos != null) {
                fos.close();
            }
        }
    } catch (RemoteException e) {
    // Ignore
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) ParcelFileDescriptor(android.os.ParcelFileDescriptor) RemoteException(android.os.RemoteException)

Example 64 with ParcelFileDescriptor

use of android.os.ParcelFileDescriptor in project XobotOS by xamarin.

the class SQLiteStatement method simpleQueryForBlobFileDescriptor.

/**
     * Executes a statement that returns a 1 by 1 table with a blob value.
     *
     * @return A read-only file descriptor for a copy of the blob value, or {@code null}
     *         if the value is null or could not be read for some reason.
     *
     * @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows
     */
public ParcelFileDescriptor simpleQueryForBlobFileDescriptor() {
    try {
        long timeStart = acquireAndLock(READ);
        ParcelFileDescriptor retValue = native_1x1_blob_ashmem();
        mDatabase.logTimeStat(mSql, timeStart);
        return retValue;
    } catch (IOException ex) {
        Log.e(TAG, "simpleQueryForBlobFileDescriptor() failed", ex);
        return null;
    } catch (SQLiteDoneException e) {
        throw new SQLiteDoneException("expected 1 row from this query but query returned no data. check the query: " + mSql);
    } finally {
        releaseAndUnlock();
    }
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException)

Example 65 with ParcelFileDescriptor

use of android.os.ParcelFileDescriptor in project XobotOS by xamarin.

the class BluetoothHealthProfileHandler method getMainChannelFd.

ParcelFileDescriptor getMainChannelFd(BluetoothDevice device, BluetoothHealthAppConfiguration config) {
    HealthChannel chan = getMainChannel(device, config);
    if (chan != null) {
        ParcelFileDescriptor pfd = null;
        try {
            pfd = chan.mChannelFd.dup();
            return pfd;
        } catch (IOException e) {
            return null;
        }
    }
    String objectPath = mBluetoothService.getObjectPathFromAddress(device.getAddress());
    if (objectPath == null)
        return null;
    String mainChannelPath = mBluetoothService.getMainChannelNative(objectPath);
    if (mainChannelPath == null)
        return null;
    // We had no record of the main channel but querying Bluez we got a
    // main channel. We might not have received the PropertyChanged yet for
    // the main channel creation so update our data structure here.
    chan = findChannelByPath(device, mainChannelPath);
    if (chan == null) {
        errorLog("Main Channel present but we don't have any account of it:" + device + ":" + config);
        return null;
    }
    chan.mMainChannel = true;
    try {
        return chan.mChannelFd.dup();
    } catch (IOException e) {
        return null;
    }
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException)

Aggregations

ParcelFileDescriptor (android.os.ParcelFileDescriptor)526 IOException (java.io.IOException)199 FileNotFoundException (java.io.FileNotFoundException)136 RemoteException (android.os.RemoteException)127 File (java.io.File)127 FileDescriptor (java.io.FileDescriptor)58 FileOutputStream (java.io.FileOutputStream)58 AssetFileDescriptor (android.content.res.AssetFileDescriptor)44 FileInputStream (java.io.FileInputStream)36 Parcel (android.os.Parcel)35 Uri (android.net.Uri)33 Intent (android.content.Intent)30 Bundle (android.os.Bundle)29 Cursor (android.database.Cursor)27 StorageManager (android.os.storage.StorageManager)25 Request (android.app.DownloadManager.Request)24 Bitmap (android.graphics.Bitmap)22 InputStream (java.io.InputStream)18 ProfilerInfo (android.app.ProfilerInfo)17 Binder (android.os.Binder)17