Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 57f656b9 authored by Shishir Agrawal's avatar Shishir Agrawal
Browse files

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
parent 7d2edfc0
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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";
+8 −0
Original line number Diff line number Diff line
@@ -982,6 +982,14 @@
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="signature" />

    <!-- Allows an application to communicate with a SIM card using logical
         channels. -->
    <permission android:name="android.permission.SIM_COMMUNICATION"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:label="@string/permlab_sim_communication"
        android:description="@string/permdesc_sim_communication"
        android:protectionLevel="dangerous" />

    <!-- =========================================== -->
    <!-- Permissions associated with audio capture -->
    <!-- =========================================== -->
+5 −0
Original line number Diff line number Diff line
@@ -1483,6 +1483,11 @@
      microphone.  This permission allows the app to record audio at any time
      without your confirmation.</string>

    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
    <string name="permlab_sim_communication">sim communication</string>
    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
    <string name="permdesc_sim_communication">Allows the app to send commands to the SIM. This is very dangerous.</string>

    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
    <string name="permlab_camera">take pictures and videos</string>
    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+63 −0
Original line number Diff line number Diff line
@@ -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 "";
    }
}
+41 −1
Original line number Diff line number Diff line
@@ -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);
}