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);
}
}
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));
}
}
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;
}
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;
}
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);
}
}
Aggregations