[Audiosharing] Start join handler activity from receiver

Test: atest
Flag: com.android.settingslib.flags.promote_audio_sharing_for_second_auto_connected_lea_device
Bug: 395786392
Change-Id: I7363ba5d7de9049f85dad4ce01467a93af4cb52e
This commit is contained in:
Yiyi Shen
2025-02-28 16:20:17 +08:00
parent 0abe3f4e17
commit ab466747e7
2 changed files with 15 additions and 3 deletions

View File

@@ -16,6 +16,8 @@
package com.android.settings.connecteddevice.audiosharing;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast.EXTRA_BLUETOOTH_DEVICE;
import android.Manifest;
@@ -143,8 +145,12 @@ public class AudioSharingReceiver extends BroadcastReceiver {
return;
}
if (isAppInForeground(context)) {
// TODO: show dialog
Log.d(TAG, "App in foreground, show share audio dialog");
Intent dialogIntent = new Intent();
dialogIntent.setClass(context, AudioSharingJoinHandlerActivity.class);
dialogIntent.addFlags(FLAG_ACTIVITY_NEW_TASK);
dialogIntent.putExtra(EXTRA_BLUETOOTH_DEVICE, device);
context.startActivity(dialogIntent);
} else {
Log.d(TAG, "App not in foreground, show share audio notification");
LocalBluetoothManager manager = Utils.getLocalBtManager(context);

View File

@@ -74,6 +74,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@@ -370,7 +371,12 @@ public class AudioSharingReceiverTest {
verify(mNm, never()).notify(
eq(com.android.settings.R.string.share_audio_notification_title),
any(Notification.class));
// TODO: verify show dialog once impl complete
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mContext).startActivity(intentCaptor.capture());
assertThat(intentCaptor.getValue().getComponent().getClassName()).isEqualTo(
AudioSharingJoinHandlerActivity.class.getName());
assertThat(intentCaptor.getValue().getParcelableExtra(EXTRA_BLUETOOTH_DEVICE,
BluetoothDevice.class)).isEqualTo(mDevice);
}
@Test
@@ -513,7 +519,7 @@ public class AudioSharingReceiverTest {
AudioSharingReceiver audioSharingReceiver = getAudioSharingReceiver(intent);
audioSharingReceiver.onReceive(mContext, intent);
// TODO: verify no dialog once impl complete
verify(mContext, never()).startActivity(any());
verify(mNm).notify(eq(com.android.settings.R.string.share_audio_notification_title),
any(Notification.class));
}