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

Commit 96117aeb authored by Jack He's avatar Jack He
Browse files

Bluetooth: Enable in-band ringing in vibration mode (3/4)

* Add AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING mode to force Bluetooth SCO
  in vibration mode
* Modify default audio policy engine to route audio through SCO only
  in AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING mode

Bug: 72647074
Test: Call phone in vibration mode and hear ringtone on HFP enabled
      headset, verify that ringtone is only played through headset.
      Then disconnect headset and call again to verify that ringtone
      does not play through phone speaker in vibration mode.

Change-Id: I2185955bd51166b76156ffd4efdd1f2f01757518
(cherry picked from commit 644693eee633980d356afcfedc7518ea7fed2c47)
parent ec57d7b5
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -62,7 +62,8 @@ static const std::string gForceUseCriterionTag[AUDIO_POLICY_FORCE_USE_CNT] =
    [AUDIO_POLICY_FORCE_FOR_DOCK] =                 "ForceUseForDock",
    [AUDIO_POLICY_FORCE_FOR_SYSTEM] =               "ForceUseForSystem",
    [AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO] =    "ForceUseForHdmiSystemAudio",
    [AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND] =     "ForceUseForEncodedSurround"
    [AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND] =     "ForceUseForEncodedSurround",
    [AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING] =      "ForceUseForVibrateRinging"
};


+25 −6
Original line number Diff line number Diff line
@@ -154,6 +154,13 @@ status_t Engine::setForceUse(audio_policy_force_use_t usage, audio_policy_forced
        }
        mForceUse[usage] = config;
        break;
    case AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING:
        if (config != AUDIO_POLICY_FORCE_BT_SCO && config != AUDIO_POLICY_FORCE_NONE) {
            ALOGW("setForceUse() invalid config %d for FOR_VIBRATE_RINGING", config);
            return BAD_VALUE;
        }
        mForceUse[usage] = config;
        break;
    default:
        ALOGW("setForceUse() invalid usage %d", usage);
        break; // TODO return BAD_VALUE?
@@ -423,8 +430,7 @@ audio_devices_t Engine::getDeviceForStrategyInt(routing_strategy strategy,

        // if SCO headset is connected and we are told to use it, play ringtone over
        // speaker and BT SCO
        if (((availableOutputDevicesType & AUDIO_DEVICE_OUT_ALL_SCO) != 0) &&
                (mForceUse[AUDIO_POLICY_FORCE_FOR_COMMUNICATION] == AUDIO_POLICY_FORCE_BT_SCO)) {
        if ((availableOutputDevicesType & AUDIO_DEVICE_OUT_ALL_SCO) != 0) {
            uint32_t device2 = AUDIO_DEVICE_NONE;
            device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT;
            if (device2 == AUDIO_DEVICE_NONE) {
@@ -433,12 +439,25 @@ audio_devices_t Engine::getDeviceForStrategyInt(routing_strategy strategy,
            if (device2 == AUDIO_DEVICE_NONE) {
                device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO;
            }

            // Use ONLY Bluetooth SCO output when ringing in vibration mode
            if (!((mForceUse[AUDIO_POLICY_FORCE_FOR_SYSTEM] == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED)
                    && (strategy == STRATEGY_ENFORCED_AUDIBLE))) {
                if (mForceUse[AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING]
                        == AUDIO_POLICY_FORCE_BT_SCO) {
                    if (device2 != AUDIO_DEVICE_NONE) {
                        device = device2;
                        break;
                    }
                }
            }
            // Use both Bluetooth SCO and phone default output when ringing in normal mode
            if (mForceUse[AUDIO_POLICY_FORCE_FOR_COMMUNICATION] == AUDIO_POLICY_FORCE_BT_SCO) {
                if (device2 != AUDIO_DEVICE_NONE) {
                    device |= device2;
                    break;
                }
            }
        }
        // The second device used for sonification is the same as the device used by media strategy
        // FALL THROUGH