Start VPN as early as possible during startup

- Switch from USER_STARTING to USER_STARTED which is the foreground
  version of the broadcast

- Set the new VPN network as CONNECTING initially to avoid spamming
  apps with useless notifications ahead of the network being fully
  available

Bug: 26694104
Fix: 28335277
Change-Id: I31d5260dda62ff440c31c44eb0aa5c891e2717e5
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
index a111bf9..6c1e1a7 100644
--- a/services/core/java/com/android/server/connectivity/Vpn.java
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -449,8 +449,7 @@
             mNetworkCapabilities.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
         }
 
-        mNetworkInfo.setIsAvailable(true);
-        mNetworkInfo.setDetailedState(DetailedState.CONNECTED, null, null);
+        mNetworkInfo.setDetailedState(DetailedState.CONNECTING, null, null);
 
         NetworkMisc networkMisc = new NetworkMisc();
         networkMisc.allowBypass = mConfig.allowBypass;
@@ -485,6 +484,9 @@
             }
         }
         mNetworkAgent.addUidRanges(mVpnUsers.toArray(new UidRange[mVpnUsers.size()]));
+
+        mNetworkInfo.setIsAvailable(true);
+        updateState(DetailedState.CONNECTED, "agentConnect");
     }
 
     private boolean canHaveRestrictedProfile(int userId) {