OSDN Git Service

Fixed PBAP to use simple pairing instead of numeric comparison (same as before).
authorFred <fredc@broadcom.com>
Fri, 25 May 2012 17:56:18 +0000 (10:56 -0700)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Tue, 17 Jul 2012 05:10:09 +0000 (22:10 -0700)
Also, escape special characters in vCard-Listing XML object

Change-Id: I32eb126f3dba4b35af39e6e0636f2f7f7e8d94a8

src/com/android/bluetooth/pbap/BluetoothPbapObexServer.java
src/com/android/bluetooth/pbap/BluetoothPbapService.java

index a0ebfe9..f5c48ed 100755 (executable)
@@ -42,6 +42,8 @@ import android.provider.CallLog;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.text.CharacterIterator;
+import java.text.StringCharacterIterator;
 import java.util.ArrayList;
 import java.util.Arrays;
 
@@ -575,10 +577,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
             if (D) Log.d(TAG, "call log list, size=" + requestSize + " offset=" + listStartOffset);
 
             for (int j = startPoint; j < endPoint; j++) {
-                // listing object begin with 1.vcf
-                result.append("<card handle=\"" + (j + 1) + ".vcf\" name=\"" + nameList.get(j)
-                        + "\"" + "/>");
-                itemsFound++;
+                writeVCardEntry(j+1, nameList.get(j),result);
             }
         }
         result.append("</vCard-listing>");
@@ -611,8 +610,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
                     if (D) Log.d(TAG, "currentValue=" + currentValue);
                     if (currentValue.startsWith(compareValue)) {
                         itemsFound++;
-                        result.append("<card handle=\"" + pos + ".vcf\" name=\""
-                                + currentValue + "\"" + "/>");
+                        writeVCardEntry(pos, currentValue,result);
                     }
                 }
                 if (itemsFound >= requestSize) {
@@ -629,8 +627,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
                 if (D) Log.d(TAG, "currentValue=" + currentValue);
                 if (searchValue == null || currentValue.startsWith(compareValue)) {
                     itemsFound++;
-                    result.append("<card handle=\"" + pos + ".vcf\" name=\""
-                            + currentValue + "\"" + "/>");
+                    writeVCardEntry(pos, currentValue,result);
                 }
             }
         }
@@ -982,6 +979,48 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
         return selection;
     }
 
+    /**
+     * XML encode special characters in the name field
+     */
+    private void xmlEncode(String name, StringBuilder result) {
+        if (name == null) {
+            return;
+        }
+
+        final StringCharacterIterator iterator = new StringCharacterIterator(name);
+        char character =  iterator.current();
+        while (character != CharacterIterator.DONE ){
+            if (character == '<') {
+                result.append("&lt;");
+            }
+            else if (character == '>') {
+                result.append("&gt;");
+            }
+            else if (character == '\"') {
+                result.append("&quot;");
+            }
+            else if (character == '\'') {
+                result.append("&#039;");
+            }
+            else if (character == '&') {
+                result.append("&amp;");
+            }
+            else {
+                // The char is not a special one, add it to the result as is
+                result.append(character);
+            }
+            character = iterator.next();
+        }
+    }
+
+    private void writeVCardEntry(int vcfIndex, String name, StringBuilder result) {
+        result.append("<card handle=\"");
+        result.append(vcfIndex);
+        result.append(".vcf\" name=\"");
+        xmlEncode(name, result);
+        result.append("\"/>");
+    }
+
     public static final void logHeader(HeaderSet hs) {
         Log.v(TAG, "Dumping HeaderSet " + hs.toString());
         try {
index 6ff0bf5..21d0e52 100755 (executable)
@@ -340,7 +340,8 @@ public class BluetoothPbapService extends Service {
             try {
                 // It is mandatory for PSE to support initiation of bonding and
                 // encryption.
-                mServerSocket = mAdapter.listenUsingRfcommWithServiceRecord("OBEX Phoneboox Access Server", BluetoothUuid.PBAP_PSE.getUuid());
+                mServerSocket = mAdapter. listenUsingEncryptedRfcommWithServiceRecord("OBEX Phoneboox Access Server", BluetoothUuid.PBAP_PSE.getUuid());
+
             } catch (IOException e) {
                 Log.e(TAG, "Error create RfcommServerSocket " + e.toString());
                 initSocketOK = false;