Revert "Refactor onIpv6AddressRemoved callback in IpClient."

This reverts commit efdd91cfa7271cb73b96011fefee118d9d401450.

Reason for revert: <aosp/2846095 introduces CompareResults method to check if one IPv6 address has been removed, but that way also introduce the flakiness, revert this CL to fix the flaky tests first>

Change-Id: I56e41cfe005881b99da5fade90a27514bda5a7ce
diff --git a/src/android/net/ip/IpClient.java b/src/android/net/ip/IpClient.java
index 56e85bd..1cc2278 100644
--- a/src/android/net/ip/IpClient.java
+++ b/src/android/net/ip/IpClient.java
@@ -961,6 +961,23 @@
                     }
 
                     @Override
+                    public void onIpv6AddressRemoved(final Inet6Address address) {
+                        // The update of Gratuitous NA target addresses set or unsolicited
+                        // multicast NS source addresses set should be only accessed from the
+                        // handler thread of IpClient StateMachine, keeping the behaviour
+                        // consistent with relying on the non-blocking NetworkObserver callbacks,
+                        // see {@link registerObserverForNonblockingCallback}. This can be done
+                        // by either sending a message to StateMachine or posting a handler.
+                        if (address.isLinkLocalAddress()) return;
+                        getHandler().post(() -> {
+                            mLog.log("Remove IPv6 GUA " + address
+                                    + " from both Gratuituous NA and Multicast NS sets");
+                            mGratuitousNaTargetAddresses.remove(address);
+                            mMulticastNsSourceAddresses.remove(address);
+                        });
+                    }
+
+                    @Override
                     public void onClatInterfaceStateUpdate(boolean add) {
                         // TODO: when clat interface was removed, consider sending a message to
                         // the IpClient main StateMachine thread, in case "NDO enabled" state
@@ -1748,18 +1765,7 @@
                 final IpPrefix prefix = new IpPrefix(la.getAddress(), RFC7421_PREFIX_LENGTH);
                 mDelegatedPrefixes.remove(prefix);
             }
-            // Also remove the global IPv6 address from the Gratuitous NA target addresses set or
-            // unsolicited multicast NS source addresses set if the address is present.
-            if (la.isIpv6()) {
-                final Inet6Address address = (Inet6Address) la.getAddress();
-                if (address.isLinkLocalAddress()) continue;
-                if (DBG) {
-                    mLog.log("Remove IPv6 GUA " + address
-                            + " from Gratuituous NA and Multicast NS sets");
-                }
-                mGratuitousNaTargetAddresses.remove(address);
-                mMulticastNsSourceAddresses.remove(address);
-            }
+            // TODO: remove onIpv6AddressRemoved callback.
         }
 
         // [3] Add in data from DHCPv4, if available.
diff --git a/src/android/net/ip/IpClientLinkObserver.java b/src/android/net/ip/IpClientLinkObserver.java
index 9f27e02..2068caa 100644
--- a/src/android/net/ip/IpClientLinkObserver.java
+++ b/src/android/net/ip/IpClientLinkObserver.java
@@ -122,6 +122,13 @@
         void update(boolean linkState);
 
         /**
+         * Called when an IPv6 address was removed from the interface.
+         *
+         * @param addr The removed IPv6 address.
+         */
+        void onIpv6AddressRemoved(Inet6Address addr);
+
+        /**
          * Called when the clat interface was added/removed.
          *
          * @param add True: clat interface was added.
@@ -325,6 +332,10 @@
         }
         if (changed) {
             mCallback.update(linkState);
+            if (!add && address.isIpv6()) {
+                final Inet6Address addr = (Inet6Address) address.getAddress();
+                mCallback.onIpv6AddressRemoved(addr);
+            }
         }
         return changed;
     }
diff --git a/tests/integration/common/android/net/ip/IpClientIntegrationTestCommon.java b/tests/integration/common/android/net/ip/IpClientIntegrationTestCommon.java
index dc06fe1..84e8151 100644
--- a/tests/integration/common/android/net/ip/IpClientIntegrationTestCommon.java
+++ b/tests/integration/common/android/net/ip/IpClientIntegrationTestCommon.java
@@ -5438,7 +5438,6 @@
                 mNetd.getProcSysNet(INetd.IPV6, INetd.CONF, mIfaceName, "accept_ra_defrtr"));
         assertEquals(1, acceptRaDefRtr);
     }
-
     private void runDhcpDomainSearchListOptionTest(final String domainName,
             final List<String> domainSearchList, final String expectedDomain) throws Exception {
         when(mResources.getBoolean(R.bool.config_dhcp_client_domain_search_list)).thenReturn(true);