Merge "Replace buildTemplate* with NetworkTemplate.Builder" am: b892406528
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1933089 Change-Id: I1ebee1b55bf0627f0d3f6a0c61ff92d9e7365d67
This commit is contained in:
@@ -27,18 +27,11 @@ import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
|||||||
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
||||||
import static android.net.NetworkIdentity.OEM_PAID;
|
import static android.net.NetworkIdentity.OEM_PAID;
|
||||||
import static android.net.NetworkIdentity.OEM_PRIVATE;
|
import static android.net.NetworkIdentity.OEM_PRIVATE;
|
||||||
import static android.net.NetworkStats.DEFAULT_NETWORK_ALL;
|
|
||||||
import static android.net.NetworkStats.METERED_ALL;
|
|
||||||
import static android.net.NetworkStats.METERED_YES;
|
import static android.net.NetworkStats.METERED_YES;
|
||||||
import static android.net.NetworkStats.ROAMING_ALL;
|
|
||||||
import static android.net.NetworkTemplate.MATCH_ETHERNET;
|
import static android.net.NetworkTemplate.MATCH_ETHERNET;
|
||||||
import static android.net.NetworkTemplate.MATCH_MOBILE_WILDCARD;
|
import static android.net.NetworkTemplate.MATCH_MOBILE;
|
||||||
import static android.net.NetworkTemplate.MATCH_WIFI_WILDCARD;
|
import static android.net.NetworkTemplate.MATCH_WIFI;
|
||||||
import static android.net.NetworkTemplate.NETWORK_TYPE_ALL;
|
|
||||||
import static android.net.NetworkTemplate.OEM_MANAGED_ALL;
|
import static android.net.NetworkTemplate.OEM_MANAGED_ALL;
|
||||||
import static android.net.NetworkTemplate.buildTemplateMobileWildcard;
|
|
||||||
import static android.net.NetworkTemplate.buildTemplateMobileWithRatType;
|
|
||||||
import static android.net.NetworkTemplate.buildTemplateWifiWildcard;
|
|
||||||
import static android.net.NetworkTemplate.getAllCollapsedRatTypes;
|
import static android.net.NetworkTemplate.getAllCollapsedRatTypes;
|
||||||
import static android.os.Debug.getIonHeapsSizeKb;
|
import static android.os.Debug.getIonHeapsSizeKb;
|
||||||
import static android.os.Process.LAST_SHARED_APPLICATION_GID;
|
import static android.os.Process.LAST_SHARED_APPLICATION_GID;
|
||||||
@@ -1155,9 +1148,10 @@ public class StatsPullAtomService extends SystemService {
|
|||||||
}
|
}
|
||||||
case FrameworkStatsLog.BYTES_TRANSFER_BY_TAG_AND_METERED: {
|
case FrameworkStatsLog.BYTES_TRANSFER_BY_TAG_AND_METERED: {
|
||||||
final NetworkStats wifiStats = getUidNetworkStatsSnapshotForTemplate(
|
final NetworkStats wifiStats = getUidNetworkStatsSnapshotForTemplate(
|
||||||
buildTemplateWifiWildcard(), /*includeTags=*/true);
|
new NetworkTemplate.Builder(MATCH_WIFI).build(), /*includeTags=*/true);
|
||||||
final NetworkStats cellularStats = getUidNetworkStatsSnapshotForTemplate(
|
final NetworkStats cellularStats = getUidNetworkStatsSnapshotForTemplate(
|
||||||
buildTemplateMobileWildcard(), /*includeTags=*/true);
|
new NetworkTemplate.Builder(MATCH_MOBILE)
|
||||||
|
.setMeteredness(METERED_YES).build(), /*includeTags=*/true);
|
||||||
if (wifiStats != null && cellularStats != null) {
|
if (wifiStats != null && cellularStats != null) {
|
||||||
final NetworkStats stats = wifiStats.add(cellularStats);
|
final NetworkStats stats = wifiStats.add(cellularStats);
|
||||||
ret.add(new NetworkStatsExt(sliceNetworkStatsByUidTagAndMetered(stats),
|
ret.add(new NetworkStatsExt(sliceNetworkStatsByUidTagAndMetered(stats),
|
||||||
@@ -1307,24 +1301,22 @@ public class StatsPullAtomService extends SystemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull private List<NetworkStatsExt> getDataUsageBytesTransferSnapshotForOemManaged() {
|
@NonNull private List<NetworkStatsExt> getDataUsageBytesTransferSnapshotForOemManaged() {
|
||||||
final int[] transports = new int[] {MATCH_ETHERNET, MATCH_MOBILE_WILDCARD,
|
final int[] matchRules = new int[] {MATCH_ETHERNET, MATCH_MOBILE, MATCH_WIFI};
|
||||||
MATCH_WIFI_WILDCARD};
|
|
||||||
final int[] oemManagedTypes = new int[] {OEM_PAID | OEM_PRIVATE, OEM_PAID, OEM_PRIVATE};
|
final int[] oemManagedTypes = new int[] {OEM_PAID | OEM_PRIVATE, OEM_PAID, OEM_PRIVATE};
|
||||||
|
|
||||||
final List<NetworkStatsExt> ret = new ArrayList<>();
|
final List<NetworkStatsExt> ret = new ArrayList<>();
|
||||||
|
|
||||||
for (final int transport : transports) {
|
for (final int matchRule : matchRules) {
|
||||||
for (final int oemManaged : oemManagedTypes) {
|
for (final int oemManaged : oemManagedTypes) {
|
||||||
/* A null subscriberId will set wildcard=true, since we aren't trying to select a
|
// Subscriber Ids and Wifi Network Keys will not be set since the purpose is to
|
||||||
specific ssid or subscriber. */
|
// slice statistics of different OEM managed networks among all network types.
|
||||||
final NetworkTemplate template = new NetworkTemplate(transport,
|
// Thus, specifying networks through their identifiers are not needed.
|
||||||
/*subscriberId=*/null, /*matchSubscriberIds=*/null, /*networkId=*/null,
|
final NetworkTemplate template = new NetworkTemplate.Builder(matchRule)
|
||||||
METERED_ALL, ROAMING_ALL, DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL,
|
.setOemManaged(oemManaged).build();
|
||||||
oemManaged);
|
|
||||||
final NetworkStats stats = getUidNetworkStatsSnapshotForTemplate(template, true);
|
final NetworkStats stats = getUidNetworkStatsSnapshotForTemplate(template, true);
|
||||||
if (stats != null) {
|
if (stats != null) {
|
||||||
ret.add(new NetworkStatsExt(sliceNetworkStatsByUidTagAndMetered(stats),
|
ret.add(new NetworkStatsExt(sliceNetworkStatsByUidTagAndMetered(stats),
|
||||||
new int[] {transport}, /*slicedByFgbg=*/true, /*slicedByTag=*/true,
|
new int[] {matchRule}, /*slicedByFgbg=*/true, /*slicedByTag=*/true,
|
||||||
/*slicedByMetered=*/true, TelephonyManager.NETWORK_TYPE_UNKNOWN,
|
/*slicedByMetered=*/true, TelephonyManager.NETWORK_TYPE_UNKNOWN,
|
||||||
/*subInfo=*/null, oemManaged));
|
/*subInfo=*/null, oemManaged));
|
||||||
}
|
}
|
||||||
@@ -1338,10 +1330,18 @@ public class StatsPullAtomService extends SystemService {
|
|||||||
* Create a snapshot of NetworkStats for a given transport.
|
* Create a snapshot of NetworkStats for a given transport.
|
||||||
*/
|
*/
|
||||||
@Nullable private NetworkStats getUidNetworkStatsSnapshotForTransport(int transport) {
|
@Nullable private NetworkStats getUidNetworkStatsSnapshotForTransport(int transport) {
|
||||||
final NetworkTemplate template = (transport == TRANSPORT_CELLULAR)
|
NetworkTemplate template = null;
|
||||||
? NetworkTemplate.buildTemplateMobileWithRatType(
|
switch (transport) {
|
||||||
/*subscriptionId=*/null, NETWORK_TYPE_ALL, METERED_YES)
|
case TRANSPORT_CELLULAR:
|
||||||
: NetworkTemplate.buildTemplateWifiWildcard();
|
template = new NetworkTemplate.Builder(MATCH_MOBILE)
|
||||||
|
.setMeteredness(METERED_YES).build();
|
||||||
|
break;
|
||||||
|
case TRANSPORT_WIFI:
|
||||||
|
template = new NetworkTemplate.Builder(MATCH_WIFI).build();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log.wtf(TAG, "Unexpected transport.");
|
||||||
|
}
|
||||||
return getUidNetworkStatsSnapshotForTemplate(template, /*includeTags=*/false);
|
return getUidNetworkStatsSnapshotForTemplate(template, /*includeTags=*/false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1380,8 +1380,10 @@ public class StatsPullAtomService extends SystemService {
|
|||||||
final List<NetworkStatsExt> ret = new ArrayList<>();
|
final List<NetworkStatsExt> ret = new ArrayList<>();
|
||||||
for (final int ratType : getAllCollapsedRatTypes()) {
|
for (final int ratType : getAllCollapsedRatTypes()) {
|
||||||
final NetworkTemplate template =
|
final NetworkTemplate template =
|
||||||
buildTemplateMobileWithRatType(subInfo.subscriberId, ratType,
|
new NetworkTemplate.Builder(MATCH_MOBILE)
|
||||||
METERED_YES);
|
.setSubscriberIds(Set.of(subInfo.subscriberId))
|
||||||
|
.setRatType(ratType)
|
||||||
|
.setMeteredness(METERED_YES).build();
|
||||||
final NetworkStats stats =
|
final NetworkStats stats =
|
||||||
getUidNetworkStatsSnapshotForTemplate(template, /*includeTags=*/false);
|
getUidNetworkStatsSnapshotForTemplate(template, /*includeTags=*/false);
|
||||||
if (stats != null) {
|
if (stats != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user