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

Commit 4629f29a authored by Geoffrey Pitsch's avatar Geoffrey Pitsch Committed by android-build-merger
Browse files

Merge "Pre-O apps can see Default Channel name." into oc-dev am: e7fb3c9f

am: b6eedcc8

Change-Id: I639c8b667e83657d0bf4a25285e57548eef6c876
parents d74dedc2 b6eedcc8
Loading
Loading
Loading
Loading
+16 −14
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
    private int mAppUid;
    private List<NotificationChannel> mNotificationChannels;
    private NotificationChannel mSingleNotificationChannel;
    private boolean mIsSingleDefaultChannel;
    private StatusBarNotification mSbn;
    private int mStartingUserImportance;

@@ -113,17 +114,23 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
        mSbn = sbn;
        mPm = pm;
        mAppSettingsClickListener = onAppSettingsClick;
        boolean isSingleDefaultChannel = false;
        mStartingUserImportance = startingUserImportance;
        int numTotalChannels = 1;
        numTotalChannels = iNotificationManager.getNumNotificationChannelsForPackage(
                pkg, mAppUid, false /* includeDeleted */);
        if (mNotificationChannels.isEmpty()) {
            throw new IllegalArgumentException("bindNotification requires at least one channel");
        } else  {
            if (mNotificationChannels.size() == 1) {
                mSingleNotificationChannel = mNotificationChannels.get(0);
                isSingleDefaultChannel = mSingleNotificationChannel.getId()
                        .equals(NotificationChannel.DEFAULT_CHANNEL_ID);
                // Special behavior for the Default channel if no other channels have been defined.
                mIsSingleDefaultChannel =
                        (mSingleNotificationChannel.getId()
                                .equals(NotificationChannel.DEFAULT_CHANNEL_ID) &&
                        numTotalChannels <= 1);
            } else {
                mSingleNotificationChannel = null;
                mIsSingleDefaultChannel = false;
            }
        }

@@ -148,19 +155,16 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
        }
        ((ImageView) findViewById(R.id.pkgicon)).setImageDrawable(pkgicon);

        int numChannels = 1;
        numChannels = iNotificationManager.getNumNotificationChannelsForPackage(
                pkg, mAppUid, false /* includeDeleted */);

        String channelsDescText;
        mNumChannelsView = findViewById(R.id.num_channels_desc);
        if (isSingleDefaultChannel) {
        if (mIsSingleDefaultChannel) {
            channelsDescText = mContext.getString(R.string.notification_default_channel_desc);
        } else {
            switch (mNotificationChannels.size()) {
                case 1:
                    channelsDescText = String.format(mContext.getResources().getQuantityString(
                            R.plurals.notification_num_channels_desc, numChannels), numChannels);
                            R.plurals.notification_num_channels_desc, numTotalChannels),
                            numTotalChannels);
                    break;
                case 2:
                    channelsDescText = mContext.getString(
@@ -185,7 +189,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
            // Multiple channels don't use a channel name for the title.
            channelNameText = mContext.getString(R.string.notification_num_channels,
                    mNotificationChannels.size());
        } else if (isSingleDefaultChannel) {
        } else if (mIsSingleDefaultChannel) {
            // If this is the default channel, don't use our channel-specific text.
            channelNameText = mContext.getString(R.string.notification_header_default_channel);
        } else {
@@ -241,7 +245,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
                    (View view) -> {
                        onSettingsClick.onClick(view, mSingleNotificationChannel, appUidF);
                    });
            if (numChannels > 1) {
            if (numTotalChannels > 1) {
                settingsButton.setText(R.string.notification_all_categories);
            } else {
                settingsButton.setText(R.string.notification_more_settings);
@@ -327,14 +331,12 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
    private void updateSecondaryText() {
        final boolean disabled = mSingleNotificationChannel != null &&
                getSelectedImportance() == IMPORTANCE_NONE;
        final boolean isDefaultChannel = mSingleNotificationChannel != null &&
                mSingleNotificationChannel.getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID);
        if (disabled) {
            mChannelDisabledView.setVisibility(View.VISIBLE);
            mNumChannelsView.setVisibility(View.GONE);
        } else {
            mChannelDisabledView.setVisibility(View.GONE);
            mNumChannelsView.setVisibility(isDefaultChannel ? View.INVISIBLE : View.VISIBLE);
            mNumChannelsView.setVisibility(mIsSingleDefaultChannel ? View.INVISIBLE : View.VISIBLE);
        }
    }

+39 −0
Original line number Diff line number Diff line
@@ -209,6 +209,30 @@ public class NotificationInfoTest extends SysuiTestCase {
        assertEquals(TEST_CHANNEL_NAME, textView.getText());
    }

    @Test
    public void testBindNotification_DefaultChannelDoesNotUseChannelName() throws Exception {
        mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
                TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel),
                mNotificationChannel.getImportance(), mSbn, null, null, null,
                null, null);
        final TextView textView = (TextView) mNotificationInfo.findViewById(R.id.channel_name);
        assertEquals(mContext.getString(R.string.notification_header_default_channel),
                textView.getText());
    }

    @Test
    public void testBindNotification_DefaultChannelUsesNameWhenMoreThanOneChannelExists()
            throws Exception {
        when(mMockINotificationManager.getNumNotificationChannelsForPackage(
                eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(2);
        mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
                TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel),
                mNotificationChannel.getImportance(), mSbn, null, null, null,
                null, null);
        final TextView textView = (TextView) mNotificationInfo.findViewById(R.id.channel_name);
        assertEquals(mDefaultNotificationChannel.getName(), textView.getText());
    }

    @Test
    public void testBindNotification_SetsOnClickListenerForSettings() throws Exception {
        final CountDownLatch latch = new CountDownLatch(1);
@@ -324,6 +348,21 @@ public class NotificationInfoTest extends SysuiTestCase {
        assertEquals(View.INVISIBLE, numChannelsView.getVisibility());
    }

    @Test
    public void testBindNotification_NumChannelsTextDisplaysWhenMoreThanOneChannelExists()
            throws Exception {
        when(mMockINotificationManager.getNumNotificationChannelsForPackage(
                eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(2);
        mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
                TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel),
                mNotificationChannel.getImportance(), mSbn, null, null,
                null, null, null);
        final TextView numChannelsView =
                (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
        assertEquals(numChannelsView.getVisibility(), View.VISIBLE);
        assertEquals(getNumChannelsDescString(2), numChannelsView.getText());
    }

    @Test
    public void testBindNotification_NumChannelsTextDisplaysWhenNotDefaultChannel()
            throws Exception {