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

Commit 65dbfc6e authored by Hariprasad Jayakumar's avatar Hariprasad Jayakumar Committed by Linux Build Service Account
Browse files

Telephony: Notify Unsol OEM_HOOK events to registrants

Process RIL_UNSOL_OEM_HOOK_RAW messages that are meant for
framework consumption and notify the registrants of the same.

Change-Id: Ib3e099c5fa100e180dc5e74969908d00dd1499a8
CRs-Fixed: 459157, 568685
(cherry picked from commit bd5574f7cac71d17f6acf0647c3807dd81748140)
parent 2f6c2eaf
Loading
Loading
Loading
Loading
+43 −7
Original line number Diff line number Diff line
@@ -70,6 +70,10 @@ public abstract class BaseCommands implements CommandsInterface {
    protected RegistrantList mIccRefreshRegistrants = new RegistrantList();
    protected RegistrantList mRilCellInfoListRegistrants = new RegistrantList();
    protected RegistrantList mSubscriptionStatusRegistrants = new RegistrantList();
    protected RegistrantList mCdmaFwdBurstDtmfRegistrants = new RegistrantList();
    protected RegistrantList mCdmaFwdContDtmfStartRegistrants = new RegistrantList();
    protected RegistrantList mCdmaFwdContDtmfStopRegistrants = new RegistrantList();
    protected RegistrantList mWmsReadyRegistrants = new RegistrantList();

    protected Registrant mGsmSmsRegistrant;
    protected Registrant mCdmaSmsRegistrant;
@@ -690,6 +694,38 @@ public abstract class BaseCommands implements CommandsInterface {
        mSubscriptionStatusRegistrants.remove(h);
    }

    public void registerForCdmaFwdBurstDtmf(Handler h, int what, Object obj) {
        mCdmaFwdBurstDtmfRegistrants.addUnique(h, what, obj);
    }

    public void unregisterForCdmaFwdBurstDtmf(Handler h) {
        mCdmaFwdBurstDtmfRegistrants.remove(h);
    }

    public void registerForCdmaFwdContDtmfStart(Handler h, int what, Object obj) {
        mCdmaFwdContDtmfStartRegistrants.addUnique(h, what, obj);
    }

    public void unregisterForCdmaFwdContDtmfStart(Handler h) {
        mCdmaFwdContDtmfStartRegistrants.remove(h);
    }

    public void registerForCdmaFwdContDtmfStop(Handler h, int what, Object obj) {
        mCdmaFwdContDtmfStopRegistrants.addUnique(h, what, obj);
    }

    public void unregisterForCdmaFwdContDtmfStop(Handler h) {
        mCdmaFwdContDtmfStopRegistrants.remove(h);
    }

    public void registerForWmsReadyEvent(Handler h, int what, Object obj) {
        mWmsReadyRegistrants.addUnique(h, what, obj);
    }

    public void unregisterForWmsReadyEvent(Handler h) {
        mWmsReadyRegistrants.remove(h);
    }

    /**
     * {@inheritDoc}
     */
+117 −2
Original line number Diff line number Diff line
@@ -77,6 +77,8 @@ import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -231,6 +233,15 @@ public final class RIL extends BaseCommands implements CommandsInterface {
     */
    private static final int DEFAULT_WAKE_LOCK_TIMEOUT = 60000;

    /** Starting number for OEMHOOK request and response IDs */
    final int OEMHOOK_BASE = 0x80000;

    /** qcrilhook unsolicited response IDs */
    final int OEMHOOK_UNSOL_CDMA_BURST_DTMF = OEMHOOK_BASE + 1001;
    final int OEMHOOK_UNSOL_CDMA_CONT_DTMF_START = OEMHOOK_BASE + 1002;
    final int OEMHOOK_UNSOL_CDMA_CONT_DTMF_STOP = OEMHOOK_BASE + 1003;
    final int OEMHOOK_UNSOL_WMS_READY = OEMHOOK_BASE + 1009;

    //***** Instance Variables

    LocalSocket mSocket;
@@ -3004,7 +3015,13 @@ public final class RIL extends BaseCommands implements CommandsInterface {

            case RIL_UNSOL_OEM_HOOK_RAW:
                if (RILJ_LOGD) unsljLogvRet(response, IccUtils.bytesToHexString((byte[]) ret));
                if (mUnsolOemHookRawRegistrant != null) {
                ByteBuffer oemHookResponse = ByteBuffer.wrap((byte[]) ret);
                oemHookResponse.order(ByteOrder.nativeOrder());
                if (isQcUnsolOemHookResp(oemHookResponse)) {
                    Rlog.d(RILJ_LOG_TAG, "OEM ID check Passed");
                    processUnsolOemhookResponse(oemHookResponse);
                } else if (mUnsolOemHookRawRegistrant != null) {
                    Rlog.d(RILJ_LOG_TAG, "External OEM message, to be notified");
                    mUnsolOemHookRawRegistrant.notifyRegistrant(new AsyncResult(null, ret, null));
                }
                break;
@@ -3127,6 +3144,104 @@ public final class RIL extends BaseCommands implements CommandsInterface {
        }
    }

    private boolean isQcUnsolOemHookResp(ByteBuffer oemHookResponse) {
        String mOemIdentifier = "QOEMHOOK";
        int INT_SIZE = 4;
        int mHeaderSize = mOemIdentifier.length() + 2 * INT_SIZE;

        /* Check OEM ID in UnsolOemHook response */
        if (oemHookResponse.capacity() < mHeaderSize) {
            /*
             * size of UnsolOemHook message is less than expected, considered as
             * External OEM's message
             */
            Rlog.d(RILJ_LOG_TAG,
                    "RIL_UNSOL_OEM_HOOK_RAW data size is " + oemHookResponse.capacity());
            return false;
        } else {
            byte[] oemIdBytes = new byte[mOemIdentifier.length()];
            oemHookResponse.get(oemIdBytes);
            String oemIdString = new String(oemIdBytes);
            Rlog.d(RILJ_LOG_TAG, "Oem ID in RIL_UNSOL_OEM_HOOK_RAW is " + oemIdString);
            if (!oemIdString.equals(mOemIdentifier)) {
                /* OEM ID not matched, considered as External OEM's message */
                return false;
            }
        }
        return true;
    }

    private void processUnsolOemhookResponse(ByteBuffer oemHookResponse) {
        int responseId = 0, responseSize = 0;

        responseId = oemHookResponse.getInt();
        Rlog.d(RILJ_LOG_TAG, "Response ID in RIL_UNSOL_OEM_HOOK_RAW is " + responseId);

        responseSize = oemHookResponse.getInt();
        if (responseSize < 0) {
            Rlog.e(RILJ_LOG_TAG, "Response Size is Invalid " + responseSize);
            return;
        }

        byte[] responseData = new byte[responseSize];
        if (oemHookResponse.remaining() == responseSize) {
            oemHookResponse.get(responseData, 0, responseSize);
        } else {
            Rlog.e(RILJ_LOG_TAG, "Response Size(" + responseSize
                    + ") doesnot match remaining bytes(" +
                    oemHookResponse.remaining() + ") in the buffer. So, don't process further");
            return;
        }

        switch (responseId) {
            case OEMHOOK_UNSOL_CDMA_BURST_DTMF:
                notifyCdmaFwdBurstDtmf(responseData);
                break;

            case OEMHOOK_UNSOL_CDMA_CONT_DTMF_START:
                notifyCdmaFwdContDtmfStart(responseData);
                break;

            case OEMHOOK_UNSOL_CDMA_CONT_DTMF_STOP:
                notifyCdmaFwdContDtmfStop();
                break;

            case OEMHOOK_UNSOL_WMS_READY:
                notifyWmsReady(responseData);
                break;

            default:
                Rlog.d(RILJ_LOG_TAG, "Response ID " + responseId
                        + " is not served in this process.");
                break;
        }
    }

    /** Notify registrants of FWD Burst DTMF Tone. */
    protected void notifyCdmaFwdBurstDtmf(byte[] data) {
        AsyncResult ar = new AsyncResult(null, data, null);
        mCdmaFwdBurstDtmfRegistrants.notifyRegistrants(ar);
    }

    /** Notify registrants of FWD Continuous DTMF Tone Start. */
    protected void notifyCdmaFwdContDtmfStart(byte[] data) {
        AsyncResult ar = new AsyncResult(null, data, null);
        mCdmaFwdContDtmfStartRegistrants.notifyRegistrants(ar);
    }

    /** Notify registrants of FWD Continuous DTMF Tone Stop. */
    protected void notifyCdmaFwdContDtmfStop() {
        AsyncResult ar = new AsyncResult(null, null, null);
        mCdmaFwdContDtmfStopRegistrants.notifyRegistrants(ar);
    }

    /** Notify registrants of WMS_READY event. */
    protected void notifyWmsReady(byte[] data) {
        AsyncResult ar = new AsyncResult(null, data, null);
        mWmsReadyRegistrants.notifyRegistrants(ar);
        Rlog.d(RILJ_LOG_TAG, "WMS_READY notified to registrants");
    }

    private Object
    responseInts(Parcel p) {
        int numInts;