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

Commit e7111f67 authored by Pawit Pornkitprasan's avatar Pawit Pornkitprasan Committed by Gerrit Code Review
Browse files

Add Samsung STK support (telephony part)

Support for SMS-based SIM applications.
Partially rewritten the original patch by Jüri Schultz to be less intrusive.

Change-Id: I15d2de1781a2823e24941dd792db3d372578aa9f
parent e15ecd0f
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -84,6 +84,7 @@ public abstract class BaseCommands implements CommandsInterface {
    protected Registrant mCatProCmdRegistrant;
    protected Registrant mCatProCmdRegistrant;
    protected Registrant mCatEventRegistrant;
    protected Registrant mCatEventRegistrant;
    protected Registrant mCatCallSetUpRegistrant;
    protected Registrant mCatCallSetUpRegistrant;
    protected Registrant mCatSendSmsResultRegistrant;
    protected Registrant mIccSmsFullRegistrant;
    protected Registrant mIccSmsFullRegistrant;
    protected Registrant mEmergencyCallbackModeRegistrant;
    protected Registrant mEmergencyCallbackModeRegistrant;
    protected Registrant mRingRegistrant;
    protected Registrant mRingRegistrant;
@@ -349,6 +350,15 @@ public abstract class BaseCommands implements CommandsInterface {
        mCatCallSetUpRegistrant.clear();
        mCatCallSetUpRegistrant.clear();
    }
    }


    // For Samsung STK
    public void setOnCatSendSmsResult(Handler h, int what, Object obj) {
        mCatSendSmsResultRegistrant = new Registrant(h, what, obj);
    }

    public void unSetOnCatSendSmsResult(Handler h) {
        mCatSendSmsResultRegistrant.clear();
    }

    public void setOnIccSmsFull(Handler h, int what, Object obj) {
    public void setOnIccSmsFull(Handler h, int what, Object obj) {
        mIccSmsFullRegistrant = new Registrant (h, what, obj);
        mIccSmsFullRegistrant = new Registrant (h, what, obj);
    }
    }
+8 −0
Original line number Original line Diff line number Diff line
@@ -1588,4 +1588,12 @@ public interface CommandsInterface {
     * CM-specific: Ask the RIL about the presence of back-compat flags
     * CM-specific: Ask the RIL about the presence of back-compat flags
     */
     */
    public boolean needsOldRilFeature(String feature);
    public boolean needsOldRilFeature(String feature);

    /**
     * @hide
     * samsung stk service implementation - set up registrant for sending
     * sms send result from modem(RIL) to catService
     */
    void setOnCatSendSmsResult(Handler h, int what, Object obj);
    void unSetOnCatSendSmsResult(Handler h);
}
}
+15 −0
Original line number Original line Diff line number Diff line
@@ -2563,6 +2563,7 @@ public class RIL extends BaseCommands implements CommandsInterface {
            case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break;
            case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break;
            case RIL_UNSOL_RIL_CONNECTED: ret = responseInts(p); break;
            case RIL_UNSOL_RIL_CONNECTED: ret = responseInts(p); break;
            case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: ret =  responseInts(p); break;
            case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: ret =  responseInts(p); break;
            case RIL_UNSOL_STK_SEND_SMS_RESULT: ret = responseInts(p); break; // Samsung STK


            default:
            default:
                throw new RuntimeException("Unrecognized unsol response: " + response);
                throw new RuntimeException("Unrecognized unsol response: " + response);
@@ -2924,6 +2925,19 @@ public class RIL extends BaseCommands implements CommandsInterface {
                notifyRegistrantsRilConnectionChanged(((int[])ret)[0]);
                notifyRegistrantsRilConnectionChanged(((int[])ret)[0]);
                break;
                break;
            }
            }

            // Samsung STK
            case RIL_UNSOL_STK_SEND_SMS_RESULT:
                if (Resources.getSystem().
                        getBoolean(com.android.internal.R.bool.config_samsung_stk)) {
                    if (RILJ_LOGD) unsljLogRet(response, ret);

                    if (mCatSendSmsResultRegistrant != null) {
                        mCatSendSmsResultRegistrant.notifyRegistrant(
                                new AsyncResult (null, ret, null));
                    }
                }
                break;
        }
        }
    }
    }


@@ -3733,6 +3747,7 @@ public class RIL extends BaseCommands implements CommandsInterface {
            case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
            case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
            case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
            case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
            case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
            case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
            case RIL_UNSOL_STK_SEND_SMS_RESULT: return "RIL_UNSOL_STK_SEND_SMS_RESULT";
            default: return "<unknown reponse>";
            default: return "<unknown reponse>";
        }
        }
    }
    }
+44 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.cat;


public enum CallControlResult {

    CALL_CONTROL_NO_CONTROL(0x00),
    CALL_CONTROL_ALLOWED_NO_MOD(0x01),
    CALL_CONTROL_NOT_ALLOWED(0x02),
    CALL_CONTROL_ALLOWED_WITH_MOD(0x03);
    private int mValue;

    CallControlResult(int value) {
        mValue = value;
    }

    public static CallControlResult fromInt(int value) {
        for (CallControlResult e : CallControlResult.values()) {
            if (e.mValue == value) {
                return e;
            }
        }
        return null;
    }

    public int value() {
        return mValue;
    }
}
+113 −0
Original line number Original line Diff line number Diff line
@@ -76,6 +76,10 @@ public class CatService extends Handler implements AppInterface {
    private CatCmdMessage mCurrntCmd = null;
    private CatCmdMessage mCurrntCmd = null;
    private CatCmdMessage mMenuCmd = null;
    private CatCmdMessage mMenuCmd = null;


    // Samsung STK
    private int mTimeoutDest = 0;
    private int mCallControlResultCode = 0;

    private RilMessageDecoder mMsgDecoder = null;
    private RilMessageDecoder mMsgDecoder = null;
    private boolean mStkAppInstalled = false;
    private boolean mStkAppInstalled = false;


@@ -88,7 +92,9 @@ public class CatService extends Handler implements AppInterface {
    static final int MSG_ID_RESPONSE                 = 6;
    static final int MSG_ID_RESPONSE                 = 6;
    static final int MSG_ID_SIM_READY                = 7;
    static final int MSG_ID_SIM_READY                = 7;


    static final int MSG_ID_TIMEOUT                  = 9;  // Samsung STK
    static final int MSG_ID_RIL_MSG_DECODED          = 10;
    static final int MSG_ID_RIL_MSG_DECODED          = 10;
    static final int MSG_ID_SEND_SMS_RESULT          = 12; // Samsung STK


    // Events to signal SIM presence or absent in the device.
    // Events to signal SIM presence or absent in the device.
    private static final int MSG_ID_ICC_RECORDS_LOADED       = 20;
    private static final int MSG_ID_ICC_RECORDS_LOADED       = 20;
@@ -102,6 +108,14 @@ public class CatService extends Handler implements AppInterface {


    static final String STK_DEFAULT = "Defualt Message";
    static final String STK_DEFAULT = "Defualt Message";


    // Samsung STK SEND_SMS
    static final int WAITING_SMS_RESULT = 2;
    static final int WAITING_SMS_RESULT_TIME = 60000;

    static final int SMS_SEND_OK = 0;
    static final int SMS_SEND_FAIL = 32790;
    static final int SMS_SEND_RETRY = 32810;

    /* Intentionally private for singleton */
    /* Intentionally private for singleton */
    private CatService(CommandsInterface ci, UiccCardApplication ca, IccRecords ir,
    private CatService(CommandsInterface ci, UiccCardApplication ca, IccRecords ir,
            Context context, IccFileHandler fh, UiccCard ic) {
            Context context, IccFileHandler fh, UiccCard ic) {
@@ -121,6 +135,7 @@ public class CatService extends Handler implements AppInterface {
        mCmdIf.setOnCatProactiveCmd(this, MSG_ID_PROACTIVE_COMMAND, null);
        mCmdIf.setOnCatProactiveCmd(this, MSG_ID_PROACTIVE_COMMAND, null);
        mCmdIf.setOnCatEvent(this, MSG_ID_EVENT_NOTIFY, null);
        mCmdIf.setOnCatEvent(this, MSG_ID_EVENT_NOTIFY, null);
        mCmdIf.setOnCatCallSetUp(this, MSG_ID_CALL_SETUP, null);
        mCmdIf.setOnCatCallSetUp(this, MSG_ID_CALL_SETUP, null);
        mCmdIf.setOnCatSendSmsResult(this, MSG_ID_SEND_SMS_RESULT, null); // Samsung STK
        //mCmdIf.setOnSimRefresh(this, MSG_ID_REFRESH, null);
        //mCmdIf.setOnSimRefresh(this, MSG_ID_REFRESH, null);


        mIccRecords = ir;
        mIccRecords = ir;
@@ -142,6 +157,7 @@ public class CatService extends Handler implements AppInterface {
        mCmdIf.unSetOnCatProactiveCmd(this);
        mCmdIf.unSetOnCatProactiveCmd(this);
        mCmdIf.unSetOnCatEvent(this);
        mCmdIf.unSetOnCatEvent(this);
        mCmdIf.unSetOnCatCallSetUp(this);
        mCmdIf.unSetOnCatCallSetUp(this);
        mCmdIf.unSetOnCatSendSmsResult(this);


        this.removeCallbacksAndMessages(null);
        this.removeCallbacksAndMessages(null);
    }
    }
@@ -271,6 +287,11 @@ public class CatService extends Handler implements AppInterface {
                break;
                break;
            case SEND_DTMF:
            case SEND_DTMF:
            case SEND_SMS:
            case SEND_SMS:
                if (mContext.getResources().
                        getBoolean(com.android.internal.R.bool.config_samsung_stk)) {
                    handleProactiveCommandSendSMS((SendSMSParams) cmdParams);
                }
                // Fall through
            case SEND_SS:
            case SEND_SS:
            case SEND_USSD:
            case SEND_USSD:
                if ((((DisplayTextParams)cmdParams).textMsg.text != null)
                if ((((DisplayTextParams)cmdParams).textMsg.text != null)
@@ -654,6 +675,76 @@ public class CatService extends Handler implements AppInterface {
            CatLog.d(this, "SIM ready. Reporting STK service running now...");
            CatLog.d(this, "SIM ready. Reporting STK service running now...");
            mCmdIf.reportStkServiceIsRunning(null);
            mCmdIf.reportStkServiceIsRunning(null);
            break;
            break;
        case MSG_ID_TIMEOUT: // Should only be called for Samsung STK
            if (mTimeoutDest == WAITING_SMS_RESULT) {
                CatLog.d(this, "SMS SEND TIMEOUT");
                if (CallControlResult.fromInt(mCallControlResultCode) ==
                        CallControlResult.CALL_CONTROL_NOT_ALLOWED)
                    sendTerminalResponse(mCurrntCmd.mCmdDet,
                            ResultCode.USIM_CALL_CONTROL_PERMANENT, true, 1, null);
                else
                    sendTerminalResponse(mCurrntCmd.mCmdDet,
                            ResultCode.TERMINAL_CRNTLY_UNABLE_TO_PROCESS, false, 0, null);
                break;
            }
            break;
        case MSG_ID_SEND_SMS_RESULT: // Samsung STK SEND_SMS
            if (mContext.getResources().
                        getBoolean(com.android.internal.R.bool.config_samsung_stk)) {
                int[] sendResult;
                AsyncResult ar;
                CatLog.d(this, "handleMsg : MSG_ID_SEND_SMS_RESULT");
                cancelTimeOut();
                CatLog.d(this, "The Msg ID data:" + msg.what);
                if (msg.obj == null)
                    break;
                ar = (AsyncResult) msg.obj;
                if (ar == null || ar.result == null || mCurrntCmd == null || mCurrntCmd.mCmdDet == null)
                    break;
                sendResult = (int[]) ar.result;
                switch (sendResult[0]) {
                    default:
                        CatLog.d(this, "SMS SEND GENERIC FAIL");
                        if (CallControlResult.fromInt(mCallControlResultCode) ==
                                CallControlResult.CALL_CONTROL_NOT_ALLOWED)
                            sendTerminalResponse(mCurrntCmd.mCmdDet,
                                    ResultCode.USIM_CALL_CONTROL_PERMANENT, true, 1, null);
                        else
                            sendTerminalResponse(mCurrntCmd.mCmdDet,
                                    ResultCode.TERMINAL_CRNTLY_UNABLE_TO_PROCESS, false, 0, null);
                        break;
                    case SMS_SEND_OK: // '\0'
                        CatLog.d(this, "SMS SEND OK");
                        if (CallControlResult.fromInt(mCallControlResultCode) ==
                                CallControlResult.CALL_CONTROL_NOT_ALLOWED)
                            sendTerminalResponse(mCurrntCmd.mCmdDet,
                                    ResultCode.USIM_CALL_CONTROL_PERMANENT, true, 1, null);
                        else
                            sendTerminalResponse(mCurrntCmd.mCmdDet, ResultCode.OK, false, 0, null);
                        break;
                    case SMS_SEND_FAIL:
                        CatLog.d(this, "SMS SEND FAIL - MEMORY NOT AVAILABLE");
                        if (CallControlResult.fromInt(mCallControlResultCode) ==
                                CallControlResult.CALL_CONTROL_NOT_ALLOWED)
                            sendTerminalResponse(mCurrntCmd.mCmdDet,
                                    ResultCode.USIM_CALL_CONTROL_PERMANENT, true, 1, null);
                        else
                            sendTerminalResponse(mCurrntCmd.mCmdDet,
                                    ResultCode.TERMINAL_CRNTLY_UNABLE_TO_PROCESS, false, 0, null);
                        break;
                    case SMS_SEND_RETRY:
                        CatLog.d(this, "SMS SEND FAIL RETRY");
                        if (CallControlResult.fromInt(mCallControlResultCode) ==
                                CallControlResult.CALL_CONTROL_NOT_ALLOWED)
                            sendTerminalResponse(mCurrntCmd.mCmdDet,
                                    ResultCode.USIM_CALL_CONTROL_PERMANENT, true, 1, null);
                        else
                            sendTerminalResponse(mCurrntCmd.mCmdDet,
                                    ResultCode.NETWORK_CRNTLY_UNABLE_TO_PROCESS, false, 0, null);
                        break;
                    }
            }
            break;
        default:
        default:
            throw new AssertionError("Unrecognized CAT command: " + msg.what);
            throw new AssertionError("Unrecognized CAT command: " + msg.what);
        }
        }
@@ -776,4 +867,26 @@ public class CatService extends Handler implements AppInterface {


        return (numReceiver > 0);
        return (numReceiver > 0);
    }
    }

    /**
     * Samsung STK SEND_SMS
     * @param cmdPar
     */
    private void handleProactiveCommandSendSMS(SendSMSParams cmdPar) {
        CatLog.d(this, "The smscaddress is: " + cmdPar.smscAddress);
        CatLog.d(this, "The SMS tpdu is: " + cmdPar.pdu);
        mCmdIf.sendSMS(cmdPar.smscAddress, cmdPar.pdu, null);
        startTimeOut(WAITING_SMS_RESULT, WAITING_SMS_RESULT_TIME);
    }

    private void cancelTimeOut() {
        removeMessages(MSG_ID_TIMEOUT);
        mTimeoutDest = 0;
    }

    private void startTimeOut(int timeout, int delay) {
        cancelTimeOut();
        mTimeoutDest = timeout;
        sendMessageDelayed(obtainMessage(MSG_ID_TIMEOUT), delay);
    }
}
}
Loading