Reinstate USER_PRESENT for ConnectivityService

Reverts half of commit 89e7a696f0902f1116f3ccc7eec786aec0c5de97
Reverts parts of commit 9a5f48535d5d2972308c06d81fd55adf7e44dc49

Lockdown VPN still needs this to start properly on devices without FBE,
such as phones upgraded from M. Without listening to USER_PRESENT the
first unlock of keystore may get missed, since USER_UNLOCKED is sent too
soon to be useful.

Bug: 34587043
Change-Id: If7a2f5a3173b0f6856244a5f7904bf00c9a5b5e7
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 803c2db..0c798ec 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -815,6 +815,8 @@
         intentFilter.addAction(Intent.ACTION_USER_UNLOCKED);
         mContext.registerReceiverAsUser(
                 mUserIntentReceiver, UserHandle.ALL, intentFilter, null, null);
+        mContext.registerReceiverAsUser(mUserPresentReceiver, UserHandle.SYSTEM,
+                new IntentFilter(Intent.ACTION_USER_PRESENT), null, null);
 
         try {
             mNetd.registerObserver(mTethering);
@@ -4000,6 +4002,16 @@
         }
     };
 
+    private BroadcastReceiver mUserPresentReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // Try creating lockdown tracker, since user present usually means
+            // unlocked keystore.
+            updateLockdownVpn();
+            mContext.unregisterReceiver(this);
+        }
+    };
+
     private final HashMap<Messenger, NetworkFactoryInfo> mNetworkFactoryInfos =
             new HashMap<Messenger, NetworkFactoryInfo>();
     private final HashMap<NetworkRequest, NetworkRequestInfo> mNetworkRequests =