Merge "Wrap subManager creation with createForAllProfiles" into main

This commit is contained in:
Ling Ma
2024-01-23 18:03:11 +00:00
committed by Android (Google) Code Review
15 changed files with 34 additions and 38 deletions

View File

@@ -174,7 +174,8 @@ public abstract class ActiveSubscriptionsListener
*/
public SubscriptionManager getSubscriptionManager() {
if (mSubscriptionManager == null) {
mSubscriptionManager = mContext.getSystemService(SubscriptionManager.class);
mSubscriptionManager = mContext.getSystemService(SubscriptionManager.class)
.createForAllUserProfiles();
}
return mSubscriptionManager;
}

View File

@@ -153,7 +153,8 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
mPreferenceGroupKey = preferenceGroupKey;
mStartOrder = startOrder;
mTelephonyManager = context.getSystemService(TelephonyManager.class);
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
mSubscriptionManager = context.getSystemService(SubscriptionManager.class)
.createForAllUserProfiles();
mWifiManager = context.getSystemService(WifiManager.class);
mSubscriptionPreferences = new ArrayMap<>();
mSubscriptionsListener = new SubscriptionsChangeListener(context, this);

View File

@@ -101,7 +101,7 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
}
SubscriptionManager subscriptionManager = getContext().getSystemService(
SubscriptionManager.class);
SubscriptionManager.class).createForAllUserProfiles();
mActiveSubInfos = SubscriptionUtil.getActiveSubscriptions(subscriptionManager);
// To check whether the esim slot's port is active. If yes, skip setSlotMapping. If no,

View File

@@ -92,7 +92,7 @@ public class SwitchToRemovableSlotSidecar extends EuiccOperationSidecar
mPhysicalSlotId = physicalSlotId;
mRemovedSubInfo = removedSubInfo;
SubscriptionManager subscriptionManager =
getContext().getSystemService(SubscriptionManager.class);
getContext().getSystemService(SubscriptionManager.class).createForAllUserProfiles();
if (!mTelephonyManager.isMultiSimEnabled()
&& SubscriptionUtil.getActiveSubscriptions(subscriptionManager).stream().anyMatch(
SubscriptionInfo::isEmbedded)) {

View File

@@ -162,7 +162,7 @@ public class UiccSlotUtil {
Log.d(TAG, "The SimSlotMapping: " + uiccSlotMappings);
SubscriptionManager subscriptionManager = context.getSystemService(
SubscriptionManager.class);
SubscriptionManager.class).createForAllUserProfiles();
int excludedLogicalSlotIndex = getExcludedLogicalSlotIndex(uiccSlotMappings,
SubscriptionUtil.getActiveSubscriptions(subscriptionManager), removedSubInfo,
telMgr.isMultiSimEnabled());
@@ -203,7 +203,7 @@ public class UiccSlotUtil {
}
SubscriptionManager subscriptionManager = context.getSystemService(
SubscriptionManager.class);
SubscriptionManager.class).createForAllUserProfiles();
int excludedLogicalSlotIndex = getExcludedLogicalSlotIndex(uiccSlotMappings,
SubscriptionUtil.getActiveSubscriptions(subscriptionManager), removedSubInfo,
telMgr.isMultiSimEnabled());
@@ -222,7 +222,7 @@ public class UiccSlotUtil {
List<UiccCardInfo> uiccCardInfos = telMgr.getUiccCardsInfo();
ImmutableList<UiccSlotInfo> slotInfos = UiccSlotUtil.getSlotInfos(telMgr);
SubscriptionManager subscriptionManager = context.getSystemService(
SubscriptionManager.class);
SubscriptionManager.class).createForAllUserProfiles();
SubscriptionInfo subInfo = SubscriptionUtil.getSubById(subscriptionManager, subId);
// checking whether this is the removable esim. If it is, then return the removable slot id.

View File

@@ -146,7 +146,7 @@ public class SelectableSubscriptions implements Callable<List<SubscriptionAnnota
}
protected SubscriptionManager getSubscriptionManager(Context context) {
return context.getSystemService(SubscriptionManager.class);
return context.getSystemService(SubscriptionManager.class).createForAllUserProfiles();
}
protected List<SubscriptionInfo> getAvailableSubInfoList(Context context) {

View File

@@ -357,7 +357,7 @@ public class MobileNetworkUtils {
final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class)
.createForSubscriptionId(subId);
final SubscriptionManager subscriptionManager = context.getSystemService(
SubscriptionManager.class);
SubscriptionManager.class).createForAllUserProfiles();
telephonyManager.setDataEnabled(enabled);
if (disableOtherSubscriptions) {
@@ -666,39 +666,26 @@ public class MobileNetworkUtils {
* 2. Similar design which aligned with operator name displayed in status bar
*/
public static CharSequence getCurrentCarrierNameForDisplay(Context context, int subId) {
final SubscriptionManager sm = context.getSystemService(SubscriptionManager.class);
if (sm != null) {
final SubscriptionInfo subInfo = getSubscriptionInfo(sm, subId);
if (subInfo != null) {
return subInfo.getCarrierName();
}
final SubscriptionInfo subInfo = getSubscriptionInfo(context, subId);
if (subInfo != null) {
return subInfo.getCarrierName();
}
return getOperatorNameFromTelephonyManager(context);
}
public static CharSequence getCurrentCarrierNameForDisplay(Context context) {
final SubscriptionManager sm = context.getSystemService(SubscriptionManager.class);
if (sm != null) {
final int subId = sm.getDefaultSubscriptionId();
final SubscriptionInfo subInfo = getSubscriptionInfo(sm, subId);
if (subInfo != null) {
return subInfo.getCarrierName();
}
final SubscriptionInfo subInfo = getSubscriptionInfo(context,
SubscriptionManager.getDefaultSubscriptionId());
if (subInfo != null) {
return subInfo.getCarrierName();
}
return getOperatorNameFromTelephonyManager(context);
}
private static SubscriptionInfo getSubscriptionInfo(SubscriptionManager subManager, int subId) {
List<SubscriptionInfo> subInfos = subManager.getActiveSubscriptionInfoList();
if (subInfos == null) {
return null;
}
for (SubscriptionInfo subInfo : subInfos) {
if (subInfo.getSubscriptionId() == subId) {
return subInfo;
}
}
return null;
private static @Nullable SubscriptionInfo getSubscriptionInfo(Context context, int subId) {
SubscriptionManager sm = context.getSystemService(SubscriptionManager.class);
if (sm == null) return null;
return sm.createForAllUserProfiles().getActiveSubscriptionInfo(subId);
}
private static String getOperatorNameFromTelephonyManager(Context context) {
@@ -712,7 +699,7 @@ public class MobileNetworkUtils {
private static int[] getActiveSubscriptionIdList(Context context) {
final SubscriptionManager subscriptionManager = context.getSystemService(
SubscriptionManager.class);
SubscriptionManager.class).createForAllUserProfiles();
final List<SubscriptionInfo> subInfoList =
subscriptionManager.getActiveSubscriptionInfoList();
if (subInfoList == null) {

View File

@@ -79,7 +79,8 @@ public class NetworkProviderWifiCallingGroup extends
String preferenceGroupKey) {
super(context);
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
mSubscriptionManager = context.getSystemService(SubscriptionManager.class)
.createForAllUserProfiles();
mPreferenceGroupKey = preferenceGroupKey;
mWifiCallingForSubPreferences = new ArrayMap<>();
setSubscriptionInfoList(context);

View File

@@ -43,7 +43,8 @@ public class SubscriptionActionDialogActivity extends FragmentActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSubscriptionManager = getSystemService(SubscriptionManager.class);
mSubscriptionManager = getSystemService(SubscriptionManager.class)
.createForAllUserProfiles();
setProgressState(PROGRESS_IS_NOT_SHOWING);
}

View File

@@ -49,7 +49,8 @@ class OpenNetworkSelectPagePreferenceControllerTest {
}
private val mockSubscriptionManager = mock<SubscriptionManager> {
on { activeSubscriptionInfoList } doAnswer { listOf(subscriptionInfo) }
on { createForAllUserProfiles() } doReturn mock
on { getActiveSubscriptionInfo(SUB_ID) } doReturn subscriptionInfo
}
private val context: Context = spy(ApplicationProvider.getApplicationContext()) {

View File

@@ -77,6 +77,7 @@ public class ActiveSubscriptionsListenerTest {
mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
doReturn(mSubscriptionManager).when(mSubscriptionManager).createForAllUserProfiles();
mActiveSubscriptions = new ArrayList<SubscriptionInfo>();
addMockSubscription(SUB_ID1);

View File

@@ -77,6 +77,7 @@ public class UiccSlotUtilTest {
when(mTelephonyManager.getUiccCardsInfo()).thenReturn(mUiccCardInfo);
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
when(mSubscriptionManager.createForAllUserProfiles()).thenReturn(mSubscriptionManager);
when(mSubscriptionManager.getAllSubscriptionInfoList()).thenReturn(mSubscriptionInfoList);
}

View File

@@ -113,6 +113,7 @@ public class MobileNetworkUtilsTest {
mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
when(mSubscriptionManager.createForAllUserProfiles()).thenReturn(mSubscriptionManager);
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
when(mTelephonyManager.createForSubscriptionId(SUB_ID_1)).thenReturn(mTelephonyManager);
when(mTelephonyManager.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2);

View File

@@ -37,7 +37,6 @@ import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.FeatureFlagUtils;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceManager;
@@ -100,6 +99,7 @@ public class NetworkProviderWifiCallingGroupTest {
when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(
mCarrierConfigManager);
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
when(mSubscriptionManager.createForAllUserProfiles()).thenReturn(mSubscriptionManager);
when(mContext.getSystemService(TelecomManager.class)).thenReturn(mTelecomManager);
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);

View File

@@ -55,6 +55,7 @@ public class TelephonyBasePreferenceControllerTest {
mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getSystemService(SubscriptionManager.class))
.thenReturn(mSubscriptionManager);
when(mSubscriptionManager.createForAllUserProfiles()).thenReturn(mSubscriptionManager);
when(mSubscriptionInfo.getSubscriptionId()).thenReturn(VALID_SUB_ID);
mPreferenceController = new TestPreferenceController(mContext, "prefKey");
}