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

Commit 15cd6ec2 authored by Wink Saville's avatar Wink Saville
Browse files

Tear down connection with unwanted linkproperty change

Make sure to disconnect the link when RIL reported link property change
which could cause connectivity issue. (i.e. IP address)

Change-Id: I6601ef53e4561bdc7d2760d00e134b8431512cb2
parent 16e8d22b
Loading
Loading
Loading
Loading
+26 −8
Original line number Diff line number Diff line
@@ -22,8 +22,10 @@ import com.android.internal.util.Protocol;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;

import android.net.LinkAddress;
import android.net.LinkCapabilities;
import android.net.LinkProperties;
import android.net.NetworkUtils;
import android.net.ProxyProperties;
import android.os.AsyncResult;
import android.os.Bundle;
@@ -33,6 +35,7 @@ import android.os.Parcelable;
import android.os.SystemProperties;
import android.text.TextUtils;

import java.util.Collection;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger;

@@ -533,8 +536,10 @@ public abstract class DataConnection extends StateMachine {
        return response.setLinkProperties(lp, okToUseSystemPropertyDns);
    }

    private boolean updateLinkProperty(DataCallState newState) {
        boolean changed = false;
    private DataConnectionAc.LinkPropertyChangeAction updateLinkProperty(
                                                      DataCallState newState) {
        DataConnectionAc.LinkPropertyChangeAction changed =
                        DataConnectionAc.LinkPropertyChangeAction.NONE;

        if (newState == null) return changed;

@@ -553,9 +558,23 @@ public abstract class DataConnection extends StateMachine {
        if (DBG) log("old LP=" + mLinkProperties);
        if (DBG) log("new LP=" + newLp);

        // Check consistency of link address. Currently we expect
        // only one "global" address is assigned per each IP type.
        Collection<LinkAddress> oLinks = mLinkProperties.getLinkAddresses();
        Collection<LinkAddress> nLinks = newLp.getLinkAddresses();
        for (LinkAddress oldLink : oLinks) {
            for (LinkAddress newLink : nLinks) {
                if ((NetworkUtils.addressTypeMatches(oldLink.getAddress(),
                                        newLink.getAddress())) &&
                    (oldLink.equals(newLink) == false)) {
                    return DataConnectionAc.LinkPropertyChangeAction.RESET;
                }
            }
        }

        if (mLinkProperties == null || !mLinkProperties.equals(newLp)) {
            mLinkProperties = newLp;
            changed = true;
            changed = DataConnectionAc.LinkPropertyChangeAction.CHANGED;
        }

        return changed;
@@ -633,15 +652,14 @@ public abstract class DataConnection extends StateMachine {
                }
                case DataConnectionAc.REQ_UPDATE_LINK_PROPERTIES_DATA_CALL_STATE: {
                    DataCallState newState = (DataCallState) msg.obj;
                    int updated = updateLinkProperty(newState) ? 1 : 0;
                    DataConnectionAc.LinkPropertyChangeAction action = updateLinkProperty(newState);
                    if (DBG) {
                        log("REQ_UPDATE_LINK_PROPERTIES_DATA_CALL_STATE updated="
                                + (updated == 1)
                                + " newState=" + newState);
                        log("REQ_UPDATE_LINK_PROPERTIES_DATA_CALL_STATE action="
                            + action + " newState=" + newState);
                    }
                    mAc.replyToMessage(msg,
                                   DataConnectionAc.RSP_UPDATE_LINK_PROPERTIES_DATA_CALL_STATE,
                                   updated);
                                   action.ordinal());
                    break;
                }
                case DataConnectionAc.REQ_GET_LINK_CAPABILITIES: {
+24 −4
Original line number Diff line number Diff line
@@ -59,6 +59,26 @@ public class DataConnectionAc extends AsyncChannel {
    public static final int REQ_RESET = BASE + 14;
    public static final int RSP_RESET = BASE + 15;

    /**
     * enum used to notify action taken or necessary to be
     * taken after the link property is changed.
     */
    public enum LinkPropertyChangeAction {
        NONE, CHANGED, RESET;

        public static LinkPropertyChangeAction fromInt(int value) {
            if (value == NONE.ordinal()) {
                return NONE;
            } else if (value == CHANGED.ordinal()) {
                return CHANGED;
            } else if (value == RESET.ordinal()) {
                return RESET;
            } else {
                throw new RuntimeException("LinkPropertyChangeAction.fromInt: bad value=" + value);
            }
        }
    }

    public DataConnectionAc(DataConnection dc, String logTag) {
        dataConnection = dc;
        mLogTag = logTag;
@@ -234,8 +254,8 @@ public class DataConnectionAc extends AsyncChannel {
        if (DBG) log("reqUpdateLinkPropertiesDataCallState");
    }

    public boolean rspUpdateLinkPropertiesDataCallState(Message response) {
        boolean retVal = response.arg1 == 1;
    public LinkPropertyChangeAction rspUpdateLinkPropertiesDataCallState(Message response) {
        LinkPropertyChangeAction retVal = LinkPropertyChangeAction.fromInt(response.arg1);
        if (DBG) log("rspUpdateLinkPropertiesState=" + retVal);
        return retVal;
    }
@@ -245,7 +265,7 @@ public class DataConnectionAc extends AsyncChannel {
     *
     * @return true if link property has been updated. false otherwise.
     */
    public boolean updateLinkPropertiesDataCallStateSync(DataCallState newState) {
    public LinkPropertyChangeAction updateLinkPropertiesDataCallStateSync(DataCallState newState) {
        Message response =
            sendMessageSynchronously(REQ_UPDATE_LINK_PROPERTIES_DATA_CALL_STATE, newState);
        if ((response != null) &&
@@ -253,7 +273,7 @@ public class DataConnectionAc extends AsyncChannel {
            return rspUpdateLinkPropertiesDataCallState(response);
        } else {
            log("getLinkProperties error response=" + response);
            return false;
            return LinkPropertyChangeAction.NONE;
        }
    }

+25 −13
Original line number Diff line number Diff line
@@ -1059,25 +1059,37 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
                    if (DBG) log("onDataStateChanged(ar): Found ConnId=" + connectionId
                            + " newState=" + newState.toString());
                    if (newState.active != 0) {
                        boolean changed
                            = dcac.updateLinkPropertiesDataCallStateSync(newState);
                        if (changed) {
                        boolean resetConnection;
                        switch (dcac.updateLinkPropertiesDataCallStateSync(newState)) {
                        case NONE:
                            if (DBG) log("onDataStateChanged(ar): Found but no change, skip");
                            resetConnection = false;
                            break;
                        case CHANGED:
                            if (DBG) log("onDataStateChanged(ar): Found and changed, notify");
                            mPhone.notifyDataConnection(Phone.REASON_LINK_PROPERTIES_CHANGED,
                                                        apnContext.getApnType());
                            // Temporary hack, if false we'll reset connections and at this
                            // time a transition from CDMA -> Global fails. The DEACTIVATE
                            // fails with a GENERIC_FAILURE and the VZWINTERNET connection is
                            // never setup. @see bug/
                            // Temporary hack, at this time a transition from CDMA -> Global
                            // fails so we'll hope for the best and not reset the connection.
                            // @see bug/4455071
                            if (SystemProperties.getBoolean("telephony.ignore-state-changes",
                                                            true)) {
                                log("onDataStateChanged(ar): STOPSHIP don't reset, continue");
                                continue;
                            }
                                resetConnection = false;
                            } else {
                            if (DBG) log("onDataStateChanged(ar): Found but no change, skip");
                            continue;
                                // Things changed so reset connection, when hack is removed
                                // this is the normal path.
                                log("onDataStateChanged(ar): changed so resetting connection");
                                resetConnection = true;
                            }
                            break;
                        case RESET:
                        default:
                            if (DBG) log("onDataStateChanged(ar): an error, reset connection");
                            resetConnection = true;
                            break;
                        }
                        if (resetConnection == false) continue;
                    }
                }