Support generic qr code scanners.
Test: atest Bug: 308368124 Flag: com.android.settingslib.flags.enable_le_audio_sharing Change-Id: I8dee57903c42d00351e28a891cee917e078839ac
This commit is contained in:
@@ -5456,6 +5456,12 @@
|
|||||||
<action android:name="android.settings.AUDIO_STREAM_DIALOG" />
|
<action android:name="android.settings.AUDIO_STREAM_DIALOG" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</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"
|
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||||
android:value="com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamConfirmDialog" />
|
android:value="com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamConfirmDialog" />
|
||||||
</activity>
|
</activity>
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
||||||
|
|
||||||
import static com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamsDashboardFragment.KEY_BROADCAST_METADATA;
|
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.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
@@ -48,9 +49,13 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment {
|
|||||||
static final int DEFAULT_DEVICE_NAME = R.string.audio_streams_dialog_default_device;
|
static final int DEFAULT_DEVICE_NAME = R.string.audio_streams_dialog_default_device;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@VisibleForTesting @Nullable Activity mActivity;
|
@VisibleForTesting
|
||||||
@Nullable private BluetoothLeBroadcastMetadata mBroadcastMetadata;
|
@Nullable
|
||||||
@Nullable private BluetoothDevice mConnectedDevice;
|
Activity mActivity;
|
||||||
|
@Nullable
|
||||||
|
private BluetoothLeBroadcastMetadata mBroadcastMetadata;
|
||||||
|
@Nullable
|
||||||
|
private BluetoothDevice mConnectedDevice;
|
||||||
private int mAudioStreamConfirmDialogId = SettingsEnums.PAGE_UNKNOWN;
|
private int mAudioStreamConfirmDialogId = SettingsEnums.PAGE_UNKNOWN;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -206,12 +211,23 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable BluetoothLeBroadcastMetadata getMetadata(Intent intent) {
|
private @Nullable BluetoothLeBroadcastMetadata getMetadata(Intent intent) {
|
||||||
|
// Get the metadata from the intent extras
|
||||||
String metadata = intent.getStringExtra(KEY_BROADCAST_METADATA);
|
String metadata = intent.getStringExtra(KEY_BROADCAST_METADATA);
|
||||||
if (metadata == null || metadata.isEmpty()) {
|
if (metadata != null && !metadata.isEmpty()) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata(metadata);
|
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) {
|
private int getDialogId(boolean hasMetadata, boolean hasConnectedDevice) {
|
||||||
if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) {
|
if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) {
|
||||||
|
@@ -36,6 +36,7 @@ import android.bluetooth.BluetoothDevice;
|
|||||||
import android.bluetooth.BluetoothStatusCodes;
|
import android.bluetooth.BluetoothStatusCodes;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@@ -82,6 +83,9 @@ public class AudioStreamConfirmDialogTest {
|
|||||||
private static final String VALID_METADATA =
|
private static final String VALID_METADATA =
|
||||||
"BLUETOOTH:UUID:184F;BN:VGVzdA==;AT:1;AD:00A1A1A1A1A1;BI:1E240;BC:VGVzdENvZGU=;"
|
"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=;;";
|
+ "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 static final String DEVICE_NAME = "device_name";
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
@Mock private LocalBluetoothManager mLocalBluetoothManager;
|
@Mock private LocalBluetoothManager mLocalBluetoothManager;
|
||||||
@@ -371,4 +375,63 @@ public class AudioStreamConfirmDialogTest {
|
|||||||
assertThat(dialog.isShowing()).isFalse();
|
assertThat(dialog.isShowing()).isFalse();
|
||||||
verify(mDialogFragment.mActivity, times(2)).finish();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user