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

Commit 780dfa42 authored by Stan Chesnutt's avatar Stan Chesnutt
Browse files

Propagate new link-status-change message to any NetworkManagementService

observers.  Also fix the syntax of the "interface-status-change" message.  Add
a null handler in the ThrottleService and Tethering classes (plus fix names).

Change-Id: I58cabc7b0ce5662243bc6513b2de4818065e6c52
parent a7806034
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -23,12 +23,21 @@ package android.net;
 */
interface INetworkManagementEventObserver {
    /**
     * Interface link status has changed.
     * Interface configuration status has changed.
     *
     * @param iface The interface.
     * @param link True if link is up.
     * @param up True if the interface has been enabled.
     */
    void interfaceLinkStatusChanged(String iface, boolean link);
    void interfaceStatusChanged(String iface, boolean up);

    /**
     * Interface physical-layer link status has changed.  For Ethernet,
     * this method is invoked when the cable is plugged in or unplugged.
     *
     * @param iface The interface.
     * @param up  True if the physical link-layer connection signal is valid.
     */
     void interfaceLinkStateChanged(String iface, boolean up);

    /**
     * An interface has been added to the system
+22 −4
Original line number Diff line number Diff line
@@ -131,12 +131,26 @@ class NetworkManagementService extends INetworkManagementService.Stub {
    }

    /**
     * Notify our observers of an interface link status change
     * Notify our observers of an interface status change
     */
    private void notifyInterfaceLinkStatusChanged(String iface, boolean link) {
    private void notifyInterfaceStatusChanged(String iface, boolean up) {
        for (INetworkManagementEventObserver obs : mObservers) {
            try {
                obs.interfaceLinkStatusChanged(iface, link);
                obs.interfaceStatusChanged(iface, up);
            } catch (Exception ex) {
                Slog.w(TAG, "Observer notifier failed", ex);
            }
        }
    }

    /**
     * Notify our observers of an interface link status change.
     * (typically, an Ethernet cable has been plugged-in or unplugged).
     */
    private void notifyInterfaceLinkStateChanged(String iface, boolean up) {
        for (INetworkManagementEventObserver obs : mObservers) {
            try {
                obs.interfaceLinkStateChanged(iface, up);
            } catch (Exception ex) {
                Slog.w(TAG, "Observer notifier failed", ex);
            }
@@ -197,6 +211,7 @@ class NetworkManagementService extends INetworkManagementService.Stub {
                 * Format: "NNN Iface added <name>"
                 *         "NNN Iface removed <name>"
                 *         "NNN Iface changed <name> <up/down>"
                 *         "NNN Iface linkstatus <name> <up/down>"
                 */
                if (cooked.length < 4 || !cooked[1].equals("Iface")) {
                    throw new IllegalStateException(
@@ -209,7 +224,10 @@ class NetworkManagementService extends INetworkManagementService.Stub {
                    notifyInterfaceRemoved(cooked[3]);
                    return true;
                } else if (cooked[2].equals("changed") && cooked.length == 5) {
                    notifyInterfaceLinkStatusChanged(cooked[3], cooked[4].equals("up"));
                    notifyInterfaceStatusChanged(cooked[3], cooked[4].equals("up"));
                    return true;
                } else if (cooked[2].equals("linkstatus") && cooked.length == 5) {
                    notifyInterfaceLinkStateChanged(cooked[3], cooked[4].equals("up"));
                    return true;
                }
                throw new IllegalStateException(
+3 −1
Original line number Diff line number Diff line
@@ -160,7 +160,7 @@ public class ThrottleService extends IThrottleManager.Stub {
            mIface = iface;
        }

        public void interfaceLinkStatusChanged(String iface, boolean link) {
        public void interfaceStatusChanged(String iface, boolean link) {
            if (link) {
                if (TextUtils.equals(iface, mIface)) {
                    mHandler.obtainMessage(mMsg).sendToTarget();
@@ -176,6 +176,8 @@ public class ThrottleService extends IThrottleManager.Stub {
            }
        }

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

        public void interfaceRemoved(String iface) {}
    }

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

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

    public void interfaceStatusChanged(String iface, boolean up) {
        if (DEBUG) Log.d(TAG, "interfaceStatusChanged " + iface + ", " + up);
        boolean found = false;
        boolean usb = false;
        if (isWifi(iface)) {
@@ -218,7 +221,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {

        synchronized (mIfaces) {
            TetherInterfaceSM sm = mIfaces.get(iface);
            if (link) {
            if (up) {
                if (sm == null) {
                    sm = new TetherInterfaceSM(iface, mLooper, usb);
                    mIfaces.put(iface, sm);