Search in sources :

Example 16 with OperationCanceledException

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

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 17 with OperationCanceledException

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

the class SQLiteConnectionPool method cancelConnectionWaiterLocked.

// Can't throw.
private void cancelConnectionWaiterLocked(ConnectionWaiter waiter) {
    if (waiter.mAssignedConnection != null || waiter.mException != null) {
        // Waiter is done waiting but has not woken up yet.
        return;
    }
    // Waiter must still be waiting.  Dequeue it.
    ConnectionWaiter predecessor = null;
    ConnectionWaiter current = mConnectionWaiterQueue;
    while (current != waiter) {
        assert current != null;
        predecessor = current;
        current = current.mNext;
    }
    if (predecessor != null) {
        predecessor.mNext = waiter.mNext;
    } else {
        mConnectionWaiterQueue = waiter.mNext;
    }
    // Send the waiter an exception and unpark it.
    waiter.mException = new OperationCanceledException();
    LockSupport.unpark(waiter.mThread);
    // Check whether removing this waiter will enable other waiters to make progress.
    wakeConnectionWaitersLocked();
}
Also used : OperationCanceledException(android.os.OperationCanceledException)

Example 18 with OperationCanceledException

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

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 19 with OperationCanceledException

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

the class SQLiteConnectionPool method cancelConnectionWaiterLocked.

// Can't throw.
private void cancelConnectionWaiterLocked(ConnectionWaiter waiter) {
    if (waiter.mAssignedConnection != null || waiter.mException != null) {
        // Waiter is done waiting but has not woken up yet.
        return;
    }
    // Waiter must still be waiting.  Dequeue it.
    ConnectionWaiter predecessor = null;
    ConnectionWaiter current = mConnectionWaiterQueue;
    while (current != waiter) {
        assert current != null;
        predecessor = current;
        current = current.mNext;
    }
    if (predecessor != null) {
        predecessor.mNext = waiter.mNext;
    } else {
        mConnectionWaiterQueue = waiter.mNext;
    }
    // Send the waiter an exception and unpark it.
    waiter.mException = new OperationCanceledException();
    LockSupport.unpark(waiter.mThread);
    // Check whether removing this waiter will enable other waiters to make progress.
    wakeConnectionWaitersLocked();
}
Also used : OperationCanceledException(android.os.OperationCanceledException)

Example 20 with OperationCanceledException

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

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)

Aggregations

OperationCanceledException (android.os.OperationCanceledException)24 CancellationSignal (android.os.CancellationSignal)17 Cursor (android.database.Cursor)12 ContentProviderClient (android.content.ContentProviderClient)5 ContentResolver (android.content.ContentResolver)5 Uri (android.net.Uri)5 RemoteException (android.os.RemoteException)5 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 FutureTask (java.util.concurrent.FutureTask)5 Test (org.junit.Test)1