use of android.os.ParcelFileDescriptor in project cw-omnibus by commonsguy.
the class DemoDocumentsProvider method openDocument.
@Override
public ParcelFileDescriptor openDocument(String documentId, String mode, CancellationSignal signal) throws FileNotFoundException {
ParcelFileDescriptor[] pipe = null;
try {
pipe = ParcelFileDescriptor.createPipe();
AssetManager assets = getContext().getResources().getAssets();
new TransferThread(assets.open(documentId), new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1])).start();
} catch (IOException e) {
Log.e(getClass().getSimpleName(), "Exception opening pipe", e);
throw new FileNotFoundException("Could not open pipe for: " + documentId);
}
return (pipe[0]);
}
use of android.os.ParcelFileDescriptor in project android_frameworks_base by ParanoidAndroid.
the class Am method runProfile.
private void runProfile() throws Exception {
String profileFile = null;
boolean start = false;
boolean wall = false;
int userId = UserHandle.USER_CURRENT;
int profileType = 0;
String process = null;
String cmd = nextArgRequired();
if ("start".equals(cmd)) {
start = true;
String opt;
while ((opt = nextOption()) != null) {
if (opt.equals("--user")) {
userId = parseUserArg(nextArgRequired());
} else if (opt.equals("--wall")) {
wall = true;
} else {
System.err.println("Error: Unknown option: " + opt);
return;
}
}
process = nextArgRequired();
} else if ("stop".equals(cmd)) {
String opt;
while ((opt = nextOption()) != null) {
if (opt.equals("--user")) {
userId = parseUserArg(nextArgRequired());
} else {
System.err.println("Error: Unknown option: " + opt);
return;
}
}
process = nextArg();
} else {
// Compatibility with old syntax: process is specified first.
process = cmd;
cmd = nextArgRequired();
if ("start".equals(cmd)) {
start = true;
} else if (!"stop".equals(cmd)) {
throw new IllegalArgumentException("Profile command " + process + " not valid");
}
}
if (userId == UserHandle.USER_ALL) {
System.err.println("Error: Can't profile with user 'all'");
return;
}
ParcelFileDescriptor fd = null;
if (start) {
profileFile = nextArgRequired();
try {
fd = ParcelFileDescriptor.open(new File(profileFile), ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_TRUNCATE | ParcelFileDescriptor.MODE_READ_WRITE);
} catch (FileNotFoundException e) {
System.err.println("Error: Unable to open file: " + profileFile);
return;
}
}
try {
if (wall) {
// XXX doesn't work -- this needs to be set before booting.
String props = SystemProperties.get("dalvik.vm.extra-opts");
if (props == null || !props.contains("-Xprofile:wallclock")) {
props = props + " -Xprofile:wallclock";
//SystemProperties.set("dalvik.vm.extra-opts", props);
}
} else if (start) {
//removeWallOption();
}
if (!mAm.profileControl(process, userId, start, profileFile, fd, profileType)) {
wall = false;
throw new AndroidException("PROFILE FAILED on process " + process);
}
} finally {
if (!wall) {
//removeWallOption();
}
}
}
use of android.os.ParcelFileDescriptor in project android_frameworks_base by ParanoidAndroid.
the class WallpaperManager method setBitmap.
/**
* Change the current system wallpaper to a bitmap. The given bitmap is
* converted to a PNG and stored as the wallpaper. On success, the intent
* {@link Intent#ACTION_WALLPAPER_CHANGED} is broadcast.
*
* <p>This method requires the caller to hold the permission
* {@link android.Manifest.permission#SET_WALLPAPER}.
*
* @param bitmap The bitmap to save.
*
* @throws IOException If an error occurs reverting to the default
* wallpaper.
*/
public void setBitmap(Bitmap bitmap) throws IOException {
if (sGlobals.mService == null) {
Log.w(TAG, "WallpaperService not running");
return;
}
try {
ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null);
if (fd == null) {
return;
}
FileOutputStream fos = null;
try {
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
} finally {
if (fos != null) {
fos.close();
}
}
} catch (RemoteException e) {
// Ignore
}
}
use of android.os.ParcelFileDescriptor in project android_frameworks_base by ParanoidAndroid.
the class BackupHelperDispatcher method doOneBackup.
private void doOneBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState, Header header, BackupHelper helper) throws IOException {
int err;
FileDescriptor newStateFD = newState.getFileDescriptor();
// allocate space for the header in the file
int pos = allocateHeader_native(header, newStateFD);
if (pos < 0) {
throw new IOException("allocateHeader_native failed (error " + pos + ")");
}
data.setKeyPrefix(header.keyPrefix);
// do the backup
helper.performBackup(oldState, data, newState);
// fill in the header (seeking back to pos). The file pointer will be returned to
// where it was at the end of performBackup. Header.chunkSize will not be filled in.
err = writeHeader_native(header, newStateFD, pos);
if (err != 0) {
throw new IOException("writeHeader_native failed (error " + err + ")");
}
}
use of android.os.ParcelFileDescriptor 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);
}
}
Aggregations