Merge "Use ParcelableException to put exception in bundle" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
13c7d899da
@@ -47,8 +47,8 @@ import android.os.Bundle;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.IBinder;
|
||||
import android.os.ICancellationSignal;
|
||||
import android.os.Parcel;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.ParcelableException;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteCallback;
|
||||
import android.os.RemoteException;
|
||||
@@ -307,7 +307,8 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
|
||||
try {
|
||||
result.putString(ContentResolver.REMOTE_CALLBACK_RESULT, getType(uri));
|
||||
} catch (Exception e) {
|
||||
putExceptionInBundle(result, ContentResolver.REMOTE_CALLBACK_ERROR, e);
|
||||
result.putParcelable(ContentResolver.REMOTE_CALLBACK_ERROR,
|
||||
new ParcelableException(e));
|
||||
}
|
||||
callback.sendResult(result);
|
||||
}
|
||||
@@ -594,7 +595,8 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
|
||||
result.putParcelable(ContentResolver.REMOTE_CALLBACK_RESULT,
|
||||
canonicalize(callingPkg, attributionTag, uri));
|
||||
} catch (Exception e) {
|
||||
putExceptionInBundle(result, ContentResolver.REMOTE_CALLBACK_ERROR, e);
|
||||
result.putParcelable(ContentResolver.REMOTE_CALLBACK_ERROR,
|
||||
new ParcelableException(e));
|
||||
}
|
||||
callback.sendResult(result);
|
||||
}
|
||||
@@ -709,22 +711,6 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
|
||||
|
||||
return AppOpsManager.MODE_ALLOWED;
|
||||
}
|
||||
|
||||
private void putExceptionInBundle(Bundle bundle, String key, Exception e) {
|
||||
Parcel parcel = Parcel.obtain();
|
||||
try {
|
||||
try {
|
||||
parcel.writeException(e);
|
||||
} catch (Exception ex) {
|
||||
// getType threw an unparcelable exception. Wrap the message into
|
||||
// a parcelable exception type
|
||||
parcel.writeException(new IllegalStateException(e.getMessage()));
|
||||
}
|
||||
bundle.putByteArray(key, parcel.marshall());
|
||||
} finally {
|
||||
parcel.recycle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean checkUser(int pid, int uid, Context context) {
|
||||
|
||||
@@ -55,8 +55,8 @@ import android.os.DeadObjectException;
|
||||
import android.os.IBinder;
|
||||
import android.os.ICancellationSignal;
|
||||
import android.os.OperationCanceledException;
|
||||
import android.os.Parcel;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.ParcelableException;
|
||||
import android.os.RemoteCallback;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
@@ -931,8 +931,15 @@ public abstract class ContentResolver implements ContentInterface {
|
||||
@Override
|
||||
public void onResult(Bundle result) {
|
||||
synchronized (this) {
|
||||
this.exception = getExceptionFromBundle(result);
|
||||
if (this.exception == null) {
|
||||
ParcelableException e = result.getParcelable(REMOTE_CALLBACK_ERROR);
|
||||
if (e != null) {
|
||||
Throwable t = e.getCause();
|
||||
if (t instanceof RuntimeException) {
|
||||
this.exception = (RuntimeException) t;
|
||||
} else {
|
||||
this.exception = new RuntimeException(t);
|
||||
}
|
||||
} else {
|
||||
this.result = getResultFromBundle(result);
|
||||
}
|
||||
done = true;
|
||||
@@ -940,26 +947,6 @@ public abstract class ContentResolver implements ContentInterface {
|
||||
}
|
||||
}
|
||||
|
||||
private RuntimeException getExceptionFromBundle(Bundle result) {
|
||||
byte[] bytes = result.getByteArray(REMOTE_CALLBACK_ERROR);
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Parcel parcel = Parcel.obtain();
|
||||
try {
|
||||
parcel.unmarshall(bytes, 0, bytes.length);
|
||||
parcel.setDataPosition(0);
|
||||
parcel.readException();
|
||||
} catch (RuntimeException ex) {
|
||||
return ex;
|
||||
} finally {
|
||||
parcel.recycle();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected abstract T getResultFromBundle(Bundle result);
|
||||
|
||||
public void waitForResult(long timeout) {
|
||||
|
||||
Reference in New Issue
Block a user