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

Commit 549c8f28 authored by Yuri Lin's avatar Yuri Lin
Browse files

Log whether notifications are ongoing or foreground services as well as timeout.

This adds a new method to NotificationRecordLogger to detect whether something is a foreground service notification. There's already an existing method in StatusBarNotification to check for ongoing notifications.

Bug: 183020043, 189500414
Test: atest NotificationRecordLoggerTest; statsd_testdrive
Change-Id: I39c700ab844d06a6fb20990c19a27e90440d92c7
parent 9af4c687
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -429,4 +429,14 @@ public interface NotificationRecordLogger {
        return NotificationChannelLogger.getLoggingImportance(channel, importance);
    }

    /**
     * @param r NotificationRecord
     * @return Whether the notification is a foreground service notification.
     */
    static boolean isForegroundService(@NonNull NotificationRecord r) {
        if (r.getSbn() == null || r.getSbn().getNotification() == null) {
            return false;
        }
        return (r.getSbn().getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE) != 0;
    }
}
+6 −1
Original line number Diff line number Diff line
@@ -63,7 +63,12 @@ public class NotificationRecordLoggerImpl implements NotificationRecordLogger {
                /* android.stats.sysui.NotificationImportance importance_asst = 19 */
                r.getAssistantImportance(),
                /* int32 assistant_hash = 20 */ p.getAssistantHash(),
                /* float assistant_ranking_score = 21 */ r.getRankingScore()
                /* float assistant_ranking_score = 21 */ r.getRankingScore(),
                /* bool is_ongoing = 22 */ r.getSbn().isOngoing(),
                /* bool is_foreground_service = 23 */
                NotificationRecordLogger.isForegroundService(r),
                /* optional int64 timeout_millis = 24 */
                r.getSbn().getNotification().getTimeoutAfter()
        );
    }

+14 −0
Original line number Diff line number Diff line
@@ -16,10 +16,13 @@

package com.android.server.notification;

import static android.app.Notification.FLAG_FOREGROUND_SERVICE;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import android.app.Notification;
import android.app.NotificationChannel;
@@ -116,4 +119,15 @@ public class NotificationRecordLoggerTest extends UiServiceTestCase {
                SmallHash.hash(group.hashCode()),
                p.getGroupIdHash());
    }

    @Test
    public void testIsForegroundService() {
        NotificationRecordLogger.NotificationRecordPair p = getNotificationRecordPair(
                0, null);
        assertFalse(NotificationRecordLogger.isForegroundService(p.r));

        // Set foreground service
        p.r.getSbn().getNotification().flags |= FLAG_FOREGROUND_SERVICE;
        assertTrue(NotificationRecordLogger.isForegroundService(p.r));
    }
}