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

Commit b6055fe7 authored by JP Abgrall's avatar JP Abgrall Committed by Android (Google) Code Review
Browse files

Merge "NetworkManagementService: receive bandwidth controller events"

parents f726c1de 12b933d0
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -103,6 +103,10 @@ public class EthernetDataTracker implements NetworkStateTracker {
        public void interfaceRemoved(String iface) {
            mTracker.interfaceRemoved(iface);
        }

        public void limitReached(String limitName, String iface) {
            // Ignored.
        }
    }

    private EthernetDataTracker() {
+10 −0
Original line number Diff line number Diff line
@@ -52,4 +52,14 @@ interface INetworkManagementEventObserver {
     * @param iface The interface.
     */
    void interfaceRemoved(String iface);

    /**
     * A networking quota limit has been reached. The quota might not
     * be specific to an interface.
     *
     * @param limitName The name of the limit that triggered.
     * @param iface The interface on which the limit was detected.
     */
    void limitReached(String limitName, String iface);

}
+60 −25
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ class NetworkManagementService extends INetworkManagementService.Stub {
    private static final String KEY_TX = "tx_bytes";

    class NetdResponseCode {
        /* Keep in sync with system/netd/ResponseCode.h */
        public static final int InterfaceListResult       = 110;
        public static final int TetherInterfaceListResult = 111;
        public static final int TetherDnsFwdTgtListResult = 112;
@@ -108,6 +109,7 @@ class NetworkManagementService extends INetworkManagementService.Stub {
        public static final int InterfaceTxThrottleResult = 219;

        public static final int InterfaceChange           = 600;
        public static final int BandwidthControl          = 601;
    }

    /**
@@ -264,6 +266,20 @@ class NetworkManagementService extends INetworkManagementService.Stub {
        }
    }

    /**
     * Notify our observers of a limit reached.
     */
    private void notifyLimitReached(String limitName, String iface) {
        for (INetworkManagementEventObserver obs : mObservers) {
            try {
                obs.limitReached(limitName, iface);
                Slog.d(TAG, "Observer notified limit reached for " + limitName + " " + iface);
            } catch (Exception ex) {
                Slog.w(TAG, "Observer notifier failed", ex);
            }
        }
    }

    /**
     * Let us know the daemon is connected
     */
@@ -286,7 +302,8 @@ class NetworkManagementService extends INetworkManagementService.Stub {
            }.start();
        }
        public boolean onEvent(int code, String raw, String[] cooked) {
            if (code == NetdResponseCode.InterfaceChange) {
            switch (code) {
            case NetdResponseCode.InterfaceChange:
                    /*
                     * a network interface change occured
                     * Format: "NNN Iface added <name>"
@@ -313,6 +330,24 @@ class NetworkManagementService extends INetworkManagementService.Stub {
                    }
                    throw new IllegalStateException(
                            String.format("Invalid event from daemon (%s)", raw));
                    // break;
            case NetdResponseCode.BandwidthControl:
                    /*
                     * Bandwidth control needs some attention
                     * Format: "NNN limit alert <alertName> <ifaceName>"
                     */
                    if (cooked.length < 5 || !cooked[1].equals("limit")) {
                        throw new IllegalStateException(
                                String.format("Invalid event from daemon (%s)", raw));
                    }
                    if (cooked[2].equals("alert")) {
                        notifyLimitReached(cooked[3], cooked[4]);
                        return true;
                    }
                    throw new IllegalStateException(
                            String.format("Invalid event from daemon (%s)", raw));
                    // break;
            default: break;
            }
            return false;
        }
+1 −0
Original line number Diff line number Diff line
@@ -194,6 +194,7 @@ public class ThrottleService extends IThrottleManager.Stub {
        }

        public void interfaceRemoved(String iface) {}
        public void limitReached(String limitName, String iface) {}
    }


+2 −0
Original line number Diff line number Diff line
@@ -288,6 +288,8 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
        }
    }

    public void limitReached(String limitName, String iface) {}

    public int tether(String iface) {
        Log.d(TAG, "Tethering " + iface);
        TetherInterfaceSM sm = null;
Loading