Skip to content

Commit d3b0b5d

Browse files
jsharkeyAndroid (Google) Code Review
authored andcommitted
Merge "Suppress StrictMode when reading /proc/ files."
2 parents bce4d98 + 453dafa commit d3b0b5d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

core/java/com/android/internal/net/NetworkStatsFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static com.android.server.NetworkManagementSocketTagger.kernelToTag;
2323

2424
import android.net.NetworkStats;
25+
import android.os.StrictMode;
2526
import android.os.SystemClock;
2627
import android.util.Slog;
2728

@@ -106,6 +107,8 @@ public NetworkStats readNetworkStatsSummary() throws IllegalStateException {
106107
}
107108

108109
private NetworkStats readNetworkStatsSummarySingleFile() {
110+
final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
111+
109112
final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 6);
110113
final NetworkStats.Entry entry = new NetworkStats.Entry();
111114

@@ -156,6 +159,7 @@ private NetworkStats readNetworkStatsSummarySingleFile() {
156159
throw new IllegalStateException("problem parsing stats: " + e);
157160
} finally {
158161
IoUtils.closeQuietly(reader);
162+
StrictMode.setThreadPolicy(savedPolicy);
159163
}
160164
return stats;
161165
}
@@ -165,6 +169,8 @@ private NetworkStats readNetworkStatsSummarySingleFile() {
165169
*/
166170
@Deprecated
167171
private NetworkStats readNetworkStatsSummaryMultipleFiles() {
172+
final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
173+
168174
final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 6);
169175
final NetworkStats.Entry entry = new NetworkStats.Entry();
170176

@@ -241,6 +247,7 @@ private NetworkStats readNetworkStatsSummaryMultipleFiles() {
241247
throw new IllegalStateException("problem parsing stats: " + e);
242248
} finally {
243249
IoUtils.closeQuietly(reader);
250+
StrictMode.setThreadPolicy(savedPolicy);
244251
}
245252

246253
return stats;
@@ -257,6 +264,8 @@ public NetworkStats readNetworkStatsDetail() {
257264
* @throws IllegalStateException when problem parsing stats.
258265
*/
259266
public NetworkStats readNetworkStatsDetail(int limitUid) throws IllegalStateException {
267+
final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
268+
260269
final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 24);
261270
final NetworkStats.Entry entry = new NetworkStats.Entry();
262271

@@ -300,6 +309,7 @@ public NetworkStats readNetworkStatsDetail(int limitUid) throws IllegalStateExce
300309
throw new IllegalStateException("problem parsing idx " + idx, e);
301310
} finally {
302311
IoUtils.closeQuietly(reader);
312+
StrictMode.setThreadPolicy(savedPolicy);
303313
}
304314

305315
return stats;

0 commit comments

Comments
 (0)