Added the reply draft as an extra to the content intent
Change-Id: I406833a5875221731baf0834f2e47e283b84aae9
Fixes: 36858677
Test: Add notification, draft reply and click on it. Ensure that extra is sent
diff --git a/api/current.txt b/api/current.txt
index 61465ac..b07e8bc 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -5224,6 +5224,7 @@
field public static final java.lang.String EXTRA_PROGRESS = "android.progress";
field public static final java.lang.String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate";
field public static final java.lang.String EXTRA_PROGRESS_MAX = "android.progressMax";
+ field public static final java.lang.String EXTRA_REMOTE_INPUT_DRAFT = "android.remoteInputDraft";
field public static final java.lang.String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory";
field public static final deprecated java.lang.String EXTRA_SELF_DISPLAY_NAME = "android.selfDisplayName";
field public static final java.lang.String EXTRA_SHOW_CHRONOMETER = "android.showChronometer";
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index d6fddfc..0b5b363 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -200,6 +200,16 @@
*/
private static final int MAX_REPLY_HISTORY = 5;
+
+ /**
+ * If the notification contained an unsent draft for a RemoteInput when the user clicked on it,
+ * we're adding the draft as a String extra to the {@link #contentIntent} using this key.
+ *
+ * <p>Apps may use this extra to prepopulate text fields in the app, where the user usually
+ * sends messages.</p>
+ */
+ public static final String EXTRA_REMOTE_INPUT_DRAFT = "android.remoteInputDraft";
+
/**
* A timestamp related to this notification, in milliseconds since the epoch.
*
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
index 3901277..e9673ea 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
@@ -1458,6 +1458,11 @@
mMenuRow.resetMenu();
}
+ public CharSequence getActiveRemoteInputText() {
+ return mPrivateLayout.getActiveRemoteInputText();
+ }
+
+
public void animateTranslateNotification(final float leftTarget) {
if (mTranslateAnim != null) {
mTranslateAnim.cancel();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
index a4c17e3..e811ed3 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
@@ -1563,4 +1563,14 @@
}
return visibleWrapper.shouldClipToRounding(topRounded, bottomRounded);
}
+
+ public CharSequence getActiveRemoteInputText() {
+ if (mExpandedRemoteInput != null && mExpandedRemoteInput.isActive()) {
+ return mExpandedRemoteInput.getText();
+ }
+ if (mHeadsUpRemoteInput != null && mHeadsUpRemoteInput.isActive()) {
+ return mHeadsUpRemoteInput.getText();
+ }
+ return null;
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index 77afe9b..a423c12 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -100,6 +100,8 @@
import android.service.notification.StatusBarNotification;
import android.service.vr.IVrManager;
import android.service.vr.IVrStateCallbacks;
+import android.text.SpannedString;
+import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.EventLog;
import android.util.Log;
@@ -4937,9 +4939,25 @@
}
}
}
+ Intent fillInIntent = null;
+ Entry entry = row.getEntry();
+ CharSequence remoteInputText = null;
+ RemoteInputController controller = mRemoteInputManager.getController();
+ if (controller.isRemoteInputActive(entry)) {
+ remoteInputText = row.getActiveRemoteInputText();
+ }
+ if (TextUtils.isEmpty(remoteInputText)
+ && !TextUtils.isEmpty(entry.remoteInputText)) {
+ remoteInputText = entry.remoteInputText;
+ }
+ if (!TextUtils.isEmpty(remoteInputText)
+ && !controller.isSpinning(entry.key)) {
+ fillInIntent = new Intent().putExtra(Notification.EXTRA_REMOTE_INPUT_DRAFT,
+ remoteInputText.toString());
+ }
try {
- launchResult = intent.sendAndReturnResult(null, 0, null, null, null, null,
- getActivityOptions(row));
+ launchResult = intent.sendAndReturnResult(mContext, 0, fillInIntent, null,
+ null, null, getActivityOptions(row));
} catch (PendingIntent.CanceledException e) {
// the stack trace isn't very helpful here.
// Just log the exception message.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java
index b63c1da..179c0d5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java
@@ -169,6 +169,10 @@
}
}
+ public CharSequence getText() {
+ return mEditText.getText();
+ }
+
public static RemoteInputView inflate(Context context, ViewGroup root,
NotificationData.Entry entry,
RemoteInputController controller) {