From 57f656b9f6271cf857b5ecec5f8c7eacb321ec0b Mon Sep 17 00:00:00 2001 From: Shishir Agrawal Date: Mon, 28 Oct 2013 14:25:38 -0700 Subject: [PATCH] Adding support for SIM communication from Android over logical channels. Expose the folowing commands in ITelephony.aidl and TelephonyManager: - iccOpenLogicalChannel - iccCloseLogicalChannel - iccTransmitApduLogicalChannel Also add a new SIM_COMMUNICATION permission (maked as dangerous) to control access to the above commands. Change-Id: I89c08adc6f9738907e3b547c749f3cc61f300710 --- api/current.txt | 4 ++ core/res/AndroidManifest.xml | 8 +++ core/res/res/values/strings.xml | 5 ++ .../android/telephony/TelephonyManager.java | 63 +++++++++++++++++++ .../internal/telephony/ITelephony.aidl | 42 ++++++++++++- 5 files changed, 121 insertions(+), 1 deletion(-) diff --git a/api/current.txt b/api/current.txt index ce92fcb173a39..a006e5b47e89e 100644 --- a/api/current.txt +++ b/api/current.txt @@ -127,6 +127,7 @@ package android { field public static final java.lang.String SET_WALLPAPER = "android.permission.SET_WALLPAPER"; field public static final java.lang.String SET_WALLPAPER_HINTS = "android.permission.SET_WALLPAPER_HINTS"; field public static final java.lang.String SIGNAL_PERSISTENT_PROCESSES = "android.permission.SIGNAL_PERSISTENT_PROCESSES"; + field public static final java.lang.String SIM_COMMUNICATION = "android.permission.SIM_COMMUNICATION"; field public static final java.lang.String STATUS_BAR = "android.permission.STATUS_BAR"; field public static final java.lang.String SUBSCRIBED_FEEDS_READ = "android.permission.SUBSCRIBED_FEEDS_READ"; field public static final java.lang.String SUBSCRIBED_FEEDS_WRITE = "android.permission.SUBSCRIBED_FEEDS_WRITE"; @@ -24118,6 +24119,9 @@ package android.telephony { method public java.lang.String getVoiceMailAlphaTag(); method public java.lang.String getVoiceMailNumber(); method public boolean hasIccCard(); + method public boolean iccCloseLogicalChannel(int); + method public int iccOpenLogicalChannel(java.lang.String); + method public java.lang.String iccTransmitApduLogicalChannel(int, int, int, int, int, int, java.lang.String); method public boolean isNetworkRoaming(); method public void listen(android.telephony.PhoneStateListener, int); field public static final java.lang.String ACTION_PHONE_STATE_CHANGED = "android.intent.action.PHONE_STATE"; diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index c923e14e4e9ec..5af7a4af5f104 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -982,6 +982,14 @@ android:permissionGroup="android.permission-group.SYSTEM_TOOLS" android:protectionLevel="signature" /> + + + diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 9a850b1a99a9e..bbe39094e045e 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -1483,6 +1483,11 @@ microphone. This permission allows the app to record audio at any time without your confirmation. + + sim communication + + Allows the app to send commands to the SIM. This is very dangerous. + take pictures and videos diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 8f17e72799245..e0602ed982173 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -1439,4 +1439,67 @@ public class TelephonyManager { return mContext.getResources().getString( com.android.internal.R.string.config_mms_user_agent_profile_url); } + + /** + * Opens a logical channel to the ICC card. + * + * Input parameters equivalent to TS 27.007 AT+CCHO command. + * + * @param AID Application id. See ETSI 102.221 and 101.220. + * @return The logical channel id which is negative on error. + */ + public int iccOpenLogicalChannel(String AID) { + try { + return getITelephony().iccOpenLogicalChannel(AID); + } catch (RemoteException ex) { + } catch (NullPointerException ex) { + } + return -1; + } + + /** + * Closes a previously opened logical channel to the ICC card. + * + * Input parameters equivalent to TS 27.007 AT+CCHC command. + * + * @param channel is the channel id to be closed as retruned by a successful + * iccOpenLogicalChannel. + * @return true if the channel was closed successfully. + */ + public boolean iccCloseLogicalChannel(int channel) { + try { + return getITelephony().iccCloseLogicalChannel(channel); + } catch (RemoteException ex) { + } catch (NullPointerException ex) { + } + return false; + } + + /** + * Transmit an APDU to the ICC card over a logical channel. + * + * Input parameters equivalent to TS 27.007 AT+CGLA command. + * + * @param channel is the channel id to be closed as retruned by a successful + * iccOpenLogicalChannel. + * @param cla Class of the APDU command. + * @param instruction Instruction of the APDU command. + * @param p1 P1 value of the APDU command. + * @param p2 P2 value of the APDU command. + * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU + * is sent to the SIM. + * @param data Data to be sent with the APDU. + * @return The APDU response from the ICC card with the status appended at + * the end. If an error occurs, an empty string is returned. + */ + public String iccTransmitApduLogicalChannel(int channel, int cla, + int command, int p1, int p2, int p3, String data) { + try { + return getITelephony().iccTransmitApduLogicalChannel(channel, cla, + command, p1, p2, p3, data); + } catch (RemoteException ex) { + } catch (NullPointerException ex) { + } + return ""; + } } diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 7bd2c8412e979..55da6445ef243 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -324,5 +324,45 @@ interface ITelephony { * Sets minimum time in milli-seconds between onCellInfoChanged */ void setCellInfoListRate(int rateInMillis); -} + /** + * Opens a logical channel to the ICC card. + * + * Input parameters equivalent to TS 27.007 AT+CCHO command. + * + * @param AID Application id. See ETSI 102.221 and 101.220. + * @return The logical channel id which is set to -1 on error. + */ + int iccOpenLogicalChannel(String AID); + + /** + * Closes a previously opened logical channel to the ICC card. + * + * Input parameters equivalent to TS 27.007 AT+CCHC command. + * + * @param channel is the channel id to be closed as retruned by a + * successful iccOpenLogicalChannel. + * @return true if the channel was closed successfully. + */ + boolean iccCloseLogicalChannel(int channel); + + /** + * Transmit an APDU to the ICC card over a logical channel. + * + * Input parameters equivalent to TS 27.007 AT+CGLA command. + * + * @param channel is the channel id to be closed as retruned by a + * successful iccOpenLogicalChannel. + * @param cla Class of the APDU command. + * @param instruction Instruction of the APDU command. + * @param p1 P1 value of the APDU command. + * @param p2 P2 value of the APDU command. + * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU + * is sent to the SIM. + * @param data Data to be sent with the APDU. + * @return The APDU response from the ICC card with the status appended at + * the end. If an error occurs, an empty string is returned. + */ + String iccTransmitApduLogicalChannel(int channel, int cla, int command, + int p1, int p2, int p3, String data); +}