From 6b8bc034c1eb304c99e886eecb3002299c2fedc5 Mon Sep 17 00:00:00 2001 From: Erwan Croze Date: Thu, 13 Sep 2018 14:23:52 +0200 Subject: [PATCH] Add avatar in notif --- src/android/org/linphone/LinphoneService.java | 40 +++++++++++-------- src/android/org/linphone/LinphoneUtils.java | 12 ++++++ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/android/org/linphone/LinphoneService.java b/src/android/org/linphone/LinphoneService.java index 7d1af44d5..d1238d766 100644 --- a/src/android/org/linphone/LinphoneService.java +++ b/src/android/org/linphone/LinphoneService.java @@ -33,11 +33,13 @@ import org.linphone.contacts.LinphoneContact; import org.linphone.core.Address; import org.linphone.core.Call; import org.linphone.core.Call.State; +import org.linphone.core.ChatRoomSecurityLevel; import org.linphone.core.Core; import org.linphone.core.GlobalState; import org.linphone.core.LogLevel; import org.linphone.core.LoggingService; import org.linphone.core.LoggingServiceListener; +import org.linphone.core.PresenceModel; import org.linphone.core.RegistrationState; import org.linphone.core.Factory; import org.linphone.core.LogCollectionState; @@ -73,6 +75,9 @@ import android.provider.MediaStore; import android.util.ArrayMap; import android.view.WindowManager; +import static org.linphone.LinphoneUtils.getSecurityLevelForChatRoom; +import static org.linphone.LinphoneUtils.getSecurityLevelForSipUri; + /** * Linphone service, reacting to Incoming calls, ...
* @@ -639,16 +644,18 @@ public final class LinphoneService extends Service { mChatNotifMap.put(conferenceAddress, notif); } - Bitmap bm = null; - if (fromPictureUri != null) { - try { - bm = MediaStore.Images.Media.getBitmap(getContentResolver(), fromPictureUri); - } catch (Exception e) { - bm = BitmapFactory.decodeResource(getResources(), R.drawable.avatar_group_small_secure1); - } - } else { + Bitmap bm; + ChatRoomSecurityLevel securityLevel = getSecurityLevelForChatRoom(LinphoneManager.getLc(), conferenceAddress); + if (securityLevel == ChatRoomSecurityLevel.Safe) { + bm = BitmapFactory.decodeResource(getResources(), R.drawable.avatar_group_small_secure2); + } else if (securityLevel == ChatRoomSecurityLevel.Unsafe) { + bm = BitmapFactory.decodeResource(getResources(), R.drawable.avatar_group_small_unsecure); + } else if (securityLevel == ChatRoomSecurityLevel.Encrypted) { bm = BitmapFactory.decodeResource(getResources(), R.drawable.avatar_group_small_secure1); + } else { + bm = BitmapFactory.decodeResource(getResources(), R.drawable.avatar_group_small_unregistered); } + Notification notification = Compatibility.createMessageNotification(getApplicationContext(), notif.numberOfUnreadMessage, subject, getString(R.string.group_chat_notif).replace("%1", fromName).replace("%2", message), bm, notifContentIntent); @@ -677,15 +684,16 @@ public final class LinphoneService extends Service { mChatNotifMap.put(fromSipUri, notif); } - Bitmap bm = null; - if (fromPictureUri != null) { - try { - bm = MediaStore.Images.Media.getBitmap(getContentResolver(), fromPictureUri); - } catch (Exception e) { - bm = BitmapFactory.decodeResource(getResources(), R.drawable.avatar_small_secure1); - } - } else { + Bitmap bm; + ChatRoomSecurityLevel securityLevel = getSecurityLevelForChatRoom(LinphoneManager.getLc(), fromSipUri); + if (securityLevel == ChatRoomSecurityLevel.Safe) { + bm = BitmapFactory.decodeResource(getResources(), R.drawable.avatar_small_secure2); + } else if (securityLevel == ChatRoomSecurityLevel.Unsafe) { + bm = BitmapFactory.decodeResource(getResources(), R.drawable.avatar_small_unsecure); + } else if (securityLevel == ChatRoomSecurityLevel.Encrypted) { bm = BitmapFactory.decodeResource(getResources(), R.drawable.avatar_small_secure1); + } else { + bm = BitmapFactory.decodeResource(getResources(), R.drawable.avatar_small_unregistered); } Notification notification = Compatibility.createMessageNotification(getApplicationContext(), notif.numberOfUnreadMessage, fromName, message, bm, notifContentIntent); diff --git a/src/android/org/linphone/LinphoneUtils.java b/src/android/org/linphone/LinphoneUtils.java index 32b955122..1dfa5c889 100644 --- a/src/android/org/linphone/LinphoneUtils.java +++ b/src/android/org/linphone/LinphoneUtils.java @@ -809,6 +809,18 @@ public final class LinphoneUtils { return ChatRoomSecurityLevel.ClearText; } + public static ChatRoomSecurityLevel getSecurityLevelForChatRoom(Core lc, String chatUri) { + if (chatUri == null) return ChatRoomSecurityLevel.ClearText; + + for (ChatRoom cr : lc.getChatRooms()) { + if (cr != null && cr.getConferenceAddress().asStringUriOnly().equalsIgnoreCase(chatUri)) { + return cr.getSecurityLevel(); + } + } + + return ChatRoomSecurityLevel.ClearText; + } + public static boolean hasContentFileSharing(Content[] contents) { if (contents == null) return false;