Use LinkAddress in address notifications.

Currently address{Updated,Removed} pass in the address as a
string such as "fe80::1/64". Use LinkAddresses instead, since
that's what it is.

This makes the code more robust in the unlikely case that netd
passes in an invalid string. In the future we can move flags and
scope into the LinkAddress itself and simplify the code further.

Bug: 9180552
Change-Id: I66599f9529cf421caa7676fdd0141bb110b8589e
diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java
index 8089fbc..40ea49e 100644
--- a/services/java/com/android/server/NetworkManagementService.java
+++ b/services/java/com/android/server/NetworkManagementService.java
@@ -405,7 +405,7 @@
     /**
      * Notify our observers of a new or updated interface address.
      */
-    private void notifyAddressUpdated(String address, String iface, int flags, int scope) {
+    private void notifyAddressUpdated(LinkAddress address, String iface, int flags, int scope) {
         final int length = mObservers.beginBroadcast();
         for (int i = 0; i < length; i++) {
             try {
@@ -420,7 +420,7 @@
     /**
      * Notify our observers of a deleted interface address.
      */
-    private void notifyAddressRemoved(String address, String iface, int flags, int scope) {
+    private void notifyAddressRemoved(LinkAddress address, String iface, int flags, int scope) {
         final int length = mObservers.beginBroadcast();
         for (int i = 0; i < length; i++) {
             try {
@@ -537,17 +537,21 @@
 
                     int flags;
                     int scope;
+                    LinkAddress address;
                     try {
                         flags = Integer.parseInt(cooked[5]);
                         scope = Integer.parseInt(cooked[6]);
-                    } catch(NumberFormatException e) {
-                        throw new IllegalStateException(errorMessage);
+                        address = new LinkAddress(cooked[3]);
+                    } catch(NumberFormatException e) {     // Non-numeric lifetime or scope.
+                        throw new IllegalStateException(errorMessage, e);
+                    } catch(IllegalArgumentException e) {  // Malformed IP address.
+                        throw new IllegalStateException(errorMessage, e);
                     }
 
                     if (cooked[2].equals("updated")) {
-                        notifyAddressUpdated(cooked[3], cooked[4], flags, scope);
+                        notifyAddressUpdated(address, cooked[4], flags, scope);
                     } else {
-                        notifyAddressRemoved(cooked[3], cooked[4], flags, scope);
+                        notifyAddressRemoved(address, cooked[4], flags, scope);
                     }
                     return true;
                     // break;