am 9a07c990: Merge "Cherry-pick "Fix VPN notification helper" from master." into honeycomb

* commit '9a07c990d305243d1b9b8557fea96f273c46dc0f':
  Cherry-pick "Fix VPN notification helper" from master.
This commit is contained in:
Hung-ying Tyan
2011-01-18 22:41:18 -08:00
committed by Android Git Automerger

View File

@@ -328,6 +328,7 @@ abstract class VpnService<E extends VpnProfile> implements Serializable {
public void run() { public void run() {
Log.i(TAG, "VPN connectivity monitor running"); Log.i(TAG, "VPN connectivity monitor running");
try { try {
mNotification.update(mStartTime); // to pop up notification
for (int i = 10; ; i--) { for (int i = 10; ; i--) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
@@ -417,13 +418,27 @@ abstract class VpnService<E extends VpnProfile> implements Serializable {
// Helper class for showing, updating notification. // Helper class for showing, updating notification.
private class NotificationHelper { private class NotificationHelper {
private NotificationManager mNotificationManager = (NotificationManager)
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
private Notification mNotification =
new Notification(R.drawable.vpn_connected, null, 0L);
private PendingIntent mPendingIntent = PendingIntent.getActivity(
mContext, 0,
new VpnManager(mContext).createSettingsActivityIntent(), 0);
private String mConnectedTitle;
void update(long now) { void update(long now) {
String title = getNotificationTitle(true); Notification n = mNotification;
Notification n = new Notification(R.drawable.vpn_connected, title, if (now == mStartTime) {
mStartTime); // to pop up the notification for the first time
n.setLatestEventInfo(mContext, title, n.when = mStartTime;
n.tickerText = mConnectedTitle = getNotificationTitle(true);
} else {
n.tickerText = null;
}
n.setLatestEventInfo(mContext, mConnectedTitle,
getConnectedNotificationMessage(now), getConnectedNotificationMessage(now),
prepareNotificationIntent()); mPendingIntent);
n.flags |= Notification.FLAG_NO_CLEAR; n.flags |= Notification.FLAG_NO_CLEAR;
n.flags |= Notification.FLAG_ONGOING_EVENT; n.flags |= Notification.FLAG_ONGOING_EVENT;
enableNotification(n); enableNotification(n);
@@ -435,25 +450,18 @@ abstract class VpnService<E extends VpnProfile> implements Serializable {
title, System.currentTimeMillis()); title, System.currentTimeMillis());
n.setLatestEventInfo(mContext, title, n.setLatestEventInfo(mContext, title,
getDisconnectedNotificationMessage(), getDisconnectedNotificationMessage(),
prepareNotificationIntent()); mPendingIntent);
n.flags |= Notification.FLAG_AUTO_CANCEL; n.flags |= Notification.FLAG_AUTO_CANCEL;
disableNotification(); disableNotification();
enableNotification(n); enableNotification(n);
} }
void disableNotification() { void disableNotification() {
((NotificationManager) mContext.getSystemService( mNotificationManager.cancel(NOTIFICATION_ID);
Context.NOTIFICATION_SERVICE)).cancel(NOTIFICATION_ID);
} }
private void enableNotification(Notification n) { private void enableNotification(Notification n) {
((NotificationManager) mContext.getSystemService( mNotificationManager.notify(NOTIFICATION_ID, n);
Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, n);
}
private PendingIntent prepareNotificationIntent() {
return PendingIntent.getActivity(mContext, 0,
new VpnManager(mContext).createSettingsActivityIntent(), 0);
} }
private String getNotificationTitle(boolean connected) { private String getNotificationTitle(boolean connected) {