Merge "Get rid of old ParcelFileDescriptor API." into honeycomb
This commit is contained in:
committed by
Android (Google) Code Review
commit
45a8f53b25
@ -144137,23 +144137,6 @@
|
|||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
</method>
|
</method>
|
||||||
<method name="fromData"
|
|
||||||
return="android.os.ParcelFileDescriptor"
|
|
||||||
abstract="false"
|
|
||||||
native="false"
|
|
||||||
synchronized="false"
|
|
||||||
static="true"
|
|
||||||
final="false"
|
|
||||||
deprecated="deprecated"
|
|
||||||
visibility="public"
|
|
||||||
>
|
|
||||||
<parameter name="data" type="byte[]">
|
|
||||||
</parameter>
|
|
||||||
<parameter name="name" type="java.lang.String">
|
|
||||||
</parameter>
|
|
||||||
<exception name="IOException" type="java.io.IOException">
|
|
||||||
</exception>
|
|
||||||
</method>
|
|
||||||
<method name="fromSocket"
|
<method name="fromSocket"
|
||||||
return="android.os.ParcelFileDescriptor"
|
return="android.os.ParcelFileDescriptor"
|
||||||
abstract="false"
|
abstract="false"
|
||||||
|
@ -19,6 +19,7 @@ package android.content;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
import android.util.Slog;
|
||||||
import android.util.TimeUtils;
|
import android.util.TimeUtils;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
@ -31,9 +32,8 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
* @param <D> the data type to be loaded.
|
* @param <D> the data type to be loaded.
|
||||||
*/
|
*/
|
||||||
public abstract class AsyncTaskLoader<D> extends Loader<D> {
|
public abstract class AsyncTaskLoader<D> extends Loader<D> {
|
||||||
|
static final String TAG = "AsyncTaskLoader";
|
||||||
|
static final boolean DEBUG = false;
|
||||||
private static final String TAG = "AsyncTaskLoader";
|
|
||||||
|
|
||||||
final class LoadTask extends AsyncTask<Void, Void, D> implements Runnable {
|
final class LoadTask extends AsyncTask<Void, Void, D> implements Runnable {
|
||||||
|
|
||||||
@ -45,13 +45,16 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> {
|
|||||||
/* Runs on a worker thread */
|
/* Runs on a worker thread */
|
||||||
@Override
|
@Override
|
||||||
protected D doInBackground(Void... params) {
|
protected D doInBackground(Void... params) {
|
||||||
|
if (DEBUG) Slog.v(TAG, this + " >>> doInBackground");
|
||||||
result = AsyncTaskLoader.this.onLoadInBackground();
|
result = AsyncTaskLoader.this.onLoadInBackground();
|
||||||
|
if (DEBUG) Slog.v(TAG, this + " <<< doInBackground");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Runs on the UI thread */
|
/* Runs on the UI thread */
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(D data) {
|
protected void onPostExecute(D data) {
|
||||||
|
if (DEBUG) Slog.v(TAG, this + " onPostExecute");
|
||||||
try {
|
try {
|
||||||
AsyncTaskLoader.this.dispatchOnLoadComplete(this, data);
|
AsyncTaskLoader.this.dispatchOnLoadComplete(this, data);
|
||||||
} finally {
|
} finally {
|
||||||
@ -61,6 +64,7 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCancelled() {
|
protected void onCancelled() {
|
||||||
|
if (DEBUG) Slog.v(TAG, this + " onCancelled");
|
||||||
try {
|
try {
|
||||||
AsyncTaskLoader.this.dispatchOnCancelled(this, result);
|
AsyncTaskLoader.this.dispatchOnCancelled(this, result);
|
||||||
} finally {
|
} finally {
|
||||||
@ -105,6 +109,7 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> {
|
|||||||
super.onForceLoad();
|
super.onForceLoad();
|
||||||
cancelLoad();
|
cancelLoad();
|
||||||
mTask = new LoadTask();
|
mTask = new LoadTask();
|
||||||
|
if (DEBUG) Slog.v(TAG, "Preparing load: mTask=" + mTask);
|
||||||
executePendingTask();
|
executePendingTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,10 +130,13 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> {
|
|||||||
* <tt>true</tt> otherwise.
|
* <tt>true</tt> otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean cancelLoad() {
|
public boolean cancelLoad() {
|
||||||
|
if (DEBUG) Slog.v(TAG, "cancelLoad: mTask=" + mTask);
|
||||||
if (mTask != null) {
|
if (mTask != null) {
|
||||||
if (mCancellingTask != null) {
|
if (mCancellingTask != null) {
|
||||||
// There was a pending task already waiting for a previous
|
// There was a pending task already waiting for a previous
|
||||||
// one being canceled; just drop it.
|
// one being canceled; just drop it.
|
||||||
|
if (DEBUG) Slog.v(TAG,
|
||||||
|
"cancelLoad: still waiting for cancelled task; dropping next");
|
||||||
if (mTask.waiting) {
|
if (mTask.waiting) {
|
||||||
mTask.waiting = false;
|
mTask.waiting = false;
|
||||||
mHandler.removeCallbacks(mTask);
|
mHandler.removeCallbacks(mTask);
|
||||||
@ -138,12 +146,14 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> {
|
|||||||
} else if (mTask.waiting) {
|
} else if (mTask.waiting) {
|
||||||
// There is a task, but it is waiting for the time it should
|
// There is a task, but it is waiting for the time it should
|
||||||
// execute. We can just toss it.
|
// execute. We can just toss it.
|
||||||
|
if (DEBUG) Slog.v(TAG, "cancelLoad: task is waiting, dropping it");
|
||||||
mTask.waiting = false;
|
mTask.waiting = false;
|
||||||
mHandler.removeCallbacks(mTask);
|
mHandler.removeCallbacks(mTask);
|
||||||
mTask = null;
|
mTask = null;
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
boolean cancelled = mTask.cancel(false);
|
boolean cancelled = mTask.cancel(false);
|
||||||
|
if (DEBUG) Slog.v(TAG, "cancelLoad: cancelled=" + cancelled);
|
||||||
if (cancelled) {
|
if (cancelled) {
|
||||||
mCancellingTask = mTask;
|
mCancellingTask = mTask;
|
||||||
}
|
}
|
||||||
@ -171,11 +181,15 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> {
|
|||||||
long now = SystemClock.uptimeMillis();
|
long now = SystemClock.uptimeMillis();
|
||||||
if (now < (mLastLoadCompleteTime+mUpdateThrottle)) {
|
if (now < (mLastLoadCompleteTime+mUpdateThrottle)) {
|
||||||
// Not yet time to do another load.
|
// Not yet time to do another load.
|
||||||
|
if (DEBUG) Slog.v(TAG, "Waiting until "
|
||||||
|
+ (mLastLoadCompleteTime+mUpdateThrottle)
|
||||||
|
+ " to execute: " + mTask);
|
||||||
mTask.waiting = true;
|
mTask.waiting = true;
|
||||||
mHandler.postAtTime(mTask, mLastLoadCompleteTime+mUpdateThrottle);
|
mHandler.postAtTime(mTask, mLastLoadCompleteTime+mUpdateThrottle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (DEBUG) Slog.v(TAG, "Executing: " + mTask);
|
||||||
mTask.execute((Void[]) null);
|
mTask.execute((Void[]) null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,6 +197,7 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> {
|
|||||||
void dispatchOnCancelled(LoadTask task, D data) {
|
void dispatchOnCancelled(LoadTask task, D data) {
|
||||||
onCancelled(data);
|
onCancelled(data);
|
||||||
if (mCancellingTask == task) {
|
if (mCancellingTask == task) {
|
||||||
|
if (DEBUG) Slog.v(TAG, "Cancelled task is now canceled!");
|
||||||
mLastLoadCompleteTime = SystemClock.uptimeMillis();
|
mLastLoadCompleteTime = SystemClock.uptimeMillis();
|
||||||
mCancellingTask = null;
|
mCancellingTask = null;
|
||||||
executePendingTask();
|
executePendingTask();
|
||||||
@ -191,10 +206,12 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> {
|
|||||||
|
|
||||||
void dispatchOnLoadComplete(LoadTask task, D data) {
|
void dispatchOnLoadComplete(LoadTask task, D data) {
|
||||||
if (mTask != task) {
|
if (mTask != task) {
|
||||||
|
if (DEBUG) Slog.v(TAG, "Load complete of old task, trying to cancel");
|
||||||
dispatchOnCancelled(task, data);
|
dispatchOnCancelled(task, data);
|
||||||
} else {
|
} else {
|
||||||
mLastLoadCompleteTime = SystemClock.uptimeMillis();
|
mLastLoadCompleteTime = SystemClock.uptimeMillis();
|
||||||
mTask = null;
|
mTask = null;
|
||||||
|
if (DEBUG) Slog.v(TAG, "Delivering result");
|
||||||
deliverResult(data);
|
deliverResult(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ public class ParcelFileDescriptor implements Parcelable {
|
|||||||
private static native int createPipeNative(FileDescriptor[] outFds);
|
private static native int createPipeNative(FileDescriptor[] outFds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Please use createPipe() or ContentProvider.openPipeHelper().
|
* @hide Please use createPipe() or ContentProvider.openPipeHelper().
|
||||||
* Gets a file descriptor for a read-only copy of the given data.
|
* Gets a file descriptor for a read-only copy of the given data.
|
||||||
*
|
*
|
||||||
* @param data Data to copy.
|
* @param data Data to copy.
|
||||||
|
Reference in New Issue
Block a user