summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2018-08-02 13:03:48 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-08-02 13:03:48 +0000
commitc4f2ec7b3a731ddbc0415ca8d56dbcd0be85291e (patch)
treec7305b399d30ff23e91f617e47df3d05d58a4e78 /core/java/android
parente87edb1810fe47c77c966da680a976b916aa8413 (diff)
parentc9acf67886d27e040bcb1bd3e665ab8a4351ae07 (diff)
Merge "Allow NotificationAssistantService to suggest smart replies"
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/service/notification/Adjustment.java6
-rw-r--r--core/java/android/service/notification/NotificationListenerService.java34
-rw-r--r--core/java/android/service/notification/NotificationRankingUpdate.java11
3 files changed, 48 insertions, 3 deletions
diff --git a/core/java/android/service/notification/Adjustment.java b/core/java/android/service/notification/Adjustment.java
index 0d94af4bc828..e0c354ac0f23 100644
--- a/core/java/android/service/notification/Adjustment.java
+++ b/core/java/android/service/notification/Adjustment.java
@@ -71,6 +71,12 @@ public final class Adjustment implements Parcelable {
public static final String KEY_SMART_ACTIONS = "key_smart_actions";
/**
+ * Data type: ArrayList of {@link CharSequence}.
+ * Used to suggest smart replies for a notification.
+ */
+ public static final String KEY_SMART_REPLIES = "key_smart_replies";
+
+ /**
* Create a notification adjustment.
*
* @param pkg The package of the notification.
diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java
index 09425a9c5d28..09eecd8e2868 100644
--- a/core/java/android/service/notification/NotificationListenerService.java
+++ b/core/java/android/service/notification/NotificationListenerService.java
@@ -1427,6 +1427,7 @@ public abstract class NotificationListenerService extends Service {
private @UserSentiment int mUserSentiment = USER_SENTIMENT_NEUTRAL;
private boolean mHidden;
private ArrayList<Notification.Action> mSmartActions;
+ private ArrayList<CharSequence> mSmartReplies;
public Ranking() {}
@@ -1564,6 +1565,13 @@ public abstract class NotificationListenerService extends Service {
}
/**
+ * @hide
+ */
+ public List<CharSequence> getSmartReplies() {
+ return mSmartReplies;
+ }
+
+ /**
* Returns whether this notification can be displayed as a badge.
*
* @return true if the notification can be displayed as a badge, false otherwise.
@@ -1591,7 +1599,8 @@ public abstract class NotificationListenerService extends Service {
CharSequence explanation, String overrideGroupKey,
NotificationChannel channel, ArrayList<String> overridePeople,
ArrayList<SnoozeCriterion> snoozeCriteria, boolean showBadge,
- int userSentiment, boolean hidden, ArrayList<Notification.Action> smartActions) {
+ int userSentiment, boolean hidden, ArrayList<Notification.Action> smartActions,
+ ArrayList<CharSequence> smartReplies) {
mKey = key;
mRank = rank;
mIsAmbient = importance < NotificationManager.IMPORTANCE_LOW;
@@ -1608,6 +1617,7 @@ public abstract class NotificationListenerService extends Service {
mUserSentiment = userSentiment;
mHidden = hidden;
mSmartActions = smartActions;
+ mSmartReplies = smartReplies;
}
/**
@@ -1658,6 +1668,7 @@ public abstract class NotificationListenerService extends Service {
private ArrayMap<String, Integer> mUserSentiment;
private ArrayMap<String, Boolean> mHidden;
private ArrayMap<String, ArrayList<Notification.Action>> mSmartActions;
+ private ArrayMap<String, ArrayList<CharSequence>> mSmartReplies;
private RankingMap(NotificationRankingUpdate rankingUpdate) {
mRankingUpdate = rankingUpdate;
@@ -1686,7 +1697,8 @@ public abstract class NotificationListenerService extends Service {
getVisibilityOverride(key), getSuppressedVisualEffects(key),
getImportance(key), getImportanceExplanation(key), getOverrideGroupKey(key),
getChannel(key), getOverridePeople(key), getSnoozeCriteria(key),
- getShowBadge(key), getUserSentiment(key), getHidden(key), getSmartActions(key));
+ getShowBadge(key), getUserSentiment(key), getHidden(key), getSmartActions(key),
+ getSmartReplies(key));
return rank >= 0;
}
@@ -1833,6 +1845,15 @@ public abstract class NotificationListenerService extends Service {
return mSmartActions.get(key);
}
+ private ArrayList<CharSequence> getSmartReplies(String key) {
+ synchronized (this) {
+ if (mSmartReplies == null) {
+ buildSmartReplies();
+ }
+ }
+ return mSmartReplies.get(key);
+ }
+
// Locked by 'this'
private void buildRanksLocked() {
String[] orderedKeys = mRankingUpdate.getOrderedKeys();
@@ -1959,6 +1980,15 @@ public abstract class NotificationListenerService extends Service {
}
}
+ // Locked by 'this'
+ private void buildSmartReplies() {
+ Bundle smartReplies = mRankingUpdate.getSmartReplies();
+ mSmartReplies = new ArrayMap<>(smartReplies.size());
+ for (String key : smartReplies.keySet()) {
+ mSmartReplies.put(key, smartReplies.getCharSequenceArrayList(key));
+ }
+ }
+
// ----------- Parcelable
@Override
diff --git a/core/java/android/service/notification/NotificationRankingUpdate.java b/core/java/android/service/notification/NotificationRankingUpdate.java
index bed221494d4e..c67fad01d6cd 100644
--- a/core/java/android/service/notification/NotificationRankingUpdate.java
+++ b/core/java/android/service/notification/NotificationRankingUpdate.java
@@ -38,12 +38,14 @@ public class NotificationRankingUpdate implements Parcelable {
private final Bundle mUserSentiment;
private final Bundle mHidden;
private final Bundle mSmartActions;
+ private final Bundle mSmartReplies;
public NotificationRankingUpdate(String[] keys, String[] interceptedKeys,
Bundle visibilityOverrides, Bundle suppressedVisualEffects,
int[] importance, Bundle explanation, Bundle overrideGroupKeys,
Bundle channels, Bundle overridePeople, Bundle snoozeCriteria,
- Bundle showBadge, Bundle userSentiment, Bundle hidden, Bundle smartActions) {
+ Bundle showBadge, Bundle userSentiment, Bundle hidden, Bundle smartActions,
+ Bundle smartReplies) {
mKeys = keys;
mInterceptedKeys = interceptedKeys;
mVisibilityOverrides = visibilityOverrides;
@@ -58,6 +60,7 @@ public class NotificationRankingUpdate implements Parcelable {
mUserSentiment = userSentiment;
mHidden = hidden;
mSmartActions = smartActions;
+ mSmartReplies = smartReplies;
}
public NotificationRankingUpdate(Parcel in) {
@@ -76,6 +79,7 @@ public class NotificationRankingUpdate implements Parcelable {
mUserSentiment = in.readBundle();
mHidden = in.readBundle();
mSmartActions = in.readBundle();
+ mSmartReplies = in.readBundle();
}
@Override
@@ -99,6 +103,7 @@ public class NotificationRankingUpdate implements Parcelable {
out.writeBundle(mUserSentiment);
out.writeBundle(mHidden);
out.writeBundle(mSmartActions);
+ out.writeBundle(mSmartReplies);
}
public static final Parcelable.Creator<NotificationRankingUpdate> CREATOR
@@ -167,4 +172,8 @@ public class NotificationRankingUpdate implements Parcelable {
public Bundle getSmartActions() {
return mSmartActions;
}
+
+ public Bundle getSmartReplies() {
+ return mSmartReplies;
+ }
}