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

Commit 0fe02ad0 authored by Jack He's avatar Jack He
Browse files

HFP: Fix phone state change in Telecom and VoIP calls

* We used to ignore phone state change when devices are all disconnected
* Instead, phone state change should always be captured by HeadsetService's
  HeadsetPhoneState regardless of device connection state.
* This prevents HeadsetService from notifying remote device wrong phone
  state when just connected
* VoIP calls' phone state change should also be handled in
  HeadsetService to allow multiple connected HFP devices to sync
* Add unit test for phone state change
* Synchronize HeadsetServce state cleanup and setters using
  mStateMachines to avoid race condition
* Log the pid and uid of key SCO event callers
* Intents should be sent when audio is disconnected from headset

Call Policy after this change:
* VoIP call -> Telecom Call: Telecom call should cause VoIP call to stop
* Telecom call -> VoIP call: VoIP call should be rejected
* VoIP call state is no longer cleaned during SCO tear down, instead, it
  should be teared down by the original caller to
  startScoUsingVirtualVoiceCall() via stopScoUsingVirtualVoiceCall()

Bug: 76201254
Bug: 76114959
Test: HeadsetServiceTest, HeadsetServiceAndStateMachineTest
      Connect to Bose QC35, call, turn off headset, end call, turn on
      headset
Change-Id: I230f4da47fc57392208e26156f9e975ea2a1fad5
(cherry picked from commit 22442dd1)
parent 0bd8d9f3
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -382,4 +382,13 @@ public final class Utils {
            throw new IllegalStateException("Not in BluetoothInstrumentationTest");
        }
    }

    /**
     * Get uid/pid string in a binder call
     *
     * @return "uid/pid=xxxx/yyyy"
     */
    public static String getUidPidString() {
        return "uid/pid=" + Binder.getCallingUid() + "/" + Binder.getCallingPid();
    }
}
+22 −1
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.bluetooth.hfp;

import java.util.Objects;

/**
 * A blob of data representing an overall call state on the phone
 */
@@ -59,7 +61,7 @@ class HeadsetCallState extends HeadsetMessageObject {
                .append(mNumActive)
                .append(", numHeld=")
                .append(mNumHeld)
                .append(", callState")
                .append(", callState=")
                .append(mCallState)
                .append(", number=");
        if (mNumber == null) {
@@ -69,4 +71,23 @@ class HeadsetCallState extends HeadsetMessageObject {
        }
        builder.append(mNumber).append(", type=").append(mType).append("]");
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        if (!(object instanceof HeadsetCallState)) {
            return false;
        }
        HeadsetCallState that = (HeadsetCallState) object;
        return mNumActive == that.mNumActive && mNumHeld == that.mNumHeld
                && mCallState == that.mCallState && Objects.equals(mNumber, that.mNumber)
                && mType == that.mType;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mNumActive, mNumHeld, mCallState, mNumber, mType);
    }
}
+7 −3
Original line number Diff line number Diff line
@@ -192,7 +192,8 @@ public class HeadsetPhoneState {
        return mNumActive;
    }

    void setNumActiveCall(int numActive) {
    @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
    public void setNumActiveCall(int numActive) {
        mNumActive = numActive;
    }

@@ -200,7 +201,8 @@ public class HeadsetPhoneState {
        return mCallState;
    }

    void setCallState(int callState) {
    @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
    public void setCallState(int callState) {
        mCallState = callState;
    }

@@ -208,7 +210,8 @@ public class HeadsetPhoneState {
        return mNumHeld;
    }

    void setNumHeldCall(int numHeldCall) {
    @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
    public void setNumHeldCall(int numHeldCall) {
        mNumHeld = numHeldCall;
    }

@@ -225,6 +228,7 @@ public class HeadsetPhoneState {
     *
     * @param batteryLevel battery level value
     */
    @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
    public void setCindBatteryCharge(int batteryLevel) {
        if (mCindBatteryCharge != batteryLevel) {
            mCindBatteryCharge = batteryLevel;
+297 −75

File changed.

Preview size limit exceeded, changes collapsed.

+68 −239

File changed.

Preview size limit exceeded, changes collapsed.

Loading