[Audiosharing] Listen to onProfileConnectionStateChanged of LE_AUDIO_BROADCAST_ASSISTANT to be more precise on device connection status upon bluetooth on/off. Also increase test coverage.
Test: atest -c com.android.settings.connecteddevice.audiosharing.audiostreams Flag: com.android.settingslib.flags.enable_le_audio_qr_code_private_broadcast_sharing Bug: 345686602 Change-Id: Ia78b1fe19bff3cb179794db1dc09374db13818d8
This commit is contained in:
@@ -16,24 +16,22 @@
|
||||
|
||||
package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
public class AudioStreamsActiveDeviceSummaryUpdater implements BluetoothCallback {
|
||||
private static final String TAG = "AudioStreamsActiveDeviceSummaryUpdater";
|
||||
private static final boolean DEBUG = BluetoothUtils.D;
|
||||
private final LocalBluetoothManager mBluetoothManager;
|
||||
private Context mContext;
|
||||
@Nullable private String mSummary;
|
||||
@@ -47,17 +45,20 @@ public class AudioStreamsActiveDeviceSummaryUpdater implements BluetoothCallback
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActiveDeviceChanged(
|
||||
@Nullable CachedBluetoothDevice activeDevice, int bluetoothProfile) {
|
||||
if (DEBUG) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"onActiveDeviceChanged() with activeDevice : "
|
||||
+ (activeDevice == null ? "null" : activeDevice.getAddress())
|
||||
+ " on profile : "
|
||||
+ bluetoothProfile);
|
||||
public void onBluetoothStateChanged(@AdapterState int bluetoothState) {
|
||||
if (bluetoothState == BluetoothAdapter.STATE_OFF) {
|
||||
notifyChangeIfNeeded();
|
||||
}
|
||||
if (bluetoothProfile == BluetoothProfile.LE_AUDIO) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProfileConnectionStateChanged(
|
||||
@NonNull CachedBluetoothDevice cachedDevice,
|
||||
@ConnectionState int state,
|
||||
int bluetoothProfile) {
|
||||
if (bluetoothProfile == BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT
|
||||
&& (state == BluetoothAdapter.STATE_CONNECTED
|
||||
|| state == BluetoothAdapter.STATE_DISCONNECTED)) {
|
||||
notifyChangeIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
@@ -44,9 +44,13 @@ public class AudioStreamsCategoryController extends AudioSharingBasePreferenceCo
|
||||
private final BluetoothCallback mBluetoothCallback =
|
||||
new BluetoothCallback() {
|
||||
@Override
|
||||
public void onActiveDeviceChanged(
|
||||
@Nullable CachedBluetoothDevice activeDevice, int bluetoothProfile) {
|
||||
if (bluetoothProfile == BluetoothProfile.LE_AUDIO) {
|
||||
public void onProfileConnectionStateChanged(
|
||||
@NonNull CachedBluetoothDevice cachedDevice,
|
||||
@ConnectionState int state,
|
||||
int bluetoothProfile) {
|
||||
if (bluetoothProfile == BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT
|
||||
&& (state == BluetoothAdapter.STATE_CONNECTED
|
||||
|| state == BluetoothAdapter.STATE_DISCONNECTED)) {
|
||||
updateVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothLeBroadcastMetadata;
|
||||
import android.bluetooth.BluetoothLeBroadcastReceiveState;
|
||||
import android.util.Log;
|
||||
|
||||
public class AudioStreamsProgressCategoryCallback extends AudioStreamsBroadcastAssistantCallback {
|
||||
private static final String TAG = "AudioStreamsProgressCategoryCallback";
|
||||
@@ -53,10 +52,6 @@ public class AudioStreamsProgressCategoryCallback extends AudioStreamsBroadcastA
|
||||
@Override
|
||||
public void onSearchStarted(int reason) {
|
||||
super.onSearchStarted(reason);
|
||||
if (mCategoryController == null) {
|
||||
Log.w(TAG, "onSearchStarted() : mCategoryController is null!");
|
||||
return;
|
||||
}
|
||||
mCategoryController.setScanning(true);
|
||||
}
|
||||
|
||||
@@ -69,10 +64,6 @@ public class AudioStreamsProgressCategoryCallback extends AudioStreamsBroadcastA
|
||||
@Override
|
||||
public void onSearchStopped(int reason) {
|
||||
super.onSearchStopped(reason);
|
||||
if (mCategoryController == null) {
|
||||
Log.w(TAG, "onSearchStopped() : mCategoryController is null!");
|
||||
return;
|
||||
}
|
||||
mCategoryController.setScanning(false);
|
||||
}
|
||||
|
||||
@@ -86,10 +77,6 @@ public class AudioStreamsProgressCategoryCallback extends AudioStreamsBroadcastA
|
||||
@Override
|
||||
public void onSourceFound(BluetoothLeBroadcastMetadata source) {
|
||||
super.onSourceFound(source);
|
||||
if (mCategoryController == null) {
|
||||
Log.w(TAG, "onSourceFound() : mCategoryController is null!");
|
||||
return;
|
||||
}
|
||||
mCategoryController.handleSourceFound(source);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
@@ -47,9 +48,13 @@ public class AudioStreamsScanQrCodeController extends BasePreferenceController
|
||||
final BluetoothCallback mBluetoothCallback =
|
||||
new BluetoothCallback() {
|
||||
@Override
|
||||
public void onActiveDeviceChanged(
|
||||
@Nullable CachedBluetoothDevice activeDevice, int bluetoothProfile) {
|
||||
if (bluetoothProfile == BluetoothProfile.LE_AUDIO) {
|
||||
public void onProfileConnectionStateChanged(
|
||||
@NonNull CachedBluetoothDevice cachedDevice,
|
||||
@ConnectionState int state,
|
||||
int bluetoothProfile) {
|
||||
if (bluetoothProfile == BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT
|
||||
&& (state == BluetoothAdapter.STATE_CONNECTED
|
||||
|| state == BluetoothAdapter.STATE_DISCONNECTED)) {
|
||||
updateVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user