HFP: Fix regressions in HFP state machine

* When we reject an incoming HF connection, we should notify the event
  to other parts of the stack so that hanlders such as PhonePolicy could
  react to the event such as attempting A2DP connection
* During SLC establishment, when remote device sends an unexpected
  command, we should still try to handle them, but generate a warning
  message to help debugging

Bug: 65246419
Test: connect with car kits and headsets, testplans/105951
Change-Id: I51f861a11948e5bfe3a0e0a58cee072f1eef4f5c
Merged-In: I51f861a11948e5bfe3a0e0a58cee072f1eef4f5c
(cherry picked from commit bc67ac7b9ef7a6b33fc550257b75726d86641923)
(cherry picked from commit 081c0e3696690dc3d98a54c0863dc9cc95248897)
(cherry picked from commit e5528ec2c195619ca1706e539df16c65f0b984bd)
diff --git a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
index 11dd48b..a8fcf15 100644
--- a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
+++ b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
@@ -435,6 +435,9 @@
                                         + device.getBondState() + ", device=" + device);
                         // reject the connection and stay in Disconnected state itself
                         disconnectHfpNative(getByteAddress(device));
+                        // the other profile connection should be initiated
+                        broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
+                                BluetoothProfile.STATE_DISCONNECTED);
                     }
                     break;
                 case HeadsetHalConstants.CONNECTION_STATE_DISCONNECTING:
@@ -518,6 +521,60 @@
                         case EVENT_TYPE_BIND:
                             processAtBind(event.valueString, event.device);
                             break;
+                        // Unexpected AT commands, we only handle them for comparability reasons
+                        case EVENT_TYPE_VR_STATE_CHANGED:
+                            Log.w(TAG,
+                                    "Pending: Unexpected VR event, device=" + event.device
+                                            + ", state=" + event.valueInt);
+                            processVrEvent(event.valueInt, event.device);
+                            break;
+                        case EVENT_TYPE_DIAL_CALL:
+                            Log.w(TAG, "Pending: Unexpected dial event, device=" + event.device);
+                            processDialCall(event.valueString, event.device);
+                            break;
+                        case EVENT_TYPE_SUBSCRIBER_NUMBER_REQUEST:
+                            Log.w(TAG,
+                                    "Pending: Unexpected subscriber number event for" + event.device
+                                            + ", state=" + event.valueInt);
+                            processSubscriberNumberRequest(event.device);
+                            break;
+                        case EVENT_TYPE_AT_COPS:
+                            Log.w(TAG, "Pending: Unexpected COPS event for " + event.device);
+                            processAtCops(event.device);
+                            break;
+                        case EVENT_TYPE_AT_CLCC:
+                            Log.w(TAG, "Pending: Unexpected CLCC event for" + event.device);
+                            processAtClcc(event.device);
+                            break;
+                        case EVENT_TYPE_UNKNOWN_AT:
+                            Log.w(TAG,
+                                    "Pending: Unexpected unknown AT event for" + event.device
+                                            + ", cmd=" + event.valueString);
+                            processUnknownAt(event.valueString, event.device);
+                            break;
+                        case EVENT_TYPE_KEY_PRESSED:
+                            Log.w(TAG, "Pending: Unexpected key-press event for " + event.device);
+                            processKeyPressed(event.device);
+                            break;
+                        case EVENT_TYPE_BIEV:
+                            Log.w(TAG,
+                                    "Pending: Unexpected BIEV event for " + event.device
+                                            + ", indId=" + event.valueInt
+                                            + ", indVal=" + event.valueInt2);
+                            processAtBiev(event.valueInt, event.valueInt2, event.device);
+                            break;
+                        case EVENT_TYPE_VOLUME_CHANGED:
+                            Log.w(TAG, "Pending: Unexpected volume event for " + event.device);
+                            processVolumeEvent(event.valueInt, event.valueInt2, event.device);
+                            break;
+                        case EVENT_TYPE_ANSWER_CALL:
+                            Log.w(TAG, "Pending: Unexpected answer event for " + event.device);
+                            processAnswerCall(event.device);
+                            break;
+                        case EVENT_TYPE_HANGUP_CALL:
+                            Log.w(TAG, "Pending: Unexpected hangup event for " + event.device);
+                            processHangupCall(event.device);
+                            break;
                         default:
                             Log.e(TAG, "Pending: Unexpected event: " + event.type);
                             break;
@@ -920,11 +977,9 @@
                             processVrEvent(event.valueInt, event.device);
                             break;
                         case EVENT_TYPE_ANSWER_CALL:
-                            // TODO(BT) could answer call happen on Connected state?
                             processAnswerCall(event.device);
                             break;
                         case EVENT_TYPE_HANGUP_CALL:
-                            // TODO(BT) could hangup call happen on Connected state?
                             processHangupCall(event.device);
                             break;
                         case EVENT_TYPE_VOLUME_CHANGED: