Search in sources :

Example 96 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 97 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 98 with ParcelFileDescriptor

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

the class ContentProviderProxy method openFile.

public ParcelFileDescriptor openFile(Uri url, String mode) throws RemoteException, FileNotFoundException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInterfaceToken(IContentProvider.descriptor);
        url.writeToParcel(data, 0);
        data.writeString(mode);
        mRemote.transact(IContentProvider.OPEN_FILE_TRANSACTION, data, reply, 0);
        DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(reply);
        int has = reply.readInt();
        ParcelFileDescriptor fd = has != 0 ? reply.readFileDescriptor() : null;
        return fd;
    } finally {
        data.recycle();
        reply.recycle();
    }
}
Also used : Parcel(android.os.Parcel) ParcelFileDescriptor(android.os.ParcelFileDescriptor)

Example 99 with ParcelFileDescriptor

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

the class ContentProvider method openPipeHelper.

/**
     * A helper function for implementing {@link #openTypedAssetFile}, for
     * creating a data pipe and background thread allowing you to stream
     * generated data back to the client.  This function returns a new
     * ParcelFileDescriptor that should be returned to the caller (the caller
     * is responsible for closing it).
     *
     * @param uri The URI whose data is to be written.
     * @param mimeType The desired type of data to be written.
     * @param opts Options supplied by caller.
     * @param args Your own custom arguments.
     * @param func Interface implementing the function that will actually
     * stream the data.
     * @return Returns a new ParcelFileDescriptor holding the read side of
     * the pipe.  This should be returned to the caller for reading; the caller
     * is responsible for closing it when done.
     */
public <T> ParcelFileDescriptor openPipeHelper(final Uri uri, final String mimeType, final Bundle opts, final T args, final PipeDataWriter<T> func) throws FileNotFoundException {
    try {
        final ParcelFileDescriptor[] fds = ParcelFileDescriptor.createPipe();
        AsyncTask<Object, Object, Object> task = new AsyncTask<Object, Object, Object>() {

            @Override
            protected Object doInBackground(Object... params) {
                func.writeDataToPipe(fds[1], uri, mimeType, opts, args);
                try {
                    fds[1].close();
                } catch (IOException e) {
                    Log.w(TAG, "Failure closing pipe", e);
                }
                return null;
            }
        };
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Object[]) null);
        return fds[0];
    } catch (IOException e) {
        throw new FileNotFoundException("failure making pipe");
    }
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) AsyncTask(android.os.AsyncTask) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 100 with ParcelFileDescriptor

use of android.os.ParcelFileDescriptor in project android_frameworks_base by DirtyUnicorns.

the class DevicePolicyManagerService method shareBugreportWithDeviceOwnerIfExists.

private void shareBugreportWithDeviceOwnerIfExists(String bugreportUriString, String bugreportHash) {
    ParcelFileDescriptor pfd = null;
    try {
        if (bugreportUriString == null) {
            throw new FileNotFoundException();
        }
        Uri bugreportUri = Uri.parse(bugreportUriString);
        pfd = mContext.getContentResolver().openFileDescriptor(bugreportUri, "r");
        synchronized (this) {
            Intent intent = new Intent(DeviceAdminReceiver.ACTION_BUGREPORT_SHARE);
            intent.setComponent(mOwners.getDeviceOwnerComponent());
            intent.setDataAndType(bugreportUri, RemoteBugreportUtils.BUGREPORT_MIMETYPE);
            intent.putExtra(DeviceAdminReceiver.EXTRA_BUGREPORT_HASH, bugreportHash);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            LocalServices.getService(ActivityManagerInternal.class).grantUriPermissionFromIntent(Process.SHELL_UID, mOwners.getDeviceOwnerComponent().getPackageName(), intent, mOwners.getDeviceOwnerUserId());
            mContext.sendBroadcastAsUser(intent, UserHandle.of(mOwners.getDeviceOwnerUserId()));
        }
    } catch (FileNotFoundException e) {
        Bundle extras = new Bundle();
        extras.putInt(DeviceAdminReceiver.EXTRA_BUGREPORT_FAILURE_REASON, DeviceAdminReceiver.BUGREPORT_FAILURE_FILE_NO_LONGER_AVAILABLE);
        sendDeviceOwnerCommand(DeviceAdminReceiver.ACTION_BUGREPORT_FAILED, extras);
    } finally {
        try {
            if (pfd != null) {
                pfd.close();
            }
        } catch (IOException ex) {
        // Ignore
        }
        mRemoteBugreportSharingAccepted.set(false);
        setDeviceOwnerRemoteBugreportUriAndHash(null, null);
    }
}
Also used : ActivityManagerInternal(android.app.ActivityManagerInternal) Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileNotFoundException(java.io.FileNotFoundException) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) IOException(java.io.IOException) Uri(android.net.Uri)

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