use of android.os.OperationCanceledException in project platform_frameworks_base by android.
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();
}
use of android.os.OperationCanceledException in project squidb by yahoo.
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();
}
use of android.os.OperationCanceledException 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));
}
use of android.os.OperationCanceledException 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;
}
use of android.os.OperationCanceledException in project android_frameworks_base by AOSPA.
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;
}
Aggregations