Add synchronized to UidRange getter and dump methods
- The UidRange getter and dump methods which is to access
mVpnInterfaceUidRanges and mVpnLockdownUidRanges need to guard
with synchronized to ensure the value won't be changed during
accessing.
- Also make getVpnLockdownUidRanges() to be a package-private
method. It's accessed from PermissionMonitorTest only.
Bug: 232048835
Test: FrameworksNetTests CtsNetTestCases
Change-Id: I850f155a01c309f9d75f5143dc0a46a1505415bd
diff --git a/service/src/com/android/server/connectivity/PermissionMonitor.java b/service/src/com/android/server/connectivity/PermissionMonitor.java
index 9f1613f..ff979d8 100755
--- a/service/src/com/android/server/connectivity/PermissionMonitor.java
+++ b/service/src/com/android/server/connectivity/PermissionMonitor.java
@@ -1213,13 +1213,13 @@
/** Should only be used by unit tests */
@VisibleForTesting
- public Set<UidRange> getVpnInterfaceUidRanges(String iface) {
+ public synchronized Set<UidRange> getVpnInterfaceUidRanges(String iface) {
return mVpnInterfaceUidRanges.get(iface);
}
/** Should only be used by unit tests */
@VisibleForTesting
- public Set<UidRange> getVpnLockdownUidRanges() {
+ synchronized Set<UidRange> getVpnLockdownUidRanges() {
return mVpnLockdownUidRanges.getSet();
}
@@ -1295,8 +1295,10 @@
pw.println();
pw.println("Lockdown filtering rules:");
pw.increaseIndent();
- for (final UidRange range : mVpnLockdownUidRanges.getSet()) {
- pw.println("UIDs: " + range);
+ synchronized (this) {
+ for (final UidRange range : mVpnLockdownUidRanges.getSet()) {
+ pw.println("UIDs: " + range);
+ }
}
pw.decreaseIndent();