Skip to content

Commit 5f42b73

Browse files
lucaslinGenkzsz11
authored andcommitted
Add synchronized to make sure data correctness
Both mNetworkAgent and mConfig are mutable, add synchronized to make sure the data correctness of those two vars when getNetId() and getVpnConfig() are called. Bug: 168576152 Test: atest FrameworkNetTests atest CtsHostsideNetworkTests:HostsideVpnTests Change-Id: I4133de84c904009b5fbf4208853773fc79fdd17f Signed-off-by: DennySPb <dennyspb@gmail.com>
1 parent ba84cac commit 5f42b73

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • services/core/java/com/android/server/connectivity

services/core/java/com/android/server/connectivity/Vpn.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,13 @@ public NetworkInfo getNetworkInfo() {
11301130
return mNetworkInfo;
11311131
}
11321132

1133-
public int getNetId() {
1133+
/**
1134+
* Return netId of current running VPN network.
1135+
*
1136+
* @return a netId if there is a running VPN network or NETID_UNSET if there is no running VPN
1137+
* network or network is null.
1138+
*/
1139+
public synchronized int getNetId() {
11341140
final NetworkAgent agent = mNetworkAgent;
11351141
if (null == agent) return NETID_UNSET;
11361142
final Network network = agent.getNetwork();
@@ -1708,7 +1714,7 @@ private boolean setAllowOnlyVpnForUids(boolean enforce, Collection<UidRange> ran
17081714
/**
17091715
* Return the configuration of the currently running VPN.
17101716
*/
1711-
public VpnConfig getVpnConfig() {
1717+
public synchronized VpnConfig getVpnConfig() {
17121718
enforceControlPermission();
17131719
return mConfig;
17141720
}

0 commit comments

Comments
 (0)