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

Commit f59c7d0f authored by Mike J. Chen's avatar Mike J. Chen
Browse files

Hookup interface status to other clients



After unreverting the linkstate change patch, hook up notification handlers
that didn't exist when the first patch was created, like
EthernetDataTracker.java and Vpn.java.

For the observers that handle interfaceStatusChanged(), I made
interfaceLinkStatusChanged() call it so they both do the same thing.

Change-Id: I0077e5e5f48f3932ba98f5bf363243892f2de6cc
Signed-off-by: default avatarMike J. Chen <mjchen@google.com>
parent 6143f5f7
Loading
Loading
Loading
Loading
+32 −8
Original line number Original line Diff line number Diff line
@@ -53,6 +53,7 @@ public class EthernetDataTracker implements NetworkStateTracker {
    private AtomicInteger mDefaultGatewayAddr = new AtomicInteger(0);
    private AtomicInteger mDefaultGatewayAddr = new AtomicInteger(0);
    private AtomicBoolean mDefaultRouteSet = new AtomicBoolean(false);
    private AtomicBoolean mDefaultRouteSet = new AtomicBoolean(false);


    private static boolean mLinkUp;
    private LinkProperties mLinkProperties;
    private LinkProperties mLinkProperties;
    private LinkCapabilities mLinkCapabilities;
    private LinkCapabilities mLinkCapabilities;
    private NetworkInfo mNetworkInfo;
    private NetworkInfo mNetworkInfo;
@@ -74,8 +75,25 @@ public class EthernetDataTracker implements NetworkStateTracker {
            mTracker = tracker;
            mTracker = tracker;
        }
        }


        public void interfaceLinkStatusChanged(String iface, boolean up) {
        public void interfaceStatusChanged(String iface, boolean up) {
            Log.d(TAG, "Interface status changed: " + iface + (up ? "up" : "down"));
        }

        public void interfaceLinkStateChanged(String iface, boolean up) {
            if (mIface.equals(iface) && mLinkUp != up) {
                Log.d(TAG, "Interface " + iface + " link " + (up ? "up" : "down"));
                Log.d(TAG, "Interface " + iface + " link " + (up ? "up" : "down"));
                mLinkUp = up;

                // use DHCP
                if (up) {
                    mTracker.reconnect();
                } else {
                    NetworkUtils.stopDhcp(mIface);
                    mTracker.mNetworkInfo.setIsAvailable(false);
                    mTracker.mNetworkInfo.setDetailedState(DetailedState.DISCONNECTED,
                                                           null, null);
                }
            }
        }
        }


        public void interfaceAdded(String iface) {
        public void interfaceAdded(String iface) {
@@ -91,6 +109,7 @@ public class EthernetDataTracker implements NetworkStateTracker {
        mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_ETHERNET, 0, NETWORKTYPE, "");
        mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_ETHERNET, 0, NETWORKTYPE, "");
        mLinkProperties = new LinkProperties();
        mLinkProperties = new LinkProperties();
        mLinkCapabilities = new LinkCapabilities();
        mLinkCapabilities = new LinkCapabilities();
        mLinkUp = false;


        mNetworkInfo.setIsAvailable(false);
        mNetworkInfo.setIsAvailable(false);
        setTeardownRequested(false);
        setTeardownRequested(false);
@@ -182,14 +201,11 @@ public class EthernetDataTracker implements NetworkStateTracker {
        // register for notifications from NetworkManagement Service
        // register for notifications from NetworkManagement Service
        IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
        IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
        INetworkManagementService service = INetworkManagementService.Stub.asInterface(b);
        INetworkManagementService service = INetworkManagementService.Stub.asInterface(b);

        mInterfaceObserver = new InterfaceObserver(this);
        mInterfaceObserver = new InterfaceObserver(this);
        try {
            service.registerObserver(mInterfaceObserver);
        } catch (RemoteException e) {
            Log.e(TAG, "Could not register InterfaceObserver " + e);
        }


        // connect to an ethernet interface that already exists
        // enable and try to connect to an ethernet interface that
        // already exists
        sIfaceMatch = context.getResources().getString(
        sIfaceMatch = context.getResources().getString(
            com.android.internal.R.string.config_ethernet_iface_regex);
            com.android.internal.R.string.config_ethernet_iface_regex);
        try {
        try {
@@ -197,6 +213,8 @@ public class EthernetDataTracker implements NetworkStateTracker {
            for (String iface : ifaces) {
            for (String iface : ifaces) {
                if (iface.matches(sIfaceMatch)) {
                if (iface.matches(sIfaceMatch)) {
                    mIface = iface;
                    mIface = iface;
                    InterfaceConfiguration config = service.getInterfaceConfig(iface);
                    mLinkUp = config.isActive();
                    reconnect();
                    reconnect();
                    break;
                    break;
                }
                }
@@ -204,6 +222,12 @@ public class EthernetDataTracker implements NetworkStateTracker {
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "Could not get list of interfaces " + e);
            Log.e(TAG, "Could not get list of interfaces " + e);
        }
        }

        try {
            service.registerObserver(mInterfaceObserver);
        } catch (RemoteException e) {
            Log.e(TAG, "Could not register InterfaceObserver " + e);
        }
    }
    }


    /**
    /**
+2 −2
Original line number Original line Diff line number Diff line
@@ -31,7 +31,7 @@ interface INetworkManagementEventObserver {
    void interfaceStatusChanged(String iface, boolean up);
    void interfaceStatusChanged(String iface, boolean up);


    /**
    /**
     * Interface physical-layer link status has changed.  For Ethernet,
     * Interface physical-layer link state has changed.  For Ethernet,
     * this method is invoked when the cable is plugged in or unplugged.
     * this method is invoked when the cable is plugged in or unplugged.
     *
     *
     * @param iface The interface.
     * @param iface The interface.
+2 −2
Original line number Original line Diff line number Diff line
@@ -154,7 +154,7 @@ class NetworkManagementService extends INetworkManagementService.Stub {
    }
    }


    /**
    /**
     * Notify our observers of an interface link status change.
     * Notify our observers of an interface link state change
     * (typically, an Ethernet cable has been plugged-in or unplugged).
     * (typically, an Ethernet cable has been plugged-in or unplugged).
     */
     */
    private void notifyInterfaceLinkStateChanged(String iface, boolean up) {
    private void notifyInterfaceLinkStateChanged(String iface, boolean up) {
@@ -236,7 +236,7 @@ class NetworkManagementService extends INetworkManagementService.Stub {
                } else if (cooked[2].equals("changed") && cooked.length == 5) {
                } else if (cooked[2].equals("changed") && cooked.length == 5) {
                    notifyInterfaceStatusChanged(cooked[3], cooked[4].equals("up"));
                    notifyInterfaceStatusChanged(cooked[3], cooked[4].equals("up"));
                    return true;
                    return true;
                } else if (cooked[2].equals("linkstatus") && cooked.length == 5) {
                } else if (cooked[2].equals("linkstate") && cooked.length == 5) {
                    notifyInterfaceLinkStateChanged(cooked[3], cooked[4].equals("up"));
                    notifyInterfaceLinkStateChanged(cooked[3], cooked[4].equals("up"));
                    return true;
                    return true;
                }
                }
+5 −4
Original line number Original line Diff line number Diff line
@@ -179,14 +179,17 @@ public class ThrottleService extends IThrottleManager.Stub {
            mIface = iface;
            mIface = iface;
        }
        }


        public void interfaceStatusChanged(String iface, boolean link) {
        public void interfaceStatusChanged(String iface, boolean up) {
            if (link) {
            if (up) {
                if (TextUtils.equals(iface, mIface)) {
                if (TextUtils.equals(iface, mIface)) {
                    mHandler.obtainMessage(mMsg).sendToTarget();
                    mHandler.obtainMessage(mMsg).sendToTarget();
                }
                }
            }
            }
        }
        }


        public void interfaceLinkStateChanged(String iface, boolean up) {
        }

        public void interfaceAdded(String iface) {
        public void interfaceAdded(String iface) {
            // TODO - an interface added in the UP state should also trigger a StatusChanged
            // TODO - an interface added in the UP state should also trigger a StatusChanged
            // notification..
            // notification..
@@ -195,8 +198,6 @@ public class ThrottleService extends IThrottleManager.Stub {
            }
            }
        }
        }


        public void interfaceLinkStateChanged(String iface, boolean linkState) {}

        public void interfaceRemoved(String iface) {}
        public void interfaceRemoved(String iface) {}
    }
    }


+5 −3
Original line number Original line Diff line number Diff line
@@ -189,9 +189,6 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
        mDnsServers[1] = DNS_DEFAULT_SERVER2;
        mDnsServers[1] = DNS_DEFAULT_SERVER2;
    }
    }


    public void interfaceLinkStateChanged(String iface, boolean up) {
    }

    public void interfaceStatusChanged(String iface, boolean up) {
    public void interfaceStatusChanged(String iface, boolean up) {
        if (DEBUG) Log.d(TAG, "interfaceStatusChanged " + iface + ", " + up);
        if (DEBUG) Log.d(TAG, "interfaceStatusChanged " + iface + ", " + up);
        boolean found = false;
        boolean found = false;
@@ -223,6 +220,11 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
        }
        }
    }
    }


    public void interfaceLinkStateChanged(String iface, boolean up) {
        if (DEBUG) Log.d(TAG, "interfaceLinkStateChanged " + iface + ", " + up);
        interfaceStatusChanged(iface, up);
    }

    private boolean isUsb(String iface) {
    private boolean isUsb(String iface) {
        for (String regex : mTetherableUsbRegexs) {
        for (String regex : mTetherableUsbRegexs) {
            if (iface.matches(regex)) return true;
            if (iface.matches(regex)) return true;
Loading