From d6c684fff43c76dfa9847a7540541e8778ae44ed Mon Sep 17 00:00:00 2001 From: Jordan Liu Date: Fri, 18 Jan 2019 10:29:56 -0800 Subject: [PATCH] Card ID APIs are public These were system API but we should expose them for apps with carrier privileges. Test: manual Bug: 122974656 Change-Id: Ie60e4c580dfa9dd0d7d6fb6b94226661d0620dad --- api/current.txt | 16 +++++++ api/system-current.txt | 16 ------- .../android/telephony/SubscriptionInfo.java | 6 +-- .../android/telephony/TelephonyManager.java | 45 ++++++++++--------- .../java/android/telephony/UiccCardInfo.java | 21 +++++++-- .../internal/telephony/ITelephony.aidl | 31 ++++++++----- 6 files changed, 81 insertions(+), 54 deletions(-) diff --git a/api/current.txt b/api/current.txt index a81d5b18a32d0..eca050b5c86ed 100755 --- a/api/current.txt +++ b/api/current.txt @@ -42815,6 +42815,7 @@ package android.telephony { public class SubscriptionInfo implements android.os.Parcelable { method public android.graphics.Bitmap createIconBitmap(android.content.Context); method public int describeContents(); + method public int getCardId(); method public int getCarrierId(); method public CharSequence getCarrierName(); method public String getCountryIso(); @@ -42928,6 +42929,7 @@ package android.telephony { method public android.telephony.TelephonyManager createForSubscriptionId(int); method @RequiresPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) public java.util.List getAllCellInfo(); method public int getCallState(); + method public int getCardIdForDefaultEuicc(); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) @WorkerThread public android.os.PersistableBundle getCarrierConfig(); method public int getCarrierIdFromSimMccMnc(); method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.ACCESS_COARSE_LOCATION, android.Manifest.permission.ACCESS_FINE_LOCATION}) public android.telephony.CellLocation getCellLocation(); @@ -42975,6 +42977,7 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getSubscriberId(); method public String getTypeAllocationCode(); method public String getTypeAllocationCode(int); + method @RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE") public java.util.List getUiccCardsInfo(); method @Nullable @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getVisualVoicemailPackageName(); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getVoiceMailAlphaTag(); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getVoiceMailNumber(); @@ -43066,6 +43069,7 @@ package android.telephony { field public static final String EXTRA_STATE_RINGING; field public static final String EXTRA_SUBSCRIPTION_ID = "android.telephony.extra.SUBSCRIPTION_ID"; field public static final String EXTRA_VOICEMAIL_NUMBER = "android.telephony.extra.VOICEMAIL_NUMBER"; + field public static final int INVALID_CARD_ID = -1; // 0xffffffff field public static final String METADATA_HIDE_VOICEMAIL_SETTINGS_MENU = "android.telephony.HIDE_VOICEMAIL_SETTINGS_MENU"; field public static final int NETWORK_TYPE_1xRTT = 7; // 0x7 field public static final int NETWORK_TYPE_CDMA = 4; // 0x4 @@ -43133,6 +43137,18 @@ package android.telephony { method public void onResults(java.util.List); } + public final class UiccCardInfo implements android.os.Parcelable { + ctor public UiccCardInfo(boolean, int, String, String, int); + method public int describeContents(); + method public int getCardId(); + method public String getEid(); + method public String getIccId(); + method public int getSlotIndex(); + method public boolean isEuicc(); + method public void writeToParcel(android.os.Parcel, int); + field public static final android.os.Parcelable.Creator CREATOR; + } + public abstract class VisualVoicemailService extends android.app.Service { ctor public VisualVoicemailService(); method public android.os.IBinder onBind(android.content.Intent); diff --git a/api/system-current.txt b/api/system-current.txt index 6d2473673051c..2833299cfe214 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -6053,7 +6053,6 @@ package android.telephony { public class SubscriptionInfo implements android.os.Parcelable { method @Nullable public java.util.List getAccessRules(); - method public int getCardId(); method public int getProfileClass(); } @@ -6112,7 +6111,6 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void enableVideoCalling(boolean); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getAidForAppType(int); method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public java.util.List getAllowedCarriers(int); - method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public int getCardIdForDefaultEuicc(); method public java.util.List getCarrierPackageNamesForIntent(android.content.Intent); method public java.util.List getCarrierPackageNamesForIntentAndPhone(android.content.Intent, int); method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public android.telephony.CarrierRestrictionRules getCarrierRestrictionRules(); @@ -6135,7 +6133,6 @@ package android.telephony { method public int getSimCardState(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getSupportedRadioAccessFamily(); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public java.util.List getTelephonyHistograms(); - method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public android.telephony.UiccCardInfo[] getUiccCardsInfo(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public android.telephony.UiccSlotInfo[] getUiccSlotsInfo(); method @Nullable public android.os.Bundle getVisualVoicemailSettings(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getVoiceActivationState(); @@ -6183,7 +6180,6 @@ package android.telephony { field public static final String EXTRA_SIM_STATE = "android.telephony.extra.SIM_STATE"; field public static final String EXTRA_VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL = "android.telephony.extra.VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL"; field public static final String EXTRA_VOICEMAIL_SCRAMBLED_PIN_STRING = "android.telephony.extra.VOICEMAIL_SCRAMBLED_PIN_STRING"; - field public static final int INVALID_CARD_ID = -1; // 0xffffffff field public static final long MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS = 60000L; // 0xea60L field public static final int NETWORK_MODE_CDMA_EVDO = 4; // 0x4 field public static final int NETWORK_MODE_CDMA_NO_EVDO = 5; // 0x5 @@ -6258,18 +6254,6 @@ package android.telephony { field public static final android.os.Parcelable.Creator CREATOR; } - public class UiccCardInfo implements android.os.Parcelable { - ctor public UiccCardInfo(boolean, int, String, String, int); - method public int describeContents(); - method public int getCardId(); - method public String getEid(); - method public String getIccId(); - method public int getSlotIndex(); - method public boolean isEuicc(); - method public void writeToParcel(android.os.Parcel, int); - field public static final android.os.Parcelable.Creator CREATOR; - } - public class UiccSlotInfo implements android.os.Parcelable { ctor public UiccSlotInfo(boolean, boolean, String, int, int, boolean); method public int describeContents(); diff --git a/telephony/java/android/telephony/SubscriptionInfo.java b/telephony/java/android/telephony/SubscriptionInfo.java index 4a25818c82b81..5aa89aeb47cb7 100644 --- a/telephony/java/android/telephony/SubscriptionInfo.java +++ b/telephony/java/android/telephony/SubscriptionInfo.java @@ -561,10 +561,10 @@ public class SubscriptionInfo implements Parcelable { } /** - * @return the cardId of the SIM card which contains the subscription. - * @hide + * Returns the card ID of the SIM card which contains the subscription (see + * {@link UiccCardInfo#getCardId()}. + * @return the cardId */ - @SystemApi public int getCardId() { return this.mCardId; } diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index a28c59ffced2c..d6384d7efefcd 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -226,10 +226,9 @@ public class TelephonyManager { public static final int SRVCC_STATE_HANDOVER_CANCELED = 3; /** - * An invalid card identifier. - * @hide + * An invalid UICC card identifier. See {@link #getCardIdForDefaultEuicc()} and + * {@link UiccCardInfo#getCardId()}. */ - @SystemApi public static final int INVALID_CARD_ID = -1; /** @hide */ @@ -3112,14 +3111,8 @@ public class TelephonyManager { * unique to a device, and always refer to the same UICC or eUICC card unless the device goes * through a factory reset. * - *

Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} - * * @return card ID of the default eUICC card. - * @hide */ - @SystemApi - @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges - @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public int getCardIdForDefaultEuicc() { try { ITelephony telephony = getITelephony(); @@ -3133,25 +3126,37 @@ public class TelephonyManager { } /** - * Gets information about currently inserted UICCs and eUICCs. See {@link UiccCardInfo} for more - * details on the kind of information available. + * Gets information about currently inserted UICCs and enabled eUICCs. + *

+ * Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). + *

+ * If the caller has carrier priviliges on any active subscription, then they have permission to + * get simple information like the card ID ({@link UiccCardInfo#getCardId()}), whether the card + * is an eUICC ({@link UiccCardInfo#isEuicc()}), and the slot index where the card is inserted + * ({@link UiccCardInfo#getSlotIndex()}). + *

+ * To get private information such as the EID ({@link UiccCardInfo#getEid()}) or ICCID + * ({@link UiccCardInfo#getIccId()}), the caller must have carrier priviliges on that specific + * UICC or eUICC card. + *

+ * See {@link UiccCardInfo} for more details on the kind of information available. * - * @return UiccCardInfo an array of UiccCardInfo objects, representing information on the - * currently inserted UICCs and eUICCs. - * - * @hide + * @return a list of UiccCardInfo objects, representing information on the currently inserted + * UICCs and eUICCs. Each UiccCardInfo in the list will have private information filtered out if + * the caller does not have adequate permissions for that card. */ - @SystemApi @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) - public UiccCardInfo[] getUiccCardsInfo() { + public List getUiccCardsInfo() { try { ITelephony telephony = getITelephony(); if (telephony == null) { - return null; + Log.e(TAG, "Error in getUiccCardsInfo: unable to connect to Telephony service."); + return new ArrayList(); } - return telephony.getUiccCardsInfo(); + return telephony.getUiccCardsInfo(mContext.getOpPackageName()); } catch (RemoteException e) { - return null; + Log.e(TAG, "Error in getUiccCardsInfo: " + e); + return new ArrayList(); } } diff --git a/telephony/java/android/telephony/UiccCardInfo.java b/telephony/java/android/telephony/UiccCardInfo.java index 45e4704e8894a..19f357a14687d 100644 --- a/telephony/java/android/telephony/UiccCardInfo.java +++ b/telephony/java/android/telephony/UiccCardInfo.java @@ -15,7 +15,6 @@ */ package android.telephony; -import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; @@ -23,10 +22,8 @@ import java.util.Objects; /** * The UiccCardInfo represents information about a currently inserted UICC or embedded eUICC. - * @hide */ -@SystemApi -public class UiccCardInfo implements Parcelable { +public final class UiccCardInfo implements Parcelable { private final boolean mIsEuicc; private final int mCardId; @@ -95,6 +92,9 @@ public class UiccCardInfo implements Parcelable { /** * Get the embedded ID (EID) of the eUICC. If the UiccCardInfo is not an eUICC * (see {@link #isEuicc()}), returns null. + *

+ * Note that this field may be omitted if the caller does not have the correct permissions + * (see {@link TelephonyManager#getUiccCardsInfo()}). */ public String getEid() { if (!mIsEuicc) { @@ -105,6 +105,9 @@ public class UiccCardInfo implements Parcelable { /** * Get the ICCID of the UICC. + *

+ * Note that this field may be omitted if the caller does not have the correct permissions + * (see {@link TelephonyManager#getUiccCardsInfo()}). */ public String getIccId() { return mIccId; @@ -117,6 +120,16 @@ public class UiccCardInfo implements Parcelable { return mSlotIndex; } + /** + * Returns a copy of the UiccCardinfo with the clears the EID and ICCID set to null. These + * values are generally private and require carrier privileges to view. + * + * @hide + */ + public UiccCardInfo getUnprivileged() { + return new UiccCardInfo(mIsEuicc, mCardId, null, null, mSlotIndex); + } + @Override public boolean equals(Object obj) { if (this == obj) { diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 2032666f6c7c3..dca1270b2f78c 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -1483,25 +1483,34 @@ interface ITelephony { * Get the card ID of the default eUICC card. If there is no eUICC, returns * {@link #INVALID_CARD_ID}. * - *

Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} - * * @param subId subscription ID used for authentication * @param callingPackage package making the call * @return card ID of the default eUICC card. - * @hide */ - int getCardIdForDefaultEuicc(int subId, String callingPackage); + int getCardIdForDefaultEuicc(int subId, String callingPackage); /** - * Gets information about currently inserted UICCs and eUICCs. See {@link UiccCardInfo} for more - * details on the kind of information available. + * Gets information about currently inserted UICCs and enabled eUICCs. + *

+ * Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). + *

+ * If the caller has carrier priviliges on any active subscription, then they have permission to + * get simple information like the card ID ({@link UiccCardInfo#getCardId()}), whether the card + * is an eUICC ({@link UiccCardInfo#isEuicc()}), and the slot index where the card is inserted + * ({@link UiccCardInfo#getSlotIndex()}). + *

+ * To get private information such as the EID ({@link UiccCardInfo#getEid()}) or ICCID + * ({@link UiccCardInfo#getIccId()}), the caller must have carrier priviliges on that specific + * UICC or eUICC card. + *

+ * See {@link UiccCardInfo} for more details on the kind of information available. * - * @return UiccCardInfo an array of UiccCardInfo objects, representing information on the - * currently inserted UICCs and eUICCs. - * - * @hide + * @param callingPackage package making the call, used to evaluate carrier privileges + * @return a list of UiccCardInfo objects, representing information on the currently inserted + * UICCs and eUICCs. Each UiccCardInfo in the list will have private information filtered out if + * the caller does not have adequate permissions for that card. */ - UiccCardInfo[] getUiccCardsInfo(); + List getUiccCardsInfo(String callingPackage); /** * Get slot info for all the UICC slots.