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
343 for(Message message : messages) {
344 if (message.hasMeCommand()) {
345 style.addLine(UIHelper.getMessagePreview(mXmppConnectionService,message).first);
346 } else {
347 style.addLine(Html.fromHtml("<b>" + UIHelper.getMessageDisplayName(message) + "</b>: " + UIHelper.getMessagePreview(mXmppConnectionService, message).first));
348 }
349 }
350 builder.setContentText((first.hasMeCommand() ? "" :UIHelper.getMessageDisplayName(first)+ ": ") +UIHelper.getMessagePreview(mXmppConnectionService, first).first);
351 builder.setStyle(style);
352 if (notify) {
353 builder.setTicker((last.hasMeCommand() ? "" : UIHelper.getMessageDisplayName(last) + ": ") + UIHelper.getMessagePreview(mXmppConnectionService,last).first);
354 }
355 }
356
357 private Message getImage(final Iterable<Message> messages) {
358 for (final Message message : messages) {
359 if (message.getType() != Message.TYPE_TEXT
360 && message.getTransferable() == null
361 && message.getEncryption() != Message.ENCRYPTION_PGP
362 && message.getFileParams().height > 0) {
363 return message;
364 }
365 }
366 return null;
367 }
368
369 private Message getFirstDownloadableMessage(final Iterable<Message> messages) {
370 for (final Message message : messages) {
371 if ((message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) &&
372 message.getTransferable() != null) {
373 return message;
374 }
375 }
376 return null;
377 }
378
379 private Message getFirstLocationMessage(final Iterable<Message> messages) {
380 for (final Message message : messages) {
381 if (GeoHelper.isGeoUri(message.getBody())) {
382 return message;
383 }
384 }
385 return null;
386 }
387
388 private CharSequence getMergedBodies(final ArrayList<Message> messages) {
389 final StringBuilder text = new StringBuilder();
390 for (int i = 0; i < messages.size(); ++i) {
391 text.append(UIHelper.getMessagePreview(mXmppConnectionService, messages.get(i)).first);
392 if (i != messages.size() - 1) {
393 text.append("\n");
394 }
395 }
396 return text.toString();
397 }
398
399 private PendingIntent createShowLocationIntent(final Message message) {
400 Iterable<Intent> intents = GeoHelper.createGeoIntentsFromMessage(message);
401 for (Intent intent : intents) {
402 if (intent.resolveActivity(mXmppConnectionService.getPackageManager()) != null) {
403 return PendingIntent.getActivity(mXmppConnectionService, 18, intent, PendingIntent.FLAG_UPDATE_CURRENT);
404 }
405 }
406 return createOpenConversationsIntent();
407 }
408
409 private PendingIntent createContentIntent(final String conversationUuid, final String downloadMessageUuid) {
410 final TaskStackBuilder stackBuilder = TaskStackBuilder
411 .create(mXmppConnectionService);
412 stackBuilder.addParentStack(ConversationActivity.class);
413
414 final Intent viewConversationIntent = new Intent(mXmppConnectionService,
415 ConversationActivity.class);
416 if (downloadMessageUuid != null) {
417 viewConversationIntent.setAction(ConversationActivity.ACTION_DOWNLOAD);
418 } else {
419 viewConversationIntent.setAction(Intent.ACTION_VIEW);
420 }
421 if (conversationUuid != null) {
422 viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversationUuid);
423 viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
424 }
425 if (downloadMessageUuid != null) {
426 viewConversationIntent.putExtra(ConversationActivity.MESSAGE, downloadMessageUuid);
427 }
428
429 stackBuilder.addNextIntent(viewConversationIntent);
430
431 return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
432 }
433
434 private PendingIntent createDownloadIntent(final Message message) {
435 return createContentIntent(message.getConversationUuid(), message.getUuid());
436 }
437
438 private PendingIntent createContentIntent(final Conversation conversation) {
439 return createContentIntent(conversation.getUuid(), null);
440 }
441
442 private PendingIntent createDeleteIntent() {
443 final Intent intent = new Intent(mXmppConnectionService,
444 XmppConnectionService.class);
445 intent.setAction(XmppConnectionService.ACTION_CLEAR_NOTIFICATION);
446 return PendingIntent.getService(mXmppConnectionService, 0, intent, 0);
447 }
448
449 private PendingIntent createDisableForeground() {
450 final Intent intent = new Intent(mXmppConnectionService,
451 XmppConnectionService.class);
452 intent.setAction(XmppConnectionService.ACTION_DISABLE_FOREGROUND);
453 return PendingIntent.getService(mXmppConnectionService, 34, intent, 0);
454 }
455
456 private PendingIntent createTryAgainIntent() {
457 final Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class);
458 intent.setAction(XmppConnectionService.ACTION_TRY_AGAIN);
459 return PendingIntent.getService(mXmppConnectionService, 45, intent, 0);
460 }
461
462 private PendingIntent createDisableAccountIntent(final Account account) {
463 final Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class);
464 intent.setAction(XmppConnectionService.ACTION_DISABLE_ACCOUNT);
465 intent.putExtra("account", account.getJid().toBareJid().toString());
466 return PendingIntent.getService(mXmppConnectionService, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
467 }
468
469 private boolean wasHighlightedOrPrivate(final Message message) {
470 final String nick = message.getConversation().getMucOptions().getActualNick();
471 final Pattern highlight = generateNickHighlightPattern(nick);
472 if (message.getBody() == null || nick == null) {
473 return false;
474 }
475 final Matcher m = highlight.matcher(message.getBody());
476 return (m.find() || message.getType() == Message.TYPE_PRIVATE);
477 }
478
479 private static Pattern generateNickHighlightPattern(final String nick) {
480 // We expect a word boundary, i.e. space or start of string, followed by
481 // the
482 // nick (matched in case-insensitive manner), followed by optional
483 // punctuation (for example "bob: i disagree" or "how are you alice?"),
484 // followed by another word boundary.
485 return Pattern.compile("\\b" + Pattern.quote(nick) + "\\p{Punct}?\\b",
486 Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
487 }
488
489 public void setOpenConversation(final Conversation conversation) {
490 this.mOpenConversation = conversation;
491 }
492
493 public void setIsInForeground(final boolean foreground) {
494 this.mIsInForeground = foreground;
495 }
496
497 private int getPixel(final int dp) {
498 final DisplayMetrics metrics = mXmppConnectionService.getResources()
499 .getDisplayMetrics();
500 return ((int) (dp * metrics.density));
501 }
502
503 private void markLastNotification() {
504 this.mLastNotification = SystemClock.elapsedRealtime();
505 }
506
507 private boolean inMiniGracePeriod(final Account account) {
508 final int miniGrace = account.getStatus() == Account.State.ONLINE ? Config.MINI_GRACE_PERIOD
509 : Config.MINI_GRACE_PERIOD * 2;
510 return SystemClock.elapsedRealtime() < (this.mLastNotification + miniGrace);
511 }
512
513 public Notification createForegroundNotification() {
514 final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
515
516 mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.conversations_foreground_service));
517 if (Config.SHOW_CONNECTED_ACCOUNTS) {
518 List<Account> accounts = mXmppConnectionService.getAccounts();
519 int enabled = 0;
520 int connected = 0;
521 for (Account account : accounts) {
522 if (account.isOnlineAndConnected()) {
523 connected++;
524 enabled++;
525 } else if (!account.isOptionSet(Account.OPTION_DISABLED)) {
526 enabled++;
527 }
528 }
529 mBuilder.setContentText(mXmppConnectionService.getString(R.string.connected_accounts, connected, enabled));
530 } else {
531 mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_open_conversations));
532 }
533 mBuilder.setContentIntent(createOpenConversationsIntent());
534 mBuilder.setWhen(0);
535 mBuilder.setPriority(Config.SHOW_CONNECTED_ACCOUNTS ? NotificationCompat.PRIORITY_DEFAULT : NotificationCompat.PRIORITY_MIN);
536 final int cancelIcon;
537 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
538 mBuilder.setCategory(Notification.CATEGORY_SERVICE);
539 cancelIcon = R.drawable.ic_cancel_white_24dp;
540 } else {
541 cancelIcon = R.drawable.ic_action_cancel;
542 }
543 mBuilder.setSmallIcon(R.drawable.ic_link_white_24dp);
544 mBuilder.addAction(cancelIcon,
545 mXmppConnectionService.getString(R.string.disable_foreground_service),
546 createDisableForeground());
547 return mBuilder.build();
548 }
549
550 private PendingIntent createOpenConversationsIntent() {
551 return PendingIntent.getActivity(mXmppConnectionService, 0, new Intent(mXmppConnectionService, ConversationActivity.class), 0);
552 }
553
554 public void updateErrorNotification() {
555 final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService.getSystemService(Context.NOTIFICATION_SERVICE);
556 final List<Account> errors = new ArrayList<>();
557 for (final Account account : mXmppConnectionService.getAccounts()) {
558 if (account.hasErrorStatus()) {
559 errors.add(account);
560 }
561 }
562 if (mXmppConnectionService.getPreferences().getBoolean("keep_foreground_service", false)) {
563 notificationManager.notify(FOREGROUND_NOTIFICATION_ID, createForegroundNotification());
564 }
565 final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
566 if (errors.size() == 0) {
567 notificationManager.cancel(ERROR_NOTIFICATION_ID);
568 return;
569 } else if (errors.size() == 1) {
570 mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_account));
571 mBuilder.setContentText(errors.get(0).getJid().toBareJid().toString());
572 } else {
573 mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_accounts));
574 mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_fix));
575 }
576 mBuilder.addAction(R.drawable.ic_autorenew_white_24dp,
577 mXmppConnectionService.getString(R.string.try_again),
578 createTryAgainIntent());
579 if (errors.size() == 1) {
580 mBuilder.addAction(R.drawable.ic_block_white_24dp,
581 mXmppConnectionService.getString(R.string.disable_account),
582 createDisableAccountIntent(errors.get(0)));
583 }
584 mBuilder.setOngoing(true);
585 //mBuilder.setLights(0xffffffff, 2000, 4000);
586 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
587 mBuilder.setSmallIcon(R.drawable.ic_warning_white_24dp);
588 } else {
589 mBuilder.setSmallIcon(R.drawable.ic_stat_alert_warning);
590 }
591 final TaskStackBuilder stackBuilder = TaskStackBuilder.create(mXmppConnectionService);
592 stackBuilder.addParentStack(ConversationActivity.class);
593
594 final Intent manageAccountsIntent = new Intent(mXmppConnectionService, ManageAccountActivity.class);
595 stackBuilder.addNextIntent(manageAccountsIntent);
596
597 final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
598
599 mBuilder.setContentIntent(resultPendingIntent);
600 notificationManager.notify(ERROR_NOTIFICATION_ID, mBuilder.build());
601 }
602}