Loading packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java +21 −10 Original line number Diff line number Diff line Loading @@ -311,10 +311,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi mConfig = MobileMappings.Config.readConfig(mContext); mTelephonyManager = mTelephonyManager.createForSubscriptionId(mDefaultDataSubId); mSubIdTelephonyManagerMap.put(mDefaultDataSubId, mTelephonyManager); InternetTelephonyCallback telephonyCallback = new InternetTelephonyCallback(mDefaultDataSubId); mSubIdTelephonyCallbackMap.put(mDefaultDataSubId, telephonyCallback); mTelephonyManager.registerTelephonyCallback(mExecutor, telephonyCallback); registerInternetTelephonyCallback(mTelephonyManager, mDefaultDataSubId); // Listen the connectivity changes mConnectivityManager.registerDefaultNetworkCallback(mConnectivityManagerNetworkCallback); mCanConfigWifi = canConfigWifi; Loading Loading @@ -346,6 +343,23 @@ public class InternetDialogController implements AccessPointController.AccessPoi mCallback = null; } /** * This is to generate and register the new callback to Telephony for uncached subscription id, * then cache it. Telephony also cached this callback into * {@link com.android.server.TelephonyRegistry}, so if subscription id and callback were cached * already, it shall do nothing to avoid registering redundant callback to Telephony. */ private void registerInternetTelephonyCallback( TelephonyManager telephonyManager, int subId) { if (mSubIdTelephonyCallbackMap.containsKey(subId)) { // Avoid to generate and register unnecessary callback to Telephony. return; } InternetTelephonyCallback telephonyCallback = new InternetTelephonyCallback(subId); mSubIdTelephonyCallbackMap.put(subId, telephonyCallback); telephonyManager.registerTelephonyCallback(mExecutor, telephonyCallback); } boolean isAirplaneModeEnabled() { return mGlobalSettings.getInt(Settings.Global.AIRPLANE_MODE_ON, 0) != 0; } Loading Loading @@ -673,9 +687,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi int subId = subInfo.getSubscriptionId(); if (mSubIdTelephonyManagerMap.get(subId) == null) { TelephonyManager secondaryTm = mTelephonyManager.createForSubscriptionId(subId); InternetTelephonyCallback telephonyCallback = new InternetTelephonyCallback(subId); secondaryTm.registerTelephonyCallback(mExecutor, telephonyCallback); mSubIdTelephonyCallbackMap.put(subId, telephonyCallback); registerInternetTelephonyCallback(secondaryTm, subId); mSubIdTelephonyManagerMap.put(subId, secondaryTm); } return subId; Loading Loading @@ -1351,6 +1363,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi if (DEBUG) { Log.d(TAG, "DDS: defaultDataSubId:" + defaultDataSubId); } if (SubscriptionManager.isUsableSubscriptionId(defaultDataSubId)) { // clean up old defaultDataSubId TelephonyCallback oldCallback = mSubIdTelephonyCallbackMap.get(mDefaultDataSubId); Loading @@ -1366,9 +1379,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi // create for new defaultDataSubId mTelephonyManager = mTelephonyManager.createForSubscriptionId(defaultDataSubId); mSubIdTelephonyManagerMap.put(defaultDataSubId, mTelephonyManager); InternetTelephonyCallback newCallback = new InternetTelephonyCallback(defaultDataSubId); mSubIdTelephonyCallbackMap.put(defaultDataSubId, newCallback); mTelephonyManager.registerTelephonyCallback(mHandler::post, newCallback); registerInternetTelephonyCallback(mTelephonyManager, defaultDataSubId); mCallback.onSubscriptionsChanged(defaultDataSubId); } mDefaultDataSubId = defaultDataSubId; Loading packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogDelegateControllerTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -886,6 +887,34 @@ public class InternetDialogDelegateControllerTest extends SysuiTestCase { assertThat(subId).isEqualTo(SubscriptionManager.INVALID_SUBSCRIPTION_ID); } @Test public void getActiveAutoSwitchNonDdsSubId_registerCallbackForExistedSubId_notRegister() { mFlags.set(Flags.QS_SECONDARY_DATA_SUB_INFO, true); // Adds non DDS subId SubscriptionInfo info = mock(SubscriptionInfo.class); doReturn(SUB_ID2).when(info).getSubscriptionId(); doReturn(false).when(info).isOpportunistic(); when(mSubscriptionManager.getActiveSubscriptionInfo(anyInt())).thenReturn(info); mInternetDialogController.getActiveAutoSwitchNonDdsSubId(); // 1st time is onStart(), 2nd time is getActiveAutoSwitchNonDdsSubId() verify(mTelephonyManager, times(2)).registerTelephonyCallback(any(), any()); assertThat(mInternetDialogController.mSubIdTelephonyCallbackMap.size() == 2); // Adds non DDS subId again doReturn(SUB_ID2).when(info).getSubscriptionId(); doReturn(false).when(info).isOpportunistic(); when(mSubscriptionManager.getActiveSubscriptionInfo(anyInt())).thenReturn(info); mInternetDialogController.getActiveAutoSwitchNonDdsSubId(); // Does not add due to cached subInfo in mSubIdTelephonyCallbackMap. verify(mTelephonyManager, times(2)).registerTelephonyCallback(any(), any()); assertThat(mInternetDialogController.mSubIdTelephonyCallbackMap.size() == 2); } @Test public void getMobileNetworkSummary() { mFlags.set(Flags.QS_SECONDARY_DATA_SUB_INFO, true); Loading Loading
packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java +21 −10 Original line number Diff line number Diff line Loading @@ -311,10 +311,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi mConfig = MobileMappings.Config.readConfig(mContext); mTelephonyManager = mTelephonyManager.createForSubscriptionId(mDefaultDataSubId); mSubIdTelephonyManagerMap.put(mDefaultDataSubId, mTelephonyManager); InternetTelephonyCallback telephonyCallback = new InternetTelephonyCallback(mDefaultDataSubId); mSubIdTelephonyCallbackMap.put(mDefaultDataSubId, telephonyCallback); mTelephonyManager.registerTelephonyCallback(mExecutor, telephonyCallback); registerInternetTelephonyCallback(mTelephonyManager, mDefaultDataSubId); // Listen the connectivity changes mConnectivityManager.registerDefaultNetworkCallback(mConnectivityManagerNetworkCallback); mCanConfigWifi = canConfigWifi; Loading Loading @@ -346,6 +343,23 @@ public class InternetDialogController implements AccessPointController.AccessPoi mCallback = null; } /** * This is to generate and register the new callback to Telephony for uncached subscription id, * then cache it. Telephony also cached this callback into * {@link com.android.server.TelephonyRegistry}, so if subscription id and callback were cached * already, it shall do nothing to avoid registering redundant callback to Telephony. */ private void registerInternetTelephonyCallback( TelephonyManager telephonyManager, int subId) { if (mSubIdTelephonyCallbackMap.containsKey(subId)) { // Avoid to generate and register unnecessary callback to Telephony. return; } InternetTelephonyCallback telephonyCallback = new InternetTelephonyCallback(subId); mSubIdTelephonyCallbackMap.put(subId, telephonyCallback); telephonyManager.registerTelephonyCallback(mExecutor, telephonyCallback); } boolean isAirplaneModeEnabled() { return mGlobalSettings.getInt(Settings.Global.AIRPLANE_MODE_ON, 0) != 0; } Loading Loading @@ -673,9 +687,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi int subId = subInfo.getSubscriptionId(); if (mSubIdTelephonyManagerMap.get(subId) == null) { TelephonyManager secondaryTm = mTelephonyManager.createForSubscriptionId(subId); InternetTelephonyCallback telephonyCallback = new InternetTelephonyCallback(subId); secondaryTm.registerTelephonyCallback(mExecutor, telephonyCallback); mSubIdTelephonyCallbackMap.put(subId, telephonyCallback); registerInternetTelephonyCallback(secondaryTm, subId); mSubIdTelephonyManagerMap.put(subId, secondaryTm); } return subId; Loading Loading @@ -1351,6 +1363,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi if (DEBUG) { Log.d(TAG, "DDS: defaultDataSubId:" + defaultDataSubId); } if (SubscriptionManager.isUsableSubscriptionId(defaultDataSubId)) { // clean up old defaultDataSubId TelephonyCallback oldCallback = mSubIdTelephonyCallbackMap.get(mDefaultDataSubId); Loading @@ -1366,9 +1379,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi // create for new defaultDataSubId mTelephonyManager = mTelephonyManager.createForSubscriptionId(defaultDataSubId); mSubIdTelephonyManagerMap.put(defaultDataSubId, mTelephonyManager); InternetTelephonyCallback newCallback = new InternetTelephonyCallback(defaultDataSubId); mSubIdTelephonyCallbackMap.put(defaultDataSubId, newCallback); mTelephonyManager.registerTelephonyCallback(mHandler::post, newCallback); registerInternetTelephonyCallback(mTelephonyManager, defaultDataSubId); mCallback.onSubscriptionsChanged(defaultDataSubId); } mDefaultDataSubId = defaultDataSubId; Loading
packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogDelegateControllerTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -886,6 +887,34 @@ public class InternetDialogDelegateControllerTest extends SysuiTestCase { assertThat(subId).isEqualTo(SubscriptionManager.INVALID_SUBSCRIPTION_ID); } @Test public void getActiveAutoSwitchNonDdsSubId_registerCallbackForExistedSubId_notRegister() { mFlags.set(Flags.QS_SECONDARY_DATA_SUB_INFO, true); // Adds non DDS subId SubscriptionInfo info = mock(SubscriptionInfo.class); doReturn(SUB_ID2).when(info).getSubscriptionId(); doReturn(false).when(info).isOpportunistic(); when(mSubscriptionManager.getActiveSubscriptionInfo(anyInt())).thenReturn(info); mInternetDialogController.getActiveAutoSwitchNonDdsSubId(); // 1st time is onStart(), 2nd time is getActiveAutoSwitchNonDdsSubId() verify(mTelephonyManager, times(2)).registerTelephonyCallback(any(), any()); assertThat(mInternetDialogController.mSubIdTelephonyCallbackMap.size() == 2); // Adds non DDS subId again doReturn(SUB_ID2).when(info).getSubscriptionId(); doReturn(false).when(info).isOpportunistic(); when(mSubscriptionManager.getActiveSubscriptionInfo(anyInt())).thenReturn(info); mInternetDialogController.getActiveAutoSwitchNonDdsSubId(); // Does not add due to cached subInfo in mSubIdTelephonyCallbackMap. verify(mTelephonyManager, times(2)).registerTelephonyCallback(any(), any()); assertThat(mInternetDialogController.mSubIdTelephonyCallbackMap.size() == 2); } @Test public void getMobileNetworkSummary() { mFlags.set(Flags.QS_SECONDARY_DATA_SUB_INFO, true); Loading