OSDN Git Service

Send empty LinkProperties when entering StoppedState.
authorErik Kline <ek@google.com>
Wed, 6 Dec 2017 04:37:09 +0000 (13:37 +0900)
committerErik Kline <ek@google.com>
Thu, 7 Dec 2017 09:07:38 +0000 (18:07 +0900)
Test: as follows
    - built
    - flashed
    - booted
    - runtest frameworks-net passes
    - changing from DHCPv4 to static while continuously pinging the
      default gateway works jsut fine
    - dumpsys log shows that during the change we send the empty LP:
  12-06 08:46:51.085 - CMD_ON_QUIT wlan0/23 0 0 null [rcvd_in=StoppingState, proc_in=StoppingState]
  12-06 08:46:51.092 - INVOKE onLinkPropertiesChange({{InterfaceName: wlan0 LinkAddresses: []  Routes: [] DnsAddresses: [] Domains: null MTU: 0}})

Bug: 69800563
Change-Id: I01047e9a72fce718a167c592bf14406c3bab3ba9

services/net/java/android/net/ip/IpClient.java
tests/net/java/android/net/ip/IpManagerTest.java

index 70983c8..5c58cdb 100644 (file)
@@ -163,10 +163,10 @@ public class IpClient extends StateMachine {
     // TODO: Find an lighter weight approach.
     private class LoggingCallbackWrapper extends Callback {
         private static final String PREFIX = "INVOKE ";
-        private Callback mCallback;
+        private final Callback mCallback;
 
         public LoggingCallbackWrapper(Callback callback) {
-            mCallback = callback;
+            mCallback = (callback != null) ? callback : new Callback();
         }
 
         private void log(String msg) {
@@ -1273,6 +1273,7 @@ public class IpClient extends StateMachine {
             stopAllIP();
 
             resetLinkProperties();
+            mCallback.onLinkPropertiesChange(new LinkProperties(mLinkProperties));
             if (mStartTimeMillis > 0) {
                 recordMetric(IpManagerEvent.COMPLETE_LIFECYCLE);
                 mStartTimeMillis = 0;
index 22d88fb..ebf121a 100644 (file)
@@ -69,6 +69,8 @@ import java.util.Set;
 
 /**
  * Tests for IpManager.
+ *
+ * TODO: Rename to IpClientTest.
  */
 @RunWith(AndroidJUnit4.class)
 @SmallTest
@@ -111,6 +113,10 @@ public class IpManagerTest {
         verify(mNMService, times(1)).registerObserver(arg.capture());
         mObserver = arg.getValue();
         reset(mNMService);
+        final LinkProperties emptyLp = new LinkProperties();
+        emptyLp.setInterfaceName(ifname);
+        verify(mCb, timeout(100)).onLinkPropertiesChange(eq(emptyLp));
+        reset(mCb);
         return ipm;
     }