Support for Android N direct reply notifications

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2016-12-25 19:00:33 -08:00
parent a9bd84c69c
commit 373a0f9527
5 changed files with 22 additions and 14 deletions

View File

@ -460,7 +460,7 @@
</intent-filter>
</receiver>
<receiver android:name=".notifications.WearReplyReceiver"
<receiver android:name=".notifications.RemoteReplyReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>

View File

@ -86,7 +86,7 @@ public class MessageNotifier {
private static final String TAG = MessageNotifier.class.getSimpleName();
public static final String EXTRA_VOICE_REPLY = "extra_voice_reply";
public static final String EXTRA_REMOTE_REPLY = "extra_remote_reply";
private static final int SUMMARY_NOTIFICATION_ID = 1338;
private static final String NOTIFICATION_GROUP = "messages";
@ -309,7 +309,8 @@ public class MessageNotifier {
builder.addActions(masterSecret,
notificationState.getMarkAsReadIntent(context, notificationId),
notificationState.getQuickReplyIntent(context, notifications.get(0).getRecipients()),
notificationState.getWearableReplyIntent(context, notifications.get(0).getRecipients()));
notificationState.getRemoteReplyIntent(context, notifications.get(0).getRecipients()));
builder.addAndroidAutoAction(notificationState.getAndroidAutoReplyIntent(context, notifications.get(0).getRecipients()),
notificationState.getAndroidAutoHeardIntent(context, notificationId), notifications.get(0).getTimestamp());

View File

@ -13,11 +13,9 @@ import org.thoughtcrime.securesms.ConversationPopupActivity;
import org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.VibrateState;
import org.thoughtcrime.securesms.recipients.Recipients;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
public class NotificationState {
@ -117,13 +115,13 @@ public class NotificationState {
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
public PendingIntent getWearableReplyIntent(Context context, Recipients recipients) {
public PendingIntent getRemoteReplyIntent(Context context, Recipients recipients) {
if (threads.size() != 1) throw new AssertionError("We only support replies to single thread notifications!");
Intent intent = new Intent(WearReplyReceiver.REPLY_ACTION);
intent.setClass(context, WearReplyReceiver.class);
Intent intent = new Intent(RemoteReplyReceiver.REPLY_ACTION);
intent.setClass(context, RemoteReplyReceiver.class);
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
intent.putExtra(WearReplyReceiver.RECIPIENT_IDS_EXTRA, recipients.getIds());
intent.putExtra(RemoteReplyReceiver.RECIPIENT_IDS_EXTRA, recipients.getIds());
intent.setPackage(context.getPackageName());
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Whisper Systems
* Copyright (C) 2016 Open Whisper Systems
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -42,9 +42,9 @@ import java.util.List;
/**
* Get the response text from the Wearable Device and sends an message as a reply
*/
public class WearReplyReceiver extends MasterSecretBroadcastReceiver {
public class RemoteReplyReceiver extends MasterSecretBroadcastReceiver {
public static final String TAG = WearReplyReceiver.class.getSimpleName();
public static final String TAG = RemoteReplyReceiver.class.getSimpleName();
public static final String REPLY_ACTION = "org.thoughtcrime.securesms.notifications.WEAR_REPLY";
public static final String RECIPIENT_IDS_EXTRA = "recipient_ids";
@ -59,7 +59,7 @@ public class WearReplyReceiver extends MasterSecretBroadcastReceiver {
if (remoteInput == null) return;
final long[] recipientIds = intent.getLongArrayExtra(RECIPIENT_IDS_EXTRA);
final CharSequence responseText = remoteInput.getCharSequence(MessageNotifier.EXTRA_VOICE_REPLY);
final CharSequence responseText = remoteInput.getCharSequence(MessageNotifier.EXTRA_REMOTE_REPLY);
final Recipients recipients = RecipientFactory.getRecipientsForIds(context, recipientIds, false);
if (masterSecret != null && responseText != null) {

View File

@ -136,10 +136,19 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
context.getString(R.string.MessageNotifier_reply),
quickReplyIntent);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
replyAction = new Action.Builder(R.drawable.ic_reply_white_36dp,
context.getString(R.string.MessageNotifier_reply),
wearableReplyIntent)
.addRemoteInput(new RemoteInput.Builder(MessageNotifier.EXTRA_REMOTE_REPLY)
.setLabel(context.getString(R.string.MessageNotifier_reply)).build())
.build();
}
Action wearableReplyAction = new Action.Builder(R.drawable.ic_reply,
context.getString(R.string.MessageNotifier_reply),
wearableReplyIntent)
.addRemoteInput(new RemoteInput.Builder(MessageNotifier.EXTRA_VOICE_REPLY)
.addRemoteInput(new RemoteInput.Builder(MessageNotifier.EXTRA_REMOTE_REPLY)
.setLabel(context.getString(R.string.MessageNotifier_reply)).build())
.build();