catch dead system exception when creating error notification

This commit is contained in:
Daniel Gultsch 2019-10-23 22:33:51 +02:00
parent 9c24ebd57b
commit 2f59d66fd1
1 changed files with 20 additions and 11 deletions

View File

@ -563,8 +563,9 @@ public class NotificationService {
if (addedActionsCount < 3) { if (addedActionsCount < 3) {
final Message firstLocationMessage = getFirstLocationMessage(messages); final Message firstLocationMessage = getFirstLocationMessage(messages);
if (firstLocationMessage != null) { if (firstLocationMessage != null) {
String label = mXmppConnectionService.getResources().getString(R.string.show_location); final PendingIntent pendingShowLocationIntent = createShowLocationIntent(firstLocationMessage);
PendingIntent pendingShowLocationIntent = createShowLocationIntent(firstLocationMessage); if (pendingShowLocationIntent != null) {
final String label = mXmppConnectionService.getResources().getString(R.string.show_location);
NotificationCompat.Action locationAction = new NotificationCompat.Action.Builder( NotificationCompat.Action locationAction = new NotificationCompat.Action.Builder(
R.drawable.ic_room_white_24dp, R.drawable.ic_room_white_24dp,
label, label,
@ -573,6 +574,7 @@ public class NotificationService {
++addedActionsCount; ++addedActionsCount;
} }
} }
}
if (addedActionsCount < 3) { if (addedActionsCount < 3) {
Message firstDownloadableMessage = getFirstDownloadableMessage(messages); Message firstDownloadableMessage = getFirstDownloadableMessage(messages);
if (firstDownloadableMessage != null) { if (firstDownloadableMessage != null) {
@ -766,7 +768,7 @@ public class NotificationService {
return PendingIntent.getActivity(mXmppConnectionService, generateRequestCode(message.getConversation(), 18), intent, PendingIntent.FLAG_UPDATE_CURRENT); return PendingIntent.getActivity(mXmppConnectionService, generateRequestCode(message.getConversation(), 18), intent, PendingIntent.FLAG_UPDATE_CURRENT);
} }
} }
return createOpenConversationsIntent(); return null;
} }
private PendingIntent createContentIntent(final String conversationUuid, final String downloadMessageUuid) { private PendingIntent createContentIntent(final String conversationUuid, final String downloadMessageUuid) {
@ -906,7 +908,10 @@ public class NotificationService {
} }
} }
mBuilder.setContentText(mXmppConnectionService.getString(R.string.connected_accounts, connected, enabled)); mBuilder.setContentText(mXmppConnectionService.getString(R.string.connected_accounts, connected, enabled));
mBuilder.setContentIntent(createOpenConversationsIntent()); final PendingIntent openIntent = createOpenConversationsIntent();
if (openIntent != null) {
mBuilder.setContentIntent(openIntent);
}
mBuilder.setWhen(0); mBuilder.setWhen(0);
mBuilder.setPriority(Notification.PRIORITY_MIN); mBuilder.setPriority(Notification.PRIORITY_MIN);
mBuilder.setSmallIcon(connected > 0 ? R.drawable.ic_link_white_24dp : R.drawable.ic_link_off_white_24dp); mBuilder.setSmallIcon(connected > 0 ? R.drawable.ic_link_white_24dp : R.drawable.ic_link_off_white_24dp);
@ -920,7 +925,11 @@ public class NotificationService {
} }
private PendingIntent createOpenConversationsIntent() { private PendingIntent createOpenConversationsIntent() {
try {
return PendingIntent.getActivity(mXmppConnectionService, 0, new Intent(mXmppConnectionService, ConversationsActivity.class), 0); return PendingIntent.getActivity(mXmppConnectionService, 0, new Intent(mXmppConnectionService, ConversationsActivity.class), 0);
} catch (RuntimeException e) {
return null;
}
} }
void updateErrorNotification() { void updateErrorNotification() {