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

Commit 95334134 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Proxy notifications should not change an app's usage bucket

Test: atest
Change-Id: I9ec9fe68e9a7672b50a1c1beec052e4c950e2e4b
Fixes: 117784235
parent b444a8b8
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -1952,10 +1952,12 @@ public class NotificationManagerService extends SystemService {
     */
    @GuardedBy("mNotificationLock")
    protected void reportSeen(NotificationRecord r) {
        if (!r.isProxied()) {
            mAppUsageStats.reportEvent(r.sbn.getPackageName(),
                    getRealUserId(r.sbn.getUserId()),
                    UsageEvents.Event.NOTIFICATION_SEEN);
        }
    }

    protected int calculateSuppressedVisualEffects(Policy incomingPolicy, Policy currPolicy,
            int targetSdkVersion) {
+7 −1
Original line number Diff line number Diff line
@@ -151,7 +151,6 @@ public final class NotificationRecord {

    private int mSuppressedVisualEffects = 0;
    private String mUserExplanation;
    private String mPeopleExplanation;
    private boolean mPreChannelsNotification = true;
    private Uri mSound;
    private long[] mVibration;
@@ -1190,6 +1189,13 @@ public final class NotificationRecord {
        return mSmartReplies;
    }

    /**
     * Returns whether this notification was posted by a secondary app
     */
    public boolean isProxied() {
        return !Objects.equals(sbn.getPackageName(), sbn.getOpPkg());
    }

    /**
     * @return all {@link Uri} that should have permission granted to whoever
     *         will be rendering it. This list has already been vetted to only
+24 −6
Original line number Diff line number Diff line
@@ -231,11 +231,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
            return null;
        }

        @Override
        protected void reportSeen(NotificationRecord r) {
            return;
        }

        @Override
        protected void reportUserInteraction(NotificationRecord r) {
            return;
@@ -3831,4 +3826,27 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

        assertEquals(0, mService.countLogSmartSuggestionsVisible);
    }

    public void testReportSeen_delegated() {
        Notification.Builder nb =
                new Notification.Builder(mContext, mTestNotificationChannel.getId())
                        .setContentTitle("foo")
                        .setSmallIcon(android.R.drawable.sym_def_app_icon);

        StatusBarNotification sbn = new StatusBarNotification(PKG, "opPkg", 0, "tag", mUid, 0,
                nb.build(), new UserHandle(mUid), null, 0);
        NotificationRecord r =  new NotificationRecord(mContext, sbn, mTestNotificationChannel);

        mService.reportSeen(r);
        verify(mAppUsageStats, never()).reportEvent(anyString(), anyInt(), anyInt());

    }

    @Test
    public void testReportSeen_notDelegated() {
        NotificationRecord r = generateNotificationRecord(mTestNotificationChannel);

        mService.reportSeen(r);
        verify(mAppUsageStats, times(1)).reportEvent(anyString(), anyInt(), anyInt());
    }
}