[Settings] Use TelephonyManasger.registerTelephonyCallback instead of TelephonyManager.listen

Bug: 175270951
Test: make and atest
Change-Id: I15e1a199e6a34914db97055bfea9392c5bbdc9c6
This commit is contained in:
Zoey Chen
2021-03-10 16:01:18 +08:00
parent 0872d40a75
commit b8a639f8fd
12 changed files with 202 additions and 175 deletions

View File

@@ -124,13 +124,12 @@ public class MobileNetworkPreferenceControllerTest {
mLifecycleRegistry.handleLifecycleEvent(Event.ON_START);
verify(mController).onStart();
verify(mTelephonyManager).listen(mController.mPhoneStateListener,
PhoneStateListener.LISTEN_SERVICE_STATE);
verify(mTelephonyManager).registerTelephonyCallback(
mContext.getMainExecutor(), mController.mTelephonyCallback);
mLifecycleRegistry.handleLifecycleEvent(Event.ON_STOP);
verify(mController).onStop();
verify(mTelephonyManager).listen(mController.mPhoneStateListener,
PhoneStateListener.LISTEN_NONE);
verify(mTelephonyManager).unregisterTelephonyCallback(mController.mTelephonyCallback);
}
@Test
@@ -148,12 +147,12 @@ public class MobileNetworkPreferenceControllerTest {
mController.displayPreference(mScreen);
mLifecycleRegistry.handleLifecycleEvent(Event.ON_START);
verify(mController).onStart();
verify(mTelephonyManager).listen(mController.mPhoneStateListener,
PhoneStateListener.LISTEN_SERVICE_STATE);
verify(mTelephonyManager).registerTelephonyCallback(
mContext.getMainExecutor(), mController.mTelephonyCallback);
doReturn(testCarrierName).when(mController).getSummary();
mController.mPhoneStateListener.onServiceStateChanged(null);
mController.mTelephonyCallback.onServiceStateChanged(null);
// Carrier name should be set.
Assert.assertEquals(mPreference.getSummary(), testCarrierName);