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

Commit e3a65696 authored by Julia Reynolds's avatar Julia Reynolds Committed by Automerger Merge Worker
Browse files

Merge "Allow additional reason/surface combinations for cancel" into udc-qpr-dev am: dd9450a1

parents 019f0b54 dd9450a1
Loading
Loading
Loading
Loading
+27 −35
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.app.Person;
import android.os.Bundle;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationStats;
import android.util.Log;

import com.android.internal.config.sysui.SystemUiSystemPropertiesFlags;
import com.android.internal.config.sysui.SystemUiSystemPropertiesFlags.NotificationFlags;
@@ -48,6 +49,8 @@ import java.util.Objects;
 */
interface NotificationRecordLogger {

    static final String TAG = "NotificationRecordLogger";

    // The high-level interface used by clients.

    /**
@@ -228,33 +231,13 @@ interface NotificationRecordLogger {
                @NotificationStats.DismissalSurface int surface) {
            // Shouldn't be possible to get a non-dismissed notification here.
            if (surface == NotificationStats.DISMISSAL_NOT_DISMISSED) {
                if (NotificationManagerService.DBG) {
                    throw new IllegalArgumentException("Unexpected surface " + surface);
                }
                return INVALID;
            }
            // Most cancel reasons do not have a meaningful surface. Reason codes map directly
            // to NotificationCancelledEvent codes.
            if (surface == NotificationStats.DISMISSAL_OTHER) {
                if ((REASON_CLICK <= reason) && (reason <= REASON_CLEAR_DATA)) {
                    return NotificationCancelledEvent.values()[reason];
                }
                if (reason == REASON_ASSISTANT_CANCEL) {
                    return NotificationCancelledEvent.NOTIFICATION_CANCEL_ASSISTANT;
                }
                if (NotificationManagerService.DBG) {
                    throw new IllegalArgumentException("Unexpected cancel reason " + reason);
                }
                Log.wtf(TAG, "Unexpected surface: " + surface + " with reason " + reason);
                return INVALID;
            }

            // User cancels have a meaningful surface, which we differentiate by. See b/149038335
            // for caveats.
            if (reason != REASON_CANCEL) {
                if (NotificationManagerService.DBG) {
                    throw new IllegalArgumentException("Unexpected cancel with surface " + reason);
                }
                return INVALID;
            }
            if (reason == REASON_CANCEL) {
                switch (surface) {
                    case NotificationStats.DISMISSAL_PEEK:
                        return NOTIFICATION_CANCEL_USER_PEEK;
@@ -266,11 +249,20 @@ interface NotificationRecordLogger {
                        return NOTIFICATION_CANCEL_USER_BUBBLE;
                    case NotificationStats.DISMISSAL_LOCKSCREEN:
                        return NOTIFICATION_CANCEL_USER_LOCKSCREEN;
                    case NotificationStats.DISMISSAL_OTHER:
                        return NOTIFICATION_CANCEL_USER_OTHER;
                    default:
                    if (NotificationManagerService.DBG) {
                        throw new IllegalArgumentException("Unexpected surface for user-dismiss "
                                + reason);
                        Log.wtf(TAG, "Unexpected surface: " + surface + " with reason " + reason);
                        return INVALID;
                }
            } else {
                if ((REASON_CLICK <= reason) && (reason <= REASON_CLEAR_DATA)) {
                    return NotificationCancelledEvent.values()[reason];
                }
                if (reason == REASON_ASSISTANT_CANCEL) {
                    return NotificationCancelledEvent.NOTIFICATION_CANCEL_ASSISTANT;
                }
                Log.wtf(TAG, "Unexpected reason: " + reason + " with surface " + surface);
                return INVALID;
            }
        }
+22 −0
Original line number Diff line number Diff line
@@ -18,6 +18,14 @@ package com.android.server.notification;

import static android.app.Notification.FLAG_FOREGROUND_SERVICE;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.service.notification.NotificationListenerService.REASON_CANCEL;
import static android.service.notification.NotificationListenerService.REASON_GROUP_SUMMARY_CANCELED;
import static android.service.notification.NotificationStats.DISMISSAL_BUBBLE;
import static android.service.notification.NotificationStats.DISMISSAL_OTHER;

import static com.android.server.notification.NotificationRecordLogger.NotificationCancelledEvent.NOTIFICATION_CANCEL_CLICK;
import static com.android.server.notification.NotificationRecordLogger.NotificationCancelledEvent.NOTIFICATION_CANCEL_GROUP_SUMMARY_CANCELED;
import static com.android.server.notification.NotificationRecordLogger.NotificationCancelledEvent.NOTIFICATION_CANCEL_USER_OTHER;
import static com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent.NOTIFICATION_POSTED;
import static com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent.NOTIFICATION_UPDATED;

@@ -208,4 +216,18 @@ public class NotificationRecordLoggerTest extends UiServiceTestCase {
                /* eventType= */ NOTIFICATION_POSTED);
        assertEquals(FrameworkStatsLog.NOTIFICATION_REPORTED__FSI_STATE__NO_FSI, fsiState);
    }

    @Test
    public void testBubbleGroupSummaryDismissal() {
        assertEquals(NOTIFICATION_CANCEL_GROUP_SUMMARY_CANCELED,
                NotificationRecordLogger.NotificationCancelledEvent.fromCancelReason(
                REASON_GROUP_SUMMARY_CANCELED, DISMISSAL_BUBBLE));
    }

    @Test
    public void testOtherNotificationCancel() {
        assertEquals(NOTIFICATION_CANCEL_USER_OTHER,
                NotificationRecordLogger.NotificationCancelledEvent.fromCancelReason(
                        REASON_CANCEL, DISMISSAL_OTHER));
    }
}