Skip to content

Commit

Permalink
Don't redisplay notifications after they have been dismissed
Browse files Browse the repository at this point in the history
Fixes signalapp#5751
Fixes signalapp#6218
// FREEBIE
  • Loading branch information
moxie0 committed Mar 14, 2017
1 parent 33e0b4f commit 2f46c6c
Show file tree
Hide file tree
Showing 18 changed files with 141 additions and 88 deletions.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,9 @@
</intent-filter>
</receiver>

<receiver android:name=".notifications.MessageNotifier$DeleteReceiver">
<receiver android:name=".notifications.DeleteNotificationReceiver">
<intent-filter>
<action android:name="org.thoughtcrime.securesms.MessageNotifier.DELETE_REMINDER_ACTION"/>
<action android:name="org.thoughtcrime.securesms.DELETE_NOTIFICATION"/>
</intent-filter>
</receiver>

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.0'
classpath files('libs/gradle-witness.jar')
}
}
Expand Down Expand Up @@ -189,7 +189,7 @@ dependencyVerification {

android {
compileSdkVersion 25
buildToolsVersion '23.0.3'
buildToolsVersion '25.0.0'
useLibrary 'org.apache.http.legacy'

dexOptions {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
2 changes: 1 addition & 1 deletion src/org/thoughtcrime/redphone/RedPhoneService.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private void handleBusyCall(Intent intent) {
private void handleMissedCall(String remoteNumber, boolean signal) {
Pair<Long, Long> messageAndThreadId = DatabaseFactory.getSmsDatabase(this).insertMissedCall(remoteNumber);
MessageNotifier.updateNotification(this, KeyCachingService.getMasterSecret(this),
false, messageAndThreadId.second, signal);
messageAndThreadId.second, signal);
}

private void handleAnswerCall(Intent intent) {
Expand Down
14 changes: 13 additions & 1 deletion src/org/thoughtcrime/securesms/database/DatabaseFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public class DatabaseFactory {
private static final int INTRODUCED_EXPIRE_MESSAGES_VERSION = 28;
private static final int INTRODUCED_LAST_SEEN = 29;
private static final int INTRODUCED_DIGEST = 30;
private static final int DATABASE_VERSION = 30;
private static final int INTRODUCED_NOTIFIED = 31;
private static final int DATABASE_VERSION = 31;

private static final String DATABASE_NAME = "messages.db";
private static final Object lock = new Object();
Expand Down Expand Up @@ -841,6 +842,17 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("ALTER TABLE groups ADD COLUMN avatar_digest BLOB");
}

if (oldVersion < INTRODUCED_NOTIFIED) {
db.execSQL("ALTER TABLE sms ADD COLUMN notified INTEGER DEFAULT 0");
db.execSQL("ALTER TABLE mms ADD COLUMN notified INTEGER DEFAULT 0");

db.execSQL("DROP INDEX sms_read_and_thread_id_index");
db.execSQL("CREATE INDEX IF NOT EXISTS sms_read_and_notified_and_thread_id_index ON sms(read,notified,thread_id)");

db.execSQL("DROP INDEX mms_read_and_thread_id_index");
db.execSQL("CREATE INDEX IF NOT EXISTS mms_read_and_notified_and_thread_id_index ON mms(read,notified,thread_id)");
}

db.setTransactionSuccessful();
db.endTransaction();
}
Expand Down
15 changes: 12 additions & 3 deletions src/org/thoughtcrime/securesms/database/MmsDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ public class MmsDatabase extends MessagingDatabase {
RECEIPT_COUNT + " INTEGER DEFAULT 0, " + MISMATCHED_IDENTITIES + " TEXT DEFAULT NULL, " +
NETWORK_FAILURE + " TEXT DEFAULT NULL," + "d_rpt" + " INTEGER, " +
SUBSCRIPTION_ID + " INTEGER DEFAULT -1, " + EXPIRES_IN + " INTEGER DEFAULT 0, " +
EXPIRE_STARTED + " INTEGER DEFAULT 0);";
EXPIRE_STARTED + " INTEGER DEFAULT 0, " + NOTIFIED + " INTEGER DEFAULT 0);";

public static final String[] CREATE_INDEXS = {
"CREATE INDEX IF NOT EXISTS mms_thread_id_index ON " + TABLE_NAME + " (" + THREAD_ID + ");",
"CREATE INDEX IF NOT EXISTS mms_read_index ON " + TABLE_NAME + " (" + READ + ");",
"CREATE INDEX IF NOT EXISTS mms_read_and_thread_id_index ON " + TABLE_NAME + "(" + READ + "," + THREAD_ID + ");",
"CREATE INDEX IF NOT EXISTS mms_read_and_notified_and_thread_id_index ON " + TABLE_NAME + "(" + READ + "," + NOTIFIED + "," + THREAD_ID + ");",
"CREATE INDEX IF NOT EXISTS mms_message_box_index ON " + TABLE_NAME + " (" + MESSAGE_BOX + ");",
"CREATE INDEX IF NOT EXISTS mms_date_sent_index ON " + TABLE_NAME + " (" + DATE_SENT + ");",
"CREATE INDEX IF NOT EXISTS mms_thread_date_index ON " + TABLE_NAME + " (" + THREAD_ID + ", " + DATE_RECEIVED + ");"
Expand All @@ -133,7 +133,7 @@ public class MmsDatabase extends MessagingDatabase {
MESSAGE_SIZE, STATUS, TRANSACTION_ID,
BODY, PART_COUNT, ADDRESS, ADDRESS_DEVICE_ID,
RECEIPT_COUNT, MISMATCHED_IDENTITIES, NETWORK_FAILURE, SUBSCRIPTION_ID,
EXPIRES_IN, EXPIRE_STARTED,
EXPIRES_IN, EXPIRE_STARTED, NOTIFIED,
AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.ROW_ID + " AS " + AttachmentDatabase.ATTACHMENT_ID_ALIAS,
AttachmentDatabase.UNIQUE_ID,
AttachmentDatabase.MMS_ID,
Expand Down Expand Up @@ -458,6 +458,15 @@ public void markExpireStarted(long messageId, long startedTimestamp) {
notifyConversationListeners(threadId);
}

public void markAsNotified(long id) {
SQLiteDatabase database = databaseHelper.getWritableDatabase();
ContentValues contentValues = new ContentValues();

contentValues.put(NOTIFIED, 1);

database.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {String.valueOf(id)});
}

public List<MarkedMessageInfo> setMessagesRead(long threadId) {
SQLiteDatabase database = databaseHelper.getWritableDatabase();
String where = THREAD_ID + " = ? AND " + READ + " = 0";
Expand Down
1 change: 1 addition & 0 deletions src/org/thoughtcrime/securesms/database/MmsSmsColumns.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface MmsSmsColumns {
public static final String SUBSCRIPTION_ID = "subscription_id";
public static final String EXPIRES_IN = "expires_in";
public static final String EXPIRE_STARTED = "expire_started";
public static final String NOTIFIED = "notified";

public static class Types {
protected static final long TOTAL_MASK = 0xFFFFFFFF;
Expand Down
12 changes: 9 additions & 3 deletions src/org/thoughtcrime/securesms/database/MmsSmsDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public class MmsSmsDatabase extends Database {
MmsDatabase.NETWORK_FAILURE,
MmsSmsColumns.SUBSCRIPTION_ID,
MmsSmsColumns.EXPIRES_IN,
MmsSmsColumns.EXPIRE_STARTED, TRANSPORT,
MmsSmsColumns.EXPIRE_STARTED,
MmsSmsColumns.NOTIFIED,
TRANSPORT,
AttachmentDatabase.ATTACHMENT_ID_ALIAS,
AttachmentDatabase.UNIQUE_ID,
AttachmentDatabase.MMS_ID,
Expand Down Expand Up @@ -107,13 +109,13 @@ public Cursor getConversationSnippet(long threadId) {

public Cursor getUnread() {
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " ASC";
String selection = MmsSmsColumns.READ + " = 0";
String selection = MmsSmsColumns.READ + " = 0 AND " + MmsSmsColumns.NOTIFIED + " = 0";

return queryTables(PROJECTION, selection, order, null);
}

public int getUnreadCount(long threadId) {
String selection = MmsSmsColumns.READ + " = 0 AND " + MmsSmsColumns.THREAD_ID + " = " + threadId;
String selection = MmsSmsColumns.READ + " = 0 AND " + MmsSmsColumns.NOTIFIED + " = 0 AND " + MmsSmsColumns.THREAD_ID + " = " + threadId;
Cursor cursor = queryTables(PROJECTION, selection, null, null);

try {
Expand Down Expand Up @@ -150,6 +152,7 @@ private Cursor queryTables(String[] projection, String selection, String order,
MmsDatabase.MESSAGE_SIZE, MmsDatabase.EXPIRY, MmsDatabase.STATUS,
MmsSmsColumns.RECEIPT_COUNT, MmsSmsColumns.MISMATCHED_IDENTITIES,
MmsSmsColumns.SUBSCRIPTION_ID, MmsSmsColumns.EXPIRES_IN, MmsSmsColumns.EXPIRE_STARTED,
MmsSmsColumns.NOTIFIED,
MmsDatabase.NETWORK_FAILURE, TRANSPORT,
AttachmentDatabase.UNIQUE_ID,
AttachmentDatabase.MMS_ID,
Expand Down Expand Up @@ -177,6 +180,7 @@ private Cursor queryTables(String[] projection, String selection, String order,
MmsDatabase.MESSAGE_SIZE, MmsDatabase.EXPIRY, MmsDatabase.STATUS,
MmsSmsColumns.RECEIPT_COUNT, MmsSmsColumns.MISMATCHED_IDENTITIES,
MmsSmsColumns.SUBSCRIPTION_ID, MmsSmsColumns.EXPIRES_IN, MmsSmsColumns.EXPIRE_STARTED,
MmsSmsColumns.NOTIFIED,
MmsDatabase.NETWORK_FAILURE, TRANSPORT,
AttachmentDatabase.UNIQUE_ID,
AttachmentDatabase.MMS_ID,
Expand Down Expand Up @@ -227,6 +231,7 @@ private Cursor queryTables(String[] projection, String selection, String order,
mmsColumnsPresent.add(MmsDatabase.TRANSACTION_ID);
mmsColumnsPresent.add(MmsDatabase.MESSAGE_SIZE);
mmsColumnsPresent.add(MmsDatabase.EXPIRY);
mmsColumnsPresent.add(MmsDatabase.NOTIFIED);
mmsColumnsPresent.add(MmsDatabase.STATUS);
mmsColumnsPresent.add(MmsDatabase.NETWORK_FAILURE);

Expand Down Expand Up @@ -255,6 +260,7 @@ private Cursor queryTables(String[] projection, String selection, String order,
smsColumnsPresent.add(MmsSmsColumns.SUBSCRIPTION_ID);
smsColumnsPresent.add(MmsSmsColumns.EXPIRES_IN);
smsColumnsPresent.add(MmsSmsColumns.EXPIRE_STARTED);
smsColumnsPresent.add(MmsSmsColumns.NOTIFIED);
smsColumnsPresent.add(SmsDatabase.TYPE);
smsColumnsPresent.add(SmsDatabase.SUBJECT);
smsColumnsPresent.add(SmsDatabase.DATE_SENT);
Expand Down
16 changes: 13 additions & 3 deletions src/org/thoughtcrime/securesms/database/SmsDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public class SmsDatabase extends MessagingDatabase {
STATUS + " INTEGER DEFAULT -1," + TYPE + " INTEGER, " + REPLY_PATH_PRESENT + " INTEGER, " +
RECEIPT_COUNT + " INTEGER DEFAULT 0," + SUBJECT + " TEXT, " + BODY + " TEXT, " +
MISMATCHED_IDENTITIES + " TEXT DEFAULT NULL, " + SERVICE_CENTER + " TEXT, " + SUBSCRIPTION_ID + " INTEGER DEFAULT -1, " +
EXPIRES_IN + " INTEGER DEFAULT 0, " + EXPIRE_STARTED + " INTEGER DEFAULT 0);";
EXPIRES_IN + " INTEGER DEFAULT 0, " + EXPIRE_STARTED + " INTEGER DEFAULT 0, " + NOTIFIED + " DEFAULT 0);";

public static final String[] CREATE_INDEXS = {
"CREATE INDEX IF NOT EXISTS sms_thread_id_index ON " + TABLE_NAME + " (" + THREAD_ID + ");",
"CREATE INDEX IF NOT EXISTS sms_read_index ON " + TABLE_NAME + " (" + READ + ");",
"CREATE INDEX IF NOT EXISTS sms_read_and_thread_id_index ON " + TABLE_NAME + "(" + READ + "," + THREAD_ID + ");",
"CREATE INDEX IF NOT EXISTS sms_read_and_notified_and_thread_id_index ON " + TABLE_NAME + "(" + READ + "," + NOTIFIED + "," + THREAD_ID + ");",
"CREATE INDEX IF NOT EXISTS sms_type_index ON " + TABLE_NAME + " (" + TYPE + ");",
"CREATE INDEX IF NOT EXISTS sms_date_sent_index ON " + TABLE_NAME + " (" + DATE_SENT + ");",
"CREATE INDEX IF NOT EXISTS sms_thread_date_index ON " + TABLE_NAME + " (" + THREAD_ID + ", " + DATE_RECEIVED + ");"
Expand All @@ -96,7 +96,8 @@ public class SmsDatabase extends MessagingDatabase {
DATE_SENT + " AS " + NORMALIZED_DATE_SENT,
PROTOCOL, READ, STATUS, TYPE,
REPLY_PATH_PRESENT, SUBJECT, BODY, SERVICE_CENTER, RECEIPT_COUNT,
MISMATCHED_IDENTITIES, SUBSCRIPTION_ID, EXPIRES_IN, EXPIRE_STARTED
MISMATCHED_IDENTITIES, SUBSCRIPTION_ID, EXPIRES_IN, EXPIRE_STARTED,
NOTIFIED
};

private static final EarlyReceiptCache earlyReceiptCache = new EarlyReceiptCache();
Expand Down Expand Up @@ -271,6 +272,15 @@ public void markAsSentFailed(long id) {
updateTypeBitmask(id, Types.BASE_TYPE_MASK, Types.BASE_SENT_FAILED_TYPE);
}

public void markAsNotified(long id) {
SQLiteDatabase database = databaseHelper.getWritableDatabase();
ContentValues contentValues = new ContentValues();

contentValues.put(NOTIFIED, 1);

database.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {String.valueOf(id)});
}

public void incrementDeliveryReceiptCount(SyncMessageId messageId) {
SQLiteDatabase database = databaseHelper.getWritableDatabase();
Cursor cursor = null;
Expand Down
1 change: 0 additions & 1 deletion src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public void onRun() throws NoSuchMessageException {

if (!IdentityKeyUtil.hasIdentityKey(context)) {
Log.w(TAG, "Skipping job, waiting for migration...");
MessageNotifier.updateNotification(context, null, true, -2);
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.thoughtcrime.securesms.notifications;


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;

import org.thoughtcrime.securesms.database.DatabaseFactory;

public class DeleteNotificationReceiver extends BroadcastReceiver {

public static String DELETE_NOTIFICATION_ACTION = "org.thoughtcrime.securesms.DELETE_NOTIFICATION";

public static String EXTRA_IDS = "message_ids";
public static String EXTRA_MMS = "is_mms";

@Override
public void onReceive(final Context context, Intent intent) {
if (DELETE_NOTIFICATION_ACTION.equals(intent.getAction())) {
MessageNotifier.clearReminder(context);

final long[] ids = intent.getLongArrayExtra(EXTRA_IDS);
final boolean[] mms = intent.getBooleanArrayExtra(EXTRA_MMS);

if (ids == null || mms == null || ids.length != mms.length) return;

new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
for (int i=0;i<ids.length;i++) {
if (!mms[i]) DatabaseFactory.getSmsDatabase(context).markAsNotified(ids[i]);
else DatabaseFactory.getMmsDatabase(context).markAsNotified(ids[i]);
}

return null;
}
}.execute();
}
}
}
Loading

0 comments on commit 2f46c6c

Please sign in to comment.