Fix Vivo NPE quirk.

This commit is contained in:
Cody Henthorne 2022-05-25 11:29:46 -04:00 committed by Alex Hart
parent 08556b111b
commit 4a8083f7b1
2 changed files with 14 additions and 6 deletions

View file

@ -8,6 +8,7 @@ import android.net.Uri
import android.text.SpannableStringBuilder import android.text.SpannableStringBuilder
import androidx.core.app.TaskStackBuilder import androidx.core.app.TaskStackBuilder
import org.signal.core.util.PendingIntentFlags import org.signal.core.util.PendingIntentFlags
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.contacts.TurnOffContactJoinedNotificationsActivity import org.thoughtcrime.securesms.contacts.TurnOffContactJoinedNotificationsActivity
import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto
@ -26,6 +27,7 @@ import org.thoughtcrime.securesms.service.KeyCachingService
import org.thoughtcrime.securesms.stories.StoryViewerArgs import org.thoughtcrime.securesms.stories.StoryViewerArgs
import org.thoughtcrime.securesms.stories.viewer.StoryViewerActivity import org.thoughtcrime.securesms.stories.viewer.StoryViewerActivity
import org.thoughtcrime.securesms.util.Util import org.thoughtcrime.securesms.util.Util
import java.lang.NullPointerException
/** /**
* Encapsulate all the notifications for a given conversation (thread) and the top * Encapsulate all the notifications for a given conversation (thread) and the top
@ -113,7 +115,7 @@ data class NotificationConversation(
return messageCount == other.messageCount && notificationItems.zip(other.notificationItems).all { (item, otherItem) -> item.hasSameContent(otherItem) } return messageCount == other.messageCount && notificationItems.zip(other.notificationItems).all { (item, otherItem) -> item.hasSameContent(otherItem) }
} }
fun getPendingIntent(context: Context): PendingIntent { fun getPendingIntent(context: Context): PendingIntent? {
val intent: Intent = if (thread.groupStoryId != null) { val intent: Intent = if (thread.groupStoryId != null) {
StoryViewerActivity.createIntent( StoryViewerActivity.createIntent(
context, context,
@ -131,9 +133,15 @@ data class NotificationConversation(
.build() .build()
}.makeUniqueToPreventMerging() }.makeUniqueToPreventMerging()
return TaskStackBuilder.create(context) return try {
TaskStackBuilder.create(context)
.addNextIntentWithParentStack(intent) .addNextIntentWithParentStack(intent)
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)!! .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)
} catch (e: NullPointerException) {
Log.w(NotificationFactory.TAG, "Vivo device quirk sometimes throws NPE", e)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
PendingIntent.getActivity(context, 0, intent, PendingIntentFlags.updateCurrent())
}
} }
fun getDeleteIntent(context: Context): PendingIntent? { fun getDeleteIntent(context: Context): PendingIntent? {

View file

@ -32,13 +32,13 @@ import org.thoughtcrime.securesms.util.ConversationUtil
import org.thoughtcrime.securesms.util.ServiceUtil import org.thoughtcrime.securesms.util.ServiceUtil
import org.thoughtcrime.securesms.util.TextSecurePreferences import org.thoughtcrime.securesms.util.TextSecurePreferences
private val TAG = Log.tag(NotificationFactory::class.java)
/** /**
* Given a notification state consisting of conversations of messages, show appropriate system notifications. * Given a notification state consisting of conversations of messages, show appropriate system notifications.
*/ */
object NotificationFactory { object NotificationFactory {
val TAG = Log.tag(NotificationFactory::class.java)
fun notify( fun notify(
context: Context, context: Context,
state: NotificationStateV2, state: NotificationStateV2,