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