diff options
author | Roshan Pius <rpius@google.com> | 2018-02-08 14:29:14 -0800 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2018-03-05 12:38:49 -0800 |
commit | a2e62c7f5bfb411ccead4eab0d435d50fcdd4909 (patch) | |
tree | ad9aeb96ef4344a43ec8e226b3b4a3318b005a77 /service | |
parent | 34226fdc35f33a5c3a95e0b86138c933c5682370 (diff) |
WifiNative: Mask interface up/down notifications without change
During the setup/teardown of client/softap interface, there could be
recurring interface up/down events. Mask these out in the interface mgmt
layer in WifiNative since these not that useful to WifiStateMachine,
etc.
Also,
a) Check the interface state before we get out of
setupInterface() methods to avoid any races.
b) Ignore interface events from ifaces we don't care about.
Note: For all practical purposes, interface is considered down before
setupInterface() is called. This will help mask any down events which
come if there is a mode switch. For example, setting up interface
(wlan0) for AP will bring down the STA on older devices.
Bug: 73129404
Test: Unit tests
Test: Ran WifiManagerTest & WifiSoftApTest ACTS test
Test: Manually verified that duplicate iface up/down events are not
being generated from WifiNative to WifiStateMachine.
Test: Manually verified that iface down from other interfaces are
ignored (ifconfig rmnet_ipa0 down).
Test: Integration tests passed (b/74072922)
Change-Id: I04d5c61d7d2d3b71995df59f09152a49ac546648
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiNative.java | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index 908344a15..8125ea408 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -123,6 +123,8 @@ public class WifiNative { public final @IfaceType int type; /** Name of the interface */ public String name; + /** Is the interface up? This is used to mask up/down notifications to external clients. */ + public boolean isUp; /** External iface destroyed listener for the iface */ public InterfaceCallback externalListener; /** Network observer registered for this interface */ @@ -519,6 +521,23 @@ public class WifiNative { } } + /** Helper method invoked to handle interface change. */ + private void onInterfaceStateChanged(Iface iface, boolean isUp) { + synchronized (mLock) { + // Mask multiple notifications with the same state. + if (isUp == iface.isUp) { + Log.d(TAG, "Interface status unchanged from " + isUp + ", Ignoring..."); + return; + } + if (isUp) { + iface.externalListener.onUp(iface.name); + } else { + iface.externalListener.onDown(iface.name); + } + iface.isUp = isUp; + } + } + /** * Network observer to use for all interface up/down notifications. */ @@ -534,18 +553,19 @@ public class WifiNative { public void interfaceLinkStateChanged(String ifaceName, boolean isUp) { synchronized (mLock) { Log.i(TAG, "Interface link state changed=" + ifaceName + ", isUp=" + isUp); - final Iface iface = mIfaceMgr.getIface(mInterfaceId); - if (iface == null) { + final Iface ifaceWithId = mIfaceMgr.getIface(mInterfaceId); + if (ifaceWithId == null) { Log.e(TAG, "Received iface up/down notification on an invalid iface=" - + ifaceName); + + mInterfaceId); return; } - - if (isUp) { - iface.externalListener.onUp(ifaceName); - } else { - iface.externalListener.onDown(ifaceName); + final Iface ifaceWithName = mIfaceMgr.getIface(ifaceName); + if (ifaceWithName == null || ifaceWithName != ifaceWithId) { + Log.e(TAG, "Received iface up/down notification on an invalid iface=" + + ifaceName); + return; } + onInterfaceStateChanged(ifaceWithName, isUp); } } } @@ -783,6 +803,9 @@ public class WifiNative { teardownInterface(iface.name); return null; } + // Just to avoid any race conditions with interface state change callbacks, + // update the interface state before we exit. + onInterfaceStateChanged(iface, isInterfaceUp(iface.name)); initializeNwParamsForClientInterface(iface.name); Log.i(TAG, "Successfully setup iface=" + iface.name); return iface.name; @@ -832,6 +855,9 @@ public class WifiNative { teardownInterface(iface.name); return null; } + // Just to avoid any race conditions with interface state change callbacks, + // update the interface state before we exit. + onInterfaceStateChanged(iface, isInterfaceUp(iface.name)); Log.i(TAG, "Successfully setup iface=" + iface.name); return iface.name; } |