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

Commit 8beff958 authored by Robert Greenwalt's avatar Robert Greenwalt
Browse files

Stop using shared DUN APN when tethering stops.

Even if other people are sharing the connection (ie, carrier wants
default and tethered traffic on the same APN) stop using
a carrier-described APN when the tethering stops.

bug:5525764
Change-Id: I95ed2aaed4d79519d233a62cf2945edead8114bc
parent 2b072677
Loading
Loading
Loading
Loading
+25 −11
Original line number Diff line number Diff line
@@ -1031,9 +1031,14 @@ private NetworkStateTracker makeWimaxStateTracker() {
                if ((ni.isConnectedOrConnecting() == true) &&
                        !network.isTeardownRequested()) {
                    if (ni.isConnected() == true) {
                        final long token = Binder.clearCallingIdentity();
                        try {
                            // add the pid-specific dns
                            handleDnsConfigurationChange(usedNetworkType);
                            if (VDBG) log("special network already active");
                        } finally {
                            Binder.restoreCallingIdentity(token);
                        }
                        return Phone.APN_ALREADY_ACTIVE;
                    }
                    if (VDBG) log("special network already connecting");
@@ -1221,6 +1226,7 @@ private NetworkStateTracker makeWimaxStateTracker() {
        }

        if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
            if (DBG) log("requestRouteToHostAddress on invalid network: " + networkType);
            return false;
        }
        NetworkStateTracker tracker = mNetTrackers[networkType];
@@ -1233,11 +1239,16 @@ private NetworkStateTracker makeWimaxStateTracker() {
            }
            return false;
        }
        final long token = Binder.clearCallingIdentity();
        try {
            InetAddress addr = InetAddress.getByAddress(hostAddress);
            LinkProperties lp = tracker.getLinkProperties();
            return addRouteToAddress(lp, addr);
        } catch (UnknownHostException e) {}
        } catch (UnknownHostException e) {
            if (DBG) log("requestRouteToHostAddress got " + e.toString());
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        return false;
    }

@@ -1277,7 +1288,10 @@ private NetworkStateTracker makeWimaxStateTracker() {

    private boolean modifyRoute(String ifaceName, LinkProperties lp, RouteInfo r, int cycleCount,
            boolean doAdd, boolean toDefaultTable) {
        if ((ifaceName == null) || (lp == null) || (r == null)) return false;
        if ((ifaceName == null) || (lp == null) || (r == null)) {
            if (DBG) log("modifyRoute got unexpected null: " + ifaceName + ", " + lp + ", " + r);
            return false;
        }

        if (cycleCount > MAX_HOSTROUTE_CYCLE_COUNT) {
            loge("Error modifying route - too much recursion");
@@ -1309,7 +1323,7 @@ private NetworkStateTracker makeWimaxStateTracker() {
                }
            } catch (Exception e) {
                // never crash - catch them all
                if (VDBG) loge("Exception trying to add a route: " + e);
                if (DBG) loge("Exception trying to add a route: " + e);
                return false;
            }
        } else {
@@ -1323,7 +1337,7 @@ private NetworkStateTracker makeWimaxStateTracker() {
                        mNetd.removeRoute(ifaceName, r);
                    } catch (Exception e) {
                        // never crash - catch them all
                        if (VDBG) loge("Exception trying to remove a route: " + e);
                        if (DBG) loge("Exception trying to remove a route: " + e);
                        return false;
                    }
                } else {
@@ -1335,7 +1349,7 @@ private NetworkStateTracker makeWimaxStateTracker() {
                    mNetd.removeSecondaryRoute(ifaceName, r);
                } catch (Exception e) {
                    // never crash - catch them all
                    if (VDBG) loge("Exception trying to remove a route: " + e);
                    if (DBG) loge("Exception trying to remove a route: " + e);
                    return false;
                }
            }
@@ -1998,7 +2012,7 @@ private NetworkStateTracker makeWimaxStateTracker() {
                        mNetd.removeRoute(ifaceName, r);
                    } catch (Exception e) {
                        // never crash - catch them all
                        if (VDBG) loge("Exception trying to remove a route: " + e);
                        if (DBG) loge("Exception trying to remove a route: " + e);
                    }
                }
            }
@@ -2212,7 +2226,7 @@ private NetworkStateTracker makeWimaxStateTracker() {
                mNetd.setDnsServersForInterface(iface, NetworkUtils.makeStrings(dnses));
                mNetd.setDefaultInterfaceForDns(iface);
            } catch (Exception e) {
                if (VDBG) loge("exception setting default dns interface: " + e);
                if (DBG) loge("exception setting default dns interface: " + e);
            }
        }
        if (!domains.equals(SystemProperties.get("net.dns.search"))) {
@@ -2242,7 +2256,7 @@ private NetworkStateTracker makeWimaxStateTracker() {
                    mNetd.setDnsServersForInterface(p.getInterfaceName(),
                            NetworkUtils.makeStrings(dnses));
                } catch (Exception e) {
                    if (VDBG) loge("exception setting dns servers: " + e);
                    if (DBG) loge("exception setting dns servers: " + e);
                }
                // set per-pid dns for attached secondary nets
                List pids = mNetRequestersPids[netType];
+63 −5
Original line number Diff line number Diff line
@@ -68,6 +68,8 @@ public abstract class DataConnection extends StateMachine {
    private List<ApnContext> mApnList = null;
    PendingIntent mReconnectIntent = null;

    private DataConnectionTracker mDataConnectionTracker = null;

    /**
     * Used internally for saving connecting parameters.
     */
@@ -201,6 +203,7 @@ public abstract class DataConnection extends StateMachine {
    protected static final int EVENT_DEACTIVATE_DONE = BASE + 3;
    protected static final int EVENT_DISCONNECT = BASE + 4;
    protected static final int EVENT_RIL_CONNECTED = BASE + 5;
    protected static final int EVENT_DISCONNECT_ALL = BASE + 6;

    //***** Tag IDs for EventLog
    protected static final int EVENT_LOG_BAD_DNS_ADDRESS = 50100;
@@ -233,10 +236,12 @@ public abstract class DataConnection extends StateMachine {


   //***** Constructor
    protected DataConnection(PhoneBase phone, String name, int id, RetryManager rm) {
    protected DataConnection(PhoneBase phone, String name, int id, RetryManager rm,
            DataConnectionTracker dct) {
        super(name);
        if (DBG) log("DataConnection constructor E");
        this.phone = phone;
        this.mDataConnectionTracker = dct;
        mId = id;
        mRetryMgr = rm;
        this.cid = -1;
@@ -315,11 +320,16 @@ public abstract class DataConnection extends StateMachine {
     *
     * @param dp is the DisconnectParams.
     */
    private void notifyDisconnectCompleted(DisconnectParams dp) {
    private void notifyDisconnectCompleted(DisconnectParams dp, boolean sendAll) {
        if (VDBG) log("NotifyDisconnectCompleted");

        ApnContext alreadySent = null;
        String reason = null;

        if (dp.onCompletedMsg != null) {
            Message msg = dp.onCompletedMsg;
            alreadySent = (ApnContext)msg.obj;
            reason = dp.reason;
            if (VDBG) {
                log(String.format("msg=%s msg.obj=%s", msg.toString(),
                    ((msg.obj instanceof String) ? (String) msg.obj : "<no-reason>")));
@@ -327,6 +337,17 @@ public abstract class DataConnection extends StateMachine {
            AsyncResult.forMessage(msg);
            msg.sendToTarget();
        }
        if (sendAll) {
            for (ApnContext a : mApnList) {
                if (a == alreadySent) continue;
                if (reason != null) a.setReason(reason);
                Message msg = mDataConnectionTracker.obtainMessage(
                        DataConnectionTracker.EVENT_DISCONNECT_DONE, a);
                AsyncResult.forMessage(msg);
                msg.sendToTarget();
            }
        }

        if (DBG) log("NotifyDisconnectCompleted DisconnectParams=" + dp);
    }

@@ -705,6 +726,13 @@ public abstract class DataConnection extends StateMachine {
                    deferMessage(msg);
                    break;

                case EVENT_DISCONNECT_ALL:
                    if (DBG) {
                        log("DcDefaultState deferring msg.what=EVENT_DISCONNECT_ALL" + mRefCount);
                    }
                    deferMessage(msg);
                    break;

                case EVENT_RIL_CONNECTED:
                    ar = (AsyncResult)msg.obj;
                    if (ar.exception == null) {
@@ -770,7 +798,7 @@ public abstract class DataConnection extends StateMachine {
            }
            if (mDisconnectParams != null) {
                if (VDBG) log("DcInactiveState: enter notifyDisconnectCompleted");
                notifyDisconnectCompleted(mDisconnectParams);
                notifyDisconnectCompleted(mDisconnectParams, true);
            }
            clearSettings();
        }
@@ -811,7 +839,13 @@ public abstract class DataConnection extends StateMachine {

                case EVENT_DISCONNECT:
                    if (DBG) log("DcInactiveState: msg.what=EVENT_DISCONNECT");
                    notifyDisconnectCompleted((DisconnectParams)msg.obj);
                    notifyDisconnectCompleted((DisconnectParams)msg.obj, false);
                    retVal = HANDLED;
                    break;

                case EVENT_DISCONNECT_ALL:
                    if (DBG) log("DcInactiveState: msg.what=EVENT_DISCONNECT_ALL");
                    notifyDisconnectCompleted((DisconnectParams)msg.obj, false);
                    retVal = HANDLED;
                    break;

@@ -988,9 +1022,21 @@ public abstract class DataConnection extends StateMachine {
                        transitionTo(mDisconnectingState);
                    } else {
                        if (msg.obj != null) {
                            notifyDisconnectCompleted((DisconnectParams) msg.obj);
                            notifyDisconnectCompleted((DisconnectParams) msg.obj, false);
                        }
                    }
                    retVal = HANDLED;
                    break;

                case EVENT_DISCONNECT_ALL:
                    if (DBG) {
                        log("DcActiveState msg.what=EVENT_DISCONNECT_ALL RefCount=" + mRefCount);
                    }
                    mRefCount = 0;
                    DisconnectParams dp = (DisconnectParams) msg.obj;
                    dp.tag = mTag;
                    tearDownData(dp);
                    transitionTo(mDisconnectingState);
                    retVal = HANDLED;
                    break;

@@ -1123,4 +1169,16 @@ public abstract class DataConnection extends StateMachine {
    public void tearDown(String reason, Message onCompletedMsg) {
        sendMessage(obtainMessage(EVENT_DISCONNECT, new DisconnectParams(reason, onCompletedMsg)));
    }

    /**
     * Tear down the connection through the apn on the network.  Ignores refcount and
     * and always tears down.
     *
     * @param onCompletedMsg is sent with its msg.obj as an AsyncResult object.
     *        With AsyncResult.userObj set to the original msg.obj.
     */
    public void tearDownAll(String reason, Message onCompletedMsg) {
        sendMessage(obtainMessage(EVENT_DISCONNECT_ALL,
                new DisconnectParams(reason, onCompletedMsg)));
    }
}
+7 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.os.Message;
import android.util.Log;

import com.android.internal.telephony.DataConnection;
import com.android.internal.telephony.DataConnectionTracker;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.RILConstants;
import com.android.internal.telephony.RetryManager;
@@ -32,8 +33,9 @@ public class CdmaDataConnection extends DataConnection {
    private static final String LOG_TAG = "CDMA";

    // ***** Constructor
    private CdmaDataConnection(CDMAPhone phone, String name, int id, RetryManager rm) {
        super(phone, name, id, rm);
    private CdmaDataConnection(CDMAPhone phone, String name, int id, RetryManager rm,
            DataConnectionTracker dct) {
        super(phone, name, id, rm, dct);
    }

    /**
@@ -44,12 +46,13 @@ public class CdmaDataConnection extends DataConnection {
     * @param rm the RetryManager
     * @return CdmaDataConnection that was created.
     */
    static CdmaDataConnection makeDataConnection(CDMAPhone phone, int id, RetryManager rm) {
    static CdmaDataConnection makeDataConnection(CDMAPhone phone, int id, RetryManager rm,
            DataConnectionTracker dct) {
        synchronized (mCountLock) {
            mCount += 1;
        }
        CdmaDataConnection cdmaDc = new CdmaDataConnection(phone, "CdmaDC-" + mCount,
                id, rm);
                id, rm, dct);
        cdmaDc.start();
        if (DBG) cdmaDc.log("Made " + cdmaDc.getName());
        return cdmaDc;
+1 −1
Original line number Diff line number Diff line
@@ -772,7 +772,7 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
            }

            int id = mUniqueIdGenerator.getAndIncrement();
            dataConn = CdmaDataConnection.makeDataConnection(mCdmaPhone, id, rm);
            dataConn = CdmaDataConnection.makeDataConnection(mCdmaPhone, id, rm, this);
            mDataConnections.put(id, dataConn);
            DataConnectionAc dcac = new DataConnectionAc(dataConn, LOG_TAG);
            int status = dcac.fullyConnectSync(mPhone.getContext(), this, dataConn.getHandler());
+7 −4
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.util.Patterns;
import android.text.TextUtils;

import com.android.internal.telephony.DataConnection;
import com.android.internal.telephony.DataConnectionTracker;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneBase;
import com.android.internal.telephony.RILConstants;
@@ -37,8 +38,9 @@ public class GsmDataConnection extends DataConnection {
    //***** Instance Variables
    protected int mProfileId = RILConstants.DATA_PROFILE_DEFAULT;
    //***** Constructor
    private GsmDataConnection(PhoneBase phone, String name, int id, RetryManager rm) {
        super(phone, name, id, rm);
    private GsmDataConnection(PhoneBase phone, String name, int id, RetryManager rm,
            DataConnectionTracker dct) {
        super(phone, name, id, rm, dct);
    }

    /**
@@ -49,11 +51,12 @@ public class GsmDataConnection extends DataConnection {
     * @param rm the RetryManager
     * @return GsmDataConnection that was created.
     */
    static GsmDataConnection makeDataConnection(PhoneBase phone, int id, RetryManager rm) {
    static GsmDataConnection makeDataConnection(PhoneBase phone, int id, RetryManager rm,
            DataConnectionTracker dct) {
        synchronized (mCountLock) {
            mCount += 1;
        }
        GsmDataConnection gsmDc = new GsmDataConnection(phone, "GsmDC-" + mCount, id, rm);
        GsmDataConnection gsmDc = new GsmDataConnection(phone, "GsmDC-" + mCount, id, rm, dct);
        gsmDc.start();
        if (DBG) gsmDc.log("Made " + gsmDc.getName());
        return gsmDc;
Loading