Merge "[Audiosharing] add profile service listener when BT just on" into main

This commit is contained in:
Yiyi Shen
2025-01-23 18:23:17 -08:00
committed by Android (Google) Code Review
4 changed files with 147 additions and 39 deletions

View File

@@ -136,9 +136,18 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
new BroadcastReceiver() { new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)
== BluetoothAdapter.STATE_ON
&& !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
if (mProfileManager != null) {
mProfileManager.addServiceListener(
AudioSharingSwitchBarController.this);
}
} else {
updateSwitch(); updateSwitch();
mListener.onAudioSharingStateChanged(); mListener.onAudioSharingStateChanged();
} }
}
}; };
@VisibleForTesting @VisibleForTesting
@@ -360,14 +369,14 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
} }
mContext.registerReceiver(mReceiver, mIntentFilter, Context.RECEIVER_EXPORTED_UNAUDITED); mContext.registerReceiver(mReceiver, mIntentFilter, Context.RECEIVER_EXPORTED_UNAUDITED);
updateSwitch(); updateSwitch();
registerCallbacks();
if (!AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) { if (!AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
if (mProfileManager != null) { if (mProfileManager != null) {
mProfileManager.addServiceListener(this); mProfileManager.addServiceListener(this);
} }
Log.d(TAG, "Skip register callbacks. Profile is not ready."); Log.d(TAG, "Skip handleStartAudioSharingFromIntent. Profile is not ready.");
return; return;
} }
registerCallbacks();
if (mIntentHandleStage.compareAndSet( if (mIntentHandleStage.compareAndSet(
StartIntentHandleStage.TO_HANDLE.ordinal(), StartIntentHandleStage.TO_HANDLE.ordinal(),
StartIntentHandleStage.HANDLE_AUTO_ADD.ordinal())) { StartIntentHandleStage.HANDLE_AUTO_ADD.ordinal())) {
@@ -445,7 +454,6 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
public void onServiceConnected() { public void onServiceConnected() {
Log.d(TAG, "onServiceConnected()"); Log.d(TAG, "onServiceConnected()");
if (AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) { if (AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
registerCallbacks();
updateSwitch(); updateSwitch();
mListener.onAudioSharingProfilesConnected(); mListener.onAudioSharingProfilesConnected();
mListener.onAudioSharingStateChanged(); mListener.onAudioSharingStateChanged();
@@ -525,7 +533,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
} }
private void unregisterCallbacks() { private void unregisterCallbacks() {
if (!isAvailable() || !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) { if (!isAvailable()) {
Log.d(TAG, "Skip unregisterCallbacks(). Feature is not available."); Log.d(TAG, "Skip unregisterCallbacks(). Feature is not available.");
return; return;
} }

View File

@@ -52,8 +52,16 @@ public class StreamSettingsCategoryController extends BasePreferenceController
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (!BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) return; if (!BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) return;
if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)
== BluetoothAdapter.STATE_ON && !isProfileReady()) {
if (mProfileManager != null) {
mProfileManager.addServiceListener(
StreamSettingsCategoryController.this);
}
} else {
updateVisibility(); updateVisibility();
} }
}
}; };
public StreamSettingsCategoryController(Context context, String key) { public StreamSettingsCategoryController(Context context, String key) {
@@ -97,7 +105,7 @@ public class StreamSettingsCategoryController extends BasePreferenceController
@Override @Override
public void onServiceConnected() { public void onServiceConnected() {
if (isAvailable() && isProfileReady()) { if (isProfileReady()) {
updateVisibility(); updateVisibility();
if (mProfileManager != null) { if (mProfileManager != null) {
mProfileManager.removeServiceListener(this); mProfileManager.removeServiceListener(this);

View File

@@ -51,6 +51,8 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.os.Bundle; import android.os.Bundle;
import android.os.Looper; import android.os.Looper;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule; import android.platform.test.flag.junit.SetFlagsRule;
import android.util.FeatureFlagUtils; import android.util.FeatureFlagUtils;
import android.util.Pair; import android.util.Pair;
@@ -245,8 +247,53 @@ public class AudioSharingSwitchBarControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void bluetoothOn_profileReady_switchEnabled() {
mSwitchBar.setEnabled(false);
mContext.registerReceiver(
mController.mReceiver,
mController.mIntentFilter,
Context.RECEIVER_EXPORTED_UNAUDITED);
mShadowBluetoothAdapter.setEnabled(true);
when(mBroadcast.isEnabled(null)).thenReturn(false);
Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_ON);
mContext.sendBroadcast(intent);
shadowOf(Looper.getMainLooper()).idle();
verify(mSwitchBar).setEnabled(true);
assertThat(mSwitchBar.isChecked()).isFalse();
assertThat(mOnAudioSharingStateChanged).isTrue();
assertThat(mOnAudioSharingServiceConnected).isFalse();
verify(mBtProfileManager, never()).addServiceListener(any());
}
@Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void bluetoothOn_profileNotReady_switchDisabled_registerProfileListener() {
mSwitchBar.setEnabled(false);
mContext.registerReceiver(
mController.mReceiver,
mController.mIntentFilter,
Context.RECEIVER_EXPORTED_UNAUDITED);
mShadowBluetoothAdapter.setEnabled(true);
when(mBroadcast.isEnabled(null)).thenReturn(false);
when(mBroadcast.isProfileReady()).thenReturn(false);
Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_ON);
mContext.sendBroadcast(intent);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mSwitchBar.isEnabled()).isFalse();
assertThat(mSwitchBar.isChecked()).isFalse();
assertThat(mOnAudioSharingStateChanged).isFalse();
assertThat(mOnAudioSharingServiceConnected).isFalse();
verify(mBtProfileManager).addServiceListener(mController);
}
@Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void bluetoothOff_switchDisabled() { public void bluetoothOff_switchDisabled() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
assertThat(mSwitchBar.isEnabled()).isTrue(); assertThat(mSwitchBar.isEnabled()).isTrue();
mContext.registerReceiver( mContext.registerReceiver(
mController.mReceiver, mController.mReceiver,
@@ -263,11 +310,12 @@ public class AudioSharingSwitchBarControllerTest {
assertThat(mSwitchBar.isChecked()).isFalse(); assertThat(mSwitchBar.isChecked()).isFalse();
assertThat(mOnAudioSharingStateChanged).isTrue(); assertThat(mOnAudioSharingStateChanged).isTrue();
assertThat(mOnAudioSharingServiceConnected).isFalse(); assertThat(mOnAudioSharingServiceConnected).isFalse();
verify(mBtProfileManager, never()).addServiceListener(any());
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onServiceConnected_switchEnabled() { public void onServiceConnected_switchEnabled() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isEnabled(null)).thenReturn(true); when(mBroadcast.isEnabled(null)).thenReturn(true);
mController.onServiceConnected(); mController.onServiceConnected();
shadowOf(Looper.getMainLooper()).idle(); shadowOf(Looper.getMainLooper()).idle();
@@ -280,20 +328,20 @@ public class AudioSharingSwitchBarControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void getAvailabilityStatus_flagOn() { public void getAvailabilityStatus_flagOn() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void getAvailabilityStatus_flagOff() { public void getAvailabilityStatus_flagOff() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStart_flagOff_doNothing() { public void onStart_flagOff_doNothing() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStart(mLifecycleOwner); mController.onStart(mLifecycleOwner);
verify(mContext, never()) verify(mContext, never())
.registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class), anyInt()); .registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class), anyInt());
@@ -307,8 +355,8 @@ public class AudioSharingSwitchBarControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStart_flagOnProfileNotReady_registerProfileCallback() { public void onStart_flagOnProfileNotReady_registerProfileCallback() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isEnabled(null)).thenReturn(false); when(mBroadcast.isEnabled(null)).thenReturn(false);
when(mBroadcast.isProfileReady()).thenReturn(false); when(mBroadcast.isProfileReady()).thenReturn(false);
mController.onStart(mLifecycleOwner); mController.onStart(mLifecycleOwner);
@@ -316,21 +364,21 @@ public class AudioSharingSwitchBarControllerTest {
verify(mContext) verify(mContext)
.registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class), anyInt()); .registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class), anyInt());
verify(mBroadcast, never()) verify(mBroadcast)
.registerServiceCallBack( .registerServiceCallBack(
any(Executor.class), any(BluetoothLeBroadcast.Callback.class)); any(Executor.class), any(BluetoothLeBroadcast.Callback.class));
verify(mAssistant, never()) verify(mAssistant)
.registerServiceCallBack( .registerServiceCallBack(
any(Executor.class), any(BluetoothLeBroadcastAssistant.Callback.class)); any(Executor.class), any(BluetoothLeBroadcastAssistant.Callback.class));
verify(mEventManager, never()).registerCallback(any(BluetoothCallback.class)); verify(mEventManager).registerCallback(any(BluetoothCallback.class));
verify(mBtProfileManager).addServiceListener(mController); verify(mBtProfileManager).addServiceListener(mController);
assertThat(mSwitchBar.isChecked()).isFalse(); assertThat(mSwitchBar.isChecked()).isFalse();
assertThat(mSwitchBar.isEnabled()).isFalse(); assertThat(mSwitchBar.isEnabled()).isFalse();
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStart_flagOn_registerCallback() { public void onStart_flagOn_registerCallback() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isEnabled(null)).thenReturn(true); when(mBroadcast.isEnabled(null)).thenReturn(true);
mController.onStart(mLifecycleOwner); mController.onStart(mLifecycleOwner);
shadowOf(Looper.getMainLooper()).idle(); shadowOf(Looper.getMainLooper()).idle();
@@ -350,8 +398,8 @@ public class AudioSharingSwitchBarControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStart_flagOn_updateSwitch() { public void onStart_flagOn_updateSwitch() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isEnabled(null)).thenReturn(false); when(mBroadcast.isEnabled(null)).thenReturn(false);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of()); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.onStart(mLifecycleOwner); mController.onStart(mLifecycleOwner);
@@ -362,8 +410,8 @@ public class AudioSharingSwitchBarControllerTest {
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOff_doNothing() { public void onStop_flagOff_doNothing() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStop(mLifecycleOwner); mController.onStop(mLifecycleOwner);
verify(mContext, never()).unregisterReceiver(any(BroadcastReceiver.class)); verify(mContext, never()).unregisterReceiver(any(BroadcastReceiver.class));
verify(mBroadcast, never()) verify(mBroadcast, never())
@@ -375,8 +423,8 @@ public class AudioSharingSwitchBarControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOn_notRegistered_doNothing() { public void onStop_flagOn_notRegistered_doNothing() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(false); mController.setCallbacksRegistered(false);
doNothing().when(mContext).unregisterReceiver(any(BroadcastReceiver.class)); doNothing().when(mContext).unregisterReceiver(any(BroadcastReceiver.class));
mController.onStop(mLifecycleOwner); mController.onStop(mLifecycleOwner);
@@ -391,8 +439,8 @@ public class AudioSharingSwitchBarControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOn_registered_unregisterCallback() { public void onStop_flagOn_registered_unregisterCallback() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(true); mController.setCallbacksRegistered(true);
mContext.registerReceiver( mContext.registerReceiver(
mController.mReceiver, mController.mReceiver,
@@ -963,8 +1011,8 @@ public class AudioSharingSwitchBarControllerTest {
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void handleStartAudioSharingFromIntent_flagOff_doNothing() { public void handleStartAudioSharingFromIntent_flagOff_doNothing() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
var unused = setUpFragmentWithStartSharingIntent(); var unused = setUpFragmentWithStartSharingIntent();
mController.onStart(mLifecycleOwner); mController.onStart(mLifecycleOwner);
shadowOf(Looper.getMainLooper()).idle(); shadowOf(Looper.getMainLooper()).idle();
@@ -973,8 +1021,8 @@ public class AudioSharingSwitchBarControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void handleStartAudioSharingFromIntent_profileNotReady_doNothing() { public void handleStartAudioSharingFromIntent_profileNotReady_doNothing() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mAssistant.isProfileReady()).thenReturn(false); when(mAssistant.isProfileReady()).thenReturn(false);
var unused = setUpFragmentWithStartSharingIntent(); var unused = setUpFragmentWithStartSharingIntent();
mController.onServiceConnected(); mController.onServiceConnected();
@@ -984,8 +1032,8 @@ public class AudioSharingSwitchBarControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void handleStartAudioSharingFromIntent_argFalse_doNothing() { public void handleStartAudioSharingFromIntent_argFalse_doNothing() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStart(mLifecycleOwner); mController.onStart(mLifecycleOwner);
shadowOf(Looper.getMainLooper()).idle(); shadowOf(Looper.getMainLooper()).idle();
@@ -993,8 +1041,8 @@ public class AudioSharingSwitchBarControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void handleStartAudioSharingFromIntent_handle() { public void handleStartAudioSharingFromIntent_handle() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBtnView.isEnabled()).thenReturn(true); when(mBtnView.isEnabled()).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice2, mDevice1)); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice2, mDevice1));
when(mBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn(mMetadata); when(mBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn(mMetadata);

View File

@@ -36,6 +36,8 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.os.Looper; import android.os.Looper;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule; import android.platform.test.flag.junit.SetFlagsRule;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
@@ -124,8 +126,50 @@ public class StreamSettingsCategoryControllerTest {
} }
@Test @Test
public void bluetoothOff_updateVisibility() { public void bluetoothOn_profileReady_updateVisibility() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mShadowBluetoothAdapter.setEnabled(false);
mContext.registerReceiver(
mController.mReceiver,
mController.mIntentFilter,
Context.RECEIVER_EXPORTED_UNAUDITED);
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.isVisible()).isFalse();
mShadowBluetoothAdapter.setEnabled(true);
Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_ON);
mContext.sendBroadcast(intent);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.isVisible()).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void bluetoothOn_profileNotReady_registerProfileListener() {
mShadowBluetoothAdapter.setEnabled(false);
mContext.registerReceiver(
mController.mReceiver,
mController.mIntentFilter,
Context.RECEIVER_EXPORTED_UNAUDITED);
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.isVisible()).isFalse();
when(mBroadcast.isProfileReady()).thenReturn(false);
mShadowBluetoothAdapter.setEnabled(true);
Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_ON);
mContext.sendBroadcast(intent);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.isVisible()).isFalse();
verify(mBtProfileManager).addServiceListener(mController);
}
@Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void bluetoothOff_updateVisibility() {
mContext.registerReceiver( mContext.registerReceiver(
mController.mReceiver, mController.mReceiver,
mController.mIntentFilter, mController.mIntentFilter,
@@ -143,20 +187,20 @@ public class StreamSettingsCategoryControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void getAvailabilityStatus_flagOn() { public void getAvailabilityStatus_flagOn() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void getAvailabilityStatus_flagOff() { public void getAvailabilityStatus_flagOff() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStart_flagOff_doNothing() { public void onStart_flagOff_doNothing() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStart(mLifecycleOwner); mController.onStart(mLifecycleOwner);
verify(mContext, times(0)) verify(mContext, times(0))
.registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class), anyInt()); .registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class), anyInt());
@@ -164,8 +208,8 @@ public class StreamSettingsCategoryControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStart_flagOn_registerCallback() { public void onStart_flagOn_registerCallback() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStart(mLifecycleOwner); mController.onStart(mLifecycleOwner);
verify(mContext) verify(mContext)
.registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class), anyInt()); .registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class), anyInt());
@@ -173,8 +217,8 @@ public class StreamSettingsCategoryControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStart_flagOnProfileNotReady_registerProfileManagerCallback() { public void onStart_flagOnProfileNotReady_registerProfileManagerCallback() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isProfileReady()).thenReturn(false); when(mBroadcast.isProfileReady()).thenReturn(false);
mController.onStart(mLifecycleOwner); mController.onStart(mLifecycleOwner);
verify(mContext) verify(mContext)
@@ -183,16 +227,16 @@ public class StreamSettingsCategoryControllerTest {
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOff_doNothing() { public void onStop_flagOff_doNothing() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStop(mLifecycleOwner); mController.onStop(mLifecycleOwner);
verify(mContext, times(0)).unregisterReceiver(any(BroadcastReceiver.class)); verify(mContext, times(0)).unregisterReceiver(any(BroadcastReceiver.class));
verify(mBtProfileManager, times(0)).removeServiceListener(mController); verify(mBtProfileManager, times(0)).removeServiceListener(mController);
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOn_unregisterCallback() { public void onStop_flagOn_unregisterCallback() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
doNothing().when(mContext).unregisterReceiver(any(BroadcastReceiver.class)); doNothing().when(mContext).unregisterReceiver(any(BroadcastReceiver.class));
mController.onStop(mLifecycleOwner); mController.onStop(mLifecycleOwner);
verify(mContext).unregisterReceiver(any(BroadcastReceiver.class)); verify(mContext).unregisterReceiver(any(BroadcastReceiver.class));
@@ -200,8 +244,8 @@ public class StreamSettingsCategoryControllerTest {
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void displayPreference_flagOff_preferenceInvisible() { public void displayPreference_flagOff_preferenceInvisible() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mPreference.setVisible(true); mPreference.setVisible(true);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle(); shadowOf(Looper.getMainLooper()).idle();
@@ -209,8 +253,8 @@ public class StreamSettingsCategoryControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void displayPreference_BluetoothOff_preferenceInvisible() { public void displayPreference_BluetoothOff_preferenceInvisible() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mPreference.setVisible(true); mPreference.setVisible(true);
mShadowBluetoothAdapter.setEnabled(false); mShadowBluetoothAdapter.setEnabled(false);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -219,8 +263,8 @@ public class StreamSettingsCategoryControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void displayPreference_BluetoothOnProfileNotReady_preferenceInvisible() { public void displayPreference_BluetoothOnProfileNotReady_preferenceInvisible() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mPreference.setVisible(true); mPreference.setVisible(true);
when(mBroadcast.isProfileReady()).thenReturn(false); when(mBroadcast.isProfileReady()).thenReturn(false);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -229,8 +273,8 @@ public class StreamSettingsCategoryControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void displayPreference_BluetoothOnProfileReady_preferenceVisible() { public void displayPreference_BluetoothOnProfileReady_preferenceVisible() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mPreference.setVisible(false); mPreference.setVisible(false);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle(); shadowOf(Looper.getMainLooper()).idle();
@@ -238,8 +282,8 @@ public class StreamSettingsCategoryControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onServiceConnected_updateVisibility() { public void onServiceConnected_updateVisibility() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isProfileReady()).thenReturn(false); when(mBroadcast.isProfileReady()).thenReturn(false);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle(); shadowOf(Looper.getMainLooper()).idle();