Enforce a limit on GAL lookup responses

Change-Id: Id353758c1221d2f1097566e7becc8baacf7984d9
This commit is contained in:
Marc Blank 2010-08-31 17:54:17 -07:00
parent aee3f053fb
commit 28ca167a89
3 changed files with 22 additions and 8 deletions

View File

@ -412,8 +412,6 @@
/>
<!--EXCHANGE-REMOVE-SECTION-START-->
<!-- In this release, GAL information is used locally only, so we used the same
strict permissions. -->
<provider
android:name="com.android.exchange.provider.ExchangeDirectoryProvider"
android:authorities="com.android.exchange.directory.provider"

View File

@ -803,7 +803,7 @@ public class EasSyncService extends AbstractSyncService {
* TODO: make watchdog actually work (it doesn't understand our service w/Mailbox == 0)
* TODO: figure out why sendHttpClientPost() hangs - possibly pool exhaustion
*/
static public GalResult searchGal(Context context, long accountId, String filter) {
static public GalResult searchGal(Context context, long accountId, String filter, int limit) {
Account acct = ExchangeService.getAccountById(accountId);
if (acct != null) {
HostAuth ha = HostAuth.restoreHostAuthWithId(context, acct.mHostAuthKeyRecv);
@ -830,7 +830,7 @@ public class EasSyncService extends AbstractSyncService {
s.start(Tags.SEARCH_SEARCH).start(Tags.SEARCH_STORE);
s.data(Tags.SEARCH_NAME, "GAL").data(Tags.SEARCH_QUERY, filter);
s.start(Tags.SEARCH_OPTIONS);
s.data(Tags.SEARCH_RANGE, "0-19"); // Return 0..20 results
s.data(Tags.SEARCH_RANGE, "0-" + Integer.toString(limit - 1));
s.end().end().end().done();
if (DEBUG_GAL_SERVICE) svc.userLog("GAL lookup starting for " + ha.mAddress);
HttpResponse resp = svc.sendHttpClientPost("Search", s.toByteArray());

View File

@ -32,14 +32,15 @@ import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.os.Binder;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Directory;
import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Contacts.Data;
import android.provider.ContactsContract.Directory;
import android.provider.ContactsContract.RawContacts;
import android.text.TextUtils;
import java.util.HashMap;
@ -53,6 +54,7 @@ public class ExchangeDirectoryProvider extends ContentProvider {
public static final String EXCHANGE_GAL_AUTHORITY = "com.android.exchange.directory.provider";
private static final int DEFAULT_CONTACT_ID = 1;
private static final int DEFAULT_LOOKUP_LIMIT = 20;
private static final int GAL_BASE = 0;
private static final int GAL_DIRECTORIES = GAL_BASE;
@ -226,6 +228,20 @@ public class ExchangeDirectoryProvider extends ContentProvider {
return null;
}
// Enforce a limit on the number of lookup responses
String limitString = uri.getQueryParameter(ContactsContract.LIMIT_PARAM_KEY);
int limit = DEFAULT_LOOKUP_LIMIT;
if (limitString != null) {
try {
limit = Integer.parseInt(limitString);
} catch (NumberFormatException e) {
limit = 0;
}
if (limit <= 0) {
throw new IllegalArgumentException("Limit not valid: " + limitString);
}
}
Account account = ExchangeService.getAccountByName(accountName);
if (account == null) {
return null;
@ -235,7 +251,7 @@ public class ExchangeDirectoryProvider extends ContentProvider {
try {
// Get results from the Exchange account
GalResult galResult = EasSyncService.searchGal(getContext(), account.mId,
filter);
filter, limit);
if (galResult != null) {
return buildGalResultCursor(projection, galResult);
}