FM: Take care of audio routing when BT is connected and disconnected.

BT A2DP has four change states. FM shouldn't change audio routing when it
receives every change states. It only needs to take care of two change
states, A2DP CONNECTED AND DISCONNECTED.

Change-Id: I69bed753c3d2f9c2fea0c3cd06a31d09fc2e1343
CRs-Fixed: 889151
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index 25ceeb2..8e2b657 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -551,7 +551,9 @@
                        // audio policy manager switch audio to speaker.
                        mHandler.removeCallbacks(mHeadsetPluginHandler);
                        mHandler.post(mHeadsetPluginHandler);
-                    } else if(mA2dpDeviceState.isA2dpStateChange(action) ) {
+                    } else if(mA2dpDeviceState.isA2dpStateChange(action) &&
+                             (mA2dpDeviceState.isConnected(intent) ||
+                              mA2dpDeviceState.isDisconnected(intent))) {
                         boolean  bA2dpConnected =
                         mA2dpDeviceState.isConnected(intent);
                         Log.d(LOGTAG, "bA2dpConnected:" +bA2dpConnected);
diff --git a/fmapp2/src/com/caf/hc_utils/A2dpDeviceStatus.java b/fmapp2/src/com/caf/hc_utils/A2dpDeviceStatus.java
index 45b647e..6b58f9e 100644
--- a/fmapp2/src/com/caf/hc_utils/A2dpDeviceStatus.java
+++ b/fmapp2/src/com/caf/hc_utils/A2dpDeviceStatus.java
@@ -65,6 +65,15 @@
         }
         return isConnected;
     }
+    public boolean isDisconnected(Intent intent) {
+        boolean isDisconnected = false;
+        int state = intent.getIntExtra(BluetoothA2dp.EXTRA_STATE,
+                                BluetoothA2dp.STATE_CONNECTED);
+        if((state == BluetoothA2dp.STATE_DISCONNECTED)) {
+            isDisconnected = true;
+        }
+        return isDisconnected;
+    }
     public boolean isPlaying(Intent intent) {
         boolean isPlaying = false;
         int state = intent.getIntExtra(BluetoothA2dp.EXTRA_STATE,