From b94f8d3fb39eedb0524b74d08469fcdb141e4f82 Mon Sep 17 00:00:00 2001 From: Holly Jiuyu Sun Date: Wed, 30 Jan 2019 15:25:24 -0800 Subject: [PATCH] Refresh cardId before using it. Bug: 122978614 Bug: 111614811 Test: on phone Change-Id: I30d70b839f05183ad201a114ea12c79c730f4206 --- .../android/telephony/euicc/EuiccManager.java | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/telephony/java/android/telephony/euicc/EuiccManager.java b/telephony/java/android/telephony/euicc/EuiccManager.java index bca088e618c04..72f298b1d7762 100644 --- a/telephony/java/android/telephony/euicc/EuiccManager.java +++ b/telephony/java/android/telephony/euicc/EuiccManager.java @@ -408,7 +408,7 @@ public class EuiccManager { public static final int EUICC_OTA_STATUS_UNAVAILABLE = 5; private final Context mContext; - private final int mCardId; + private int mCardId; /** @hide */ public EuiccManager(Context context) { @@ -446,7 +446,7 @@ public class EuiccManager { public boolean isEnabled() { // In the future, this may reach out to IEuiccController (if non-null) to check any dynamic // restrictions. - return getIEuiccController() != null && mCardId != TelephonyManager.INVALID_CARD_ID; + return getIEuiccController() != null; } /** @@ -456,11 +456,11 @@ public class EuiccManager { * current eUICC. A calling app with carrier privileges for one eUICC may not necessarily have * access to the EID of another eUICC. * - * @return the EID. May be null if {@link #isEnabled()} is false or the eUICC is not ready. + * @return the EID. May be null if the eUICC is not ready. */ @Nullable public String getEid() { - if (!isEnabled()) { + if (!refreshCardIdIfInvalid()) { return null; } try { @@ -475,15 +475,15 @@ public class EuiccManager { * *

Requires the {@link android.Manifest.permission#WRITE_EMBEDDED_SUBSCRIPTIONS} permission. * - * @return the status of eUICC OTA. If {@link #isEnabled()} is false or the eUICC is not ready, - * {@link OtaStatus#EUICC_OTA_STATUS_UNAVAILABLE} will be returned. + * @return the status of eUICC OTA. If the eUICC is not ready, + * {@link OtaStatus#EUICC_OTA_STATUS_UNAVAILABLE} will be returned. * * @hide */ @SystemApi @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS) public int getOtaStatus() { - if (!isEnabled()) { + if (!refreshCardIdIfInvalid()) { return EUICC_OTA_STATUS_UNAVAILABLE; } try { @@ -509,7 +509,7 @@ public class EuiccManager { @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS) public void downloadSubscription(DownloadableSubscription subscription, boolean switchAfterDownload, PendingIntent callbackIntent) { - if (!isEnabled()) { + if (!refreshCardIdIfInvalid()) { sendUnavailableError(callbackIntent); return; } @@ -571,7 +571,7 @@ public class EuiccManager { @SystemApi @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS) public void continueOperation(Intent resolutionIntent, Bundle resolutionExtras) { - if (!isEnabled()) { + if (!refreshCardIdIfInvalid()) { PendingIntent callbackIntent = resolutionIntent.getParcelableExtra( EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_RESOLUTION_CALLBACK_INTENT); @@ -608,7 +608,7 @@ public class EuiccManager { @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS) public void getDownloadableSubscriptionMetadata( DownloadableSubscription subscription, PendingIntent callbackIntent) { - if (!isEnabled()) { + if (!refreshCardIdIfInvalid()) { sendUnavailableError(callbackIntent); return; } @@ -638,7 +638,7 @@ public class EuiccManager { @SystemApi @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS) public void getDefaultDownloadableSubscriptionList(PendingIntent callbackIntent) { - if (!isEnabled()) { + if (!refreshCardIdIfInvalid()) { sendUnavailableError(callbackIntent); return; } @@ -653,12 +653,11 @@ public class EuiccManager { /** * Returns information about the eUICC chip/device. * - * @return the {@link EuiccInfo}. May be null if {@link #isEnabled()} is false or the eUICC is - * not ready. + * @return the {@link EuiccInfo}. May be null if the eUICC is not ready. */ @Nullable public EuiccInfo getEuiccInfo() { - if (!isEnabled()) { + if (!refreshCardIdIfInvalid()) { return null; } try { @@ -683,7 +682,7 @@ public class EuiccManager { */ @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS) public void deleteSubscription(int subscriptionId, PendingIntent callbackIntent) { - if (!isEnabled()) { + if (!refreshCardIdIfInvalid()) { sendUnavailableError(callbackIntent); return; } @@ -711,7 +710,7 @@ public class EuiccManager { */ @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS) public void switchToSubscription(int subscriptionId, PendingIntent callbackIntent) { - if (!isEnabled()) { + if (!refreshCardIdIfInvalid()) { sendUnavailableError(callbackIntent); return; } @@ -737,7 +736,7 @@ public class EuiccManager { @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS) public void updateSubscriptionNickname( int subscriptionId, String nickname, PendingIntent callbackIntent) { - if (!isEnabled()) { + if (!refreshCardIdIfInvalid()) { sendUnavailableError(callbackIntent); return; } @@ -761,7 +760,7 @@ public class EuiccManager { @SystemApi @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS) public void eraseSubscriptions(PendingIntent callbackIntent) { - if (!isEnabled()) { + if (!refreshCardIdIfInvalid()) { sendUnavailableError(callbackIntent); return; } @@ -791,7 +790,7 @@ public class EuiccManager { * @hide */ public void retainSubscriptionsForFactoryReset(PendingIntent callbackIntent) { - if (!isEnabled()) { + if (!refreshCardIdIfInvalid()) { sendUnavailableError(callbackIntent); return; } @@ -802,6 +801,19 @@ public class EuiccManager { } } + private boolean refreshCardIdIfInvalid() { + if (!isEnabled()) { + return false; + } + // Refresh mCardId if it's invalid. + if (mCardId == TelephonyManager.INVALID_CARD_ID) { + TelephonyManager tm = (TelephonyManager) + mContext.getSystemService(Context.TELEPHONY_SERVICE); + mCardId = tm.getCardIdForDefaultEuicc(); + } + return true; + } + private static void sendUnavailableError(PendingIntent callbackIntent) { try { callbackIntent.send(EMBEDDED_SUBSCRIPTION_RESULT_ERROR);