Loading src/java/com/android/internal/telephony/uicc/UiccCarrierPrivilegeRules.java +71 −36 Original line number Diff line number Diff line Loading @@ -54,7 +54,10 @@ public class UiccCarrierPrivilegeRules extends Handler { private static final String LOG_TAG = "UiccCarrierPrivilegeRules"; private static final boolean DBG = false; private static final String AID = "A00000015141434C00"; private static final String ARAM_AID = "A00000015141434C00"; private static final String ARAD_AID = "A00000015144414300"; private static final int ARAM = 1; private static final int ARAD = 0; private static final int CLA = 0x80; private static final int COMMAND = 0xCA; private static final int P1 = 0xFF; Loading Loading @@ -184,18 +187,21 @@ public class UiccCarrierPrivilegeRules extends Handler { private String mStatusMessage; // Only used for debugging. private int mChannelId; // Channel Id for communicating with UICC. private int mRetryCount; // Number of retries for open logical channel. private boolean mCheckedRules = false; // Flag that used to mark whether get rules from ARA-D. private int mAIDInUse; // Message component to identify which AID is currently in-use. private final Runnable mRetryRunnable = new Runnable() { @Override public void run() { openChannel(); openChannel(mAIDInUse); } }; private void openChannel() { private void openChannel(int aidId) { // Send open logical channel request. String aid = (aidId == ARAD) ? ARAD_AID : ARAM_AID; int p2 = 0x00; mUiccCard.iccOpenLogicalChannel(AID, p2, /* supported p2 value */ obtainMessage(EVENT_OPEN_LOGICAL_CHANNEL_DONE, null)); mUiccCard.iccOpenLogicalChannel(aid, p2, /* supported p2 value */ obtainMessage(EVENT_OPEN_LOGICAL_CHANNEL_DONE, 0, aidId, null)); } public UiccCarrierPrivilegeRules(UiccCard uiccCard, Message loadedCallback) { Loading @@ -207,7 +213,9 @@ public class UiccCarrierPrivilegeRules extends Handler { mRules = ""; mAccessRules = new ArrayList<>(); openChannel(); // Open logical channel with ARA_D. mAIDInUse = ARAD; openChannel(mAIDInUse); } /** Loading Loading @@ -391,6 +399,7 @@ public class UiccCarrierPrivilegeRules extends Handler { @Override public void handleMessage(Message msg) { AsyncResult ar; mAIDInUse = msg.arg2; // 0 means ARA-D and 1 means ARA-M. switch (msg.what) { Loading @@ -400,8 +409,8 @@ public class UiccCarrierPrivilegeRules extends Handler { if (ar.exception == null && ar.result != null) { mChannelId = ((int[]) ar.result)[0]; mUiccCard.iccTransmitApduLogicalChannel(mChannelId, CLA, COMMAND, P1, P2, P3, DATA, obtainMessage(EVENT_TRANSMIT_LOGICAL_CHANNEL_DONE, mChannelId)); DATA, obtainMessage(EVENT_TRANSMIT_LOGICAL_CHANNEL_DONE, mChannelId, mAIDInUse)); } else { // MISSING_RESOURCE could be due to logical channels temporarily unavailable, // so we retry up to MAX_RETRY times, with an interval of RETRY_INTERVAL_MS. Loading @@ -412,13 +421,24 @@ public class UiccCarrierPrivilegeRules extends Handler { removeCallbacks(mRetryRunnable); postDelayed(mRetryRunnable, RETRY_INTERVAL_MS); } else { // if rules cannot be read from ARA applet, if (mAIDInUse == ARAD) { // Open logical channel with ARA_M. mRules = ""; openChannel(1); } if (mAIDInUse == ARAM) { if (mCheckedRules) { updateState(STATE_LOADED, "Success!"); } else { // if rules cannot be read from both ARA_D and ARA_M applet, // fallback to PKCS15-based ARF. log("No ARA, try ARF next."); mUiccPkcs15 = new UiccPkcs15(mUiccCard, obtainMessage(EVENT_PKCS15_READ_DONE)); } } } } break; case EVENT_TRANSMIT_LOGICAL_CHANNEL_DONE: Loading @@ -432,34 +452,49 @@ public class UiccCarrierPrivilegeRules extends Handler { mRules += IccUtils.bytesToHexString(response.payload) .toUpperCase(Locale.US); if (isDataComplete()) { mAccessRules = parseRules(mRules); mAccessRules.addAll(parseRules(mRules)); if (mAIDInUse == ARAD) { mCheckedRules = true; } else { updateState(STATE_LOADED, "Success!"); } } else { mUiccCard.iccTransmitApduLogicalChannel(mChannelId, CLA, COMMAND, P1, P2_EXTENDED_DATA, P3, DATA, obtainMessage(EVENT_TRANSMIT_LOGICAL_CHANNEL_DONE, mChannelId)); mChannelId, mAIDInUse)); break; } } catch (IllegalArgumentException | IndexOutOfBoundsException ex) { if (mAIDInUse == ARAM) { updateState(STATE_ERROR, "Error parsing rules: " + ex); } } } else { if (mAIDInUse == ARAM) { String errorMsg = "Invalid response: payload=" + response.payload + " sw1=" + response.sw1 + " sw2=" + response.sw2; updateState(STATE_ERROR, errorMsg); } } } else { if (mAIDInUse == ARAM) { updateState(STATE_ERROR, "Error reading value from SIM."); } } mUiccCard.iccCloseLogicalChannel(mChannelId, obtainMessage( EVENT_CLOSE_LOGICAL_CHANNEL_DONE)); EVENT_CLOSE_LOGICAL_CHANNEL_DONE, 0, mAIDInUse)); mChannelId = -1; break; case EVENT_CLOSE_LOGICAL_CHANNEL_DONE: log("EVENT_CLOSE_LOGICAL_CHANNEL_DONE"); if (mAIDInUse == ARAD) { // Close logical channel with ARA_D and then open logical channel with ARA_M. mRules = ""; openChannel(1); } break; case EVENT_PKCS15_READ_DONE: Loading tests/telephonytests/src/com/android/internal/telephony/uicc/UiccCardTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -208,9 +208,9 @@ public class UiccCardTest extends TelephonyTest { waitForMs(50); assertTrue(mUicccard.areCarrierPriviligeRulesLoaded()); verify(mSimulatedCommandsVerifier, times(1)).iccOpenLogicalChannel(isA(String.class), verify(mSimulatedCommandsVerifier, times(2)).iccOpenLogicalChannel(isA(String.class), anyInt(), isA(Message.class)); verify(mSimulatedCommandsVerifier, times(1)).iccTransmitApduLogicalChannel( verify(mSimulatedCommandsVerifier, times(2)).iccTransmitApduLogicalChannel( eq(mChannelId), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyString(), isA(Message.class) ); Loading tests/telephonytests/src/com/android/internal/telephony/uicc/UiccCarrierPrivilegeRulesTest.java +336 −8 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
src/java/com/android/internal/telephony/uicc/UiccCarrierPrivilegeRules.java +71 −36 Original line number Diff line number Diff line Loading @@ -54,7 +54,10 @@ public class UiccCarrierPrivilegeRules extends Handler { private static final String LOG_TAG = "UiccCarrierPrivilegeRules"; private static final boolean DBG = false; private static final String AID = "A00000015141434C00"; private static final String ARAM_AID = "A00000015141434C00"; private static final String ARAD_AID = "A00000015144414300"; private static final int ARAM = 1; private static final int ARAD = 0; private static final int CLA = 0x80; private static final int COMMAND = 0xCA; private static final int P1 = 0xFF; Loading Loading @@ -184,18 +187,21 @@ public class UiccCarrierPrivilegeRules extends Handler { private String mStatusMessage; // Only used for debugging. private int mChannelId; // Channel Id for communicating with UICC. private int mRetryCount; // Number of retries for open logical channel. private boolean mCheckedRules = false; // Flag that used to mark whether get rules from ARA-D. private int mAIDInUse; // Message component to identify which AID is currently in-use. private final Runnable mRetryRunnable = new Runnable() { @Override public void run() { openChannel(); openChannel(mAIDInUse); } }; private void openChannel() { private void openChannel(int aidId) { // Send open logical channel request. String aid = (aidId == ARAD) ? ARAD_AID : ARAM_AID; int p2 = 0x00; mUiccCard.iccOpenLogicalChannel(AID, p2, /* supported p2 value */ obtainMessage(EVENT_OPEN_LOGICAL_CHANNEL_DONE, null)); mUiccCard.iccOpenLogicalChannel(aid, p2, /* supported p2 value */ obtainMessage(EVENT_OPEN_LOGICAL_CHANNEL_DONE, 0, aidId, null)); } public UiccCarrierPrivilegeRules(UiccCard uiccCard, Message loadedCallback) { Loading @@ -207,7 +213,9 @@ public class UiccCarrierPrivilegeRules extends Handler { mRules = ""; mAccessRules = new ArrayList<>(); openChannel(); // Open logical channel with ARA_D. mAIDInUse = ARAD; openChannel(mAIDInUse); } /** Loading Loading @@ -391,6 +399,7 @@ public class UiccCarrierPrivilegeRules extends Handler { @Override public void handleMessage(Message msg) { AsyncResult ar; mAIDInUse = msg.arg2; // 0 means ARA-D and 1 means ARA-M. switch (msg.what) { Loading @@ -400,8 +409,8 @@ public class UiccCarrierPrivilegeRules extends Handler { if (ar.exception == null && ar.result != null) { mChannelId = ((int[]) ar.result)[0]; mUiccCard.iccTransmitApduLogicalChannel(mChannelId, CLA, COMMAND, P1, P2, P3, DATA, obtainMessage(EVENT_TRANSMIT_LOGICAL_CHANNEL_DONE, mChannelId)); DATA, obtainMessage(EVENT_TRANSMIT_LOGICAL_CHANNEL_DONE, mChannelId, mAIDInUse)); } else { // MISSING_RESOURCE could be due to logical channels temporarily unavailable, // so we retry up to MAX_RETRY times, with an interval of RETRY_INTERVAL_MS. Loading @@ -412,13 +421,24 @@ public class UiccCarrierPrivilegeRules extends Handler { removeCallbacks(mRetryRunnable); postDelayed(mRetryRunnable, RETRY_INTERVAL_MS); } else { // if rules cannot be read from ARA applet, if (mAIDInUse == ARAD) { // Open logical channel with ARA_M. mRules = ""; openChannel(1); } if (mAIDInUse == ARAM) { if (mCheckedRules) { updateState(STATE_LOADED, "Success!"); } else { // if rules cannot be read from both ARA_D and ARA_M applet, // fallback to PKCS15-based ARF. log("No ARA, try ARF next."); mUiccPkcs15 = new UiccPkcs15(mUiccCard, obtainMessage(EVENT_PKCS15_READ_DONE)); } } } } break; case EVENT_TRANSMIT_LOGICAL_CHANNEL_DONE: Loading @@ -432,34 +452,49 @@ public class UiccCarrierPrivilegeRules extends Handler { mRules += IccUtils.bytesToHexString(response.payload) .toUpperCase(Locale.US); if (isDataComplete()) { mAccessRules = parseRules(mRules); mAccessRules.addAll(parseRules(mRules)); if (mAIDInUse == ARAD) { mCheckedRules = true; } else { updateState(STATE_LOADED, "Success!"); } } else { mUiccCard.iccTransmitApduLogicalChannel(mChannelId, CLA, COMMAND, P1, P2_EXTENDED_DATA, P3, DATA, obtainMessage(EVENT_TRANSMIT_LOGICAL_CHANNEL_DONE, mChannelId)); mChannelId, mAIDInUse)); break; } } catch (IllegalArgumentException | IndexOutOfBoundsException ex) { if (mAIDInUse == ARAM) { updateState(STATE_ERROR, "Error parsing rules: " + ex); } } } else { if (mAIDInUse == ARAM) { String errorMsg = "Invalid response: payload=" + response.payload + " sw1=" + response.sw1 + " sw2=" + response.sw2; updateState(STATE_ERROR, errorMsg); } } } else { if (mAIDInUse == ARAM) { updateState(STATE_ERROR, "Error reading value from SIM."); } } mUiccCard.iccCloseLogicalChannel(mChannelId, obtainMessage( EVENT_CLOSE_LOGICAL_CHANNEL_DONE)); EVENT_CLOSE_LOGICAL_CHANNEL_DONE, 0, mAIDInUse)); mChannelId = -1; break; case EVENT_CLOSE_LOGICAL_CHANNEL_DONE: log("EVENT_CLOSE_LOGICAL_CHANNEL_DONE"); if (mAIDInUse == ARAD) { // Close logical channel with ARA_D and then open logical channel with ARA_M. mRules = ""; openChannel(1); } break; case EVENT_PKCS15_READ_DONE: Loading
tests/telephonytests/src/com/android/internal/telephony/uicc/UiccCardTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -208,9 +208,9 @@ public class UiccCardTest extends TelephonyTest { waitForMs(50); assertTrue(mUicccard.areCarrierPriviligeRulesLoaded()); verify(mSimulatedCommandsVerifier, times(1)).iccOpenLogicalChannel(isA(String.class), verify(mSimulatedCommandsVerifier, times(2)).iccOpenLogicalChannel(isA(String.class), anyInt(), isA(Message.class)); verify(mSimulatedCommandsVerifier, times(1)).iccTransmitApduLogicalChannel( verify(mSimulatedCommandsVerifier, times(2)).iccTransmitApduLogicalChannel( eq(mChannelId), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyString(), isA(Message.class) ); Loading
tests/telephonytests/src/com/android/internal/telephony/uicc/UiccCarrierPrivilegeRulesTest.java +336 −8 File changed.Preview size limit exceeded, changes collapsed. Show changes