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

Commit 59aa427f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove communication device refactor flag" into main

parents 13371a80 89f991ad
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -41,14 +41,6 @@ flag {
  bug: "306113816"
}

# OWNER=pmadapurmath TARGET=24Q3
flag {
  name: "call_audio_communication_device_refactor"
  namespace: "telecom"
  description: "Refactor call audio set/clear communication device and include unsupported routes."
  bug: "308968392"
}

# OWNER=pmadapurmath TARGET=24Q3
flag {
  name: "communication_device_protected_by_lock"
+23 −73
Original line number Diff line number Diff line
@@ -281,10 +281,8 @@ public class CallAudioRouteStateMachine extends StateMachine implements CallAudi
        public void enter() {
            super.enter();
            setSpeakerphoneOn(false);
            if (mFeatureFlags.callAudioCommunicationDeviceRefactor()) {
            mCommunicationDeviceTracker.setCommunicationDevice(
                    AudioDeviceInfo.TYPE_BUILTIN_EARPIECE, null);
            }
            CallAudioState newState = new CallAudioState(mIsMuted, ROUTE_EARPIECE,
                    mAvailableRoutes, null,
                    mBluetoothRouteManager.getConnectedDevices());
@@ -320,10 +318,8 @@ public class CallAudioRouteStateMachine extends StateMachine implements CallAudi
                case SWITCH_BLUETOOTH:
                case USER_SWITCH_BLUETOOTH:
                    if ((mAvailableRoutes & ROUTE_BLUETOOTH) != 0) {
                        if (mFeatureFlags.callAudioCommunicationDeviceRefactor()) {
                        mCommunicationDeviceTracker.clearCommunicationDevice(
                                AudioDeviceInfo.TYPE_BUILTIN_EARPIECE);
                        }
                        if (mAudioFocusType == ACTIVE_FOCUS
                                || mBluetoothRouteManager.isInbandRingingEnabled()) {
                            String address = (msg.obj instanceof SomeArgs) ?
@@ -340,10 +336,8 @@ public class CallAudioRouteStateMachine extends StateMachine implements CallAudi
                case SWITCH_HEADSET:
                case USER_SWITCH_HEADSET:
                    if ((mAvailableRoutes & ROUTE_WIRED_HEADSET) != 0) {
                        if (mFeatureFlags.callAudioCommunicationDeviceRefactor()) {
                        mCommunicationDeviceTracker.clearCommunicationDevice(
                                AudioDeviceInfo.TYPE_BUILTIN_EARPIECE);
                        }
                        transitionTo(mActiveHeadsetRoute);
                    } else {
                        Log.w(this, "Ignoring switch to headset command. Not available.");
@@ -353,10 +347,8 @@ public class CallAudioRouteStateMachine extends StateMachine implements CallAudi
                    // fall through; we want to switch to speaker mode when docked and in a call.
                case SWITCH_SPEAKER:
                case USER_SWITCH_SPEAKER:
                    if (mFeatureFlags.callAudioCommunicationDeviceRefactor()) {
                    mCommunicationDeviceTracker.clearCommunicationDevice(
                            AudioDeviceInfo.TYPE_BUILTIN_EARPIECE);
                    }
                    setSpeakerphoneOn(true);
                    // fall through
                case SPEAKER_ON:
@@ -510,10 +502,8 @@ public class CallAudioRouteStateMachine extends StateMachine implements CallAudi
        public void enter() {
            super.enter();
            setSpeakerphoneOn(false);
            if (mFeatureFlags.callAudioCommunicationDeviceRefactor()) {
            mCommunicationDeviceTracker.setCommunicationDevice(
                    AudioDeviceInfo.TYPE_WIRED_HEADSET, null);
            }
            CallAudioState newState = new CallAudioState(mIsMuted, ROUTE_WIRED_HEADSET,
                    mAvailableRoutes, null, mBluetoothRouteManager.getConnectedDevices());
            if (mFeatureFlags.earlyUpdateInternalCallAudioState()) {
@@ -540,10 +530,8 @@ public class CallAudioRouteStateMachine extends StateMachine implements CallAudi
                case SWITCH_EARPIECE:
                case USER_SWITCH_EARPIECE:
                    if ((mAvailableRoutes & ROUTE_EARPIECE) != 0) {
                        if (mFeatureFlags.callAudioCommunicationDeviceRefactor()) {
                        mCommunicationDeviceTracker.clearCommunicationDevice(
                                AudioDeviceInfo.TYPE_WIRED_HEADSET);
                        }
                        transitionTo(mActiveEarpieceRoute);
                    } else {
                        Log.w(this, "Ignoring switch to earpiece command. Not available.");
@@ -559,10 +547,8 @@ public class CallAudioRouteStateMachine extends StateMachine implements CallAudi
                                || mBluetoothRouteManager.isInbandRingingEnabled()) {
                            String address = (msg.obj instanceof SomeArgs) ?
                                    (String) ((SomeArgs) msg.obj).arg2 : null;
                            if (mFeatureFlags.callAudioCommunicationDeviceRefactor()) {
                            mCommunicationDeviceTracker.clearCommunicationDevice(
                                    AudioDeviceInfo.TYPE_WIRED_HEADSET);
                            }
                            // Omit transition to ActiveBluetoothRoute until actual connection.
                            setBluetoothOn(address);
                        } else {
@@ -579,10 +565,8 @@ public class CallAudioRouteStateMachine extends StateMachine implements CallAudi
                    return HANDLED;
                case SWITCH_SPEAKER:
                case USER_SWITCH_SPEAKER:
                    if (mFeatureFlags.callAudioCommunicationDeviceRefactor()) {
                    mCommunicationDeviceTracker.clearCommunicationDevice(
                            AudioDeviceInfo.TYPE_WIRED_HEADSET);
                    }
                    setSpeakerphoneOn(true);
                    // fall through
                case SPEAKER_ON:
@@ -750,9 +734,7 @@ public class CallAudioRouteStateMachine extends StateMachine implements CallAudi
            // the BT connection fails to be set. Previously, the logic was to setBluetoothOn in
            // ACTIVE_FOCUS but the route would still remain in a quiescent route, so instead we
            // should be transitioning directly into the active route.
            if (mFeatureFlags.callAudioCommunicationDeviceRefactor()) {
            setBluetoothOn(null);
            }
            if (mFeatureFlags.updateRouteMaskWhenBtConnected()) {
                mAvailableRoutes |= ROUTE_BLUETOOTH;
            }
@@ -1053,11 +1035,7 @@ public class CallAudioRouteStateMachine extends StateMachine implements CallAudi
                    if (msg.arg1 == ACTIVE_FOCUS) {
                        // It is possible that the connection to BT will fail while in-call, in
                        // which case, we want to transition into the active route.
                        if (mFeatureFlags.callAudioCommunicationDeviceRefactor()) {
                        transitionTo(mActiveBluetoothRoute);
                        } else {
                            setBluetoothOn(null);
                        }
                    } else if (msg.arg1 == RINGING_FOCUS) {
                        if (mBluetoothRouteManager.isInbandRingingEnabled()) {
                            setBluetoothOn(null);
@@ -1777,7 +1755,6 @@ public class CallAudioRouteStateMachine extends StateMachine implements CallAudi
        // These APIs are all via two-way binder calls so can potentially block Telecom.  Since none
        // of this has to happen in the Telecom lock we'll offload it to the async executor.
        boolean speakerOn = false;
        if (mFeatureFlags.callAudioCommunicationDeviceRefactor()) {
        if (on) {
            speakerOn = mCommunicationDeviceTracker.setCommunicationDevice(
                    AudioDeviceInfo.TYPE_BUILTIN_SPEAKER, null);
@@ -1785,9 +1762,6 @@ public class CallAudioRouteStateMachine extends StateMachine implements CallAudi
            mCommunicationDeviceTracker.clearCommunicationDevice(
                    AudioDeviceInfo.TYPE_BUILTIN_SPEAKER);
        }
        } else {
            speakerOn = processLegacySpeakerCommunicationDevice(on);
        }
        mStatusBarNotifier.notifySpeakerphone(hasAnyCalls && speakerOn);
    }

@@ -2036,30 +2010,6 @@ public class CallAudioRouteStateMachine extends StateMachine implements CallAudi
        return containsWatchDevice && !containsNonWatchDevice && !isActiveDeviceWatch;
    }

    private boolean processLegacySpeakerCommunicationDevice(boolean on) {
        AudioDeviceInfo speakerDevice = null;
        for (AudioDeviceInfo info : mAudioManager.getAvailableCommunicationDevices()) {
            if (info.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
                speakerDevice = info;
                break;
            }
        }
        boolean speakerOn = false;
        if (speakerDevice != null && on) {
            boolean result = mAudioManager.setCommunicationDevice(speakerDevice);
            if (result) {
                speakerOn = true;
            }
        } else {
            AudioDeviceInfo curDevice = mAudioManager.getCommunicationDevice();
            if (curDevice != null
                    && curDevice.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
                mAudioManager.clearCommunicationDevice();
            }
        }
        return speakerOn;
    }

    private int calculateBaselineRouteMessage(boolean isExplicitUserRequest,
            boolean includeBluetooth) {
        boolean isSkipEarpiece = false;
+6 −16
Original line number Diff line number Diff line
@@ -589,14 +589,8 @@ public class BluetoothDeviceManager {
    }

    public void disconnectAudio() {
        if (mFeatureFlags.callAudioCommunicationDeviceRefactor()) {
        mCommunicationDeviceTracker.clearBtCommunicationDevice();
        disconnectSco();
        } else {
            disconnectSco();
            clearLeAudioCommunicationDevice();
            clearHearingAidCommunicationDevice();
        }
    }

    public int disconnectSco() {
@@ -857,10 +851,8 @@ public class BluetoothDeviceManager {
                 * Only after receiving ACTION_ACTIVE_DEVICE_CHANGED it is known that device that
                 * will be audio switched to is available to be choose as communication device */
                if (!switchingBtDevices) {
                    return mFeatureFlags.callAudioCommunicationDeviceRefactor() ?
                            mCommunicationDeviceTracker.setCommunicationDevice(
                                    AudioDeviceInfo.TYPE_BLE_HEADSET, device)
                            : setLeAudioCommunicationDevice();
                    return mCommunicationDeviceTracker.setCommunicationDevice(
                            AudioDeviceInfo.TYPE_BLE_HEADSET, device);
                }
                return true;
            }
@@ -873,10 +865,8 @@ public class BluetoothDeviceManager {
                 * Only after receiving ACTION_ACTIVE_DEVICE_CHANGED it is known that device that
                 * will be audio switched to is available to be choose as communication device */
                if (!switchingBtDevices) {
                    return mFeatureFlags.callAudioCommunicationDeviceRefactor() ?
                            mCommunicationDeviceTracker.setCommunicationDevice(
                                    AudioDeviceInfo.TYPE_HEARING_AID, null)
                            : setHearingAidCommunicationDevice();
                    return mCommunicationDeviceTracker.setCommunicationDevice(
                            AudioDeviceInfo.TYPE_HEARING_AID, null);
                }
                return true;
            }
+8 −22
Original line number Diff line number Diff line
@@ -714,22 +714,14 @@ public class BluetoothRouteManager extends StateMachine {
        if (deviceType == BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO) {
            mLeAudioActiveDeviceCache = device;
            if (device == null) {
                if (mFeatureFlags.callAudioCommunicationDeviceRefactor()) {
                mCommunicationDeviceTracker.clearCommunicationDevice(
                        AudioDeviceInfo.TYPE_BLE_HEADSET);
                } else {
                    mDeviceManager.clearLeAudioCommunicationDevice();
                }
            }
        } else if (deviceType == BluetoothDeviceManager.DEVICE_TYPE_HEARING_AID) {
            mHearingAidActiveDeviceCache = device;
            if (device == null) {
                if (mFeatureFlags.callAudioCommunicationDeviceRefactor()) {
                mCommunicationDeviceTracker.clearCommunicationDevice(
                        AudioDeviceInfo.TYPE_HEARING_AID);
                } else {
                    mDeviceManager.clearHearingAidCommunicationDevice();
                }
            }
        } else if (deviceType == BluetoothDeviceManager.DEVICE_TYPE_HEADSET) {
            mHfpActiveDeviceCache = device;
@@ -975,11 +967,8 @@ public class BluetoothRouteManager extends StateMachine {
            }
        }

        boolean isHearingAidSetForCommunication =
                mFeatureFlags.callAudioCommunicationDeviceRefactor()
                ? mCommunicationDeviceTracker.isAudioDeviceSetForType(
                        AudioDeviceInfo.TYPE_HEARING_AID)
                : mDeviceManager.isHearingAidSetAsCommunicationDevice();
        boolean isHearingAidSetForCommunication = mCommunicationDeviceTracker
                .isAudioDeviceSetForType(AudioDeviceInfo.TYPE_HEARING_AID);
        if (bluetoothHearingAid != null) {
            if (isHearingAidSetForCommunication) {
                List<BluetoothDevice> hearingAidsActiveDevices = bluetoothAdapter.getActiveDevices(
@@ -999,11 +988,8 @@ public class BluetoothRouteManager extends StateMachine {
            }
        }

        boolean isLeAudioSetForCommunication =
                mFeatureFlags.callAudioCommunicationDeviceRefactor()
                        ? mCommunicationDeviceTracker.isAudioDeviceSetForType(
                        AudioDeviceInfo.TYPE_BLE_HEADSET)
                        : mDeviceManager.isLeAudioCommunicationDevice();
        boolean isLeAudioSetForCommunication = mCommunicationDeviceTracker.isAudioDeviceSetForType(
                AudioDeviceInfo.TYPE_BLE_HEADSET);
        if (bluetoothLeAudio != null) {
            if (isLeAudioSetForCommunication) {
                for (BluetoothDevice device : bluetoothAdapter.getActiveDevices(
+4 −11
Original line number Diff line number Diff line
@@ -334,11 +334,8 @@ public class BluetoothStateReceiver extends BroadcastReceiver {
                        /* In Le Audio case, once device got Active, the Telecom needs to make sure
                         * it is set as communication device before we can say that BT_AUDIO_IS_ON
                         */
                        boolean isLeAudioSetForCommunication =
                                mFeatureFlags.callAudioCommunicationDeviceRefactor()
                                        ? mCommunicationDeviceTracker.setCommunicationDevice(
                                        AudioDeviceInfo.TYPE_BLE_HEADSET, device)
                                        : mBluetoothDeviceManager.setLeAudioCommunicationDevice();
                        boolean isLeAudioSetForCommunication = mCommunicationDeviceTracker
                                .setCommunicationDevice(AudioDeviceInfo.TYPE_BLE_HEADSET, device);
                        if ((!usePreferredAudioProfile
                                || preferredDuplexProfile == BluetoothProfile.LE_AUDIO)
                                && !isLeAudioSetForCommunication) {
@@ -347,12 +344,8 @@ public class BluetoothStateReceiver extends BroadcastReceiver {
                                    device);
                        }
                    } else {
                        boolean isHearingAidSetForCommunication =
                                mFeatureFlags.callAudioCommunicationDeviceRefactor()
                                        ? mCommunicationDeviceTracker.setCommunicationDevice(
                                        AudioDeviceInfo.TYPE_HEARING_AID, null)
                                        : mBluetoothDeviceManager
                                        .setHearingAidCommunicationDevice();
                        boolean isHearingAidSetForCommunication = mCommunicationDeviceTracker
                                .setCommunicationDevice(AudioDeviceInfo.TYPE_HEARING_AID, null);
                        /* deviceType == BluetoothDeviceManager.DEVICE_TYPE_HEARING_AID */
                        if (!isHearingAidSetForCommunication) {
                            Log.w(LOG_TAG,
Loading