Merge "Add getSubscriptionId API"
This commit is contained in:
@@ -558,11 +558,10 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
|||||||
if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
|
if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
|
||||||
int numPhones = getTelephonyManager().getActiveModemCount();
|
int numPhones = getTelephonyManager().getActiveModemCount();
|
||||||
for (int phoneId = 0; phoneId < numPhones; phoneId++) {
|
for (int phoneId = 0; phoneId < numPhones; phoneId++) {
|
||||||
int[] subIds = SubscriptionManager.getSubId(phoneId);
|
int subId = SubscriptionManager.getSubscriptionId(phoneId);
|
||||||
int subId =
|
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||||
(subIds != null) && (subIds.length > 0)
|
subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
|
||||||
? subIds[0]
|
}
|
||||||
: SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
|
|
||||||
TelephonyRegistry.this.notifyCellLocationForSubscriber(
|
TelephonyRegistry.this.notifyCellLocationForSubscriber(
|
||||||
subId, mCellIdentity[phoneId], true /* hasUserSwitched */);
|
subId, mCellIdentity[phoneId], true /* hasUserSwitched */);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ import android.telephony.SubscriptionManager;
|
|||||||
import android.telephony.TelephonyRegistryManager;
|
import android.telephony.TelephonyRegistryManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.util.ArrayUtils;
|
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
@@ -237,12 +235,7 @@ public abstract class CarrierService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void getCarrierConfig(int phoneId, CarrierIdentifier id, ResultReceiver result) {
|
public void getCarrierConfig(int phoneId, CarrierIdentifier id, ResultReceiver result) {
|
||||||
try {
|
try {
|
||||||
int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
int subId = SubscriptionManager.getSubscriptionId(phoneId);
|
||||||
int[] subIds = SubscriptionManager.getSubId(phoneId);
|
|
||||||
if (!ArrayUtils.isEmpty(subIds)) {
|
|
||||||
// There should be at most one active subscription mapping to the phoneId.
|
|
||||||
subId = subIds[0];
|
|
||||||
}
|
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
data.putParcelable(KEY_CONFIG_BUNDLE, CarrierService.this.onLoadConfig(subId, id));
|
data.putParcelable(KEY_CONFIG_BUNDLE, CarrierService.this.onLoadConfig(subId, id));
|
||||||
result.send(RESULT_OK, data);
|
result.send(RESULT_OK, data);
|
||||||
|
|||||||
@@ -266,6 +266,11 @@ public class SubscriptionManager {
|
|||||||
CACHE_KEY_SLOT_INDEX_PROPERTY,
|
CACHE_KEY_SLOT_INDEX_PROPERTY,
|
||||||
INVALID_SIM_SLOT_INDEX);
|
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 */
|
/** Cache depends on getDefaultSubId, so we use the defaultSubId cache key */
|
||||||
private static IntegerPropertyInvalidatedCache<Integer> sPhoneIdCache =
|
private static IntegerPropertyInvalidatedCache<Integer> sPhoneIdCache =
|
||||||
new IntegerPropertyInvalidatedCache<>(ISub::getPhoneId,
|
new IntegerPropertyInvalidatedCache<>(ISub::getPhoneId,
|
||||||
@@ -2125,7 +2130,7 @@ public class SubscriptionManager {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public int[] getSubscriptionIds(int slotIndex) {
|
public int[] getSubscriptionIds(int slotIndex) {
|
||||||
return getSubId(slotIndex);
|
return new int[]{getSubscriptionId(slotIndex)};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -2150,6 +2155,22 @@ public class SubscriptionManager {
|
|||||||
return subId;
|
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 */
|
/** @hide */
|
||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
|
||||||
public static int getPhoneId(int subId) {
|
public static int getPhoneId(int subId) {
|
||||||
@@ -2404,9 +2425,9 @@ public class SubscriptionManager {
|
|||||||
/** @hide */
|
/** @hide */
|
||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
|
||||||
public static void putPhoneIdAndSubIdExtra(Intent intent, int phoneId) {
|
public static void putPhoneIdAndSubIdExtra(Intent intent, int phoneId) {
|
||||||
int[] subIds = SubscriptionManager.getSubId(phoneId);
|
int subId = SubscriptionManager.getSubscriptionId(phoneId);
|
||||||
if (subIds != null && subIds.length > 0) {
|
if (isValidSubscriptionId(subId)) {
|
||||||
putPhoneIdAndSubIdExtra(intent, phoneId, subIds[0]);
|
putPhoneIdAndSubIdExtra(intent, phoneId, subId);
|
||||||
} else {
|
} else {
|
||||||
logd("putPhoneIdAndSubIdExtra: no valid subs");
|
logd("putPhoneIdAndSubIdExtra: no valid subs");
|
||||||
intent.putExtra(PhoneConstants.PHONE_KEY, phoneId);
|
intent.putExtra(PhoneConstants.PHONE_KEY, phoneId);
|
||||||
|
|||||||
@@ -2375,47 +2375,6 @@ public class TelephonyManager {
|
|||||||
return getNaiBySubscriberId(getSubId());
|
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) {
|
private String getNaiBySubscriberId(int subId) {
|
||||||
try {
|
try {
|
||||||
IPhoneSubInfo info = getSubscriberInfoService();
|
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. */
|
/** Data connection activity: No traffic. */
|
||||||
public static final int DATA_ACTIVITY_NONE = 0x00000000;
|
public static final int DATA_ACTIVITY_NONE = 0x00000000;
|
||||||
/** Data connection activity: Currently receiving IP PPP traffic. */
|
/** Data connection activity: Currently receiving IP PPP traffic. */
|
||||||
|
|||||||
@@ -246,6 +246,8 @@ interface ISub {
|
|||||||
|
|
||||||
int[] getSubIds(int slotIndex);
|
int[] getSubIds(int slotIndex);
|
||||||
|
|
||||||
|
int getSubId(int slotIndex);
|
||||||
|
|
||||||
int getDefaultSubId();
|
int getDefaultSubId();
|
||||||
|
|
||||||
int clearSubInfo();
|
int clearSubInfo();
|
||||||
|
|||||||
Reference in New Issue
Block a user