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

Commit b584b965 authored by Hemant Gupta's avatar Hemant Gupta Committed by Myles Watson
Browse files

PBAP: Apply listStartOffset in the final list.

Precondition
Have 2 numbers with same name, with different handles, for example
1.vcf and 5.vcf on DUT

Usecase
1) Connect from carkit for PBAP
2) Search by name, with offset - 0
3) Search by name, with offset - 1
4) Search by name, with offset - 2

Expected behaviour
Carkit is able to show correct list with offset as specified by user

Observed result
 ListStartOffset does not work as expected for PullvCardListing Function.

Fix:
This change will apply the offet value in the final list of vcard values prepared after comparing
with the search value as per the specification. ListStartOffset was being applied on the original
list of names earlier returning extra set of values of names while Vcardlisting.

Test: Perform the usecase as described above and at step2, 1.vcf and 5.vcf are shown,
at step3, 5.vcf are shown and at step4, Nothing is shown.

Bug: 35026764
Change-Id: I36d757a12d0cc94628d4f4ad91c9370397035c4e
parent 9874cb01
Loading
Loading
Loading
Loading
+31 −16
Original line number Diff line number Diff line
@@ -817,50 +817,65 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
        }

        if (type.equals("number")) {
            ArrayList<Integer> savedPosList = new ArrayList<>();
            ArrayList<String> selectedNameList = new ArrayList<String>();
            // query the number, to get the names
            ArrayList<String> names =
                    mVcardManager.getContactNamesByNumber(appParamValue.searchValue);
            if (mOrderBy == ORDER_BY_ALPHABETICAL) Collections.sort(names);
            for (int i = 0; i < names.size(); i++) {
                compareValue = names.get(i).trim();
                if (D) {
                    Log.d(TAG, "compareValue=" + compareValue);
                }
                for (int pos = appParamValue.listStartOffset;
                        pos < listSize && itemsFound < requestSize; pos++) {
                if (D) Log.d(TAG, "compareValue=" + compareValue);
                for (int pos = 0; pos < listSize; pos++) {
                    currentValue = nameList.get(pos);
                    if (V) {
                        Log.d(TAG, "currentValue=" + currentValue);
                    }
                    if (currentValue.equals(compareValue)) {
                        itemsFound++;
                        if (currentValue.contains(",")) {
                            currentValue = currentValue.substring(0, currentValue.lastIndexOf(','));
                        }
                        writeVCardEntry(pos, currentValue, result);
                        selectedNameList.add(currentValue);
                        savedPosList.add(pos);
                    }
                }
                if (itemsFound >= requestSize) {
                    break;
            }

            for (int j = appParamValue.listStartOffset;
                    j < selectedNameList.size() && itemsFound < requestSize; j++) {
                itemsFound++;
                writeVCardEntry(savedPosList.get(j), selectedNameList.get(j), result);
            }

        } else {
            ArrayList<Integer> savedPosList = new ArrayList<>();
            ArrayList<String> selectedNameList = new ArrayList<String>();
            if (appParamValue.searchValue != null) {
                compareValue = appParamValue.searchValue.trim().toLowerCase();
            }
            for (int pos = appParamValue.listStartOffset;
                    pos < listSize && itemsFound < requestSize; pos++) {

            for (int pos = 0; pos < listSize; pos++) {
                currentValue = nameList.get(pos);

                if (currentValue.contains(",")) {
                    currentValue = currentValue.substring(0, currentValue.lastIndexOf(','));
                }

                if (appParamValue.searchValue.isEmpty() || ((currentValue.toLowerCase()).startsWith(
                        compareValue))) {
                    itemsFound++;
                    writeVCardEntry(pos, currentValue, result);
                if (appParamValue.searchValue != null) {
                    if (appParamValue.searchValue.isEmpty()
                            || ((currentValue.toLowerCase())
                                               .startsWith(compareValue.toLowerCase()))) {
                        selectedNameList.add(currentValue);
                        savedPosList.add(pos);
                    }
                }
            }

            for (int i = appParamValue.listStartOffset;
                    i < selectedNameList.size() && itemsFound < requestSize; i++) {
                itemsFound++;
                writeVCardEntry(savedPosList.get(i), selectedNameList.get(i), result);
            }
        }
        return itemsFound;
    }
+8 −1
Original line number Diff line number Diff line
@@ -332,12 +332,18 @@ public class BluetoothPbapVcardManager {
            contactCursor = mResolver.query(myUri, PHONES_CONTACTS_PROJECTION, null, null,
                    Phone.CONTACT_ID);

            ArrayList<String> contactNameIdList = new ArrayList<String>();
            appendDistinctNameIdList(contactNameIdList,
                    mContext.getString(android.R.string.unknownName), contactCursor);

            if (contactCursor != null) {
                if (!composer.initWithCallback(contactCursor,
                        new EnterpriseRawContactEntitlesInfoCallback())) {
                    return nameList;
                }

                int i = 0;
                contactCursor.moveToFirst();
                while (!composer.isAfterLast()) {
                    String vcard = composer.createOneEntry();
                    if (vcard == null) {
@@ -362,8 +368,9 @@ public class BluetoothPbapVcardManager {
                        if (TextUtils.isEmpty(name)) {
                            name = mContext.getString(android.R.string.unknownName);
                        }
                        nameList.add(name);
                        nameList.add(contactNameIdList.get(i));
                    }
                    i++;
                }
                if (orderByWhat == BluetoothPbapObexServer.ORDER_BY_INDEXED) {
                    if (V) {