Check existing notification on People Tile add
Change-Id: I6b82d49504e5773a96c5ee5fa52ca324b44443b7 Test: manual and unit tests Bug: 179038776
This commit is contained in:
@@ -20,6 +20,7 @@ import android.app.Activity;
|
||||
|
||||
import com.android.systemui.ForegroundServicesDialog;
|
||||
import com.android.systemui.keyguard.WorkLockActivity;
|
||||
import com.android.systemui.people.PeopleSpaceActivity;
|
||||
import com.android.systemui.screenrecord.ScreenRecordDialog;
|
||||
import com.android.systemui.settings.brightness.BrightnessDialog;
|
||||
import com.android.systemui.statusbar.tv.notifications.TvNotificationPanelActivity;
|
||||
@@ -92,4 +93,10 @@ public abstract class DefaultActivityBinder {
|
||||
@IntoMap
|
||||
@ClassKey(TvNotificationPanelActivity.class)
|
||||
public abstract Activity bindTvNotificationPanelActivity(TvNotificationPanelActivity activity);
|
||||
|
||||
/** Inject into PeopleSpaceActivity. */
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ClassKey(PeopleSpaceActivity.class)
|
||||
public abstract Activity bindPeopleSpaceActivity(PeopleSpaceActivity activity);
|
||||
}
|
||||
|
||||
@@ -37,9 +37,12 @@ import android.view.ViewGroup;
|
||||
import com.android.internal.logging.UiEventLogger;
|
||||
import com.android.internal.logging.UiEventLoggerImpl;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.statusbar.notification.NotificationEntryManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Shows the user their tiles for their priority People (go/live-status).
|
||||
*/
|
||||
@@ -54,10 +57,17 @@ public class PeopleSpaceActivity extends Activity {
|
||||
private LauncherApps mLauncherApps;
|
||||
private Context mContext;
|
||||
private AppWidgetManager mAppWidgetManager;
|
||||
private NotificationEntryManager mNotificationEntryManager;
|
||||
private int mAppWidgetId;
|
||||
private boolean mShowSingleConversation;
|
||||
private UiEventLogger mUiEventLogger = new UiEventLoggerImpl();
|
||||
|
||||
@Inject
|
||||
public PeopleSpaceActivity(NotificationEntryManager notificationEntryManager) {
|
||||
super();
|
||||
mNotificationEntryManager = notificationEntryManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -91,8 +101,8 @@ public class PeopleSpaceActivity extends Activity {
|
||||
*/
|
||||
private void setTileViewsWithPriorityConversations() {
|
||||
try {
|
||||
List<PeopleSpaceTile> tiles = PeopleSpaceUtils.getTiles(
|
||||
mContext, mNotificationManager, mPeopleManager, mLauncherApps);
|
||||
List<PeopleSpaceTile> tiles = PeopleSpaceUtils.getTiles(mContext, mNotificationManager,
|
||||
mPeopleManager, mLauncherApps, mNotificationEntryManager);
|
||||
for (PeopleSpaceTile tile : tiles) {
|
||||
PeopleSpaceTileView tileView = new PeopleSpaceTileView(mContext, mPeopleSpaceLayout,
|
||||
tile.getId());
|
||||
|
||||
@@ -60,9 +60,12 @@ import com.android.internal.logging.UiEvent;
|
||||
import com.android.internal.logging.UiEventLogger;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.people.widget.LaunchConversationActivity;
|
||||
import com.android.systemui.people.widget.PeopleSpaceWidgetProvider;
|
||||
import com.android.systemui.statusbar.notification.NotificationEntryManager;
|
||||
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Duration;
|
||||
@@ -137,7 +140,7 @@ public class PeopleSpaceUtils {
|
||||
/** Returns a list of map entries corresponding to user's conversations. */
|
||||
public static List<PeopleSpaceTile> getTiles(
|
||||
Context context, INotificationManager notificationManager, IPeopleManager peopleManager,
|
||||
LauncherApps launcherApps)
|
||||
LauncherApps launcherApps, NotificationEntryManager notificationEntryManager)
|
||||
throws Exception {
|
||||
boolean showOnlyPriority = Settings.Global.getInt(context.getContentResolver(),
|
||||
Settings.Global.PEOPLE_SPACE_CONVERSATION_TYPE, 0) == 1;
|
||||
@@ -173,6 +176,8 @@ public class PeopleSpaceUtils {
|
||||
getSortedTiles(peopleManager, launcherApps, mergedStream);
|
||||
tiles.addAll(recentTiles);
|
||||
}
|
||||
|
||||
tiles = augmentTilesFromVisibleNotifications(tiles, notificationEntryManager);
|
||||
return tiles;
|
||||
}
|
||||
|
||||
@@ -258,7 +263,8 @@ public class PeopleSpaceUtils {
|
||||
ServiceManager.getService(Context.NOTIFICATION_SERVICE)),
|
||||
IPeopleManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.PEOPLE_SERVICE)),
|
||||
context.getSystemService(LauncherApps.class));
|
||||
context.getSystemService(LauncherApps.class),
|
||||
Dependency.get(NotificationEntryManager.class));
|
||||
Optional<PeopleSpaceTile> entry = tiles.stream().filter(
|
||||
e -> e.getId().equals(shortcutId)).findFirst();
|
||||
if (entry.isPresent()) {
|
||||
@@ -339,6 +345,41 @@ public class PeopleSpaceUtils {
|
||||
&& storedUserId == userId;
|
||||
}
|
||||
|
||||
static List<PeopleSpaceTile> augmentTilesFromVisibleNotifications(List<PeopleSpaceTile> tiles,
|
||||
NotificationEntryManager notificationEntryManager) {
|
||||
if (notificationEntryManager == null) {
|
||||
Log.w(TAG, "NotificationEntryManager is null");
|
||||
return tiles;
|
||||
}
|
||||
Map<String, NotificationEntry> visibleNotifications = notificationEntryManager
|
||||
.getVisibleNotifications()
|
||||
.stream()
|
||||
.filter(entry -> entry.getRanking() != null
|
||||
&& entry.getRanking().getConversationShortcutInfo() != null)
|
||||
.collect(Collectors.toMap(PeopleSpaceUtils::getKey, e -> e));
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Number of visible notifications:" + visibleNotifications.size());
|
||||
}
|
||||
return tiles
|
||||
.stream()
|
||||
.map(entry -> augmentTileFromVisibleNotifications(entry, visibleNotifications))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
static PeopleSpaceTile augmentTileFromVisibleNotifications(PeopleSpaceTile tile,
|
||||
Map<String, NotificationEntry> visibleNotifications) {
|
||||
String shortcutId = tile.getId();
|
||||
String packageName = tile.getPackageName();
|
||||
int userId = UserHandle.getUserHandleForUid(tile.getUid()).getIdentifier();
|
||||
String key = getKey(shortcutId, packageName, userId);
|
||||
if (!visibleNotifications.containsKey(key)) {
|
||||
if (DEBUG) Log.d(TAG, "No existing notifications for key:" + key);
|
||||
return tile;
|
||||
}
|
||||
if (DEBUG) Log.d(TAG, "Augmenting tile from visible notifications, key:" + key);
|
||||
return augmentTileFromNotification(tile, visibleNotifications.get(key).getSbn());
|
||||
}
|
||||
|
||||
/**
|
||||
* If incoming notification changed tile, store the changes in the tile options.
|
||||
*/
|
||||
@@ -355,17 +396,7 @@ public class PeopleSpaceUtils {
|
||||
}
|
||||
if (notificationAction == PeopleSpaceUtils.NotificationAction.POSTED) {
|
||||
if (DEBUG) Log.i(TAG, "Adding notification to storage, appWidgetId: " + appWidgetId);
|
||||
Notification.MessagingStyle.Message message = getLastMessagingStyleMessage(sbn);
|
||||
if (message == null) {
|
||||
if (DEBUG) Log.i(TAG, "Notification doesn't have content, skipping.");
|
||||
return;
|
||||
}
|
||||
storedTile = storedTile
|
||||
.toBuilder()
|
||||
.setNotificationKey(sbn.getKey())
|
||||
.setNotificationContent(message.getText())
|
||||
.setNotificationDataUri(message.getDataUri())
|
||||
.build();
|
||||
storedTile = augmentTileFromNotification(storedTile, sbn);
|
||||
} else {
|
||||
if (DEBUG) {
|
||||
Log.i(TAG, "Removing notification from storage, appWidgetId: " + appWidgetId);
|
||||
@@ -380,6 +411,21 @@ public class PeopleSpaceUtils {
|
||||
updateAppWidgetOptionsAndView(appWidgetManager, context, appWidgetId, storedTile);
|
||||
}
|
||||
|
||||
static PeopleSpaceTile augmentTileFromNotification(PeopleSpaceTile tile,
|
||||
StatusBarNotification sbn) {
|
||||
Notification.MessagingStyle.Message message = getLastMessagingStyleMessage(sbn);
|
||||
if (message == null) {
|
||||
if (DEBUG) Log.i(TAG, "Notification doesn't have content, skipping.");
|
||||
return tile;
|
||||
}
|
||||
return tile
|
||||
.toBuilder()
|
||||
.setNotificationKey(sbn.getKey())
|
||||
.setNotificationContent(message.getText())
|
||||
.setNotificationDataUri(message.getDataUri())
|
||||
.build();
|
||||
}
|
||||
|
||||
private static void updateAppWidgetOptions(AppWidgetManager appWidgetManager, int appWidgetId,
|
||||
PeopleSpaceTile tile) {
|
||||
if (tile == null) {
|
||||
@@ -792,6 +838,16 @@ public class PeopleSpaceUtils {
|
||||
return lookupKeysWithBirthdaysToday;
|
||||
}
|
||||
|
||||
static String getKey(NotificationEntry entry) {
|
||||
if (entry.getRanking() == null || entry.getRanking().getConversationShortcutInfo() == null
|
||||
|| entry.getSbn() == null || entry.getSbn().getUser() == null) {
|
||||
return null;
|
||||
}
|
||||
return getKey(entry.getRanking().getConversationShortcutInfo().getId(),
|
||||
entry.getSbn().getPackageName(),
|
||||
entry.getSbn().getUser().getIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the uniquely identifying key for the conversation.
|
||||
*
|
||||
|
||||
@@ -135,12 +135,14 @@ public class PeopleSpaceWidgetManager {
|
||||
try {
|
||||
String sbnShortcutId = sbn.getShortcutId();
|
||||
if (sbnShortcutId == null) {
|
||||
if (DEBUG) Log.d(TAG, "Sbn shortcut id is null");
|
||||
return;
|
||||
}
|
||||
int[] widgetIds = mAppWidgetService.getAppWidgetIds(
|
||||
new ComponentName(mContext, PeopleSpaceWidgetProvider.class)
|
||||
);
|
||||
if (widgetIds.length == 0) {
|
||||
Log.d(TAG, "No app widget ids returned");
|
||||
return;
|
||||
}
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
@@ -148,6 +150,7 @@ public class PeopleSpaceWidgetManager {
|
||||
String key = PeopleSpaceUtils.getKey(sbnShortcutId, sbn.getPackageName(), userId);
|
||||
Set<String> storedWidgetIds = new HashSet<>(sp.getStringSet(key, new HashSet<>()));
|
||||
if (storedWidgetIds.isEmpty()) {
|
||||
Log.d(TAG, "No stored widget ids");
|
||||
return;
|
||||
}
|
||||
for (String widgetIdString : storedWidgetIds) {
|
||||
|
||||
@@ -28,9 +28,11 @@ import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
import android.widget.RemoteViewsService;
|
||||
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.people.PeopleSpaceTileView;
|
||||
import com.android.systemui.people.PeopleSpaceUtils;
|
||||
import com.android.systemui.statusbar.notification.NotificationEntryManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -42,6 +44,7 @@ public class PeopleSpaceWidgetRemoteViewsFactory implements RemoteViewsService.R
|
||||
|
||||
private IPeopleManager mPeopleManager;
|
||||
private INotificationManager mNotificationManager;
|
||||
private NotificationEntryManager mNotificationEntryManager;
|
||||
private PackageManager mPackageManager;
|
||||
private LauncherApps mLauncherApps;
|
||||
private List<PeopleSpaceTile> mTiles = new ArrayList<>();
|
||||
@@ -56,6 +59,7 @@ public class PeopleSpaceWidgetRemoteViewsFactory implements RemoteViewsService.R
|
||||
if (DEBUG) Log.d(TAG, "onCreate called");
|
||||
mNotificationManager = INotificationManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
||||
mNotificationEntryManager = Dependency.get(NotificationEntryManager.class);
|
||||
mPackageManager = mContext.getPackageManager();
|
||||
mPeopleManager = IPeopleManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.PEOPLE_SERVICE));
|
||||
@@ -70,7 +74,7 @@ public class PeopleSpaceWidgetRemoteViewsFactory implements RemoteViewsService.R
|
||||
private void setTileViewsWithPriorityConversations() {
|
||||
try {
|
||||
mTiles = PeopleSpaceUtils.getTiles(mContext, mNotificationManager,
|
||||
mPeopleManager, mLauncherApps);
|
||||
mPeopleManager, mLauncherApps, mNotificationEntryManager);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Couldn't retrieve conversations", e);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.systemui.people;
|
||||
|
||||
import static com.android.systemui.people.PeopleSpaceUtils.OPTIONS_PEOPLE_SPACE_TILE;
|
||||
import static com.android.systemui.people.PeopleSpaceUtils.PACKAGE_NAME;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@@ -52,6 +53,7 @@ import android.graphics.drawable.Icon;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.ContactsContract;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.ConversationChannelWrapper;
|
||||
@@ -64,6 +66,9 @@ import com.android.systemui.R;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.statusbar.NotificationListener;
|
||||
import com.android.systemui.statusbar.SbnBuilder;
|
||||
import com.android.systemui.statusbar.notification.NotificationEntryManager;
|
||||
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
|
||||
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -82,10 +87,17 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
|
||||
private static final int WIDGET_ID_WITH_SHORTCUT = 1;
|
||||
private static final int WIDGET_ID_WITHOUT_SHORTCUT = 2;
|
||||
private static final String SHORTCUT_ID = "101";
|
||||
private static final String SHORTCUT_ID_1 = "101";
|
||||
private static final String SHORTCUT_ID_2 = "202";
|
||||
private static final String SHORTCUT_ID_3 = "303";
|
||||
private static final String SHORTCUT_ID_4 = "404";
|
||||
private static final String NOTIFICATION_KEY = "notification_key";
|
||||
private static final String NOTIFICATION_CONTENT = "notification_content";
|
||||
private static final String TEST_LOOKUP_KEY = "lookup_key";
|
||||
private static final String NOTIFICATION_TEXT_1 = "notification_text_1";
|
||||
private static final String NOTIFICATION_TEXT_2 = "notification_text_2";
|
||||
private static final String NOTIFICATION_TEXT_3 = "notification_text_3";
|
||||
private static final String NOTIFICATION_TEXT_4 = "notification_text_4";
|
||||
private static final int TEST_COLUMN_INDEX = 1;
|
||||
private static final Uri URI = Uri.parse("fake_uri");
|
||||
private static final Icon ICON = Icon.createWithResource("package", R.drawable.ic_android);
|
||||
@@ -97,20 +109,66 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
.build();
|
||||
private static final PeopleSpaceTile PERSON_TILE =
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID, "username", ICON, new Intent())
|
||||
.Builder(SHORTCUT_ID_1, "username", ICON, new Intent())
|
||||
.setNotificationKey(NOTIFICATION_KEY)
|
||||
.setNotificationContent(NOTIFICATION_CONTENT)
|
||||
.setNotificationDataUri(URI)
|
||||
.build();
|
||||
|
||||
private final ShortcutInfo mShortcutInfo = new ShortcutInfo.Builder(mContext,
|
||||
SHORTCUT_ID).setLongLabel(
|
||||
SHORTCUT_ID_1).setLongLabel(
|
||||
"name").setPerson(PERSON)
|
||||
.build();
|
||||
private final ShortcutInfo mShortcutInfoWithoutPerson = new ShortcutInfo.Builder(mContext,
|
||||
SHORTCUT_ID).setLongLabel(
|
||||
SHORTCUT_ID_1).setLongLabel(
|
||||
"name")
|
||||
.build();
|
||||
private final Notification mNotification1 = new Notification.Builder(mContext, "test")
|
||||
.setContentTitle("TEST_TITLE")
|
||||
.setContentText("TEST_TEXT")
|
||||
.setShortcutId(SHORTCUT_ID_1)
|
||||
.setStyle(new Notification.MessagingStyle(PERSON)
|
||||
.addMessage(new Notification.MessagingStyle.Message(
|
||||
NOTIFICATION_TEXT_1, 0, PERSON))
|
||||
.addMessage(new Notification.MessagingStyle.Message(
|
||||
NOTIFICATION_TEXT_2, 20, PERSON))
|
||||
.addMessage(new Notification.MessagingStyle.Message(
|
||||
NOTIFICATION_TEXT_3, 10, PERSON))
|
||||
)
|
||||
.build();
|
||||
private final Notification mNotification2 = new Notification.Builder(mContext, "test2")
|
||||
.setContentTitle("TEST_TITLE")
|
||||
.setContentText("OTHER_TEXT")
|
||||
.setShortcutId(SHORTCUT_ID_2)
|
||||
.setStyle(new Notification.MessagingStyle(PERSON)
|
||||
.addMessage(new Notification.MessagingStyle.Message(
|
||||
NOTIFICATION_TEXT_4, 0, PERSON))
|
||||
)
|
||||
.build();
|
||||
private final Notification mNotification3 = new Notification.Builder(mContext, "test2")
|
||||
.setContentTitle("TEST_TITLE")
|
||||
.setContentText("OTHER_TEXT")
|
||||
.setShortcutId(SHORTCUT_ID_3)
|
||||
.setStyle(new Notification.MessagingStyle(PERSON))
|
||||
.build();
|
||||
private final NotificationEntry mNotificationEntry1 = new NotificationEntryBuilder()
|
||||
.setNotification(mNotification1)
|
||||
.setShortcutInfo(new ShortcutInfo.Builder(mContext, SHORTCUT_ID_1).build())
|
||||
.setUser(UserHandle.of(0))
|
||||
.setPkg(PACKAGE_NAME)
|
||||
.build();
|
||||
private final NotificationEntry mNotificationEntry2 = new NotificationEntryBuilder()
|
||||
.setNotification(mNotification2)
|
||||
.setShortcutInfo(new ShortcutInfo.Builder(mContext, SHORTCUT_ID_2).build())
|
||||
.setUser(UserHandle.of(0))
|
||||
.setPkg(PACKAGE_NAME)
|
||||
.build();
|
||||
private final NotificationEntry mNotificationEntry3 = new NotificationEntryBuilder()
|
||||
.setNotification(mNotification3)
|
||||
.setShortcutInfo(new ShortcutInfo.Builder(mContext, SHORTCUT_ID_3).build())
|
||||
.setUser(UserHandle.of(0))
|
||||
.setPkg(PACKAGE_NAME)
|
||||
.build();
|
||||
|
||||
@Mock
|
||||
private NotificationListener mListenerService;
|
||||
@@ -130,6 +188,8 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
private ContentResolver mMockContentResolver;
|
||||
@Mock
|
||||
private Context mMockContext;
|
||||
@Mock
|
||||
private NotificationEntryManager mNotificationEntryManager;
|
||||
|
||||
@Before
|
||||
public void setUp() throws RemoteException {
|
||||
@@ -152,15 +212,17 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
isNull())).thenReturn(mMockCursor);
|
||||
when(mMockContext.getString(R.string.birthday_status)).thenReturn(
|
||||
mContext.getString(R.string.birthday_status));
|
||||
when(mNotificationEntryManager.getVisibleNotifications())
|
||||
.thenReturn(List.of(mNotificationEntry1, mNotificationEntry2, mNotificationEntry3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTilesReturnsSortedListWithMultipleRecentConversations() throws Exception {
|
||||
// Ensure the less-recent Important conversation is before more recent conversations.
|
||||
ConversationChannelWrapper newerNonImportantConversation = getConversationChannelWrapper(
|
||||
SHORTCUT_ID, false, 3);
|
||||
SHORTCUT_ID_1, false, 3);
|
||||
ConversationChannelWrapper olderImportantConversation = getConversationChannelWrapper(
|
||||
SHORTCUT_ID + 1,
|
||||
SHORTCUT_ID_1 + 1,
|
||||
true, 1);
|
||||
when(mNotificationManager.getConversations(anyBoolean())).thenReturn(
|
||||
new ParceledListSlice(Arrays.asList(
|
||||
@@ -169,9 +231,9 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
// Ensure the non-Important conversation is sorted between these recent conversations.
|
||||
ConversationChannel recentConversationBeforeNonImportantConversation =
|
||||
getConversationChannel(
|
||||
SHORTCUT_ID + 2, 4);
|
||||
SHORTCUT_ID_1 + 2, 4);
|
||||
ConversationChannel recentConversationAfterNonImportantConversation =
|
||||
getConversationChannel(SHORTCUT_ID + 3,
|
||||
getConversationChannel(SHORTCUT_ID_1 + 3,
|
||||
2);
|
||||
when(mPeopleManager.getRecentConversations()).thenReturn(
|
||||
new ParceledListSlice(Arrays.asList(recentConversationAfterNonImportantConversation,
|
||||
@@ -179,7 +241,8 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
|
||||
List<String> orderedShortcutIds = PeopleSpaceUtils.getTiles(
|
||||
mContext, mNotificationManager, mPeopleManager,
|
||||
mLauncherApps).stream().map(tile -> tile.getId()).collect(Collectors.toList());
|
||||
mLauncherApps, mNotificationEntryManager)
|
||||
.stream().map(tile -> tile.getId()).collect(Collectors.toList());
|
||||
|
||||
assertThat(orderedShortcutIds).containsExactly(
|
||||
// Even though the oldest conversation, should be first since "important"
|
||||
@@ -196,11 +259,11 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
throws Exception {
|
||||
// Ensure the less-recent Important conversation is before more recent conversations.
|
||||
ConversationChannelWrapper newerNonImportantConversation = getConversationChannelWrapper(
|
||||
SHORTCUT_ID, false, 3);
|
||||
SHORTCUT_ID_1, false, 3);
|
||||
ConversationChannelWrapper newerImportantConversation = getConversationChannelWrapper(
|
||||
SHORTCUT_ID + 1, true, 3);
|
||||
SHORTCUT_ID_1 + 1, true, 3);
|
||||
ConversationChannelWrapper olderImportantConversation = getConversationChannelWrapper(
|
||||
SHORTCUT_ID + 2,
|
||||
SHORTCUT_ID_1 + 2,
|
||||
true, 1);
|
||||
when(mNotificationManager.getConversations(anyBoolean())).thenReturn(
|
||||
new ParceledListSlice(Arrays.asList(
|
||||
@@ -210,9 +273,9 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
// Ensure the non-Important conversation is sorted between these recent conversations.
|
||||
ConversationChannel recentConversationBeforeNonImportantConversation =
|
||||
getConversationChannel(
|
||||
SHORTCUT_ID + 3, 4);
|
||||
SHORTCUT_ID_1 + 3, 4);
|
||||
ConversationChannel recentConversationAfterNonImportantConversation =
|
||||
getConversationChannel(SHORTCUT_ID + 4,
|
||||
getConversationChannel(SHORTCUT_ID_1 + 4,
|
||||
2);
|
||||
when(mPeopleManager.getRecentConversations()).thenReturn(
|
||||
new ParceledListSlice(Arrays.asList(recentConversationAfterNonImportantConversation,
|
||||
@@ -220,7 +283,8 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
|
||||
List<String> orderedShortcutIds = PeopleSpaceUtils.getTiles(
|
||||
mContext, mNotificationManager, mPeopleManager,
|
||||
mLauncherApps).stream().map(tile -> tile.getId()).collect(Collectors.toList());
|
||||
mLauncherApps, mNotificationEntryManager)
|
||||
.stream().map(tile -> tile.getId()).collect(Collectors.toList());
|
||||
|
||||
assertThat(orderedShortcutIds).containsExactly(
|
||||
// Important conversations should be sorted at the beginning.
|
||||
@@ -238,7 +302,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
Notification notification = new Notification.Builder(mContext, "test")
|
||||
.setContentTitle("TEST_TITLE")
|
||||
.setContentText("TEST_TEXT")
|
||||
.setShortcutId(SHORTCUT_ID)
|
||||
.setShortcutId(SHORTCUT_ID_1)
|
||||
.build();
|
||||
StatusBarNotification sbn = new SbnBuilder()
|
||||
.setNotification(notification)
|
||||
@@ -341,24 +405,126 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetLastMessagingStyleMessage() {
|
||||
Notification notification = new Notification.Builder(mContext, "test")
|
||||
.setContentTitle("TEST_TITLE")
|
||||
.setContentText("TEST_TEXT")
|
||||
.setShortcutId(SHORTCUT_ID)
|
||||
.setStyle(new Notification.MessagingStyle(PERSON)
|
||||
.addMessage(new Notification.MessagingStyle.Message("text1", 0, PERSON))
|
||||
.addMessage(new Notification.MessagingStyle.Message("text2", 20, PERSON))
|
||||
.addMessage(new Notification.MessagingStyle.Message("text3", 10, PERSON))
|
||||
)
|
||||
.build();
|
||||
StatusBarNotification sbn = new SbnBuilder()
|
||||
.setNotification(notification)
|
||||
.setNotification(mNotification1)
|
||||
.build();
|
||||
|
||||
Notification.MessagingStyle.Message lastMessage =
|
||||
PeopleSpaceUtils.getLastMessagingStyleMessage(sbn);
|
||||
|
||||
assertThat(lastMessage.getText()).isEqualTo("text2");
|
||||
assertThat(lastMessage.getText().toString()).isEqualTo(NOTIFICATION_TEXT_2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAugmentTileFromNotification() {
|
||||
StatusBarNotification sbn = new SbnBuilder()
|
||||
.setNotification(mNotification1)
|
||||
.build();
|
||||
|
||||
PeopleSpaceTile tile =
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_1, "userName", ICON, new Intent())
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUid(0)
|
||||
.build();
|
||||
PeopleSpaceTile actual = PeopleSpaceUtils
|
||||
.augmentTileFromNotification(tile, sbn);
|
||||
|
||||
assertThat(actual.getNotificationContent().toString()).isEqualTo(NOTIFICATION_TEXT_2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAugmentTileFromNotificationNoContent() {
|
||||
StatusBarNotification sbn = new SbnBuilder()
|
||||
.setNotification(mNotification3)
|
||||
.build();
|
||||
|
||||
PeopleSpaceTile tile =
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_3, "userName", ICON, new Intent())
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUid(0)
|
||||
.build();
|
||||
PeopleSpaceTile actual = PeopleSpaceUtils
|
||||
.augmentTileFromNotification(tile, sbn);
|
||||
|
||||
assertThat(actual.getNotificationKey()).isEqualTo(null);
|
||||
assertThat(actual.getNotificationContent()).isEqualTo(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAugmentTileFromVisibleNotifications() {
|
||||
PeopleSpaceTile tile =
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_1, "userName", ICON, new Intent())
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUid(0)
|
||||
.build();
|
||||
PeopleSpaceTile actual = PeopleSpaceUtils
|
||||
.augmentTileFromVisibleNotifications(tile,
|
||||
Map.of(PeopleSpaceUtils.getKey(mNotificationEntry1), mNotificationEntry1));
|
||||
|
||||
assertThat(actual.getNotificationContent().toString()).isEqualTo(NOTIFICATION_TEXT_2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAugmentTileFromVisibleNotificationsDifferentShortcutId() {
|
||||
PeopleSpaceTile tile =
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_4, "userName", ICON, new Intent())
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUid(0)
|
||||
.build();
|
||||
PeopleSpaceTile actual = PeopleSpaceUtils
|
||||
.augmentTileFromVisibleNotifications(tile,
|
||||
Map.of(PeopleSpaceUtils.getKey(mNotificationEntry1), mNotificationEntry1));
|
||||
|
||||
assertThat(actual.getNotificationContent()).isEqualTo(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAugmentTilesFromVisibleNotificationsSingleTile() {
|
||||
PeopleSpaceTile tile =
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_1, "userName", ICON, new Intent())
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUid(0)
|
||||
.build();
|
||||
List<PeopleSpaceTile> actualList = PeopleSpaceUtils
|
||||
.augmentTilesFromVisibleNotifications(List.of(tile), mNotificationEntryManager);
|
||||
|
||||
assertThat(actualList.size()).isEqualTo(1);
|
||||
assertThat(actualList.get(0).getNotificationContent().toString())
|
||||
.isEqualTo(NOTIFICATION_TEXT_2);
|
||||
|
||||
verify(mNotificationEntryManager, times(1)).getVisibleNotifications();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAugmentTilesFromVisibleNotificationsMultipleTiles() {
|
||||
PeopleSpaceTile tile1 =
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_1, "userName", ICON, new Intent())
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUid(1)
|
||||
.build();
|
||||
PeopleSpaceTile tile2 =
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_2, "userName2", ICON, new Intent())
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUid(0)
|
||||
.build();
|
||||
List<PeopleSpaceTile> actualList = PeopleSpaceUtils
|
||||
.augmentTilesFromVisibleNotifications(List.of(tile1, tile2),
|
||||
mNotificationEntryManager);
|
||||
|
||||
assertThat(actualList.size()).isEqualTo(2);
|
||||
assertThat(actualList.get(0).getNotificationContent().toString())
|
||||
.isEqualTo(NOTIFICATION_TEXT_2);
|
||||
assertThat(actualList.get(1).getNotificationContent().toString())
|
||||
.isEqualTo(NOTIFICATION_TEXT_4);
|
||||
|
||||
verify(mNotificationEntryManager, times(1)).getVisibleNotifications();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -421,6 +421,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
|
||||
throws Exception {
|
||||
int[] widgetIdsArray = {WIDGET_ID_WITH_SHORTCUT, WIDGET_ID_WITHOUT_SHORTCUT};
|
||||
when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray);
|
||||
setStorageForTile(SHORTCUT_ID, TEST_PACKAGE_A, WIDGET_ID_WITH_SHORTCUT);
|
||||
|
||||
Notification notificationWithoutMessagingStyle = new Notification.Builder(mContext)
|
||||
.setContentTitle("TEST_TITLE")
|
||||
@@ -429,15 +430,21 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
|
||||
.build();
|
||||
StatusBarNotification sbn = new SbnBuilder()
|
||||
.setNotification(notificationWithoutMessagingStyle)
|
||||
.setPkg(TEST_PACKAGE_A)
|
||||
.setUid(0)
|
||||
.build();
|
||||
NotifEvent notif1 = mNoMan.postNotif(new NotificationEntryBuilder()
|
||||
.setSbn(sbn)
|
||||
.setId(1));
|
||||
mClock.advanceTime(MIN_LINGER_DURATION);
|
||||
|
||||
verify(mAppWidgetManager, never())
|
||||
.updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), any());
|
||||
verify(mAppWidgetManager, never()).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT),
|
||||
verify(mAppWidgetManager, times(1))
|
||||
.updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT),
|
||||
mBundleArgumentCaptor.capture());
|
||||
Bundle options = requireNonNull(mBundleArgumentCaptor.getValue());
|
||||
assertThat((PeopleSpaceTile) options.getParcelable(OPTIONS_PEOPLE_SPACE_TILE))
|
||||
.isEqualTo(PERSON_TILE);
|
||||
verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT),
|
||||
any());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user