Don't modify content URI to non-email providers
The "?limit=" param is only supported by EmailProvider, so don't add it to other URIs. Doing so causes a permission error when opening an EML attachment on gmail, because we're granted the permission only to the passed URI, but not to the URI with the "?limit=" param. Bug 3371630 Change-Id: I88fff88a7e48e5bc958124eedec3e592978a40c7
This commit is contained in:
parent
092ff131af
commit
7093746dd5
src/com/android/email
tests/src/com/android/email
@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.email;
|
||||
|
||||
import com.android.email.activity.Welcome;
|
||||
import com.android.email.provider.EmailContent;
|
||||
import com.android.email.provider.EmailContent.Account;
|
||||
import com.android.email.provider.EmailContent.AccountColumns;
|
||||
@ -851,6 +850,21 @@ public class Utility {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return if {@code original} is to the EmailProvider, add "?limit=1". Otherwise just returns
|
||||
* {@code original}.
|
||||
*
|
||||
* Other providers don't support the limit param. Also, changing URI passed from other apps
|
||||
* can cause permission errors.
|
||||
*/
|
||||
/* package */ static Uri buildLimitOneUri(Uri original) {
|
||||
if ("content".equals(original.getScheme()) &&
|
||||
EmailContent.AUTHORITY.equals(original.getAuthority())) {
|
||||
return EmailContent.uriWithLimit(original, 1);
|
||||
}
|
||||
return original;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a generic in column {@code column} of the first result row, if the query returns at
|
||||
* least 1 row. Otherwise returns {@code defaultValue}.
|
||||
@ -859,7 +873,7 @@ public class Utility {
|
||||
String[] projection, String selection, String[] selectionArgs, String sortOrder,
|
||||
int column, T defaultValue, CursorGetter<T> getter) {
|
||||
// Use PARAMETER_LIMIT to restrict the query to the single row we need
|
||||
uri = uri.buildUpon().appendQueryParameter(EmailContent.PARAMETER_LIMIT, "1").build();
|
||||
uri = buildLimitOneUri(uri);
|
||||
Cursor c = context.getContentResolver().query(uri, projection, selection, selectionArgs,
|
||||
sortOrder);
|
||||
if (c != null) {
|
||||
|
@ -26,6 +26,7 @@ import com.android.email.provider.EmailProvider;
|
||||
import com.android.email.provider.ProviderTestUtils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.test.ProviderTestCase2;
|
||||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
|
||||
@ -121,6 +122,20 @@ public class UtilityMediumTests extends ProviderTestCase2<EmailProvider> {
|
||||
assertTrue(Utility.attachmentExists(mMockContext, attachment));
|
||||
}
|
||||
|
||||
public void testBuildLimitOneUri() {
|
||||
// EmailProvider supports "?limit="
|
||||
assertEquals(Uri.parse("content://com.android.email.provider?limit=1"),
|
||||
Utility.buildLimitOneUri(Uri.parse("content://com.android.email.provider")));
|
||||
|
||||
// Others don't -- so don't add it.
|
||||
assertEquals(Uri.parse("content://com.android.email.attachmentprovider"),
|
||||
Utility.buildLimitOneUri(Uri.parse("content://com.android.email.attachmentprovider"
|
||||
)));
|
||||
assertEquals(Uri.parse("content://gmail-ls/android@gmail.com"),
|
||||
Utility.buildLimitOneUri(Uri.parse("content://gmail-ls/android@gmail.com"
|
||||
)));
|
||||
}
|
||||
|
||||
public void testGetFirstRowLong() {
|
||||
Account account1 = ProviderTestUtils.setupAccount("1", true, mMockContext);
|
||||
Account account2 = ProviderTestUtils.setupAccount("X1", true, mMockContext);
|
||||
|
@ -113,7 +113,7 @@ public class ContactStatusLoaderTest
|
||||
assertTrue(mProvider.mUris.size() >= 2);
|
||||
assertEquals("content://com.android.contacts/data/emails/lookup/a%40b.c",
|
||||
mProvider.mUris.get(0));
|
||||
assertEquals("content://com.android.contacts/data/12345?limit=1",
|
||||
assertEquals("content://com.android.contacts/data/12345",
|
||||
mProvider.mUris.get(1));
|
||||
|
||||
// Check result
|
||||
|
Loading…
Reference in New Issue
Block a user