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

Commit f2288c96 authored by Irfan Sheriff's avatar Irfan Sheriff Committed by Android (Google) Code Review
Browse files

Merge "Fix IP address cleanup on network disconnect"

parents de47f1c3 f5600618
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -58,6 +58,11 @@ interface INetworkManagementService
     */
    void setInterfaceConfig(String iface, in InterfaceConfiguration cfg);

    /**
     * Clear all IP addresses on the specified interface
     */
    void clearInterfaceAddresses(String iface);

    /**
     * Retrieves the network routes currently configured on the specified
     * interface
+12 −0
Original line number Diff line number Diff line
@@ -311,6 +311,18 @@ class NetworkManagementService extends INetworkManagementService.Stub {
        }
    }

    /* TODO: This is right now a IPv4 only function. Works for wifi which loses its
       IPv6 addresses on interface down, but we need to do full clean up here */
    public void clearInterfaceAddresses(String iface) throws IllegalStateException {
         String cmd = String.format("interface clearaddrs %s", iface);
        try {
            mConnector.doCommand(cmd);
        } catch (NativeDaemonConnectorException e) {
            throw new IllegalStateException(
                    "Unable to communicate with native daemon to interface clearallips - " + e);
        }
    }

    public void addRoute(String interfaceName, RouteInfo route) {
        modifyRoute(interfaceName, ADD, route);
    }
+10 −9
Original line number Diff line number Diff line
@@ -1028,9 +1028,6 @@ public class WifiStateMachine extends StateMachine {
        boolean wifiTethered = false;
        boolean wifiAvailable = false;

        IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
        INetworkManagementService service = INetworkManagementService.Stub.asInterface(b);

        if (mCm == null) {
            mCm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        }
@@ -1043,14 +1040,14 @@ public class WifiStateMachine extends StateMachine {

                    InterfaceConfiguration ifcg = null;
                    try {
                        ifcg = service.getInterfaceConfig(intf);
                        ifcg = nwService.getInterfaceConfig(intf);
                        if (ifcg != null) {
                            /* IP/netmask: 192.168.43.1/255.255.255.0 */
                            ifcg.addr = new LinkAddress(NetworkUtils.numericToInetAddress(
                                    "192.168.43.1"), 24);
                            ifcg.interfaceFlags = "[up]";

                            service.setInterfaceConfig(intf, ifcg);
                            nwService.setInterfaceConfig(intf, ifcg);
                        }
                    } catch (Exception e) {
                        Log.e(TAG, "Error configuring interface " + intf + ", :" + e);
@@ -1450,7 +1447,7 @@ public class WifiStateMachine extends StateMachine {
     * using the interface, stopping DHCP & disabling interface
     */
    private void handleNetworkDisconnect() {
        Log.d(TAG, "Reset connections and stopping DHCP");
        Log.d(TAG, "Stopping DHCP and clearing IP");

        /*
         * stop DHCP
@@ -1461,6 +1458,12 @@ public class WifiStateMachine extends StateMachine {
            mDhcpStateMachine = null;
        }

        try {
            nwService.clearInterfaceAddresses(mInterfaceName);
        } catch (Exception e) {
            Log.e(TAG, "Failed to clear IP addresses on disconnect" + e);
        }

        /* Reset data structures */
        mWifiInfo.setInetAddress(null);
        mWifiInfo.setBSSID(null);
@@ -2656,13 +2659,11 @@ public class WifiStateMachine extends StateMachine {
            } else {
                DhcpInfoInternal dhcpInfoInternal = WifiConfigStore.getIpConfiguration(
                        mLastNetworkId);
                IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
                INetworkManagementService netd = INetworkManagementService.Stub.asInterface(b);
                InterfaceConfiguration ifcg = new InterfaceConfiguration();
                ifcg.addr = dhcpInfoInternal.makeLinkAddress();
                ifcg.interfaceFlags = "[up]";
                try {
                    netd.setInterfaceConfig(mInterfaceName, ifcg);
                    nwService.setInterfaceConfig(mInterfaceName, ifcg);
                    Log.v(TAG, "Static IP configuration succeeded");
                    sendMessage(CMD_STATIC_IP_SUCCESS, dhcpInfoInternal);
                } catch (RemoteException re) {