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

Commit b5c51d5f authored by Robert Greenwalt's avatar Robert Greenwalt Committed by Android (Google) Code Review
Browse files

Merge "DO NOT MERGE Backport of I1f55df8a from master." into gingerbread

parents 367f41f8 6b09916e
Loading
Loading
Loading
Loading
+17 −50
Original line number Original line Diff line number Diff line
@@ -1089,18 +1089,10 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                    info.getExtraInfo());
                    info.getExtraInfo());
        }
        }


        NetworkStateTracker newNet = null;
        if (mNetAttributes[prevNetType].isDefault()) {
        if (mNetAttributes[prevNetType].isDefault()) {
            newNet = tryFailover(prevNetType);
            tryFailover(prevNetType);
            if (newNet != null) {
            if (mActiveDefaultNetwork != -1) {
                NetworkInfo switchTo = newNet.getNetworkInfo();
                NetworkInfo switchTo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
                if (!switchTo.isConnected()) {
                    // if the other net is connected they've already reset this and perhaps even gotten
                    // a positive report we don't want to overwrite, but if not we need to clear this now
                    // to turn our cellular sig strength white
                    mDefaultInetConditionPublished = 0;
                    intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
                }
                intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
                intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
            } else {
            } else {
                mDefaultInetConditionPublished = 0; // we're not connected anymore
                mDefaultInetConditionPublished = 0; // we're not connected anymore
@@ -1116,25 +1108,21 @@ public class ConnectivityService extends IConnectivityManager.Stub {
         * If the failover network is already connected, then immediately send
         * If the failover network is already connected, then immediately send
         * out a followup broadcast indicating successful failover
         * out a followup broadcast indicating successful failover
         */
         */
        if (newNet != null && newNet.getNetworkInfo().isConnected()) {
        if (mActiveDefaultNetwork != -1) {
            sendConnectedBroadcast(newNet.getNetworkInfo());
            sendConnectedBroadcast(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo());
        }
        }
    }
    }


    // returns null if no failover available
    private void tryFailover(int prevNetType) {
    private NetworkStateTracker tryFailover(int prevNetType) {
        /*
        /*
         * If this is a default network, check if other defaults are available
         * If this is a default network, check if other defaults are available
         * or active
         * or active
         */
         */
        NetworkStateTracker newNet = null;
        if (mNetAttributes[prevNetType].isDefault()) {
        if (mNetAttributes[prevNetType].isDefault()) {
            if (mActiveDefaultNetwork == prevNetType) {
            if (mActiveDefaultNetwork == prevNetType) {
                mActiveDefaultNetwork = -1;
                mActiveDefaultNetwork = -1;
            }
            }


            int newType = -1;
            int newPriority = -1;
            boolean noMobileData = !getMobileDataEnabled();
            boolean noMobileData = !getMobileDataEnabled();
            for (int checkType=0; checkType <= ConnectivityManager.MAX_NETWORK_TYPE; checkType++) {
            for (int checkType=0; checkType <= ConnectivityManager.MAX_NETWORK_TYPE; checkType++) {
                if (checkType == prevNetType) continue;
                if (checkType == prevNetType) continue;
@@ -1146,29 +1134,15 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                            " because Mobile Data Disabled");
                            " because Mobile Data Disabled");
                    continue;
                    continue;
                }
                }
                NetworkStateTracker tracker = mNetTrackers[checkType];
                NetworkStateTracker checkTracker = mNetTrackers[checkType];
                NetworkInfo info = tracker.getNetworkInfo();
                NetworkInfo checkInfo = checkTracker.getNetworkInfo();
                if (!info.isConnectedOrConnecting() ||
                if (!checkInfo.isConnectedOrConnecting() || checkTracker.isTeardownRequested()) {
                        tracker.isTeardownRequested()) {
                    checkInfo.setFailover(true);
                    info.setFailover(true);
                    checkTracker.reconnect();
                    tracker.reconnect();
                }
                if (DBG) Slog.d(TAG, "Attempting to switch to " + info.getTypeName());

                // figure out if this is the highest priority network
                // so we send an appropriate return value
                if (checkType == mNetworkPreference) {
                    newType = checkType;
                }
                if (mNetAttributes[checkType].mPriority > newPriority &&
                        newType != mNetworkPreference) {
                    newType = checkType;
                    newPriority = mNetAttributes[checkType].mPriority;
                }
                }
                if (DBG) Slog.d(TAG, "Attempting to switch to " + checkInfo.getTypeName());
            }
            }
        }
        }

        return newNet;
    }
    }


    private void sendConnectedBroadcast(NetworkInfo info) {
    private void sendConnectedBroadcast(NetworkInfo info) {
@@ -1231,17 +1205,10 @@ public class ConnectivityService extends IConnectivityManager.Stub {
            info.setFailover(false);
            info.setFailover(false);
        }
        }


        NetworkStateTracker newNet = null;
        if (mNetAttributes[info.getType()].isDefault()) {
        if (mNetAttributes[info.getType()].isDefault()) {
            newNet = tryFailover(info.getType());
            tryFailover(info.getType());
            if (newNet != null) {
            if (mActiveDefaultNetwork != -1) {
                NetworkInfo switchTo = newNet.getNetworkInfo();
                NetworkInfo switchTo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
                if (!switchTo.isConnected()) {
                    // if the other net is connected they've already reset this and perhaps
                    // even gotten a positive report we don't want to overwrite, but if not
                    // we need to clear this now to turn our cellular sig strength white
                    mDefaultInetConditionPublished = 0;
                }
                intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
                intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
            } else {
            } else {
                mDefaultInetConditionPublished = 0;
                mDefaultInetConditionPublished = 0;
@@ -1255,8 +1222,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
         * If the failover network is already connected, then immediately send
         * If the failover network is already connected, then immediately send
         * out a followup broadcast indicating successful failover
         * out a followup broadcast indicating successful failover
         */
         */
        if (newNet != null && newNet.getNetworkInfo().isConnected()) {
        if (mActiveDefaultNetwork != -1) {
            sendConnectedBroadcast(newNet.getNetworkInfo());
            sendConnectedBroadcast(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo());
        }
        }
    }
    }