Add getters to NetworkStateSnapshot

Address API council feedback, add getters to NetworkStateSnapshot
instead of exposing the bare fields directly.

Bug: 183972826
Test: FrameworksNetTests
Change-Id: Id1707753b42ae88d2b95e4bd00a792609434e4f5
This commit is contained in:
Aaron Huang
2021-04-20 17:19:46 +08:00
parent e3bad0320d
commit c8081e954e
2 changed files with 7 additions and 7 deletions

View File

@@ -2150,11 +2150,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
for (NetworkStateSnapshot snapshot : getAllNetworkStateSnapshot()) {
// NetworkStateSnapshot doesn't contain NetworkInfo, so need to fetch it from the
// NetworkAgentInfo.
final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(snapshot.network);
final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(snapshot.getNetwork());
if (nai != null && nai.networkInfo.isConnected()) {
result.add(new NetworkState(new NetworkInfo(nai.networkInfo),
snapshot.linkProperties, snapshot.networkCapabilities, snapshot.network,
snapshot.subscriberId));
snapshot.getLinkProperties(), snapshot.getNetworkCapabilities(),
snapshot.getNetwork(), snapshot.getSubscriberId()));
}
}
return result.toArray(new NetworkState[result.size()]);

View File

@@ -88,8 +88,8 @@ import android.net.NetworkStateSnapshot;
import android.net.NetworkStats;
import android.net.NetworkStatsHistory;
import android.net.NetworkTemplate;
import android.net.UnderlyingNetworkInfo;
import android.net.TelephonyNetworkSpecifier;
import android.net.UnderlyingNetworkInfo;
import android.net.netstats.provider.INetworkStatsProviderCallback;
import android.os.ConditionVariable;
import android.os.Handler;
@@ -873,7 +873,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
final LinkProperties stackedProp = new LinkProperties();
stackedProp.setInterfaceName(stackedIface);
final NetworkStateSnapshot wifiState = buildWifiState();
wifiState.linkProperties.addStackedLink(stackedProp);
wifiState.getLinkProperties().addStackedLink(stackedProp);
NetworkStateSnapshot[] states = new NetworkStateSnapshot[] {wifiState};
expectNetworkStatsSummary(buildEmptyStats());
@@ -1564,10 +1564,10 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
}
private String getActiveIface(NetworkStateSnapshot... states) throws Exception {
if (states == null || states.length == 0 || states[0].linkProperties == null) {
if (states == null || states.length == 0 || states[0].getLinkProperties() == null) {
return null;
}
return states[0].linkProperties.getInterfaceName();
return states[0].getLinkProperties().getInterfaceName();
}
private void expectNetworkStatsSummary(NetworkStats summary) throws Exception {