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

Commit dbd64e7b authored by Rohan Shah's avatar Rohan Shah
Browse files

[Notif] Write AppUid earlier in NotificationInfo

Noticed that appuid was being used but it wasn't set until later in the
lifecycle of the notificationinfo (rendering the channel logic moot).

If the notif is now posting notificiations to the default channel while
having multiple channels, it'll now show "Uncategorized" in the blocking
helper/notification info screens.

Fixes: 77240828
Test: Ran NotifInfoTest (added one new test case)
Test: Visually, artificially sent default ch notif with app having 9 ch
Change-Id: I45f2c35fb6dae610e511b2d316b3c184b84f2d09
parent 7eee509d
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -165,6 +165,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
        mIsForeground =
        mIsForeground =
                (mSbn.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE) != 0;
                (mSbn.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE) != 0;
        mIsForBlockingHelper = isForBlockingHelper;
        mIsForBlockingHelper = isForBlockingHelper;
        mAppUid = mSbn.getUid();


        int numTotalChannels = mINotificationManager.getNumNotificationChannelsForPackage(
        int numTotalChannels = mINotificationManager.getNumNotificationChannelsForPackage(
                pkg, mAppUid, false /* includeDeleted */);
                pkg, mAppUid, false /* includeDeleted */);
@@ -173,9 +174,9 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
        } else  {
        } else  {
            // Special behavior for the Default channel if no other channels have been defined.
            // Special behavior for the Default channel if no other channels have been defined.
            mIsSingleDefaultChannel = mNumNotificationChannels == 1
            mIsSingleDefaultChannel = mNumNotificationChannels == 1
                    && mSingleNotificationChannel.getId()
                    && mSingleNotificationChannel.getId().equals(
                    .equals(NotificationChannel.DEFAULT_CHANNEL_ID)
                            NotificationChannel.DEFAULT_CHANNEL_ID)
                    && numTotalChannels <= 1;
                    && numTotalChannels == 1;
        }
        }


        try {
        try {
@@ -210,7 +211,6 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
                            | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
                            | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
                            | PackageManager.MATCH_DIRECT_BOOT_AWARE);
                            | PackageManager.MATCH_DIRECT_BOOT_AWARE);
            if (info != null) {
            if (info != null) {
                mAppUid = mSbn.getUid();
                mAppName = String.valueOf(mPm.getApplicationLabel(info));
                mAppName = String.valueOf(mPm.getApplicationLabel(info));
                pkgicon = mPm.getApplicationIcon(info);
                pkgicon = mPm.getApplicationIcon(info);
            }
            }
+12 −0
Original line number Original line Diff line number Diff line
@@ -217,6 +217,18 @@ public class NotificationInfoTest extends SysuiTestCase {
        assertEquals(GONE, textView.getVisibility());
        assertEquals(GONE, textView.getVisibility());
    }
    }


    @Test
    public void testBindNotification_DefaultChannelUsesChannelNameIfMoreChannelsExist()
            throws Exception {
        // Package has one channel by default.
        when(mMockINotificationManager.getNumNotificationChannelsForPackage(
                eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(10);
        mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
                TEST_PACKAGE_NAME, mDefaultNotificationChannel, 1, mSbn, null, null, null, null);
        final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
        assertEquals(VISIBLE, textView.getVisibility());
    }

    @Test
    @Test
    public void testBindNotification_UnblockablePackageUsesChannelName() throws Exception {
    public void testBindNotification_UnblockablePackageUsesChannelName() throws Exception {
        mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
        mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,