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

Commit 04ff3ee7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Clarify notif guts for apps that don't use shortcuts" into rvc-dev am: dee3bbc8

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11813695

Change-Id: Ic662c41f9dc86b84674fd77f83255f76dfa10ecc
parents 7ae48385 dee3bbc8
Loading
Loading
Loading
Loading
+1 −15
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@
        android:clipChildren="false"
        android:clipToPadding="false">
        <ImageView
            android:id="@+id/conversation_icon"
            android:id="@+id/icon"
            android:layout_width="@dimen/notification_guts_conversation_icon_size"
            android:layout_height="@dimen/notification_guts_conversation_icon_size"
            android:layout_centerVertical="true"
@@ -59,20 +59,6 @@
                android:ellipsize="end"
                android:textDirection="locale"
                style="@style/TextAppearance.NotificationImportanceChannel"/>
            <TextView
                android:id="@+id/parent_channel_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ellipsize="end"
                android:textDirection="locale"
                style="@style/TextAppearance.NotificationImportanceChannel"/>
            <TextView
                android:id="@+id/group_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ellipsize="end"
                android:textDirection="locale"
                style="@style/TextAppearance.NotificationImportanceChannelGroup"/>
            <TextView
                android:id="@+id/delegate_name"
                android:layout_width="match_parent"
+5 −47
Original line number Diff line number Diff line
@@ -148,8 +148,7 @@ public class PartialConversationInfo extends LinearLayout implements
    }

    private void bindHeader() {
        bindConversationDetails();

        bindPackage();
        // Delegate
        bindDelegate();
    }
@@ -180,51 +179,6 @@ public class PartialConversationInfo extends LinearLayout implements
        });
    }

    private void bindConversationDetails() {
        final TextView channelName = findViewById(R.id.parent_channel_name);
        channelName.setText(mNotificationChannel.getName());

        bindGroup();
        bindName();
        bindPackage();
        bindIcon();
    }

    private void bindName() {
        TextView name = findViewById(R.id.name);
        Bundle extras = mSbn.getNotification().extras;
        CharSequence nameString = extras.getCharSequence(Notification.EXTRA_CONVERSATION_TITLE, "");
        if (TextUtils.isEmpty(nameString)) {
            nameString = extras.getCharSequence(Notification.EXTRA_TITLE, "");
        }
        name.setText(nameString);
    }

    private void bindIcon() {
        ImageView image = findViewById(R.id.conversation_icon);
        if (mSbn.getNotification().extras.getBoolean(EXTRA_IS_GROUP_CONVERSATION, false)) {
            // TODO: maybe use a generic group icon, or a composite of recent senders
            image.setImageDrawable(mPkgIcon);
        } else {
            final List<Notification.MessagingStyle.Message> messages =
                    Notification.MessagingStyle.Message.getMessagesFromBundleArray(
                            (Parcelable[]) mSbn.getNotification().extras.get(
                                    Notification.EXTRA_MESSAGES));

            final Notification.MessagingStyle.Message latestMessage =
                    Notification.MessagingStyle.findLatestIncomingMessage(messages);
            Icon personIcon = null;
            if (latestMessage != null && latestMessage.getSenderPerson() != null) {
                personIcon = latestMessage.getSenderPerson().getIcon();
            }
            if (personIcon != null) {
                image.setImageIcon(latestMessage.getSenderPerson().getIcon());
            } else {
                image.setImageDrawable(mPkgIcon);
            }
        }
    }

    private void bindPackage() {
        ApplicationInfo info;
        try {
@@ -241,6 +195,10 @@ public class PartialConversationInfo extends LinearLayout implements
        } catch (PackageManager.NameNotFoundException e) {
            mPkgIcon = mPm.getDefaultActivityIcon();
        }
        TextView name = findViewById(R.id.name);
        name.setText(mAppName);
        ImageView image = findViewById(R.id.icon);
        image.setImageDrawable(mPkgIcon);
    }

    private void bindDelegate() {
+6 −91
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.view.View.VISIBLE;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;

import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyInt;
@@ -162,6 +163,7 @@ public class PartialConversationInfoTest extends SysuiTestCase {

    @Test
    public void testBindNotification_SetsName() {
        when(mMockPackageManager.getApplicationLabel(any())).thenReturn("Package");
        mInfo.bindNotification(
                mMockPackageManager,
                mMockINotificationManager,
@@ -174,42 +176,13 @@ public class PartialConversationInfoTest extends SysuiTestCase {
                true,
                false);
        final TextView textView = mInfo.findViewById(R.id.name);
        assertTrue(textView.getText().toString().contains("title"));
        assertTrue(textView.getText().toString().equals("Package"));
    }

    @Test
    public void testBindNotification_groupSetsPackageIcon() {
        mEntry.getSbn().getNotification().extras.putBoolean(EXTRA_IS_GROUP_CONVERSATION, true);
        final Drawable iconDrawable = mock(Drawable.class);
        when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class)))
                .thenReturn(iconDrawable);
        mInfo.bindNotification(
                mMockPackageManager,
                mMockINotificationManager,
                mChannelEditorDialogController,
                TEST_PACKAGE_NAME,
                mNotificationChannel,
                mNotificationChannelSet,
                mEntry,
                null,
                true,
                false);
        final ImageView iconView = mInfo.findViewById(R.id.conversation_icon);
        assertEquals(iconDrawable, iconView.getDrawable());
    }

    @Test
    public void testBindNotification_notGroupSetsMessageIcon() {
        Notification n = new Notification.Builder(mContext, TEST_CHANNEL_NAME)
                .setStyle(new Notification.MessagingStyle(
                        new Person.Builder().setName("me").build())
                .addMessage(new Notification.MessagingStyle.Message("hello", 0,
                        new Person.Builder().setName("friend").setIcon(mIcon).build())))
                .build();
        mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0,
                n, UserHandle.CURRENT, null, 0);
        mEntry.setSbn(mSbn);
        mEntry.getSbn().getNotification().extras.putBoolean(EXTRA_IS_GROUP_CONVERSATION, false);
    public void testBindNotification_setsIcon() {
        when(mMockPackageManager.getApplicationIcon((ApplicationInfo) any())).thenReturn(mDrawable);
        mInfo.bindNotification(
                mMockPackageManager,
                mMockINotificationManager,
@@ -221,7 +194,7 @@ public class PartialConversationInfoTest extends SysuiTestCase {
                null,
                true,
                false);
        final ImageView iconView = mInfo.findViewById(R.id.conversation_icon);
        final ImageView iconView = mInfo.findViewById(R.id.icon);
        assertEquals(mDrawable.hashCode() + "", mDrawable, iconView.getDrawable());
    }

@@ -269,64 +242,6 @@ public class PartialConversationInfoTest extends SysuiTestCase {
        assertTrue(nameView.getText().toString().contains("Proxied"));
    }

    @Test
    public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception {
        mInfo.bindNotification(
                mMockPackageManager,
                mMockINotificationManager,
                mChannelEditorDialogController,
                TEST_PACKAGE_NAME,
                mNotificationChannel,
                mNotificationChannelSet,
                mEntry,
                null,
                true,
                false);
        final TextView groupNameView = mInfo.findViewById(R.id.group_name);
        assertEquals(GONE, groupNameView.getVisibility());
    }

    @Test
    public void testBindNotification_SetsGroupNameIfNonNull() throws Exception {
        mNotificationChannel.setGroup("test_group_id");
        final NotificationChannelGroup notificationChannelGroup =
                new NotificationChannelGroup("test_group_id", "Test Group Name");
        when(mMockINotificationManager.getNotificationChannelGroupForPackage(
                eq("test_group_id"), eq(TEST_PACKAGE_NAME), eq(TEST_UID)))
                .thenReturn(notificationChannelGroup);
        mInfo.bindNotification(
                mMockPackageManager,
                mMockINotificationManager,
                mChannelEditorDialogController,
                TEST_PACKAGE_NAME,
                mNotificationChannel,
                mNotificationChannelSet,
                mEntry,
                null,
                true,
                false);
        final TextView groupNameView = mInfo.findViewById(R.id.group_name);
        assertEquals(View.VISIBLE, groupNameView.getVisibility());
        assertEquals("Test Group Name", groupNameView.getText());
    }

    @Test
    public void testBindNotification_SetsTextChannelName() {
        mInfo.bindNotification(
                mMockPackageManager,
                mMockINotificationManager,
                mChannelEditorDialogController,
                TEST_PACKAGE_NAME,
                mNotificationChannel,
                mNotificationChannelSet,
                mEntry,
                null,
                true,
                false);
        final TextView textView = mInfo.findViewById(R.id.parent_channel_name);
        assertEquals(TEST_CHANNEL_NAME, textView.getText());
    }

    @Test
    public void testBindNotification_SetsOnClickListenerForSettings() {
        final CountDownLatch latch = new CountDownLatch(1);