OSDN Git Service

Add unbond reason to bond state change intent
authorRavi Nagarajan <nravi@broadcom.com>
Mon, 6 Aug 2012 12:39:35 +0000 (05:39 -0700)
committerMatthew Xie <mattx@google.com>
Fri, 10 Aug 2012 06:19:14 +0000 (23:19 -0700)
HAL sends the status to indicate the reason for bonding failure, if any.
Add this to bond state change intent, so that the Settings app can
display the error dialong, if necessary.
bug 6936335

Change-Id: Ide7c9e497bbfc6428b60c7a6de6e01ca538edfb8

src/com/android/bluetooth/btservice/AbstractionLayer.java [changed mode: 0644->0755]
src/com/android/bluetooth/btservice/BondStateMachine.java

old mode 100644 (file)
new mode 100755 (executable)
index a726843..8478102
@@ -54,4 +54,14 @@ final public class AbstractionLayer {
     static final int BT_UUID_SIZE = 16; // bytes
 
     public static final int BT_STATUS_SUCCESS = 0;
+    public static final int BT_STATUS_FAIL = 1;
+    public static final int BT_STATUS_NOT_READY = 2;
+    public static final int BT_STATUS_NOMEM = 3;
+    public static final int BT_STATUS_BUSY = 4;
+    public static final int BT_STATUS_DONE = 5;
+    public static final int BT_STATUS_UNSUPPORTED = 6;
+    public static final int BT_STATUS_PARM_INVALID = 7;
+    public static final int BT_STATUS_UNHANDLED = 8;
+    public static final int BT_STATUS_AUTH_FAILURE = 9;
+    public static final int BT_STATUS_RMT_DEV_DOWN = 10;
 }
index cdd93f2..c111dff 100755 (executable)
@@ -97,7 +97,7 @@ final class BondStateMachine extends StateMachine {
                 /* if incoming pairing, transition to pending state */
                 if (newState == BluetoothDevice.BOND_BONDING)
                 {
-                    sendIntent(dev, newState);
+                    sendIntent(dev, newState, 0);
                     transitionTo(mPendingCommandState);
                 }
                 else
@@ -149,7 +149,8 @@ final class BondStateMachine extends StateMachine {
                     break;
                 case BONDING_STATE_CHANGE:
                     int newState = msg.arg1;
-                    sendIntent(dev, newState);
+                    int reason = getUnbondReasonFromHALCode(msg.arg2);
+                    sendIntent(dev, newState, reason);
                     if(newState != BluetoothDevice.BOND_BONDING )
                     {
                         /* this is either none/bonded, remove and transition */
@@ -217,7 +218,8 @@ final class BondStateMachine extends StateMachine {
             infoLog("Bond address is:" + dev);
             byte[] addr = Utils.getBytesFromAddress(dev.getAddress());
             if (!mAdapterService.createBondNative(addr)) {
-                sendIntent(dev, BluetoothDevice.BOND_NONE);
+                sendIntent(dev, BluetoothDevice.BOND_NONE,
+                           BluetoothDevice.UNBOND_REASON_REMOVED);
                 return false;
             } else if (transition) {
                 transitionTo(mPendingCommandState);
@@ -227,7 +229,7 @@ final class BondStateMachine extends StateMachine {
         return false;
     }
 
-    private void sendIntent(BluetoothDevice device, int newState) {
+    private void sendIntent(BluetoothDevice device, int newState, int reason) {
         DeviceProperties devProp = mRemoteDevices.getDeviceProperties(device);
         int oldState = BluetoothDevice.BOND_NONE;
         if (devProp != null) {
@@ -240,6 +242,8 @@ final class BondStateMachine extends StateMachine {
         intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
         intent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, newState);
         intent.putExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, oldState);
+        if (newState == BluetoothDevice.BOND_NONE)
+            intent.putExtra(BluetoothDevice.EXTRA_REASON, reason);
         mAdapterService.sendBroadcast(intent, AdapterService.BLUETOOTH_PERM);
         infoLog("Bond State Change Intent:" + device + " OldState: " + oldState
                 + " NewState: " + newState);
@@ -267,6 +271,7 @@ final class BondStateMachine extends StateMachine {
             msg.arg1 = BluetoothDevice.BOND_BONDING;
         else
             msg.arg1 = BluetoothDevice.BOND_NONE;
+        msg.arg2 = status;
 
         sendMessage(msg);
     }
@@ -313,4 +318,15 @@ final class BondStateMachine extends StateMachine {
         Log.e(TAG, msg);
     }
 
+    private int getUnbondReasonFromHALCode (int reason) {
+        if (reason == AbstractionLayer.BT_STATUS_SUCCESS)
+            return BluetoothDevice.BOND_SUCCESS;
+        else if (reason == AbstractionLayer.BT_STATUS_RMT_DEV_DOWN)
+            return BluetoothDevice.UNBOND_REASON_REMOTE_DEVICE_DOWN;
+        else if (reason == AbstractionLayer.BT_STATUS_AUTH_FAILURE)
+            return BluetoothDevice.UNBOND_REASON_AUTH_FAILED;
+
+        /* default */
+        return BluetoothDevice.UNBOND_REASON_REMOVED;
+    }
 }