summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/TelephonyRegistry.java9
-rw-r--r--telephony/java/android/service/carrier/CarrierService.java9
-rw-r--r--telephony/java/android/telephony/SubscriptionManager.java29
-rw-r--r--telephony/java/android/telephony/TelephonyManager.java81
-rw-r--r--telephony/java/com/android/internal/telephony/ISub.aidl2
5 files changed, 32 insertions, 98 deletions
diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java
index 2652ebec5255..ca86021cd629 100644
--- a/services/core/java/com/android/server/TelephonyRegistry.java
+++ b/services/core/java/com/android/server/TelephonyRegistry.java
@@ -558,11 +558,10 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
int numPhones = getTelephonyManager().getActiveModemCount();
for (int phoneId = 0; phoneId < numPhones; phoneId++) {
- int[] subIds = SubscriptionManager.getSubId(phoneId);
- int subId =
- (subIds != null) && (subIds.length > 0)
- ? subIds[0]
- : SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
+ int subId = SubscriptionManager.getSubscriptionId(phoneId);
+ if (!SubscriptionManager.isValidSubscriptionId(subId)) {
+ subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
+ }
TelephonyRegistry.this.notifyCellLocationForSubscriber(
subId, mCellIdentity[phoneId], true /* hasUserSwitched */);
}
diff --git a/telephony/java/android/service/carrier/CarrierService.java b/telephony/java/android/service/carrier/CarrierService.java
index ae91d4d9b595..1c531486f3b1 100644
--- a/telephony/java/android/service/carrier/CarrierService.java
+++ b/telephony/java/android/service/carrier/CarrierService.java
@@ -28,8 +28,6 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyRegistryManager;
import android.util.Log;
-import com.android.internal.util.ArrayUtils;
-
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -237,12 +235,7 @@ public abstract class CarrierService extends Service {
@Override
public void getCarrierConfig(int phoneId, CarrierIdentifier id, ResultReceiver result) {
try {
- int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
- int[] subIds = SubscriptionManager.getSubId(phoneId);
- if (!ArrayUtils.isEmpty(subIds)) {
- // There should be at most one active subscription mapping to the phoneId.
- subId = subIds[0];
- }
+ int subId = SubscriptionManager.getSubscriptionId(phoneId);
Bundle data = new Bundle();
data.putParcelable(KEY_CONFIG_BUNDLE, CarrierService.this.onLoadConfig(subId, id));
result.send(RESULT_OK, data);
diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java
index 713522b6ba8f..eade18652db4 100644
--- a/telephony/java/android/telephony/SubscriptionManager.java
+++ b/telephony/java/android/telephony/SubscriptionManager.java
@@ -266,6 +266,11 @@ public class SubscriptionManager {
CACHE_KEY_SLOT_INDEX_PROPERTY,
INVALID_SIM_SLOT_INDEX);
+ private static IntegerPropertyInvalidatedCache<Integer> sSubIdCache =
+ new IntegerPropertyInvalidatedCache<>(ISub::getSubId,
+ CACHE_KEY_SLOT_INDEX_PROPERTY,
+ INVALID_SUBSCRIPTION_ID);
+
/** Cache depends on getDefaultSubId, so we use the defaultSubId cache key */
private static IntegerPropertyInvalidatedCache<Integer> sPhoneIdCache =
new IntegerPropertyInvalidatedCache<>(ISub::getPhoneId,
@@ -2125,7 +2130,7 @@ public class SubscriptionManager {
*/
@Nullable
public int[] getSubscriptionIds(int slotIndex) {
- return getSubId(slotIndex);
+ return new int[]{getSubscriptionId(slotIndex)};
}
/** @hide */
@@ -2150,6 +2155,22 @@ public class SubscriptionManager {
return subId;
}
+ /**
+ * Get the subscription id for specified slot index.
+ *
+ * @param slotIndex Logical SIM slot index.
+ * @return The subscription id. {@link #INVALID_SUBSCRIPTION_ID} if SIM is absent.
+ *
+ * @hide
+ */
+ public static int getSubscriptionId(int slotIndex) {
+ if (!isValidSlotIndex(slotIndex)) {
+ return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
+ }
+
+ return sSubIdCache.query(slotIndex);
+ }
+
/** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public static int getPhoneId(int subId) {
@@ -2404,9 +2425,9 @@ public class SubscriptionManager {
/** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public static void putPhoneIdAndSubIdExtra(Intent intent, int phoneId) {
- int[] subIds = SubscriptionManager.getSubId(phoneId);
- if (subIds != null && subIds.length > 0) {
- putPhoneIdAndSubIdExtra(intent, phoneId, subIds[0]);
+ int subId = SubscriptionManager.getSubscriptionId(phoneId);
+ if (isValidSubscriptionId(subId)) {
+ putPhoneIdAndSubIdExtra(intent, phoneId, subId);
} else {
logd("putPhoneIdAndSubIdExtra: no valid subs");
intent.putExtra(PhoneConstants.PHONE_KEY, phoneId);
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index 1654848e3f3c..7a19d36ba743 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -2375,47 +2375,6 @@ public class TelephonyManager {
return getNaiBySubscriberId(getSubId());
}
- /**
- * Returns the NAI. Return null if NAI is not available.
- *
- * <p>Starting with API level 29, persistent device identifiers are guarded behind additional
- * restrictions, and apps are recommended to use resettable identifiers (see <a
- * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This
- * method can be invoked if one of the following requirements is met:
- * <ul>
- * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this
- * is a privileged permission that can only be granted to apps preloaded on the device.
- * <li>If the calling app is the device owner of a fully-managed device, a profile
- * owner of an organization-owned device, or their delegates (see {@link
- * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}).
- * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
- * <li>If the calling app is the default SMS role holder (see {@link
- * RoleManager#isRoleHeld(String)}).
- * </ul>
- *
- * <p>If the calling app does not meet one of these requirements then this method will behave
- * as follows:
- *
- * <ul>
- * <li>If the calling app's target SDK is API level 28 or lower and the app has the
- * READ_PHONE_STATE permission then null is returned.</li>
- * <li>If the calling app's target SDK is API level 28 or lower and the app does not have
- * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or
- * higher, then a SecurityException is thrown.</li>
- * </ul>
- *
- * @param slotIndex of which Nai is returned
- */
- /** {@hide}*/
- @UnsupportedAppUsage
- public String getNai(int slotIndex) {
- int[] subId = SubscriptionManager.getSubId(slotIndex);
- if (subId == null) {
- return null;
- }
- return getNaiBySubscriberId(subId[0]);
- }
-
private String getNaiBySubscriberId(int subId) {
try {
IPhoneSubInfo info = getSubscriberInfoService();
@@ -6130,46 +6089,6 @@ public class TelephonyManager {
}
}
- /**
- * @hide
- */
- @UnsupportedAppUsage
- private IPhoneSubInfo getSubscriberInfo() {
- return getSubscriberInfoService();
- }
-
- /**
- * Returns the Telephony call state for calls on a specific SIM slot.
- * <p>
- * Note: This method considers ONLY telephony/mobile calls, where {@link #getCallState()}
- * considers the state of calls from other {@link android.telecom.ConnectionService}
- * implementations.
- * <p>
- * Requires Permission:
- * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} for applications
- * targeting API level 31+ or that the calling application has carrier privileges
- * (see {@link #hasCarrierPrivileges()}).
- *
- * @param slotIndex the SIM slot index to check call state for.
- * @hide
- */
- @RequiresPermission(value = android.Manifest.permission.READ_PHONE_STATE, conditional = true)
- public @CallState int getCallStateForSlot(int slotIndex) {
- try {
- int[] subId = SubscriptionManager.getSubId(slotIndex);
- ITelephony telephony = getITelephony();
- if (telephony == null || subId == null || subId.length == 0) {
- return CALL_STATE_IDLE;
- }
- return telephony.getCallStateForSubscription(subId[0], mContext.getPackageName(),
- mContext.getAttributionTag());
- } catch (RemoteException | NullPointerException ex) {
- // the phone process is restarting.
- return CALL_STATE_IDLE;
- }
- }
-
-
/** Data connection activity: No traffic. */
public static final int DATA_ACTIVITY_NONE = 0x00000000;
/** Data connection activity: Currently receiving IP PPP traffic. */
diff --git a/telephony/java/com/android/internal/telephony/ISub.aidl b/telephony/java/com/android/internal/telephony/ISub.aidl
index 4fef4d7df87f..fa1ced54bef2 100644
--- a/telephony/java/com/android/internal/telephony/ISub.aidl
+++ b/telephony/java/com/android/internal/telephony/ISub.aidl
@@ -246,6 +246,8 @@ interface ISub {
int[] getSubIds(int slotIndex);
+ int getSubId(int slotIndex);
+
int getDefaultSubId();
int clearSubInfo();