Refesh mobile network details page on carrier config changes
In general the mobile network details page has several preference controllers that don't listen to carrier config changes, so instead of having each one add a listener, we instead just have one listener and refresh the entire page when we see the broadcast. Fixes: 135587885 Test: make RunSettingsRoboTests Change-Id: Iff5b28dbfe12d94c901b442b23cece8e68218983
This commit is contained in:
@@ -22,7 +22,10 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -31,6 +34,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
@@ -161,19 +165,56 @@ public class MobileNetworkActivityTest {
|
||||
@Test
|
||||
public void phoneChangeReceiver_ignoresStickyBroadcastFromBeforeRegistering() {
|
||||
Activity activity = Robolectric.setupActivity(Activity.class);
|
||||
final int[] onChangeCallbackCount = {0};
|
||||
MobileNetworkActivity.PhoneChangeReceiver.Client client = mock(
|
||||
MobileNetworkActivity.PhoneChangeReceiver.Client.class);
|
||||
MobileNetworkActivity.PhoneChangeReceiver receiver =
|
||||
new MobileNetworkActivity.PhoneChangeReceiver(activity, () -> {
|
||||
onChangeCallbackCount[0]++;
|
||||
});
|
||||
new MobileNetworkActivity.PhoneChangeReceiver(activity, client);
|
||||
Intent intent = new Intent(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
|
||||
activity.sendStickyBroadcast(intent);
|
||||
|
||||
receiver.register();
|
||||
assertThat(onChangeCallbackCount[0]).isEqualTo(0);
|
||||
verify(client, never()).onPhoneChange();
|
||||
|
||||
activity.sendStickyBroadcast(intent);
|
||||
assertThat(onChangeCallbackCount[0]).isEqualTo(1);
|
||||
verify(client, times(1)).onPhoneChange();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void phoneChangeReceiver_ignoresCarrierConfigChangeForWrongSubscriptionId() {
|
||||
Activity activity = Robolectric.setupActivity(Activity.class);
|
||||
|
||||
MobileNetworkActivity.PhoneChangeReceiver.Client client = mock(
|
||||
MobileNetworkActivity.PhoneChangeReceiver.Client.class);
|
||||
doReturn(2).when(client).getSubscriptionId();
|
||||
|
||||
MobileNetworkActivity.PhoneChangeReceiver receiver =
|
||||
new MobileNetworkActivity.PhoneChangeReceiver(activity, client);
|
||||
|
||||
receiver.register();
|
||||
|
||||
Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
|
||||
intent.putExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX, 3);
|
||||
activity.sendBroadcast(intent);
|
||||
verify(client, never()).onPhoneChange();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void phoneChangeReceiver_dispatchesCarrierConfigChangeForCorrectSubscriptionId() {
|
||||
Activity activity = Robolectric.setupActivity(Activity.class);
|
||||
|
||||
MobileNetworkActivity.PhoneChangeReceiver.Client client = mock(
|
||||
MobileNetworkActivity.PhoneChangeReceiver.Client.class);
|
||||
doReturn(2).when(client).getSubscriptionId();
|
||||
|
||||
MobileNetworkActivity.PhoneChangeReceiver receiver =
|
||||
new MobileNetworkActivity.PhoneChangeReceiver(activity, client);
|
||||
|
||||
receiver.register();
|
||||
|
||||
Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
|
||||
intent.putExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX, 2);
|
||||
activity.sendBroadcast(intent);
|
||||
verify(client).onPhoneChange();
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user