Use ParcelableException to put exception in bundle
Test: atest FrameworksCoreTests:android.content.ContentResolverTest
Bug: 149184281
Change-Id: Ice6e1207ace7a0cc6b4b8dc1b99da22b13b04031
diff --git a/core/java/android/content/ContentProvider.java b/core/java/android/content/ContentProvider.java
index 9cf6569..60ecf64 100644
--- a/core/java/android/content/ContentProvider.java
+++ b/core/java/android/content/ContentProvider.java
@@ -47,8 +47,8 @@
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 @@
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 @@
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 @@
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) {