android.os.ICancellationSignal Java Examples

The following examples show how to use android.os.ICancellationSignal. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContentResolver.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This allows clients to request an explicit refresh of content identified by {@code uri}.
 * <p>
 * Client code should only invoke this method when there is a strong indication (such as a user
 * initiated pull to refresh gesture) that the content is stale.
 * <p>
 *
 * @param url The Uri identifying the data to refresh.
 * @param args Additional options from the client. The definitions of these are specific to the
 *            content provider being called.
 * @param cancellationSignal A signal to cancel the operation in progress, or {@code null} if
 *            none. For example, if you called refresh on a particular uri, you should call
 *            {@link CancellationSignal#throwIfCanceled()} to check whether the client has
 *            canceled the refresh request.
 * @return true if the provider actually tried refreshing.
 */
public final boolean refresh(@NonNull Uri url, @Nullable Bundle args,
        @Nullable CancellationSignal cancellationSignal) {
    Preconditions.checkNotNull(url, "url");
    IContentProvider provider = acquireProvider(url);
    if (provider == null) {
        return false;
    }

    try {
        ICancellationSignal remoteCancellationSignal = null;
        if (cancellationSignal != null) {
            cancellationSignal.throwIfCanceled();
            remoteCancellationSignal = provider.createCancellationSignal();
            cancellationSignal.setRemote(remoteCancellationSignal);
        }
        return provider.refresh(mPackageName, url, args, remoteCancellationSignal);
    } catch (RemoteException e) {
        // Arbitrary and not worth documenting, as Activity
        // Manager will kill this process shortly anyway.
        return false;
    } finally {
        releaseProvider(provider);
    }
}
 
Example #2
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContentProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean refresh(String callingPkg, Uri uri, Bundle args,
        ICancellationSignal cancellationSignal) throws RemoteException {
    validateIncomingUri(uri);
    uri = getUriWithoutUserId(uri);
    if (enforceReadPermission(callingPkg, uri, null) != AppOpsManager.MODE_ALLOWED) {
        return false;
    }
    final String original = setCallingPackage(callingPkg);
    try {
        return ContentProvider.this.refresh(uri, args,
                CancellationSignal.fromTransport(cancellationSignal));
    } finally {
        setCallingPackage(original);
    }
}
 
Example #3
Source Project: android_9.0.0_r45   Author: lulululbj   File: CancellationSignal.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets the remote transport.
 *
 * If {@link CancellationSignal#cancel} has already been called, then the provided
 * remote transport is canceled immediately.
 *
 * This method is guaranteed that the remote transport will not be called after it
 * has been removed.
 *
 * @param remote The remote transport, or null to remove.
 *
 * @hide
 */
public void setRemote(ICancellationSignal remote) {
    synchronized (this) {
        waitForCancelFinishedLocked();

        if (mRemote == remote) {
            return;
        }
        mRemote = remote;
        if (!mIsCanceled || remote == null) {
            return;
        }
    }
    try {
        remote.cancel();
    } catch (RemoteException ex) {
    }
}
 
Example #4
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentResolver.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This allows clients to request an explicit refresh of content identified by {@code uri}.
 * <p>
 * Client code should only invoke this method when there is a strong indication (such as a user
 * initiated pull to refresh gesture) that the content is stale.
 * <p>
 *
 * @param url The Uri identifying the data to refresh.
 * @param args Additional options from the client. The definitions of these are specific to the
 *            content provider being called.
 * @param cancellationSignal A signal to cancel the operation in progress, or {@code null} if
 *            none. For example, if you called refresh on a particular uri, you should call
 *            {@link CancellationSignal#throwIfCanceled()} to check whether the client has
 *            canceled the refresh request.
 * @return true if the provider actually tried refreshing.
 */
public final boolean refresh(@NonNull Uri url, @Nullable Bundle args,
        @Nullable CancellationSignal cancellationSignal) {
    Preconditions.checkNotNull(url, "url");
    IContentProvider provider = acquireProvider(url);
    if (provider == null) {
        return false;
    }

    try {
        ICancellationSignal remoteCancellationSignal = null;
        if (cancellationSignal != null) {
            cancellationSignal.throwIfCanceled();
            remoteCancellationSignal = provider.createCancellationSignal();
            cancellationSignal.setRemote(remoteCancellationSignal);
        }
        return provider.refresh(mPackageName, url, args, remoteCancellationSignal);
    } catch (RemoteException e) {
        // Arbitrary and not worth documenting, as Activity
        // Manager will kill this process shortly anyway.
        return false;
    } finally {
        releaseProvider(provider);
    }
}
 
Example #5
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean refresh(String callingPkg, Uri uri, Bundle args,
        ICancellationSignal cancellationSignal) throws RemoteException {
    uri = validateIncomingUri(uri);
    uri = getUriWithoutUserId(uri);
    if (enforceReadPermission(callingPkg, uri, null) != AppOpsManager.MODE_ALLOWED) {
        return false;
    }
    final String original = setCallingPackage(callingPkg);
    try {
        return ContentProvider.this.refresh(uri, args,
                CancellationSignal.fromTransport(cancellationSignal));
    } finally {
        setCallingPackage(original);
    }
}
 
Example #6
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentProviderClient.java    License: Apache License 2.0 6 votes vote down vote up
/** See {@link ContentProvider#refresh} */
public boolean refresh(Uri url, @Nullable Bundle args,
        @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);
        }
        return mContentProvider.refresh(mPackageName, url, args, remoteCancellationSignal);
    } catch (DeadObjectException e) {
        if (!mStable) {
            mContentResolver.unstableProviderDied(mContentProvider);
        }
        throw e;
    } finally {
        afterRemote();
    }
}
 
Example #7
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentProviderClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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.
 */
public @Nullable 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();
    }
}
 
Example #8
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentProviderClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * See {@link ContentProvider#openAssetFile ContentProvider.openAssetFile}.
 * 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#openAssetFileDescriptor
 * ContentResolver.openAssetFileDescriptor} API instead.
 */
public @Nullable AssetFileDescriptor openAssetFile(@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.openAssetFile(mPackageName, url, mode, remoteSignal);
    } catch (DeadObjectException e) {
        if (!mStable) {
            mContentResolver.unstableProviderDied(mContentProvider);
        }
        throw e;
    } finally {
        afterRemote();
    }
}
 
Example #9
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentProviderClient.java    License: Apache License 2.0 6 votes vote down vote up
/** See {@link ContentProvider#openTypedAssetFile ContentProvider.openTypedAssetFile} */
public final @Nullable 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();
    }
}
 
Example #10
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentProviderNative.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public AssetFileDescriptor openAssetFile(
        String callingPkg, Uri url, String mode, ICancellationSignal signal)
        throws RemoteException, FileNotFoundException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInterfaceToken(IContentProvider.descriptor);

        data.writeString(callingPkg);
        url.writeToParcel(data, 0);
        data.writeString(mode);
        data.writeStrongBinder(signal != null ? signal.asBinder() : null);

        mRemote.transact(IContentProvider.OPEN_ASSET_FILE_TRANSACTION, data, reply, 0);

        DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(reply);
        int has = reply.readInt();
        AssetFileDescriptor fd = has != 0
                ? AssetFileDescriptor.CREATOR.createFromParcel(reply) : null;
        return fd;
    } finally {
        data.recycle();
        reply.recycle();
    }
}
 
Example #11
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentProviderNative.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public AssetFileDescriptor openTypedAssetFile(String callingPkg, Uri url, String mimeType,
        Bundle opts, ICancellationSignal signal) throws RemoteException, FileNotFoundException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInterfaceToken(IContentProvider.descriptor);

        data.writeString(callingPkg);
        url.writeToParcel(data, 0);
        data.writeString(mimeType);
        data.writeBundle(opts);
        data.writeStrongBinder(signal != null ? signal.asBinder() : null);

        mRemote.transact(IContentProvider.OPEN_TYPED_ASSET_FILE_TRANSACTION, data, reply, 0);

        DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(reply);
        int has = reply.readInt();
        AssetFileDescriptor fd = has != 0
                ? AssetFileDescriptor.CREATOR.createFromParcel(reply) : null;
        return fd;
    } finally {
        data.recycle();
        reply.recycle();
    }
}
 
Example #12
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentProviderNative.java    License: Apache License 2.0 6 votes vote down vote up
@Override
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();
    }
}
 
Example #13
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentProviderNative.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean refresh(String callingPkg, Uri url, Bundle args, ICancellationSignal signal)
        throws RemoteException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInterfaceToken(IContentProvider.descriptor);

        data.writeString(callingPkg);
        url.writeToParcel(data, 0);
        data.writeBundle(args);
        data.writeStrongBinder(signal != null ? signal.asBinder() : null);

        mRemote.transact(IContentProvider.REFRESH_TRANSACTION, data, reply, 0);

        DatabaseUtils.readExceptionFromParcel(reply);
        int success = reply.readInt();
        return (success == 0);
    } finally {
        data.recycle();
        reply.recycle();
    }
}
 
Example #14
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContentProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Cursor query(String callingPkg, Uri uri, @Nullable String[] projection,
        @Nullable Bundle queryArgs, @Nullable ICancellationSignal cancellationSignal) {
    validateIncomingUri(uri);
    uri = maybeGetUriWithoutUserId(uri);
    if (enforceReadPermission(callingPkg, uri, null) != AppOpsManager.MODE_ALLOWED) {
        // The caller has no access to the data, so return an empty cursor with
        // the columns in the requested order. The caller may ask for an invalid
        // column and we would not catch that but this is not a problem in practice.
        // We do not call ContentProvider#query with a modified where clause since
        // the implementation is not guaranteed to be backed by a SQL database, hence
        // it may not handle properly the tautology where clause we would have created.
        if (projection != null) {
            return new MatrixCursor(projection, 0);
        }

        // Null projection means all columns but we have no idea which they are.
        // However, the caller may be expecting to access them my index. Hence,
        // we have to execute the query as if allowed to get a cursor with the
        // columns. We then use the column names to return an empty cursor.
        Cursor cursor = ContentProvider.this.query(
                uri, projection, queryArgs,
                CancellationSignal.fromTransport(cancellationSignal));
        if (cursor == null) {
            return null;
        }

        // Return an empty cursor for all columns.
        return new MatrixCursor(cursor.getColumnNames(), 0);
    }
    final String original = setCallingPackage(callingPkg);
    try {
        return ContentProvider.this.query(
                uri, projection, queryArgs,
                CancellationSignal.fromTransport(cancellationSignal));
    } finally {
        setCallingPackage(original);
    }
}
 
Example #15
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContentProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ParcelFileDescriptor openFile(
        String callingPkg, Uri uri, String mode, ICancellationSignal cancellationSignal,
        IBinder callerToken) throws FileNotFoundException {
    validateIncomingUri(uri);
    uri = maybeGetUriWithoutUserId(uri);
    enforceFilePermission(callingPkg, uri, mode, callerToken);
    final String original = setCallingPackage(callingPkg);
    try {
        return ContentProvider.this.openFile(
                uri, mode, CancellationSignal.fromTransport(cancellationSignal));
    } finally {
        setCallingPackage(original);
    }
}
 
Example #16
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContentProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public AssetFileDescriptor openAssetFile(
        String callingPkg, Uri uri, String mode, ICancellationSignal cancellationSignal)
        throws FileNotFoundException {
    validateIncomingUri(uri);
    uri = maybeGetUriWithoutUserId(uri);
    enforceFilePermission(callingPkg, uri, mode, null);
    final String original = setCallingPackage(callingPkg);
    try {
        return ContentProvider.this.openAssetFile(
                uri, mode, CancellationSignal.fromTransport(cancellationSignal));
    } finally {
        setCallingPackage(original);
    }
}
 
Example #17
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContentProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public AssetFileDescriptor openTypedAssetFile(String callingPkg, Uri uri, String mimeType,
        Bundle opts, ICancellationSignal cancellationSignal) throws FileNotFoundException {
    Bundle.setDefusable(opts, true);
    validateIncomingUri(uri);
    uri = maybeGetUriWithoutUserId(uri);
    enforceFilePermission(callingPkg, uri, "r", null);
    final String original = setCallingPackage(callingPkg);
    try {
        return ContentProvider.this.openTypedAssetFile(
                uri, mimeType, opts, CancellationSignal.fromTransport(cancellationSignal));
    } finally {
        setCallingPackage(original);
    }
}
 
Example #18
Source Project: android_9.0.0_r45   Author: lulululbj   File: PrintManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void layout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
        ILayoutResultCallback callback, Bundle metadata, int sequence) {

    ICancellationSignal cancellationTransport = CancellationSignal.createTransport();
    try {
        callback.onLayoutStarted(cancellationTransport, sequence);
    } catch (RemoteException re) {
        // The spooler is dead - can't recover.
        Log.e(LOG_TAG, "Error notifying for layout start", re);
        return;
    }

    synchronized (mLock) {
        // If destroyed the handler is null.
        if (isDestroyedLocked()) {
            return;
        }

        CancellationSignal cancellationSignal = CancellationSignal.fromTransport(
                cancellationTransport);

        SomeArgs args = SomeArgs.obtain();
        args.arg1 = mDocumentAdapter;
        args.arg2 = oldAttributes;
        args.arg3 = newAttributes;
        args.arg4 = cancellationSignal;
        args.arg5 = new MyLayoutResultCallback(callback, sequence);
        args.arg6 = metadata;

        mHandler.obtainMessage(MyHandler.MSG_ON_LAYOUT, args).sendToTarget();
    }
}
 
Example #19
Source Project: android_9.0.0_r45   Author: lulululbj   File: PrintManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void write(PageRange[] pages, ParcelFileDescriptor fd,
        IWriteResultCallback callback, int sequence) {

    ICancellationSignal cancellationTransport = CancellationSignal.createTransport();
    try {
        callback.onWriteStarted(cancellationTransport, sequence);
    } catch (RemoteException re) {
        // The spooler is dead - can't recover.
        Log.e(LOG_TAG, "Error notifying for write start", re);
        return;
    }

    synchronized (mLock) {
        // If destroyed the handler is null.
        if (isDestroyedLocked()) {
            return;
        }

        CancellationSignal cancellationSignal = CancellationSignal.fromTransport(
                cancellationTransport);

        SomeArgs args = SomeArgs.obtain();
        args.arg1 = mDocumentAdapter;
        args.arg2 = pages;
        args.arg3 = fd;
        args.arg4 = cancellationSignal;
        args.arg5 = new MyWriteResultCallback(callback, fd, sequence);

        mHandler.obtainMessage(MyHandler.MSG_ON_WRITE, args).sendToTarget();
    }
}
 
Example #20
Source Project: android_9.0.0_r45   Author: lulululbj   File: CancellationSignal.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Cancels the operation and signals the cancellation listener.
 * If the operation has not yet started, then it will be canceled as soon as it does.
 */
public void cancel() {
    final OnCancelListener listener;
    final ICancellationSignal remote;
    synchronized (this) {
        if (mIsCanceled) {
            return;
        }
        mIsCanceled = true;
        mCancelInProgress = true;
        listener = mOnCancelListener;
        remote = mRemote;
    }

    try {
        if (listener != null) {
            listener.onCancel();
        }
        if (remote != null) {
            try {
                remote.cancel();
            } catch (RemoteException ex) {
            }
        }
    } finally {
        synchronized (this) {
            mCancelInProgress = false;
            notifyAll();
        }
    }
}
 
Example #21
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Cursor query(String callingPkg, Uri uri, @Nullable String[] projection,
        @Nullable Bundle queryArgs, @Nullable ICancellationSignal cancellationSignal) {
    uri = validateIncomingUri(uri);
    uri = maybeGetUriWithoutUserId(uri);
    if (enforceReadPermission(callingPkg, uri, null) != AppOpsManager.MODE_ALLOWED) {
        // The caller has no access to the data, so return an empty cursor with
        // the columns in the requested order. The caller may ask for an invalid
        // column and we would not catch that but this is not a problem in practice.
        // We do not call ContentProvider#query with a modified where clause since
        // the implementation is not guaranteed to be backed by a SQL database, hence
        // it may not handle properly the tautology where clause we would have created.
        if (projection != null) {
            return new MatrixCursor(projection, 0);
        }

        // Null projection means all columns but we have no idea which they are.
        // However, the caller may be expecting to access them my index. Hence,
        // we have to execute the query as if allowed to get a cursor with the
        // columns. We then use the column names to return an empty cursor.
        Cursor cursor = ContentProvider.this.query(
                uri, projection, queryArgs,
                CancellationSignal.fromTransport(cancellationSignal));
        if (cursor == null) {
            return null;
        }

        // Return an empty cursor for all columns.
        return new MatrixCursor(cursor.getColumnNames(), 0);
    }
    final String original = setCallingPackage(callingPkg);
    try {
        return ContentProvider.this.query(
                uri, projection, queryArgs,
                CancellationSignal.fromTransport(cancellationSignal));
    } finally {
        setCallingPackage(original);
    }
}
 
Example #22
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ParcelFileDescriptor openFile(
        String callingPkg, Uri uri, String mode, ICancellationSignal cancellationSignal,
        IBinder callerToken) throws FileNotFoundException {
    uri = validateIncomingUri(uri);
    uri = maybeGetUriWithoutUserId(uri);
    enforceFilePermission(callingPkg, uri, mode, callerToken);
    final String original = setCallingPackage(callingPkg);
    try {
        return ContentProvider.this.openFile(
                uri, mode, CancellationSignal.fromTransport(cancellationSignal));
    } finally {
        setCallingPackage(original);
    }
}
 
Example #23
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public AssetFileDescriptor openAssetFile(
        String callingPkg, Uri uri, String mode, ICancellationSignal cancellationSignal)
        throws FileNotFoundException {
    uri = validateIncomingUri(uri);
    uri = maybeGetUriWithoutUserId(uri);
    enforceFilePermission(callingPkg, uri, mode, null);
    final String original = setCallingPackage(callingPkg);
    try {
        return ContentProvider.this.openAssetFile(
                uri, mode, CancellationSignal.fromTransport(cancellationSignal));
    } finally {
        setCallingPackage(original);
    }
}
 
Example #24
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public AssetFileDescriptor openTypedAssetFile(String callingPkg, Uri uri, String mimeType,
        Bundle opts, ICancellationSignal cancellationSignal) throws FileNotFoundException {
    Bundle.setDefusable(opts, true);
    uri = validateIncomingUri(uri);
    uri = maybeGetUriWithoutUserId(uri);
    enforceFilePermission(callingPkg, uri, "r", null);
    final String original = setCallingPackage(callingPkg);
    try {
        return ContentProvider.this.openTypedAssetFile(
                uri, mimeType, opts, CancellationSignal.fromTransport(cancellationSignal));
    } finally {
        setCallingPackage(original);
    }
}
 
Example #25
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentProviderClient.java    License: Apache License 2.0 5 votes vote down vote up
/** See {@link ContentProvider#query ContentProvider.query} */
public @Nullable Cursor query(@NonNull Uri uri, @Nullable String[] projection,
        Bundle queryArgs, @Nullable CancellationSignal cancellationSignal)
                throws RemoteException {
    Preconditions.checkNotNull(uri, "url");

    beforeRemote();
    try {
        ICancellationSignal remoteCancellationSignal = null;
        if (cancellationSignal != null) {
            cancellationSignal.throwIfCanceled();
            remoteCancellationSignal = mContentProvider.createCancellationSignal();
            cancellationSignal.setRemote(remoteCancellationSignal);
        }
        final Cursor cursor = mContentProvider.query(
                mPackageName, uri, projection, queryArgs, remoteCancellationSignal);
        if (cursor == null) {
            return null;
        }
        return new CursorWrapperInner(cursor);
    } catch (DeadObjectException e) {
        if (!mStable) {
            mContentResolver.unstableProviderDied(mContentProvider);
        }
        throw e;
    } finally {
        afterRemote();
    }
}
 
Example #26
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContentProviderNative.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ParcelFileDescriptor openFile(
        String callingPkg, Uri url, String mode, ICancellationSignal signal, IBinder token)
        throws RemoteException, FileNotFoundException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInterfaceToken(IContentProvider.descriptor);

        data.writeString(callingPkg);
        url.writeToParcel(data, 0);
        data.writeString(mode);
        data.writeStrongBinder(signal != null ? signal.asBinder() : null);
        data.writeStrongBinder(token);

        mRemote.transact(IContentProvider.OPEN_FILE_TRANSACTION, data, reply, 0);

        DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(reply);
        int has = reply.readInt();
        ParcelFileDescriptor fd = has != 0 ? ParcelFileDescriptor.CREATOR
                .createFromParcel(reply) : null;
        return fd;
    } finally {
        data.recycle();
        reply.recycle();
    }
}
 
Example #27
Source Project: android_9.0.0_r45   Author: lulululbj   File: AutofillService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onFillRequest(FillRequest request, IFillCallback callback) {
    ICancellationSignal transport = CancellationSignal.createTransport();
    try {
        callback.onCancellable(transport);
    } catch (RemoteException e) {
        e.rethrowFromSystemServer();
    }
    mHandler.sendMessage(obtainMessage(
            AutofillService::onFillRequest,
            AutofillService.this, request, CancellationSignal.fromTransport(transport),
            new FillCallback(callback, request.getId())));
}
 
Example #28
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContentProvider.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ICancellationSignal createCancellationSignal() {
    return CancellationSignal.createTransport();
}
 
Example #29
Source Project: AndroidComponentPlugin   Author: androidmalin   File: IContentProvider.java    License: Apache License 2.0 4 votes vote down vote up
public Cursor query(String callingPkg, Uri url, @Nullable String[] projection,
@Nullable Bundle queryArgs, @Nullable ICancellationSignal cancellationSignal)
throws RemoteException;
 
Example #30
Source Project: AndroidComponentPlugin   Author: androidmalin   File: IContentProvider.java    License: Apache License 2.0 4 votes vote down vote up
public ParcelFileDescriptor openFile(
String callingPkg, Uri url, String mode, ICancellationSignal signal,
IBinder callerToken)
throws RemoteException, FileNotFoundException;