From 2dec5414377fe8fa7f3f4fcb6685cb0b3462b4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Sat, 6 Jul 2019 18:16:35 -0400 Subject: [PATCH] notifications: fix crash Change-Id: I8e51e2ca92cdd79c7be314af72cbe137f054d015 --- ring-android/app/build.gradle | 4 ++-- .../ring/services/NotificationServiceImpl.java | 18 +++++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/ring-android/app/build.gradle b/ring-android/app/build.gradle index bd5d036bb..5076d62af 100644 --- a/ring-android/app/build.gradle +++ b/ring-android/app/build.gradle @@ -8,8 +8,8 @@ android { defaultConfig { minSdkVersion 21 targetSdkVersion 29 - versionCode 173 - versionName "20190704-01" + versionCode 174 + versionName "20190706-01" } sourceSets { diff --git a/ring-android/app/src/main/java/cx/ring/services/NotificationServiceImpl.java b/ring-android/app/src/main/java/cx/ring/services/NotificationServiceImpl.java index 34d6424f1..b30a4d7ea 100644 --- a/ring-android/app/src/main/java/cx/ring/services/NotificationServiceImpl.java +++ b/ring-android/app/src/main/java/cx/ring/services/NotificationServiceImpl.java @@ -207,7 +207,6 @@ public class NotificationServiceImpl implements NotificationService { } SipCall call = conference.getParticipants().get(0); - CallContact contact = call.getContact(); final int notificationId = call.getCallId().hashCode(); notificationManager.cancel(notificationId); @@ -227,8 +226,8 @@ public class NotificationServiceImpl implements NotificationService { return; } - NotificationCompat.Builder messageNotificationBuilder = null; - + CallContact contact = call.getContact(); + NotificationCompat.Builder messageNotificationBuilder; if (conference.isOnGoing()) { messageNotificationBuilder = new NotificationCompat.Builder(mContext, NOTIF_CHANNEL_CALL_IN_PROGRESS); messageNotificationBuilder.setContentTitle(mContext.getString(R.string.notif_current_call_title, contact.getDisplayName())) @@ -247,7 +246,6 @@ public class NotificationServiceImpl implements NotificationService { } else if (conference.isRinging()) { if (conference.isIncoming()) { messageNotificationBuilder = new NotificationCompat.Builder(mContext, NOTIF_CHANNEL_INCOMING_CALL); - Bundle extras = new Bundle(); messageNotificationBuilder.setContentTitle(mContext.getString(R.string.notif_incoming_call_title, contact.getDisplayName())) .setPriority(NotificationCompat.PRIORITY_MAX) .setContentText(mContext.getText(R.string.notif_incoming_call)) @@ -264,8 +262,7 @@ public class NotificationServiceImpl implements NotificationService { new Intent(DRingService.ACTION_CALL_ACCEPT) .setClass(mContext, DRingService.class) .putExtra(KEY_CALL_ID, call.getCallId()), - PendingIntent.FLAG_ONE_SHOT)) - .addExtras(extras); + PendingIntent.FLAG_ONE_SHOT)); } else { messageNotificationBuilder = new NotificationCompat.Builder(mContext, NOTIF_CHANNEL_CALL_IN_PROGRESS); messageNotificationBuilder.setContentTitle(mContext.getString(R.string.notif_outgoing_call_title, contact.getDisplayName())) @@ -273,6 +270,8 @@ public class NotificationServiceImpl implements NotificationService { .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setContentIntent(gotoIntent) .setSound(null) + .setColorized(true) + .setColor(mContext.getResources().getColor(R.color.color_primary_light)) .addAction(R.drawable.baseline_call_end_24, mContext.getText(R.string.action_call_hangup), PendingIntent.getService(mContext, random.nextInt(), new Intent(DRingService.ACTION_CALL_END) @@ -280,6 +279,8 @@ public class NotificationServiceImpl implements NotificationService { .putExtra(KEY_CALL_ID, call.getCallId()), PendingIntent.FLAG_ONE_SHOT)); } + } else { + return; } messageNotificationBuilder.setOngoing(true) @@ -287,12 +288,7 @@ public class NotificationServiceImpl implements NotificationService { .setSmallIcon(R.drawable.ic_ring_logo_white); setContactPicture(contact, messageNotificationBuilder); - - messageNotificationBuilder.setColor(ResourcesCompat.getColor(mContext.getResources(), - R.color.color_primary_dark, null)); - notificationManager.notify(notificationId, messageNotificationBuilder.build()); - mNotificationBuilders.put(notificationId, messageNotificationBuilder); } @Override -- GitLab