Add a listener for subscription changes to SimDialogFragment

For some kinds of telephony changes that might happen while we're
already showing one of these dialogs, we already get sent a new intent
for the dialog which we internally convert into a refresh of the dialog
contents instead of stacking a new copy on top of the old one.

But it turns out there are some other cases where the telephony stack
doesn't send a new intent for the dialog but *does* send a change event
through the SubscriptionManager, and we want to respond to those as
well. This CL adds a listener for those events.

Fixes: 135276696
Test: make RunSettingsRoboTests
Change-Id: Ifb93ae95f45fda5831e112306dd9361ccaa5119c
(cherry picked from commit 6a1d7e60ac)
This commit is contained in:
Antony Sargent
2019-06-19 11:30:33 -07:00
parent ab63fd3c25
commit 45f0701380
2 changed files with 50 additions and 1 deletions

View File

@@ -26,6 +26,7 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import android.telephony.SubscriptionManager;
@@ -77,6 +78,22 @@ public class SimListDialogFragmentTest extends SimDialogFragmentTestBase<SimList
verify(activity).onSubscriptionSelected(dialogType, SIM2_ID);
}
@Test
public void onSubscriptionsChanged_dialogUpdates() {
final int dialogType = DATA_PICK;
setDialogType(dialogType);
mFragment = spy(SimListDialogFragment.newInstance(dialogType, R.string.select_sim_for_data,
false /* includeAskEveryTime */));
doReturn(Arrays.asList(mSim1, mSim2)).when(mFragment).getCurrentSubscriptions();
// Avoid problems robolectric has with our real adapter.
doNothing().when(mFragment).setAdapter(any());
startDialog();
verify(mFragment).updateDialog();
mFragment.onSubscriptionsChanged();
verify(mFragment, times(2)).updateDialog();
}
@Test
public void onCreateDialog_twoSubscriptionsAskEveryTime_threeSubsForDisplay() {
final int dialogType = SMS_PICK;