Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e40ecaed authored by Sunny Kapdi's avatar Sunny Kapdi Committed by Zhihai Xu
Browse files

MHF: Broadcast connected state for HS

- Since telephony doesn't store list of connected HS, BT needs
to broadcast connected state for an already connected HS,
when other HS disconnects. This will notify telephony that
even though one HS is disconnected, but still there is one
other connected HS. This fixes call routing issue to BT HS
from phone UI.

- Set mActiveScoDevice to null when HS disconnects while
it has SCO connected for ongoing call.

Change-Id: I91aba22844938b61afc0bac52b5b6de95354f491
CRs-Fixed: 619841
parent 1ae869ab
Loading
Loading
Loading
Loading
+33 −28
Original line number Diff line number Diff line
@@ -696,10 +696,6 @@ final class HeadsetStateMachine extends StateMachine {
                transitionTo(mConnected);
                int deviceSize = mConnectedDevicesList.size();
                mCurrentDevice = mConnectedDevicesList.get(deviceSize-1);
                log("Pending state: processMultiHFConnected ," +
                               "fake broadcasting for new mCurrentDevice");
                broadcastConnectionState(mCurrentDevice, BluetoothProfile.STATE_CONNECTED,
                                             BluetoothProfile.STATE_DISCONNECTED);
            } else {
                // The disconnected device is not current active device
                if (mAudioState == BluetoothHeadset.STATE_AUDIO_CONNECTED)
@@ -708,6 +704,10 @@ final class HeadsetStateMachine extends StateMachine {
            }
            log("processMultiHFConnected , the latest mCurrentDevice is:"
                                             + mCurrentDevice);
            log("Pending state: processMultiHFConnected ," +
                           "fake broadcasting for mCurrentDevice");
            broadcastConnectionState(mCurrentDevice, BluetoothProfile.STATE_CONNECTED,
                                         BluetoothProfile.STATE_DISCONNECTED);
        }
    }

@@ -1075,22 +1075,26 @@ final class HeadsetStateMachine extends StateMachine {

        private void processMultiHFConnected(BluetoothDevice device) {
            log("Connect state: processMultiHFConnected");
            if (mActiveScoDevice != null && mActiveScoDevice.equals(device)) {
                log ("mActiveScoDevice is disconnected, setting it to null");
                mActiveScoDevice = null;
            }
            /* Assign the current activedevice again if the disconnected
                         device equals to the current active device */
            if (mCurrentDevice != null && mCurrentDevice.equals(device)) {
                transitionTo(mConnected);
                int deviceSize = mConnectedDevicesList.size();
                mCurrentDevice = mConnectedDevicesList.get(deviceSize-1);
                log("Connect state: processMultiHFConnected ," +
                           "fake broadcasting for new mCurrentDevice");
                broadcastConnectionState(mCurrentDevice, BluetoothProfile.STATE_CONNECTED,
                                BluetoothProfile.STATE_DISCONNECTED);
            } else {
                // The disconnected device is not current active device
                transitionTo(mConnected);
            }
            log("processMultiHFConnected , the latest mCurrentDevice is:" +
                                     mCurrentDevice);
            log("Connect state: processMultiHFConnected ," +
                       "fake broadcasting for mCurrentDevice");
            broadcastConnectionState(mCurrentDevice, BluetoothProfile.STATE_CONNECTED,
                            BluetoothProfile.STATE_DISCONNECTED);
        }
    }

@@ -1388,7 +1392,8 @@ final class HeadsetStateMachine extends StateMachine {
                            mHeadsetBrsf.remove(device);
                            Log.d(TAG, "device " + device.getAddress() +
                                           " is removed in AudioOn state");

                            broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
                                                     BluetoothProfile.STATE_CONNECTED);
                            if (mConnectedDevicesList.size() == 0) {
                                transitionTo(mDisconnected);
                            }
@@ -1396,8 +1401,6 @@ final class HeadsetStateMachine extends StateMachine {
                                processMultiHFConnected(device);
                            }
                        }
                        broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
                                                 BluetoothProfile.STATE_CONNECTED);
                    } else {
                        Log.e(TAG, "Disconnected from unknown device: " + device);
                    }
@@ -1507,16 +1510,16 @@ final class HeadsetStateMachine extends StateMachine {
            if (mCurrentDevice != null && mCurrentDevice.equals(device)) {
                int deviceSize = mConnectedDevicesList.size();
                mCurrentDevice = mConnectedDevicesList.get(deviceSize-1);
                log("AudioOn state: processMultiHFConnected ," +
                           "fake broadcasting for new mCurrentDevice");
                broadcastConnectionState(mCurrentDevice, BluetoothProfile.STATE_CONNECTED,
                                BluetoothProfile.STATE_DISCONNECTED);
            }
            if (mAudioState != BluetoothHeadset.STATE_AUDIO_CONNECTED)
                transitionTo(mConnected);

            log("processMultiHFConnected , the latest mCurrentDevice is:"
                                      + mCurrentDevice);
            log("AudioOn state: processMultiHFConnected ," +
                       "fake broadcasting for mCurrentDevice");
            broadcastConnectionState(mCurrentDevice, BluetoothProfile.STATE_CONNECTED,
                            BluetoothProfile.STATE_DISCONNECTED);
        }
    }

@@ -1727,6 +1730,9 @@ final class HeadsetStateMachine extends StateMachine {
                              mHeadsetBrsf.remove(device);
                              Log.d(TAG, "device " + device.getAddress() +
                                      " is removed in MultiHFPending state");
                              broadcastConnectionState(device,
                                        BluetoothProfile.STATE_DISCONNECTED,
                                        BluetoothProfile.STATE_DISCONNECTING);
                          }

                          if (mTargetDevice != null) {
@@ -1759,9 +1765,6 @@ final class HeadsetStateMachine extends StateMachine {
                                  }
                              }
                           }
                           broadcastConnectionState(device,
                                     BluetoothProfile.STATE_DISCONNECTED,
                                     BluetoothProfile.STATE_DISCONNECTING);
                        } else {
                            /* Another HF disconnected when one HF is connecting */
                            synchronized (HeadsetStateMachine.this) {
@@ -1934,24 +1937,26 @@ final class HeadsetStateMachine extends StateMachine {

        private void processMultiHFConnected(BluetoothDevice device) {
            log("MultiHFPending state: processMultiHFConnected");
            if (mActiveScoDevice != null && mActiveScoDevice.equals(device)) {
                log ("mActiveScoDevice is disconnected, setting it to null");
                mActiveScoDevice = null;
            }
            /* Assign the current activedevice again if the disconnected
               device equals to the current active device */
            if (mCurrentDevice != null && mCurrentDevice.equals(device)) {
                transitionTo(mConnected);
                int deviceSize = mConnectedDevicesList.size();
                mCurrentDevice = mConnectedDevicesList.get(deviceSize-1);
                log("MultiHFPending state: processMultiHFConnected ," +
                             "fake broadcasting for new mCurrentDevice");
                broadcastConnectionState(mCurrentDevice, BluetoothProfile.STATE_CONNECTED,
                                BluetoothProfile.STATE_DISCONNECTED);
            } else {
            }
            // The disconnected device is not current active device
            if (mAudioState == BluetoothHeadset.STATE_AUDIO_CONNECTED)
                transitionTo(mAudioOn);
            else transitionTo(mConnected);
            }
            log("processMultiHFConnected , the latest mCurrentDevice is:"
                                            + mCurrentDevice);
            log("MultiHFPending state: processMultiHFConnected ," +
                         "fake broadcasting for mCurrentDevice");
            broadcastConnectionState(mCurrentDevice, BluetoothProfile.STATE_CONNECTED,
                            BluetoothProfile.STATE_DISCONNECTED);
        }

    }