From 9d5d43cf3af13de8e4ff3163bf3275ba882bc3a3 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Sun, 4 Feb 2018 11:26:02 -0800 Subject: [PATCH] Wait to process messages until after migration when screenlocked Fixes #7390 --- res/values/strings.xml | 2 ++ .../securesms/DatabaseUpgradeActivity.java | 4 ++++ .../securesms/jobs/PushDecryptJob.java | 22 ++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 09a782142b..edcd6ac31b 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1318,6 +1318,8 @@ Signal needs Contacts permission in order to search your contacts, but it has been permanently denied. Please continue to app settings, select \"Permissions\", and enable \"Contacts\". ENABLE SIGNAL MESSAGES Migrating Signal database + New locked message + Unlock to view pending messages diff --git a/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java b/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java index 697c30b197..c09e8f8135 100644 --- a/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java +++ b/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java @@ -275,6 +275,10 @@ public class DatabaseUpgradeActivity extends BaseActivity { } } + if (params[0] < SQLCIPHER) { + scheduleMessagesInPushDatabase(context); + } + return null; } diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 03cbf5749d..869b9cccfa 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -1,13 +1,19 @@ package org.thoughtcrime.securesms.jobs; +import android.app.Notification; +import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Build; import android.support.annotation.NonNull; +import android.support.v4.app.NotificationCompat; +import android.support.v4.app.NotificationManagerCompat; import android.util.Log; import android.util.Pair; import org.thoughtcrime.securesms.ApplicationContext; +import org.thoughtcrime.securesms.ConversationListActivity; +import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.attachments.DatabaseAttachment; import org.thoughtcrime.securesms.attachments.PointerAttachment; import org.thoughtcrime.securesms.crypto.IdentityKeyUtil; @@ -112,12 +118,26 @@ public class PushDecryptJob extends ContextJob { @Override public void onRun() throws NoSuchMessageException { - if (!IdentityKeyUtil.hasIdentityKey(context)) { Log.w(TAG, "Skipping job, waiting for migration..."); return; } + if (TextSecurePreferences.getNeedsSqlCipherMigration(context)) { + Log.w(TAG, "Skipping job, waiting for sqlcipher migration..."); + NotificationManagerCompat.from(context).notify(494949, + new NotificationCompat.Builder(context) + .setSmallIcon(R.drawable.icon_notification) + .setPriority(NotificationCompat.PRIORITY_HIGH) + .setCategory(NotificationCompat.CATEGORY_MESSAGE) + .setContentTitle(context.getString(R.string.PushDecryptJob_new_locked_message)) + .setContentText(context.getString(R.string.PushDecryptJob_unlock_to_view_pending_messages)) + .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, ConversationListActivity.class), 0)) + .setDefaults(NotificationCompat.DEFAULT_SOUND | NotificationCompat.DEFAULT_VIBRATE) + .build()); + return; + } + PushDatabase database = DatabaseFactory.getPushDatabase(context); SignalServiceEnvelope envelope = database.get(messageId); Optional optionalSmsMessageId = smsMessageId > 0 ? Optional.of(smsMessageId) : Optional.absent();