Fixes isDefaultNetworkActive and onNetworkActive unreasonable behavior

This CL changes the behavior as follows.

Before this CL, isDefaultNetworkActive returns true if there is no
default network.
After this CL, isDefaultNetworkActive returns false if there is no
default network on all releases.

Before this CL, LegacyNetworkActivityTracker does not call
onNetworkActive callback for networks that tracker does not add the idle
timer to (e.g.  ethernet, cell network configured with activity tracking
disabled).
After this CL,
On T-, onNetworkActive keeps the current behavior.
On U+, onNetworkActive is called regardless of the idle timer existence. This behavior is consistent with ConnectivityManager#isDefaultNetworkActive, which always returns true for a network that has no activity tracking.

Bug: 267870186
Bug: 279380356
Test: atest FrameworksNetTests
Change-Id: I7b1d493fea0ab028b53a3d640a58a00ebbdcc143
This commit is contained in:
Motomu Utsumi
2023-05-29 15:08:57 +09:00
parent c298cf0c2d
commit 6225d57b18
2 changed files with 34 additions and 27 deletions

View File

@@ -11315,18 +11315,17 @@ public class ConnectivityServiceTest {
}
@Test
public void testOnNetworkActive_NewEthernetConnects_CallbackNotCalled() throws Exception {
// LegacyNetworkActivityTracker calls onNetworkActive callback only for networks that
public void testOnNetworkActive_NewEthernetConnects_Callback() throws Exception {
// On T-, LegacyNetworkActivityTracker calls onNetworkActive callback only for networks that
// tracker adds the idle timer to. And the tracker does not set the idle timer for the
// ethernet network.
// So onNetworkActive is not called when the ethernet becomes the default network
doTestOnNetworkActive_NewNetworkConnects(TRANSPORT_ETHERNET, false /* expectCallback */);
doTestOnNetworkActive_NewNetworkConnects(TRANSPORT_ETHERNET, mDeps.isAtLeastU());
}
@Test
public void testIsDefaultNetworkActiveNoDefaultNetwork() throws Exception {
// isDefaultNetworkActive returns true if there is no default network, which is known issue.
assertTrue(mCm.isDefaultNetworkActive());
assertFalse(mCm.isDefaultNetworkActive());
final LinkProperties cellLp = new LinkProperties();
cellLp.setInterfaceName(MOBILE_IFNAME);
@@ -11338,7 +11337,7 @@ public class ConnectivityServiceTest {
mCellAgent.disconnect();
waitForIdle();
assertTrue(mCm.isDefaultNetworkActive());
assertFalse(mCm.isDefaultNetworkActive());
}
@Test