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.primary));
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
184		if (notifications.size() == 0) {
185			notificationManager.cancel(NOTIFICATION_ID);
186		} else {
187			if (notify) {
188				this.markLastNotification();
189			}
190			final Builder mBuilder;
191			if (notifications.size() == 1) {
192				mBuilder = buildSingleConversations(notify);
193			} else {
194				mBuilder = buildMultipleConversation();
195			}
196			if (notify && !isQuietHours()) {
197				if (vibrate) {
198					final int dat = 70;
199					final long[] pattern = {0, 3 * dat, dat, dat};
200					mBuilder.setVibrate(pattern);
201				}
202				if (ringtone != null) {
203					mBuilder.setSound(Uri.parse(ringtone));
204				}
205			}
206			if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
207				mBuilder.setCategory(Notification.CATEGORY_MESSAGE);
208			}
209			setNotificationColor(mBuilder);
210			mBuilder.setDefaults(0);
211			mBuilder.setSmallIcon(R.drawable.ic_notification);
212			mBuilder.setDeleteIntent(createDeleteIntent());
213			mBuilder.setLights(0xff00FF00, 2000, 3000);
214			final Notification notification = mBuilder.build();
215			notificationManager.notify(NOTIFICATION_ID, notification);
216		}
217	}
218
219	private Builder buildMultipleConversation() {
220		final Builder mBuilder = new NotificationCompat.Builder(
221				mXmppConnectionService);
222		final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
223		style.setBigContentTitle(notifications.size()
224				+ " "
225				+ mXmppConnectionService
226				.getString(R.string.unread_conversations));
227		final StringBuilder names = new StringBuilder();
228		Conversation conversation = null;
229		for (final ArrayList<Message> messages : notifications.values()) {
230			if (messages.size() > 0) {
231				conversation = messages.get(0).getConversation();
232				final String name = conversation.getName();
233				if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
234					int count = messages.size();
235					style.addLine(Html.fromHtml("<b>"+name+"</b> "+mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages,count,count)));
236				} else {
237					style.addLine(Html.fromHtml("<b>" + name + "</b> "
238							+ UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first));
239				}
240				names.append(name);
241				names.append(", ");
242			}
243		}
244		if (names.length() >= 2) {
245			names.delete(names.length() - 2, names.length());
246		}
247		mBuilder.setContentTitle(notifications.size()
248				+ " "
249				+ mXmppConnectionService
250				.getString(R.string.unread_conversations));
251		mBuilder.setContentText(names.toString());
252		mBuilder.setStyle(style);
253		if (conversation != null) {
254			mBuilder.setContentIntent(createContentIntent(conversation));
255		}
256		return mBuilder;
257	}
258
259	private Builder buildSingleConversations(final boolean notify) {
260		final Builder mBuilder = new NotificationCompat.Builder(
261				mXmppConnectionService);
262		final ArrayList<Message> messages = notifications.values().iterator().next();
263		if (messages.size() >= 1) {
264			final Conversation conversation = messages.get(0).getConversation();
265			mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService()
266					.get(conversation, getPixel(64)));
267			mBuilder.setContentTitle(conversation.getName());
268			if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
269				int count = messages.size();
270				mBuilder.setContentText(mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages,count,count));
271			} else {
272				Message message;
273				if ((message = getImage(messages)) != null) {
274					modifyForImage(mBuilder, message, messages, notify);
275				} else if (conversation.getMode() == Conversation.MODE_MULTI) {
276					modifyForConference(mBuilder, conversation, messages, notify);
277				} else {
278					modifyForTextOnly(mBuilder, messages, notify);
279				}
280				if ((message = getFirstDownloadableMessage(messages)) != null) {
281					mBuilder.addAction(
282							Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
283									R.drawable.ic_file_download_white_24dp : R.drawable.ic_action_download,
284							mXmppConnectionService.getResources().getString(R.string.download_x_file,
285									UIHelper.getFileDescriptionString(mXmppConnectionService, message)),
286							createDownloadIntent(message)
287					);
288				}
289				if ((message = getFirstLocationMessage(messages)) != null) {
290					mBuilder.addAction(R.drawable.ic_room_white_24dp,
291							mXmppConnectionService.getString(R.string.show_location),
292							createShowLocationIntent(message));
293				}
294			}
295			mBuilder.setContentIntent(createContentIntent(conversation));
296		}
297		return mBuilder;
298	}
299
300	private void modifyForImage(final Builder builder, final Message message,
301								final ArrayList<Message> messages, final boolean notify) {
302		try {
303			final Bitmap bitmap = mXmppConnectionService.getFileBackend()
304					.getThumbnail(message, getPixel(288), false);
305			final ArrayList<Message> tmp = new ArrayList<>();
306			for (final Message msg : messages) {
307				if (msg.getType() == Message.TYPE_TEXT
308						&& msg.getTransferable() == null) {
309					tmp.add(msg);
310				}
311			}
312			final BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
313			bigPictureStyle.bigPicture(bitmap);
314			if (tmp.size() > 0) {
315				bigPictureStyle.setSummaryText(getMergedBodies(tmp));
316				builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService, tmp.get(0)).first);
317			} else {
318				builder.setContentText(mXmppConnectionService.getString(
319						R.string.received_x_file,
320						UIHelper.getFileDescriptionString(mXmppConnectionService, message)));
321			}
322			builder.setStyle(bigPictureStyle);
323		} catch (final FileNotFoundException e) {
324			modifyForTextOnly(builder, messages, notify);
325		}
326	}
327
328	private void modifyForTextOnly(final Builder builder,
329								   final ArrayList<Message> messages, final boolean notify) {
330		builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getMergedBodies(messages)));
331		builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first);
332		if (notify) {
333			builder.setTicker(UIHelper.getMessagePreview(mXmppConnectionService, messages.get(messages.size() - 1)).first);
334		}
335	}
336
337	private void modifyForConference(Builder builder, Conversation conversation, List<Message> messages, boolean notify) {
338		final Message first = messages.get(0);
339		final Message last = messages.get(messages.size() - 1);
340		final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
341		style.setBigContentTitle(conversation.getName());
342		for(Message message : messages) {
343			style.addLine(Html.fromHtml("<b>"+UIHelper.getMessageDisplayName(message)+"</b> "+UIHelper.getMessagePreview(mXmppConnectionService,message).first));
344		}
345		builder.setContentText(UIHelper.getMessageDisplayName(first)+ ": " +UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first);
346		builder.setStyle(style);
347		if (notify) {
348			builder.setTicker(UIHelper.getMessageDisplayName(last) + ": " + UIHelper.getMessagePreview(mXmppConnectionService,last).first);
349		}
350	}
351
352	private Message getImage(final Iterable<Message> messages) {
353		for (final Message message : messages) {
354			if (message.getType() != Message.TYPE_TEXT
355					&& message.getTransferable() == null
356					&& message.getEncryption() != Message.ENCRYPTION_PGP
357					&& message.getFileParams().height > 0) {
358				return message;
359			}
360		}
361		return null;
362	}
363
364	private Message getFirstDownloadableMessage(final Iterable<Message> messages) {
365		for (final Message message : messages) {
366			if ((message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) &&
367					message.getTransferable() != null) {
368				return message;
369			}
370		}
371		return null;
372	}
373
374	private Message getFirstLocationMessage(final Iterable<Message> messages) {
375		for (final Message message : messages) {
376			if (GeoHelper.isGeoUri(message.getBody())) {
377				return message;
378			}
379		}
380		return null;
381	}
382
383	private CharSequence getMergedBodies(final ArrayList<Message> messages) {
384		final StringBuilder text = new StringBuilder();
385		for (int i = 0; i < messages.size(); ++i) {
386			text.append(UIHelper.getMessagePreview(mXmppConnectionService, messages.get(i)).first);
387			if (i != messages.size() - 1) {
388				text.append("\n");
389			}
390		}
391		return text.toString();
392	}
393
394	private PendingIntent createShowLocationIntent(final Message message) {
395		Iterable<Intent> intents = GeoHelper.createGeoIntentsFromMessage(message);
396		for (Intent intent : intents) {
397			if (intent.resolveActivity(mXmppConnectionService.getPackageManager()) != null) {
398				return PendingIntent.getActivity(mXmppConnectionService, 18, intent, PendingIntent.FLAG_UPDATE_CURRENT);
399			}
400		}
401		return createOpenConversationsIntent();
402	}
403
404	private PendingIntent createContentIntent(final String conversationUuid, final String downloadMessageUuid) {
405		final TaskStackBuilder stackBuilder = TaskStackBuilder
406				.create(mXmppConnectionService);
407		stackBuilder.addParentStack(ConversationActivity.class);
408
409		final Intent viewConversationIntent = new Intent(mXmppConnectionService,
410				ConversationActivity.class);
411		if (downloadMessageUuid != null) {
412			viewConversationIntent.setAction(ConversationActivity.ACTION_DOWNLOAD);
413		} else {
414			viewConversationIntent.setAction(Intent.ACTION_VIEW);
415		}
416		if (conversationUuid != null) {
417			viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversationUuid);
418			viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
419		}
420		if (downloadMessageUuid != null) {
421			viewConversationIntent.putExtra(ConversationActivity.MESSAGE, downloadMessageUuid);
422		}
423
424		stackBuilder.addNextIntent(viewConversationIntent);
425
426		return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
427	}
428
429	private PendingIntent createDownloadIntent(final Message message) {
430		return createContentIntent(message.getConversationUuid(), message.getUuid());
431	}
432
433	private PendingIntent createContentIntent(final Conversation conversation) {
434		return createContentIntent(conversation.getUuid(), null);
435	}
436
437	private PendingIntent createDeleteIntent() {
438		final Intent intent = new Intent(mXmppConnectionService,
439				XmppConnectionService.class);
440		intent.setAction(XmppConnectionService.ACTION_CLEAR_NOTIFICATION);
441		return PendingIntent.getService(mXmppConnectionService, 0, intent, 0);
442	}
443
444	private PendingIntent createDisableForeground() {
445		final Intent intent = new Intent(mXmppConnectionService,
446				XmppConnectionService.class);
447		intent.setAction(XmppConnectionService.ACTION_DISABLE_FOREGROUND);
448		return PendingIntent.getService(mXmppConnectionService, 34, intent, 0);
449	}
450
451	private PendingIntent createTryAgainIntent() {
452		final Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class);
453		intent.setAction(XmppConnectionService.ACTION_TRY_AGAIN);
454		return PendingIntent.getService(mXmppConnectionService, 45, intent, 0);
455	}
456
457	private PendingIntent createDisableAccountIntent(final Account account) {
458		final Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class);
459		intent.setAction(XmppConnectionService.ACTION_DISABLE_ACCOUNT);
460		intent.putExtra("account", account.getJid().toBareJid().toString());
461		return PendingIntent.getService(mXmppConnectionService, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
462	}
463
464	private boolean wasHighlightedOrPrivate(final Message message) {
465		final String nick = message.getConversation().getMucOptions().getActualNick();
466		final Pattern highlight = generateNickHighlightPattern(nick);
467		if (message.getBody() == null || nick == null) {
468			return false;
469		}
470		final Matcher m = highlight.matcher(message.getBody());
471		return (m.find() || message.getType() == Message.TYPE_PRIVATE);
472	}
473
474	private static Pattern generateNickHighlightPattern(final String nick) {
475		// We expect a word boundary, i.e. space or start of string, followed by
476		// the
477		// nick (matched in case-insensitive manner), followed by optional
478		// punctuation (for example "bob: i disagree" or "how are you alice?"),
479		// followed by another word boundary.
480		return Pattern.compile("\\b" + Pattern.quote(nick) + "\\p{Punct}?\\b",
481				Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
482	}
483
484	public void setOpenConversation(final Conversation conversation) {
485		this.mOpenConversation = conversation;
486	}
487
488	public void setIsInForeground(final boolean foreground) {
489		this.mIsInForeground = foreground;
490	}
491
492	private int getPixel(final int dp) {
493		final DisplayMetrics metrics = mXmppConnectionService.getResources()
494				.getDisplayMetrics();
495		return ((int) (dp * metrics.density));
496	}
497
498	private void markLastNotification() {
499		this.mLastNotification = SystemClock.elapsedRealtime();
500	}
501
502	private boolean inMiniGracePeriod(final Account account) {
503		final int miniGrace = account.getStatus() == Account.State.ONLINE ? Config.MINI_GRACE_PERIOD
504				: Config.MINI_GRACE_PERIOD * 2;
505		return SystemClock.elapsedRealtime() < (this.mLastNotification + miniGrace);
506	}
507
508	public Notification createForegroundNotification() {
509		final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
510
511		mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.conversations_foreground_service));
512		if (Config.SHOW_CONNECTED_ACCOUNTS) {
513			List<Account> accounts = mXmppConnectionService.getAccounts();
514			int enabled = 0;
515			int connected = 0;
516			for (Account account : accounts) {
517				if (account.isOnlineAndConnected()) {
518					connected++;
519					enabled++;
520				} else if (!account.isOptionSet(Account.OPTION_DISABLED)) {
521					enabled++;
522				}
523			}
524			mBuilder.setContentText(mXmppConnectionService.getString(R.string.connected_accounts, connected, enabled));
525		} else {
526			mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_open_conversations));
527		}
528		mBuilder.setContentIntent(createOpenConversationsIntent());
529		mBuilder.setWhen(0);
530		mBuilder.setPriority(Config.SHOW_CONNECTED_ACCOUNTS ? NotificationCompat.PRIORITY_DEFAULT : NotificationCompat.PRIORITY_MIN);
531		final int cancelIcon;
532		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
533			mBuilder.setCategory(Notification.CATEGORY_SERVICE);
534			cancelIcon = R.drawable.ic_cancel_white_24dp;
535		} else {
536			cancelIcon = R.drawable.ic_action_cancel;
537		}
538		mBuilder.setSmallIcon(R.drawable.ic_link_white_24dp);
539		mBuilder.addAction(cancelIcon,
540				mXmppConnectionService.getString(R.string.disable_foreground_service),
541				createDisableForeground());
542		return mBuilder.build();
543	}
544
545	private PendingIntent createOpenConversationsIntent() {
546		return PendingIntent.getActivity(mXmppConnectionService, 0, new Intent(mXmppConnectionService, ConversationActivity.class), 0);
547	}
548
549	public void updateErrorNotification() {
550		final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService.getSystemService(Context.NOTIFICATION_SERVICE);
551		final List<Account> errors = new ArrayList<>();
552		for (final Account account : mXmppConnectionService.getAccounts()) {
553			if (account.hasErrorStatus()) {
554				errors.add(account);
555			}
556		}
557		if (mXmppConnectionService.getPreferences().getBoolean("keep_foreground_service", false)) {
558			notificationManager.notify(FOREGROUND_NOTIFICATION_ID, createForegroundNotification());
559		}
560		final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
561		if (errors.size() == 0) {
562			notificationManager.cancel(ERROR_NOTIFICATION_ID);
563			return;
564		} else if (errors.size() == 1) {
565			mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_account));
566			mBuilder.setContentText(errors.get(0).getJid().toBareJid().toString());
567		} else {
568			mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_accounts));
569			mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_fix));
570		}
571		mBuilder.addAction(R.drawable.ic_autorenew_white_24dp,
572				mXmppConnectionService.getString(R.string.try_again),
573				createTryAgainIntent());
574		if (errors.size() == 1) {
575			mBuilder.addAction(R.drawable.ic_block_white_24dp,
576					mXmppConnectionService.getString(R.string.disable_account),
577					createDisableAccountIntent(errors.get(0)));
578		}
579		mBuilder.setOngoing(true);
580		//mBuilder.setLights(0xffffffff, 2000, 4000);
581		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
582			mBuilder.setSmallIcon(R.drawable.ic_warning_white_24dp);
583		} else {
584			mBuilder.setSmallIcon(R.drawable.ic_stat_alert_warning);
585		}
586		final TaskStackBuilder stackBuilder = TaskStackBuilder.create(mXmppConnectionService);
587		stackBuilder.addParentStack(ConversationActivity.class);
588
589		final Intent manageAccountsIntent = new Intent(mXmppConnectionService, ManageAccountActivity.class);
590		stackBuilder.addNextIntent(manageAccountsIntent);
591
592		final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
593
594		mBuilder.setContentIntent(resultPendingIntent);
595		notificationManager.notify(ERROR_NOTIFICATION_ID, mBuilder.build());
596	}
597}