Remove unused getTetherStats
Before Android R, getTetherStats were used to collect tethering
iface stats of all clients who extends ITetheringStatsProvider,
which typically contains NetdTetheringStatsProvider and
OffloadController.
However, this always returns 0 since Android R, because:
1. OffloadController implemented NetworkStatsProvider and no
longer reports stats through getTetherStats.
2. NetdTetheringStatsProvider always return 0 by design since
non-offloaded iface tethering stats are already included
in native iface stats.
This change is a no-op refactoring to remove unused
getTetherStats and update test which is not pratical.
Fix for offloaded tethering stats will be in follow-up CLs.
Test: atest FrameworksNetTests TetheringTests
Bug: 162292214
Change-Id: Icd0717c5c2807ae3bd98626b897e4b148f142815
This commit is contained in:
@@ -1083,13 +1083,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
if (nativeIfaceStats == -1) {
|
||||
return nativeIfaceStats;
|
||||
} else {
|
||||
// When tethering offload is in use, nativeIfaceStats does not contain usage from
|
||||
// offload, add it back here.
|
||||
// When tethering offload is not in use, nativeIfaceStats contains tethering usage.
|
||||
// this does not cause double-counting of tethering traffic, because
|
||||
// NetdTetheringStatsProvider returns zero NetworkStats
|
||||
// when called with STATS_PER_IFACE.
|
||||
return nativeIfaceStats + getTetherStats(iface, type);
|
||||
// TODO: When tethering offload is in use, nativeIfaceStats does not contain usage from
|
||||
// offload, add it back here.
|
||||
return nativeIfaceStats;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1100,42 +1096,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
return nativeTotalStats;
|
||||
} else {
|
||||
// Refer to comment in getIfaceStats
|
||||
return nativeTotalStats + getTetherStats(IFACE_ALL, type);
|
||||
}
|
||||
}
|
||||
|
||||
private long getTetherStats(String iface, int type) {
|
||||
final NetworkStats tetherSnapshot;
|
||||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
tetherSnapshot = getNetworkStatsTethering(STATS_PER_IFACE);
|
||||
} catch (RemoteException e) {
|
||||
Slog.w(TAG, "Error get TetherStats: " + e);
|
||||
return 0;
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(token);
|
||||
}
|
||||
HashSet<String> limitIfaces;
|
||||
if (iface == IFACE_ALL) {
|
||||
limitIfaces = null;
|
||||
} else {
|
||||
limitIfaces = new HashSet<String>();
|
||||
limitIfaces.add(iface);
|
||||
}
|
||||
NetworkStats.Entry entry = tetherSnapshot.getTotal(null, limitIfaces);
|
||||
if (LOGD) Slog.d(TAG, "TetherStats: iface=" + iface + " type=" + type +
|
||||
" entry=" + entry);
|
||||
switch (type) {
|
||||
case 0: // TYPE_RX_BYTES
|
||||
return entry.rxBytes;
|
||||
case 1: // TYPE_RX_PACKETS
|
||||
return entry.rxPackets;
|
||||
case 2: // TYPE_TX_BYTES
|
||||
return entry.txBytes;
|
||||
case 3: // TYPE_TX_PACKETS
|
||||
return entry.txPackets;
|
||||
default:
|
||||
return 0;
|
||||
return nativeTotalStats;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1429,14 +1390,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
final NetworkStats devSnapshot = readNetworkStatsSummaryDev();
|
||||
Trace.traceEnd(TRACE_TAG_NETWORK);
|
||||
|
||||
// Tethering snapshot for dev and xt stats. Counts per-interface data from tethering stats
|
||||
// providers that isn't already counted by dev and XT stats.
|
||||
Trace.traceBegin(TRACE_TAG_NETWORK, "snapshotTether");
|
||||
final NetworkStats tetherSnapshot = getNetworkStatsTethering(STATS_PER_IFACE);
|
||||
Trace.traceEnd(TRACE_TAG_NETWORK);
|
||||
xtSnapshot.combineAllValues(tetherSnapshot);
|
||||
devSnapshot.combineAllValues(tetherSnapshot);
|
||||
|
||||
// Snapshot for dev/xt stats from all custom stats providers. Counts per-interface data
|
||||
// from stats providers that isn't already counted by dev and XT stats.
|
||||
Trace.traceBegin(TRACE_TAG_NETWORK, "snapshotStatsProvider");
|
||||
@@ -1931,9 +1884,13 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return snapshot of current tethering statistics. Will return empty
|
||||
* {@link NetworkStats} if any problems are encountered.
|
||||
* Return snapshot of current non-offloaded tethering statistics. Will return empty
|
||||
* {@link NetworkStats} if any problems are encountered, or queried by {@code STATS_PER_IFACE}
|
||||
* since it is already included by {@link #nativeGetIfaceStat}.
|
||||
* See {@code OffloadTetheringStatsProvider} for offloaded tethering stats.
|
||||
*/
|
||||
// TODO: Remove this by implementing {@link NetworkStatsProvider} for non-offloaded
|
||||
// tethering stats.
|
||||
private NetworkStats getNetworkStatsTethering(int how) throws RemoteException {
|
||||
try {
|
||||
return mNetworkManager.getNetworkStatsTethering(how);
|
||||
|
||||
Reference in New Issue
Block a user