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

Commit 7720ee88 authored by Yuyang Huang's avatar Yuyang Huang
Browse files

Integrate createHfpInfo to notify Audio Framework that active device is changed

Bug: 294134504
Bug: 315234036
Test: m .
Change-Id: Ieffbf7903b4f09398a1d2b7a9f1c7a6b085b9ccd
parent bfe2ae56
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.os.PowerExemptionManager.TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED;
import static android.permission.PermissionManager.PERMISSION_HARD_DENIED;

import static com.android.modules.utils.build.SdkLevel.isAtLeastV;

import android.Manifest;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -164,6 +166,10 @@ public final class Utils {
    public static boolean isScoManagedByAudioEnabled() {
        if (Flags.isScoManagedByAudio()) {
            Log.d(TAG, "isScoManagedByAudioEnabled state is: " + isScoManagedByAudioEnabled);
            if (isScoManagedByAudioEnabled && !isAtLeastV()) {
                Log.e(TAG, "isScoManagedByAudio should not be enabled before Android V");
                return false;
            }
            return isScoManagedByAudioEnabled;
        }
        return false;
+33 −2
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioDeviceInfo;
import android.media.AudioManager;
import android.media.BluetoothProfileConnectionInfo;
import android.net.Uri;
import android.os.BatteryManager;
import android.os.Handler;
@@ -1198,7 +1199,7 @@ public class HeadsetService extends ProfileService {
            } else {
                stateMachine.sendMessage(HeadsetStateMachine.VOICE_RECOGNITION_START, device);
            }
            if (Flags.isScoManagedByAudio()) {
            if (Utils.isScoManagedByAudioEnabled()) {
                // when isScoManagedByAudio is on, tell AudioManager to connect SCO
                AudioManager am = mSystemInterface.getAudioManager();
                BluetoothDevice finalDevice = device;
@@ -1470,6 +1471,15 @@ public class HeadsetService extends ProfileService {
                    }
                    return false;
                }
                if (Utils.isScoManagedByAudioEnabled()) {
                    // tell Audio Framework that active device changed
                    mSystemInterface
                            .getAudioManager()
                            .handleBluetoothActiveDeviceChanged(
                                    mActiveDevice,
                                    previousActiveDevice,
                                    BluetoothProfileConnectionInfo.createHfpInfo());
                }
                broadcastActiveDevice(mActiveDevice);
            } else if (shouldPersistAudio()) {
                /* If HFP is getting active for a phonecall and there is LeAudio device active,
@@ -1481,8 +1491,20 @@ public class HeadsetService extends ProfileService {
                    Log.i(TAG, "Make sure there is no le audio device active.");
                    leAudioService.setInactiveForHfpHandover(mActiveDevice);
                }

                if (Utils.isScoManagedByAudioEnabled()) {
                    // tell Audio Framework that active device changed
                    mSystemInterface
                            .getAudioManager()
                            .handleBluetoothActiveDeviceChanged(
                                    mActiveDevice,
                                    previousActiveDevice,
                                    BluetoothProfileConnectionInfo.createHfpInfo());
                }
                broadcastActiveDevice(mActiveDevice);
                if (Utils.isScoManagedByAudioEnabled()) {
                    // Audio Framework will handle audio transition
                    return true;
                }
                int connectStatus = connectAudio(mActiveDevice);
                if (connectStatus != BluetoothStatusCodes.SUCCESS) {
                    Log.e(TAG, "setActiveDevice: fail to connectAudio to " + mActiveDevice
@@ -1496,6 +1518,15 @@ public class HeadsetService extends ProfileService {
                    return false;
                }
            } else {
                if (Utils.isScoManagedByAudioEnabled()) {
                    // tell Audio Framework that active device changed
                    mSystemInterface
                            .getAudioManager()
                            .handleBluetoothActiveDeviceChanged(
                                    mActiveDevice,
                                    previousActiveDevice,
                                    BluetoothProfileConnectionInfo.createHfpInfo());
                }
                broadcastActiveDevice(mActiveDevice);
            }
        }