NotificationService.java

  1package eu.siacs.conversations.services;
  2
  3import android.app.Notification;
  4import android.app.NotificationManager;
  5import android.app.PendingIntent;
  6import android.content.Context;
  7import android.content.Intent;
  8import android.content.SharedPreferences;
  9import android.graphics.Bitmap;
 10import android.net.Uri;
 11import android.os.Build;
 12import android.os.SystemClock;
 13import android.support.v4.app.NotificationCompat;
 14import android.support.v4.app.NotificationCompat.BigPictureStyle;
 15import android.support.v4.app.NotificationCompat.Builder;
 16import android.support.v4.app.TaskStackBuilder;
 17import android.text.Html;
 18import android.util.DisplayMetrics;
 19
 20import org.json.JSONArray;
 21import org.json.JSONObject;
 22
 23import java.io.FileNotFoundException;
 24import java.util.ArrayList;
 25import java.util.Calendar;
 26import java.util.HashMap;
 27import java.util.LinkedHashMap;
 28import java.util.List;
 29import java.util.regex.Matcher;
 30import java.util.regex.Pattern;
 31
 32import eu.siacs.conversations.Config;
 33import eu.siacs.conversations.R;
 34import eu.siacs.conversations.entities.Account;
 35import eu.siacs.conversations.entities.Conversation;
 36import eu.siacs.conversations.entities.Message;
 37import eu.siacs.conversations.ui.ConversationActivity;
 38import eu.siacs.conversations.ui.ManageAccountActivity;
 39import eu.siacs.conversations.ui.TimePreference;
 40import eu.siacs.conversations.utils.GeoHelper;
 41import eu.siacs.conversations.utils.UIHelper;
 42
 43public class NotificationService {
 44
 45	private final XmppConnectionService mXmppConnectionService;
 46
 47	private final LinkedHashMap<String, ArrayList<Message>> notifications = new LinkedHashMap<>();
 48
 49	public static final int NOTIFICATION_ID = 0x2342;
 50	public static final int FOREGROUND_NOTIFICATION_ID = 0x8899;
 51	public static final int ERROR_NOTIFICATION_ID = 0x5678;
 52
 53	private Conversation mOpenConversation;
 54	private boolean mIsInForeground;
 55	private long mLastNotification;
 56
 57	public NotificationService(final XmppConnectionService service) {
 58		this.mXmppConnectionService = service;
 59	}
 60
 61	public boolean notify(final Message message) {
 62		return (message.getStatus() == Message.STATUS_RECEIVED)
 63				&& notificationsEnabled()
 64				&& !message.getConversation().isMuted()
 65				&& (message.getConversation().isPnNA()
 66				|| conferenceNotificationsEnabled()
 67				|| wasHighlightedOrPrivate(message)
 68		);
 69	}
 70
 71	public void notifyPebble(final Message message) {
 72		final Intent i = new Intent("com.getpebble.action.SEND_NOTIFICATION");
 73
 74		final Conversation conversation = message.getConversation();
 75		final JSONObject jsonData = new JSONObject(new HashMap<String, String>(2) {{
 76			put("title", conversation.getName());
 77			put("body", message.getBody());
 78		}});
 79		final String notificationData = new JSONArray().put(jsonData).toString();
 80
 81		i.putExtra("messageType", "PEBBLE_ALERT");
 82		i.putExtra("sender", "Conversations"); /* XXX: Shouldn't be hardcoded, e.g., AbstractGenerator.APP_NAME); */
 83		i.putExtra("notificationData", notificationData);
 84		// notify Pebble App
 85		i.setPackage("com.getpebble.android");
 86		mXmppConnectionService.sendBroadcast(i);
 87		// notify Gadgetbridge
 88		i.setPackage("nodomain.freeyourgadget.gadgetbridge");
 89		mXmppConnectionService.sendBroadcast(i);
 90	}
 91
 92
 93	public boolean notificationsEnabled() {
 94		return mXmppConnectionService.getPreferences().getBoolean("show_notification", true);
 95	}
 96
 97	public boolean isQuietHours() {
 98		if (!mXmppConnectionService.getPreferences().getBoolean("enable_quiet_hours", false)) {
 99			return false;
100		}
101		final long startTime = mXmppConnectionService.getPreferences().getLong("quiet_hours_start", TimePreference.DEFAULT_VALUE) % Config.MILLISECONDS_IN_DAY;
102		final long endTime = mXmppConnectionService.getPreferences().getLong("quiet_hours_end", TimePreference.DEFAULT_VALUE) % Config.MILLISECONDS_IN_DAY;
103		final long nowTime = Calendar.getInstance().getTimeInMillis() % Config.MILLISECONDS_IN_DAY;
104
105		if (endTime < startTime) {
106			return nowTime > startTime || nowTime < endTime;
107		} else {
108			return nowTime > startTime && nowTime < endTime;
109		}
110	}
111
112	public boolean conferenceNotificationsEnabled() {
113		return mXmppConnectionService.getPreferences().getBoolean("always_notify_in_conference", false);
114	}
115
116	public void pushFromBacklog(final Message message) {
117		if (notify(message)) {
118			pushToStack(message);
119		}
120	}
121
122	public void finishBacklog(boolean notify) {
123		synchronized (notifications) {
124			mXmppConnectionService.updateUnreadCountBadge();
125			updateNotification(notify);
126		}
127	}
128
129	private void pushToStack(final Message message) {
130		final String conversationUuid = message.getConversationUuid();
131		if (notifications.containsKey(conversationUuid)) {
132			notifications.get(conversationUuid).add(message);
133		} else {
134			final ArrayList<Message> mList = new ArrayList<>();
135			mList.add(message);
136			notifications.put(conversationUuid, mList);
137		}
138	}
139
140	public void push(final Message message) {
141		mXmppConnectionService.updateUnreadCountBadge();
142		if (!notify(message)) {
143			return;
144		}
145		final boolean isScreenOn = mXmppConnectionService.isInteractive();
146		if (this.mIsInForeground && isScreenOn && this.mOpenConversation == message.getConversation()) {
147			return;
148		}
149		synchronized (notifications) {
150			pushToStack(message);
151			final Account account = message.getConversation().getAccount();
152			final boolean doNotify = (!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn)
153					&& !account.inGracePeriod()
154					&& !this.inMiniGracePeriod(account);
155			updateNotification(doNotify);
156			if (doNotify) {
157				notifyPebble(message);
158			}
159		}
160	}
161
162	public void clear() {
163		synchronized (notifications) {
164			notifications.clear();
165			updateNotification(false);
166		}
167	}
168
169	public void clear(final Conversation conversation) {
170		synchronized (notifications) {
171			notifications.remove(conversation.getUuid());
172			updateNotification(false);
173		}
174	}
175
176	private void setNotificationColor(final Builder mBuilder) {
177		mBuilder.setColor(mXmppConnectionService.getResources().getColor(R.color.primary));
178	}
179
180	public void updateNotification(final boolean notify) {
181		final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService
182				.getSystemService(Context.NOTIFICATION_SERVICE);
183		final SharedPreferences preferences = mXmppConnectionService.getPreferences();
184
185		final String ringtone = preferences.getString("notification_ringtone", null);
186		final boolean vibrate = preferences.getBoolean("vibrate_on_notification", true);
187
188		if (notifications.size() == 0) {
189			notificationManager.cancel(NOTIFICATION_ID);
190		} else {
191			if (notify) {
192				this.markLastNotification();
193			}
194			final Builder mBuilder;
195			if (notifications.size() == 1) {
196				mBuilder = buildSingleConversations(notify);
197			} else {
198				mBuilder = buildMultipleConversation();
199			}
200			if (notify && !isQuietHours()) {
201				if (vibrate) {
202					final int dat = 70;
203					final long[] pattern = {0, 3 * dat, dat, dat};
204					mBuilder.setVibrate(pattern);
205				}
206				if (ringtone != null) {
207					mBuilder.setSound(Uri.parse(ringtone));
208				}
209			}
210			if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
211				mBuilder.setCategory(Notification.CATEGORY_MESSAGE);
212			}
213			setNotificationColor(mBuilder);
214			mBuilder.setDefaults(0);
215			mBuilder.setSmallIcon(R.drawable.ic_notification);
216			mBuilder.setDeleteIntent(createDeleteIntent());
217			mBuilder.setLights(0xff00FF00, 2000, 3000);
218			final Notification notification = mBuilder.build();
219			notificationManager.notify(NOTIFICATION_ID, notification);
220		}
221	}
222
223	private Builder buildMultipleConversation() {
224		final Builder mBuilder = new NotificationCompat.Builder(
225				mXmppConnectionService);
226		final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
227		style.setBigContentTitle(notifications.size()
228				+ " "
229				+ mXmppConnectionService
230				.getString(R.string.unread_conversations));
231		final StringBuilder names = new StringBuilder();
232		Conversation conversation = null;
233		for (final ArrayList<Message> messages : notifications.values()) {
234			if (messages.size() > 0) {
235				conversation = messages.get(0).getConversation();
236				final String name = conversation.getName();
237				if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
238					int count = messages.size();
239					style.addLine(Html.fromHtml("<b>"+name+"</b> "+mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages,count,count)));
240				} else {
241					style.addLine(Html.fromHtml("<b>" + name + "</b> "
242							+ UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first));
243				}
244				names.append(name);
245				names.append(", ");
246			}
247		}
248		if (names.length() >= 2) {
249			names.delete(names.length() - 2, names.length());
250		}
251		mBuilder.setContentTitle(notifications.size()
252				+ " "
253				+ mXmppConnectionService
254				.getString(R.string.unread_conversations));
255		mBuilder.setContentText(names.toString());
256		mBuilder.setStyle(style);
257		if (conversation != null) {
258			mBuilder.setContentIntent(createContentIntent(conversation));
259		}
260		return mBuilder;
261	}
262
263	private Builder buildSingleConversations(final boolean notify) {
264		final Builder mBuilder = new NotificationCompat.Builder(
265				mXmppConnectionService);
266		final ArrayList<Message> messages = notifications.values().iterator().next();
267		if (messages.size() >= 1) {
268			final Conversation conversation = messages.get(0).getConversation();
269			mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService()
270					.get(conversation, getPixel(64)));
271			mBuilder.setContentTitle(conversation.getName());
272			if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
273				int count = messages.size();
274				mBuilder.setContentText(mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages,count,count));
275			} else {
276				Message message;
277				if ((message = getImage(messages)) != null) {
278					modifyForImage(mBuilder, message, messages, notify);
279				} else if (conversation.getMode() == Conversation.MODE_MULTI) {
280					modifyForConference(mBuilder, conversation, messages, notify);
281				} else {
282					modifyForTextOnly(mBuilder, messages, notify);
283				}
284				if ((message = getFirstDownloadableMessage(messages)) != null) {
285					mBuilder.addAction(
286							Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
287									R.drawable.ic_file_download_white_24dp : R.drawable.ic_action_download,
288							mXmppConnectionService.getResources().getString(R.string.download_x_file,
289									UIHelper.getFileDescriptionString(mXmppConnectionService, message)),
290							createDownloadIntent(message)
291					);
292				}
293				if ((message = getFirstLocationMessage(messages)) != null) {
294					mBuilder.addAction(R.drawable.ic_room_white_24dp,
295							mXmppConnectionService.getString(R.string.show_location),
296							createShowLocationIntent(message));
297				}
298			}
299			mBuilder.setContentIntent(createContentIntent(conversation));
300		}
301		return mBuilder;
302	}
303
304	private void modifyForImage(final Builder builder, final Message message,
305								final ArrayList<Message> messages, final boolean notify) {
306		try {
307			final Bitmap bitmap = mXmppConnectionService.getFileBackend()
308					.getThumbnail(message, getPixel(288), false);
309			final ArrayList<Message> tmp = new ArrayList<>();
310			for (final Message msg : messages) {
311				if (msg.getType() == Message.TYPE_TEXT
312						&& msg.getTransferable() == null) {
313					tmp.add(msg);
314				}
315			}
316			final BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
317			bigPictureStyle.bigPicture(bitmap);
318			if (tmp.size() > 0) {
319				bigPictureStyle.setSummaryText(getMergedBodies(tmp));
320				builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService, tmp.get(0)).first);
321			} else {
322				builder.setContentText(mXmppConnectionService.getString(
323						R.string.received_x_file,
324						UIHelper.getFileDescriptionString(mXmppConnectionService, message)));
325			}
326			builder.setStyle(bigPictureStyle);
327		} catch (final FileNotFoundException e) {
328			modifyForTextOnly(builder, messages, notify);
329		}
330	}
331
332	private void modifyForTextOnly(final Builder builder,
333								   final ArrayList<Message> messages, final boolean notify) {
334		builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getMergedBodies(messages)));
335		builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first);
336		if (notify) {
337			builder.setTicker(UIHelper.getMessagePreview(mXmppConnectionService, messages.get(messages.size() - 1)).first);
338		}
339	}
340
341	private void modifyForConference(Builder builder, Conversation conversation, List<Message> messages, boolean notify) {
342		final Message first = messages.get(0);
343		final Message last = messages.get(messages.size() - 1);
344		final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
345		style.setBigContentTitle(conversation.getName());
346		for(Message message : messages) {
347			style.addLine(Html.fromHtml("<b>"+UIHelper.getMessageDisplayName(message)+"</b> "+UIHelper.getMessagePreview(mXmppConnectionService,message).first));
348		}
349		builder.setContentText(UIHelper.getMessageDisplayName(first)+ ": " +UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first);
350		builder.setStyle(style);
351		if (notify) {
352			builder.setTicker(UIHelper.getMessageDisplayName(last) + ": " + UIHelper.getMessagePreview(mXmppConnectionService,last).first);
353		}
354	}
355
356	private Message getImage(final Iterable<Message> messages) {
357		for (final Message message : messages) {
358			if (message.getType() != Message.TYPE_TEXT
359					&& message.getTransferable() == null
360					&& message.getEncryption() != Message.ENCRYPTION_PGP
361					&& message.getFileParams().height > 0) {
362				return message;
363			}
364		}
365		return null;
366	}
367
368	private Message getFirstDownloadableMessage(final Iterable<Message> messages) {
369		for (final Message message : messages) {
370			if ((message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) &&
371					message.getTransferable() != null) {
372				return message;
373			}
374		}
375		return null;
376	}
377
378	private Message getFirstLocationMessage(final Iterable<Message> messages) {
379		for (final Message message : messages) {
380			if (GeoHelper.isGeoUri(message.getBody())) {
381				return message;
382			}
383		}
384		return null;
385	}
386
387	private CharSequence getMergedBodies(final ArrayList<Message> messages) {
388		final StringBuilder text = new StringBuilder();
389		for (int i = 0; i < messages.size(); ++i) {
390			text.append(UIHelper.getMessagePreview(mXmppConnectionService, messages.get(i)).first);
391			if (i != messages.size() - 1) {
392				text.append("\n");
393			}
394		}
395		return text.toString();
396	}
397
398	private PendingIntent createShowLocationIntent(final Message message) {
399		Iterable<Intent> intents = GeoHelper.createGeoIntentsFromMessage(message);
400		for (Intent intent : intents) {
401			if (intent.resolveActivity(mXmppConnectionService.getPackageManager()) != null) {
402				return PendingIntent.getActivity(mXmppConnectionService, 18, intent, PendingIntent.FLAG_UPDATE_CURRENT);
403			}
404		}
405		return createOpenConversationsIntent();
406	}
407
408	private PendingIntent createContentIntent(final String conversationUuid, final String downloadMessageUuid) {
409		final TaskStackBuilder stackBuilder = TaskStackBuilder
410				.create(mXmppConnectionService);
411		stackBuilder.addParentStack(ConversationActivity.class);
412
413		final Intent viewConversationIntent = new Intent(mXmppConnectionService,
414				ConversationActivity.class);
415		if (downloadMessageUuid != null) {
416			viewConversationIntent.setAction(ConversationActivity.ACTION_DOWNLOAD);
417		} else {
418			viewConversationIntent.setAction(Intent.ACTION_VIEW);
419		}
420		if (conversationUuid != null) {
421			viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversationUuid);
422			viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
423		}
424		if (downloadMessageUuid != null) {
425			viewConversationIntent.putExtra(ConversationActivity.MESSAGE, downloadMessageUuid);
426		}
427
428		stackBuilder.addNextIntent(viewConversationIntent);
429
430		return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
431	}
432
433	private PendingIntent createDownloadIntent(final Message message) {
434		return createContentIntent(message.getConversationUuid(), message.getUuid());
435	}
436
437	private PendingIntent createContentIntent(final Conversation conversation) {
438		return createContentIntent(conversation.getUuid(), null);
439	}
440
441	private PendingIntent createDeleteIntent() {
442		final Intent intent = new Intent(mXmppConnectionService,
443				XmppConnectionService.class);
444		intent.setAction(XmppConnectionService.ACTION_CLEAR_NOTIFICATION);
445		return PendingIntent.getService(mXmppConnectionService, 0, intent, 0);
446	}
447
448	private PendingIntent createDisableForeground() {
449		final Intent intent = new Intent(mXmppConnectionService,
450				XmppConnectionService.class);
451		intent.setAction(XmppConnectionService.ACTION_DISABLE_FOREGROUND);
452		return PendingIntent.getService(mXmppConnectionService, 34, intent, 0);
453	}
454
455	private PendingIntent createTryAgainIntent() {
456		final Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class);
457		intent.setAction(XmppConnectionService.ACTION_TRY_AGAIN);
458		return PendingIntent.getService(mXmppConnectionService, 45, intent, 0);
459	}
460
461	private PendingIntent createDisableAccountIntent(final Account account) {
462		final Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class);
463		intent.setAction(XmppConnectionService.ACTION_DISABLE_ACCOUNT);
464		intent.putExtra("account", account.getJid().toBareJid().toString());
465		return PendingIntent.getService(mXmppConnectionService, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
466	}
467
468	private boolean wasHighlightedOrPrivate(final Message message) {
469		final String nick = message.getConversation().getMucOptions().getActualNick();
470		final Pattern highlight = generateNickHighlightPattern(nick);
471		if (message.getBody() == null || nick == null) {
472			return false;
473		}
474		final Matcher m = highlight.matcher(message.getBody());
475		return (m.find() || message.getType() == Message.TYPE_PRIVATE);
476	}
477
478	private static Pattern generateNickHighlightPattern(final String nick) {
479		// We expect a word boundary, i.e. space or start of string, followed by
480		// the
481		// nick (matched in case-insensitive manner), followed by optional
482		// punctuation (for example "bob: i disagree" or "how are you alice?"),
483		// followed by another word boundary.
484		return Pattern.compile("\\b" + Pattern.quote(nick) + "\\p{Punct}?\\b",
485				Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
486	}
487
488	public void setOpenConversation(final Conversation conversation) {
489		this.mOpenConversation = conversation;
490	}
491
492	public void setIsInForeground(final boolean foreground) {
493		this.mIsInForeground = foreground;
494	}
495
496	private int getPixel(final int dp) {
497		final DisplayMetrics metrics = mXmppConnectionService.getResources()
498				.getDisplayMetrics();
499		return ((int) (dp * metrics.density));
500	}
501
502	private void markLastNotification() {
503		this.mLastNotification = SystemClock.elapsedRealtime();
504	}
505
506	private boolean inMiniGracePeriod(final Account account) {
507		final int miniGrace = account.getStatus() == Account.State.ONLINE ? Config.MINI_GRACE_PERIOD
508				: Config.MINI_GRACE_PERIOD * 2;
509		return SystemClock.elapsedRealtime() < (this.mLastNotification + miniGrace);
510	}
511
512	public Notification createForegroundNotification() {
513		final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
514
515		mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.conversations_foreground_service));
516		if (Config.SHOW_CONNECTED_ACCOUNTS) {
517			List<Account> accounts = mXmppConnectionService.getAccounts();
518			int enabled = 0;
519			int connected = 0;
520			for (Account account : accounts) {
521				if (account.isOnlineAndConnected()) {
522					connected++;
523					enabled++;
524				} else if (!account.isOptionSet(Account.OPTION_DISABLED)) {
525					enabled++;
526				}
527			}
528			mBuilder.setContentText(mXmppConnectionService.getString(R.string.connected_accounts, connected, enabled));
529		} else {
530			mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_open_conversations));
531		}
532		mBuilder.setContentIntent(createOpenConversationsIntent());
533		mBuilder.setWhen(0);
534		mBuilder.setPriority(Config.SHOW_CONNECTED_ACCOUNTS ? NotificationCompat.PRIORITY_DEFAULT : NotificationCompat.PRIORITY_MIN);
535		final int cancelIcon;
536		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
537			mBuilder.setCategory(Notification.CATEGORY_SERVICE);
538			cancelIcon = R.drawable.ic_cancel_white_24dp;
539		} else {
540			cancelIcon = R.drawable.ic_action_cancel;
541		}
542		mBuilder.setSmallIcon(R.drawable.ic_link_white_24dp);
543		mBuilder.addAction(cancelIcon,
544				mXmppConnectionService.getString(R.string.disable_foreground_service),
545				createDisableForeground());
546		return mBuilder.build();
547	}
548
549	private PendingIntent createOpenConversationsIntent() {
550		return PendingIntent.getActivity(mXmppConnectionService, 0, new Intent(mXmppConnectionService, ConversationActivity.class), 0);
551	}
552
553	public void updateErrorNotification() {
554		final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService.getSystemService(Context.NOTIFICATION_SERVICE);
555		final List<Account> errors = new ArrayList<>();
556		for (final Account account : mXmppConnectionService.getAccounts()) {
557			if (account.hasErrorStatus()) {
558				errors.add(account);
559			}
560		}
561		if (mXmppConnectionService.getPreferences().getBoolean("keep_foreground_service", false)) {
562			notificationManager.notify(FOREGROUND_NOTIFICATION_ID, createForegroundNotification());
563		}
564		final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
565		if (errors.size() == 0) {
566			notificationManager.cancel(ERROR_NOTIFICATION_ID);
567			return;
568		} else if (errors.size() == 1) {
569			mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_account));
570			mBuilder.setContentText(errors.get(0).getJid().toBareJid().toString());
571		} else {
572			mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_accounts));
573			mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_fix));
574		}
575		mBuilder.addAction(R.drawable.ic_autorenew_white_24dp,
576				mXmppConnectionService.getString(R.string.try_again),
577				createTryAgainIntent());
578		if (errors.size() == 1) {
579			mBuilder.addAction(R.drawable.ic_block_white_24dp,
580					mXmppConnectionService.getString(R.string.disable_account),
581					createDisableAccountIntent(errors.get(0)));
582		}
583		mBuilder.setOngoing(true);
584		//mBuilder.setLights(0xffffffff, 2000, 4000);
585		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
586			mBuilder.setSmallIcon(R.drawable.ic_warning_white_24dp);
587		} else {
588			mBuilder.setSmallIcon(R.drawable.ic_stat_alert_warning);
589		}
590		final TaskStackBuilder stackBuilder = TaskStackBuilder.create(mXmppConnectionService);
591		stackBuilder.addParentStack(ConversationActivity.class);
592
593		final Intent manageAccountsIntent = new Intent(mXmppConnectionService, ManageAccountActivity.class);
594		stackBuilder.addNextIntent(manageAccountsIntent);
595
596		final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
597
598		mBuilder.setContentIntent(resultPendingIntent);
599		notificationManager.notify(ERROR_NOTIFICATION_ID, mBuilder.build());
600	}
601}