[Audiosharing] Refresh the dialog handling onNewIntent
If an instance of the activity already exists at the top of the current task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity. So we need manually trigger the handling logic in onNewIntent to refresh the dialogs. Test: atest Flag: com.android.settingslib.flags.promote_audio_sharing_for_second_auto_connected_lea_device Bug: 395786392 Change-Id: Iccb0ef649ee60cb97f7557943760f854d31ccc80
This commit is contained in:
@@ -18,20 +18,27 @@ package com.android.settings.connecteddevice.audiosharing;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothStatusCodes;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.platform.test.annotations.DisableFlags;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settingslib.flags.Flags;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -66,9 +73,9 @@ public class AudioSharingJoinHandlerActivityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE)
|
||||
@DisableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void onCreate_flagOff_finish() {
|
||||
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
mActivity.onCreate(new Bundle());
|
||||
verify(mActivity).finish();
|
||||
}
|
||||
@@ -91,4 +98,26 @@ public class AudioSharingJoinHandlerActivityTest {
|
||||
public void isValidFragment_returnsFalse() {
|
||||
assertThat(mActivity.isValidFragment("")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void onNewIntent_flagOff_finish() {
|
||||
Intent intent = new Intent();
|
||||
mActivity.onNewIntent(intent);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void onNewIntent_flagOn_handleDeviceConnectedFromIntent() {
|
||||
FragmentManager fragmentManager = mock(FragmentManager.class);
|
||||
AudioSharingJoinHandlerDashboardFragment fragment = mock(
|
||||
AudioSharingJoinHandlerDashboardFragment.class);
|
||||
when(mActivity.getSupportFragmentManager()).thenReturn(fragmentManager);
|
||||
when(fragmentManager.getFragments()).thenReturn(ImmutableList.of(fragment));
|
||||
Intent intent = new Intent();
|
||||
mActivity.onNewIntent(intent);
|
||||
verify(fragment).handleDeviceConnectedFromIntent(intent);
|
||||
}
|
||||
}
|
||||
|
@@ -18,15 +18,26 @@ package com.android.settings.connecteddevice.audiosharing;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AudioSharingJoinHandlerDashboardFragmentTest {
|
||||
@Rule
|
||||
public final MockitoRule mocks = MockitoJUnit.rule();
|
||||
|
||||
private AudioSharingJoinHandlerDashboardFragment mFragment;
|
||||
|
||||
@Before
|
||||
@@ -49,4 +60,14 @@ public class AudioSharingJoinHandlerDashboardFragmentTest {
|
||||
public void getMetricsCategory_returnsCorrectCategory() {
|
||||
assertThat(mFragment.getMetricsCategory()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleDeviceConnectedFromIntent() {
|
||||
AudioSharingJoinHandlerController controller = mock(
|
||||
AudioSharingJoinHandlerController.class);
|
||||
mFragment.setController(controller);
|
||||
Intent intent = new Intent();
|
||||
mFragment.handleDeviceConnectedFromIntent(intent);
|
||||
verify(controller).handleDeviceConnectedFromIntent(intent);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user