Search in sources :

Example 6 with CancellationSignal

use of android.os.CancellationSignal in project android_frameworks_base by ResurrectionRemix.

the class CursorLoader method loadInBackground.

/* Runs on a worker thread */
@Override
public Cursor loadInBackground() {
    synchronized (this) {
        if (isLoadInBackgroundCanceled()) {
            throw new OperationCanceledException();
        }
        mCancellationSignal = new CancellationSignal();
    }
    try {
        Cursor cursor = getContext().getContentResolver().query(mUri, mProjection, mSelection, mSelectionArgs, mSortOrder, mCancellationSignal);
        if (cursor != null) {
            try {
                // Ensure the cursor window is filled.
                cursor.getCount();
                cursor.registerContentObserver(mObserver);
            } catch (RuntimeException ex) {
                cursor.close();
                throw ex;
            }
        }
        return cursor;
    } finally {
        synchronized (this) {
            mCancellationSignal = null;
        }
    }
}
Also used : OperationCanceledException(android.os.OperationCanceledException) Cursor(android.database.Cursor) CancellationSignal(android.os.CancellationSignal)

Example 7 with CancellationSignal

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

the class RemoteViews method startTaskOnExecutor.

private CancellationSignal startTaskOnExecutor(AsyncApplyTask task, Executor executor) {
    CancellationSignal cancelSignal = new CancellationSignal();
    cancelSignal.setOnCancelListener(task);
    task.executeOnExecutor(executor == null ? AsyncTask.THREAD_POOL_EXECUTOR : executor);
    return cancelSignal;
}
Also used : CancellationSignal(android.os.CancellationSignal)

Example 8 with CancellationSignal

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

the class MtpManagerTest method testCancelEvent.

public void testCancelEvent() throws Exception {
    final CancellationSignal signal = new CancellationSignal();
    final FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() {

        @Override
        public Boolean call() throws IOException {
            try {
                while (true) {
                    mManager.readEvent(mUsbDevice.getDeviceId(), signal);
                }
            } catch (OperationCanceledException exception) {
                return true;
            }
        }
    });
    final Thread thread = new Thread(future);
    thread.start();
    SystemClock.sleep(TIMEOUT_MS);
    signal.cancel();
    assertTrue(future.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
}
Also used : FutureTask(java.util.concurrent.FutureTask) OperationCanceledException(android.os.OperationCanceledException) IOException(java.io.IOException) CancellationSignal(android.os.CancellationSignal)

Example 9 with CancellationSignal

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

the class DirectoryLoader method loadInBackground.

@Override
public final DirectoryResult loadInBackground() {
    synchronized (this) {
        if (isLoadInBackgroundCanceled()) {
            throw new OperationCanceledException();
        }
        mSignal = new CancellationSignal();
    }
    final ContentResolver resolver = getContext().getContentResolver();
    final String authority = mUri.getAuthority();
    final DirectoryResult result = new DirectoryResult();
    result.doc = mDoc;
    // Use default document when searching
    if (mSearchMode) {
        final Uri docUri = DocumentsContract.buildDocumentUri(mRoot.authority, mRoot.documentId);
        try {
            mDoc = DocumentInfo.fromUri(resolver, docUri);
        } catch (FileNotFoundException e) {
            Log.w(TAG, "Failed to query", e);
            result.exception = e;
            return result;
        }
    }
    if (mUserSortOrder != State.SORT_ORDER_UNKNOWN) {
        result.sortOrder = mUserSortOrder;
    } else {
        if ((mDoc.flags & Document.FLAG_DIR_PREFERS_LAST_MODIFIED) != 0) {
            result.sortOrder = State.SORT_ORDER_LAST_MODIFIED;
        } else {
            result.sortOrder = State.SORT_ORDER_DISPLAY_NAME;
        }
    }
    // Search always uses ranking from provider
    if (mSearchMode) {
        result.sortOrder = State.SORT_ORDER_UNKNOWN;
    }
    if (DEBUG)
        Log.d(TAG, "userSortOrder=" + mUserSortOrder + ", sortOrder=" + result.sortOrder);
    ContentProviderClient client = null;
    Cursor cursor = null;
    try {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, authority);
        cursor = client.query(mUri, null, null, null, getQuerySortOrder(result.sortOrder), mSignal);
        if (cursor == null) {
            throw new RemoteException("Provider returned null");
        }
        cursor.registerContentObserver(mObserver);
        cursor = new RootCursorWrapper(mUri.getAuthority(), mRoot.rootId, cursor, -1);
        if (mSearchMode) {
            // Filter directories out of search results, for now
            cursor = new FilteringCursorWrapper(cursor, null, SEARCH_REJECT_MIMES);
        }
        result.client = client;
        result.cursor = cursor;
    } catch (Exception e) {
        Log.w(TAG, "Failed to query", e);
        result.exception = e;
        ContentProviderClient.releaseQuietly(client);
    } finally {
        synchronized (this) {
            mSignal = null;
        }
    }
    return result;
}
Also used : OperationCanceledException(android.os.OperationCanceledException) FileNotFoundException(java.io.FileNotFoundException) Cursor(android.database.Cursor) Uri(android.net.Uri) OperationCanceledException(android.os.OperationCanceledException) RemoteException(android.os.RemoteException) FileNotFoundException(java.io.FileNotFoundException) ContentResolver(android.content.ContentResolver) RemoteException(android.os.RemoteException) CancellationSignal(android.os.CancellationSignal) ContentProviderClient(android.content.ContentProviderClient)

Example 10 with CancellationSignal

use of android.os.CancellationSignal in project LolliPin by OrangeGangsters.

the class FingerprintUiHelper method startListening.

/**
     * Starts listening to {@link FingerprintManager}
     *
     * @throws SecurityException If the hardware is not available, or the permission are not set
     */
public void startListening() throws SecurityException {
    if (initCipher()) {
        FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(mCipher);
        if (!isFingerprintAuthAvailable()) {
            return;
        }
        mCancellationSignal = new CancellationSignal();
        mSelfCancelled = false;
        mFingerprintManager.authenticate(cryptoObject, mCancellationSignal, 0, /* flags */
        this, null);
        mIcon.setImageResource(R.drawable.ic_fp_40px);
    }
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager) CancellationSignal(android.os.CancellationSignal)

Aggregations

CancellationSignal (android.os.CancellationSignal)79 OperationCanceledException (android.os.OperationCanceledException)18 Cursor (android.database.Cursor)13 FileNotFoundException (java.io.FileNotFoundException)11 IOException (java.io.IOException)11 RemoteException (android.os.RemoteException)10 FingerprintManager (android.hardware.fingerprint.FingerprintManager)8 ContentProviderClient (android.content.ContentProviderClient)7 ContentResolver (android.content.ContentResolver)6 Uri (android.net.Uri)6 ParcelFileDescriptor (android.os.ParcelFileDescriptor)6 AssetFileDescriptor (android.content.res.AssetFileDescriptor)5 MtpEvent (android.mtp.MtpEvent)5 InputStream (java.io.InputStream)5 FutureTask (java.util.concurrent.FutureTask)4 Test (org.junit.Test)4 KeyguardManager (android.app.KeyguardManager)2 BiometricPrompt (android.hardware.biometrics.BiometricPrompt)2 Bundle (android.os.Bundle)2 Handler (android.os.Handler)2