diff options
4 files changed, 24 insertions, 2 deletions
diff --git a/services/people/java/com/android/server/people/data/ConversationInfo.java b/services/people/java/com/android/server/people/data/ConversationInfo.java index ce353667b62d..859cdf24bc7e 100644 --- a/services/people/java/com/android/server/people/data/ConversationInfo.java +++ b/services/people/java/com/android/server/people/data/ConversationInfo.java @@ -137,6 +137,11 @@ public class ConversationInfo { return hasShortcutFlags(ShortcutInfo.FLAG_LONG_LIVED); } + /** Whether the shortcut for this conversation is cached in Shortcut Service. */ + public boolean isShortcutCached() { + return hasShortcutFlags(ShortcutInfo.FLAG_CACHED); + } + /** Whether this conversation is marked as important by the user. */ public boolean isImportant() { return hasConversationFlags(FLAG_IMPORTANT); @@ -213,6 +218,9 @@ public class ConversationInfo { if (isShortcutLongLived()) { sb.append("Liv"); } + if (isShortcutCached()) { + sb.append("Cac"); + } sb.append("]"); sb.append(", conversationFlags=0x").append(Integer.toHexString(mConversationFlags)); sb.append(" ["); 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 39a26662da4b..dd9cbd00f6a2 100644 --- a/services/people/java/com/android/server/people/data/DataManager.java +++ b/services/people/java/com/android/server/people/data/DataManager.java @@ -696,7 +696,15 @@ public class DataManager { break; } conversationStore.addOrUpdate(builder.build()); - // TODO: Cache the shortcut when a conversation's notification setting is changed. + + if (modificationType == NOTIFICATION_CHANNEL_OR_GROUP_UPDATED + && conversationInfo.isShortcutLongLived() + && !conversationInfo.isShortcutCached()) { + mShortcutServiceInternal.cacheShortcuts(user.getIdentifier(), + mContext.getPackageName(), pkg, + Collections.singletonList(conversationInfo.getShortcutId()), + user.getIdentifier()); + } } } diff --git a/services/tests/servicestests/src/com/android/server/people/data/ConversationInfoTest.java b/services/tests/servicestests/src/com/android/server/people/data/ConversationInfoTest.java index c0e7927a8d72..70d6cf81c3b0 100644 --- a/services/tests/servicestests/src/com/android/server/people/data/ConversationInfoTest.java +++ b/services/tests/servicestests/src/com/android/server/people/data/ConversationInfoTest.java @@ -46,7 +46,7 @@ public final class ConversationInfoTest { .setContactUri(CONTACT_URI) .setContactPhoneNumber(PHONE_NUMBER) .setNotificationChannelId(NOTIFICATION_CHANNEL_ID) - .setShortcutFlags(ShortcutInfo.FLAG_LONG_LIVED) + .setShortcutFlags(ShortcutInfo.FLAG_LONG_LIVED | ShortcutInfo.FLAG_CACHED) .setImportant(true) .setNotificationSilenced(true) .setBubbled(true) @@ -62,6 +62,7 @@ public final class ConversationInfoTest { assertEquals(PHONE_NUMBER, conversationInfo.getContactPhoneNumber()); assertEquals(NOTIFICATION_CHANNEL_ID, conversationInfo.getNotificationChannelId()); assertTrue(conversationInfo.isShortcutLongLived()); + assertTrue(conversationInfo.isShortcutCached()); assertTrue(conversationInfo.isImportant()); assertTrue(conversationInfo.isNotificationSilenced()); assertTrue(conversationInfo.isBubbled()); @@ -83,6 +84,7 @@ public final class ConversationInfoTest { assertNull(conversationInfo.getContactPhoneNumber()); assertNull(conversationInfo.getNotificationChannelId()); assertFalse(conversationInfo.isShortcutLongLived()); + assertFalse(conversationInfo.isShortcutCached()); assertFalse(conversationInfo.isImportant()); assertFalse(conversationInfo.isNotificationSilenced()); assertFalse(conversationInfo.isBubbled()); 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 b6e6f97bcc13..3ecd3193058a 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 @@ -416,6 +416,9 @@ public final class DataManagerTest { assertTrue(conversationInfo.isImportant()); assertFalse(conversationInfo.isNotificationSilenced()); assertFalse(conversationInfo.isDemoted()); + verify(mShortcutServiceInternal).cacheShortcuts( + anyInt(), any(), eq(TEST_PKG_NAME), + eq(Collections.singletonList(TEST_SHORTCUT_ID)), eq(USER_ID_PRIMARY)); } @Test @@ -612,6 +615,7 @@ public final class DataManagerTest { when(mockContext.getUser()).thenReturn(UserHandle.of(userId)); ShortcutInfo.Builder builder = new ShortcutInfo.Builder(mockContext, id) .setShortLabel(id) + .setLongLived(true) .setIntent(new Intent("TestIntent")); if (person != null) { builder.setPersons(new Person[] {person}); |