Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7836b086 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov Committed by Automerger Merge Worker
Browse files

Merge "Use ParcelableException to put exception in bundle" into rvc-dev am:...

Merge "Use ParcelableException to put exception in bundle" into rvc-dev am: 13c7d899 am: 3c7be536

Change-Id: I4f3a88642964e32caf966877446f1b6a003214ce
parents 9bcdb802 3c7be536
Loading
Loading
Loading
Loading
+5 −19
Original line number Original line Diff line number Diff line
@@ -47,8 +47,8 @@ import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.CancellationSignal;
import android.os.IBinder;
import android.os.IBinder;
import android.os.ICancellationSignal;
import android.os.ICancellationSignal;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor;
import android.os.ParcelableException;
import android.os.Process;
import android.os.Process;
import android.os.RemoteCallback;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.RemoteException;
@@ -307,7 +307,8 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
            try {
            try {
                result.putString(ContentResolver.REMOTE_CALLBACK_RESULT, getType(uri));
                result.putString(ContentResolver.REMOTE_CALLBACK_RESULT, getType(uri));
            } catch (Exception e) {
            } catch (Exception e) {
                putExceptionInBundle(result, ContentResolver.REMOTE_CALLBACK_ERROR, e);
                result.putParcelable(ContentResolver.REMOTE_CALLBACK_ERROR,
                        new ParcelableException(e));
            }
            }
            callback.sendResult(result);
            callback.sendResult(result);
        }
        }
@@ -594,7 +595,8 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
                result.putParcelable(ContentResolver.REMOTE_CALLBACK_RESULT,
                result.putParcelable(ContentResolver.REMOTE_CALLBACK_RESULT,
                        canonicalize(callingPkg, attributionTag, uri));
                        canonicalize(callingPkg, attributionTag, uri));
            } catch (Exception e) {
            } catch (Exception e) {
                putExceptionInBundle(result, ContentResolver.REMOTE_CALLBACK_ERROR, e);
                result.putParcelable(ContentResolver.REMOTE_CALLBACK_ERROR,
                        new ParcelableException(e));
            }
            }
            callback.sendResult(result);
            callback.sendResult(result);
        }
        }
@@ -709,22 +711,6 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall


            return AppOpsManager.MODE_ALLOWED;
            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) {
    boolean checkUser(int pid, int uid, Context context) {
+10 −23
Original line number Original line Diff line number Diff line
@@ -55,8 +55,8 @@ import android.os.DeadObjectException;
import android.os.IBinder;
import android.os.IBinder;
import android.os.ICancellationSignal;
import android.os.ICancellationSignal;
import android.os.OperationCanceledException;
import android.os.OperationCanceledException;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor;
import android.os.ParcelableException;
import android.os.RemoteCallback;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager;
@@ -931,8 +931,15 @@ public abstract class ContentResolver implements ContentInterface {
        @Override
        @Override
        public void onResult(Bundle result) {
        public void onResult(Bundle result) {
            synchronized (this) {
            synchronized (this) {
                this.exception = getExceptionFromBundle(result);
                ParcelableException e = result.getParcelable(REMOTE_CALLBACK_ERROR);
                if (this.exception == null) {
                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);
                    this.result = getResultFromBundle(result);
                }
                }
                done = true;
                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);
        protected abstract T getResultFromBundle(Bundle result);


        public void waitForResult(long timeout) {
        public void waitForResult(long timeout) {