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

Commit 31db6967 authored by Lyn Han's avatar Lyn Han Committed by Android (Google) Code Review
Browse files

Merge "Log FSI fields on NotificationReported" into udc-qpr-dev

parents c3b5665d 4f2c8448
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static android.service.notification.NotificationListenerService.Ranking.U
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.IActivityManager;
import android.app.KeyguardManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.Person;
@@ -46,6 +47,7 @@ import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.UserHandle;
import android.os.VibrationEffect;
import android.provider.Settings;
@@ -101,7 +103,8 @@ public final class NotificationRecord {
    final int mTargetSdkVersion;
    final int mOriginalFlags;
    private final Context mContext;

    private final KeyguardManager mKeyguardManager;
    private final PowerManager mPowerManager;
    NotificationUsageStats.SingleNotificationStats stats;
    boolean isCanceled;
    IBinder permissionOwner;
@@ -228,6 +231,8 @@ public final class NotificationRecord {
        mUpdateTimeMs = mCreationTimeMs;
        mInterruptionTimeMs = mCreationTimeMs;
        mContext = context;
        mKeyguardManager = mContext.getSystemService(KeyguardManager.class);
        mPowerManager = mContext.getSystemService(PowerManager.class);
        stats = new NotificationUsageStats.SingleNotificationStats();
        mChannel = channel;
        mPreChannelsNotification = isPreChannelsNotification();
@@ -1619,6 +1624,11 @@ public final class NotificationRecord {
        return mPhoneNumbers;
    }

    boolean isLocked() {
        return mKeyguardManager.isKeyguardLocked()
                || !mPowerManager.isInteractive();  // Unlocked AOD
    }

    @VisibleForTesting
    static final class Light {
        public final int color;
+43 −1
Original line number Diff line number Diff line
@@ -31,9 +31,12 @@ import android.os.Bundle;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationStats;

import com.android.internal.config.sysui.SystemUiSystemPropertiesFlags;
import com.android.internal.config.sysui.SystemUiSystemPropertiesFlags.NotificationFlags;
import com.android.internal.logging.InstanceId;
import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.util.FrameworkStatsLog;

import java.util.ArrayList;
import java.util.Objects;
@@ -500,6 +503,8 @@ interface NotificationRecordLogger {
        final boolean is_foreground_service;
        final long timeout_millis;
        final boolean is_non_dismissible;
        final int fsi_state;
        final boolean is_locked;
        @DurationMillisLong long post_duration_millis; // Not final; calculated at the end.

        NotificationReported(NotificationRecordPair p,
@@ -530,6 +535,20 @@ interface NotificationRecordLogger {
            this.is_foreground_service = NotificationRecordLogger.isForegroundService(p.r);
            this.timeout_millis = p.r.getSbn().getNotification().getTimeoutAfter();
            this.is_non_dismissible = NotificationRecordLogger.isNonDismissible(p.r);

            final boolean isStickyHunFlagEnabled = SystemUiSystemPropertiesFlags.getResolver()
                    .isEnabled(NotificationFlags.SHOW_STICKY_HUN_FOR_DENIED_FSI);

            final boolean hasFullScreenIntent =
                    p.r.getSbn().getNotification().fullScreenIntent != null;

            final boolean hasFsiRequestedButDeniedFlag =  (p.r.getSbn().getNotification().flags
                    & Notification.FLAG_FSI_REQUESTED_BUT_DENIED) != 0;

            this.fsi_state = NotificationRecordLogger.getFsiState(isStickyHunFlagEnabled,
                    hasFullScreenIntent, hasFsiRequestedButDeniedFlag, eventType);

            this.is_locked = p.r.isLocked();
        }
    }

@@ -558,7 +577,6 @@ interface NotificationRecordLogger {
    }

    /**
     * @param r NotificationRecord
     * @return Whether the notification is a non-dismissible notification.
     */
    static boolean isNonDismissible(@NonNull NotificationRecord r) {
@@ -567,4 +585,28 @@ interface NotificationRecordLogger {
        }
        return (r.getNotification().flags & Notification.FLAG_NO_DISMISS) != 0;
    }

    /**
     * @return FrameworkStatsLog enum of the state of the full screen intent posted with this
     * notification.
     */
    static int getFsiState(boolean isStickyHunFlagEnabled,
                           boolean hasFullScreenIntent,
                           boolean hasFsiRequestedButDeniedFlag,
                           NotificationReportedEvent eventType) {

        if (!isStickyHunFlagEnabled
                || eventType == NotificationReportedEvent.NOTIFICATION_UPDATED) {
            // Zeroes in protos take zero bandwidth, but non-zero numbers take bandwidth,
            // so we should log 0 when possible.
            return 0;
        }
        if (hasFullScreenIntent) {
            return FrameworkStatsLog.NOTIFICATION_REPORTED__FSI_STATE__FSI_ALLOWED;
        }
        if (hasFsiRequestedButDeniedFlag) {
            return FrameworkStatsLog.NOTIFICATION_REPORTED__FSI_STATE__FSI_DENIED;
        }
        return FrameworkStatsLog.NOTIFICATION_REPORTED__FSI_STATE__NO_FSI;
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -75,7 +75,9 @@ class NotificationRecordLoggerImpl implements NotificationRecordLogger {
                notificationReported.is_foreground_service,
                notificationReported.timeout_millis,
                notificationReported.is_non_dismissible,
                notificationReported.post_duration_millis);
                notificationReported.post_duration_millis,
                notificationReported.fsi_state,
                notificationReported.is_locked);
    }

    @Override
+53 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.server.notification;

import static android.app.Notification.FLAG_FOREGROUND_SERVICE;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent.NOTIFICATION_POSTED;
import static com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent.NOTIFICATION_UPDATED;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -33,6 +35,7 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.server.UiServiceTestCase;
import com.android.internal.util.FrameworkStatsLog;

import org.junit.Test;
import org.junit.runner.RunWith;
@@ -155,4 +158,54 @@ public class NotificationRecordLoggerTest extends UiServiceTestCase {
        // Then: should return false
        assertFalse(NotificationRecordLogger.isNonDismissible(p.r));
    }

    @Test
    public void testGetFsiState_stickyHunFlagDisabled_zero() {
        final int fsiState = NotificationRecordLogger.getFsiState(
                /* isStickyHunFlagEnabled= */ false,
                /* hasFullScreenIntent= */ true,
                /* hasFsiRequestedButDeniedFlag= */ true,
                /* eventType= */ NOTIFICATION_POSTED);
        assertEquals(0, fsiState);
    }

    @Test
    public void testGetFsiState_isUpdate_zero() {
        final int fsiState = NotificationRecordLogger.getFsiState(
                /* isStickyHunFlagEnabled= */ true,
                /* hasFullScreenIntent= */ true,
                /* hasFsiRequestedButDeniedFlag= */ true,
                /* eventType= */ NOTIFICATION_UPDATED);
        assertEquals(0, fsiState);
    }

    @Test
    public void testGetFsiState_hasFsi_allowedEnum() {
        final int fsiState = NotificationRecordLogger.getFsiState(
                /* isStickyHunFlagEnabled= */ true,
                /* hasFullScreenIntent= */ true,
                /* hasFsiRequestedButDeniedFlag= */ false,
                /* eventType= */ NOTIFICATION_POSTED);
        assertEquals(FrameworkStatsLog.NOTIFICATION_REPORTED__FSI_STATE__FSI_ALLOWED, fsiState);
    }

    @Test
    public void testGetFsiState_fsiPermissionDenied_deniedEnum() {
        final int fsiState = NotificationRecordLogger.getFsiState(
                /* isStickyHunFlagEnabled= */ true,
                /* hasFullScreenIntent= */ false,
                /* hasFsiRequestedButDeniedFlag= */ true,
                /* eventType= */ NOTIFICATION_POSTED);
        assertEquals(FrameworkStatsLog.NOTIFICATION_REPORTED__FSI_STATE__FSI_DENIED, fsiState);
    }

    @Test
    public void testGetFsiState_noFsi_noFsiEnum() {
        final int fsiState = NotificationRecordLogger.getFsiState(
                /* isStickyHunFlagEnabled= */ true,
                /* hasFullScreenIntent= */ false,
                /* hasFsiRequestedButDeniedFlag= */ false,
                /* eventType= */ NOTIFICATION_POSTED);
        assertEquals(FrameworkStatsLog.NOTIFICATION_REPORTED__FSI_STATE__NO_FSI, fsiState);
    }
}