Methods Summary |
---|
public void | cancel()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.
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();
}
}
|
public static android.os.ICancellationSignal | createTransport()Creates a transport that can be returned back to the caller of
a Binder function and subsequently used to dispatch a cancellation signal.
return new Transport();
|
public static android.os.CancellationSignal | fromTransport(android.os.ICancellationSignal transport)Given a locally created transport, returns its associated cancellation signal.
if (transport instanceof Transport) {
return ((Transport)transport).mCancellationSignal;
}
return null;
|
public boolean | isCanceled()Returns true if the operation has been canceled.
synchronized (this) {
return mIsCanceled;
}
|
public void | setOnCancelListener(android.os.CancellationSignal$OnCancelListener listener)Sets the cancellation listener to be called when canceled.
This method is intended to be used by the recipient of a cancellation signal
such as a database or a content provider to handle cancellation requests
while performing a long-running operation. This method is not intended to be
used by applications themselves.
If {@link CancellationSignal#cancel} has already been called, then the provided
listener is invoked immediately.
This method is guaranteed that the listener will not be called after it
has been removed.
synchronized (this) {
waitForCancelFinishedLocked();
if (mOnCancelListener == listener) {
return;
}
mOnCancelListener = listener;
if (!mIsCanceled || listener == null) {
return;
}
}
listener.onCancel();
|
public void | setRemote(android.os.ICancellationSignal remote)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.
synchronized (this) {
waitForCancelFinishedLocked();
if (mRemote == remote) {
return;
}
mRemote = remote;
if (!mIsCanceled || remote == null) {
return;
}
}
try {
remote.cancel();
} catch (RemoteException ex) {
}
|
public void | throwIfCanceled()Throws {@link OperationCanceledException} if the operation has been canceled.
if (isCanceled()) {
throw new OperationCanceledException();
}
|
private void | waitForCancelFinishedLocked()
while (mCancelInProgress) {
try {
wait();
} catch (InterruptedException ex) {
}
}
|