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

Commit 0de9c096 authored by Yuyang Huang's avatar Yuyang Huang Committed by Gerrit Code Review
Browse files

Merge "Integrate createHfpInfo to notify Audio Framework that active device is changed" into main

parents 383ef540 7720ee88
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;
@@ -1197,7 +1198,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;
@@ -1469,6 +1470,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,
@@ -1480,8 +1490,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
@@ -1495,6 +1517,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);
            }
        }