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