diff options
2 files changed, 79 insertions, 27 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 4c7f10e2bc6b..2e6ea0e28d86 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 @@ -142,21 +142,28 @@ public class InternetDialogController implements AccessPointController.AccessPoi private static final int SUBTITLE_TEXT_ALL_CARRIER_NETWORK_UNAVAILABLE = R.string.all_network_unavailable; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); + private static final TelephonyDisplayInfo DEFAULT_TELEPHONY_DISPLAY_INFO = + new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_UNKNOWN, + TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE); static final int MAX_WIFI_ENTRY_COUNT = 3; private final FeatureFlags mFeatureFlags; + @VisibleForTesting + /** Should be accessible only to the main thread. */ + final Map<Integer, TelephonyDisplayInfo> mSubIdTelephonyDisplayInfoMap = new HashMap<>(); + private WifiManager mWifiManager; private Context mContext; private SubscriptionManager mSubscriptionManager; + /** Should be accessible only to the main thread. */ private Map<Integer, TelephonyManager> mSubIdTelephonyManagerMap = new HashMap<>(); + /** Should be accessible only to the main thread. */ + private Map<Integer, TelephonyCallback> mSubIdTelephonyCallbackMap = new HashMap<>(); private TelephonyManager mTelephonyManager; private ConnectivityManager mConnectivityManager; private CarrierConfigTracker mCarrierConfigTracker; - private TelephonyDisplayInfo mTelephonyDisplayInfo = - new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_UNKNOWN, - TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE); private Handler mHandler; private Handler mWorkerHandler; private MobileMappings.Config mConfig = null; @@ -190,8 +197,6 @@ public class InternetDialogController implements AccessPointController.AccessPoi @VisibleForTesting protected SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangedListener; @VisibleForTesting - protected InternetTelephonyCallback mInternetTelephonyCallback; - @VisibleForTesting protected WifiUtils.InternetIconInjector mWifiIconInjector; @VisibleForTesting protected boolean mCanConfigWifi; @@ -290,8 +295,10 @@ public class InternetDialogController implements AccessPointController.AccessPoi mConfig = MobileMappings.Config.readConfig(mContext); mTelephonyManager = mTelephonyManager.createForSubscriptionId(mDefaultDataSubId); mSubIdTelephonyManagerMap.put(mDefaultDataSubId, mTelephonyManager); - mInternetTelephonyCallback = new InternetTelephonyCallback(); - mTelephonyManager.registerTelephonyCallback(mExecutor, mInternetTelephonyCallback); + InternetTelephonyCallback telephonyCallback = + new InternetTelephonyCallback(mDefaultDataSubId); + mSubIdTelephonyCallbackMap.put(mDefaultDataSubId, telephonyCallback); + mTelephonyManager.registerTelephonyCallback(mExecutor, telephonyCallback); // Listen the connectivity changes mConnectivityManager.registerDefaultNetworkCallback(mConnectivityManagerNetworkCallback); mCanConfigWifi = canConfigWifi; @@ -304,7 +311,12 @@ public class InternetDialogController implements AccessPointController.AccessPoi } mBroadcastDispatcher.unregisterReceiver(mConnectionStateReceiver); for (TelephonyManager tm : mSubIdTelephonyManagerMap.values()) { - tm.unregisterTelephonyCallback(mInternetTelephonyCallback); + TelephonyCallback callback = mSubIdTelephonyCallbackMap.get(tm.getSubscriptionId()); + if (callback != null) { + tm.unregisterTelephonyCallback(callback); + } else if (DEBUG) { + Log.e(TAG, "Unexpected null telephony call back for Sub " + tm.getSubscriptionId()); + } } mSubscriptionManager.removeOnSubscriptionsChangedListener( mOnSubscriptionsChangedListener); @@ -623,7 +635,9 @@ public class InternetDialogController implements AccessPointController.AccessPoi int subId = subInfo.getSubscriptionId(); if (mSubIdTelephonyManagerMap.get(subId) == null) { TelephonyManager secondaryTm = mTelephonyManager.createForSubscriptionId(subId); - secondaryTm.registerTelephonyCallback(mExecutor, mInternetTelephonyCallback); + InternetTelephonyCallback telephonyCallback = new InternetTelephonyCallback(subId); + secondaryTm.registerTelephonyCallback(mExecutor, telephonyCallback); + mSubIdTelephonyCallbackMap.put(subId, telephonyCallback); mSubIdTelephonyManagerMap.put(subId, secondaryTm); } return subId; @@ -637,8 +651,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi } String getMobileNetworkSummary(int subId) { - String description = getNetworkTypeDescription(mContext, mConfig, - mTelephonyDisplayInfo, subId); + String description = getNetworkTypeDescription(mContext, mConfig, subId); return getMobileSummary(mContext, description, subId); } @@ -646,7 +659,9 @@ public class InternetDialogController implements AccessPointController.AccessPoi * Get currently description of mobile network type. */ private String getNetworkTypeDescription(Context context, MobileMappings.Config config, - TelephonyDisplayInfo telephonyDisplayInfo, int subId) { + int subId) { + TelephonyDisplayInfo telephonyDisplayInfo = + mSubIdTelephonyDisplayInfoMap.getOrDefault(subId, DEFAULT_TELEPHONY_DISPLAY_INFO); String iconKey = getIconKey(telephonyDisplayInfo); if (mapIconSets(config) == null || mapIconSets(config).get(iconKey) == null) { @@ -725,11 +740,10 @@ public class InternetDialogController implements AccessPointController.AccessPoi Intent getSubSettingIntent(int subId) { final Intent intent = new Intent(Settings.ACTION_NETWORK_OPERATOR_SETTINGS); - final Bundle fragmentArgs = new Bundle(); // Special contract for Settings to highlight permission row fragmentArgs.putString(SETTINGS_EXTRA_FRAGMENT_ARG_KEY, AUTO_DATA_SWITCH_SETTING_R_ID); - fragmentArgs.putInt(Settings.EXTRA_SUB_ID, subId); + intent.putExtra(Settings.EXTRA_SUB_ID, subId); intent.putExtra(SETTINGS_EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs); return intent; } @@ -1054,6 +1068,11 @@ public class InternetDialogController implements AccessPointController.AccessPoi TelephonyCallback.SignalStrengthsListener, TelephonyCallback.UserMobileDataStateListener { + private final int mSubId; + private InternetTelephonyCallback(int subId) { + mSubId = subId; + } + @Override public void onServiceStateChanged(@NonNull ServiceState serviceState) { mCallback.onServiceStateChanged(serviceState); @@ -1071,7 +1090,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi @Override public void onDisplayInfoChanged(@NonNull TelephonyDisplayInfo telephonyDisplayInfo) { - mTelephonyDisplayInfo = telephonyDisplayInfo; + mSubIdTelephonyDisplayInfoMap.put(mSubId, telephonyDisplayInfo); mCallback.onDisplayInfoChanged(telephonyDisplayInfo); } @@ -1196,19 +1215,30 @@ public class InternetDialogController implements AccessPointController.AccessPoi } return; } - - mDefaultDataSubId = defaultDataSubId; if (DEBUG) { - Log.d(TAG, "DDS: defaultDataSubId:" + mDefaultDataSubId); - } - if (SubscriptionManager.isUsableSubscriptionId(mDefaultDataSubId)) { - mTelephonyManager.unregisterTelephonyCallback(mInternetTelephonyCallback); - mTelephonyManager = mTelephonyManager.createForSubscriptionId(mDefaultDataSubId); - mSubIdTelephonyManagerMap.put(mDefaultDataSubId, mTelephonyManager); - mTelephonyManager.registerTelephonyCallback(mHandler::post, - mInternetTelephonyCallback); - mCallback.onSubscriptionsChanged(mDefaultDataSubId); + Log.d(TAG, "DDS: defaultDataSubId:" + defaultDataSubId); + } + if (SubscriptionManager.isUsableSubscriptionId(defaultDataSubId)) { + // clean up old defaultDataSubId + TelephonyCallback oldCallback = mSubIdTelephonyCallbackMap.get(mDefaultDataSubId); + if (oldCallback != null) { + mTelephonyManager.unregisterTelephonyCallback(oldCallback); + } else if (DEBUG) { + Log.e(TAG, "Unexpected null telephony call back for Sub " + mDefaultDataSubId); + } + mSubIdTelephonyCallbackMap.remove(mDefaultDataSubId); + mSubIdTelephonyDisplayInfoMap.remove(mDefaultDataSubId); + mSubIdTelephonyManagerMap.remove(mDefaultDataSubId); + + // 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); + mCallback.onSubscriptionsChanged(defaultDataSubId); } + mDefaultDataSubId = defaultDataSubId; } public WifiUtils.InternetIconInjector getWifiIconInjector() { 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 8d1ccd0df587..6d2972d818fe 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 @@ -31,6 +31,7 @@ import static org.mockito.Mockito.when; import android.animation.Animator; import android.content.Intent; +import android.content.res.Resources; import android.graphics.PixelFormat; import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; @@ -40,6 +41,7 @@ import android.telephony.ServiceState; import android.telephony.SignalStrength; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; +import android.telephony.TelephonyDisplayInfo; import android.telephony.TelephonyManager; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; @@ -85,6 +87,7 @@ import org.mockito.quality.Strictness; import java.util.ArrayList; import java.util.List; +import java.util.Map; @SmallTest @RunWith(AndroidTestingRunner.class) @@ -753,15 +756,34 @@ public class InternetDialogControllerTest extends SysuiTestCase { @Test public void getMobileNetworkSummary() { mFlags.set(Flags.QS_SECONDARY_DATA_SUB_INFO, true); + Resources res1 = mock(Resources.class); + doReturn("EDGE").when(res1).getString(anyInt()); + Resources res2 = mock(Resources.class); + doReturn("LTE").when(res2).getString(anyInt()); + when(SubscriptionManager.getResourcesForSubId(any(), eq(SUB_ID))).thenReturn(res1); + when(SubscriptionManager.getResourcesForSubId(any(), eq(SUB_ID2))).thenReturn(res2); + InternetDialogController spyController = spy(mInternetDialogController); + Map<Integer, TelephonyDisplayInfo> mSubIdTelephonyDisplayInfoMap = + spyController.mSubIdTelephonyDisplayInfoMap; + TelephonyDisplayInfo info1 = new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_EDGE, + TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE); + TelephonyDisplayInfo info2 = new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_LTE, + TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE); + + mSubIdTelephonyDisplayInfoMap.put(SUB_ID, info1); + mSubIdTelephonyDisplayInfoMap.put(SUB_ID2, info2); + doReturn(SUB_ID2).when(spyController).getActiveAutoSwitchNonDdsSubId(); doReturn(true).when(spyController).isMobileDataEnabled(); doReturn(true).when(spyController).activeNetworkIsCellular(); String dds = spyController.getMobileNetworkSummary(SUB_ID); String nonDds = spyController.getMobileNetworkSummary(SUB_ID2); + String ddsNetworkType = dds.split("/")[1]; + String nonDdsNetworkType = nonDds.split("/")[1]; assertThat(dds).contains(mContext.getString(R.string.mobile_data_poor_connection)); - assertThat(dds).isNotEqualTo(nonDds); + assertThat(ddsNetworkType).isNotEqualTo(nonDdsNetworkType); } @Test |