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

Commit 5fe20bdf authored by jt1134's avatar jt1134
Browse files

correctly export gateway and local ip to the framework on Samsung CDMA devices

using FroYo RIL blobs, we can extract this information from system properties

Change-Id: Iaba4eb4ead13216a67fb96f7269847ed902db54f
parent 0d6e46d6
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@ import android.telephony.TelephonyManager;
import android.util.Log;
import android.text.TextUtils;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Track the state of mobile data connectivity. This is done by
 * receiving broadcast intents from the Phone process whenever
@@ -243,7 +246,14 @@ public class MobileDataStateTracker extends NetworkStateTracker {
                                if (mInterfaceName == null) {
                                    Log.d(TAG, "CONNECTED event did not supply interface name.");
                                }

                                // Samsung CDMA devices do not export gateway to the framework correctly
                                // if using FroYo RIL blobs, we can extract it from system properties
                                if (SystemProperties.get("ro.ril.samsung_cdma").equals("true"))
                                    mDefaultGatewayAddr = getIpFromString(SystemProperties.get("net.ppp0.remote-ip"));
                                else
                                    mDefaultGatewayAddr = intent.getIntExtra(Phone.DATA_GATEWAY_KEY, 0);

                                if (mDefaultGatewayAddr == 0) {
                                    Log.d(TAG, "CONNECTED event did not supply a default gateway.");
                                }
@@ -264,6 +274,24 @@ public class MobileDataStateTracker extends NetworkStateTracker {
        }
    }

    private int getIpFromString(String ip)
    {
        InetAddress inetAddress;
        try {
            inetAddress = InetAddress.getByName(ip);
        } catch (UnknownHostException e) {
            return -1;
        }
        byte[] addrBytes;
        int addr;
        addrBytes = inetAddress.getAddress();
        addr = ((addrBytes[3] & 0xff) << 24)
                | ((addrBytes[2] & 0xff) << 16)
                | ((addrBytes[1] & 0xff) << 8)
                |  (addrBytes[0] & 0xff);
        return addr;
    }

    private void getPhoneService(boolean forceRefresh) {
        if ((mPhoneService == null) || forceRefresh) {
            mPhoneService = ITelephony.Stub.asInterface(ServiceManager.getService("phone"));
+17 −5
Original line number Diff line number Diff line
@@ -395,6 +395,8 @@ public abstract class DataConnection extends HierarchicalStateMachine {
        String[] response = ((String[]) ar.result);
        ConnectionParams cp = (ConnectionParams) ar.userObj;

        boolean mIsSamsungCdma = SystemProperties.getBoolean("ro.ril.samsung_cdma", false);

        if (ar.exception != null) {
            if (DBG) log("DataConnection Init failed " + ar.exception);

@@ -418,11 +420,21 @@ public abstract class DataConnection extends HierarchicalStateMachine {
//            }
            if (response.length >= 2) {
                cid = Integer.parseInt(response[0]);
                interfaceName = response[1];
                if (response.length > 2) {
                    // Samsung CDMA devices do not export gateway/ip to the framework correctly
                    // if using FroYo RIL blobs, we can extract it from system properties
                    String prefix;
                    if (mIsSamsungCdma) {
                        interfaceName = "ppp0";
                        prefix = "net." + interfaceName + ".";
                        ipAddress = SystemProperties.get(prefix + "local-ip");
                        gatewayAddress = SystemProperties.get(prefix + "remote-ip");
                    } else {
                        interfaceName = response[1];
                        prefix = "net." + interfaceName + ".";
                        ipAddress = response[2];
                    String prefix = "net." + interfaceName + ".";
                        gatewayAddress = SystemProperties.get(prefix + "gw");
                    }
                    dnsServers[0] = SystemProperties.get(prefix + "dns1");
                    dnsServers[1] = SystemProperties.get(prefix + "dns2");
                    if (DBG) {
@@ -445,7 +457,7 @@ public abstract class DataConnection extends HierarchicalStateMachine {
        }
        // Samsung CDMA devices require this property to be set
        // so that pppd will be called to start 3G data
        if (SystemProperties.get("ro.ril.samsung_cdma").equals("true"))
        if (mIsSamsungCdma)
            SystemProperties.set("ril.cdma.data_ready", "true");

        if (DBG) log("DataConnection setup result='" + result + "' on cid=" + cid);