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

Commit 62d0e160 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov Committed by Automerger Merge Worker
Browse files

Merge "Propagate exception thrown by ContentProvider.canonicalize" into...

Merge "Propagate exception thrown by ContentProvider.canonicalize" into rvc-dev am: f7b0b5a3 am: 59e92797

Change-Id: I9db4aa98150961583f2fc65344bed7882b47a474
parents 077ff2f3 59e92797
Loading
Loading
Loading
Loading
+23 −15
Original line number Diff line number Diff line
@@ -307,19 +307,7 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
            try {
                result.putString(ContentResolver.REMOTE_CALLBACK_RESULT, getType(uri));
            } catch (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()));
                    }
                    result.putByteArray(ContentResolver.REMOTE_CALLBACK_ERROR, parcel.marshall());
                } finally {
                    parcel.recycle();
                }
                putExceptionInBundle(result, ContentResolver.REMOTE_CALLBACK_ERROR, e);
            }
            callback.sendResult(result);
        }
@@ -602,8 +590,12 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
        public void canonicalizeAsync(String callingPkg, @Nullable String attributionTag, Uri uri,
                RemoteCallback callback) {
            final Bundle result = new Bundle();
            try {
                result.putParcelable(ContentResolver.REMOTE_CALLBACK_RESULT,
                        canonicalize(callingPkg, attributionTag, uri));
            } catch (Exception e) {
                putExceptionInBundle(result, ContentResolver.REMOTE_CALLBACK_ERROR, e);
            }
            callback.sendResult(result);
        }

@@ -717,6 +709,22 @@ 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) {
+14 −6
Original line number Diff line number Diff line
@@ -238,12 +238,9 @@ public class ContentResolverTest {

    @Test
    public void testGetType_providerException() {
        try {
        String type =
                mResolver.getType(Uri.parse("content://android.content.FakeProviderRemote/error"));
            fail("Expected IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        assertThat(type).isNull();
    }

    @Test
@@ -253,4 +250,15 @@ public class ContentResolverTest {
        assertThat(canonical).isEqualTo(
                Uri.parse("content://android.content.FakeProviderRemote/canonical"));
    }

    @Test
    public void testCanonicalize_providerException() {
        try {
            mResolver.canonicalize(
                    Uri.parse("content://android.content.FakeProviderRemote/error"));
            fail("Expected IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -60,6 +60,9 @@ public class FakeProviderRemote extends ContentProvider {

    @Override
    public Uri canonicalize(Uri uri) {
        if (uri.getPath() != null && uri.getPath().contains("error")) {
            throw new IllegalArgumentException("Expected exception");
        }
        return new Uri.Builder().scheme(uri.getScheme()).authority(uri.getAuthority())
                .appendPath("canonical").build();
    }