OSDN Git Service

Add BT address and mimeType to handover intents.
authorMartijn Coenen <maco@google.com>
Mon, 14 May 2012 17:09:01 +0000 (10:09 -0700)
committerMartijn Coenen <maco@google.com>
Mon, 14 May 2012 20:58:05 +0000 (13:58 -0700)
Also, allow refreshing whitelisted entries by sending
another whitelist intent.

Change-Id: If85db397e31364939c67b3018413b625a1888ae6

src/com/android/bluetooth/opp/BluetoothOppManager.java
src/com/android/bluetooth/opp/BluetoothOppNotification.java
src/com/android/bluetooth/opp/BluetoothOppReceiver.java
src/com/android/bluetooth/opp/Constants.java

index 158707a..c996690 100644 (file)
@@ -165,13 +165,19 @@ public class BluetoothOppManager {
         }
     }
 
-    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;
index cdd74fb..a5b913d 100644 (file)
@@ -120,6 +120,8 @@ class BluetoothOppNotification {
         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 @@ class BluetoothOppNotification {
         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 @@ class BluetoothOppNotification {
             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 @@ class BluetoothOppNotification {
                 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 @@ class BluetoothOppNotification {
                 }
                 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;
             }
index bd35352..a061fa8 100644 (file)
@@ -240,11 +240,15 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
                             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);
index 1ebc858..20b9e2a 100644 (file)
@@ -89,6 +89,10 @@ public class Constants {
     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 class Constants {
     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";