From aef0bd76dbc137fb178d954088abbdd5b2e92f83 Mon Sep 17 00:00:00 2001 From: Ling Ma Date: Tue, 9 May 2023 10:50:22 -0700 Subject: [PATCH] Clear TelephonyManagerMap onStop The change clears all telephony manager related maps onStop, in order for future callbacks/information to be registered properly. Fix: 281529123 Test: manual reproduce and verify fix Test: test task b/281884811 Test: included in daily validation test Change-Id: Ie6e4ec7d5a03920dc07ff9e0300d3399181a602a --- .../dialog/InternetDialogController.java | 13 ++++++++---- .../dialog/InternetDialogControllerTest.java | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) 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)); }