Merge "[MS34.2] Replace TelephonyManager#getSubscriberId(subId) with public API"
This commit is contained in:
@@ -41,6 +41,7 @@ import android.telephony.PhoneStateListener;
|
|||||||
import android.telephony.ServiceState;
|
import android.telephony.ServiceState;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
import android.util.SparseArray;
|
||||||
|
|
||||||
import com.android.internal.util.CollectionUtils;
|
import com.android.internal.util.CollectionUtils;
|
||||||
import com.android.server.net.NetworkStatsSubscriptionsMonitor.RatTypeListener;
|
import com.android.server.net.NetworkStatsSubscriptionsMonitor.RatTypeListener;
|
||||||
@@ -71,6 +72,8 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
|||||||
@Mock private Context mContext;
|
@Mock private Context mContext;
|
||||||
@Mock private SubscriptionManager mSubscriptionManager;
|
@Mock private SubscriptionManager mSubscriptionManager;
|
||||||
@Mock private TelephonyManager mTelephonyManager;
|
@Mock private TelephonyManager mTelephonyManager;
|
||||||
|
private final SparseArray<TelephonyManager> mTelephonyManagerOfSub = new SparseArray<>();
|
||||||
|
private final SparseArray<RatTypeListener> mRatTypeListenerOfSub = new SparseArray<>();
|
||||||
@Mock private NetworkStatsSubscriptionsMonitor.Delegate mDelegate;
|
@Mock private NetworkStatsSubscriptionsMonitor.Delegate mDelegate;
|
||||||
private final List<Integer> mTestSubList = new ArrayList<>();
|
private final List<Integer> mTestSubList = new ArrayList<>();
|
||||||
|
|
||||||
@@ -82,8 +85,6 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
|
|
||||||
|
|
||||||
when(mContext.getSystemService(eq(Context.TELEPHONY_SUBSCRIPTION_SERVICE)))
|
when(mContext.getSystemService(eq(Context.TELEPHONY_SUBSCRIPTION_SERVICE)))
|
||||||
.thenReturn(mSubscriptionManager);
|
.thenReturn(mSubscriptionManager);
|
||||||
when(mContext.getSystemService(eq(Context.TELEPHONY_SERVICE)))
|
when(mContext.getSystemService(eq(Context.TELEPHONY_SERVICE)))
|
||||||
@@ -116,12 +117,10 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setRatTypeForSub(List<RatTypeListener> listeners,
|
private void setRatTypeForSub(int subId, int type) {
|
||||||
int subId, int type) {
|
|
||||||
final ServiceState serviceState = mock(ServiceState.class);
|
final ServiceState serviceState = mock(ServiceState.class);
|
||||||
when(serviceState.getDataNetworkType()).thenReturn(type);
|
when(serviceState.getDataNetworkType()).thenReturn(type);
|
||||||
final RatTypeListener match = CollectionUtils
|
final RatTypeListener match = mRatTypeListenerOfSub.get(subId);
|
||||||
.find(listeners, it -> it.getSubId() == subId);
|
|
||||||
if (match == null) {
|
if (match == null) {
|
||||||
fail("Could not find listener with subId: " + subId);
|
fail("Could not find listener with subId: " + subId);
|
||||||
}
|
}
|
||||||
@@ -136,21 +135,41 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
|||||||
|
|
||||||
final int[] subList = convertArrayListToIntArray(mTestSubList);
|
final int[] subList = convertArrayListToIntArray(mTestSubList);
|
||||||
when(mSubscriptionManager.getCompleteActiveSubscriptionIdList()).thenReturn(subList);
|
when(mSubscriptionManager.getCompleteActiveSubscriptionIdList()).thenReturn(subList);
|
||||||
when(mTelephonyManager.getSubscriberId(subId)).thenReturn(subscriberId);
|
updateSubscriberIdForTestSub(subId, subscriberId);
|
||||||
mMonitor.onSubscriptionsChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSubscriberIdForTestSub(int subId, @Nullable final String subscriberId) {
|
private void updateSubscriberIdForTestSub(int subId, @Nullable final String subscriberId) {
|
||||||
when(mTelephonyManager.getSubscriberId(subId)).thenReturn(subscriberId);
|
final TelephonyManager telephonyManagerOfSub;
|
||||||
|
if (mTelephonyManagerOfSub.contains(subId)) {
|
||||||
|
telephonyManagerOfSub = mTelephonyManagerOfSub.get(subId);
|
||||||
|
} else {
|
||||||
|
telephonyManagerOfSub = mock(TelephonyManager.class);
|
||||||
|
mTelephonyManagerOfSub.put(subId, telephonyManagerOfSub);
|
||||||
|
}
|
||||||
|
when(telephonyManagerOfSub.getSubscriberId()).thenReturn(subscriberId);
|
||||||
|
when(mTelephonyManager.createForSubscriptionId(subId)).thenReturn(telephonyManagerOfSub);
|
||||||
mMonitor.onSubscriptionsChanged();
|
mMonitor.onSubscriptionsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertAndCaptureRatTypeListenerRegistrationWith(int subId, int listenedState) {
|
||||||
|
final ArgumentCaptor<RatTypeListener> ratTypeListenerCaptor =
|
||||||
|
ArgumentCaptor.forClass(RatTypeListener.class);
|
||||||
|
verify(mTelephonyManagerOfSub.get(subId)).listen(ratTypeListenerCaptor.capture(),
|
||||||
|
eq(listenedState));
|
||||||
|
final RatTypeListener listener = CollectionUtils
|
||||||
|
.find(ratTypeListenerCaptor.getAllValues(), it -> it.getSubId() == subId);
|
||||||
|
assertNotNull(listener);
|
||||||
|
mRatTypeListenerOfSub.put(subId, listener);
|
||||||
|
}
|
||||||
|
|
||||||
private void removeTestSub(int subId) {
|
private void removeTestSub(int subId) {
|
||||||
// Remove subId from TestSubList.
|
// Remove subId from TestSubList.
|
||||||
mTestSubList.removeIf(it -> it == subId);
|
mTestSubList.removeIf(it -> it == subId);
|
||||||
final int[] subList = convertArrayListToIntArray(mTestSubList);
|
final int[] subList = convertArrayListToIntArray(mTestSubList);
|
||||||
when(mSubscriptionManager.getCompleteActiveSubscriptionIdList()).thenReturn(subList);
|
when(mSubscriptionManager.getCompleteActiveSubscriptionIdList()).thenReturn(subList);
|
||||||
mMonitor.onSubscriptionsChanged();
|
mMonitor.onSubscriptionsChanged();
|
||||||
|
mRatTypeListenerOfSub.delete(subId);
|
||||||
|
// Keep TelephonyManagerOfSubs so the test could verify de-registration.
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertRatTypeChangedForSub(String subscriberId, int ratType) {
|
private void assertRatTypeChangedForSub(String subscriberId, int ratType) {
|
||||||
@@ -171,9 +190,6 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSubChangedAndRatTypeChanged() {
|
public void testSubChangedAndRatTypeChanged() {
|
||||||
final ArgumentCaptor<RatTypeListener> ratTypeListenerCaptor =
|
|
||||||
ArgumentCaptor.forClass(RatTypeListener.class);
|
|
||||||
|
|
||||||
mMonitor.start();
|
mMonitor.start();
|
||||||
// Insert sim1, verify RAT type is NETWORK_TYPE_UNKNOWN, and never get any callback
|
// Insert sim1, verify RAT type is NETWORK_TYPE_UNKNOWN, and never get any callback
|
||||||
// before changing RAT type.
|
// before changing RAT type.
|
||||||
@@ -183,15 +199,16 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
|||||||
// Insert sim2.
|
// Insert sim2.
|
||||||
addTestSub(TEST_SUBID2, TEST_IMSI2);
|
addTestSub(TEST_SUBID2, TEST_IMSI2);
|
||||||
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
verify(mTelephonyManager, times(2)).listen(ratTypeListenerCaptor.capture(),
|
assertAndCaptureRatTypeListenerRegistrationWith(TEST_SUBID1,
|
||||||
eq(PhoneStateListener.LISTEN_SERVICE_STATE));
|
PhoneStateListener.LISTEN_SERVICE_STATE);
|
||||||
|
assertAndCaptureRatTypeListenerRegistrationWith(TEST_SUBID2,
|
||||||
|
PhoneStateListener.LISTEN_SERVICE_STATE);
|
||||||
reset(mDelegate);
|
reset(mDelegate);
|
||||||
|
|
||||||
// Set RAT type of sim1 to UMTS.
|
// Set RAT type of sim1 to UMTS.
|
||||||
// Verify RAT type of sim1 after subscription gets onCollapsedRatTypeChanged() callback
|
// Verify RAT type of sim1 after subscription gets onCollapsedRatTypeChanged() callback
|
||||||
// and others remain untouched.
|
// and others remain untouched.
|
||||||
setRatTypeForSub(ratTypeListenerCaptor.getAllValues(), TEST_SUBID1,
|
setRatTypeForSub(TEST_SUBID1, TelephonyManager.NETWORK_TYPE_UMTS);
|
||||||
TelephonyManager.NETWORK_TYPE_UMTS);
|
|
||||||
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UMTS);
|
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UMTS);
|
||||||
assertRatTypeNotChangedForSub(TEST_IMSI2, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeNotChangedForSub(TEST_IMSI2, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
assertRatTypeNotChangedForSub(TEST_IMSI3, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeNotChangedForSub(TEST_IMSI3, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
@@ -200,8 +217,7 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
|||||||
// Set RAT type of sim2 to LTE.
|
// Set RAT type of sim2 to LTE.
|
||||||
// Verify RAT type of sim2 after subscription gets onCollapsedRatTypeChanged() callback
|
// Verify RAT type of sim2 after subscription gets onCollapsedRatTypeChanged() callback
|
||||||
// and others remain untouched.
|
// and others remain untouched.
|
||||||
setRatTypeForSub(ratTypeListenerCaptor.getAllValues(), TEST_SUBID2,
|
setRatTypeForSub(TEST_SUBID2, TelephonyManager.NETWORK_TYPE_LTE);
|
||||||
TelephonyManager.NETWORK_TYPE_LTE);
|
|
||||||
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UMTS);
|
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UMTS);
|
||||||
assertRatTypeChangedForSub(TEST_IMSI2, TelephonyManager.NETWORK_TYPE_LTE);
|
assertRatTypeChangedForSub(TEST_IMSI2, TelephonyManager.NETWORK_TYPE_LTE);
|
||||||
assertRatTypeNotChangedForSub(TEST_IMSI3, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeNotChangedForSub(TEST_IMSI3, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
@@ -210,7 +226,8 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
|||||||
// Remove sim2 and verify that callbacks are fired and RAT type is correct for sim2.
|
// Remove sim2 and verify that callbacks are fired and RAT type is correct for sim2.
|
||||||
// while the other two remain untouched.
|
// while the other two remain untouched.
|
||||||
removeTestSub(TEST_SUBID2);
|
removeTestSub(TEST_SUBID2);
|
||||||
verify(mTelephonyManager).listen(any(), eq(PhoneStateListener.LISTEN_NONE));
|
assertAndCaptureRatTypeListenerRegistrationWith(TEST_SUBID2,
|
||||||
|
PhoneStateListener.LISTEN_NONE);
|
||||||
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UMTS);
|
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UMTS);
|
||||||
assertRatTypeChangedForSub(TEST_IMSI2, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeChangedForSub(TEST_IMSI2, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
assertRatTypeNotChangedForSub(TEST_IMSI3, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeNotChangedForSub(TEST_IMSI3, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
@@ -218,13 +235,15 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
|||||||
|
|
||||||
// Set RAT type of sim1 to UNKNOWN. Then stop monitoring subscription changes
|
// Set RAT type of sim1 to UNKNOWN. Then stop monitoring subscription changes
|
||||||
// and verify that the listener for sim1 is removed.
|
// and verify that the listener for sim1 is removed.
|
||||||
setRatTypeForSub(ratTypeListenerCaptor.getAllValues(), TEST_SUBID1,
|
setRatTypeForSub(TEST_SUBID1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
|
||||||
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
reset(mDelegate);
|
reset(mDelegate);
|
||||||
|
|
||||||
mMonitor.stop();
|
mMonitor.stop();
|
||||||
verify(mTelephonyManager, times(2)).listen(any(), eq(PhoneStateListener.LISTEN_NONE));
|
assertAndCaptureRatTypeListenerRegistrationWith(TEST_SUBID1,
|
||||||
|
PhoneStateListener.LISTEN_NONE);
|
||||||
|
assertAndCaptureRatTypeListenerRegistrationWith(TEST_SUBID2,
|
||||||
|
PhoneStateListener.LISTEN_NONE);
|
||||||
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,13 +255,9 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
|||||||
// before changing RAT type. Also capture listener for later use.
|
// before changing RAT type. Also capture listener for later use.
|
||||||
addTestSub(TEST_SUBID1, TEST_IMSI1);
|
addTestSub(TEST_SUBID1, TEST_IMSI1);
|
||||||
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
final ArgumentCaptor<RatTypeListener> ratTypeListenerCaptor =
|
assertAndCaptureRatTypeListenerRegistrationWith(TEST_SUBID1,
|
||||||
ArgumentCaptor.forClass(RatTypeListener.class);
|
PhoneStateListener.LISTEN_SERVICE_STATE);
|
||||||
verify(mTelephonyManager, times(1)).listen(ratTypeListenerCaptor.capture(),
|
final RatTypeListener listener = mRatTypeListenerOfSub.get(TEST_SUBID1);
|
||||||
eq(PhoneStateListener.LISTEN_SERVICE_STATE));
|
|
||||||
final RatTypeListener listener = CollectionUtils
|
|
||||||
.find(ratTypeListenerCaptor.getAllValues(), it -> it.getSubId() == TEST_SUBID1);
|
|
||||||
assertNotNull(listener);
|
|
||||||
|
|
||||||
// Set RAT type to 5G NSA (non-standalone) mode, verify the monitor outputs
|
// Set RAT type to 5G NSA (non-standalone) mode, verify the monitor outputs
|
||||||
// NETWORK_TYPE_5G_NSA.
|
// NETWORK_TYPE_5G_NSA.
|
||||||
@@ -267,8 +282,7 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
|||||||
reset(mDelegate);
|
reset(mDelegate);
|
||||||
|
|
||||||
// Set RAT type to 5G standalone mode, the RAT type should be NR.
|
// Set RAT type to 5G standalone mode, the RAT type should be NR.
|
||||||
setRatTypeForSub(ratTypeListenerCaptor.getAllValues(), TEST_SUBID1,
|
setRatTypeForSub(TEST_SUBID1, TelephonyManager.NETWORK_TYPE_NR);
|
||||||
TelephonyManager.NETWORK_TYPE_NR);
|
|
||||||
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_NR);
|
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_NR);
|
||||||
reset(mDelegate);
|
reset(mDelegate);
|
||||||
|
|
||||||
@@ -281,59 +295,53 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSubscriberIdUnavailable() {
|
public void testSubscriberIdUnavailable() {
|
||||||
final ArgumentCaptor<RatTypeListener> ratTypeListenerCaptor =
|
|
||||||
ArgumentCaptor.forClass(RatTypeListener.class);
|
|
||||||
|
|
||||||
mMonitor.start();
|
mMonitor.start();
|
||||||
// Insert sim1, set subscriberId to null which is normal in SIM PIN locked case.
|
// Insert sim1, set subscriberId to null which is normal in SIM PIN locked case.
|
||||||
// Verify RAT type is NETWORK_TYPE_UNKNOWN and service will not perform listener
|
// Verify RAT type is NETWORK_TYPE_UNKNOWN and service will not perform listener
|
||||||
// registration.
|
// registration.
|
||||||
addTestSub(TEST_SUBID1, null);
|
addTestSub(TEST_SUBID1, null);
|
||||||
verify(mTelephonyManager, never()).listen(any(), anyInt());
|
verify(mTelephonyManagerOfSub.get(TEST_SUBID1), never()).listen(any(), anyInt());
|
||||||
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
|
|
||||||
// Set IMSI for sim1, verify the listener will be registered.
|
// Set IMSI for sim1, verify the listener will be registered.
|
||||||
updateSubscriberIdForTestSub(TEST_SUBID1, TEST_IMSI1);
|
updateSubscriberIdForTestSub(TEST_SUBID1, TEST_IMSI1);
|
||||||
verify(mTelephonyManager, times(1)).listen(ratTypeListenerCaptor.capture(),
|
assertAndCaptureRatTypeListenerRegistrationWith(TEST_SUBID1,
|
||||||
eq(PhoneStateListener.LISTEN_SERVICE_STATE));
|
PhoneStateListener.LISTEN_SERVICE_STATE);
|
||||||
reset(mTelephonyManager);
|
reset(mTelephonyManager);
|
||||||
when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
|
|
||||||
|
|
||||||
// Set RAT type of sim1 to UMTS. Verify RAT type of sim1 is changed.
|
// Set RAT type of sim1 to UMTS. Verify RAT type of sim1 is changed.
|
||||||
setRatTypeForSub(ratTypeListenerCaptor.getAllValues(), TEST_SUBID1,
|
setRatTypeForSub(TEST_SUBID1, TelephonyManager.NETWORK_TYPE_UMTS);
|
||||||
TelephonyManager.NETWORK_TYPE_UMTS);
|
|
||||||
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UMTS);
|
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UMTS);
|
||||||
reset(mDelegate);
|
reset(mDelegate);
|
||||||
|
|
||||||
// Set IMSI to null again to simulate somehow IMSI is not available, such as
|
// Set IMSI to null again to simulate somehow IMSI is not available, such as
|
||||||
// modem crash. Verify service should unregister listener.
|
// modem crash. Verify service should unregister listener.
|
||||||
updateSubscriberIdForTestSub(TEST_SUBID1, null);
|
updateSubscriberIdForTestSub(TEST_SUBID1, null);
|
||||||
verify(mTelephonyManager, times(1)).listen(eq(ratTypeListenerCaptor.getValue()),
|
assertAndCaptureRatTypeListenerRegistrationWith(TEST_SUBID1,
|
||||||
eq(PhoneStateListener.LISTEN_NONE));
|
PhoneStateListener.LISTEN_NONE);
|
||||||
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
reset(mDelegate);
|
reset(mDelegate);
|
||||||
clearInvocations(mTelephonyManager);
|
clearInvocations(mTelephonyManagerOfSub.get(TEST_SUBID1));
|
||||||
|
|
||||||
// Simulate somehow IMSI is back. Verify service will register with
|
// Simulate somehow IMSI is back. Verify service will register with
|
||||||
// another listener and fire callback accordingly.
|
// another listener and fire callback accordingly.
|
||||||
final ArgumentCaptor<RatTypeListener> ratTypeListenerCaptor2 =
|
final ArgumentCaptor<RatTypeListener> ratTypeListenerCaptor2 =
|
||||||
ArgumentCaptor.forClass(RatTypeListener.class);
|
ArgumentCaptor.forClass(RatTypeListener.class);
|
||||||
updateSubscriberIdForTestSub(TEST_SUBID1, TEST_IMSI1);
|
updateSubscriberIdForTestSub(TEST_SUBID1, TEST_IMSI1);
|
||||||
verify(mTelephonyManager, times(1)).listen(ratTypeListenerCaptor2.capture(),
|
assertAndCaptureRatTypeListenerRegistrationWith(TEST_SUBID1,
|
||||||
eq(PhoneStateListener.LISTEN_SERVICE_STATE));
|
PhoneStateListener.LISTEN_SERVICE_STATE);
|
||||||
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
reset(mDelegate);
|
reset(mDelegate);
|
||||||
clearInvocations(mTelephonyManager);
|
clearInvocations(mTelephonyManagerOfSub.get(TEST_SUBID1));
|
||||||
|
|
||||||
// Set RAT type of sim1 to LTE. Verify RAT type of sim1 still works.
|
// Set RAT type of sim1 to LTE. Verify RAT type of sim1 still works.
|
||||||
setRatTypeForSub(ratTypeListenerCaptor2.getAllValues(), TEST_SUBID1,
|
setRatTypeForSub(TEST_SUBID1, TelephonyManager.NETWORK_TYPE_LTE);
|
||||||
TelephonyManager.NETWORK_TYPE_LTE);
|
|
||||||
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_LTE);
|
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_LTE);
|
||||||
reset(mDelegate);
|
reset(mDelegate);
|
||||||
|
|
||||||
mMonitor.stop();
|
mMonitor.stop();
|
||||||
verify(mTelephonyManager, times(1)).listen(eq(ratTypeListenerCaptor2.getValue()),
|
assertAndCaptureRatTypeListenerRegistrationWith(TEST_SUBID1,
|
||||||
eq(PhoneStateListener.LISTEN_NONE));
|
PhoneStateListener.LISTEN_NONE);
|
||||||
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,30 +357,26 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
|||||||
// Insert sim1, verify RAT type is NETWORK_TYPE_UNKNOWN, and never get any callback
|
// Insert sim1, verify RAT type is NETWORK_TYPE_UNKNOWN, and never get any callback
|
||||||
// before changing RAT type.
|
// before changing RAT type.
|
||||||
addTestSub(TEST_SUBID1, TEST_IMSI1);
|
addTestSub(TEST_SUBID1, TEST_IMSI1);
|
||||||
final ArgumentCaptor<RatTypeListener> ratTypeListenerCaptor =
|
assertAndCaptureRatTypeListenerRegistrationWith(TEST_SUBID1,
|
||||||
ArgumentCaptor.forClass(RatTypeListener.class);
|
PhoneStateListener.LISTEN_SERVICE_STATE);
|
||||||
verify(mTelephonyManager, times(1)).listen(ratTypeListenerCaptor.capture(),
|
|
||||||
eq(PhoneStateListener.LISTEN_SERVICE_STATE));
|
|
||||||
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
|
|
||||||
// Set RAT type of sim1 to UMTS.
|
// Set RAT type of sim1 to UMTS.
|
||||||
// Verify RAT type of sim1 changes accordingly.
|
// Verify RAT type of sim1 changes accordingly.
|
||||||
setRatTypeForSub(ratTypeListenerCaptor.getAllValues(), TEST_SUBID1,
|
setRatTypeForSub(TEST_SUBID1, TelephonyManager.NETWORK_TYPE_UMTS);
|
||||||
TelephonyManager.NETWORK_TYPE_UMTS);
|
|
||||||
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UMTS);
|
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UMTS);
|
||||||
reset(mDelegate);
|
reset(mDelegate);
|
||||||
clearInvocations(mTelephonyManager);
|
clearInvocations(mTelephonyManagerOfSub.get(TEST_SUBID1));
|
||||||
|
|
||||||
// Simulate IMSI of sim1 changed to IMSI2. Verify the service will register with
|
// Simulate IMSI of sim1 changed to IMSI2. Verify the service will register with
|
||||||
// another listener and remove the old one. The RAT type of new IMSI stays at
|
// another listener and remove the old one. The RAT type of new IMSI stays at
|
||||||
// NETWORK_TYPE_UNKNOWN until received initial callback from telephony.
|
// NETWORK_TYPE_UNKNOWN until received initial callback from telephony.
|
||||||
final ArgumentCaptor<RatTypeListener> ratTypeListenerCaptor2 =
|
|
||||||
ArgumentCaptor.forClass(RatTypeListener.class);
|
|
||||||
updateSubscriberIdForTestSub(TEST_SUBID1, TEST_IMSI2);
|
updateSubscriberIdForTestSub(TEST_SUBID1, TEST_IMSI2);
|
||||||
verify(mTelephonyManager, times(1)).listen(ratTypeListenerCaptor2.capture(),
|
final RatTypeListener oldListener = mRatTypeListenerOfSub.get(TEST_SUBID1);
|
||||||
eq(PhoneStateListener.LISTEN_SERVICE_STATE));
|
assertAndCaptureRatTypeListenerRegistrationWith(TEST_SUBID1,
|
||||||
verify(mTelephonyManager, times(1)).listen(eq(ratTypeListenerCaptor.getValue()),
|
PhoneStateListener.LISTEN_SERVICE_STATE);
|
||||||
eq(PhoneStateListener.LISTEN_NONE));
|
verify(mTelephonyManagerOfSub.get(TEST_SUBID1), times(1))
|
||||||
|
.listen(eq(oldListener), eq(PhoneStateListener.LISTEN_NONE));
|
||||||
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
assertRatTypeNotChangedForSub(TEST_IMSI2, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeNotChangedForSub(TEST_IMSI2, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
reset(mDelegate);
|
reset(mDelegate);
|
||||||
@@ -380,8 +384,7 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
|||||||
// Set RAT type of sim1 to UMTS for new listener to simulate the initial callback received
|
// Set RAT type of sim1 to UMTS for new listener to simulate the initial callback received
|
||||||
// from telephony after registration. Verify RAT type of sim1 changes with IMSI2
|
// from telephony after registration. Verify RAT type of sim1 changes with IMSI2
|
||||||
// accordingly.
|
// accordingly.
|
||||||
setRatTypeForSub(ratTypeListenerCaptor2.getAllValues(), TEST_SUBID1,
|
setRatTypeForSub(TEST_SUBID1, TelephonyManager.NETWORK_TYPE_UMTS);
|
||||||
TelephonyManager.NETWORK_TYPE_UMTS);
|
|
||||||
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
assertRatTypeNotChangedForSub(TEST_IMSI1, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
||||||
assertRatTypeChangedForSub(TEST_IMSI2, TelephonyManager.NETWORK_TYPE_UMTS);
|
assertRatTypeChangedForSub(TEST_IMSI2, TelephonyManager.NETWORK_TYPE_UMTS);
|
||||||
reset(mDelegate);
|
reset(mDelegate);
|
||||||
|
|||||||
Reference in New Issue
Block a user