Merge "Add an exported flag in manifest"
diff --git a/src/com/android/messaging/datamodel/BugleNotifications.java b/src/com/android/messaging/datamodel/BugleNotifications.java
index 9b96c6e..0e54027 100644
--- a/src/com/android/messaging/datamodel/BugleNotifications.java
+++ b/src/com/android/messaging/datamodel/BugleNotifications.java
@@ -906,6 +906,10 @@
         final NotificationCompat.Action.Builder actionBuilder =
                 new NotificationCompat.Action.Builder(R.drawable.ic_wear_reply,
                         context.getString(replyLabelRes), replyPendingIntent);
+
+        notifBuilder.addAction(actionBuilder.build());
+
+        // Support the action on a wearable device as well
         final String[] choices = context.getResources().getStringArray(
                 R.array.notification_reply_choices);
         final RemoteInput remoteInput = new RemoteInput.Builder(Intent.EXTRA_TEXT).setLabel(
@@ -913,9 +917,6 @@
                 setChoices(choices)
                 .build();
         actionBuilder.addRemoteInput(remoteInput);
-        notifBuilder.addAction(actionBuilder.build());
-
-        // Support the action on a wearable device as well
         wearableExtender.addAction(actionBuilder.build());
     }
 
diff --git a/src/com/android/messaging/datamodel/data/DraftMessageData.java b/src/com/android/messaging/datamodel/data/DraftMessageData.java
index 7a7199a..f63c27f 100644
--- a/src/com/android/messaging/datamodel/data/DraftMessageData.java
+++ b/src/com/android/messaging/datamodel/data/DraftMessageData.java
@@ -339,11 +339,23 @@
      */
     private boolean addOneAttachmentNoNotify(final MessagePartData attachment) {
         Assert.isTrue(attachment.isAttachment());
+        // Check duplication.
+        for (final MessagePartData existingAttachment : mAttachments) {
+            if (existingAttachment.getContentUri().equals(attachment.getContentUri())) {
+                // Destroy existing attachment and replace with new attachment instead of destroying
+                // new one so that mSelectedImages in GalleryGridView could be maintained correctly.
+                mAttachments.remove(existingAttachment);
+                existingAttachment.destroyAsync();
+                addAttachment(attachment, null /*pendingAttachment*/);
+                return false;
+            }
+        }
+
         final boolean reachedLimit = getAttachmentCount() >= getAttachmentLimit();
-        if (reachedLimit || containsAttachment(attachment.getContentUri())) {
-            // Never go over the limit. Never add duplicated attachments.
+        if (reachedLimit) {
+            // Never go over the limit.
             attachment.destroyAsync();
-            return reachedLimit;
+            return true;
         } else {
             addAttachment(attachment, null /*pendingAttachment*/);
             return false;