Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:The pad is connected to the Bluetooth headset, but sco cannot be … #1814

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TC-zerol
Copy link

…established.

Problem description: When the pad device is connected to a Bluetooth headset to initiate a VoIP call, the microphone of the pad device is called instead of the microphone of the Bluetooth headset.

https://github.com/DrKLO/Telegram/blob/master/TMessagesProj/src/main/java/org/telegram/messenger/voip/VoIPService.java

// When the pad is connected to a Bluetooth headset, the hasEarpiece() method returns false, resulting in the sco call being unable to be established. Telegram still uses the pad's microphone, not the Bluetooth headset.
if (isBluetoothHeadsetConnected() && hasEarpiece()) {
						switch (audioRouteToSet) {
							case AUDIO_ROUTE_BLUETOOTH:
								if (!bluetoothScoActive) {
									needSwitchToBluetoothAfterScoActivates = true;
									try {
										am.startBluetoothSco();
									} catch (Throwable e) {
										FileLog.e(e);
									}

The iPad device does not have telephony capabilities. To determine whether there is an earpiece, when connected to Bluetooth, the value obtained by bitmaskResult is 128 (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP), so the mask operation will return false.

if (((TelephonyManager) getSystemService(TELEPHONY_SERVICE)).getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) {
                        // The mobile device has telephony capability, so it will return true here.
			return true;
		}
		if (mHasEarpiece != null) {
			return mHasEarpiece;
		}

		// not calculated yet, do it now
		try {
			AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
			Method method = AudioManager.class.getMethod("getDevicesForStream", Integer.TYPE);
			Field field = AudioManager.class.getField("DEVICE_OUT_EARPIECE");
			int earpieceFlag = field.getInt(null);
			int bitmaskResult = (int) method.invoke(am, AudioManager.STREAM_VOICE_CALL);

			// check if masked by the earpiece flag
			if ((bitmaskResult & earpieceFlag) == earpieceFlag) {
				mHasEarpiece = Boolean.TRUE;
			} else {
				mHasEarpiece = Boolean.FALSE;
			}

There is a problem here with the judgment of whether a Bluetooth headset is connected and whether the Bluetooth headset has the ability to make calls. I hope you can help fix it.

@TC-zerol
Copy link
Author

@dkaraush please fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant