Loading android/app/src/com/android/bluetooth/Utils.java +6 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading android/app/src/com/android/bluetooth/hfp/HeadsetService.java +33 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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, Loading @@ -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 Loading @@ -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); } } Loading Loading
android/app/src/com/android/bluetooth/Utils.java +6 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading
android/app/src/com/android/bluetooth/hfp/HeadsetService.java +33 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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, Loading @@ -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 Loading @@ -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); } } Loading