Merge "Clarify notif guts for apps that don't use shortcuts" into rvc-dev am: dee3bbc823
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11813695 Change-Id: I79dc737bdfb5eb1efc9cb87a6b5577c48ffe99c8
This commit is contained in:
@@ -35,7 +35,7 @@
|
|||||||
android:clipChildren="false"
|
android:clipChildren="false"
|
||||||
android:clipToPadding="false">
|
android:clipToPadding="false">
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/conversation_icon"
|
android:id="@+id/icon"
|
||||||
android:layout_width="@dimen/notification_guts_conversation_icon_size"
|
android:layout_width="@dimen/notification_guts_conversation_icon_size"
|
||||||
android:layout_height="@dimen/notification_guts_conversation_icon_size"
|
android:layout_height="@dimen/notification_guts_conversation_icon_size"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
@@ -59,20 +59,6 @@
|
|||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:textDirection="locale"
|
android:textDirection="locale"
|
||||||
style="@style/TextAppearance.NotificationImportanceChannel"/>
|
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
|
<TextView
|
||||||
android:id="@+id/delegate_name"
|
android:id="@+id/delegate_name"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -148,8 +148,7 @@ public class PartialConversationInfo extends LinearLayout implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void bindHeader() {
|
private void bindHeader() {
|
||||||
bindConversationDetails();
|
bindPackage();
|
||||||
|
|
||||||
// Delegate
|
// Delegate
|
||||||
bindDelegate();
|
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() {
|
private void bindPackage() {
|
||||||
ApplicationInfo info;
|
ApplicationInfo info;
|
||||||
try {
|
try {
|
||||||
@@ -241,6 +195,10 @@ public class PartialConversationInfo extends LinearLayout implements
|
|||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
mPkgIcon = mPm.getDefaultActivityIcon();
|
mPkgIcon = mPm.getDefaultActivityIcon();
|
||||||
}
|
}
|
||||||
|
TextView name = findViewById(R.id.name);
|
||||||
|
name.setText(mAppName);
|
||||||
|
ImageView image = findViewById(R.id.icon);
|
||||||
|
image.setImageDrawable(mPkgIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindDelegate() {
|
private void bindDelegate() {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import static android.view.View.VISIBLE;
|
|||||||
import static junit.framework.Assert.assertEquals;
|
import static junit.framework.Assert.assertEquals;
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static junit.framework.Assert.assertTrue;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.anyObject;
|
||||||
import static org.mockito.Mockito.any;
|
import static org.mockito.Mockito.any;
|
||||||
import static org.mockito.Mockito.anyBoolean;
|
import static org.mockito.Mockito.anyBoolean;
|
||||||
import static org.mockito.Mockito.anyInt;
|
import static org.mockito.Mockito.anyInt;
|
||||||
@@ -162,6 +163,7 @@ public class PartialConversationInfoTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindNotification_SetsName() {
|
public void testBindNotification_SetsName() {
|
||||||
|
when(mMockPackageManager.getApplicationLabel(any())).thenReturn("Package");
|
||||||
mInfo.bindNotification(
|
mInfo.bindNotification(
|
||||||
mMockPackageManager,
|
mMockPackageManager,
|
||||||
mMockINotificationManager,
|
mMockINotificationManager,
|
||||||
@@ -174,15 +176,13 @@ public class PartialConversationInfoTest extends SysuiTestCase {
|
|||||||
true,
|
true,
|
||||||
false);
|
false);
|
||||||
final TextView textView = mInfo.findViewById(R.id.name);
|
final TextView textView = mInfo.findViewById(R.id.name);
|
||||||
assertTrue(textView.getText().toString().contains("title"));
|
assertTrue(textView.getText().toString().equals("Package"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindNotification_groupSetsPackageIcon() {
|
public void testBindNotification_setsIcon() {
|
||||||
mEntry.getSbn().getNotification().extras.putBoolean(EXTRA_IS_GROUP_CONVERSATION, true);
|
when(mMockPackageManager.getApplicationIcon((ApplicationInfo) any())).thenReturn(mDrawable);
|
||||||
final Drawable iconDrawable = mock(Drawable.class);
|
|
||||||
when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class)))
|
|
||||||
.thenReturn(iconDrawable);
|
|
||||||
mInfo.bindNotification(
|
mInfo.bindNotification(
|
||||||
mMockPackageManager,
|
mMockPackageManager,
|
||||||
mMockINotificationManager,
|
mMockINotificationManager,
|
||||||
@@ -194,34 +194,7 @@ public class PartialConversationInfoTest extends SysuiTestCase {
|
|||||||
null,
|
null,
|
||||||
true,
|
true,
|
||||||
false);
|
false);
|
||||||
final ImageView iconView = mInfo.findViewById(R.id.conversation_icon);
|
final ImageView iconView = mInfo.findViewById(R.id.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);
|
|
||||||
mInfo.bindNotification(
|
|
||||||
mMockPackageManager,
|
|
||||||
mMockINotificationManager,
|
|
||||||
mChannelEditorDialogController,
|
|
||||||
TEST_PACKAGE_NAME,
|
|
||||||
mNotificationChannel,
|
|
||||||
mNotificationChannelSet,
|
|
||||||
mEntry,
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
false);
|
|
||||||
final ImageView iconView = mInfo.findViewById(R.id.conversation_icon);
|
|
||||||
assertEquals(mDrawable.hashCode() + "", mDrawable, iconView.getDrawable());
|
assertEquals(mDrawable.hashCode() + "", mDrawable, iconView.getDrawable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,64 +242,6 @@ public class PartialConversationInfoTest extends SysuiTestCase {
|
|||||||
assertTrue(nameView.getText().toString().contains("Proxied"));
|
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
|
@Test
|
||||||
public void testBindNotification_SetsOnClickListenerForSettings() {
|
public void testBindNotification_SetsOnClickListenerForSettings() {
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user