OSDN Git Service

Handle NREC. On connect, enable echo cancellation locally, headset will then override it
authorRavi Nagarajan <nravi@broadcom.com>
Tue, 24 Apr 2012 08:48:02 +0000 (01:48 -0700)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Tue, 17 Jul 2012 05:03:42 +0000 (22:03 -0700)
Change-Id: I8fca1e82d1457b47122c17393ffbff362e1f3134

src/com/android/bluetooth/hfp/HeadsetStateMachine.java

index c2c1ed7..c16b676 100755 (executable)
@@ -56,6 +56,9 @@ final class HeadsetStateMachine extends StateMachine {
     private static final String TAG = "HeadsetStateMachine";
     private static final boolean DBG = true;
 
+    private static final String HEADSET_NAME = "bt_headset_name";
+    private static final String HEADSET_NREC = "bt_headset_nrec";
+
     static final int CONNECT = 1;
     static final int DISCONNECT = 2;
     static final int CONNECT_AUDIO = 3;
@@ -301,6 +304,7 @@ final class HeadsetStateMachine extends StateMachine {
                     mCurrentDevice = device;
                     transitionTo(mConnected);
                 }
+                configAudioParameters();
                 break;
             case HeadsetHalConstants.CONNECTION_STATE_DISCONNECTING:
                 Log.w(TAG, "Ignore HF DISCONNECTING event, device: " + device);
@@ -465,6 +469,7 @@ final class HeadsetStateMachine extends StateMachine {
                         transitionTo(mConnected);
                     }
                 }
+                configAudioParameters();
                 break;
             case HeadsetHalConstants.CONNECTION_STATE_CONNECTING:
                 if ((mCurrentDevice != null) && mCurrentDevice.equals(device)) {
@@ -634,6 +639,9 @@ final class HeadsetStateMachine extends StateMachine {
                         case EVENT_TYPE_SEND_DTMF:
                             processSendDtmf(event.valueInt);
                             break;
+                        case EVENT_TYPE_NOICE_REDUCTION:
+                            processNoiceReductionEvent(event.valueInt);
+                            break;
                         case EVENT_TYPE_AT_CHLD:
                             processAtChld(event.valueInt);
                             break;
@@ -733,15 +741,10 @@ final class HeadsetStateMachine extends StateMachine {
     }
 
     private class AudioOn extends State {
-        // Audio parameters
-        private static final String HEADSET_NAME = "bt_headset_name";
-        private static final String HEADSET_NREC = "bt_headset_nrec";
 
         @Override
         public void enter() {
             log("Enter AudioOn: " + getCurrentMessage().what);
-            mAudioManager.setParameters(HEADSET_NAME + "=" + getCurrentDeviceName() + ";" +
-                                        HEADSET_NREC + "=on");
         }
 
         @Override
@@ -918,16 +921,6 @@ final class HeadsetStateMachine extends StateMachine {
             }
         }
 
-        // enable 1 enable noice reduction
-        //        0 disable noice reduction
-        private void processNoiceReductionEvent(int enable) {
-            if (enable == 1) {
-                mAudioManager.setParameters(HEADSET_NREC + "=on");
-            } else {
-                mAudioManager.setParameters(HEADSET_NREC + "off");
-            }
-        }
-
         private void processIntentScoVolume(Intent intent) {
             int volumeValue = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0);
             if (mPhoneState.getSpeakerVolume() != volumeValue) {
@@ -1153,6 +1146,13 @@ final class HeadsetStateMachine extends StateMachine {
         if (DBG) log("Audio state " + device + ": " + prevState + "->" + newState);
     }
 
+    private void configAudioParameters()
+    {
+        // Reset NREC on connect event. Headset will override later
+        mAudioManager.setParameters(HEADSET_NAME + "=" + getCurrentDeviceName() + ";" +
+                                    HEADSET_NREC + "=on");
+    }
+
     private void processAnswerCall() {
         if (mPhoneProxy != null) {
             try {
@@ -1263,6 +1263,16 @@ final class HeadsetStateMachine extends StateMachine {
         }
     }
 
+    // enable 1 enable noice reduction
+    //        0 disable noice reduction
+    private void processNoiceReductionEvent(int enable) {
+        if (enable == 1) {
+            mAudioManager.setParameters(HEADSET_NREC + "=on");
+        } else {
+            mAudioManager.setParameters(HEADSET_NREC + "off");
+        }
+    }
+
     private void processAtChld(int chld) {
         if (mPhoneProxy != null) {
             try {