diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java index f7e736698e26c..abeb5af352fca 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java @@ -153,14 +153,16 @@ public class InternetDialogController implements AccessPointController.AccessPoi @VisibleForTesting /** Should be accessible only to the main thread. */ final Map mSubIdTelephonyDisplayInfoMap = new HashMap<>(); + @VisibleForTesting + /** Should be accessible only to the main thread. */ + final Map mSubIdTelephonyManagerMap = new HashMap<>(); + @VisibleForTesting + /** Should be accessible only to the main thread. */ + final Map mSubIdTelephonyCallbackMap = new HashMap<>(); private WifiManager mWifiManager; private Context mContext; private SubscriptionManager mSubscriptionManager; - /** Should be accessible only to the main thread. */ - private Map mSubIdTelephonyManagerMap = new HashMap<>(); - /** Should be accessible only to the main thread. */ - private Map mSubIdTelephonyCallbackMap = new HashMap<>(); private TelephonyManager mTelephonyManager; private ConnectivityManager mConnectivityManager; private CarrierConfigTracker mCarrierConfigTracker; @@ -320,6 +322,9 @@ public class InternetDialogController implements AccessPointController.AccessPoi Log.e(TAG, "Unexpected null telephony call back for Sub " + tm.getSubscriptionId()); } } + mSubIdTelephonyManagerMap.clear(); + mSubIdTelephonyCallbackMap.clear(); + mSubIdTelephonyDisplayInfoMap.clear(); mSubscriptionManager.removeOnSubscriptionsChangedListener( mOnSubscriptionsChangedListener); mAccessPointController.removeAccessPointCallback(this); diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java index 84cc977ce6768..66143923132b3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java @@ -43,6 +43,7 @@ import android.telephony.ServiceState; import android.telephony.SignalStrength; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; +import android.telephony.TelephonyCallback; import android.telephony.TelephonyDisplayInfo; import android.telephony.TelephonyManager; import android.testing.AndroidTestingRunner; @@ -961,6 +962,26 @@ public class InternetDialogControllerTest extends SysuiTestCase { assertThat(dds).contains(mContext.getString(R.string.carrier_network_change_mode)); } + @Test + public void onStop_cleanUp() { + doReturn(SUB_ID).when(mTelephonyManager).getSubscriptionId(); + assertThat(mInternetDialogController.mSubIdTelephonyManagerMap.get(SUB_ID)).isEqualTo( + mTelephonyManager); + assertThat(mInternetDialogController.mSubIdTelephonyCallbackMap.get(SUB_ID)).isNotNull(); + + mInternetDialogController.onStop(); + + verify(mTelephonyManager).unregisterTelephonyCallback(any(TelephonyCallback.class)); + assertThat(mInternetDialogController.mSubIdTelephonyDisplayInfoMap.isEmpty()).isTrue(); + assertThat(mInternetDialogController.mSubIdTelephonyManagerMap.isEmpty()).isTrue(); + assertThat(mInternetDialogController.mSubIdTelephonyCallbackMap.isEmpty()).isTrue(); + verify(mSubscriptionManager).removeOnSubscriptionsChangedListener(mInternetDialogController + .mOnSubscriptionsChangedListener); + verify(mAccessPointController).removeAccessPointCallback(mInternetDialogController); + verify(mConnectivityManager).unregisterNetworkCallback( + any(ConnectivityManager.NetworkCallback.class)); + } + private String getResourcesString(String name) { return mContext.getResources().getString(getResourcesId(name)); }