Include pin in pairing message bundle

Change-Id: Ic11d99af676771240232c19f57522cdedd97ddd3
(cherry picked from commit 7f2ac6913e530ece8c8b0e62f602294648b15de7)
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java
index 27d68f8..fc0646b 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java
@@ -81,11 +81,11 @@
         mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
         mBluetoothManager = (BluetoothManager) mContext.getSystemService(
                 Service.BLUETOOTH_SERVICE);
-        mPairingHelper = new BluetoothPairingHelper();
         // Use a synchronized map to avoid racing problems
         listeningDevices = Collections.synchronizedMap(new HashMap<String, BroadcastReceiver>());
 
         mEventFacade = manager.getReceiver(EventFacade.class);
+        mPairingHelper = new BluetoothPairingHelper(mEventFacade);
         mA2dpProfile = manager.getReceiver(BluetoothA2dpFacade.class);
         mA2dpSinkProfile = manager.getReceiver(BluetoothA2dpSinkFacade.class);
         mHidProfile = manager.getReceiver(BluetoothHidFacade.class);
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPairingHelper.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPairingHelper.java
index dbefd70..ce7123d 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPairingHelper.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPairingHelper.java
@@ -20,12 +20,17 @@
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
+import android.os.Bundle;
 
 import com.googlecode.android_scripting.Log;
+import com.googlecode.android_scripting.facade.EventFacade;
 
 public class BluetoothPairingHelper extends BroadcastReceiver {
-  public BluetoothPairingHelper() {
+  private final EventFacade mEventFacade;
+
+  public BluetoothPairingHelper(EventFacade eventFacade) {
     super();
+    mEventFacade = eventFacade;
     Log.d("Pairing helper created.");
   }
   /**
@@ -34,11 +39,17 @@
   @Override
   public void onReceive(Context c, Intent intent) {
     String action = intent.getAction();
+    Bundle result = new Bundle();
     Log.d("Bluetooth pairing intent received: " + action);
     BluetoothDevice mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
     if(action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
       int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.ERROR);
       Log.d("Processing Action Paring Request with type " + type);
+      int pin = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY,0);
+      result.putInt("Pin", pin);
+      result.putInt("PairingVariant", type);
+      mEventFacade.postEvent("BluetoothActionPairingRequest" + Integer.toString(type), result.clone());
+      result.clear();
       if(type == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION ||
          type == BluetoothDevice.PAIRING_VARIANT_CONSENT) {
         mDevice.setPairingConfirmation(true);
@@ -71,4 +82,4 @@
       }
     }
   }
-}
\ No newline at end of file
+}
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothRfcommFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothRfcommFacade.java
index f25e93e..8ed2f5f 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothRfcommFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothRfcommFacade.java
@@ -25,6 +25,8 @@
 import android.os.ParcelFileDescriptor;
 
 import com.googlecode.android_scripting.Log;
+import com.googlecode.android_scripting.facade.EventFacade;
+import com.googlecode.android_scripting.facade.bluetooth.BluetoothPairingHelper;
 import com.googlecode.android_scripting.facade.FacadeManager;
 import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
 import com.googlecode.android_scripting.rpc.Rpc;
@@ -63,11 +65,13 @@
           connections = new HashMap<String, BluetoothConnection>();
   private BluetoothSocket mCurrentSocket;
   private ConnectThread mCurrThread;
+  private final EventFacade mEventFacade;
 
   public BluetoothRfcommFacade(FacadeManager manager) {
     super(manager);
+    mEventFacade = manager.getReceiver(EventFacade.class);
     mService = manager.getService();
-    mPairingReceiver = new BluetoothPairingHelper();
+    mPairingReceiver = new BluetoothPairingHelper(mEventFacade);
     mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
   }