Loading src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialog.java +6 −12 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import static com.android.settingslib.bluetooth.BluetoothBroadcastUtils.SCHEME_B import android.app.Activity; import android.app.Dialog; import android.app.settings.SettingsEnums; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothLeBroadcastMetadata; import android.content.Context; import android.content.Intent; Loading @@ -42,7 +41,7 @@ import com.android.settings.core.SubSettingLauncher; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settingslib.bluetooth.BluetoothLeBroadcastMetadataExt; import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.utils.ThreadUtils; public class AudioStreamConfirmDialog extends InstrumentedDialogFragment { Loading @@ -58,7 +57,7 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment { @Nullable private BluetoothLeBroadcastMetadata mBroadcastMetadata; @Nullable private BluetoothDevice mConnectedDevice; private CachedBluetoothDevice mConnectedDevice; private int mAudioStreamConfirmDialogId = SettingsEnums.PAGE_UNKNOWN; @Override Loading Loading @@ -281,23 +280,18 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment { } @Nullable private BluetoothDevice getConnectedDevice() { private CachedBluetoothDevice getConnectedDevice() { var localBluetoothManager = Utils.getLocalBluetoothManager(getActivity()); if (localBluetoothManager == null) { return null; } LocalBluetoothLeBroadcastAssistant assistant = localBluetoothManager.getProfileManager().getLeAudioBroadcastAssistantProfile(); if (assistant == null) { return null; } var devices = assistant.getAllConnectedDevices(); return devices.isEmpty() ? null : devices.get(0); return AudioStreamsHelper.getCachedBluetoothDeviceInSharingOrLeConnected( localBluetoothManager).orElse(null); } private String getConnectedDeviceName() { if (mConnectedDevice != null) { String alias = mConnectedDevice.getAlias(); String alias = mConnectedDevice.getName(); return TextUtils.isEmpty(alias) ? getString(DEFAULT_DEVICE_NAME) : alias; } Log.w(TAG, "getConnectedDeviceName : no connected device!"); Loading tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialogTest.java +18 −25 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ import static org.robolectric.shadows.ShadowLooper.shadowMainLooper; import android.app.Dialog; import android.app.settings.SettingsEnums; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothStatusCodes; import android.content.ComponentName; import android.content.Context; Loading @@ -50,6 +49,7 @@ import com.android.settings.R; import com.android.settings.connecteddevice.audiosharing.audiostreams.testshadows.ShadowAudioStreamsHelper; import com.android.settings.testutils.shadow.ShadowBluetoothAdapter; import com.android.settings.testutils.shadow.ShadowBluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant; import com.android.settingslib.bluetooth.LocalBluetoothManager; Loading @@ -70,9 +70,6 @@ import org.robolectric.annotation.Config; import org.robolectric.shadow.api.Shadow; import org.robolectric.shadows.androidx.fragment.FragmentController; import java.util.ArrayList; import java.util.List; @RunWith(RobolectricTestRunner.class) @Config( shadows = { Loading Loading @@ -104,7 +101,7 @@ public class AudioStreamConfirmDialogTest { @Mock private VolumeControlProfile mVolumeControl; @Mock private BluetoothDevice mBluetoothDevice; private CachedBluetoothDevice mCachedBluetoothDevice; private AudioStreamConfirmDialog mDialogFragment; @Before Loading Loading @@ -133,6 +130,7 @@ public class AudioStreamConfirmDialogTest { @After public void tearDown() { ShadowBluetoothUtils.reset(); ShadowAudioStreamsHelper.reset(); mDialogFragment.dismiss(); } Loading Loading @@ -231,10 +229,9 @@ public class AudioStreamConfirmDialogTest { @Test public void showDialog_noMetadata() { List<BluetoothDevice> devices = new ArrayList<>(); devices.add(mBluetoothDevice); when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mBluetoothDevice.getAlias()).thenReturn(DEVICE_NAME); ShadowAudioStreamsHelper.setCachedBluetoothDeviceInSharingOrLeConnected( mCachedBluetoothDevice); when(mCachedBluetoothDevice.getName()).thenReturn(DEVICE_NAME); FragmentController.setupFragment( mDialogFragment, Loading Loading @@ -279,10 +276,9 @@ public class AudioStreamConfirmDialogTest { @Test public void showDialog_invalidMetadata() { List<BluetoothDevice> devices = new ArrayList<>(); devices.add(mBluetoothDevice); when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mBluetoothDevice.getAlias()).thenReturn(DEVICE_NAME); ShadowAudioStreamsHelper.setCachedBluetoothDeviceInSharingOrLeConnected( mCachedBluetoothDevice); when(mCachedBluetoothDevice.getName()).thenReturn(DEVICE_NAME); Intent intent = new Intent(); intent.putExtra(KEY_BROADCAST_METADATA, "invalid"); Loading Loading @@ -330,10 +326,9 @@ public class AudioStreamConfirmDialogTest { @Test public void showDialog_confirmListen() { List<BluetoothDevice> devices = new ArrayList<>(); devices.add(mBluetoothDevice); when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mBluetoothDevice.getAlias()).thenReturn(""); ShadowAudioStreamsHelper.setCachedBluetoothDeviceInSharingOrLeConnected( mCachedBluetoothDevice); when(mCachedBluetoothDevice.getName()).thenReturn(""); Intent intent = new Intent(); intent.putExtra(KEY_BROADCAST_METADATA, VALID_METADATA); Loading Loading @@ -389,10 +384,9 @@ public class AudioStreamConfirmDialogTest { @Test public void showDialog_turnOffTalkback() { List<BluetoothDevice> devices = new ArrayList<>(); devices.add(mBluetoothDevice); when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mBluetoothDevice.getAlias()).thenReturn(""); ShadowAudioStreamsHelper.setCachedBluetoothDeviceInSharingOrLeConnected( mCachedBluetoothDevice); when(mCachedBluetoothDevice.getName()).thenReturn(""); ShadowAudioStreamsHelper.setEnabledScreenReaderService(new ComponentName("pkg", "class")); Intent intent = new Intent(); Loading Loading @@ -449,10 +443,9 @@ public class AudioStreamConfirmDialogTest { @Test public void showDialog_getDataStringFromIntent_confirmListen() { List<BluetoothDevice> devices = new ArrayList<>(); devices.add(mBluetoothDevice); when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mBluetoothDevice.getAlias()).thenReturn(""); ShadowAudioStreamsHelper.setCachedBluetoothDeviceInSharingOrLeConnected( mCachedBluetoothDevice); when(mCachedBluetoothDevice.getName()).thenReturn(""); Intent intent = new Intent(); intent.setData(Uri.parse(VALID_METADATA_LOWERCASE)); Loading Loading
src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialog.java +6 −12 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import static com.android.settingslib.bluetooth.BluetoothBroadcastUtils.SCHEME_B import android.app.Activity; import android.app.Dialog; import android.app.settings.SettingsEnums; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothLeBroadcastMetadata; import android.content.Context; import android.content.Intent; Loading @@ -42,7 +41,7 @@ import com.android.settings.core.SubSettingLauncher; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settingslib.bluetooth.BluetoothLeBroadcastMetadataExt; import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.utils.ThreadUtils; public class AudioStreamConfirmDialog extends InstrumentedDialogFragment { Loading @@ -58,7 +57,7 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment { @Nullable private BluetoothLeBroadcastMetadata mBroadcastMetadata; @Nullable private BluetoothDevice mConnectedDevice; private CachedBluetoothDevice mConnectedDevice; private int mAudioStreamConfirmDialogId = SettingsEnums.PAGE_UNKNOWN; @Override Loading Loading @@ -281,23 +280,18 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment { } @Nullable private BluetoothDevice getConnectedDevice() { private CachedBluetoothDevice getConnectedDevice() { var localBluetoothManager = Utils.getLocalBluetoothManager(getActivity()); if (localBluetoothManager == null) { return null; } LocalBluetoothLeBroadcastAssistant assistant = localBluetoothManager.getProfileManager().getLeAudioBroadcastAssistantProfile(); if (assistant == null) { return null; } var devices = assistant.getAllConnectedDevices(); return devices.isEmpty() ? null : devices.get(0); return AudioStreamsHelper.getCachedBluetoothDeviceInSharingOrLeConnected( localBluetoothManager).orElse(null); } private String getConnectedDeviceName() { if (mConnectedDevice != null) { String alias = mConnectedDevice.getAlias(); String alias = mConnectedDevice.getName(); return TextUtils.isEmpty(alias) ? getString(DEFAULT_DEVICE_NAME) : alias; } Log.w(TAG, "getConnectedDeviceName : no connected device!"); Loading
tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialogTest.java +18 −25 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ import static org.robolectric.shadows.ShadowLooper.shadowMainLooper; import android.app.Dialog; import android.app.settings.SettingsEnums; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothStatusCodes; import android.content.ComponentName; import android.content.Context; Loading @@ -50,6 +49,7 @@ import com.android.settings.R; import com.android.settings.connecteddevice.audiosharing.audiostreams.testshadows.ShadowAudioStreamsHelper; import com.android.settings.testutils.shadow.ShadowBluetoothAdapter; import com.android.settings.testutils.shadow.ShadowBluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant; import com.android.settingslib.bluetooth.LocalBluetoothManager; Loading @@ -70,9 +70,6 @@ import org.robolectric.annotation.Config; import org.robolectric.shadow.api.Shadow; import org.robolectric.shadows.androidx.fragment.FragmentController; import java.util.ArrayList; import java.util.List; @RunWith(RobolectricTestRunner.class) @Config( shadows = { Loading Loading @@ -104,7 +101,7 @@ public class AudioStreamConfirmDialogTest { @Mock private VolumeControlProfile mVolumeControl; @Mock private BluetoothDevice mBluetoothDevice; private CachedBluetoothDevice mCachedBluetoothDevice; private AudioStreamConfirmDialog mDialogFragment; @Before Loading Loading @@ -133,6 +130,7 @@ public class AudioStreamConfirmDialogTest { @After public void tearDown() { ShadowBluetoothUtils.reset(); ShadowAudioStreamsHelper.reset(); mDialogFragment.dismiss(); } Loading Loading @@ -231,10 +229,9 @@ public class AudioStreamConfirmDialogTest { @Test public void showDialog_noMetadata() { List<BluetoothDevice> devices = new ArrayList<>(); devices.add(mBluetoothDevice); when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mBluetoothDevice.getAlias()).thenReturn(DEVICE_NAME); ShadowAudioStreamsHelper.setCachedBluetoothDeviceInSharingOrLeConnected( mCachedBluetoothDevice); when(mCachedBluetoothDevice.getName()).thenReturn(DEVICE_NAME); FragmentController.setupFragment( mDialogFragment, Loading Loading @@ -279,10 +276,9 @@ public class AudioStreamConfirmDialogTest { @Test public void showDialog_invalidMetadata() { List<BluetoothDevice> devices = new ArrayList<>(); devices.add(mBluetoothDevice); when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mBluetoothDevice.getAlias()).thenReturn(DEVICE_NAME); ShadowAudioStreamsHelper.setCachedBluetoothDeviceInSharingOrLeConnected( mCachedBluetoothDevice); when(mCachedBluetoothDevice.getName()).thenReturn(DEVICE_NAME); Intent intent = new Intent(); intent.putExtra(KEY_BROADCAST_METADATA, "invalid"); Loading Loading @@ -330,10 +326,9 @@ public class AudioStreamConfirmDialogTest { @Test public void showDialog_confirmListen() { List<BluetoothDevice> devices = new ArrayList<>(); devices.add(mBluetoothDevice); when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mBluetoothDevice.getAlias()).thenReturn(""); ShadowAudioStreamsHelper.setCachedBluetoothDeviceInSharingOrLeConnected( mCachedBluetoothDevice); when(mCachedBluetoothDevice.getName()).thenReturn(""); Intent intent = new Intent(); intent.putExtra(KEY_BROADCAST_METADATA, VALID_METADATA); Loading Loading @@ -389,10 +384,9 @@ public class AudioStreamConfirmDialogTest { @Test public void showDialog_turnOffTalkback() { List<BluetoothDevice> devices = new ArrayList<>(); devices.add(mBluetoothDevice); when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mBluetoothDevice.getAlias()).thenReturn(""); ShadowAudioStreamsHelper.setCachedBluetoothDeviceInSharingOrLeConnected( mCachedBluetoothDevice); when(mCachedBluetoothDevice.getName()).thenReturn(""); ShadowAudioStreamsHelper.setEnabledScreenReaderService(new ComponentName("pkg", "class")); Intent intent = new Intent(); Loading Loading @@ -449,10 +443,9 @@ public class AudioStreamConfirmDialogTest { @Test public void showDialog_getDataStringFromIntent_confirmListen() { List<BluetoothDevice> devices = new ArrayList<>(); devices.add(mBluetoothDevice); when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mBluetoothDevice.getAlias()).thenReturn(""); ShadowAudioStreamsHelper.setCachedBluetoothDeviceInSharingOrLeConnected( mCachedBluetoothDevice); when(mCachedBluetoothDevice.getName()).thenReturn(""); Intent intent = new Intent(); intent.setData(Uri.parse(VALID_METADATA_LOWERCASE)); Loading