Merge "Make telephonycallback specific to subId" into tm-qpr-dev am: b20b3e3024

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20444908

Change-Id: If7cae6a95a8b8234ab16bc241c55d7c5fdf97252
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Ling Ma
2022-11-22 19:40:47 +00:00
committed by Automerger Merge Worker
2 changed files with 78 additions and 26 deletions

View File

@@ -142,21 +142,28 @@ public class InternetDialogController implements AccessPointController.AccessPoi
private static final int SUBTITLE_TEXT_ALL_CARRIER_NETWORK_UNAVAILABLE = private static final int SUBTITLE_TEXT_ALL_CARRIER_NETWORK_UNAVAILABLE =
R.string.all_network_unavailable; R.string.all_network_unavailable;
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); 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; static final int MAX_WIFI_ENTRY_COUNT = 3;
private final FeatureFlags mFeatureFlags; private final FeatureFlags mFeatureFlags;
@VisibleForTesting
/** Should be accessible only to the main thread. */
final Map<Integer, TelephonyDisplayInfo> mSubIdTelephonyDisplayInfoMap = new HashMap<>();
private WifiManager mWifiManager; private WifiManager mWifiManager;
private Context mContext; private Context mContext;
private SubscriptionManager mSubscriptionManager; private SubscriptionManager mSubscriptionManager;
/** Should be accessible only to the main thread. */
private Map<Integer, TelephonyManager> mSubIdTelephonyManagerMap = new HashMap<>(); 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 TelephonyManager mTelephonyManager;
private ConnectivityManager mConnectivityManager; private ConnectivityManager mConnectivityManager;
private CarrierConfigTracker mCarrierConfigTracker; private CarrierConfigTracker mCarrierConfigTracker;
private TelephonyDisplayInfo mTelephonyDisplayInfo =
new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_UNKNOWN,
TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE);
private Handler mHandler; private Handler mHandler;
private Handler mWorkerHandler; private Handler mWorkerHandler;
private MobileMappings.Config mConfig = null; private MobileMappings.Config mConfig = null;
@@ -190,8 +197,6 @@ public class InternetDialogController implements AccessPointController.AccessPoi
@VisibleForTesting @VisibleForTesting
protected SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangedListener; protected SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangedListener;
@VisibleForTesting @VisibleForTesting
protected InternetTelephonyCallback mInternetTelephonyCallback;
@VisibleForTesting
protected WifiUtils.InternetIconInjector mWifiIconInjector; protected WifiUtils.InternetIconInjector mWifiIconInjector;
@VisibleForTesting @VisibleForTesting
protected boolean mCanConfigWifi; protected boolean mCanConfigWifi;
@@ -290,8 +295,10 @@ public class InternetDialogController implements AccessPointController.AccessPoi
mConfig = MobileMappings.Config.readConfig(mContext); mConfig = MobileMappings.Config.readConfig(mContext);
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mDefaultDataSubId); mTelephonyManager = mTelephonyManager.createForSubscriptionId(mDefaultDataSubId);
mSubIdTelephonyManagerMap.put(mDefaultDataSubId, mTelephonyManager); mSubIdTelephonyManagerMap.put(mDefaultDataSubId, mTelephonyManager);
mInternetTelephonyCallback = new InternetTelephonyCallback(); InternetTelephonyCallback telephonyCallback =
mTelephonyManager.registerTelephonyCallback(mExecutor, mInternetTelephonyCallback); new InternetTelephonyCallback(mDefaultDataSubId);
mSubIdTelephonyCallbackMap.put(mDefaultDataSubId, telephonyCallback);
mTelephonyManager.registerTelephonyCallback(mExecutor, telephonyCallback);
// Listen the connectivity changes // Listen the connectivity changes
mConnectivityManager.registerDefaultNetworkCallback(mConnectivityManagerNetworkCallback); mConnectivityManager.registerDefaultNetworkCallback(mConnectivityManagerNetworkCallback);
mCanConfigWifi = canConfigWifi; mCanConfigWifi = canConfigWifi;
@@ -304,7 +311,12 @@ public class InternetDialogController implements AccessPointController.AccessPoi
} }
mBroadcastDispatcher.unregisterReceiver(mConnectionStateReceiver); mBroadcastDispatcher.unregisterReceiver(mConnectionStateReceiver);
for (TelephonyManager tm : mSubIdTelephonyManagerMap.values()) { 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( mSubscriptionManager.removeOnSubscriptionsChangedListener(
mOnSubscriptionsChangedListener); mOnSubscriptionsChangedListener);
@@ -623,7 +635,9 @@ public class InternetDialogController implements AccessPointController.AccessPoi
int subId = subInfo.getSubscriptionId(); int subId = subInfo.getSubscriptionId();
if (mSubIdTelephonyManagerMap.get(subId) == null) { if (mSubIdTelephonyManagerMap.get(subId) == null) {
TelephonyManager secondaryTm = mTelephonyManager.createForSubscriptionId(subId); 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); mSubIdTelephonyManagerMap.put(subId, secondaryTm);
} }
return subId; return subId;
@@ -637,8 +651,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
} }
String getMobileNetworkSummary(int subId) { String getMobileNetworkSummary(int subId) {
String description = getNetworkTypeDescription(mContext, mConfig, String description = getNetworkTypeDescription(mContext, mConfig, subId);
mTelephonyDisplayInfo, subId);
return getMobileSummary(mContext, description, subId); return getMobileSummary(mContext, description, subId);
} }
@@ -646,7 +659,9 @@ public class InternetDialogController implements AccessPointController.AccessPoi
* Get currently description of mobile network type. * Get currently description of mobile network type.
*/ */
private String getNetworkTypeDescription(Context context, MobileMappings.Config config, 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); String iconKey = getIconKey(telephonyDisplayInfo);
if (mapIconSets(config) == null || mapIconSets(config).get(iconKey) == null) { if (mapIconSets(config) == null || mapIconSets(config).get(iconKey) == null) {
@@ -725,11 +740,10 @@ public class InternetDialogController implements AccessPointController.AccessPoi
Intent getSubSettingIntent(int subId) { Intent getSubSettingIntent(int subId) {
final Intent intent = new Intent(Settings.ACTION_NETWORK_OPERATOR_SETTINGS); final Intent intent = new Intent(Settings.ACTION_NETWORK_OPERATOR_SETTINGS);
final Bundle fragmentArgs = new Bundle(); final Bundle fragmentArgs = new Bundle();
// Special contract for Settings to highlight permission row // Special contract for Settings to highlight permission row
fragmentArgs.putString(SETTINGS_EXTRA_FRAGMENT_ARG_KEY, AUTO_DATA_SWITCH_SETTING_R_ID); 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); intent.putExtra(SETTINGS_EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs);
return intent; return intent;
} }
@@ -1054,6 +1068,11 @@ public class InternetDialogController implements AccessPointController.AccessPoi
TelephonyCallback.SignalStrengthsListener, TelephonyCallback.SignalStrengthsListener,
TelephonyCallback.UserMobileDataStateListener { TelephonyCallback.UserMobileDataStateListener {
private final int mSubId;
private InternetTelephonyCallback(int subId) {
mSubId = subId;
}
@Override @Override
public void onServiceStateChanged(@NonNull ServiceState serviceState) { public void onServiceStateChanged(@NonNull ServiceState serviceState) {
mCallback.onServiceStateChanged(serviceState); mCallback.onServiceStateChanged(serviceState);
@@ -1071,7 +1090,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
@Override @Override
public void onDisplayInfoChanged(@NonNull TelephonyDisplayInfo telephonyDisplayInfo) { public void onDisplayInfoChanged(@NonNull TelephonyDisplayInfo telephonyDisplayInfo) {
mTelephonyDisplayInfo = telephonyDisplayInfo; mSubIdTelephonyDisplayInfoMap.put(mSubId, telephonyDisplayInfo);
mCallback.onDisplayInfoChanged(telephonyDisplayInfo); mCallback.onDisplayInfoChanged(telephonyDisplayInfo);
} }
@@ -1196,19 +1215,30 @@ public class InternetDialogController implements AccessPointController.AccessPoi
} }
return; return;
} }
mDefaultDataSubId = defaultDataSubId;
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "DDS: defaultDataSubId:" + mDefaultDataSubId); Log.d(TAG, "DDS: defaultDataSubId:" + defaultDataSubId);
} }
if (SubscriptionManager.isUsableSubscriptionId(mDefaultDataSubId)) { if (SubscriptionManager.isUsableSubscriptionId(defaultDataSubId)) {
mTelephonyManager.unregisterTelephonyCallback(mInternetTelephonyCallback); // clean up old defaultDataSubId
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mDefaultDataSubId); TelephonyCallback oldCallback = mSubIdTelephonyCallbackMap.get(mDefaultDataSubId);
mSubIdTelephonyManagerMap.put(mDefaultDataSubId, mTelephonyManager); if (oldCallback != null) {
mTelephonyManager.registerTelephonyCallback(mHandler::post, mTelephonyManager.unregisterTelephonyCallback(oldCallback);
mInternetTelephonyCallback); } else if (DEBUG) {
mCallback.onSubscriptionsChanged(mDefaultDataSubId); 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() { public WifiUtils.InternetIconInjector getWifiIconInjector() {

View File

@@ -31,6 +31,7 @@ import static org.mockito.Mockito.when;
import android.animation.Animator; import android.animation.Animator;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
@@ -40,6 +41,7 @@ import android.telephony.ServiceState;
import android.telephony.SignalStrength; import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyDisplayInfo;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.testing.AndroidTestingRunner; import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper; import android.testing.TestableLooper;
@@ -85,6 +87,7 @@ import org.mockito.quality.Strictness;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
@SmallTest @SmallTest
@RunWith(AndroidTestingRunner.class) @RunWith(AndroidTestingRunner.class)
@@ -753,15 +756,34 @@ public class InternetDialogControllerTest extends SysuiTestCase {
@Test @Test
public void getMobileNetworkSummary() { public void getMobileNetworkSummary() {
mFlags.set(Flags.QS_SECONDARY_DATA_SUB_INFO, true); 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); 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(SUB_ID2).when(spyController).getActiveAutoSwitchNonDdsSubId();
doReturn(true).when(spyController).isMobileDataEnabled(); doReturn(true).when(spyController).isMobileDataEnabled();
doReturn(true).when(spyController).activeNetworkIsCellular(); doReturn(true).when(spyController).activeNetworkIsCellular();
String dds = spyController.getMobileNetworkSummary(SUB_ID); String dds = spyController.getMobileNetworkSummary(SUB_ID);
String nonDds = spyController.getMobileNetworkSummary(SUB_ID2); 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).contains(mContext.getString(R.string.mobile_data_poor_connection));
assertThat(dds).isNotEqualTo(nonDds); assertThat(ddsNetworkType).isNotEqualTo(nonDdsNetworkType);
} }
@Test @Test