Merge "Fix multipathPolicyTracker query-update loop" am: 8e2a6f76c7
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1951481 Change-Id: Id6a9f13de0feae8abe47b894b672beeba80f3c0e
This commit is contained in:
@@ -199,6 +199,7 @@ public class MultipathPolicyTracker {
|
|||||||
private final NetworkTemplate mNetworkTemplate;
|
private final NetworkTemplate mNetworkTemplate;
|
||||||
private final UsageCallback mUsageCallback;
|
private final UsageCallback mUsageCallback;
|
||||||
private NetworkCapabilities mNetworkCapabilities;
|
private NetworkCapabilities mNetworkCapabilities;
|
||||||
|
private final NetworkStatsManager mStatsManager;
|
||||||
|
|
||||||
public MultipathTracker(Network network, NetworkCapabilities nc) {
|
public MultipathTracker(Network network, NetworkCapabilities nc) {
|
||||||
this.network = network;
|
this.network = network;
|
||||||
@@ -238,6 +239,13 @@ public class MultipathPolicyTracker {
|
|||||||
updateMultipathBudget();
|
updateMultipathBudget();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
mStatsManager = mContext.getSystemService(NetworkStatsManager.class);
|
||||||
|
// Query stats from NetworkStatsService will trigger a poll by default.
|
||||||
|
// But since MultipathPolicyTracker listens NPMS events that triggered by
|
||||||
|
// stats updated event, and will query stats
|
||||||
|
// after the event. A polling -> updated -> query -> polling loop will be introduced
|
||||||
|
// if polls on open. Hence, set flag to false to prevent a polling loop.
|
||||||
|
mStatsManager.setPollOnOpen(false);
|
||||||
|
|
||||||
updateMultipathBudget();
|
updateMultipathBudget();
|
||||||
}
|
}
|
||||||
@@ -262,8 +270,7 @@ public class MultipathPolicyTracker {
|
|||||||
private long getNetworkTotalBytes(long start, long end) {
|
private long getNetworkTotalBytes(long start, long end) {
|
||||||
try {
|
try {
|
||||||
final android.app.usage.NetworkStats.Bucket ret =
|
final android.app.usage.NetworkStats.Bucket ret =
|
||||||
mContext.getSystemService(NetworkStatsManager.class)
|
mStatsManager.querySummaryForDevice(mNetworkTemplate, start, end);
|
||||||
.querySummaryForDevice(mNetworkTemplate, start, end);
|
|
||||||
return ret.getRxBytes() + ret.getTxBytes();
|
return ret.getRxBytes() + ret.getTxBytes();
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
Log.w(TAG, "Failed to get data usage: " + e);
|
Log.w(TAG, "Failed to get data usage: " + e);
|
||||||
|
|||||||
Reference in New Issue
Block a user