Merge "Populate Persons data in ShortcutInfo."
This commit is contained in:
committed by
Android (Google) Code Review
commit
95db66d97e
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,12 +858,36 @@ 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());
|
||||
assertTrue(result.get(0).hasActiveNotifications());
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user