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

Commit ffa59b7f authored by Sudheer Reddy Yampalla's avatar Sudheer Reddy Yampalla Committed by Steve Kondik
Browse files

Telephony: Avoid Infinite loop problem in Tethering

1. Whenever data is enabled we will try to establish the tethered
call (USB tethering enabled case) for 5 fixed number of retries.
After reaching maximum number of retries we are turning off the
upstream connection. whenever the CONNECTIVTY_ACTION received
(because of USB cable disconnected and then connected case or
some changes), it can try to bring up the dun/hipri PDP again.

2. There is no retry in case of data disabled case.

Change-Id: I16af4d2983a8bf9ce0ce904877f86169bca549b4
CRs-Fixed: 401829
(cherry picked from commit 4c923c8537fdc49ef491b964adc1871c77bfd730)
(cherry picked from commit 3135e6a89ac14008df04fe6e068bd8dd95b4ee40)
(cherry picked from commit 137b7004f716a559c7249be20e25544fe10330b6)
parent b450ca23
Loading
Loading
Loading
Loading
+29 −8
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
    // with 255.255.255.0

    private String[] mDhcpRange;
    private static final int TETHER_RETRY_UPSTREAM_LIMIT = 5;
    private static final String[] DHCP_DEFAULT_RANGE = {
        "192.168.42.2", "192.168.42.254", "192.168.43.2", "192.168.43.254",
        "192.168.44.2", "192.168.44.254", "192.168.45.2", "192.168.45.254",
@@ -1180,6 +1181,8 @@ public class Tethering extends INetworkManagementEventObserver.Stub {

        private String mUpstreamIfaceName = null;

        protected int mRetryCount;

        private static final int UPSTREAM_SETTLE_TIME_MS     = 10000;
        private static final int CELL_CONNECTION_RENEW_MS    = 40000;

@@ -1413,15 +1416,32 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
                }

                if (upType == ConnectivityManager.TYPE_NONE) {
                    try {
                        if (cm.getMobileDataEnabled()) {
                            boolean tryAgainLater = true;
                            if (mRetryCount < TETHER_RETRY_UPSTREAM_LIMIT) {
                                if ((tryCell == TRY_TO_SETUP_MOBILE_CONNECTION) &&
                            (turnOnUpstreamMobileConnection(mPreferredUpstreamMobileApn) == true)) {
                                         (turnOnUpstreamMobileConnection
                                                (mPreferredUpstreamMobileApn) == true)) {
                                    // we think mobile should be coming up - don't set a retry
                                    tryAgainLater = false;
                                    mRetryCount = 0;
                                }
                                if (tryAgainLater) {
                                    mRetryCount++;
                                    sendMessageDelayed(CMD_RETRY_UPSTREAM, UPSTREAM_SETTLE_TIME_MS);
                                }
                            } else {
                               mRetryCount = 0;
                               turnOffUpstreamMobileConnection();
                               Log.d(TAG, "chooseUpstreamType: Reached MAX, NO RETRIES");
                            }
                        } else {
                            Log.d(TAG, "Data is Disabled");
                        }
                    } catch (RemoteException e) {
                        Log.d(TAG, "Exception in getMobileDataEnabled()");
                    }
                } else {
                    LinkProperties linkProperties = null;
                    try {
@@ -1517,6 +1537,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {

                mTryCell = !WAIT_FOR_NETWORK_TO_SETTLE; // better try something first pass
                                                        // or crazy tests cases will fail
                mRetryCount = 0;
                chooseUpstreamType(mTryCell);
                mTryCell = !mTryCell;
            }