Loading services/core/java/com/android/server/stats/pull/StatsPullAtomService.java +28 −25 Original line number Diff line number Diff line Loading @@ -28,18 +28,11 @@ import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET; import static android.net.NetworkCapabilities.TRANSPORT_WIFI; import static android.net.NetworkIdentity.OEM_PAID; 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.ROAMING_ALL; import static android.net.NetworkTemplate.MATCH_ETHERNET; import static android.net.NetworkTemplate.MATCH_MOBILE_WILDCARD; import static android.net.NetworkTemplate.MATCH_WIFI_WILDCARD; import static android.net.NetworkTemplate.NETWORK_TYPE_ALL; import static android.net.NetworkTemplate.MATCH_MOBILE; import static android.net.NetworkTemplate.MATCH_WIFI; 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.os.Debug.getIonHeapsSizeKb; import static android.os.Process.LAST_SHARED_APPLICATION_GID; Loading Loading @@ -1179,9 +1172,10 @@ public class StatsPullAtomService extends SystemService { } case FrameworkStatsLog.BYTES_TRANSFER_BY_TAG_AND_METERED: { final NetworkStats wifiStats = getUidNetworkStatsSnapshotForTemplate( buildTemplateWifiWildcard(), /*includeTags=*/true); new NetworkTemplate.Builder(MATCH_WIFI).build(), /*includeTags=*/true); final NetworkStats cellularStats = getUidNetworkStatsSnapshotForTemplate( buildTemplateMobileWildcard(), /*includeTags=*/true); new NetworkTemplate.Builder(MATCH_MOBILE) .setMeteredness(METERED_YES).build(), /*includeTags=*/true); if (wifiStats != null && cellularStats != null) { final NetworkStats stats = wifiStats.add(cellularStats); ret.add(new NetworkStatsExt(sliceNetworkStatsByUidTagAndMetered(stats), Loading Loading @@ -1333,8 +1327,8 @@ public class StatsPullAtomService extends SystemService { @NonNull private List<NetworkStatsExt> getDataUsageBytesTransferSnapshotForOemManaged() { final List<Pair<Integer, Integer>> matchRulesAndTransports = List.of( new Pair(MATCH_ETHERNET, TRANSPORT_ETHERNET), new Pair(MATCH_MOBILE_WILDCARD, TRANSPORT_CELLULAR), new Pair(MATCH_WIFI_WILDCARD, TRANSPORT_WIFI) new Pair(MATCH_MOBILE, TRANSPORT_CELLULAR), new Pair(MATCH_WIFI, TRANSPORT_WIFI) ); final int[] oemManagedTypes = new int[] {OEM_PAID | OEM_PRIVATE, OEM_PAID, OEM_PRIVATE}; Loading @@ -1343,12 +1337,11 @@ public class StatsPullAtomService extends SystemService { for (Pair<Integer, Integer> ruleAndTransport : matchRulesAndTransports) { final Integer matchRule = ruleAndTransport.first; for (final int oemManaged : oemManagedTypes) { /* A null subscriberId will set wildcard=true, since we aren't trying to select a specific ssid or subscriber. */ final NetworkTemplate template = new NetworkTemplate(matchRule, /*subscriberId=*/null, /*matchSubscriberIds=*/null, /*networkId=*/null, METERED_ALL, ROAMING_ALL, DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL, oemManaged); // Subscriber Ids and Wifi Network Keys will not be set since the purpose is to // slice statistics of different OEM managed networks among all network types. // Thus, specifying networks through their identifiers are not needed. final NetworkTemplate template = new NetworkTemplate.Builder(matchRule) .setOemManaged(oemManaged).build(); final NetworkStats stats = getUidNetworkStatsSnapshotForTemplate(template, false); final Integer transport = ruleAndTransport.second; if (stats != null) { Loading @@ -1367,10 +1360,18 @@ public class StatsPullAtomService extends SystemService { * Create a snapshot of NetworkStats for a given transport. */ @Nullable private NetworkStats getUidNetworkStatsSnapshotForTransport(int transport) { final NetworkTemplate template = (transport == TRANSPORT_CELLULAR) ? NetworkTemplate.buildTemplateMobileWithRatType( /*subscriptionId=*/null, NETWORK_TYPE_ALL, METERED_YES) : NetworkTemplate.buildTemplateWifiWildcard(); NetworkTemplate template = null; switch (transport) { case TRANSPORT_CELLULAR: 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); } Loading Loading @@ -1409,8 +1410,10 @@ public class StatsPullAtomService extends SystemService { final List<NetworkStatsExt> ret = new ArrayList<>(); for (final int ratType : getAllCollapsedRatTypes()) { final NetworkTemplate template = buildTemplateMobileWithRatType(subInfo.subscriberId, ratType, METERED_YES); new NetworkTemplate.Builder(MATCH_MOBILE) .setSubscriberIds(Set.of(subInfo.subscriberId)) .setRatType(ratType) .setMeteredness(METERED_YES).build(); final NetworkStats stats = getUidNetworkStatsSnapshotForTemplate(template, /*includeTags=*/false); if (stats != null) { Loading Loading
services/core/java/com/android/server/stats/pull/StatsPullAtomService.java +28 −25 Original line number Diff line number Diff line Loading @@ -28,18 +28,11 @@ import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET; import static android.net.NetworkCapabilities.TRANSPORT_WIFI; import static android.net.NetworkIdentity.OEM_PAID; 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.ROAMING_ALL; import static android.net.NetworkTemplate.MATCH_ETHERNET; import static android.net.NetworkTemplate.MATCH_MOBILE_WILDCARD; import static android.net.NetworkTemplate.MATCH_WIFI_WILDCARD; import static android.net.NetworkTemplate.NETWORK_TYPE_ALL; import static android.net.NetworkTemplate.MATCH_MOBILE; import static android.net.NetworkTemplate.MATCH_WIFI; 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.os.Debug.getIonHeapsSizeKb; import static android.os.Process.LAST_SHARED_APPLICATION_GID; Loading Loading @@ -1179,9 +1172,10 @@ public class StatsPullAtomService extends SystemService { } case FrameworkStatsLog.BYTES_TRANSFER_BY_TAG_AND_METERED: { final NetworkStats wifiStats = getUidNetworkStatsSnapshotForTemplate( buildTemplateWifiWildcard(), /*includeTags=*/true); new NetworkTemplate.Builder(MATCH_WIFI).build(), /*includeTags=*/true); final NetworkStats cellularStats = getUidNetworkStatsSnapshotForTemplate( buildTemplateMobileWildcard(), /*includeTags=*/true); new NetworkTemplate.Builder(MATCH_MOBILE) .setMeteredness(METERED_YES).build(), /*includeTags=*/true); if (wifiStats != null && cellularStats != null) { final NetworkStats stats = wifiStats.add(cellularStats); ret.add(new NetworkStatsExt(sliceNetworkStatsByUidTagAndMetered(stats), Loading Loading @@ -1333,8 +1327,8 @@ public class StatsPullAtomService extends SystemService { @NonNull private List<NetworkStatsExt> getDataUsageBytesTransferSnapshotForOemManaged() { final List<Pair<Integer, Integer>> matchRulesAndTransports = List.of( new Pair(MATCH_ETHERNET, TRANSPORT_ETHERNET), new Pair(MATCH_MOBILE_WILDCARD, TRANSPORT_CELLULAR), new Pair(MATCH_WIFI_WILDCARD, TRANSPORT_WIFI) new Pair(MATCH_MOBILE, TRANSPORT_CELLULAR), new Pair(MATCH_WIFI, TRANSPORT_WIFI) ); final int[] oemManagedTypes = new int[] {OEM_PAID | OEM_PRIVATE, OEM_PAID, OEM_PRIVATE}; Loading @@ -1343,12 +1337,11 @@ public class StatsPullAtomService extends SystemService { for (Pair<Integer, Integer> ruleAndTransport : matchRulesAndTransports) { final Integer matchRule = ruleAndTransport.first; for (final int oemManaged : oemManagedTypes) { /* A null subscriberId will set wildcard=true, since we aren't trying to select a specific ssid or subscriber. */ final NetworkTemplate template = new NetworkTemplate(matchRule, /*subscriberId=*/null, /*matchSubscriberIds=*/null, /*networkId=*/null, METERED_ALL, ROAMING_ALL, DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL, oemManaged); // Subscriber Ids and Wifi Network Keys will not be set since the purpose is to // slice statistics of different OEM managed networks among all network types. // Thus, specifying networks through their identifiers are not needed. final NetworkTemplate template = new NetworkTemplate.Builder(matchRule) .setOemManaged(oemManaged).build(); final NetworkStats stats = getUidNetworkStatsSnapshotForTemplate(template, false); final Integer transport = ruleAndTransport.second; if (stats != null) { Loading @@ -1367,10 +1360,18 @@ public class StatsPullAtomService extends SystemService { * Create a snapshot of NetworkStats for a given transport. */ @Nullable private NetworkStats getUidNetworkStatsSnapshotForTransport(int transport) { final NetworkTemplate template = (transport == TRANSPORT_CELLULAR) ? NetworkTemplate.buildTemplateMobileWithRatType( /*subscriptionId=*/null, NETWORK_TYPE_ALL, METERED_YES) : NetworkTemplate.buildTemplateWifiWildcard(); NetworkTemplate template = null; switch (transport) { case TRANSPORT_CELLULAR: 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); } Loading Loading @@ -1409,8 +1410,10 @@ public class StatsPullAtomService extends SystemService { final List<NetworkStatsExt> ret = new ArrayList<>(); for (final int ratType : getAllCollapsedRatTypes()) { final NetworkTemplate template = buildTemplateMobileWithRatType(subInfo.subscriberId, ratType, METERED_YES); new NetworkTemplate.Builder(MATCH_MOBILE) .setSubscriberIds(Set.of(subInfo.subscriberId)) .setRatType(ratType) .setMeteredness(METERED_YES).build(); final NetworkStats stats = getUidNetworkStatsSnapshotForTemplate(template, /*includeTags=*/false); if (stats != null) { Loading