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

Commit 61f74035 authored by Austen Dicken's avatar Austen Dicken
Browse files

fix loss of data connectivity on devices that don't register their gateways in framework

some devices (namely sholes) do not use the android framework to define a default gateway.
this causes problems when the connection is put into suspension as the default gateway is
removed and never restored.

this solution caches the current gateway (determined via native call) when the device
is removing it due to suspension and the default gateway is not known to framework.
the cached gateway is then used when adding a default gateway in the event that one was
not provided in the interim.

Change-Id: I4a8a5d2e567d11689d7f70118582a92c5ee9b0c5
parent a0a61d9f
Loading
Loading
Loading
Loading
+36 −3
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ public abstract class NetworkStateTracker extends Handler {
    protected int mDefaultGatewayAddr;
    private boolean mTeardownRequested;

    private int mCachedGatewayAddr = 0;

    private static boolean DBG = false;
    private static final String TAG = "NetworkStateTracker";

@@ -161,12 +163,28 @@ public abstract class NetworkStateTracker extends Handler {
    }

    public void addDefaultRoute() {
        if ((mInterfaceName != null) && (mDefaultGatewayAddr != 0)) {
        if (mInterfaceName != null) {
            if (DBG) {
                Log.d(TAG, "addDefaultRoute for " + mNetworkInfo.getTypeName() +
                        " (" + mInterfaceName + "), GatewayAddr=" + mDefaultGatewayAddr);
                        " (" + mInterfaceName + "), GatewayAddr=" + mDefaultGatewayAddr +
                        ", CachedGatewayAddr=" + mCachedGatewayAddr);
            }

            if (mDefaultGatewayAddr != 0) {
                NetworkUtils.setDefaultRoute(mInterfaceName, mDefaultGatewayAddr);
            } else if (mCachedGatewayAddr != 0) {
                /*
                 * We don't have a default gateway set, so check if we have one cached due to
                 * a previous suspension.  If we do, then restore that one
                 */
                NetworkUtils.setDefaultRoute(mInterfaceName, mCachedGatewayAddr);
            }

            /*
             * Clear our cached value regardless of which of the above two situations
             * were hit.
             */
            mCachedGatewayAddr = 0;
        }
    }

@@ -176,6 +194,21 @@ public abstract class NetworkStateTracker extends Handler {
                Log.d(TAG, "removeDefaultRoute for " + mNetworkInfo.getTypeName() + " (" +
                        mInterfaceName + ")");
            }

            /*
             * Some devices don't use the android system to set their default gateway, in
             * which case the gateway is removed and never restored during data suspension.
             * In order to solve this, we check if the current gateway is 0 and if it is, we
             * call natively to cache the gateway before suspension.
             */
            if ((mNetworkInfo.getDetailedState() == NetworkInfo.DetailedState.SUSPENDED) &&
                    (mDefaultGatewayAddr == 0)) {
                if (DBG) {
                    Log.d(TAG, "removeDefaultRoute on suspended connection, saving current gateway for when we come out of suspension");
                }
                mCachedGatewayAddr = NetworkUtils.getDefaultRoute(mInterfaceName);
            }

            NetworkUtils.removeDefaultRoute(mInterfaceName);
        }
    }
+0 −3
Original line number Diff line number Diff line
@@ -800,9 +800,6 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
        if (state == State.CONNECTED) {
            if (!mCdmaPhone.mSST.isConcurrentVoiceAndData()) {
                startNetStatPoll();
                if("sholes".equalsIgnoreCase(android.os.Build.DEVICE)) {
                    cleanUpConnection(true, Phone.REASON_VOICE_CALL_ENDED);
                }
                phone.notifyDataConnection(Phone.REASON_VOICE_CALL_ENDED);
            } else {
                // clean slate after call end.