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

Commit eede7e89 authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by Gerrit Code Review
Browse files

Merge "Minor cleanups to NetdCallbackReceiver.onEvent."

parents 8a234809 a9626c1c
Loading
Loading
Loading
Loading
+9 −14
Original line number Diff line number Diff line
@@ -455,6 +455,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub

        @Override
        public boolean onEvent(int code, String raw, String[] cooked) {
            String errorMessage = String.format("Invalid event from daemon (%s)", raw);
            switch (code) {
            case NetdResponseCode.InterfaceChange:
                    /*
@@ -465,8 +466,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
                     *         "NNN Iface linkstatus <name> <up/down>"
                     */
                    if (cooked.length < 4 || !cooked[1].equals("Iface")) {
                        throw new IllegalStateException(
                                String.format("Invalid event from daemon (%s)", raw));
                        throw new IllegalStateException(errorMessage);
                    }
                    if (cooked[2].equals("added")) {
                        notifyInterfaceAdded(cooked[3]);
@@ -481,8 +481,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
                        notifyInterfaceLinkStateChanged(cooked[3], cooked[4].equals("up"));
                        return true;
                    }
                    throw new IllegalStateException(
                            String.format("Invalid event from daemon (%s)", raw));
                    throw new IllegalStateException(errorMessage);
                    // break;
            case NetdResponseCode.BandwidthControl:
                    /*
@@ -490,15 +489,13 @@ public class NetworkManagementService extends INetworkManagementService.Stub
                     * 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));
                        throw new IllegalStateException(errorMessage);
                    }
                    if (cooked[2].equals("alert")) {
                        notifyLimitReached(cooked[3], cooked[4]);
                        return true;
                    }
                    throw new IllegalStateException(
                            String.format("Invalid event from daemon (%s)", raw));
                    throw new IllegalStateException(errorMessage);
                    // break;
            case NetdResponseCode.InterfaceClassActivity:
                    /*
@@ -506,8 +503,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
                     * Format: "NNN IfaceClass <active/idle> <label>"
                     */
                    if (cooked.length < 4 || !cooked[1].equals("IfaceClass")) {
                        throw new IllegalStateException(
                                String.format("Invalid event from daemon (%s)", raw));
                        throw new IllegalStateException(errorMessage);
                    }
                    boolean isActive = cooked[2].equals("active");
                    notifyInterfaceClassActivity(cooked[3], isActive);
@@ -519,9 +515,8 @@ public class NetworkManagementService extends INetworkManagementService.Stub
                     * Format: "NNN Address updated <addr> <iface> <flags> <scope>"
                     *         "NNN Address removed <addr> <iface> <flags> <scope>"
                     */
                    String msg = String.format("Invalid event from daemon (%s)", raw);
                    if (cooked.length < 6 || !cooked[1].equals("Address")) {
                        throw new IllegalStateException(msg);
                    if (cooked.length < 7 || !cooked[1].equals("Address")) {
                        throw new IllegalStateException(errorMessage);
                    }

                    int flags;
@@ -530,7 +525,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
                        flags = Integer.parseInt(cooked[5]);
                        scope = Integer.parseInt(cooked[6]);
                    } catch(NumberFormatException e) {
                        throw new IllegalStateException(msg);
                        throw new IllegalStateException(errorMessage);
                    }

                    if (cooked[2].equals("updated")) {
+3 −0
Original line number Diff line number Diff line
@@ -166,6 +166,9 @@ public class NetworkManagementServiceTest extends AndroidTestCase {
        sendMessage("614 Address removed 2001:db8::1/64 wlan0 1 0");
        expectSoon(observer).addressRemoved("2001:db8::1/64", "wlan0", 1, 0);

        sendMessage("614 Address removed 2001:db8::1/64 wlan0 1");
        // Not enough arguments.

        sendMessage("666 Address added 2001:db8::1/64 wlan0 1 0");
        // Invalid code.