Wrap subManager creation with createForAllProfiles

Since U, a sub can be associated with a particular profile, and thus in V we enforce filtering on the caller and only show the subs that are associated with the caller.
However, in some cases the caller indeed needs to see all subs regardless of its association, e.g. sysUI. Therefore, a param isForAllProfile is added to indicate whether the caller intends to see all subs.

Bug: 296076674
Test: voice call + data browsing
Flag: ACONFIG com.android.internal.telephony.flags.enforce_subscription_user_filter
 DEVELOPMENT
Change-Id: Ib5ccc841029a32ae9cf25d7a65b156e363d6b139
This commit is contained in:
Ling Ma
2024-01-19 23:15:19 +00:00
parent 76144abc19
commit 9c3ad34d6e
15 changed files with 34 additions and 38 deletions

View File

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

View File

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

View File

@@ -101,7 +101,7 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
} }
SubscriptionManager subscriptionManager = getContext().getSystemService( SubscriptionManager subscriptionManager = getContext().getSystemService(
SubscriptionManager.class); SubscriptionManager.class).createForAllUserProfiles();
mActiveSubInfos = SubscriptionUtil.getActiveSubscriptions(subscriptionManager); mActiveSubInfos = SubscriptionUtil.getActiveSubscriptions(subscriptionManager);
// To check whether the esim slot's port is active. If yes, skip setSlotMapping. If no, // 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; mPhysicalSlotId = physicalSlotId;
mRemovedSubInfo = removedSubInfo; mRemovedSubInfo = removedSubInfo;
SubscriptionManager subscriptionManager = SubscriptionManager subscriptionManager =
getContext().getSystemService(SubscriptionManager.class); getContext().getSystemService(SubscriptionManager.class).createForAllUserProfiles();
if (!mTelephonyManager.isMultiSimEnabled() if (!mTelephonyManager.isMultiSimEnabled()
&& SubscriptionUtil.getActiveSubscriptions(subscriptionManager).stream().anyMatch( && SubscriptionUtil.getActiveSubscriptions(subscriptionManager).stream().anyMatch(
SubscriptionInfo::isEmbedded)) { SubscriptionInfo::isEmbedded)) {

View File

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

View File

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

View File

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

View File

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

View File

@@ -49,7 +49,8 @@ class OpenNetworkSelectPagePreferenceControllerTest {
} }
private val mockSubscriptionManager = mock<SubscriptionManager> { 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()) { private val context: Context = spy(ApplicationProvider.getApplicationContext()) {

View File

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

View File

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

View File

@@ -113,6 +113,7 @@ public class MobileNetworkUtilsTest {
mContext = spy(ApplicationProvider.getApplicationContext()); mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager); when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
when(mSubscriptionManager.createForAllUserProfiles()).thenReturn(mSubscriptionManager);
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager); when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
when(mTelephonyManager.createForSubscriptionId(SUB_ID_1)).thenReturn(mTelephonyManager); when(mTelephonyManager.createForSubscriptionId(SUB_ID_1)).thenReturn(mTelephonyManager);
when(mTelephonyManager.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2); 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.SubscriptionInfo;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.util.FeatureFlagUtils;
import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@@ -100,6 +99,7 @@ public class NetworkProviderWifiCallingGroupTest {
when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn( when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(
mCarrierConfigManager); mCarrierConfigManager);
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager); when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
when(mSubscriptionManager.createForAllUserProfiles()).thenReturn(mSubscriptionManager);
when(mContext.getSystemService(TelecomManager.class)).thenReturn(mTelecomManager); when(mContext.getSystemService(TelecomManager.class)).thenReturn(mTelecomManager);
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager); when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager); when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);

View File

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