@@ -55,6 +55,7 @@ public class LockdownVpnTracker {
5555 private static final int MAX_ERROR_COUNT = 4 ;
5656
5757 private static final String ACTION_LOCKDOWN_RESET = "com.android.server.action.LOCKDOWN_RESET" ;
58+ private static final String ACTION_VPN_SETTINGS = "android.net.vpn.SETTINGS" ;
5859
5960 private final Context mContext ;
6061 private final INetworkManagementService mNetService ;
@@ -84,9 +85,9 @@ public LockdownVpnTracker(Context context, INetworkManagementService netService,
8485 mVpn = Preconditions .checkNotNull (vpn );
8586 mProfile = Preconditions .checkNotNull (profile );
8687
87- final Intent intent = new Intent (ACTION_LOCKDOWN_RESET );
88- intent .addFlags (Intent .FLAG_RECEIVER_REGISTERED_ONLY );
89- mResetIntent = PendingIntent .getBroadcast (mContext , 0 , intent , 0 );
88+ final Intent resetIntent = new Intent (ACTION_LOCKDOWN_RESET );
89+ resetIntent .addFlags (Intent .FLAG_RECEIVER_REGISTERED_ONLY );
90+ mResetIntent = PendingIntent .getBroadcast (mContext , 0 , resetIntent , 0 );
9091 }
9192
9293 private BroadcastReceiver mResetReceiver = new BroadcastReceiver () {
@@ -115,7 +116,7 @@ private void handleStateChangedLocked() {
115116 final boolean egressChanged = egressProp == null
116117 || !TextUtils .equals (mAcceptedEgressIface , egressProp .getInterfaceName ());
117118 if (egressDisconnected || egressChanged ) {
118- clearSourceRules ();
119+ clearSourceRulesLocked ();
119120 mAcceptedEgressIface = null ;
120121 mVpn .stopLegacyVpn ();
121122 }
@@ -150,7 +151,7 @@ private void handleStateChangedLocked() {
150151 showNotification (R .string .vpn_lockdown_connected , R .drawable .vpn_connected );
151152
152153 try {
153- clearSourceRules ();
154+ clearSourceRulesLocked ();
154155
155156 mNetService .setFirewallInterfaceRule (iface , true );
156157 mNetService .setFirewallEgressSourceRule (sourceAddr , true );
@@ -167,7 +168,13 @@ private void handleStateChangedLocked() {
167168 }
168169
169170 public void init () {
170- Slog .d (TAG , "init()" );
171+ synchronized (mStateLock ) {
172+ initLocked ();
173+ }
174+ }
175+
176+ private void initLocked () {
177+ Slog .d (TAG , "initLocked()" );
171178
172179 mVpn .setEnableNotifications (false );
173180
@@ -188,7 +195,13 @@ public void init() {
188195 }
189196
190197 public void shutdown () {
191- Slog .d (TAG , "shutdown()" );
198+ synchronized (mStateLock ) {
199+ shutdownLocked ();
200+ }
201+ }
202+
203+ private void shutdownLocked () {
204+ Slog .d (TAG , "shutdownLocked()" );
192205
193206 mAcceptedEgressIface = null ;
194207 mErrorCount = 0 ;
@@ -200,23 +213,23 @@ public void shutdown() {
200213 } catch (RemoteException e ) {
201214 throw new RuntimeException ("Problem setting firewall rules" , e );
202215 }
203- clearSourceRules ();
216+ clearSourceRulesLocked ();
204217 hideNotification ();
205218
206219 mContext .unregisterReceiver (mResetReceiver );
207220 mVpn .setEnableNotifications (true );
208221 }
209222
210223 public void reset () {
211- // cycle tracker, reset error count, and trigger retry
212- shutdown ();
213- init ();
214224 synchronized (mStateLock ) {
225+ // cycle tracker, reset error count, and trigger retry
226+ shutdownLocked ();
227+ initLocked ();
215228 handleStateChangedLocked ();
216229 }
217230 }
218231
219- private void clearSourceRules () {
232+ private void clearSourceRulesLocked () {
220233 try {
221234 if (mAcceptedIface != null ) {
222235 mNetService .setFirewallInterfaceRule (mAcceptedIface , false );
0 commit comments