From 34ef29a64502d80d3c11f50e64a6ebbe209a01d6 Mon Sep 17 00:00:00 2001 From: Mikunj Varsani Date: Thu, 12 Mar 2020 09:23:39 +1100 Subject: [PATCH 1/6] Remove account authenticator. Remove unused listeners. --- AndroidManifest.xml | 62 -------------- res/xml/authenticator.xml | 6 -- .../service/AccountAuthenticatorService.java | 80 ------------------- 3 files changed, 148 deletions(-) delete mode 100644 res/xml/authenticator.xml delete mode 100644 src/org/thoughtcrime/securesms/service/AccountAuthenticatorService.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 6a3cd05962..fc6475ed64 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -529,32 +529,6 @@ - - - - - - - - - - - - - - - - - - - @@ -563,42 +537,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/org/thoughtcrime/securesms/service/AccountAuthenticatorService.java b/src/org/thoughtcrime/securesms/service/AccountAuthenticatorService.java deleted file mode 100644 index 0106818277..0000000000 --- a/src/org/thoughtcrime/securesms/service/AccountAuthenticatorService.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.thoughtcrime.securesms.service; - -import android.accounts.AbstractAccountAuthenticator; -import android.accounts.Account; -import android.accounts.AccountAuthenticatorResponse; -import android.accounts.NetworkErrorException; -import android.app.Service; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.os.IBinder; - -public class AccountAuthenticatorService extends Service { - - private static AccountAuthenticatorImpl accountAuthenticator = null; - - @Override - public IBinder onBind(Intent intent) { - if (intent.getAction().equals(android.accounts.AccountManager.ACTION_AUTHENTICATOR_INTENT)) { - return getAuthenticator().getIBinder(); - } else { - return null; - } - } - - private synchronized AccountAuthenticatorImpl getAuthenticator() { - if (accountAuthenticator == null) { - accountAuthenticator = new AccountAuthenticatorImpl(this); - } - - return accountAuthenticator; - } - - private static class AccountAuthenticatorImpl extends AbstractAccountAuthenticator { - - public AccountAuthenticatorImpl(Context context) { - super(context); - } - - @Override - public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, - String[] requiredFeatures, Bundle options) - throws NetworkErrorException - { - return null; - } - - public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) { - return null; - } - - @Override - public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) { - return null; - } - - @Override - public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, - Bundle options) throws NetworkErrorException { - return null; - } - - @Override - public String getAuthTokenLabel(String authTokenType) { - return null; - } - - @Override - public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) - throws NetworkErrorException { - return null; - } - - @Override - public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, - Bundle options) { - return null; - } - } -} From d694cfa68ad96ffa900e2c68d068971d1535cc9d Mon Sep 17 00:00:00 2001 From: Mikunj Varsani Date: Thu, 12 Mar 2020 09:52:42 +1100 Subject: [PATCH 2/6] Differentiate Signal actions from Signal actions --- AndroidManifest.xml | 18 +++++++++--------- .../securesms/ExperienceUpgradeActivity.java | 2 +- .../securesms/avatar/AvatarSelection.java | 2 +- .../AndroidAutoHeardReceiver.java | 2 +- .../AndroidAutoReplyReceiver.java | 2 +- .../DeleteNotificationReceiver.java | 2 +- .../notifications/MarkReadReceiver.java | 2 +- .../notifications/MessageNotifier.java | 2 +- .../notifications/RemoteReplyReceiver.java | 7 +------ .../securesms/notifications/ReplyMethod.java | 8 ++------ 10 files changed, 19 insertions(+), 28 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index fc6475ed64..819179fb66 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -494,7 +494,7 @@ android:label="@string/AndroidManifest_remove_photo" android:theme="@style/Theme.AppCompat.Dialog.Alert"> - + @@ -542,7 +542,7 @@ android:enabled="true" android:exported="false"> - + - + - + - + @@ -612,7 +612,7 @@ - + @@ -647,12 +647,12 @@ - + - + @@ -662,7 +662,7 @@ - + Date: Thu, 12 Mar 2020 10:42:08 +1100 Subject: [PATCH 3/6] Enable quick reply --- .../notifications/MessageNotifier.java | 32 +++++++- .../SingleRecipientNotificationBuilder.java | 74 +++++++++---------- 2 files changed, 61 insertions(+), 45 deletions(-) diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java index 7941014245..3036a79bdd 100644 --- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -49,6 +49,7 @@ import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord; import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.database.model.MmsMessageRecord; import org.thoughtcrime.securesms.logging.Log; +import org.thoughtcrime.securesms.loki.MultiDeviceUtilities; import org.thoughtcrime.securesms.mms.SlideDeck; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.service.IncomingMessageObserver; @@ -58,6 +59,8 @@ import org.thoughtcrime.securesms.util.SpanUtil; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.webrtc.CallNotificationBuilder; import org.whispersystems.signalservice.internal.util.Util; +import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus; +import org.whispersystems.signalservice.loki.utilities.PromiseUtil; import java.util.HashSet; import java.util.List; @@ -70,6 +73,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import me.leolin.shortcutbadger.ShortcutBadger; import network.loki.messenger.R; +import nl.komponents.kovenant.Promise; /** @@ -316,15 +320,35 @@ public class MessageNotifier { long timestamp = notifications.get(0).getTimestamp(); if (timestamp != 0) builder.setWhen(timestamp); + long threadId = notifications.get(0).getThreadId(); + ReplyMethod replyMethod = ReplyMethod.forRecipient(context, recipient); + + // We can only reply if we are friends with the user or we're messaging a group + boolean isGroup = recipient.isGroupRecipient() && !recipient.getAddress().isRSSFeed(); + boolean isFriends = DatabaseFactory.getLokiThreadDatabase(context).getFriendRequestStatus(threadId) == LokiThreadFriendRequestStatus.FRIENDS; + + // If we're not friends then we need to check if we're friends with any of the linked devices + if (!isGroup && !isFriends) { + Promise promise = PromiseUtil.timeout(MultiDeviceUtilities.isFriendsWithAnyLinkedDevice(context, recipient), 5000); + isFriends = PromiseUtil.get(promise, false); + } + + boolean canReply = isGroup || isFriends; + + PendingIntent quickReplyIntent = canReply ? notificationState.getQuickReplyIntent(context, notifications.get(0).getRecipient()) : null; + PendingIntent remoteReplyIntent = canReply ? notificationState.getRemoteReplyIntent(context, notifications.get(0).getRecipient(), replyMethod) : null; + builder.addActions(notificationState.getMarkAsReadIntent(context, notificationId), - /*notificationState.getQuickReplyIntent(context, notifications.get(0).getRecipient()),*/ - notificationState.getRemoteReplyIntent(context, notifications.get(0).getRecipient(), replyMethod), + quickReplyIntent, + remoteReplyIntent, replyMethod); - builder.addAndroidAutoAction(notificationState.getAndroidAutoReplyIntent(context, notifications.get(0).getRecipient()), - notificationState.getAndroidAutoHeardIntent(context, notificationId), notifications.get(0).getTimestamp()); + if (canReply) { + builder.addAndroidAutoAction(notificationState.getAndroidAutoReplyIntent(context, notifications.get(0).getRecipient()), + notificationState.getAndroidAutoHeardIntent(context, notificationId), notifications.get(0).getTimestamp()); + } ListIterator iterator = notifications.listIterator(notifications.size()); diff --git a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java index 0da777e700..a9472ebbf3 100644 --- a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java +++ b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java @@ -28,7 +28,6 @@ import org.thoughtcrime.securesms.contacts.avatars.ContactColors; import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto; import org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto; import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto; -import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader; import org.thoughtcrime.securesms.mms.GlideApp; @@ -39,7 +38,6 @@ import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.util.BitmapUtil; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.Util; -import org.whispersystems.signalservice.loki.api.LokiPublicChat; import java.util.LinkedList; import java.util.List; @@ -156,59 +154,53 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil } public void addActions(@NonNull PendingIntent markReadIntent, - @NonNull PendingIntent wearableReplyIntent, + @Nullable PendingIntent quickReplyIntent, + @Nullable PendingIntent wearableReplyIntent, @NonNull ReplyMethod replyMethod) { Action markAsReadAction = new Action(R.drawable.check, context.getString(R.string.MessageNotifier_mark_read), markReadIntent); - String actionName = context.getString(R.string.MessageNotifier_reply); - String label = context.getString(replyMethodLongDescription(replyMethod)); + addAction(markAsReadAction); - /* - Action replyAction = new Action(R.drawable.ic_reply_white_36dp, - actionName, - quickReplyIntent); - */ + NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender().addAction(markAsReadAction); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - /* - replyAction = new Action.Builder(R.drawable.ic_reply_white_36dp, - actionName, - wearableReplyIntent) - .addRemoteInput(new RemoteInput.Builder(MessageNotifier.EXTRA_REMOTE_REPLY) - .setLabel(label).build()) - .build(); - */ + if (quickReplyIntent != null) { + String actionName = context.getString(R.string.MessageNotifier_reply); + String label = context.getString(replyMethodLongDescription(replyMethod)); + + Action replyAction = new Action(R.drawable.ic_reply_white_36dp, + actionName, + quickReplyIntent); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + replyAction = new Action.Builder(R.drawable.ic_reply_white_36dp, + actionName, + wearableReplyIntent) + .addRemoteInput(new RemoteInput.Builder(MessageNotifier.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()) + .build(); + + + addAction(replyAction); + wearableExtender.addAction(wearableReplyAction); } - Action wearableReplyAction = new Action.Builder(R.drawable.ic_reply, - actionName, - wearableReplyIntent) - .addRemoteInput(new RemoteInput.Builder(MessageNotifier.EXTRA_REMOTE_REPLY) - .setLabel(label).build()) - .build(); - - addAction(markAsReadAction); - // addAction(replyAction); - - extend(new NotificationCompat.WearableExtender().addAction(markAsReadAction) - .addAction(wearableReplyAction)); + extend(wearableExtender); } @StringRes private static int replyMethodLongDescription(@NonNull ReplyMethod replyMethod) { - switch (replyMethod) { - case GroupMessage: - return R.string.MessageNotifier_reply; - case SecureMessage: - return R.string.MessageNotifier_signal_message; - case UnsecuredSmsMessage: - return R.string.MessageNotifier_unsecured_sms; - default: - return R.string.MessageNotifier_reply; - } + return R.string.MessageNotifier_reply; } public void addMessageBody(@NonNull Recipient threadRecipient, From 152ddf013b3f9df1275780e9c0ee2094ca7fb092 Mon Sep 17 00:00:00 2001 From: Mikunj Varsani Date: Thu, 12 Mar 2020 10:49:35 +1100 Subject: [PATCH 4/6] Clean up. --- .../securesms/notifications/MessageNotifier.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java index 3036a79bdd..d92cc0c141 100644 --- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -337,8 +337,8 @@ public class MessageNotifier { boolean canReply = isGroup || isFriends; - PendingIntent quickReplyIntent = canReply ? notificationState.getQuickReplyIntent(context, notifications.get(0).getRecipient()) : null; - PendingIntent remoteReplyIntent = canReply ? notificationState.getRemoteReplyIntent(context, notifications.get(0).getRecipient(), replyMethod) : null; + PendingIntent quickReplyIntent = canReply ? notificationState.getQuickReplyIntent(context, recipient) : null; + PendingIntent remoteReplyIntent = canReply ? notificationState.getRemoteReplyIntent(context, recipient, replyMethod) : null; builder.addActions(notificationState.getMarkAsReadIntent(context, notificationId), quickReplyIntent, @@ -346,8 +346,9 @@ public class MessageNotifier { replyMethod); if (canReply) { - builder.addAndroidAutoAction(notificationState.getAndroidAutoReplyIntent(context, notifications.get(0).getRecipient()), - notificationState.getAndroidAutoHeardIntent(context, notificationId), notifications.get(0).getTimestamp()); + builder.addAndroidAutoAction(notificationState.getAndroidAutoReplyIntent(context, recipient), + notificationState.getAndroidAutoHeardIntent(context, notificationId), + notifications.get(0).getTimestamp()); } ListIterator iterator = notifications.listIterator(notifications.size()); From 49be17b969cc44de9782846833df5dc6b44d2bd8 Mon Sep 17 00:00:00 2001 From: Mikunj Varsani Date: Thu, 12 Mar 2020 12:05:08 +1100 Subject: [PATCH 5/6] Fix reply showing up in RSS feed notifications. --- .../notifications/MessageNotifier.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java index d92cc0c141..7125d0e413 100644 --- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -326,16 +326,19 @@ public class MessageNotifier { // We can only reply if we are friends with the user or we're messaging a group - boolean isGroup = recipient.isGroupRecipient() && !recipient.getAddress().isRSSFeed(); - boolean isFriends = DatabaseFactory.getLokiThreadDatabase(context).getFriendRequestStatus(threadId) == LokiThreadFriendRequestStatus.FRIENDS; - - // If we're not friends then we need to check if we're friends with any of the linked devices - if (!isGroup && !isFriends) { - Promise promise = PromiseUtil.timeout(MultiDeviceUtilities.isFriendsWithAnyLinkedDevice(context, recipient), 5000); - isFriends = PromiseUtil.get(promise, false); + boolean isGroup = recipient.isGroupRecipient(); + boolean isRSS = isGroup && recipient.getAddress().isRSSFeed(); + boolean isFriends = false; + if (!isGroup) { + isFriends = DatabaseFactory.getLokiThreadDatabase(context).getFriendRequestStatus(threadId) == LokiThreadFriendRequestStatus.FRIENDS; + // If we're not friends then we need to check if we're friends with any of the linked devices + if (!isFriends) { + Promise promise = PromiseUtil.timeout(MultiDeviceUtilities.isFriendsWithAnyLinkedDevice(context, recipient), 5000); + isFriends = PromiseUtil.get(promise, false); + } } - boolean canReply = isGroup || isFriends; + boolean canReply = (isGroup && !isRSS) || isFriends; PendingIntent quickReplyIntent = canReply ? notificationState.getQuickReplyIntent(context, recipient) : null; PendingIntent remoteReplyIntent = canReply ? notificationState.getRemoteReplyIntent(context, recipient, replyMethod) : null; From f96eebde207482a7b8d13b7f52c48c7cf8b15ab4 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 12 Mar 2020 16:03:21 +1100 Subject: [PATCH 6/6] Rename variables --- .../securesms/notifications/MessageNotifier.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java index 7125d0e413..9fb501ba7e 100644 --- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -327,18 +327,18 @@ public class MessageNotifier { // We can only reply if we are friends with the user or we're messaging a group boolean isGroup = recipient.isGroupRecipient(); - boolean isRSS = isGroup && recipient.getAddress().isRSSFeed(); - boolean isFriends = false; + boolean isRSSFeed = isGroup && recipient.getAddress().isRSSFeed(); + boolean isFriend = false; if (!isGroup) { - isFriends = DatabaseFactory.getLokiThreadDatabase(context).getFriendRequestStatus(threadId) == LokiThreadFriendRequestStatus.FRIENDS; + isFriend = DatabaseFactory.getLokiThreadDatabase(context).getFriendRequestStatus(threadId) == LokiThreadFriendRequestStatus.FRIENDS; // If we're not friends then we need to check if we're friends with any of the linked devices - if (!isFriends) { + if (!isFriend) { Promise promise = PromiseUtil.timeout(MultiDeviceUtilities.isFriendsWithAnyLinkedDevice(context, recipient), 5000); - isFriends = PromiseUtil.get(promise, false); + isFriend = PromiseUtil.get(promise, false); } } - boolean canReply = (isGroup && !isRSS) || isFriends; + boolean canReply = (isGroup && !isRSSFeed) || isFriend; PendingIntent quickReplyIntent = canReply ? notificationState.getQuickReplyIntent(context, recipient) : null; PendingIntent remoteReplyIntent = canReply ? notificationState.getRemoteReplyIntent(context, recipient, replyMethod) : null;