Merge "VPN: refactor a little bit for the upcoming integration of legacy VPN."
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 88ed9c6b..afae5e3 100755
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -2788,10 +2788,10 @@
     <string name="l2tp_ipsec_psk_vpn_description">Pre-shared key based L2TP/IPSec VPN</string>
     <string name="l2tp_ipsec_crt_vpn_description">Certificate based L2TP/IPSec VPN</string>
 
-    <!-- Ticker text to show when VPN is active. -->
-    <string name="vpn_ticker"><xliff:g id="app" example="FooVPN client">%s</xliff:g> is activating VPN...</string>
     <!-- The title of the notification when VPN is active. -->
-    <string name="vpn_title">VPN is activated by <xliff:g id="app" example="FooVPN client">%s</xliff:g></string>
+    <string name="vpn_title">VPN is activated.</string>
+    <!-- The title of the notification when VPN is active with an application name. -->
+    <string name="vpn_title_long">VPN is activated by <xliff:g id="app" example="FooVPN client">%s</xliff:g></string>
     <!-- The text of the notification when VPN is active. -->
     <string name="vpn_text">Tap to manage the network.</string>
     <!-- The text of the notification when VPN is active with a session name. -->
diff --git a/services/java/com/android/server/connectivity/Vpn.java b/services/java/com/android/server/connectivity/Vpn.java
index 54bddb2..0a54fa4 100644
--- a/services/java/com/android/server/connectivity/Vpn.java
+++ b/services/java/com/android/server/connectivity/Vpn.java
@@ -40,7 +40,6 @@
 import com.android.internal.net.VpnConfig;
 import com.android.server.ConnectivityService.VpnCallback;
 
-import java.io.InputStream;
 import java.io.OutputStream;
 import java.nio.charset.Charsets;
 
@@ -132,7 +131,7 @@
     /**
      * Configure a TUN interface and return its file descriptor.
      *
-     * @param configuration The parameters to configure the interface.
+     * @param config The parameters to configure the interface.
      * @return The file descriptor of the interface.
      */
     public synchronized ParcelFileDescriptor establish(VpnConfig config) {
@@ -151,11 +150,25 @@
             return null;
         }
 
-        // Create and configure the interface.
+        // Load the label.
+        String label = app.loadLabel(pm).toString();
+
+        // Load the icon and convert it into a bitmap.
+        Drawable icon = app.loadIcon(pm);
+        Bitmap bitmap = null;
+        if (icon.getIntrinsicWidth() > 0 && icon.getIntrinsicHeight() > 0) {
+            int width = mContext.getResources().getDimensionPixelSize(
+                    android.R.dimen.notification_large_icon_width);
+            int height = mContext.getResources().getDimensionPixelSize(
+                    android.R.dimen.notification_large_icon_height);
+            icon.setBounds(0, 0, width, height);
+            bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+            icon.draw(new Canvas(bitmap));
+        }
+
+        // Create the interface and abort if any of the following steps fails.
         ParcelFileDescriptor descriptor =
                 ParcelFileDescriptor.adoptFd(jniCreateInterface(config.mtu));
-
-        // Abort if any of the following steps fails.
         try {
             String name = jniGetInterfaceName(descriptor.getFd());
             if (jniSetAddresses(name, config.addresses) < 1) {
@@ -202,41 +215,26 @@
     public synchronized void interfaceRemoved(String name) {
         if (name.equals(mInterfaceName) && jniCheckInterface(name) == 0) {
             hideNotification();
-            mInterfaceName = null;
             mCallback.restore();
+            mInterfaceName = null;
         }
     }
 
-    private void showNotification(PackageManager pm, ApplicationInfo app, VpnConfig config) {
+    private void showNotification(VpnConfig config, String label, Bitmap icon) {
         NotificationManager nm = (NotificationManager)
                 mContext.getSystemService(Context.NOTIFICATION_SERVICE);
 
         if (nm != null) {
-            // Load the icon and convert it into a bitmap.
-            Drawable icon = app.loadIcon(pm);
-            Bitmap bitmap = null;
-            if (icon.getIntrinsicWidth() > 0 && icon.getIntrinsicHeight() > 0) {
-                int width = mContext.getResources().getDimensionPixelSize(
-                        android.R.dimen.notification_large_icon_width);
-                int height = mContext.getResources().getDimensionPixelSize(
-                        android.R.dimen.notification_large_icon_height);
-                icon.setBounds(0, 0, width, height);
-                bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
-                icon.draw(new Canvas(bitmap));
-            }
-
-            // Load the label.
-            String label = app.loadLabel(pm).toString();
-
-            // Build the notification.
+            String title = (label == null) ? mContext.getString(R.string.vpn_title) :
+                    mContext.getString(R.string.vpn_title_long, label);
             String text = (config.sessionName == null) ? mContext.getString(R.string.vpn_text) :
                     mContext.getString(R.string.vpn_text_long, config.sessionName);
+
             long identity = Binder.clearCallingIdentity();
             Notification notification = new Notification.Builder(mContext)
                     .setSmallIcon(R.drawable.vpn_connected)
-                    .setLargeIcon(bitmap)
-                    .setTicker(mContext.getString(R.string.vpn_ticker, label))
-                    .setContentTitle(mContext.getString(R.string.vpn_title, label))
+                    .setLargeIcon(icon)
+                    .setContentTitle(title)
                     .setContentText(text)
                     .setContentIntent(VpnConfig.getIntentForNotification(mContext, config))
                     .setDefaults(Notification.DEFAULT_ALL)