TrafficStats 报告所有应用程序的 -1 除了我自己的应用程序?

TrafficStats reporting -1 for all applications except my own?

我 运行 我的设备上有以下代码:

PackageManager packageManager = context.getPackageManager();
List<ApplicationInfo> applications = packageManager
        .getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : applications) {
    Log.OUT.debug("NET_THRESHOLD: package = " + applicationInfo.packageName + ", uid = " + applicationInfo.uid + ", rx bytes: " + TrafficStats.getUidRxBytes(applicationInfo.uid));
}

而且它似乎报告了我设备上每个包裹的 -1(或 TrafficStats.UNSUPPORTED),除了我调用它的包裹。

这是有意为之的行为吗?

我 运行宁 Android 10 如果这有什么不同。

我刚刚在 TrafficStats#getUidRxBytes(int) 的 android 文档中找到了这个。

Starting in Build.VERSION_CODES.N this will only report traffic statistics for the calling UID. It will return UNSUPPORTED for all other UIDs for privacy reasons. To access historical network statistics belonging to other UIDs, use NetworkStatsManager.