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;
 19import android.util.Log;
 20
 21import org.json.JSONArray;
 22import org.json.JSONObject;
 23
 24import java.io.FileNotFoundException;
 25import java.util.ArrayList;
 26import java.util.Calendar;
 27import java.util.HashMap;
 28import java.util.LinkedHashMap;
 29import java.util.List;
 30import java.util.regex.Matcher;
 31import java.util.regex.Pattern;
 32
 33import eu.siacs.conversations.Config;
 34import eu.siacs.conversations.R;
 35import eu.siacs.conversations.entities.Account;
 36import eu.siacs.conversations.entities.Conversation;
 37import eu.siacs.conversations.entities.Message;
 38import eu.siacs.conversations.ui.ConversationActivity;
 39import eu.siacs.conversations.ui.ManageAccountActivity;
 40import eu.siacs.conversations.ui.TimePreference;
 41import eu.siacs.conversations.utils.GeoHelper;
 42import eu.siacs.conversations.utils.UIHelper;
 43
 44public class NotificationService {
 45
 46	private final XmppConnectionService mXmppConnectionService;
 47
 48	private final LinkedHashMap<String, ArrayList<Message>> notifications = new LinkedHashMap<>();
 49
 50	public static final int NOTIFICATION_ID = 0x2342;
 51	public static final int FOREGROUND_NOTIFICATION_ID = 0x8899;
 52	public static final int ERROR_NOTIFICATION_ID = 0x5678;
 53
 54	private Conversation mOpenConversation;
 55	private boolean mIsInForeground;
 56	private long mLastNotification;
 57
 58	public NotificationService(final XmppConnectionService service) {
 59		this.mXmppConnectionService = service;
 60	}
 61
 62	public boolean notify(final Message message) {
 63		return (message.getStatus() == Message.STATUS_RECEIVED)
 64				&& notificationsEnabled()
 65				&& !message.getConversation().isMuted()
 66				&& (message.getConversation().alwaysNotify() || wasHighlightedOrPrivate(message)
 67		);
 68	}
 69
 70	public void notifyPebble(final Message message) {
 71		final Intent i = new Intent("com.getpebble.action.SEND_NOTIFICATION");
 72
 73		final Conversation conversation = message.getConversation();
 74		final JSONObject jsonData = new JSONObject(new HashMap<String, String>(2) {{
 75			put("title", conversation.getName());
 76			put("body", message.getBody());
 77		}});
 78		final String notificationData = new JSONArray().put(jsonData).toString();
 79
 80		i.putExtra("messageType", "PEBBLE_ALERT");
 81		i.putExtra("sender", "Conversations"); /* XXX: Shouldn't be hardcoded, e.g., AbstractGenerator.APP_NAME); */
 82		i.putExtra("notificationData", notificationData);
 83		// notify Pebble App
 84		i.setPackage("com.getpebble.android");
 85		mXmppConnectionService.sendBroadcast(i);
 86		// notify Gadgetbridge
 87		i.setPackage("nodomain.freeyourgadget.gadgetbridge");
 88		mXmppConnectionService.sendBroadcast(i);
 89	}
 90
 91
 92	public boolean notificationsEnabled() {
 93		return mXmppConnectionService.getPreferences().getBoolean("show_notification", true);
 94	}
 95
 96	public boolean isQuietHours() {
 97		if (!mXmppConnectionService.getPreferences().getBoolean("enable_quiet_hours", false)) {
 98			return false;
 99		}
100		final long startTime = mXmppConnectionService.getPreferences().getLong("quiet_hours_start", TimePreference.DEFAULT_VALUE) % Config.MILLISECONDS_IN_DAY;
101		final long endTime = mXmppConnectionService.getPreferences().getLong("quiet_hours_end", TimePreference.DEFAULT_VALUE) % Config.MILLISECONDS_IN_DAY;
102		final long nowTime = Calendar.getInstance().getTimeInMillis() % Config.MILLISECONDS_IN_DAY;
103
104		if (endTime < startTime) {
105			return nowTime > startTime || nowTime < endTime;
106		} else {
107			return nowTime > startTime && nowTime < endTime;
108		}
109	}
110
111	public void pushFromBacklog(final Message message) {
112		if (notify(message)) {
113			synchronized (notifications) {
114				pushToStack(message);
115			}
116		}
117	}
118
119	public void finishBacklog(boolean notify) {
120		synchronized (notifications) {
121			mXmppConnectionService.updateUnreadCountBadge();
122			updateNotification(notify);
123		}
124	}
125
126	private void pushToStack(final Message message) {
127		final String conversationUuid = message.getConversationUuid();
128		if (notifications.containsKey(conversationUuid)) {
129			notifications.get(conversationUuid).add(message);
130		} else {
131			final ArrayList<Message> mList = new ArrayList<>();
132			mList.add(message);
133			notifications.put(conversationUuid, mList);
134		}
135	}
136
137	public void push(final Message message) {
138		mXmppConnectionService.updateUnreadCountBadge();
139		if (!notify(message)) {
140			Log.d(Config.LOGTAG,message.getConversation().getAccount().getJid().toBareJid()+": suppressing notification because turned off");
141			return;
142		}
143		final boolean isScreenOn = mXmppConnectionService.isInteractive();
144		if (this.mIsInForeground && isScreenOn && this.mOpenConversation == message.getConversation()) {
145			Log.d(Config.LOGTAG,message.getConversation().getAccount().getJid().toBareJid()+": suppressing notification because conversation is open");
146			return;
147		}
148		synchronized (notifications) {
149			pushToStack(message);
150			final Account account = message.getConversation().getAccount();
151			final boolean doNotify = (!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn)
152					&& !account.inGracePeriod()
153					&& !this.inMiniGracePeriod(account);
154			updateNotification(doNotify);
155			if (doNotify) {
156				notifyPebble(message);
157			}
158		}
159	}
160
161	public void clear() {
162		synchronized (notifications) {
163			notifications.clear();
164			updateNotification(false);
165		}
166	}
167
168	public void clear(final Conversation conversation) {
169		synchronized (notifications) {
170			notifications.remove(conversation.getUuid());
171			updateNotification(false);
172		}
173	}
174
175	private void setNotificationColor(final Builder mBuilder) {
176		mBuilder.setColor(mXmppConnectionService.getResources().getColor(R.color.primary500));
177	}
178
179	public void updateNotification(final boolean notify) {
180		final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService
181				.getSystemService(Context.NOTIFICATION_SERVICE);
182		final SharedPreferences preferences = mXmppConnectionService.getPreferences();
183
184		final String ringtone = preferences.getString("notification_ringtone", null);
185		final boolean vibrate = preferences.getBoolean("vibrate_on_notification", true);
186		final boolean led = preferences.getBoolean("led", 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			if (led) {
218				mBuilder.setLights(0xff00FF00, 2000, 3000);
219			}
220			final Notification notification = mBuilder.build();
221			notificationManager.notify(NOTIFICATION_ID, notification);
222		}
223	}
224
225	private Builder buildMultipleConversation() {
226		final Builder mBuilder = new NotificationCompat.Builder(
227				mXmppConnectionService);
228		final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
229		style.setBigContentTitle(notifications.size()
230				+ " "
231				+ mXmppConnectionService
232				.getString(R.string.unread_conversations));
233		final StringBuilder names = new StringBuilder();
234		Conversation conversation = null;
235		for (final ArrayList<Message> messages : notifications.values()) {
236			if (messages.size() > 0) {
237				conversation = messages.get(0).getConversation();
238				final String name = conversation.getName();
239				if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
240					int count = messages.size();
241					style.addLine(Html.fromHtml("<b>"+name+"</b>: "+mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages,count,count)));
242				} else {
243					style.addLine(Html.fromHtml("<b>" + name + "</b>: "
244							+ UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first));
245				}
246				names.append(name);
247				names.append(", ");
248			}
249		}
250		if (names.length() >= 2) {
251			names.delete(names.length() - 2, names.length());
252		}
253		mBuilder.setContentTitle(notifications.size()
254				+ " "
255				+ mXmppConnectionService
256				.getString(R.string.unread_conversations));
257		mBuilder.setContentText(names.toString());
258		mBuilder.setStyle(style);
259		if (conversation != null) {
260			mBuilder.setContentIntent(createContentIntent(conversation));
261		}
262		return mBuilder;
263	}
264
265	private Builder buildSingleConversations(final boolean notify) {
266		final Builder mBuilder = new NotificationCompat.Builder(
267				mXmppConnectionService);
268		final ArrayList<Message> messages = notifications.values().iterator().next();
269		if (messages.size() >= 1) {
270			final Conversation conversation = messages.get(0).getConversation();
271			mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService()
272					.get(conversation, getPixel(64)));
273			mBuilder.setContentTitle(conversation.getName());
274			if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
275				int count = messages.size();
276				mBuilder.setContentText(mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages,count,count));
277			} else {
278				Message message;
279				if ((message = getImage(messages)) != null) {
280					modifyForImage(mBuilder, message, messages, notify);
281				} else if (conversation.getMode() == Conversation.MODE_MULTI) {
282					modifyForConference(mBuilder, conversation, messages, notify);
283				} else {
284					modifyForTextOnly(mBuilder, messages, notify);
285				}
286				if ((message = getFirstDownloadableMessage(messages)) != null) {
287					mBuilder.addAction(
288							Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
289									R.drawable.ic_file_download_white_24dp : R.drawable.ic_action_download,
290							mXmppConnectionService.getResources().getString(R.string.download_x_file,
291									UIHelper.getFileDescriptionString(mXmppConnectionService, message)),
292							createDownloadIntent(message)
293					);
294				}
295				if ((message = getFirstLocationMessage(messages)) != null) {
296					mBuilder.addAction(R.drawable.ic_room_white_24dp,
297							mXmppConnectionService.getString(R.string.show_location),
298							createShowLocationIntent(message));
299				}
300			}
301			mBuilder.setContentIntent(createContentIntent(conversation));
302		}
303		return mBuilder;
304	}
305
306	private void modifyForImage(final Builder builder, final Message message,
307								final ArrayList<Message> messages, final boolean notify) {
308		try {
309			final Bitmap bitmap = mXmppConnectionService.getFileBackend()
310					.getThumbnail(message, getPixel(288), false);
311			final ArrayList<Message> tmp = new ArrayList<>();
312			for (final Message msg : messages) {
313				if (msg.getType() == Message.TYPE_TEXT
314						&& msg.getTransferable() == null) {
315					tmp.add(msg);
316				}
317			}
318			final BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
319			bigPictureStyle.bigPicture(bitmap);
320			if (tmp.size() > 0) {
321				bigPictureStyle.setSummaryText(getMergedBodies(tmp));
322				builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService, tmp.get(0)).first);
323			} else {
324				builder.setContentText(mXmppConnectionService.getString(
325						R.string.received_x_file,
326						UIHelper.getFileDescriptionString(mXmppConnectionService, message)));
327			}
328			builder.setStyle(bigPictureStyle);
329		} catch (final FileNotFoundException e) {
330			modifyForTextOnly(builder, messages, notify);
331		}
332	}
333
334	private void modifyForTextOnly(final Builder builder,
335								   final ArrayList<Message> messages, final boolean notify) {
336		builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getMergedBodies(messages)));
337		builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first);
338		if (notify) {
339			builder.setTicker(UIHelper.getMessagePreview(mXmppConnectionService, messages.get(messages.size() - 1)).first);
340		}
341	}
342
343	private void modifyForConference(Builder builder, Conversation conversation, List<Message> messages, boolean notify) {
344		final Message first = messages.get(0);
345		final Message last = messages.get(messages.size() - 1);
346		final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
347		style.setBigContentTitle(conversation.getName());
348
349		for(Message message : messages) {
350			if (message.hasMeCommand()) {
351				style.addLine(UIHelper.getMessagePreview(mXmppConnectionService,message).first);
352			} else {
353				style.addLine(Html.fromHtml("<b>" + UIHelper.getMessageDisplayName(message) + "</b>: " + UIHelper.getMessagePreview(mXmppConnectionService, message).first));
354			}
355		}
356		builder.setContentText((first.hasMeCommand() ? "" :UIHelper.getMessageDisplayName(first)+ ": ") +UIHelper.getMessagePreview(mXmppConnectionService, first).first);
357		builder.setStyle(style);
358		if (notify) {
359			builder.setTicker((last.hasMeCommand() ? "" : UIHelper.getMessageDisplayName(last) + ": ") + UIHelper.getMessagePreview(mXmppConnectionService,last).first);
360		}
361	}
362
363	private Message getImage(final Iterable<Message> messages) {
364		for (final Message message : messages) {
365			if (message.getType() != Message.TYPE_TEXT
366					&& message.getTransferable() == null
367					&& message.getEncryption() != Message.ENCRYPTION_PGP
368					&& message.getFileParams().height > 0) {
369				return message;
370			}
371		}
372		return null;
373	}
374
375	private Message getFirstDownloadableMessage(final Iterable<Message> messages) {
376		for (final Message message : messages) {
377			if (message.getTransferable() != null
378					&& (message.getType() == Message.TYPE_FILE
379							|| message.getType() == Message.TYPE_IMAGE
380							|| message.treatAsDownloadable() != Message.Decision.NEVER)) {
381				return message;
382			}
383		}
384		return null;
385	}
386
387	private Message getFirstLocationMessage(final Iterable<Message> messages) {
388		for (final Message message : messages) {
389			if (GeoHelper.isGeoUri(message.getBody())) {
390				return message;
391			}
392		}
393		return null;
394	}
395
396	private CharSequence getMergedBodies(final ArrayList<Message> messages) {
397		final StringBuilder text = new StringBuilder();
398		for (int i = 0; i < messages.size(); ++i) {
399			text.append(UIHelper.getMessagePreview(mXmppConnectionService, messages.get(i)).first);
400			if (i != messages.size() - 1) {
401				text.append("\n");
402			}
403		}
404		return text.toString();
405	}
406
407	private PendingIntent createShowLocationIntent(final Message message) {
408		Iterable<Intent> intents = GeoHelper.createGeoIntentsFromMessage(message);
409		for (Intent intent : intents) {
410			if (intent.resolveActivity(mXmppConnectionService.getPackageManager()) != null) {
411				return PendingIntent.getActivity(mXmppConnectionService, 18, intent, PendingIntent.FLAG_UPDATE_CURRENT);
412			}
413		}
414		return createOpenConversationsIntent();
415	}
416
417	private PendingIntent createContentIntent(final String conversationUuid, final String downloadMessageUuid) {
418		final Intent viewConversationIntent = new Intent(mXmppConnectionService,ConversationActivity.class);
419		viewConversationIntent.setAction(ConversationActivity.ACTION_VIEW_CONVERSATION);
420		if (conversationUuid != null) {
421			viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversationUuid);
422		}
423		if (downloadMessageUuid != null) {
424			viewConversationIntent.putExtra(ConversationActivity.EXTRA_DOWNLOAD_UUID, downloadMessageUuid);
425			return PendingIntent.getActivity(mXmppConnectionService,
426					57,
427					viewConversationIntent,
428					PendingIntent.FLAG_UPDATE_CURRENT);
429		} else {
430			return PendingIntent.getActivity(mXmppConnectionService,
431					58,
432					viewConversationIntent,
433					PendingIntent.FLAG_UPDATE_CURRENT);
434		}
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}