Loading AndroidManifest.xml +6 −0 Original line number Diff line number Diff line Loading @@ -5456,6 +5456,12 @@ <action android:name="android.settings.AUDIO_STREAM_DIALOG" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="bluetooth" /> <data android:scheme="BLUETOOTH" /> </intent-filter> <meta-data android:name="com.android.settings.FRAGMENT_CLASS" android:value="com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamConfirmDialog" /> </activity> Loading src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialog.java +22 −6 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settings.connecteddevice.audiosharing.audiostreams; import static com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamsDashboardFragment.KEY_BROADCAST_METADATA; import static com.android.settingslib.bluetooth.BluetoothBroadcastUtils.SCHEME_BT_BROADCAST_METADATA; import android.app.Activity; import android.app.Dialog; Loading Loading @@ -48,9 +49,13 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment { static final int DEFAULT_DEVICE_NAME = R.string.audio_streams_dialog_default_device; private Context mContext; @VisibleForTesting @Nullable Activity mActivity; @Nullable private BluetoothLeBroadcastMetadata mBroadcastMetadata; @Nullable private BluetoothDevice mConnectedDevice; @VisibleForTesting @Nullable Activity mActivity; @Nullable private BluetoothLeBroadcastMetadata mBroadcastMetadata; @Nullable private BluetoothDevice mConnectedDevice; private int mAudioStreamConfirmDialogId = SettingsEnums.PAGE_UNKNOWN; @Override Loading Loading @@ -206,12 +211,23 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment { } private @Nullable BluetoothLeBroadcastMetadata getMetadata(Intent intent) { // Get the metadata from the intent extras String metadata = intent.getStringExtra(KEY_BROADCAST_METADATA); if (metadata == null || metadata.isEmpty()) { return null; } if (metadata != null && !metadata.isEmpty()) { return BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata(metadata); } // Retrieve the generic data string from the intent String genericData = intent.getDataString(); if (genericData != null && !genericData.isEmpty()) { // Normalize the prefix by replacing lowercase "bluetooth" with uppercase "BLUETOOTH" genericData = genericData.replaceFirst("bluetooth", "BLUETOOTH"); if (genericData.startsWith(SCHEME_BT_BROADCAST_METADATA)) { return BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata( genericData); } } return null; } private int getDialogId(boolean hasMetadata, boolean hasConnectedDevice) { if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) { Loading tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialogTest.java +63 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothStatusCodes; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.platform.test.flag.junit.SetFlagsRule; import android.view.View; import android.widget.Button; Loading Loading @@ -82,6 +83,9 @@ public class AudioStreamConfirmDialogTest { private static final String VALID_METADATA = "BLUETOOTH:UUID:184F;BN:VGVzdA==;AT:1;AD:00A1A1A1A1A1;BI:1E240;BC:VGVzdENvZGU=;" + "MD:BgNwVGVzdA==;AS:1;PI:A0;NS:1;BS:3;NB:2;SM:BQNUZXN0BARlbmc=;;"; private static final String VALID_METADATA_LOWERCASE = "bluetooth:UUID:184F;BN:VGVzdA==;AT:1;AD:00A1A1A1A1A1;BI:1E240;BC:VGVzdENvZGU=;" + "MD:BgNwVGVzdA==;AS:1;PI:A0;NS:1;BS:3;NB:2;SM:BQNUZXN0BARlbmc=;;"; private static final String DEVICE_NAME = "device_name"; private final Context mContext = ApplicationProvider.getApplicationContext(); @Mock private LocalBluetoothManager mLocalBluetoothManager; Loading Loading @@ -371,4 +375,63 @@ public class AudioStreamConfirmDialogTest { assertThat(dialog.isShowing()).isFalse(); verify(mDialogFragment.mActivity, times(2)).finish(); } @Test public void showDialog_getDataStringFromIntent_confirmListen() { List<BluetoothDevice> devices = new ArrayList<>(); devices.add(mBluetoothDevice); when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mBluetoothDevice.getAlias()).thenReturn(""); Intent intent = new Intent(); intent.setData(Uri.parse(VALID_METADATA_LOWERCASE)); FragmentController.of(mDialogFragment, intent) .create(/* containerViewId= */ 0, /* bundle= */ null) .start() .resume() .visible() .get(); shadowMainLooper().idle(); assertThat(mDialogFragment.getMetricsCategory()) .isEqualTo(DIALOG_AUDIO_STREAM_CONFIRM_LISTEN); assertThat(mDialogFragment.mActivity).isNotNull(); mDialogFragment.mActivity = spy(mDialogFragment.mActivity); Dialog dialog = mDialogFragment.getDialog(); assertThat(dialog).isNotNull(); assertThat(dialog.isShowing()).isTrue(); TextView title = dialog.findViewById(R.id.dialog_title); assertThat(title).isNotNull(); assertThat(title.getText()) .isEqualTo( mContext.getString(R.string.audio_streams_dialog_listen_to_audio_stream)); TextView subtitle1 = dialog.findViewById(R.id.dialog_subtitle); assertThat(subtitle1).isNotNull(); assertThat(subtitle1.getVisibility()).isEqualTo(View.VISIBLE); TextView subtitle2 = dialog.findViewById(R.id.dialog_subtitle_2); assertThat(subtitle2).isNotNull(); var defaultName = mContext.getString(DEFAULT_DEVICE_NAME); assertThat(subtitle2.getText()) .isEqualTo( mContext.getString( R.string.audio_streams_dialog_control_volume, defaultName)); View leftButton = dialog.findViewById(R.id.left_button); assertThat(leftButton).isNotNull(); assertThat(leftButton.getVisibility()).isEqualTo(View.VISIBLE); assertThat(leftButton.hasOnClickListeners()).isTrue(); leftButton.callOnClick(); assertThat(dialog.isShowing()).isFalse(); Button rightButton = dialog.findViewById(R.id.right_button); assertThat(rightButton).isNotNull(); assertThat(rightButton.getText()) .isEqualTo(mContext.getString(R.string.audio_streams_dialog_listen)); assertThat(rightButton.hasOnClickListeners()).isTrue(); rightButton.callOnClick(); assertThat(dialog.isShowing()).isFalse(); verify(mDialogFragment.mActivity, times(2)).finish(); } } Loading
AndroidManifest.xml +6 −0 Original line number Diff line number Diff line Loading @@ -5456,6 +5456,12 @@ <action android:name="android.settings.AUDIO_STREAM_DIALOG" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="bluetooth" /> <data android:scheme="BLUETOOTH" /> </intent-filter> <meta-data android:name="com.android.settings.FRAGMENT_CLASS" android:value="com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamConfirmDialog" /> </activity> Loading
src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialog.java +22 −6 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settings.connecteddevice.audiosharing.audiostreams; import static com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamsDashboardFragment.KEY_BROADCAST_METADATA; import static com.android.settingslib.bluetooth.BluetoothBroadcastUtils.SCHEME_BT_BROADCAST_METADATA; import android.app.Activity; import android.app.Dialog; Loading Loading @@ -48,9 +49,13 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment { static final int DEFAULT_DEVICE_NAME = R.string.audio_streams_dialog_default_device; private Context mContext; @VisibleForTesting @Nullable Activity mActivity; @Nullable private BluetoothLeBroadcastMetadata mBroadcastMetadata; @Nullable private BluetoothDevice mConnectedDevice; @VisibleForTesting @Nullable Activity mActivity; @Nullable private BluetoothLeBroadcastMetadata mBroadcastMetadata; @Nullable private BluetoothDevice mConnectedDevice; private int mAudioStreamConfirmDialogId = SettingsEnums.PAGE_UNKNOWN; @Override Loading Loading @@ -206,12 +211,23 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment { } private @Nullable BluetoothLeBroadcastMetadata getMetadata(Intent intent) { // Get the metadata from the intent extras String metadata = intent.getStringExtra(KEY_BROADCAST_METADATA); if (metadata == null || metadata.isEmpty()) { return null; } if (metadata != null && !metadata.isEmpty()) { return BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata(metadata); } // Retrieve the generic data string from the intent String genericData = intent.getDataString(); if (genericData != null && !genericData.isEmpty()) { // Normalize the prefix by replacing lowercase "bluetooth" with uppercase "BLUETOOTH" genericData = genericData.replaceFirst("bluetooth", "BLUETOOTH"); if (genericData.startsWith(SCHEME_BT_BROADCAST_METADATA)) { return BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata( genericData); } } return null; } private int getDialogId(boolean hasMetadata, boolean hasConnectedDevice) { if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) { Loading
tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialogTest.java +63 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothStatusCodes; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.platform.test.flag.junit.SetFlagsRule; import android.view.View; import android.widget.Button; Loading Loading @@ -82,6 +83,9 @@ public class AudioStreamConfirmDialogTest { private static final String VALID_METADATA = "BLUETOOTH:UUID:184F;BN:VGVzdA==;AT:1;AD:00A1A1A1A1A1;BI:1E240;BC:VGVzdENvZGU=;" + "MD:BgNwVGVzdA==;AS:1;PI:A0;NS:1;BS:3;NB:2;SM:BQNUZXN0BARlbmc=;;"; private static final String VALID_METADATA_LOWERCASE = "bluetooth:UUID:184F;BN:VGVzdA==;AT:1;AD:00A1A1A1A1A1;BI:1E240;BC:VGVzdENvZGU=;" + "MD:BgNwVGVzdA==;AS:1;PI:A0;NS:1;BS:3;NB:2;SM:BQNUZXN0BARlbmc=;;"; private static final String DEVICE_NAME = "device_name"; private final Context mContext = ApplicationProvider.getApplicationContext(); @Mock private LocalBluetoothManager mLocalBluetoothManager; Loading Loading @@ -371,4 +375,63 @@ public class AudioStreamConfirmDialogTest { assertThat(dialog.isShowing()).isFalse(); verify(mDialogFragment.mActivity, times(2)).finish(); } @Test public void showDialog_getDataStringFromIntent_confirmListen() { List<BluetoothDevice> devices = new ArrayList<>(); devices.add(mBluetoothDevice); when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mBluetoothDevice.getAlias()).thenReturn(""); Intent intent = new Intent(); intent.setData(Uri.parse(VALID_METADATA_LOWERCASE)); FragmentController.of(mDialogFragment, intent) .create(/* containerViewId= */ 0, /* bundle= */ null) .start() .resume() .visible() .get(); shadowMainLooper().idle(); assertThat(mDialogFragment.getMetricsCategory()) .isEqualTo(DIALOG_AUDIO_STREAM_CONFIRM_LISTEN); assertThat(mDialogFragment.mActivity).isNotNull(); mDialogFragment.mActivity = spy(mDialogFragment.mActivity); Dialog dialog = mDialogFragment.getDialog(); assertThat(dialog).isNotNull(); assertThat(dialog.isShowing()).isTrue(); TextView title = dialog.findViewById(R.id.dialog_title); assertThat(title).isNotNull(); assertThat(title.getText()) .isEqualTo( mContext.getString(R.string.audio_streams_dialog_listen_to_audio_stream)); TextView subtitle1 = dialog.findViewById(R.id.dialog_subtitle); assertThat(subtitle1).isNotNull(); assertThat(subtitle1.getVisibility()).isEqualTo(View.VISIBLE); TextView subtitle2 = dialog.findViewById(R.id.dialog_subtitle_2); assertThat(subtitle2).isNotNull(); var defaultName = mContext.getString(DEFAULT_DEVICE_NAME); assertThat(subtitle2.getText()) .isEqualTo( mContext.getString( R.string.audio_streams_dialog_control_volume, defaultName)); View leftButton = dialog.findViewById(R.id.left_button); assertThat(leftButton).isNotNull(); assertThat(leftButton.getVisibility()).isEqualTo(View.VISIBLE); assertThat(leftButton.hasOnClickListeners()).isTrue(); leftButton.callOnClick(); assertThat(dialog.isShowing()).isFalse(); Button rightButton = dialog.findViewById(R.id.right_button); assertThat(rightButton).isNotNull(); assertThat(rightButton.getText()) .isEqualTo(mContext.getString(R.string.audio_streams_dialog_listen)); assertThat(rightButton.hasOnClickListeners()).isTrue(); rightButton.callOnClick(); assertThat(dialog.isShowing()).isFalse(); verify(mDialogFragment.mActivity, times(2)).finish(); } }