summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Flavio Fiszman <flaviocf@google.com> 2020-12-03 18:47:29 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-12-03 18:47:29 +0000
commit95db66d97e6a5a070211bddbcf90f027ad698b1f (patch)
tree67ad09e948a45766553e091ffb04c2bb10972afe
parenta74fdf285d66cd07bbb0775fb4044254c1258350 (diff)
parent3d40eeb9a33bd49865d923c770dac5e0e5eff0da (diff)
Merge "Populate Persons data in ShortcutInfo."
-rw-r--r--services/core/java/com/android/server/notification/ShortcutHelper.java5
-rw-r--r--services/people/java/com/android/server/people/data/DataManager.java2
-rw-r--r--services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java35
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/ShortcutHelperTest.java27
4 files changed, 66 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/notification/ShortcutHelper.java b/services/core/java/com/android/server/notification/ShortcutHelper.java
index 9c3d6d352c89..b0be20698005 100644
--- a/services/core/java/com/android/server/notification/ShortcutHelper.java
+++ b/services/core/java/com/android/server/notification/ShortcutHelper.java
@@ -16,6 +16,7 @@
package com.android.server.notification;
+import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_GET_PERSONS_DATA;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_CACHED;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED_BY_ANY_LAUNCHER;
@@ -192,8 +193,8 @@ public class ShortcutHelper {
LauncherApps.ShortcutQuery query = new LauncherApps.ShortcutQuery();
query.setPackage(packageName);
query.setShortcutIds(Arrays.asList(shortcutId));
- query.setQueryFlags(
- FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED_BY_ANY_LAUNCHER | FLAG_MATCH_CACHED);
+ query.setQueryFlags(FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED_BY_ANY_LAUNCHER
+ | FLAG_MATCH_CACHED | FLAG_GET_PERSONS_DATA);
List<ShortcutInfo> shortcuts = mLauncherAppsService.getShortcuts(query, user);
ShortcutInfo info = shortcuts != null && shortcuts.size() > 0
? shortcuts.get(0)
diff --git a/services/people/java/com/android/server/people/data/DataManager.java b/services/people/java/com/android/server/people/data/DataManager.java
index 3e06194f8bee..b5e595a42ca9 100644
--- a/services/people/java/com/android/server/people/data/DataManager.java
+++ b/services/people/java/com/android/server/people/data/DataManager.java
@@ -554,7 +554,7 @@ public class DataManager {
@Nullable List<String> shortcutIds) {
@ShortcutQuery.QueryFlags int queryFlags = ShortcutQuery.FLAG_MATCH_DYNAMIC
| ShortcutQuery.FLAG_MATCH_PINNED | ShortcutQuery.FLAG_MATCH_PINNED_BY_ANY_LAUNCHER
- | ShortcutQuery.FLAG_MATCH_CACHED;
+ | ShortcutQuery.FLAG_MATCH_CACHED | ShortcutQuery.FLAG_GET_PERSONS_DATA;
return mShortcutServiceInternal.getShortcuts(
UserHandle.USER_SYSTEM, mContext.getPackageName(),
/*changedSince=*/ 0, packageName, shortcutIds, /*locusIds=*/ null,
diff --git a/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java b/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java
index f823bb957a33..2471210f6325 100644
--- a/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java
@@ -22,6 +22,8 @@ import static android.service.notification.NotificationListenerService.NOTIFICAT
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -58,6 +60,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.LauncherApps.ShortcutChangeCallback;
+import android.content.pm.LauncherApps.ShortcutQuery;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ShortcutInfo;
@@ -136,6 +139,7 @@ public final class DataManagerTest {
@Captor private ArgumentCaptor<ShortcutChangeCallback> mShortcutChangeCallbackCaptor;
@Captor private ArgumentCaptor<BroadcastReceiver> mBroadcastReceiverCaptor;
+ @Captor private ArgumentCaptor<Integer> mQueryFlagsCaptor;
private ScheduledExecutorService mExecutorService;
private NotificationChannel mNotificationChannel;
@@ -854,6 +858,8 @@ public final class DataManagerTest {
List<ConversationChannel> result = mDataManager.getRecentConversations(USER_ID_PRIMARY);
assertEquals(1, result.size());
assertEquals(shortcut.getId(), result.get(0).getShortcutInfo().getId());
+ assertEquals(1, result.get(0).getShortcutInfo().getPersons().length);
+ assertEquals(CONTACT_URI, result.get(0).getShortcutInfo().getPersons()[0].getUri());
assertEquals(mParentNotificationChannel.getId(),
result.get(0).getParentNotificationChannel().getId());
assertEquals(mStatusBarNotification.getPostTime(), result.get(0).getLastEventTimestamp());
@@ -861,6 +867,28 @@ public final class DataManagerTest {
}
@Test
+ public void testGetRecentConversationsGetsPersonsData() {
+ mDataManager.onUserUnlocked(USER_ID_PRIMARY);
+
+ ShortcutInfo shortcut = buildShortcutInfo(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID,
+ buildPerson());
+ shortcut.setCached(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS);
+ mDataManager.addOrUpdateConversationInfo(shortcut);
+
+ NotificationListenerService listenerService =
+ mDataManager.getNotificationListenerServiceForTesting(USER_ID_PRIMARY);
+ listenerService.onNotificationPosted(mStatusBarNotification);
+
+ List<ConversationChannel> result = mDataManager.getRecentConversations(USER_ID_PRIMARY);
+
+ verify(mShortcutServiceInternal).getShortcuts(
+ anyInt(), anyString(), anyLong(), anyString(), anyList(), any(), any(),
+ mQueryFlagsCaptor.capture(), anyInt(), anyInt(), anyInt());
+ Integer queryFlags = mQueryFlagsCaptor.getValue();
+ assertThat(hasFlag(queryFlags, ShortcutQuery.FLAG_GET_PERSONS_DATA)).isTrue();
+ }
+
+ @Test
public void testPruneOldRecentConversations() {
mDataManager.onUserUnlocked(USER_ID_PRIMARY);
@@ -1068,6 +1096,13 @@ public final class DataManagerTest {
return new UserInfo(userId, "", 0);
}
+ /**
+ * Returns {@code true} iff {@link ShortcutQuery}'s {@code queryFlags} has {@code flag} set.
+ */
+ private static boolean hasFlag(int queryFlags, int flag) {
+ return (queryFlags & flag) != 0;
+ }
+
private class TestContactsQueryHelper extends ContactsQueryHelper {
private Uri mContactUri;
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ShortcutHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ShortcutHelperTest.java
index e5ae2d3f63ab..f43e5a83c95d 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/ShortcutHelperTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/ShortcutHelperTest.java
@@ -27,8 +27,11 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Notification;
+import android.app.Person;
import android.content.pm.LauncherApps;
+import android.content.pm.LauncherApps.ShortcutQuery;
import android.content.pm.ShortcutInfo;
+import android.content.pm.ShortcutQueryWrapper;
import android.content.pm.ShortcutServiceInternal;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
@@ -44,6 +47,7 @@ import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
@@ -60,6 +64,7 @@ public class ShortcutHelperTest extends UiServiceTestCase {
private static final String SHORTCUT_ID = "shortcut";
private static final String PKG = "pkg";
private static final String KEY = "key";
+ private static final Person PERSON = mock(Person.class);
@Mock
LauncherApps mLauncherApps;
@@ -78,6 +83,8 @@ public class ShortcutHelperTest extends UiServiceTestCase {
@Mock
ShortcutInfo mShortcutInfo;
+ @Captor private ArgumentCaptor<ShortcutQuery> mShortcutQueryCaptor;
+
ShortcutHelper mShortcutHelper;
@Before
@@ -298,6 +305,7 @@ public class ShortcutHelperTest extends UiServiceTestCase {
when(si.getUserId()).thenReturn(UserHandle.USER_SYSTEM);
when(si.isLongLived()).thenReturn(true);
when(si.isEnabled()).thenReturn(true);
+ when(si.getPersons()).thenReturn(new Person[]{PERSON});
ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
shortcuts.add(si);
when(mLauncherApps.getShortcuts(any(), any())).thenReturn(shortcuts);
@@ -308,4 +316,23 @@ public class ShortcutHelperTest extends UiServiceTestCase {
assertThat(mShortcutHelper.getValidShortcutInfo("a", "p", UserHandle.SYSTEM))
.isSameInstanceAs(si);
}
+
+ @Test
+ public void testGetValidShortcutInfo_hasGetPersonsDataFlag() {
+
+ ShortcutInfo info = mShortcutHelper.getValidShortcutInfo(
+ "a", "p", UserHandle.SYSTEM);
+ verify(mLauncherApps).getShortcuts(mShortcutQueryCaptor.capture(), any());
+ ShortcutQueryWrapper shortcutQuery =
+ new ShortcutQueryWrapper(mShortcutQueryCaptor.getValue());
+ assertThat(hasFlag(shortcutQuery.getQueryFlags(), ShortcutQuery.FLAG_GET_PERSONS_DATA))
+ .isTrue();
+ }
+
+ /**
+ * Returns {@code true} iff {@link ShortcutQuery}'s {@code queryFlags} has {@code flag} set.
+ */
+ private static boolean hasFlag(int queryFlags, int flag) {
+ return (queryFlags & flag) != 0;
+ }
}