summaryrefslogtreecommitdiff
path: root/framework-t/src/android/app/usage/NetworkStatsManager.java
diff options
context:
space:
mode:
authorlifr <lifr@google.com>2022-01-12 00:54:40 +0800
committerFrank <lifr@google.com>2022-01-21 13:52:41 +0800
commit02eb422cb48283b7011424281f9c00c4759e89df (patch)
tree95c1c3eedcaf12247e23b265efac4479ed63272a /framework-t/src/android/app/usage/NetworkStatsManager.java
parent717c22831a227e7977f22d1ffe5b356575c15bd7 (diff)
[DU03-1]Remove INetworkStatsService from BatteryStatsImpl
Expose systemapi NetworkStats.getDetailedUidStats for use by BatteryStats. BatteryStatsImpl is using INetworkStatsService APIs, which cannot be accessed after moving into the mainline module. So, replace and remove those hidden API usages. Bug: 210066922 Test: atest BatteryStatsImplTest WifiPowerCalculatorTest MobileRadioPowerCalculatorTest NetworkStatsServiceTest CTS-Coverage-Bug: 213437796 Change-Id: I40d713923278f4654d67bb4d12155cea85c10447
Diffstat (limited to 'framework-t/src/android/app/usage/NetworkStatsManager.java')
-rw-r--r--framework-t/src/android/app/usage/NetworkStatsManager.java52
1 files changed, 38 insertions, 14 deletions
diff --git a/framework-t/src/android/app/usage/NetworkStatsManager.java b/framework-t/src/android/app/usage/NetworkStatsManager.java
index 8d93354ea9..683678ad46 100644
--- a/framework-t/src/android/app/usage/NetworkStatsManager.java
+++ b/framework-t/src/android/app/usage/NetworkStatsManager.java
@@ -17,6 +17,8 @@
package android.app.usage;
import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;
+import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
+import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
import android.Manifest;
import android.annotation.NonNull;
@@ -55,7 +57,6 @@ import com.android.net.module.util.NetworkIdentityUtils;
import java.util.List;
import java.util.Objects;
-import java.util.Set;
/**
* Provides access to network usage history and statistics. Usage data is collected in
@@ -670,26 +671,49 @@ public class NetworkStatsManager {
}
/**
- * Query realtime network usage statistics details with interfaces constrains.
- * Return snapshot of current UID statistics, including any {@link TrafficStats#UID_TETHERING},
- * video calling data usage and count of network operations that set by
- * {@link TrafficStats#incrementOperationCount}. The returned data doesn't include any
- * statistics that is reported by {@link NetworkStatsProvider}.
+ * Query realtime mobile network usage statistics.
*
- * @param requiredIfaces A list of interfaces the stats should be restricted to, or
- * {@link NetworkStats#INTERFACES_ALL}.
+ * Return a snapshot of current UID network statistics, as it applies
+ * to the mobile radios of the device. The snapshot will include any
+ * tethering traffic, video calling data usage and count of
+ * network operations set by {@link TrafficStats#incrementOperationCount}
+ * made over a mobile radio.
+ * The snapshot will not include any statistics that cannot be seen by
+ * the kernel, e.g. statistics reported by {@link NetworkStatsProvider}s.
*
* @hide
*/
- //@SystemApi
+ @SystemApi
+ @RequiresPermission(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK)
+ @NonNull public android.net.NetworkStats getMobileUidStats() {
+ try {
+ return mService.getUidStatsForTransport(TRANSPORT_CELLULAR);
+ } catch (RemoteException e) {
+ if (DBG) Log.d(TAG, "Remote exception when get Mobile uid stats");
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Query realtime Wi-Fi network usage statistics.
+ *
+ * Return a snapshot of current UID network statistics, as it applies
+ * to the Wi-Fi radios of the device. The snapshot will include any
+ * tethering traffic, video calling data usage and count of
+ * network operations set by {@link TrafficStats#incrementOperationCount}
+ * made over a Wi-Fi radio.
+ * The snapshot will not include any statistics that cannot be seen by
+ * the kernel, e.g. statistics reported by {@link NetworkStatsProvider}s.
+ *
+ * @hide
+ */
+ @SystemApi
@RequiresPermission(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK)
- @NonNull public android.net.NetworkStats getDetailedUidStats(
- @NonNull Set<String> requiredIfaces) {
- Objects.requireNonNull(requiredIfaces, "requiredIfaces cannot be null");
+ @NonNull public android.net.NetworkStats getWifiUidStats() {
try {
- return mService.getDetailedUidStats(requiredIfaces.toArray(new String[0]));
+ return mService.getUidStatsForTransport(TRANSPORT_WIFI);
} catch (RemoteException e) {
- if (DBG) Log.d(TAG, "Remote exception when get detailed uid stats");
+ if (DBG) Log.d(TAG, "Remote exception when get WiFi uid stats");
throw e.rethrowFromSystemServer();
}
}