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

Commit 0dab82d5 authored by Ayan Ghosh's avatar Ayan Ghosh Committed by Smriti Gupta
Browse files

Bluedroid: Modify PBAP vCard filtering logic.

Modify vCard filtering logic to avoid unintended removal of
vCard attribute values. During applying filters do not
remove the entries directly from original vCard, but removes
it from the concerned token, and construct the filtered vCard with
the modified tokens and return the modified vCard.

Change-Id: I348605a9742854da6bd2e2a59167641f379d88b8
CRs-Fixed: 509165
parent 7c223c96
Loading
Loading
Loading
Loading
+28 −28
Original line number Diff line number Diff line
@@ -974,21 +974,21 @@ public class BluetoothPbapVcardManager {

        public String applyFilter ( String vCard, boolean vCardType21){
            String attr [] = vCard.split(System.getProperty("line.separator"));
            String filteredVcard = "";

            //FN is not the mandatory field in 2.1 vCard
            if(((!fn) && (vCardType21)) && (vCard.contains("FN"))) {
                for (int i=0; i < attr.length; i++) {
                    if(attr[i].startsWith("FN")){
                        vCard = vCard.replace(attr[i] + "\n", "");
                        attr[i] = "";
                        /** Remove multiline Content, if any */
                        /** End traversal before END:VCARD */
                        for (int j = i+1; j < attr.length - 1; j++) {
                            if (checkValidFilter(attr[j])) {
                                /** Start of another attribute, break */
                                break;
                            } else {
                                /** Continuation of above attribute, remove */
                                vCard = vCard.replace(attr[j] + "\n", "");
                                attr[j] = "";
                            }
                        }
                    }
@@ -999,16 +999,15 @@ public class BluetoothPbapVcardManager {
            if((!bday) && (vCard.contains("BDAY"))) {
                for (int i=0; i < attr.length; i++) {
                    if(attr[i].startsWith("BDAY")){
                        vCard = vCard.replace(attr[i] + "\n", "");
                        attr[i] = "";
                        /** Remove multiline Content, if any */
                        /** End traversal before END:VCARD */
                        for (int j = i+1; j < attr.length - 1; j++) {
                            if (checkValidFilter(attr[j])) {
                                /** Start of another attribute, break */
                                break;
                            } else {
                                /** Continuation of above attribute, remove */
                                vCard = vCard.replace(attr[j] + "\n", "");
                                attr[j] = "";
                            }
                        }
                    }
@@ -1018,16 +1017,15 @@ public class BluetoothPbapVcardManager {
            if((!adr) && (vCard.contains("ADR"))) {
                for (int i=0; i < attr.length; i++) {
                    if(attr[i].startsWith("ADR")){
                        vCard = vCard.replace(attr[i] + "\n", "");
                        attr[i] = "";
                        /** Remove multiline Content, if any */
                        /** End traversal before END:VCARD */
                        for (int j = i+1; j < attr.length - 1; j++) {
                            if (checkValidFilter(attr[j])) {
                                /** Start of another attribute, break */
                                break;
                            } else {
                                /** Continuation of above attribute, remove */
                                vCard = vCard.replace(attr[j] + "\n", "");
                                attr[j] = "";
                            }
                        }
                    }
@@ -1037,16 +1035,15 @@ public class BluetoothPbapVcardManager {
            if((!email) && (vCard.contains("EMAIL"))) {
                for (int i=0; i < attr.length; i++) {
                    if(attr[i].startsWith("EMAIL")){
                        vCard = vCard.replace(attr[i] + "\n", "");
                        attr[i] = "";
                        /** Remove multiline Content, if any */
                        /** End traversal before END:VCARD */
                        for (int j = i+1; j < attr.length - 1; j++) {
                            if (checkValidFilter(attr[j])) {
                                /** Start of another attribute, break */
                                break;
                            } else {
                                /** Continuation of above attribute, remove */
                                vCard = vCard.replace(attr[j] + "\n", "");
                                attr[j] = "";
                            }
                        }
                    }
@@ -1056,16 +1053,15 @@ public class BluetoothPbapVcardManager {
            if((!title) && (vCard.contains("TITLE"))) {
                for (int i=0; i < attr.length; i++) {
                    if(attr[i].startsWith("TITLE")){
                        vCard = vCard.replace(attr[i] + "\n", "");
                        attr[i] = "";
                        /** Remove multiline Content, if any */
                        /** End traversal before END:VCARD */
                        for (int j = i+1; j < attr.length - 1; j++) {
                            if (checkValidFilter(attr[j])) {
                                /** Start of another attribute, break */
                                break;
                            } else {
                                /** Continuation of above attribute, remove */
                                vCard = vCard.replace(attr[j] + "\n", "");
                                attr[j] = "";
                            }
                        }
                    }
@@ -1075,16 +1071,15 @@ public class BluetoothPbapVcardManager {
            if((!org) && (vCard.contains("ORG"))) {
                for (int i=0; i < attr.length; i++) {
                    if(attr[i].startsWith("ORG")){
                        vCard = vCard.replace(attr[i] + "\n", "");
                        attr[i] = "";
                        /** Remove multiline Content, if any */
                        /** End traversal before END:VCARD */
                        for (int j = i+1; j < attr.length - 1; j++) {
                            if (checkValidFilter(attr[j])) {
                                /** Start of another attribute, break */
                                break;
                            } else {
                                /** Continuation of above attribute, remove */
                                vCard = vCard.replace(attr[j] + "\n", "");
                                attr[j] = "";
                            }
                        }
                    }
@@ -1094,16 +1089,15 @@ public class BluetoothPbapVcardManager {
            if((!notes) && (vCard.contains("NOTE"))) {
                for (int i=0; i < attr.length; i++) {
                    if(attr[i].startsWith("NOTE")){
                        vCard = vCard.replace(attr[i] + "\n", "");
                        attr[i] = "";
                        /** Remove multiline Content, if any */
                        /** End traversal before END:VCARD */
                        for (int j = i+1; j < attr.length - 1; j++) {
                            if (checkValidFilter(attr[j])) {
                                /** Start of another attribute, break */
                                break;
                            } else {
                                /** Continuation of above attribute, remove */
                                vCard = vCard.replace(attr[j] + "\n", "");
                                attr[j] = "";
                            }
                        }
                    }
@@ -1116,16 +1110,15 @@ public class BluetoothPbapVcardManager {
            if(((!nickname) || (vCardType21)) && (vCard.contains("NICKNAME"))) {
                for (int i=0; i < attr.length; i++) {
                    if(attr[i].startsWith("NICKNAME")){
                        vCard = vCard.replace(attr[i] + "\n", "");
                        attr[i] = "";
                        /** Remove multiline Content, if any */
                        /** End traversal before END:VCARD */
                        for (int j = i+1; j < attr.length - 1; j++) {
                            if (checkValidFilter(attr[j])) {
                                /** Start of another attribute, break */
                                break;
                            } else {
                                /** Continuation of above attribute, remove */
                                vCard = vCard.replace(attr[j] + "\n", "");
                                attr[j] = "";
                            }
                        }
                    }
@@ -1135,16 +1128,15 @@ public class BluetoothPbapVcardManager {
            if((!url) && (vCard.contains("URL"))) {
                for (int i=0; i < attr.length; i++) {
                    if(attr[i].startsWith("URL")){
                        vCard = vCard.replace(attr[i] + "\n", "");
                        attr[i] = "";
                        /** Remove multiline Content, if any */
                        /** End traversal before END:VCARD */
                        for (int j = i+1; j < attr.length - 1; j++) {
                            if (checkValidFilter(attr[j])) {
                                /** Start of another attribute, break */
                                break;
                            } else {
                                /** Continuation of above attribute, remove */
                                vCard = vCard.replace(attr[j] + "\n", "");
                                attr[j] = "";
                            }
                        }
                    }
@@ -1169,7 +1161,15 @@ public class BluetoothPbapVcardManager {
                }
            }

            return vCard;
            Log.v(TAG, "Tokens after applying filter: ");

            for (int i=0; i < attr.length; i++) {
                if(!attr[i].equals("")){
                    filteredVcard = filteredVcard.concat(attr[i] + "\n");
                }
            }

            return filteredVcard;
        }
    }
}