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

Commit 35cf467c authored by Jaikumar Ganesh's avatar Jaikumar Ganesh Committed by Android Git Automerger
Browse files

am acd614da: Merge "Make "search by number" function work" into gingerbread

Merge commit 'acd614da' into gingerbread-plus-aosp

* commit 'acd614da':
  Make "search by number" function work
parents 9ff7e618 acd614da
Loading
Loading
Loading
Loading
+0 −0

File mode changed from 100755 to 100644.

+51 −16
Original line number Diff line number Diff line
@@ -490,7 +490,15 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
                    i += 1; // length field in triplet
                    // length of search value is variable
                    int length = appParam[i];
                    if (length == 0) {
                        parseOk = false;
                        break;
                    }
                    if (appParam[i+length] == 0x0) {
                        appParamValue.searchValue = new String(appParam, i + 1, length-1);
                    } else {
                        appParamValue.searchValue = new String(appParam, i + 1, length);
                    }
                    i += length;
                    i += 1;
                    break;
@@ -549,13 +557,11 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
        // Phonebook listing request
        if (type == ContentType.PHONEBOOK) {
            if (searchAttr.equals("0")) { // search by name
                ArrayList<String> nameList = mVcardManager.getPhonebookNameList(mOrderBy );
                itemsFound = createList(maxListCount, listStartOffset, searchValue, result,
                        nameList, "name");
                        "name");
            } else if (searchAttr.equals("1")) { // search by number
                ArrayList<String> numberList = mVcardManager.getPhonebookNumberList();
                itemsFound = createList(maxListCount, listStartOffset, searchValue, result,
                        numberList, "number");
                        "number");
            }// end of search by number
            else {
                return ResponseCodes.OBEX_HTTP_PRECON_FAILED;
@@ -587,22 +593,51 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
    }

    private int createList(final int maxListCount, final int listStartOffset,
            final String searchValue, StringBuilder result,
            ArrayList<String> dataList, String type) {
            final String searchValue, StringBuilder result, String type) {
        int itemsFound = 0;
        int requestSize = dataList.size() >= maxListCount ? maxListCount : dataList.size();
        ArrayList<String> nameList = mVcardManager.getPhonebookNameList(mOrderBy);
        final int requestSize = nameList.size() >= maxListCount ? maxListCount : nameList.size();
        final int listSize = nameList.size();
        String compareValue = "", currentValue;

        if (D) Log.d(TAG, "search by " + type + ", size=" + requestSize + " offset="
        if (D) Log.d(TAG, "search by " + type + ", requestSize=" + requestSize + " offset="
                    + listStartOffset + " searchValue=" + searchValue);

        for (int pos = listStartOffset; pos < dataList.size() && itemsFound < requestSize; pos++) {
            String currentValue = dataList.get(pos);
            if (searchValue == null || currentValue.startsWith(searchValue.trim())) {
        if (type.equals("number")) {
            // query the number, to get the names
            ArrayList<String> names = mVcardManager.getContactNamesByNumber(searchValue);
            for (int i = 0; i < names.size(); i++) {
                compareValue = names.get(i).trim();
                if (D) Log.d(TAG, "compareValue=" + compareValue);
                for (int pos = listStartOffset; pos < listSize &&
                        itemsFound < requestSize; pos++) {
                    currentValue = nameList.get(pos);
                    if (D) Log.d(TAG, "currentValue=" + currentValue);
                    if (currentValue.startsWith(compareValue)) {
                        itemsFound++;
                        result.append("<card handle=\"" + pos + ".vcf\" name=\""
                                + currentValue + "\"" + "/>");
                    }
                }
                if (itemsFound >= requestSize) {
                    break;
                }
            }
        } else {
            if (searchValue != null) {
                compareValue = searchValue.trim();
            }
            for (int pos = listStartOffset; pos < listSize &&
                    itemsFound < requestSize; pos++) {
                currentValue = nameList.get(pos);
                if (D) Log.d(TAG, "currentValue=" + currentValue);
                if (searchValue == null || currentValue.startsWith(compareValue)) {
                    itemsFound++;
                result.append("<card handle=\"" + pos + ".vcf\" " + type + "=\""
                    result.append("<card handle=\"" + pos + ".vcf\" name=\""
                            + currentValue + "\"" + "/>");
                }
            }
        }
        return itemsFound;
    }

@@ -791,7 +826,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
        String orderPara = appParamValue.order.trim();
        if (TextUtils.isEmpty(orderPara)) {
            // If order parameter is not set by PCE, set default value per spec.
            appParamValue.order = "0";
            orderPara = "0";
            if (D) Log.d(TAG, "Order parameter is not set by PCE. " +
                       "Assume order by 'Indexed' by default");
        } else if (!orderPara.equals("0") && !orderPara.equals("1")) {
+23 −16
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.PhoneLookup;
import android.text.TextUtils;
import android.util.Log;

@@ -211,9 +212,11 @@ public class BluetoothPbapVcardManager {
        Cursor contactCursor = null;
        try {
            if (orderByWhat == BluetoothPbapObexServer.ORDER_BY_INDEXED) {
                if (V) Log.v(TAG, "getPhonebookNameList, order by index");
                contactCursor = mResolver.query(myUri, CONTACTS_PROJECTION, CLAUSE_ONLY_VISIBLE,
                        null, Contacts._ID);
            } else if (orderByWhat == BluetoothPbapObexServer.ORDER_BY_ALPHABETICAL) {
                if (V) Log.v(TAG, "getPhonebookNameList, order by alpha");
                contactCursor = mResolver.query(myUri, CONTACTS_PROJECTION, CLAUSE_ONLY_VISIBLE,
                        null, Contacts.DISPLAY_NAME);
            }
@@ -235,31 +238,35 @@ public class BluetoothPbapVcardManager {
        return nameList;
    }

    public final ArrayList<String> getPhonebookNumberList() {
        ArrayList<String> numberList = new ArrayList<String>();
        numberList.add(BluetoothPbapService.getLocalPhoneNum());
    public final ArrayList<String> getContactNamesByNumber(final String phoneNumber) {
        ArrayList<String> nameList = new ArrayList<String>();

        Cursor contactCursor = null;
        final Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
                Uri.encode(phoneNumber));

        final Uri myUri = Phone.CONTENT_URI;
        Cursor phoneCursor = null;
        try {
            phoneCursor = mResolver.query(myUri, PHONES_PROJECTION, CLAUSE_ONLY_VISIBLE, null,
                    SORT_ORDER_PHONE_NUMBER);
            if (phoneCursor != null) {
                for (phoneCursor.moveToFirst(); !phoneCursor.isAfterLast(); phoneCursor
            contactCursor = mResolver.query(uri, CONTACTS_PROJECTION, CLAUSE_ONLY_VISIBLE,
                        null, Contacts._ID);

            if (contactCursor != null) {
                for (contactCursor.moveToFirst(); !contactCursor.isAfterLast(); contactCursor
                        .moveToNext()) {
                    String number = phoneCursor.getString(PHONE_NUMBER_COLUMN_INDEX);
                    if (TextUtils.isEmpty(number)) {
                        number = mContext.getString(R.string.defaultnumber);
                    String name = contactCursor.getString(CONTACTS_NAME_COLUMN_INDEX);
                    long id = contactCursor.getLong(CONTACTS_ID_COLUMN_INDEX);
                    if (TextUtils.isEmpty(name)) {
                        name = mContext.getString(android.R.string.unknownName);
                    }
                    numberList.add(number);
                    if (V) Log.v(TAG, "got name " + name + " by number " + phoneNumber + " @" + id);
                    nameList.add(name);
                }
            }
        } finally {
            if (phoneCursor != null) {
                phoneCursor.close();
            if (contactCursor != null) {
                contactCursor.close();
            }
        }
        return numberList;
        return nameList;
    }

    public final int composeAndSendCallLogVcards(final int type, Operation op,