Search in sources :

Example 11 with ICancellationSignal

use of android.os.ICancellationSignal in project android_frameworks_base by crdroidandroid.

the class ContentProviderProxy method createCancellationSignal.

public ICancellationSignal createCancellationSignal() throws RemoteException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInterfaceToken(IContentProvider.descriptor);
        mRemote.transact(IContentProvider.CREATE_CANCELATION_SIGNAL_TRANSACTION, data, reply, 0);
        DatabaseUtils.readExceptionFromParcel(reply);
        ICancellationSignal cancellationSignal = ICancellationSignal.Stub.asInterface(reply.readStrongBinder());
        return cancellationSignal;
    } finally {
        data.recycle();
        reply.recycle();
    }
}
Also used : Parcel(android.os.Parcel) ICancellationSignal(android.os.ICancellationSignal)

Example 12 with ICancellationSignal

use of android.os.ICancellationSignal in project android_frameworks_base by crdroidandroid.

the class ContentProviderClient method openTypedAssetFileDescriptor.

/** See {@link ContentProvider#openTypedAssetFile ContentProvider.openTypedAssetFile} */
@Nullable
public final AssetFileDescriptor openTypedAssetFileDescriptor(@NonNull Uri uri, @NonNull String mimeType, @Nullable Bundle opts, @Nullable CancellationSignal signal) throws RemoteException, FileNotFoundException {
    Preconditions.checkNotNull(uri, "uri");
    Preconditions.checkNotNull(mimeType, "mimeType");
    beforeRemote();
    try {
        ICancellationSignal remoteSignal = null;
        if (signal != null) {
            signal.throwIfCanceled();
            remoteSignal = mContentProvider.createCancellationSignal();
            signal.setRemote(remoteSignal);
        }
        return mContentProvider.openTypedAssetFile(mPackageName, uri, mimeType, opts, remoteSignal);
    } catch (DeadObjectException e) {
        if (!mStable) {
            mContentResolver.unstableProviderDied(mContentProvider);
        }
        throw e;
    } finally {
        afterRemote();
    }
}
Also used : ICancellationSignal(android.os.ICancellationSignal) DeadObjectException(android.os.DeadObjectException) Nullable(android.annotation.Nullable)

Example 13 with ICancellationSignal

use of android.os.ICancellationSignal in project android_frameworks_base by AOSPA.

the class ContentProviderClient method openFile.

/**
     * See {@link ContentProvider#openFile ContentProvider.openFile}.  Note that
     * this <em>does not</em>
     * take care of non-content: URIs such as file:.  It is strongly recommended
     * you use the {@link ContentResolver#openFileDescriptor
     * ContentResolver.openFileDescriptor} API instead.
     */
@Nullable
public ParcelFileDescriptor openFile(@NonNull Uri url, @NonNull String mode, @Nullable CancellationSignal signal) throws RemoteException, FileNotFoundException {
    Preconditions.checkNotNull(url, "url");
    Preconditions.checkNotNull(mode, "mode");
    beforeRemote();
    try {
        ICancellationSignal remoteSignal = null;
        if (signal != null) {
            signal.throwIfCanceled();
            remoteSignal = mContentProvider.createCancellationSignal();
            signal.setRemote(remoteSignal);
        }
        return mContentProvider.openFile(mPackageName, url, mode, remoteSignal, null);
    } catch (DeadObjectException e) {
        if (!mStable) {
            mContentResolver.unstableProviderDied(mContentProvider);
        }
        throw e;
    } finally {
        afterRemote();
    }
}
Also used : ICancellationSignal(android.os.ICancellationSignal) DeadObjectException(android.os.DeadObjectException) Nullable(android.annotation.Nullable)

Example 14 with ICancellationSignal

use of android.os.ICancellationSignal in project android_frameworks_base by AOSPA.

the class ContentResolver method openTypedAssetFileDescriptor.

/**
     * Open a raw file descriptor to access (potentially type transformed)
     * data from a "content:" URI.  This interacts with the underlying
     * {@link ContentProvider#openTypedAssetFile} method of the provider
     * associated with the given URI, to retrieve retrieve any appropriate
     * data stream for the data stored there.
     *
     * <p>Unlike {@link #openAssetFileDescriptor}, this function only works
     * with "content:" URIs, because content providers are the only facility
     * with an associated MIME type to ensure that the returned data stream
     * is of the desired type.
     *
     * <p>All text/* streams are encoded in UTF-8.
     *
     * @param uri The desired URI to open.
     * @param mimeType The desired MIME type of the returned data.  This can
     * be a pattern such as *&#47;*, which will allow the content provider to
     * select a type, though there is no way for you to determine what type
     * it is returning.
     * @param opts Additional provider-dependent options.
     * @param cancellationSignal A signal to cancel the operation in progress,
     *         or null if none. If the operation is canceled, then
     *         {@link OperationCanceledException} will be thrown.
     * @return Returns a new ParcelFileDescriptor from which you can read the
     * data stream from the provider.  Note that this may be a pipe, meaning
     * you can't seek in it.  The only seek you should do is if the
     * AssetFileDescriptor contains an offset, to move to that offset before
     * reading.  You own this descriptor and are responsible for closing it when done.
     * @throws FileNotFoundException Throws FileNotFoundException of no
     * data of the desired type exists under the URI.
     */
@Nullable
public final AssetFileDescriptor openTypedAssetFileDescriptor(@NonNull Uri uri, @NonNull String mimeType, @Nullable Bundle opts, @Nullable CancellationSignal cancellationSignal) throws FileNotFoundException {
    Preconditions.checkNotNull(uri, "uri");
    Preconditions.checkNotNull(mimeType, "mimeType");
    IContentProvider unstableProvider = acquireUnstableProvider(uri);
    if (unstableProvider == null) {
        throw new FileNotFoundException("No content provider: " + uri);
    }
    IContentProvider stableProvider = null;
    AssetFileDescriptor fd = null;
    try {
        ICancellationSignal remoteCancellationSignal = null;
        if (cancellationSignal != null) {
            cancellationSignal.throwIfCanceled();
            remoteCancellationSignal = unstableProvider.createCancellationSignal();
            cancellationSignal.setRemote(remoteCancellationSignal);
        }
        try {
            fd = unstableProvider.openTypedAssetFile(mPackageName, uri, mimeType, opts, remoteCancellationSignal);
            if (fd == null) {
                // The provider will be released by the finally{} clause
                return null;
            }
        } catch (DeadObjectException e) {
            // The remote process has died...  but we only hold an unstable
            // reference though, so we might recover!!!  Let's try!!!!
            // This is exciting!!1!!1!!!!1
            unstableProviderDied(unstableProvider);
            stableProvider = acquireProvider(uri);
            if (stableProvider == null) {
                throw new FileNotFoundException("No content provider: " + uri);
            }
            fd = stableProvider.openTypedAssetFile(mPackageName, uri, mimeType, opts, remoteCancellationSignal);
            if (fd == null) {
                // The provider will be released by the finally{} clause
                return null;
            }
        }
        if (stableProvider == null) {
            stableProvider = acquireProvider(uri);
        }
        releaseUnstableProvider(unstableProvider);
        unstableProvider = null;
        ParcelFileDescriptor pfd = new ParcelFileDescriptorInner(fd.getParcelFileDescriptor(), stableProvider);
        // Success!  Don't release the provider when exiting, let
        // ParcelFileDescriptorInner do that when it is closed.
        stableProvider = null;
        return new AssetFileDescriptor(pfd, fd.getStartOffset(), fd.getDeclaredLength());
    } catch (RemoteException e) {
        // Whatever, whatever, we'll go away.
        throw new FileNotFoundException("Failed opening content provider: " + uri);
    } catch (FileNotFoundException e) {
        throw e;
    } finally {
        if (cancellationSignal != null) {
            cancellationSignal.setRemote(null);
        }
        if (stableProvider != null) {
            releaseProvider(stableProvider);
        }
        if (unstableProvider != null) {
            releaseUnstableProvider(unstableProvider);
        }
    }
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) FileNotFoundException(java.io.FileNotFoundException) ICancellationSignal(android.os.ICancellationSignal) ParcelFileDescriptor(android.os.ParcelFileDescriptor) DeadObjectException(android.os.DeadObjectException) RemoteException(android.os.RemoteException) Nullable(android.annotation.Nullable)

Example 15 with ICancellationSignal

use of android.os.ICancellationSignal in project android_frameworks_base by AOSPA.

the class ContentProviderClient method query.

/** See {@link ContentProvider#query ContentProvider.query} */
@Nullable
public Cursor query(@NonNull Uri url, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder, @Nullable CancellationSignal cancellationSignal) throws RemoteException {
    Preconditions.checkNotNull(url, "url");
    beforeRemote();
    try {
        ICancellationSignal remoteCancellationSignal = null;
        if (cancellationSignal != null) {
            cancellationSignal.throwIfCanceled();
            remoteCancellationSignal = mContentProvider.createCancellationSignal();
            cancellationSignal.setRemote(remoteCancellationSignal);
        }
        final Cursor cursor = mContentProvider.query(mPackageName, url, projection, selection, selectionArgs, sortOrder, remoteCancellationSignal);
        if (cursor == null) {
            return null;
        }
        if ("com.google.android.gms".equals(mPackageName)) {
            // They're casting to a concrete subclass, sigh
            return cursor;
        } else {
            return new CursorWrapperInner(cursor);
        }
    } catch (DeadObjectException e) {
        if (!mStable) {
            mContentResolver.unstableProviderDied(mContentProvider);
        }
        throw e;
    } finally {
        afterRemote();
    }
}
Also used : ICancellationSignal(android.os.ICancellationSignal) DeadObjectException(android.os.DeadObjectException) Cursor(android.database.Cursor) Nullable(android.annotation.Nullable)

Aggregations

ICancellationSignal (android.os.ICancellationSignal)49 DeadObjectException (android.os.DeadObjectException)37 Nullable (android.annotation.Nullable)35 RemoteException (android.os.RemoteException)16 Cursor (android.database.Cursor)11 AssetFileDescriptor (android.content.res.AssetFileDescriptor)10 ParcelFileDescriptor (android.os.ParcelFileDescriptor)10 FileNotFoundException (java.io.FileNotFoundException)10 Parcel (android.os.Parcel)6 Resources (android.content.res.Resources)5 File (java.io.File)5