Merge "Bubbles policy: require remote input for messaging" into qt-dev am: f879566d28
am: 509956d6dc
Change-Id: I68e60a642b1c91b78499d82616c35908b3e417d0
This commit is contained in:
@@ -112,6 +112,7 @@ import android.app.NotificationManager;
|
||||
import android.app.NotificationManager.Policy;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Person;
|
||||
import android.app.RemoteInput;
|
||||
import android.app.StatusBarManager;
|
||||
import android.app.UriGrantsManager;
|
||||
import android.app.admin.DeviceAdminInfo;
|
||||
@@ -4843,17 +4844,35 @@ public class NotificationManagerService extends SystemService {
|
||||
: null;
|
||||
boolean isForegroundCall = CATEGORY_CALL.equals(notification.category)
|
||||
&& (notification.flags & FLAG_FOREGROUND_SERVICE) != 0;
|
||||
// OR message style (which always has a person)
|
||||
// OR message style (which always has a person) with any remote input
|
||||
Class<? extends Notification.Style> style = notification.getNotificationStyle();
|
||||
boolean isMessageStyle = Notification.MessagingStyle.class.equals(style);
|
||||
boolean notificationAppropriateToBubble = isMessageStyle
|
||||
boolean notificationAppropriateToBubble =
|
||||
(isMessageStyle && hasValidRemoteInput(notification))
|
||||
|| (peopleList != null && !peopleList.isEmpty() && isForegroundCall);
|
||||
|
||||
// OR something that was previously a bubble & still exists
|
||||
boolean bubbleUpdate = oldRecord != null
|
||||
&& (oldRecord.getNotification().flags & FLAG_BUBBLE) != 0;
|
||||
return canBubble && (notificationAppropriateToBubble || appIsForeground || bubbleUpdate);
|
||||
}
|
||||
|
||||
private boolean hasValidRemoteInput(Notification n) {
|
||||
// Also check for inline reply
|
||||
Notification.Action[] actions = n.actions;
|
||||
if (actions != null) {
|
||||
// Get the remote inputs
|
||||
for (int i = 0; i < actions.length; i++) {
|
||||
Notification.Action action = actions[i];
|
||||
RemoteInput[] inputs = action.getRemoteInputs();
|
||||
if (inputs != null && inputs.length > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void doChannelWarningToast(CharSequence toastText) {
|
||||
Binder.withCleanCallingIdentity(() -> {
|
||||
final int defaultWarningEnabled = Build.IS_DEBUGGABLE ? 1 : 0;
|
||||
|
||||
@@ -86,6 +86,7 @@ import android.app.NotificationChannelGroup;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Person;
|
||||
import android.app.RemoteInput;
|
||||
import android.app.admin.DevicePolicyManagerInternal;
|
||||
import android.app.usage.UsageStatsManagerInternal;
|
||||
import android.companion.ICompanionDeviceManager;
|
||||
@@ -4523,6 +4524,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
Person person = new Person.Builder()
|
||||
.setName("bubblebot")
|
||||
.build();
|
||||
// It needs remote input to be bubble-able
|
||||
RemoteInput remoteInput = new RemoteInput.Builder("reply_key").setLabel("reply").build();
|
||||
PendingIntent inputIntent = PendingIntent.getActivity(mContext, 0, new Intent(), 0);
|
||||
Icon icon = Icon.createWithResource(mContext, android.R.drawable.sym_def_app_icon);
|
||||
Notification.Action replyAction = new Notification.Action.Builder(icon, "Reply",
|
||||
inputIntent).addRemoteInput(remoteInput)
|
||||
.build();
|
||||
// Make it messaging style
|
||||
Notification.Builder nb = new Notification.Builder(mContext,
|
||||
mTestNotificationChannel.getId())
|
||||
@@ -4535,6 +4543,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
.addMessage("Is it me you're looking for?",
|
||||
SystemClock.currentThreadTimeMillis(), person)
|
||||
)
|
||||
.setActions(replyAction)
|
||||
.setSmallIcon(android.R.drawable.sym_def_app_icon);
|
||||
|
||||
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, null, mUid, 0,
|
||||
|
||||
Reference in New Issue
Block a user