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

Commit 97c46da2 authored by Yuri Lin's avatar Yuri Lin Committed by Android (Google) Code Review
Browse files

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

parents 2628fa37 549c8f28
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));
    }
}