diff options
| author | 2011-06-30 23:27:53 -0700 | |
|---|---|---|
| committer | 2011-06-30 23:27:53 -0700 | |
| commit | 2e46061cd2ff93e04461fdae4198c1d40d660e08 (patch) | |
| tree | 85c048839744cf7f32ec19fcf559b8361cd7f2e2 | |
| parent | 072d39e079aad0a92c9f9ada91968e955f2c3bd1 (diff) | |
| parent | a4b87b5e980ffa52e9bc5549688b588b1b99a1eb (diff) | |
Merge "VPN: refactor a little bit for the upcoming integration of legacy VPN."
| -rwxr-xr-x | core/res/res/values/strings.xml | 6 | ||||
| -rw-r--r-- | services/java/com/android/server/connectivity/Vpn.java | 52 |
2 files changed, 28 insertions, 30 deletions
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 88ed9c6bc586..afae5e3d8ba5 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 54bddb258aaf..0a54fa427b01 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.R; 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 @@ public class Vpn extends INetworkManagementEventObserver.Stub { /** * 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 @@ public class Vpn extends INetworkManagementEventObserver.Stub { 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 class Vpn extends INetworkManagementEventObserver.Stub { 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) |