Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 509956d6 authored by Mady Mellor's avatar Mady Mellor Committed by android-build-merger
Browse files

Merge "Bubbles policy: require remote input for messaging" into qt-dev

am: f879566d

Change-Id: I669c5eae8a0f5b0759d4f21ecc47ac7dfcba29a8
parents 830e3b2c f879566d
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -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;
+9 −0
Original line number Diff line number Diff line
@@ -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,