diff --git a/core/api/current.txt b/core/api/current.txt index ab4a42f7fd090..d5b0dd34c1daa 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -44334,6 +44334,7 @@ package android.telephony { method @Deprecated public int getPhoneCount(); method public int getPhoneType(); method @RequiresPermission(anyOf={"android.permission.READ_PRIVILEGED_PHONE_STATE", android.Manifest.permission.READ_PHONE_STATE}) public int getPreferredOpportunisticDataSubscription(); + method @NonNull public String getPrimaryImei(); method @Nullable @RequiresPermission(allOf={android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.ACCESS_COARSE_LOCATION}) public android.telephony.ServiceState getServiceState(); method @Nullable @RequiresPermission(allOf={android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.ACCESS_COARSE_LOCATION}) public android.telephony.ServiceState getServiceState(int); method @Nullable public android.telephony.SignalStrength getSignalStrength(); diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index c926a23f55ce0..665d3d0182ab9 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -17821,4 +17821,47 @@ public class TelephonyManager { ex.rethrowFromSystemServer(); } } + + /* + * Returns the primary IMEI (International Mobile Equipment Identity) of the device as + * mentioned in GSMA TS.37. {@link #getImei(int)} returns the IMEI that belongs to the selected + * slotID whereas this API {@link #getPrimaryImei()} returns primary IMEI of the device. + * A single SIM device with only one IMEI will be set by default as primary IMEI. + * A multi-SIM device with multiple IMEIs will have one of the IMEIs set as primary as + * mentioned in GSMA TS37_2.2_REQ_8. + * + *

Requires one of the following permissions + *

+ * + * @return Primary IMEI of type string + * @throws UnsupportedOperationException if the radio doesn't support this feature. + * @throws SecurityException if the caller does not have the required permission/privileges + */ + @NonNull + @RequiresFeature(PackageManager.FEATURE_TELEPHONY_GSM) + public String getPrimaryImei() { + try { + ITelephony telephony = getITelephony(); + if (telephony == null) { + Rlog.e(TAG, "getPrimaryImei(): IPhoneSubInfo instance is NULL"); + throw new IllegalStateException("Telephony service not available."); + } + return telephony.getPrimaryImei(getOpPackageName(), getAttributionTag()); + } catch (RemoteException ex) { + Rlog.e(TAG, "getPrimaryImei() RemoteException : " + ex); + throw ex.rethrowAsRuntimeException(); + } + } } diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 9445d0763c987..d1da70da40d9e 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -1319,6 +1319,16 @@ interface ITelephony { */ String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId); + /** + * Returns the primary IMEI of the device + * + * @param callingPackage The package name of the caller + * @param callingFeatureId The feature Id of the calling package + * @throws UnsupportedOperationException if the radio doesn't support this feature. + * @throws SecurityException if the caller does not have the required permission/privileges + */ + String getPrimaryImei(String callingPackage, String callingFeatureId); + /** * Returns the Type Allocation Code from the IMEI for the given slot. * diff --git a/telephony/java/com/android/internal/telephony/RILConstants.java b/telephony/java/com/android/internal/telephony/RILConstants.java index a1257e39f6685..37e26f647a964 100644 --- a/telephony/java/com/android/internal/telephony/RILConstants.java +++ b/telephony/java/com/android/internal/telephony/RILConstants.java @@ -500,7 +500,7 @@ public interface RILConstants { int RIL_REQUEST_GET_SIM_PHONEBOOK_CAPACITY = 149; int RIL_REQUEST_GET_SIM_PHONEBOOK_RECORDS = 150; int RIL_REQUEST_UPDATE_SIM_PHONEBOOK_RECORD = 151; - + int RIL_REQUEST_DEVICE_IMEI = 152; /* The following requests are not defined in RIL.h */ int RIL_REQUEST_HAL_NON_RIL_BASE = 200; int RIL_REQUEST_GET_SLOT_STATUS = 200;