Move onUpstreamCapabilitiesChanged out of reportUpstreamChange
onUpstreamCapabilitiesChanged not only be called inside
reportUpstreamChange. Separate onUpstreamCapabilitiesChanged out
of reportUpstreamChange so that reportUpstreamChange can focus
on upstream network change callback.
Bug: 243516306
Test: atest TetheringTests
Change-Id: Ie2ba9805fc43f921100c0286a9300df02f63e35d
diff --git a/Tethering/src/com/android/networkstack/tethering/Tethering.java b/Tethering/src/com/android/networkstack/tethering/Tethering.java
index b4e5781..2e71fda 100644
--- a/Tethering/src/com/android/networkstack/tethering/Tethering.java
+++ b/Tethering/src/com/android/networkstack/tethering/Tethering.java
@@ -88,7 +88,6 @@
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.Network;
-import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.TetherStatesParcel;
import android.net.TetheredClient;
@@ -1856,7 +1855,11 @@
final Network newUpstream = (ns != null) ? ns.network : null;
if (mTetherUpstream != newUpstream) {
mTetherUpstream = newUpstream;
- reportUpstreamChanged(ns);
+ reportUpstreamChanged(mTetherUpstream);
+ // Need to notify capabilities change after upstream network changed because new
+ // network's capabilities should be checked every time.
+ mNotificationUpdater.onUpstreamCapabilitiesChanged(
+ (ns != null) ? ns.networkCapabilities : null);
}
}
@@ -2084,6 +2087,7 @@
if (mTetherUpstream != null) {
mTetherUpstream = null;
reportUpstreamChanged(null);
+ mNotificationUpdater.onUpstreamCapabilitiesChanged(null);
}
mBpfCoordinator.stopPolling();
}
@@ -2438,10 +2442,8 @@
}
}
- private void reportUpstreamChanged(UpstreamNetworkState ns) {
+ private void reportUpstreamChanged(final Network network) {
final int length = mTetheringEventCallbacks.beginBroadcast();
- final Network network = (ns != null) ? ns.network : null;
- final NetworkCapabilities capabilities = (ns != null) ? ns.networkCapabilities : null;
try {
for (int i = 0; i < length; i++) {
try {
@@ -2453,9 +2455,6 @@
} finally {
mTetheringEventCallbacks.finishBroadcast();
}
- // Need to notify capabilities change after upstream network changed because new network's
- // capabilities should be checked every time.
- mNotificationUpdater.onUpstreamCapabilitiesChanged(capabilities);
}
private void reportConfigurationChanged(TetheringConfigurationParcel config) {