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

Commit 28fd0236 authored by nharold's avatar nharold Committed by android-build-merger
Browse files

Merge "Plumb NattKeepalive from HAL to DataConnection"

am: 6a89929a

Change-Id: Ie3ee2fb440a2b2bc22c510cd4d85437426195954
parents a6aa1975 6a89929a
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ public abstract class BaseCommands implements CommandsInterface {
    protected RegistrantList mCarrierInfoForImsiEncryptionRegistrants = new RegistrantList();
    protected RegistrantList mRilNetworkScanResultRegistrants = new RegistrantList();
    protected RegistrantList mModemResetRegistrants = new RegistrantList();

    protected RegistrantList mNattKeepaliveStatusRegistrants = new RegistrantList();

    protected Registrant mGsmSmsRegistrant;
    protected Registrant mCdmaSmsRegistrant;
@@ -939,4 +939,20 @@ public abstract class BaseCommands implements CommandsInterface {
    public void unregisterForCarrierInfoForImsiEncryption(Handler h) {
        mCarrierInfoForImsiEncryptionRegistrants.remove(h);
    }

    @Override
    public void registerForNattKeepaliveStatus(Handler h, int what, Object obj) {
        Registrant r = new Registrant(h, what, obj);

        synchronized (mStateMonitor) {
            mNattKeepaliveStatusRegistrants.add(r);
        }
    }

    @Override
    public void unregisterForNattKeepaliveStatus(Handler h) {
        synchronized (mStateMonitor) {
            mNattKeepaliveStatusRegistrants.remove(h);
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -259,6 +259,8 @@ public class CommandException extends RuntimeException {
                return new CommandException(Error.DEVICE_IN_USE);
            case RILConstants.ABORTED:
                return new CommandException(Error.ABORTED);
            case RILConstants.INVALID_RESPONSE:
                return new CommandException(Error.INVALID_RESPONSE);
            case RILConstants.OEM_ERROR_1:
                return new CommandException(Error.OEM_ERROR_1);
            case RILConstants.OEM_ERROR_2:
+41 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.telephony;

import android.net.KeepalivePacketData;
import android.os.Handler;
import android.os.Message;
import android.os.WorkSource;
@@ -2073,7 +2074,7 @@ public interface CommandsInterface {
     * Register for unsolicited PCO data.  This information is carrier-specific,
     * opaque binary blobs destined for carrier apps for interpretation.
     *
     * @param h Handler for notificaiton message.
     * @param h Handler for notification message.
     * @param what User-defined message code.
     * @param obj User object.
     */
@@ -2133,7 +2134,7 @@ public interface CommandsInterface {
    /**
     * Register for unsolicited Carrier Public Key.
     *
     * @param h Handler for notificaiton message.
     * @param h Handler for notification message.
     * @param what User-defined message code.
     * @param obj User object.
     */
@@ -2142,14 +2143,14 @@ public interface CommandsInterface {
    /**
     * DeRegister for unsolicited Carrier Public Key.
     *
     * @param h Handler for notificaiton message.
     * @param h Handler for notification message.
     */
    void unregisterForCarrierInfoForImsiEncryption(Handler h);

    /**
     * Register for unsolicited Network Scan result.
     *
     * @param h Handler for notificaiton message.
     * @param h Handler for notification message.
     * @param what User-defined message code.
     * @param obj User object.
     */
@@ -2158,10 +2159,45 @@ public interface CommandsInterface {
    /**
     * DeRegister for unsolicited Network Scan result.
     *
     * @param h Handler for notificaiton message.
     * @param h Handler for notification message.
     */
    void unregisterForNetworkScanResult(Handler h);

    /**
     * Register for unsolicited NATT Keepalive Status Indications
     *
     * @param h Handler for notification message.
     * @param what User-defined message code.
     * @param obj User object.
     */
    void registerForNattKeepaliveStatus(Handler h, int what, Object obj);

    /**
     * Deregister for unsolicited NATT Keepalive Status Indications.
     *
     * @param h Handler for notification message.
     */
    void unregisterForNattKeepaliveStatus(Handler h);

    /**
     * Start sending NATT Keepalive packets on a specified data connection
     *
     * @param contextId cid that identifies the data connection for this keepalive
     * @param packetData the keepalive packet data description
     * @param intervalMillis a time interval in ms between keepalive packet transmissions
     * @param result a Message to return to the requester
     */
    void startNattKeepalive(
            int contextId, KeepalivePacketData packetData, int intervalMillis, Message result);

    /**
     * Stop sending NATT Keepalive packets on a specified data connection
     *
     * @param sessionHandle the keepalive session handle (from the modem) to stop
     * @param result a Message to return to the requester
     */
    void stopNattKeepalive(int sessionHandle, Message result);

    default public List<ClientRequestStats> getClientRequestStats() {
        return null;
    }
+103 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.hardware.radio.V1_0.SimApdu;
import android.hardware.radio.V1_0.SmsWriteArgs;
import android.hardware.radio.V1_0.UusInfo;
import android.net.ConnectivityManager;
import android.net.KeepalivePacketData;
import android.net.LinkAddress;
import android.net.NetworkUtils;
import android.os.AsyncResult;
@@ -106,6 +107,7 @@ import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
@@ -3758,6 +3760,93 @@ public class RIL extends BaseCommands implements CommandsInterface {
        }
    }

    @Override
    public void startNattKeepalive(
            int contextId, KeepalivePacketData packetData, int intervalMillis, Message result) {
        checkNotNull(packetData, "KeepaliveRequest cannot be null.");
        IRadio radioProxy = getRadioProxy(result);
        if (radioProxy == null) {
            riljLoge("Radio Proxy object is null!");
            return;
        }

        android.hardware.radio.V1_1.IRadio radioProxy11 =
                android.hardware.radio.V1_1.IRadio.castFrom(radioProxy);
        if (radioProxy11 == null) {
            if (result != null) {
                AsyncResult.forMessage(result, null,
                        CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
                result.sendToTarget();
            }
            return;
        }

        RILRequest rr = obtainRequest(
                RIL_REQUEST_START_KEEPALIVE, result, mRILDefaultWorkSource);

        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));

        try {
            android.hardware.radio.V1_1.KeepaliveRequest req =
                    new android.hardware.radio.V1_1.KeepaliveRequest();

            req.cid = contextId;

            if (packetData.dstAddress instanceof Inet4Address) {
                req.type = android.hardware.radio.V1_1.KeepaliveType.NATT_IPV4;
            } else if (packetData.dstAddress instanceof Inet6Address) {
                req.type = android.hardware.radio.V1_1.KeepaliveType.NATT_IPV6;
            } else {
                AsyncResult.forMessage(result, null,
                        CommandException.fromRilErrno(INVALID_ARGUMENTS));
                result.sendToTarget();
                return;
            }

            appendPrimitiveArrayToArrayList(
                    packetData.srcAddress.getAddress(), req.sourceAddress);
            req.sourcePort = packetData.srcPort;
            appendPrimitiveArrayToArrayList(
                    packetData.dstAddress.getAddress(), req.destinationAddress);
            req.destinationPort = packetData.dstPort;

            radioProxy11.startKeepalive(rr.mSerial, req);
        } catch (RemoteException | RuntimeException e) {
            handleRadioProxyExceptionForRR(rr, "startNattKeepalive", e);
        }
    }

    @Override
    public void stopNattKeepalive(int sessionHandle, Message result) {
        IRadio radioProxy = getRadioProxy(result);
        if (radioProxy == null) {
            Rlog.e(RIL.RILJ_LOG_TAG, "Radio Proxy object is null!");
            return;
        }

        android.hardware.radio.V1_1.IRadio radioProxy11 =
                android.hardware.radio.V1_1.IRadio.castFrom(radioProxy);
        if (radioProxy11 == null) {
            if (result != null) {
                AsyncResult.forMessage(result, null,
                        CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
                result.sendToTarget();
            }
            return;
        }

        RILRequest rr = obtainRequest(
                RIL_REQUEST_STOP_KEEPALIVE, result, mRILDefaultWorkSource);

        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));

        try {
            radioProxy11.stopKeepalive(rr.mSerial, sessionHandle);
        } catch (RemoteException | RuntimeException e) {
            handleRadioProxyExceptionForRR(rr, "stopNattKeepalive", e);
        }
    }

    @Override
    public void getIMEI(Message result) {
        throw new RuntimeException("getIMEI not expected to be called");
@@ -4687,6 +4776,10 @@ public class RIL extends BaseCommands implements CommandsInterface {
                return "RIL_REQUEST_GET_SLOT_STATUS";
            case RIL_REQUEST_SET_LOGICAL_TO_PHYSICAL_SLOT_MAPPING:
                return "RIL_REQUEST_SET_LOGICAL_TO_PHYSICAL_SLOT_MAPPING";
            case RIL_REQUEST_START_KEEPALIVE:
                return "RIL_REQUEST_START_KEEPALIVE";
            case RIL_REQUEST_STOP_KEEPALIVE:
                return "RIL_REQUEST_STOP_KEEPALIVE";
            default: return "<unknown request>";
        }
    }
@@ -4791,6 +4884,8 @@ public class RIL extends BaseCommands implements CommandsInterface {
                return "RIL_UNSOL_NETWORK_SCAN_RESULT";
            case RIL_UNSOL_ICC_SLOT_STATUS:
                return "RIL_UNSOL_ICC_SLOT_STATUS";
            case RIL_UNSOL_KEEPALIVE_STATUS:
                return "RIL_UNSOL_KEEPALIVE_STATUS";
            default:
                return "<unknown response>";
        }
@@ -4871,6 +4966,13 @@ public class RIL extends BaseCommands implements CommandsInterface {
        return mClientWakelockTracker.getClientRequestStats();
    }

    /** Append the data to the end of an ArrayList */
    public static void appendPrimitiveArrayToArrayList(byte[] src, ArrayList<Byte> dst) {
        for (byte b : src) {
            dst.add(b);
        }
    }

    public static ArrayList<Byte> primitiveArrayToArrayList(byte[] arr) {
        ArrayList<Byte> arrayList = new ArrayList<>(arr.length);
        for (byte b : arr) {
@@ -4879,6 +4981,7 @@ public class RIL extends BaseCommands implements CommandsInterface {
        return arrayList;
    }

    /** Convert an ArrayList of Bytes to an exactly-sized primitive array */
    public static byte[] arrayListToPrimitiveArray(ArrayList<Byte> bytes) {
        byte[] ret = new byte[bytes.size()];
        for (int i = 0; i < ret.length; i++) {
+14 −4
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static com.android.internal.telephony.RILConstants.RIL_UNSOL_DATA_CALL_LI
import static com.android.internal.telephony.RILConstants.RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE;
import static com.android.internal.telephony.RILConstants.RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE;
import static com.android.internal.telephony.RILConstants.RIL_UNSOL_HARDWARE_CONFIG_CHANGED;
import static com.android.internal.telephony.RILConstants.RIL_UNSOL_KEEPALIVE_STATUS;
import static com.android.internal.telephony.RILConstants.RIL_UNSOL_LCEDATA_RECV;
import static com.android.internal.telephony.RILConstants.RIL_UNSOL_MODEM_RESTART;
import static com.android.internal.telephony.RILConstants.RIL_UNSOL_NETWORK_SCAN_RESULT;
@@ -80,7 +81,6 @@ import android.hardware.radio.V1_0.SimRefreshResult;
import android.hardware.radio.V1_0.SsInfoData;
import android.hardware.radio.V1_0.StkCcUnsolSsResult;
import android.hardware.radio.V1_0.SuppSvcNotification;
import android.hardware.radio.V1_1.KeepaliveStatus;
import android.hardware.radio.V1_2.IRadioIndication;
import android.hardware.radio.V1_2.PhysicalChannelConfig;
import android.os.AsyncResult;
@@ -94,6 +94,7 @@ import android.telephony.data.DataCallResponse;
import com.android.internal.telephony.cdma.CdmaCallWaitingNotification;
import com.android.internal.telephony.cdma.CdmaInformationRecords;
import com.android.internal.telephony.cdma.SmsMessageConverter;
import com.android.internal.telephony.dataconnection.KeepaliveStatus;
import com.android.internal.telephony.gsm.SsData;
import com.android.internal.telephony.gsm.SuppServiceNotification;
import com.android.internal.telephony.nano.TelephonyProto.SmsSession;
@@ -843,10 +844,19 @@ public class RadioIndication extends IRadioIndication.Stub {
    /**
     * Indicates a change in the status of an ongoing Keepalive session
     * @param indicationType RadioIndicationType
     * @param keepaliveStatus Status of the ongoing Keepalive session
     * @param halStatus Status of the ongoing Keepalive session
     */
    public void keepaliveStatus(int indicationType, KeepaliveStatus keepaliveStatus) {
        throw new UnsupportedOperationException("keepaliveStatus Indications are not implemented");
    public void keepaliveStatus(
            int indicationType, android.hardware.radio.V1_1.KeepaliveStatus halStatus) {
        mRil.processIndication(indicationType);

        if (RIL.RILJ_LOGD) {
            mRil.unsljLogRet(RIL_UNSOL_KEEPALIVE_STATUS,
                    "handle=" + halStatus.sessionHandle + " code=" +  halStatus.code);
        }

        KeepaliveStatus ks = new KeepaliveStatus(halStatus.sessionHandle, halStatus.code);
        mRil.mNattKeepaliveStatusRegistrants.notifyRegistrants(new AsyncResult(null, ks, null));
    }

    private CommandsInterface.RadioState getRadioStateFromInt(int stateInt) {
Loading