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

Commit d949946d authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "PbapVcard: Apply pattern matching" into main

parents 3528f4bb 9ada0f5e
Loading
Loading
Loading
Loading
+18 −15
Original line number Diff line number Diff line
@@ -53,10 +53,11 @@ import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;

// Next tag value for ContentProfileErrorReportUtils.report(): 22
public class BluetoothPbapVcardManager {
    private static final String TAG = "BluetoothPbapVcardManager";
    private static final String TAG = BluetoothPbapVcardManager.class.getSimpleName();

    private ContentResolver mResolver;

@@ -87,6 +88,11 @@ public class BluetoothPbapVcardManager {

    private static final int NEED_SEND_BODY = -1;

    private static final String SEPARATOR = System.getProperty("line.separator");
    private static final Pattern SEPARATOR_PATTERN = Pattern.compile(SEPARATOR);
    private static final Pattern PROPERTY_PATTERN = Pattern.compile("[;:]");
    private static final Pattern ATTRIBUTE_PATTERN = Pattern.compile(":");

    public BluetoothPbapVcardManager(final Context context) {
        mContext = context;
        mResolver = mContext.getContentResolver();
@@ -1100,7 +1106,7 @@ public class BluetoothPbapVcardManager {
            byte[] filter,
            byte[] selector,
            String vcardselectorop,
            boolean vCardSelct) {
            boolean vCardSelect) {
        long timestamp = System.currentTimeMillis();

        HandlerForStringBuffer buffer = null;
@@ -1121,7 +1127,7 @@ public class BluetoothPbapVcardManager {
                    break;
                }
                String vcard = composer.createOneEntry(vcardType21);
                if (vCardSelct) {
                if (vCardSelect) {
                    if (!vcardselector.checkVCardSelector(vcard, vcardselectorop)) {
                        Log.e(TAG, "Checking vcard selector for call log");
                        ContentProfileErrorReportUtils.report(
@@ -1176,7 +1182,7 @@ public class BluetoothPbapVcardManager {
                    buffer.writeVCard(vcard);
                }
            }
            if (needSendBody != NEED_SEND_BODY && vCardSelct) {
            if (needSendBody != NEED_SEND_BODY && vCardSelect) {
                return pbSize;
            }
        } finally {
@@ -1194,12 +1200,11 @@ public class BluetoothPbapVcardManager {
    }

    public String stripTelephoneNumber(String vCard) {
        String separator = System.getProperty("line.separator");
        String[] attr = vCard.split(separator);
        String[] attr = SEPARATOR_PATTERN.split(vCard);
        String stripedVCard = "";
        for (int i = 0; i < attr.length; i++) {
            if (attr[i].startsWith("TEL")) {
                String[] vTagAndTel = attr[i].split(":", 2);
                String[] vTagAndTel = ATTRIBUTE_PATTERN.split(attr[i], 2);
                int telLenBefore = vTagAndTel[1].length();
                // Remove '-', '(', ')' or ' ' from TEL number
                vTagAndTel[1] =
@@ -1217,7 +1222,7 @@ public class BluetoothPbapVcardManager {

        for (int i = 0; i < attr.length; i++) {
            if (!attr[i].isEmpty()) {
                stripedVCard = stripedVCard.concat(attr[i] + separator);
                stripedVCard = stripedVCard.concat(attr[i] + SEPARATOR);
            }
        }
        Log.v(TAG, "vCard with stripped telephone no.: " + stripedVCard);
@@ -1253,7 +1258,6 @@ public class BluetoothPbapVcardManager {
            }
        }

        private static final String SEPARATOR = System.getProperty("line.separator");
        private final byte[] mFilter;

        // This function returns true if the attributes needs to be included in the filtered vcard.
@@ -1284,7 +1288,7 @@ public class BluetoothPbapVcardManager {
            if (mFilter == null) {
                return vCard;
            }
            String[] lines = vCard.split(SEPARATOR);
            String[] lines = SEPARATOR_PATTERN.split(vCard);
            StringBuilder filteredVCard = new StringBuilder();
            boolean filteredIn = false;

@@ -1292,7 +1296,7 @@ public class BluetoothPbapVcardManager {
                // Check whether the current property is changing (ignoring multi-line properties)
                // and determine if the current property is filtered in.
                if (!Character.isWhitespace(line.charAt(0)) && !line.startsWith("=")) {
                    String currentProp = line.split("[;:]")[0];
                    String currentProp = PROPERTY_PATTERN.split(line, 2)[0];
                    filteredIn = true;

                    for (FilterBit bit : FilterBit.values()) {
@@ -1352,7 +1356,6 @@ public class BluetoothPbapVcardManager {
            }
        }

        private static final String SEPARATOR = System.getProperty("line.separator");
        private final byte[] mSelector;

        PropertySelector(byte[] selector) {
@@ -1463,7 +1466,7 @@ public class BluetoothPbapVcardManager {

    @VisibleForTesting
    static String getNameFromVCard(String vCard) {
        String[] lines = vCard.split(PropertySelector.SEPARATOR);
        String[] lines = SEPARATOR_PATTERN.split(vCard);
        String name = "";
        for (String line : lines) {
            if (!Character.isWhitespace(line.charAt(0)) && !line.startsWith("=")) {
@@ -1477,10 +1480,10 @@ public class BluetoothPbapVcardManager {
    }

    private static boolean doesVCardHaveProperty(String vCard, String property) {
        String[] lines = vCard.split(PropertySelector.SEPARATOR);
        String[] lines = SEPARATOR_PATTERN.split(vCard);
        for (String line : lines) {
            if (!Character.isWhitespace(line.charAt(0)) && !line.startsWith("=")) {
                String currentProperty = line.split("[;:]")[0];
                String currentProperty = PROPERTY_PATTERN.split(line)[0];
                if (property.equals(currentProperty)) {
                    return true;
                }