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

Commit 0e9c69dd authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by Steve Kondik
Browse files

Minor cleanups to NetdCallbackReceiver.onEvent.

- Clean up identical error messages.
- Fix the array length check for InterfaceAddressChange.

[Cherry-pick of 59be800e]

Bug: 9180552
Change-Id: Id871f481445b530c3ad749725f1548df0e3a1228
parent b5887d6b
Loading
Loading
Loading
Loading
+9 −14
Original line number Diff line number Diff line
@@ -468,6 +468,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:
                    /*
@@ -478,8 +479,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]);
@@ -494,8 +494,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:
                    /*
@@ -503,15 +502,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:
                    /*
@@ -519,8 +516,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);
@@ -532,9 +528,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;
@@ -543,7 +538,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.