am 20e0594a: am 3236357a: Merge "Add BT address and mimeType to handover intents." into jb-dev

* commit '20e0594a8deef6d308c6b61e037aa0a40ce1404f':
  Add BT address and mimeType to handover intents.
diff --git a/src/com/android/bluetooth/opp/BluetoothOppManager.java b/src/com/android/bluetooth/opp/BluetoothOppManager.java
index 158707a..c996690 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppManager.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppManager.java
@@ -165,13 +165,19 @@
         }
     }
 
-    public void addToWhitelist(String address) {
+    public synchronized void addToWhitelist(String address) {
         if (address == null) return;
-
+        // Remove any existing entries
+        for (Iterator<Pair<String,Long>> iter = mWhitelist.iterator(); iter.hasNext(); ) {
+            Pair<String,Long> entry = iter.next();
+            if (entry.first.equals(address)) {
+                iter.remove();
+            }
+        }
         mWhitelist.add(new Pair<String, Long>(address, SystemClock.elapsedRealtime()));
     }
 
-    public boolean isWhitelisted(String address) {
+    public synchronized boolean isWhitelisted(String address) {
         cleanupWhitelist();
         for (Pair<String,Long> entry : mWhitelist) {
             if (entry.first.equals(address)) return true;
diff --git a/src/com/android/bluetooth/opp/BluetoothOppNotification.java b/src/com/android/bluetooth/opp/BluetoothOppNotification.java
index cdd74fb..a5b913d 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppNotification.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppNotification.java
@@ -120,6 +120,8 @@
         String description; // the text above progress bar
 
         boolean handoverInitiated = false; // transfer initiated by connection handover (eg NFC)
+
+        String destination; // destination associated with this transfer
     }
 
     /**
@@ -232,6 +234,7 @@
         final int dataIndex = cursor.getColumnIndexOrThrow(BluetoothShare._DATA);
         final int filenameHintIndex = cursor.getColumnIndexOrThrow(BluetoothShare.FILENAME_HINT);
         final int confirmIndex = cursor.getColumnIndexOrThrow(BluetoothShare.USER_CONFIRMATION);
+        final int destinationIndex = cursor.getColumnIndexOrThrow(BluetoothShare.DESTINATION);
 
         mNotifications.clear();
         for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
@@ -242,6 +245,7 @@
             int current = cursor.getInt(currentBytesIndex);
             int confirmation = cursor.getInt(confirmIndex);
 
+            String destination = cursor.getString(destinationIndex);
             String fileName = cursor.getString(dataIndex);
             if (fileName == null) {
                 fileName = cursor.getString(filenameHintIndex);
@@ -273,6 +277,7 @@
                 item.totalTotal = total;
                 item.handoverInitiated =
                         confirmation == BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED;
+                item.destination = destination;
                 mNotifications.put(batchID, item);
 
                 if (V) Log.v(TAG, "ID=" + item.id + "; batchID=" + batchID + "; totoalCurrent"
@@ -302,7 +307,7 @@
                 }
                 intent.putExtra(Constants.EXTRA_BT_OPP_TRANSFER_ID, item.id);
                 intent.putExtra(Constants.EXTRA_BT_OPP_TRANSFER_PROGRESS, progress);
-
+                intent.putExtra(Constants.EXTRA_BT_OPP_ADDRESS, item.destination);
                 mContext.sendBroadcast(intent, Constants.HANDOVER_STATUS_PERMISSION);
                 continue;
             }
diff --git a/src/com/android/bluetooth/opp/BluetoothOppReceiver.java b/src/com/android/bluetooth/opp/BluetoothOppReceiver.java
index bd35352..a061fa8 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppReceiver.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppReceiver.java
@@ -240,11 +240,15 @@
                             Constants.DIRECTION_BLUETOOTH_OUTGOING);
                 }
                 handoverIntent.putExtra(Constants.EXTRA_BT_OPP_TRANSFER_ID, transInfo.mID);
+                handoverIntent.putExtra(Constants.EXTRA_BT_OPP_ADDRESS, transInfo.mDestAddr);
+
                 if (BluetoothShare.isStatusSuccess(transInfo.mStatus)) {
                     handoverIntent.putExtra(Constants.EXTRA_BT_OPP_TRANSFER_STATUS,
                             Constants.HANDOVER_TRANSFER_STATUS_SUCCESS);
                     handoverIntent.putExtra(Constants.EXTRA_BT_OPP_TRANSFER_URI,
                             transInfo.mFileName);
+                    handoverIntent.putExtra(Constants.EXTRA_BT_OPP_TRANSFER_MIMETYPE,
+                            transInfo.mFileType);
                 } else {
                     handoverIntent.putExtra(Constants.EXTRA_BT_OPP_TRANSFER_STATUS,
                             Constants.HANDOVER_TRANSFER_STATUS_FAILURE);
diff --git a/src/com/android/bluetooth/opp/Constants.java b/src/com/android/bluetooth/opp/Constants.java
index 1ebc858..20b9e2a 100644
--- a/src/com/android/bluetooth/opp/Constants.java
+++ b/src/com/android/bluetooth/opp/Constants.java
@@ -89,6 +89,10 @@
     public static final String EXTRA_BT_OPP_TRANSFER_STATUS =
             "android.btopp.intent.extra.BT_OPP_TRANSFER_STATUS";
 
+    /** intent extra used to indicate the address associated with the transfer */
+    public static final String EXTRA_BT_OPP_ADDRESS =
+            "android.btopp.intent.extra.BT_OPP_ADDRESS";
+
     public static final int HANDOVER_TRANSFER_STATUS_SUCCESS = 0;
 
     public static final int HANDOVER_TRANSFER_STATUS_FAILURE = 1;
@@ -114,6 +118,11 @@
     public static final String EXTRA_BT_OPP_TRANSFER_URI =
             "android.btopp.intent.extra.BT_OPP_TRANSFER_URI";
 
+    /** intent extra used to provide the mime-type of the data in
+     *  the handover transfer */
+    public static final String EXTRA_BT_OPP_TRANSFER_MIMETYPE =
+            "android.btopp.intent.extra.BT_OPP_TRANSFER_MIMETYPE";
+
     /** permission needed to be able to receive handover status requests */
     public static final String HANDOVER_STATUS_PERMISSION =
             "com.android.permission.HANDOVER_STATUS";