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

Commit e325392c authored by Robert Greenwalt's avatar Robert Greenwalt
Browse files

Add Java hookup to netd interface notifications.

parent 2db939bd
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -59,6 +59,10 @@ class NetworkManagementService extends INetworkManagementService.Stub {
        public static final int TetherStatusResult        = 210;
        public static final int IpFwdStatusResult         = 211;
        public static final int InterfaceGetCfgResult     = 213;
        public static final int SoftapStatusResult        = 214;
        public static final int UsbRNDISStatusResult      = 215;

        public static final int InterfaceChange           = 600;
    }

    /**
@@ -147,11 +151,34 @@ class NetworkManagementService extends INetworkManagementService.Stub {
        public void onDaemonConnected() {
            new Thread() {
                public void run() {
                    // XXX: Run some tests
                }
            }.start();
        }
        public boolean onEvent(int code, String raw, String[] cooked) {
            if (code == NetdResponseCode.InterfaceChange) {
                /*
                 * a network interface change occured
                 * Format: "NNN Iface added <name>"
                 *         "NNN Iface removed <name>"
                 *         "NNN Iface changed <name> <up/down>"
                 */
                if (cooked.length < 4 || !cooked[1].equals("Iface")) {
                    throw new IllegalStateException(
                            String.format("Invalid event from daemon (%s)", raw));
                }
                if (cooked[2].equals("added")) {
                    notifyInterfaceAdded(cooked[3]);
                    return true;
                } else if (cooked[2].equals("removed")) {
                    notifyInterfaceRemoved(cooked[3]);
                    return true;
                } else if (cooked[2].equals("changed") && cooked.length == 5) {
                    notifyInterfaceLinkStatusChanged(cooked[3], cooked[4].equals("up"));
                    return true;
                }
                throw new IllegalStateException(
                        String.format("Invalid event from daemon (%s)", raw));
            }
            return false;
        }
    }