AvatarService.java

  1package eu.siacs.conversations.services;
  2
  3import android.content.res.Resources;
  4import android.graphics.Bitmap;
  5import android.graphics.BitmapFactory;
  6import android.graphics.Canvas;
  7import android.graphics.Paint;
  8import android.graphics.PorterDuff;
  9import android.graphics.PorterDuffXfermode;
 10import android.graphics.Rect;
 11import android.graphics.Typeface;
 12import android.net.Uri;
 13import android.support.annotation.Nullable;
 14import android.text.TextUtils;
 15import android.util.DisplayMetrics;
 16import android.util.Log;
 17import android.util.LruCache;
 18
 19import java.util.ArrayList;
 20import java.util.HashMap;
 21import java.util.HashSet;
 22import java.util.List;
 23import java.util.Locale;
 24import java.util.Set;
 25
 26import eu.siacs.conversations.Config;
 27import eu.siacs.conversations.R;
 28import eu.siacs.conversations.entities.Account;
 29import eu.siacs.conversations.entities.Bookmark;
 30import eu.siacs.conversations.entities.Contact;
 31import eu.siacs.conversations.entities.Conversation;
 32import eu.siacs.conversations.entities.Conversational;
 33import eu.siacs.conversations.entities.ListItem;
 34import eu.siacs.conversations.entities.Message;
 35import eu.siacs.conversations.entities.MucOptions;
 36import eu.siacs.conversations.utils.UIHelper;
 37import eu.siacs.conversations.xmpp.OnAdvancedStreamFeaturesLoaded;
 38import eu.siacs.conversations.xmpp.XmppConnection;
 39import rocks.xmpp.addr.Jid;
 40
 41public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
 42
 43	private static final int FG_COLOR = 0xFFFAFAFA;
 44	private static final int TRANSPARENT = 0x00000000;
 45	private static final int PLACEHOLDER_COLOR = 0xFF202020;
 46
 47	private static final String PREFIX_CONTACT = "contact";
 48	private static final String PREFIX_CONVERSATION = "conversation";
 49	private static final String PREFIX_ACCOUNT = "account";
 50	private static final String PREFIX_GENERIC = "generic";
 51
 52	final private ArrayList<Integer> sizes = new ArrayList<>();
 53	final private HashMap<String, Set<String>> conversationDependentKeys = new HashMap<>();
 54
 55	protected XmppConnectionService mXmppConnectionService = null;
 56
 57	AvatarService(XmppConnectionService service) {
 58		this.mXmppConnectionService = service;
 59	}
 60
 61	private Bitmap get(final Contact contact, final int size, boolean cachedOnly) {
 62		if (contact.isSelf()) {
 63			return get(contact.getAccount(), size, cachedOnly);
 64		}
 65		final String KEY = key(contact, size);
 66		Bitmap avatar = this.mXmppConnectionService.getBitmapCache().get(KEY);
 67		if (avatar != null || cachedOnly) {
 68			return avatar;
 69		}
 70		if (contact.getAvatarFilename() != null && QuickConversationsService.isQuicksy()) {
 71			avatar = mXmppConnectionService.getFileBackend().getAvatar(contact.getAvatarFilename(), size);
 72		}
 73		if (avatar == null && contact.getProfilePhoto() != null) {
 74			avatar = mXmppConnectionService.getFileBackend().cropCenterSquare(Uri.parse(contact.getProfilePhoto()), size);
 75		}
 76		if (avatar == null && contact.getAvatarFilename() != null) {
 77			avatar = mXmppConnectionService.getFileBackend().getAvatar(contact.getAvatarFilename(), size);
 78		}
 79		if (avatar == null) {
 80			avatar = get(contact.getDisplayName(), contact.getJid().asBareJid().toString(), size, false);
 81		}
 82		this.mXmppConnectionService.getBitmapCache().put(KEY, avatar);
 83		return avatar;
 84	}
 85
 86	public Bitmap getRoundedShortcut(final Contact contact) {
 87		return getRoundedShortcut(contact, false);
 88	}
 89
 90	public Bitmap getRoundedShortcutWithIcon(final Contact contact) {
 91		return getRoundedShortcut(contact, true);
 92	}
 93
 94	private Bitmap getRoundedShortcut(final Contact contact, boolean withIcon) {
 95		DisplayMetrics metrics = mXmppConnectionService.getResources().getDisplayMetrics();
 96		int size = Math.round(metrics.density * 48);
 97		Bitmap bitmap = get(contact, size);
 98		Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
 99		Canvas canvas = new Canvas(output);
100		final Paint paint = new Paint();
101
102		drawAvatar(bitmap, canvas, paint);
103		if (withIcon) {
104			drawIcon(canvas, paint);
105		}
106		return output;
107	}
108
109	private void drawAvatar(Bitmap bitmap, Canvas canvas, Paint paint) {
110		final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
111		paint.setAntiAlias(true);
112		canvas.drawARGB(0, 0, 0, 0);
113		canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);
114		paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
115		canvas.drawBitmap(bitmap, rect, rect, paint);
116	}
117
118	private void drawIcon(Canvas canvas, Paint paint) {
119		BitmapFactory.Options opts = new BitmapFactory.Options();
120		opts.inSampleSize = 2;
121		Resources resources = mXmppConnectionService.getResources();
122		Bitmap icon = BitmapFactory.decodeResource(resources, R.mipmap.new_launcher_round, opts);
123		paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
124
125		int iconSize = Math.round(canvas.getHeight() / 2.6f);
126
127		int left = canvas.getWidth() - iconSize;
128		int top = canvas.getHeight() - iconSize;
129		final Rect rect = new Rect(left, top, left + iconSize, top + iconSize);
130		canvas.drawBitmap(icon, null, rect, paint);
131	}
132
133	public Bitmap get(final MucOptions.User user, final int size, boolean cachedOnly) {
134		Contact c = user.getContact();
135		if (c != null && (c.getProfilePhoto() != null || c.getAvatarFilename() != null || user.getAvatar() == null)) {
136			return get(c, size, cachedOnly);
137		} else {
138			return getImpl(user, size, cachedOnly);
139		}
140	}
141
142	private Bitmap getImpl(final MucOptions.User user, final int size, boolean cachedOnly) {
143		final String KEY = key(user, size);
144		Bitmap avatar = this.mXmppConnectionService.getBitmapCache().get(KEY);
145		if (avatar != null || cachedOnly) {
146			return avatar;
147		}
148		if (user.getAvatar() != null) {
149			avatar = mXmppConnectionService.getFileBackend().getAvatar(user.getAvatar(), size);
150		}
151		if (avatar == null) {
152			Contact contact = user.getContact();
153			if (contact != null) {
154				avatar = get(contact, size, false);
155			} else {
156				String seed = user.getRealJid() != null ? user.getRealJid().asBareJid().toString() : null;
157				avatar = get(user.getName(), seed, size, false);
158			}
159		}
160		this.mXmppConnectionService.getBitmapCache().put(KEY, avatar);
161		return avatar;
162	}
163
164	public void clear(Contact contact) {
165		synchronized (this.sizes) {
166			for (Integer size : sizes) {
167				this.mXmppConnectionService.getBitmapCache().remove(
168						key(contact, size));
169			}
170		}
171		for (Conversation conversation : mXmppConnectionService.findAllConferencesWith(contact)) {
172			MucOptions.User user = conversation.getMucOptions().findUserByRealJid(contact.getJid().asBareJid());
173			if (user != null) {
174				clear(user);
175			}
176			clear(conversation);
177		}
178	}
179
180	private String key(Contact contact, int size) {
181		synchronized (this.sizes) {
182			if (!this.sizes.contains(size)) {
183				this.sizes.add(size);
184			}
185		}
186		return PREFIX_CONTACT +
187				'\0' +
188				contact.getAccount().getJid().asBareJid() +
189				'\0' +
190				emptyOnNull(contact.getJid()) +
191				'\0' +
192				size;
193	}
194
195	private String key(MucOptions.User user, int size) {
196		synchronized (this.sizes) {
197			if (!this.sizes.contains(size)) {
198				this.sizes.add(size);
199			}
200		}
201		return PREFIX_CONTACT +
202				'\0' +
203				user.getAccount().getJid().asBareJid() +
204				'\0' +
205				emptyOnNull(user.getFullJid()) +
206				'\0' +
207				emptyOnNull(user.getRealJid()) +
208				'\0' +
209				size;
210	}
211
212	public Bitmap get(ListItem item, int size) {
213		return get(item, size, false);
214	}
215
216	public Bitmap get(ListItem item, int size, boolean cachedOnly) {
217		if (item instanceof Contact) {
218			return get((Contact) item, size, cachedOnly);
219		} else if (item instanceof Bookmark) {
220			Bookmark bookmark = (Bookmark) item;
221			if (bookmark.getConversation() != null) {
222				return get(bookmark.getConversation(), size, cachedOnly);
223			} else {
224				Jid jid = bookmark.getJid();
225				Account account = bookmark.getAccount();
226				Contact contact = jid == null ? null : account.getRoster().getContact(jid);
227				if (contact != null && contact.getAvatarFilename() != null) {
228					return get(contact, size, cachedOnly);
229				}
230				String seed = jid != null ? jid.asBareJid().toString() : null;
231				return get(bookmark.getDisplayName(), seed, size, cachedOnly);
232			}
233		} else {
234			String seed = item.getJid() != null ? item.getJid().asBareJid().toString() : null;
235			return get(item.getDisplayName(), seed, size, cachedOnly);
236		}
237	}
238
239	public Bitmap get(Conversation conversation, int size) {
240		return get(conversation, size, false);
241	}
242
243	public Bitmap get(Conversation conversation, int size, boolean cachedOnly) {
244		if (conversation.getMode() == Conversation.MODE_SINGLE) {
245			return get(conversation.getContact(), size, cachedOnly);
246		} else {
247			return get(conversation.getMucOptions(), size, cachedOnly);
248		}
249	}
250
251	public void clear(Conversation conversation) {
252		if (conversation.getMode() == Conversation.MODE_SINGLE) {
253			clear(conversation.getContact());
254		} else {
255			clear(conversation.getMucOptions());
256			synchronized (this.conversationDependentKeys) {
257				Set<String> keys = this.conversationDependentKeys.get(conversation.getUuid());
258				if (keys == null) {
259					return;
260				}
261				LruCache<String, Bitmap> cache = this.mXmppConnectionService.getBitmapCache();
262				for (String key : keys) {
263					cache.remove(key);
264				}
265				keys.clear();
266			}
267		}
268	}
269
270	private Bitmap get(MucOptions mucOptions, int size, boolean cachedOnly) {
271		final String KEY = key(mucOptions, size);
272		Bitmap bitmap = this.mXmppConnectionService.getBitmapCache().get(KEY);
273		if (bitmap != null || cachedOnly) {
274			return bitmap;
275		}
276
277		bitmap = mXmppConnectionService.getFileBackend().getAvatar(mucOptions.getAvatar(), size);
278
279		if (bitmap == null) {
280			final List<MucOptions.User> users = mucOptions.getUsersRelevantForNameAndAvatar();
281			if (users.size() == 0) {
282				Conversation c = mucOptions.getConversation();
283				bitmap = getImpl(c.getName().toString(), c.getJid().asBareJid().toString(), size);
284			} else {
285				bitmap = getImpl(users, size);
286			}
287		}
288
289		this.mXmppConnectionService.getBitmapCache().put(KEY, bitmap);
290
291		return bitmap;
292	}
293
294	private Bitmap get(List<MucOptions.User> users, int size, boolean cachedOnly) {
295		final String KEY = key(users, size);
296		Bitmap bitmap = this.mXmppConnectionService.getBitmapCache().get(KEY);
297		if (bitmap != null || cachedOnly) {
298			return bitmap;
299		}
300		bitmap = getImpl(users, size);
301		this.mXmppConnectionService.getBitmapCache().put(KEY, bitmap);
302		return bitmap;
303	}
304
305	private Bitmap getImpl(List<MucOptions.User> users, int size) {
306		int count = users.size();
307		Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
308		Canvas canvas = new Canvas(bitmap);
309		bitmap.eraseColor(TRANSPARENT);
310		if (count == 0) {
311			throw new AssertionError("Unable to draw tiles for 0 users");
312		} else if (count == 1) {
313			drawTile(canvas, users.get(0), 0, 0, size / 2 - 1, size);
314			drawTile(canvas, users.get(0).getAccount(), size / 2 + 1, 0, size, size);
315		} else if (count == 2) {
316			drawTile(canvas, users.get(0), 0, 0, size / 2 - 1, size);
317			drawTile(canvas, users.get(1), size / 2 + 1, 0, size, size);
318		} else if (count == 3) {
319			drawTile(canvas, users.get(0), 0, 0, size / 2 - 1, size);
320			drawTile(canvas, users.get(1), size / 2 + 1, 0, size, size / 2 - 1);
321			drawTile(canvas, users.get(2), size / 2 + 1, size / 2 + 1, size,
322					size);
323		} else if (count == 4) {
324			drawTile(canvas, users.get(0), 0, 0, size / 2 - 1, size / 2 - 1);
325			drawTile(canvas, users.get(1), 0, size / 2 + 1, size / 2 - 1, size);
326			drawTile(canvas, users.get(2), size / 2 + 1, 0, size, size / 2 - 1);
327			drawTile(canvas, users.get(3), size / 2 + 1, size / 2 + 1, size,
328					size);
329		} else {
330			drawTile(canvas, users.get(0), 0, 0, size / 2 - 1, size / 2 - 1);
331			drawTile(canvas, users.get(1), 0, size / 2 + 1, size / 2 - 1, size);
332			drawTile(canvas, users.get(2), size / 2 + 1, 0, size, size / 2 - 1);
333			drawTile(canvas, "\u2026", PLACEHOLDER_COLOR, size / 2 + 1, size / 2 + 1,
334					size, size);
335		}
336		return bitmap;
337	}
338
339	public void clear(final MucOptions options) {
340		if (options == null) {
341			return;
342		}
343		synchronized (this.sizes) {
344			for (Integer size : sizes) {
345				this.mXmppConnectionService.getBitmapCache().remove(key(options, size));
346			}
347		}
348	}
349
350	private String key(final MucOptions options, int size) {
351		synchronized (this.sizes) {
352			if (!this.sizes.contains(size)) {
353				this.sizes.add(size);
354			}
355		}
356		return PREFIX_CONVERSATION + "_" + options.getConversation().getUuid()
357				+ "_" + String.valueOf(size);
358	}
359
360	private String key(List<MucOptions.User> users, int size) {
361		final Conversation conversation = users.get(0).getConversation();
362		StringBuilder builder = new StringBuilder("TILE_");
363		builder.append(conversation.getUuid());
364
365		for (MucOptions.User user : users) {
366			builder.append("\0");
367			builder.append(emptyOnNull(user.getRealJid()));
368			builder.append("\0");
369			builder.append(emptyOnNull(user.getFullJid()));
370		}
371		builder.append('\0');
372		builder.append(size);
373		final String key = builder.toString();
374		synchronized (this.conversationDependentKeys) {
375			Set<String> keys;
376			if (this.conversationDependentKeys.containsKey(conversation.getUuid())) {
377				keys = this.conversationDependentKeys.get(conversation.getUuid());
378			} else {
379				keys = new HashSet<>();
380				this.conversationDependentKeys.put(conversation.getUuid(), keys);
381			}
382			keys.add(key);
383		}
384		return key;
385	}
386
387	public Bitmap get(Account account, int size) {
388		return get(account, size, false);
389	}
390
391	public Bitmap get(Account account, int size, boolean cachedOnly) {
392		final String KEY = key(account, size);
393		Bitmap avatar = mXmppConnectionService.getBitmapCache().get(KEY);
394		if (avatar != null || cachedOnly) {
395			return avatar;
396		}
397		avatar = mXmppConnectionService.getFileBackend().getAvatar(account.getAvatar(), size);
398		if (avatar == null) {
399			final String displayName = account.getDisplayName();
400			final String jid = account.getJid().asBareJid().toEscapedString();
401			if (QuickConversationsService.isQuicksy() && !TextUtils.isEmpty(displayName)) {
402				avatar = get(displayName, jid, size, false);
403			} else {
404				avatar = get(jid, null, size, false);
405			}
406		}
407		mXmppConnectionService.getBitmapCache().put(KEY, avatar);
408		return avatar;
409	}
410
411	public Bitmap get(Message message, int size, boolean cachedOnly) {
412		final Conversational conversation = message.getConversation();
413		if (message.getType() == Message.TYPE_STATUS && message.getCounterparts() != null && message.getCounterparts().size() > 1) {
414			return get(message.getCounterparts(), size, cachedOnly);
415		} else if (message.getStatus() == Message.STATUS_RECEIVED) {
416			Contact c = message.getContact();
417			if (c != null && (c.getProfilePhoto() != null || c.getAvatarFilename() != null)) {
418				return get(c, size, cachedOnly);
419			} else if (conversation instanceof Conversation && message.getConversation().getMode() == Conversation.MODE_MULTI) {
420				final Jid trueCounterpart = message.getTrueCounterpart();
421				final MucOptions mucOptions = ((Conversation) conversation).getMucOptions();
422				MucOptions.User user;
423				if (trueCounterpart != null) {
424					user = mucOptions.findOrCreateUserByRealJid(trueCounterpart, message.getCounterpart());
425				} else {
426					user = mucOptions.findUserByFullJid(message.getCounterpart());
427				}
428				if (user != null) {
429					return getImpl(user, size, cachedOnly);
430				}
431			} else if (c != null) {
432				return get(c, size, cachedOnly);
433			}
434			Jid tcp = message.getTrueCounterpart();
435			String seed = tcp != null ? tcp.asBareJid().toString() : null;
436			return get(UIHelper.getMessageDisplayName(message), seed, size, cachedOnly);
437		} else {
438			return get(conversation.getAccount(), size, cachedOnly);
439		}
440	}
441
442	public void clear(Account account) {
443		synchronized (this.sizes) {
444			for (Integer size : sizes) {
445				this.mXmppConnectionService.getBitmapCache().remove(key(account, size));
446			}
447		}
448	}
449
450	public void clear(MucOptions.User user) {
451		synchronized (this.sizes) {
452			for (Integer size : sizes) {
453				this.mXmppConnectionService.getBitmapCache().remove(key(user, size));
454			}
455		}
456	}
457
458	private String key(Account account, int size) {
459		synchronized (this.sizes) {
460			if (!this.sizes.contains(size)) {
461				this.sizes.add(size);
462			}
463		}
464		return PREFIX_ACCOUNT + "_" + account.getUuid() + "_"
465				+ String.valueOf(size);
466	}
467
468	/*public Bitmap get(String name, int size) {
469		return get(name,null, size,false);
470	}*/
471
472	public Bitmap get(final String name, String seed, final int size, boolean cachedOnly) {
473		final String KEY = key(seed == null ? name : name+"\0"+seed, size);
474		Bitmap bitmap = mXmppConnectionService.getBitmapCache().get(KEY);
475		if (bitmap != null || cachedOnly) {
476			return bitmap;
477		}
478		bitmap = getImpl(name, seed, size);
479		mXmppConnectionService.getBitmapCache().put(KEY, bitmap);
480		return bitmap;
481	}
482
483	private Bitmap getImpl(final String name, final String seed, final int size) {
484		Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
485		Canvas canvas = new Canvas(bitmap);
486		final String trimmedName = name == null ? "" : name.trim();
487		drawTile(canvas, trimmedName, seed, 0, 0, size, size);
488		return bitmap;
489	}
490
491	private String key(String name, int size) {
492		synchronized (this.sizes) {
493			if (!this.sizes.contains(size)) {
494				this.sizes.add(size);
495			}
496		}
497		return PREFIX_GENERIC + "_" + name + "_" + String.valueOf(size);
498	}
499
500	private boolean drawTile(Canvas canvas, String letter, int tileColor, int left, int top, int right, int bottom) {
501		letter = letter.toUpperCase(Locale.getDefault());
502		Paint tilePaint = new Paint(), textPaint = new Paint();
503		tilePaint.setColor(tileColor);
504		textPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
505		textPaint.setColor(FG_COLOR);
506		textPaint.setTypeface(Typeface.create("sans-serif-light",
507				Typeface.NORMAL));
508		textPaint.setTextSize((float) ((right - left) * 0.8));
509		Rect rect = new Rect();
510
511		canvas.drawRect(new Rect(left, top, right, bottom), tilePaint);
512		textPaint.getTextBounds(letter, 0, 1, rect);
513		float width = textPaint.measureText(letter);
514		canvas.drawText(letter, (right + left) / 2 - width / 2, (top + bottom)
515				/ 2 + rect.height() / 2, textPaint);
516		return true;
517	}
518
519	private boolean drawTile(Canvas canvas, MucOptions.User user, int left, int top, int right, int bottom) {
520		Contact contact = user.getContact();
521		if (contact != null) {
522			Uri uri = null;
523			if (contact.getAvatarFilename() != null && QuickConversationsService.isQuicksy()) {
524				uri = mXmppConnectionService.getFileBackend().getAvatarUri(contact.getAvatarFilename());
525			} else if (contact.getProfilePhoto() != null) {
526				uri = Uri.parse(contact.getProfilePhoto());
527			} else if (contact.getAvatarFilename() != null) {
528				uri = mXmppConnectionService.getFileBackend().getAvatarUri(contact.getAvatarFilename());
529			}
530			if (drawTile(canvas, uri, left, top, right, bottom)) {
531				return true;
532			}
533		} else if (user.getAvatar() != null) {
534			Uri uri = mXmppConnectionService.getFileBackend().getAvatarUri(user.getAvatar());
535			if (drawTile(canvas, uri, left, top, right, bottom)) {
536				return true;
537			}
538		}
539		if (contact != null) {
540			String seed = contact.getJid().asBareJid().toString();
541			drawTile(canvas, contact.getDisplayName(), seed, left, top, right, bottom);
542		} else {
543			String seed = user.getRealJid() == null ? null : user.getRealJid().asBareJid().toString();
544			drawTile(canvas, user.getName(), seed, left, top, right, bottom);
545		}
546		return true;
547	}
548
549	private boolean drawTile(Canvas canvas, Account account, int left, int top, int right, int bottom) {
550		String avatar = account.getAvatar();
551		if (avatar != null) {
552			Uri uri = mXmppConnectionService.getFileBackend().getAvatarUri(avatar);
553			if (uri != null) {
554				if (drawTile(canvas, uri, left, top, right, bottom)) {
555					return true;
556				}
557			}
558		}
559		String name = account.getJid().asBareJid().toString();
560		return drawTile(canvas, name, name, left, top, right, bottom);
561	}
562
563	private boolean drawTile(Canvas canvas, String name, String seed, int left, int top, int right, int bottom) {
564		if (name != null) {
565			final String letter = getFirstLetter(name);
566			final int color = UIHelper.getColorForName(seed == null ? name : seed);
567			drawTile(canvas, letter, color, left, top, right, bottom);
568			return true;
569		}
570		return false;
571	}
572
573	private static String getFirstLetter(String name) {
574		for (Character c : name.toCharArray()) {
575			if (Character.isLetterOrDigit(c)) {
576				return c.toString();
577			}
578		}
579		return "X";
580	}
581
582	private boolean drawTile(Canvas canvas, Uri uri, int left, int top, int right, int bottom) {
583		if (uri != null) {
584			Bitmap bitmap = mXmppConnectionService.getFileBackend()
585					.cropCenter(uri, bottom - top, right - left);
586			if (bitmap != null) {
587				drawTile(canvas, bitmap, left, top, right, bottom);
588				return true;
589			}
590		}
591		return false;
592	}
593
594	private boolean drawTile(Canvas canvas, Bitmap bm, int dstleft, int dsttop, int dstright, int dstbottom) {
595		Rect dst = new Rect(dstleft, dsttop, dstright, dstbottom);
596		canvas.drawBitmap(bm, null, dst, null);
597		return true;
598	}
599
600	@Override
601	public void onAdvancedStreamFeaturesAvailable(Account account) {
602		XmppConnection.Features features = account.getXmppConnection().getFeatures();
603		if (features.pep() && !features.pepPersistent()) {
604			Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": has pep but is not persistent");
605			if (account.getAvatar() != null) {
606				mXmppConnectionService.republishAvatarIfNeeded(account);
607			}
608		}
609	}
610
611	private static String emptyOnNull(@Nullable Jid value) {
612		return value == null ? "" : value.toString();
613	}
614}