From 2a88de3f610ff33b1397eacdbb666770b46c017f Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 26 Jun 2020 16:18:19 +1000 Subject: [PATCH] move old message notifier to optimized message notifier --- .../securesms/ApplicationContext.java | 8 +++++- .../securesms/ConversationListActivity.java | 2 +- .../securesms/ConversationListFragment.java | 17 ++++++----- .../securesms/DatabaseUpgradeActivity.java | 2 +- .../securesms/MessageDetailsActivity.java | 4 +-- .../conversation/ConversationActivity.java | 6 ++-- .../database/helpers/ClassicOpenHelper.java | 3 +- .../groups/GroupMessageProcessor.java | 2 +- .../securesms/jobs/AttachmentDownloadJob.java | 3 +- .../securesms/jobs/MmsDownloadJob.java | 11 +++++--- .../securesms/jobs/MmsSendJob.java | 3 +- .../securesms/jobs/PushDecryptJob.java | 28 +++++++++++-------- .../securesms/jobs/PushSendJob.java | 2 +- .../securesms/jobs/PushTextSendJob.java | 4 +-- .../securesms/jobs/SmsReceiveJob.java | 3 +- .../securesms/jobs/SmsSendJob.java | 5 ++-- .../securesms/jobs/SmsSentJob.java | 2 +- .../securesms/loki/activities/HomeActivity.kt | 4 +-- .../AndroidAutoHeardReceiver.java | 3 +- .../AndroidAutoReplyReceiver.java | 3 +- .../DeleteNotificationReceiver.java | 3 +- .../notifications/MarkReadReceiver.java | 2 +- .../notifications/RemoteReplyReceiver.java | 5 ++-- .../SingleRecipientNotificationBuilder.java | 4 +-- .../NotificationsPreferenceFragment.java | 2 +- .../securesms/service/KeyCachingService.java | 4 +-- .../securesms/service/WebRtcCallService.java | 2 +- .../securesms/util/IdentityUtil.java | 3 +- 28 files changed, 83 insertions(+), 57 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index 3121f02dd5..32f464b1f6 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -69,8 +69,10 @@ import org.thoughtcrime.securesms.loki.protocol.EphemeralMessage; import org.thoughtcrime.securesms.loki.protocol.LokiSessionResetImplementation; import org.thoughtcrime.securesms.loki.protocol.PushEphemeralMessageSendJob; import org.thoughtcrime.securesms.loki.utilities.Broadcaster; +import org.thoughtcrime.securesms.notifications.DefaultMessageNotifier; import org.thoughtcrime.securesms.notifications.MessageNotifier; import org.thoughtcrime.securesms.notifications.NotificationChannels; +import org.thoughtcrime.securesms.notifications.OptimizedMessageNotifier; import org.thoughtcrime.securesms.profiles.AvatarHelper; import org.thoughtcrime.securesms.providers.BlobProvider; import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess; @@ -148,6 +150,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc private PersistentLogger persistentLogger; // Loki + public MessageNotifier messageNotifier = null; public LokiPoller lokiPoller = null; public LokiPublicChatManager lokiPublicChatManager = null; private LokiPublicChatAPI lokiPublicChatAPI = null; @@ -173,6 +176,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc ProcessLifecycleOwner.get().getLifecycle().addObserver(this); // Loki // ======== + messageNotifier = new OptimizedMessageNotifier(new DefaultMessageNotifier()); broadcaster = new Broadcaster(this); LokiAPIDatabase apiDB = DatabaseFactory.getLokiAPIDatabase(this); LokiThreadDatabase threadDB = DatabaseFactory.getLokiThreadDatabase(this); @@ -222,7 +226,9 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc executePendingContactSync(); KeyCachingService.onAppForegrounded(this); // Loki + if (lokiPoller != null) { lokiPoller.shouldCatchUp(); } startPollingIfNeeded(); + lokiPublicChatManager.shouldAllCatchUp(); lokiPublicChatManager.startPollersIfNeeded(); } @@ -231,7 +237,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc isAppVisible = false; Log.i(TAG, "App is no longer visible."); KeyCachingService.onAppBackgrounded(this); - MessageNotifier.setVisibleThread(-1); + messageNotifier.setVisibleThread(-1); // Loki if (lokiPoller != null) { lokiPoller.stopIfNeeded(); } if (lokiPublicChatManager != null) { lokiPublicChatManager.stopPollers(); } diff --git a/src/org/thoughtcrime/securesms/ConversationListActivity.java b/src/org/thoughtcrime/securesms/ConversationListActivity.java index 49fc125778..2d9828705d 100644 --- a/src/org/thoughtcrime/securesms/ConversationListActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationListActivity.java @@ -298,7 +298,7 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit Context context = ConversationListActivity.this; List messageIds = DatabaseFactory.getThreadDatabase(context).setAllThreadsRead(); - MessageNotifier.updateNotification(context); + ApplicationContext.getInstance(context).messageNotifier.updateNotification(context); MarkReadReceiver.process(context, messageIds); return null; diff --git a/src/org/thoughtcrime/securesms/ConversationListFragment.java b/src/org/thoughtcrime/securesms/ConversationListFragment.java index d96d9860b7..27fb781e5a 100644 --- a/src/org/thoughtcrime/securesms/ConversationListFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationListFragment.java @@ -324,8 +324,9 @@ public class ConversationListFragment extends Fragment @Override protected Void doInBackground(Void... params) { - DatabaseFactory.getThreadDatabase(getActivity()).deleteConversations(selectedConversations); - MessageNotifier.updateNotification(getActivity()); + Context context = getActivity(); + DatabaseFactory.getThreadDatabase(context).deleteConversations(selectedConversations); + ApplicationContext.getInstance(context).messageNotifier.updateNotification(context); return null; } @@ -542,9 +543,10 @@ public class ConversationListFragment extends Fragment DatabaseFactory.getThreadDatabase(getActivity()).archiveConversation(threadId); if (unreadCount > 0) { - List messageIds = DatabaseFactory.getThreadDatabase(getActivity()).setRead(threadId, false); - MessageNotifier.updateNotification(getActivity()); - MarkReadReceiver.process(getActivity(), messageIds); + Context context = getActivity(); + List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, false); + ApplicationContext.getInstance(context).messageNotifier.updateNotification(context); + MarkReadReceiver.process(context, messageIds); } } @@ -553,8 +555,9 @@ public class ConversationListFragment extends Fragment DatabaseFactory.getThreadDatabase(getActivity()).unarchiveConversation(threadId); if (unreadCount > 0) { - DatabaseFactory.getThreadDatabase(getActivity()).incrementUnread(threadId, unreadCount); - MessageNotifier.updateNotification(getActivity()); + Context context = getActivity(); + DatabaseFactory.getThreadDatabase(context).incrementUnread(threadId, unreadCount); + ApplicationContext.getInstance(context).messageNotifier.updateNotification(context); } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, threadId); diff --git a/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java b/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java index ad9bfcb85e..1e6f34a855 100644 --- a/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java +++ b/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java @@ -176,7 +176,7 @@ public class DatabaseUpgradeActivity extends BaseActivity { new AsyncTask() { @Override protected Void doInBackground(Void... params) { - MessageNotifier.updateNotification(context); + ApplicationContext.getInstance(context).messageNotifier.updateNotification(context); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); diff --git a/src/org/thoughtcrime/securesms/MessageDetailsActivity.java b/src/org/thoughtcrime/securesms/MessageDetailsActivity.java index 147299bbe0..818a3d6669 100644 --- a/src/org/thoughtcrime/securesms/MessageDetailsActivity.java +++ b/src/org/thoughtcrime/securesms/MessageDetailsActivity.java @@ -133,13 +133,13 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity assert getSupportActionBar() != null; getSupportActionBar().setTitle("Message Details"); - MessageNotifier.setVisibleThread(threadId); + ApplicationContext.getInstance(this).messageNotifier.setVisibleThread(threadId); } @Override protected void onPause() { super.onPause(); - MessageNotifier.setVisibleThread(-1L); + ApplicationContext.getInstance(this).messageNotifier.setVisibleThread(-1L); } @Override diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index f85b0df933..a18509f92b 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -550,7 +550,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity setGroupShareProfileReminder(recipient); calculateCharactersRemaining(); - MessageNotifier.setVisibleThread(threadId); + ApplicationContext.getInstance(this).messageNotifier.setVisibleThread(threadId); markThreadAsRead(); DatabaseFactory.getLokiThreadDatabase(this).setDelegate(this); @@ -565,7 +565,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity @Override protected void onPause() { super.onPause(); - MessageNotifier.setVisibleThread(-1L); + ApplicationContext.getInstance(this).messageNotifier.setVisibleThread(-1L); if (isFinishing()) overridePendingTransition(R.anim.fade_scale_in, R.anim.slide_to_right); inputPanel.onPause(); @@ -2244,7 +2244,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity if (refreshFragment) { fragment.reload(recipient, threadId); - MessageNotifier.setVisibleThread(threadId); + ApplicationContext.getInstance(this).messageNotifier.setVisibleThread(threadId); } fragment.scrollToBottom(); diff --git a/src/org/thoughtcrime/securesms/database/helpers/ClassicOpenHelper.java b/src/org/thoughtcrime/securesms/database/helpers/ClassicOpenHelper.java index 8eb29d3509..7c9fe9974e 100644 --- a/src/org/thoughtcrime/securesms/database/helpers/ClassicOpenHelper.java +++ b/src/org/thoughtcrime/securesms/database/helpers/ClassicOpenHelper.java @@ -12,6 +12,7 @@ import android.text.TextUtils; import com.fasterxml.jackson.annotation.JsonProperty; +import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.DatabaseUpgradeActivity; import org.thoughtcrime.securesms.crypto.AttachmentSecret; import org.thoughtcrime.securesms.crypto.ClassicDecryptingPartInputStream; @@ -423,7 +424,7 @@ public class ClassicOpenHelper extends SQLiteOpenHelper { db.endTransaction(); // DecryptingQueue.schedulePendingDecrypts(context, masterSecret); - MessageNotifier.updateNotification(context); + ApplicationContext.getInstance(context).messageNotifier.updateNotification(context); } @Override diff --git a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java index 5dacafdd65..6ccb3279d9 100644 --- a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java +++ b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java @@ -281,7 +281,7 @@ public class GroupMessageProcessor { Optional insertResult = smsDatabase.insertMessageInbox(groupMessage); if (insertResult.isPresent()) { - MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); + ApplicationContext.getInstance(context).messageNotifier.updateNotification(context, insertResult.get().getThreadId()); return insertResult.get().getThreadId(); } else { return null; diff --git a/src/org/thoughtcrime/securesms/jobs/AttachmentDownloadJob.java b/src/org/thoughtcrime/securesms/jobs/AttachmentDownloadJob.java index 5b4b7809ca..5b34dc2f71 100644 --- a/src/org/thoughtcrime/securesms/jobs/AttachmentDownloadJob.java +++ b/src/org/thoughtcrime/securesms/jobs/AttachmentDownloadJob.java @@ -5,6 +5,7 @@ import android.support.annotation.VisibleForTesting; import android.text.TextUtils; import org.greenrobot.eventbus.EventBus; +import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.attachments.Attachment; import org.thoughtcrime.securesms.attachments.AttachmentId; import org.thoughtcrime.securesms.attachments.DatabaseAttachment; @@ -107,7 +108,7 @@ public class AttachmentDownloadJob extends BaseJob implements InjectableType { @Override public void onRun() throws IOException { doWork(); - MessageNotifier.updateNotification(context, 0); + ApplicationContext.getInstance(context).messageNotifier.updateNotification(context, 0); } public void doWork() throws IOException { diff --git a/src/org/thoughtcrime/securesms/jobs/MmsDownloadJob.java b/src/org/thoughtcrime/securesms/jobs/MmsDownloadJob.java index 47411c08f0..5b1d81abcc 100644 --- a/src/org/thoughtcrime/securesms/jobs/MmsDownloadJob.java +++ b/src/org/thoughtcrime/securesms/jobs/MmsDownloadJob.java @@ -10,6 +10,7 @@ import com.google.android.mms.pdu_alt.PduBody; import com.google.android.mms.pdu_alt.PduPart; import com.google.android.mms.pdu_alt.RetrieveConf; +import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.attachments.Attachment; import org.thoughtcrime.securesms.attachments.UriAttachment; import org.thoughtcrime.securesms.database.Address; @@ -57,6 +58,7 @@ public class MmsDownloadJob extends BaseJob { private long messageId; private long threadId; private boolean automatic; + private MessageNotifier messageNotifier; public MmsDownloadJob(long messageId, long threadId, boolean automatic) { this(new Job.Parameters.Builder() @@ -75,6 +77,7 @@ public class MmsDownloadJob extends BaseJob { this.messageId = messageId; this.threadId = threadId; this.automatic = automatic; + this.messageNotifier = ApplicationContext.getInstance(context).messageNotifier; } @Override @@ -94,7 +97,7 @@ public class MmsDownloadJob extends BaseJob { public void onAdded() { if (automatic && KeyCachingService.isLocked(context)) { DatabaseFactory.getMmsDatabase(context).markIncomingNotificationReceived(threadId); - MessageNotifier.updateNotification(context); + messageNotifier.updateNotification(context); } } @@ -177,7 +180,7 @@ public class MmsDownloadJob extends BaseJob { if (automatic) { database.markIncomingNotificationReceived(threadId); - MessageNotifier.updateNotification(context, threadId); + messageNotifier.updateNotification(context, threadId); } } @@ -252,7 +255,7 @@ public class MmsDownloadJob extends BaseJob { if (insertResult.isPresent()) { database.delete(messageId); - MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); + messageNotifier.updateNotification(context, insertResult.get().getThreadId()); } } @@ -264,7 +267,7 @@ public class MmsDownloadJob extends BaseJob { if (automatic) { db.markIncomingNotificationReceived(threadId); - MessageNotifier.updateNotification(context, threadId); + messageNotifier.updateNotification(context, threadId); } } diff --git a/src/org/thoughtcrime/securesms/jobs/MmsSendJob.java b/src/org/thoughtcrime/securesms/jobs/MmsSendJob.java index 315e13ad64..e3005573e3 100644 --- a/src/org/thoughtcrime/securesms/jobs/MmsSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/MmsSendJob.java @@ -19,6 +19,7 @@ import com.google.android.mms.pdu_alt.SendReq; import com.google.android.mms.smil.SmilHelper; import com.klinker.android.send_message.Utils; +import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.attachments.Attachment; import org.thoughtcrime.securesms.database.Address; import org.thoughtcrime.securesms.database.DatabaseFactory; @@ -304,7 +305,7 @@ public class MmsSendJob extends SendJob { Recipient recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId); if (recipient != null) { - MessageNotifier.notifyMessageDeliveryFailed(context, recipient, threadId); + ApplicationContext.getInstance(context).messageNotifier.notifyMessageDeliveryFailed(context, recipient, threadId); } } diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 9f90b19ed0..44e29fd1c8 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -159,6 +159,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType { private long messageId; private long smsMessageId; + //Loki + private MessageNotifier messageNotifier; + @Inject SignalServiceMessageSender messageSender; private Address author; @@ -178,6 +181,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { pushMessageId, smsMessageId); setContext(context); + this.messageNotifier = ApplicationContext.getInstance(context).messageNotifier; } private PushDecryptJob(@NonNull Job.Parameters parameters, long pushMessageId, long smsMessageId) { @@ -546,7 +550,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { if (threadId != null) { SessionManagementProtocol.handleEndSessionMessageIfNeeded(context, content); - MessageNotifier.updateNotification(context, threadId); + messageNotifier.updateNotification(context, threadId); } } @@ -709,10 +713,10 @@ public class PushDecryptJob extends BaseJob implements InjectableType { if (threadId != null) { DatabaseFactory.getThreadDatabase(context).setRead(threadId, true); - MessageNotifier.updateNotification(context); + messageNotifier.updateNotification(context); } - MessageNotifier.setLastDesktopActivityTimestamp(message.getTimestamp()); + messageNotifier.setLastDesktopActivityTimestamp(message.getTimestamp()); } catch (MmsException e) { throw new StorageFailedException(e, content.getSender(), content.getSenderDevice()); } @@ -775,9 +779,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType { } } - MessageNotifier.setLastDesktopActivityTimestamp(envelopeTimestamp); - MessageNotifier.cancelDelayedNotifications(); - MessageNotifier.updateNotification(context); + messageNotifier.setLastDesktopActivityTimestamp(envelopeTimestamp); + messageNotifier.cancelDelayedNotifications(); + messageNotifier.updateNotification(context); } public void handleMediaMessage(@NonNull SignalServiceContent content, @@ -843,7 +847,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { } if (insertResult.isPresent()) { - MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); + messageNotifier.updateNotification(context, insertResult.get().getThreadId()); } // Loki - Store message open group server ID if needed @@ -1015,7 +1019,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get()); if (threadId != null) { - MessageNotifier.updateNotification(context, threadId); + messageNotifier.updateNotification(context, threadId); } if (insertResult.isPresent()) { @@ -1116,7 +1120,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { if (insertResult.isPresent()) { smsDatabase.markAsInvalidVersionKeyExchange(insertResult.get().getMessageId()); - MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); + messageNotifier.updateNotification(context, insertResult.get().getThreadId()); } } else { smsDatabase.markAsInvalidVersionKeyExchange(smsMessageId.get()); @@ -1133,7 +1137,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { if (insertResult.isPresent()) { smsDatabase.markAsDecryptFailed(insertResult.get().getMessageId()); - MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); + messageNotifier.updateNotification(context, insertResult.get().getThreadId()); } } else { smsDatabase.markAsDecryptFailed(smsMessageId.get()); @@ -1151,7 +1155,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { if (insertResult.isPresent()) { smsDatabase.markAsNoSession(insertResult.get().getMessageId()); - MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); + messageNotifier.updateNotification(context, insertResult.get().getThreadId()); } } else { smsDatabase.markAsNoSession(smsMessageId.get()); @@ -1169,7 +1173,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { if (insertResult.isPresent()) { smsDatabase.markAsLegacyVersion(insertResult.get().getMessageId()); - MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); + messageNotifier.updateNotification(context, insertResult.get().getThreadId()); } } else { smsDatabase.markAsLegacyVersion(smsMessageId.get()); diff --git a/src/org/thoughtcrime/securesms/jobs/PushSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushSendJob.java index 3d0eb2e259..b3551572fe 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushSendJob.java @@ -182,7 +182,7 @@ public abstract class PushSendJob extends SendJob { Recipient recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId); if (threadId != -1 && recipient != null) { - MessageNotifier.notifyMessageDeliveryFailed(context, recipient, threadId); + ApplicationContext.getInstance(context).messageNotifier.notifyMessageDeliveryFailed(context, recipient, threadId); } } diff --git a/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java index 3d018d14dc..fbb3a068b8 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java @@ -164,7 +164,7 @@ public class PushTextSendJob extends PushSendJob implements InjectableType { warn(TAG, "Couldn't send message due to error: ", e); if (messageId >= 0) { database.markAsPendingInsecureSmsFallback(record.getId()); - MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId()); + ApplicationContext.getInstance(context).messageNotifier.notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId()); } } catch (UntrustedIdentityException e) { warn(TAG, "Couldn't send message due to error: ", e); @@ -198,7 +198,7 @@ public class PushTextSendJob extends PushSendJob implements InjectableType { Recipient recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId); if (threadId != -1 && recipient != null) { - MessageNotifier.notifyMessageDeliveryFailed(context, recipient, threadId); + ApplicationContext.getInstance(context).messageNotifier.notifyMessageDeliveryFailed(context, recipient, threadId); } } } diff --git a/src/org/thoughtcrime/securesms/jobs/SmsReceiveJob.java b/src/org/thoughtcrime/securesms/jobs/SmsReceiveJob.java index 69a6e5c12b..e6463eb11e 100644 --- a/src/org/thoughtcrime/securesms/jobs/SmsReceiveJob.java +++ b/src/org/thoughtcrime/securesms/jobs/SmsReceiveJob.java @@ -4,6 +4,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.telephony.SmsMessage; +import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.jobmanager.Data; import org.thoughtcrime.securesms.jobmanager.Job; import org.thoughtcrime.securesms.jobmanager.impl.SqlCipherMigrationConstraint; @@ -79,7 +80,7 @@ public class SmsReceiveJob extends BaseJob { Optional insertResult = storeMessage(message.get()); if (insertResult.isPresent()) { - MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); + ApplicationContext.getInstance(context).messageNotifier.updateNotification(context, insertResult.get().getThreadId()); } } else if (message.isPresent()) { Log.w(TAG, "*** Received blocked SMS, ignoring..."); diff --git a/src/org/thoughtcrime/securesms/jobs/SmsSendJob.java b/src/org/thoughtcrime/securesms/jobs/SmsSendJob.java index 282099393b..ed4ebcfdf4 100644 --- a/src/org/thoughtcrime/securesms/jobs/SmsSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/SmsSendJob.java @@ -9,6 +9,7 @@ import android.support.annotation.NonNull; import android.telephony.PhoneNumberUtils; import android.telephony.SmsManager; +import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.jobmanager.Data; import org.thoughtcrime.securesms.jobmanager.Job; import org.thoughtcrime.securesms.jobmanager.impl.NetworkOrCellServiceConstraint; @@ -88,7 +89,7 @@ public class SmsSendJob extends SendJob { } catch (UndeliverableMessageException ude) { warn(TAG, ude); DatabaseFactory.getSmsDatabase(context).markAsSentFailed(record.getId()); - MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId()); + ApplicationContext.getInstance(context).messageNotifier.notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId()); } } @@ -106,7 +107,7 @@ public class SmsSendJob extends SendJob { DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageId); if (threadId != -1 && recipient != null) { - MessageNotifier.notifyMessageDeliveryFailed(context, recipient, threadId); + ApplicationContext.getInstance(context).messageNotifier.notifyMessageDeliveryFailed(context, recipient, threadId); } } diff --git a/src/org/thoughtcrime/securesms/jobs/SmsSentJob.java b/src/org/thoughtcrime/securesms/jobs/SmsSentJob.java index cadecd0b81..43fc8d4170 100644 --- a/src/org/thoughtcrime/securesms/jobs/SmsSentJob.java +++ b/src/org/thoughtcrime/securesms/jobs/SmsSentJob.java @@ -108,7 +108,7 @@ public class SmsSentJob extends BaseJob { break; default: database.markAsSentFailed(messageId); - MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId()); + ApplicationContext.getInstance(context).messageNotifier.notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId()); } } catch (NoSuchMessageException e) { Log.w(TAG, e); diff --git a/src/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt b/src/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt index 5a4ab5d8bc..2921dc1108 100644 --- a/src/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt @@ -78,7 +78,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe val threadID = archivedConversations.getLong(archivedConversations.getColumnIndex(ThreadDatabase.ID)) AsyncTask.execute { threadDatabase.deleteConversation(threadID) - MessageNotifier.updateNotification(this) + (applicationContext as ApplicationContext).messageNotifier.updateNotification(this) } } deleteThreadAtCurrentPosition() @@ -314,7 +314,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe ApplicationContext.getInstance(activity).lokiPublicChatAPI!!.leave(publicChat.channel, publicChat.server) } threadDatabase.deleteConversation(threadID) - MessageNotifier.updateNotification(activity) + ApplicationContext.getInstance(activity).messageNotifier.updateNotification(activity) } } } diff --git a/src/org/thoughtcrime/securesms/notifications/AndroidAutoHeardReceiver.java b/src/org/thoughtcrime/securesms/notifications/AndroidAutoHeardReceiver.java index dfa974a1f8..c77e2753b7 100644 --- a/src/org/thoughtcrime/securesms/notifications/AndroidAutoHeardReceiver.java +++ b/src/org/thoughtcrime/securesms/notifications/AndroidAutoHeardReceiver.java @@ -24,6 +24,7 @@ import android.content.Intent; import android.os.AsyncTask; import android.support.v4.app.NotificationManagerCompat; +import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo; import org.whispersystems.libsignal.logging.Log; @@ -66,7 +67,7 @@ public class AndroidAutoHeardReceiver extends BroadcastReceiver { messageIdsCollection.addAll(messageIds); } - MessageNotifier.updateNotification(context); + ApplicationContext.getInstance(context).messageNotifier.updateNotification(context); MarkReadReceiver.process(context, messageIdsCollection); return null; diff --git a/src/org/thoughtcrime/securesms/notifications/AndroidAutoReplyReceiver.java b/src/org/thoughtcrime/securesms/notifications/AndroidAutoReplyReceiver.java index d196fe432e..d55df50a33 100644 --- a/src/org/thoughtcrime/securesms/notifications/AndroidAutoReplyReceiver.java +++ b/src/org/thoughtcrime/securesms/notifications/AndroidAutoReplyReceiver.java @@ -25,6 +25,7 @@ import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.RemoteInput; +import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.database.Address; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo; @@ -86,7 +87,7 @@ public class AndroidAutoReplyReceiver extends BroadcastReceiver { List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(replyThreadId, true); - MessageNotifier.updateNotification(context); + ApplicationContext.getInstance(context).messageNotifier.updateNotification(context); MarkReadReceiver.process(context, messageIds); return null; diff --git a/src/org/thoughtcrime/securesms/notifications/DeleteNotificationReceiver.java b/src/org/thoughtcrime/securesms/notifications/DeleteNotificationReceiver.java index ea065fd18a..ed2727f647 100644 --- a/src/org/thoughtcrime/securesms/notifications/DeleteNotificationReceiver.java +++ b/src/org/thoughtcrime/securesms/notifications/DeleteNotificationReceiver.java @@ -6,6 +6,7 @@ import android.content.Context; import android.content.Intent; import android.os.AsyncTask; +import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.database.DatabaseFactory; public class DeleteNotificationReceiver extends BroadcastReceiver { @@ -18,7 +19,7 @@ public class DeleteNotificationReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, Intent intent) { if (DELETE_NOTIFICATION_ACTION.equals(intent.getAction())) { - MessageNotifier.clearReminder(context); + ApplicationContext.getInstance(context).messageNotifier.clearReminder(context); final long[] ids = intent.getLongArrayExtra(EXTRA_IDS); final boolean[] mms = intent.getBooleanArrayExtra(EXTRA_MMS); diff --git a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java index 04aa6d8ead..6e5c32bf0f 100644 --- a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java +++ b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java @@ -61,7 +61,7 @@ public class MarkReadReceiver extends BroadcastReceiver { process(context, messageIdsCollection); - MessageNotifier.updateNotification(context); + ApplicationContext.getInstance(context).messageNotifier.updateNotification(context); return null; } diff --git a/src/org/thoughtcrime/securesms/notifications/RemoteReplyReceiver.java b/src/org/thoughtcrime/securesms/notifications/RemoteReplyReceiver.java index 7b42d10aca..84ff4c1664 100644 --- a/src/org/thoughtcrime/securesms/notifications/RemoteReplyReceiver.java +++ b/src/org/thoughtcrime/securesms/notifications/RemoteReplyReceiver.java @@ -25,6 +25,7 @@ import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.RemoteInput; +import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.database.Address; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo; @@ -59,7 +60,7 @@ public class RemoteReplyReceiver extends BroadcastReceiver { final Address address = intent.getParcelableExtra(ADDRESS_EXTRA); final ReplyMethod replyMethod = (ReplyMethod) intent.getSerializableExtra(REPLY_METHOD); - final CharSequence responseText = remoteInput.getCharSequence(MessageNotifier.EXTRA_REMOTE_REPLY); + final CharSequence responseText = remoteInput.getCharSequence(DefaultMessageNotifier.EXTRA_REMOTE_REPLY); if (address == null) throw new AssertionError("No address specified"); if (replyMethod == null) throw new AssertionError("No reply method specified"); @@ -91,7 +92,7 @@ public class RemoteReplyReceiver extends BroadcastReceiver { List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true); - MessageNotifier.updateNotification(context); + ApplicationContext.getInstance(context).messageNotifier.updateNotification(context); MarkReadReceiver.process(context, messageIds); return null; diff --git a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java index 7f8bf3abc9..0476cdff2f 100644 --- a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java +++ b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java @@ -177,14 +177,14 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil replyAction = new Action.Builder(R.drawable.ic_reply_white_36dp, actionName, wearableReplyIntent) - .addRemoteInput(new RemoteInput.Builder(MessageNotifier.EXTRA_REMOTE_REPLY).setLabel(label).build()) + .addRemoteInput(new RemoteInput.Builder(DefaultMessageNotifier.EXTRA_REMOTE_REPLY).setLabel(label).build()) .build(); } Action wearableReplyAction = new Action.Builder(R.drawable.ic_reply, actionName, wearableReplyIntent) - .addRemoteInput(new RemoteInput.Builder(MessageNotifier.EXTRA_REMOTE_REPLY).setLabel(label).build()) + .addRemoteInput(new RemoteInput.Builder(DefaultMessageNotifier.EXTRA_REMOTE_REPLY).setLabel(label).build()) .build(); diff --git a/src/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java b/src/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java index 9b21b90dad..b3ddb9cd1b 100644 --- a/src/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java +++ b/src/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java @@ -220,7 +220,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme new AsyncTask() { @Override protected Void doInBackground(Void... params) { - MessageNotifier.updateNotification(getActivity()); + ApplicationContext.getInstance(getActivity()).messageNotifier.updateNotification(getActivity()); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); diff --git a/src/org/thoughtcrime/securesms/service/KeyCachingService.java b/src/org/thoughtcrime/securesms/service/KeyCachingService.java index 796249b659..b07710e730 100644 --- a/src/org/thoughtcrime/securesms/service/KeyCachingService.java +++ b/src/org/thoughtcrime/securesms/service/KeyCachingService.java @@ -115,7 +115,7 @@ public class KeyCachingService extends Service { @Override protected Void doInBackground(Void... params) { if (!DatabaseUpgradeActivity.isUpdate(KeyCachingService.this)) { - MessageNotifier.updateNotification(KeyCachingService.this); + ApplicationContext.getInstance(KeyCachingService.this).messageNotifier.updateNotification(KeyCachingService.this); } return null; } @@ -188,7 +188,7 @@ public class KeyCachingService extends Service { new AsyncTask() { @Override protected Void doInBackground(Void... params) { - MessageNotifier.updateNotification(KeyCachingService.this); + ApplicationContext.getInstance(KeyCachingService.this).messageNotifier.updateNotification(KeyCachingService.this); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); diff --git a/src/org/thoughtcrime/securesms/service/WebRtcCallService.java b/src/org/thoughtcrime/securesms/service/WebRtcCallService.java index 0de3ac406f..855b327131 100644 --- a/src/org/thoughtcrime/securesms/service/WebRtcCallService.java +++ b/src/org/thoughtcrime/securesms/service/WebRtcCallService.java @@ -721,7 +721,7 @@ public class WebRtcCallService extends Service implements InjectableType, private void insertMissedCall(@NonNull Recipient recipient, boolean signal) { Pair messageAndThreadId = DatabaseFactory.getSmsDatabase(this).insertMissedCall(recipient.getAddress()); - MessageNotifier.updateNotification(this, messageAndThreadId.second, signal); + ApplicationContext.getInstance(this).messageNotifier.updateNotification(this, messageAndThreadId.second, signal); } private void handleAnswerCall(Intent intent) { diff --git a/src/org/thoughtcrime/securesms/util/IdentityUtil.java b/src/org/thoughtcrime/securesms/util/IdentityUtil.java index ae712c9f71..fe5542e9a5 100644 --- a/src/org/thoughtcrime/securesms/util/IdentityUtil.java +++ b/src/org/thoughtcrime/securesms/util/IdentityUtil.java @@ -6,6 +6,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.StringRes; +import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.crypto.storage.TextSecureIdentityKeyStore; import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore; import org.thoughtcrime.securesms.database.Address; @@ -143,7 +144,7 @@ public class IdentityUtil { Optional insertResult = smsDatabase.insertMessageInbox(individualUpdate); if (insertResult.isPresent()) { - MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); + ApplicationContext.getInstance(context).messageNotifier.updateNotification(context, insertResult.get().getThreadId()); } }