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

Commit 562e0c17 authored by Erik Kline's avatar Erik Kline
Browse files

Only disable Wi-Fi IP serving on specific interface, if available

Test: as follows
    - built
    - flashed
    - booted
    - runtest frameworks-net passes
Bug: 32163131
Bug: 62343300

Merged-In: Id8d9c3f67f7a850af69069abee86adfc62841b28
Merged-In: Iac19359fd8712fa6a135f31bed9f0da97b3f2977
Merged-In: I99b170ebacc4135d1a09ce1ec3d43f76c6765de4
Change-Id: Ifd9131bad20810ee24c9436d8c0df7a81fae11d5
(cherry picked from commit 218c226b)
(cherry picked from commit 798a93b0df76c4feb5ddd619b788f2cf9ea5bf77)
parent 736ba78a
Loading
Loading
Loading
Loading
+23 −12
Original line number Original line Diff line number Diff line
@@ -831,30 +831,41 @@ public class Tethering extends BaseNetworkObserver {
                    case WifiManager.WIFI_AP_STATE_DISABLING:
                    case WifiManager.WIFI_AP_STATE_DISABLING:
                    case WifiManager.WIFI_AP_STATE_FAILED:
                    case WifiManager.WIFI_AP_STATE_FAILED:
                    default:
                    default:
                        disableWifiIpServingLocked(curState);
                        disableWifiIpServingLocked(ifname, curState);
                        break;
                        break;
                }
                }
            }
            }
        }
        }
    }
    }


    // TODO: Pass in the interface name and, if non-empty, only turn down IP
    private void disableWifiIpServingLocked(String ifname, int apState) {
    // serving on that one interface.
        mLog.log("Canceling WiFi tethering request - AP_STATE=" + apState);
    private void disableWifiIpServingLocked(int apState) {

        if (DBG) Log.d(TAG, "Canceling WiFi tethering request - AP_STATE=" + apState);
        // Regardless of whether we requested this transition, the AP has gone
        // down.  Don't try to tether again unless we're requested to do so.
        // TODO: Remove this altogether, once Wi-Fi reliably gives us an
        // interface name with every broadcast.
        mWifiTetherRequested = false;

        if (!TextUtils.isEmpty(ifname)) {
            final TetherState ts = mTetherStates.get(ifname);
            if (ts != null) {
                ts.stateMachine.unwanted();
                return;
            }
        }


        // Tell appropriate interface state machines that they should tear
        // themselves down.
        for (int i = 0; i < mTetherStates.size(); i++) {
        for (int i = 0; i < mTetherStates.size(); i++) {
            TetherInterfaceStateMachine tism = mTetherStates.valueAt(i).stateMachine;
            TetherInterfaceStateMachine tism = mTetherStates.valueAt(i).stateMachine;
            if (tism.interfaceType() == ConnectivityManager.TETHERING_WIFI) {
            if (tism.interfaceType() == ConnectivityManager.TETHERING_WIFI) {
                tism.sendMessage(TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED);
                tism.unwanted();
                break;  // There should be at most one of these.
                return;
            }
            }
        }
        }
        // Regardless of whether we requested this transition, the AP has gone

        // down.  Don't try to tether again unless we're requested to do so.
        mLog.log("Error disabling Wi-Fi IP serving; " +
        mWifiTetherRequested = false;
                (TextUtils.isEmpty(ifname) ? "no interface name specified"
                                           : "specified interface: " + ifname));
    }
    }


    private void enableWifiIpServingLocked(String ifname, int wifiIpMode) {
    private void enableWifiIpServingLocked(String ifname, int wifiIpMode) {
+2 −0
Original line number Original line Diff line number Diff line
@@ -163,6 +163,8 @@ public class TetherInterfaceStateMachine extends StateMachine {


    public void stop() { sendMessage(CMD_INTERFACE_DOWN); }
    public void stop() { sendMessage(CMD_INTERFACE_DOWN); }


    public void unwanted() { sendMessage(CMD_TETHER_UNREQUESTED); }

    /**
    /**
     * Internals.
     * Internals.
     */
     */