Merge "Ensure that the shortcuts added to conversations are longlived" into rvc-dev am: 7cb34c5066
Change-Id: Ibcf0fe8fc31522e7943e90efa17936d213da58a7
This commit is contained in:
@@ -185,7 +185,7 @@ public class BubbleExtractor implements NotificationSignalExtractor {
|
|||||||
|
|
||||||
String shortcutId = metadata.getShortcutId();
|
String shortcutId = metadata.getShortcutId();
|
||||||
boolean shortcutValid = shortcutId != null
|
boolean shortcutValid = shortcutId != null
|
||||||
&& mShortcutHelper.hasValidShortcutInfo(shortcutId, pkg, r.getUser());
|
&& mShortcutHelper.getValidShortcutInfo(shortcutId, pkg, r.getUser()) != null;
|
||||||
if (metadata.getIntent() == null && !shortcutValid) {
|
if (metadata.getIntent() == null && !shortcutValid) {
|
||||||
// Should have a shortcut if intent is null
|
// Should have a shortcut if intent is null
|
||||||
logBubbleError(r.getKey(),
|
logBubbleError(r.getKey(),
|
||||||
|
|||||||
@@ -3453,7 +3453,7 @@ public class NotificationManagerService extends SystemService {
|
|||||||
ArrayList<ConversationChannelWrapper> conversations =
|
ArrayList<ConversationChannelWrapper> conversations =
|
||||||
mPreferencesHelper.getConversations(onlyImportant);
|
mPreferencesHelper.getConversations(onlyImportant);
|
||||||
for (ConversationChannelWrapper conversation : conversations) {
|
for (ConversationChannelWrapper conversation : conversations) {
|
||||||
conversation.setShortcutInfo(mShortcutHelper.getShortcutInfo(
|
conversation.setShortcutInfo(mShortcutHelper.getValidShortcutInfo(
|
||||||
conversation.getNotificationChannel().getConversationId(),
|
conversation.getNotificationChannel().getConversationId(),
|
||||||
conversation.getPkg(),
|
conversation.getPkg(),
|
||||||
UserHandle.of(UserHandle.getUserId(conversation.getUid()))));
|
UserHandle.of(UserHandle.getUserId(conversation.getUid()))));
|
||||||
@@ -3476,7 +3476,7 @@ public class NotificationManagerService extends SystemService {
|
|||||||
ArrayList<ConversationChannelWrapper> conversations =
|
ArrayList<ConversationChannelWrapper> conversations =
|
||||||
mPreferencesHelper.getConversations(pkg, uid);
|
mPreferencesHelper.getConversations(pkg, uid);
|
||||||
for (ConversationChannelWrapper conversation : conversations) {
|
for (ConversationChannelWrapper conversation : conversations) {
|
||||||
conversation.setShortcutInfo(mShortcutHelper.getShortcutInfo(
|
conversation.setShortcutInfo(mShortcutHelper.getValidShortcutInfo(
|
||||||
conversation.getNotificationChannel().getConversationId(),
|
conversation.getNotificationChannel().getConversationId(),
|
||||||
pkg,
|
pkg,
|
||||||
UserHandle.of(UserHandle.getUserId(uid))));
|
UserHandle.of(UserHandle.getUserId(uid))));
|
||||||
@@ -5647,7 +5647,8 @@ public class NotificationManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r.setShortcutInfo(mShortcutHelper.getShortcutInfo(notification.getShortcutId(), pkg, user));
|
r.setShortcutInfo(mShortcutHelper.getValidShortcutInfo(
|
||||||
|
notification.getShortcutId(), pkg, user));
|
||||||
|
|
||||||
if (!checkDisqualifyingFeatures(userId, notificationUid, id, tag, r,
|
if (!checkDisqualifyingFeatures(userId, notificationUid, id, tag, r,
|
||||||
r.getSbn().getOverrideGroupKey() != null)) {
|
r.getSbn().getOverrideGroupKey() != null)) {
|
||||||
|
|||||||
@@ -121,7 +121,10 @@ class ShortcutHelper {
|
|||||||
mLauncherAppsService = launcherApps;
|
mLauncherAppsService = launcherApps;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShortcutInfo getShortcutInfo(String shortcutId, String packageName, UserHandle user) {
|
/**
|
||||||
|
* Only returns shortcut info if it's found and if it's {@link ShortcutInfo#isLongLived()}.
|
||||||
|
*/
|
||||||
|
ShortcutInfo getValidShortcutInfo(String shortcutId, String packageName, UserHandle user) {
|
||||||
if (mLauncherAppsService == null) {
|
if (mLauncherAppsService == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -135,20 +138,15 @@ class ShortcutHelper {
|
|||||||
query.setShortcutIds(Arrays.asList(shortcutId));
|
query.setShortcutIds(Arrays.asList(shortcutId));
|
||||||
query.setQueryFlags(FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_CACHED);
|
query.setQueryFlags(FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_CACHED);
|
||||||
List<ShortcutInfo> shortcuts = mLauncherAppsService.getShortcuts(query, user);
|
List<ShortcutInfo> shortcuts = mLauncherAppsService.getShortcuts(query, user);
|
||||||
return shortcuts != null && shortcuts.size() > 0
|
ShortcutInfo info = shortcuts != null && shortcuts.size() > 0
|
||||||
? shortcuts.get(0)
|
? shortcuts.get(0)
|
||||||
: null;
|
: null;
|
||||||
|
return info != null && info.isLongLived() ? info : null;
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(token);
|
Binder.restoreCallingIdentity(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasValidShortcutInfo(String shortcutId, String packageName,
|
|
||||||
UserHandle user) {
|
|
||||||
ShortcutInfo shortcutInfo = getShortcutInfo(shortcutId, packageName, user);
|
|
||||||
return shortcutInfo != null && shortcutInfo.isLongLived();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shortcut based bubbles require some extra work to listen for shortcut changes.
|
* Shortcut based bubbles require some extra work to listen for shortcut changes.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
@@ -33,6 +34,7 @@ import android.app.NotificationChannel;
|
|||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.content.pm.ShortcutInfo;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.service.notification.StatusBarNotification;
|
import android.service.notification.StatusBarNotification;
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
@@ -110,8 +112,10 @@ public class BubbleCheckerTest extends UiServiceTestCase {
|
|||||||
|
|
||||||
void setUpShortcutBubble(boolean isValid) {
|
void setUpShortcutBubble(boolean isValid) {
|
||||||
when(mBubbleMetadata.getShortcutId()).thenReturn(SHORTCUT_ID);
|
when(mBubbleMetadata.getShortcutId()).thenReturn(SHORTCUT_ID);
|
||||||
when(mShortcutHelper.hasValidShortcutInfo(SHORTCUT_ID, PKG, mUserHandle))
|
ShortcutInfo info = mock(ShortcutInfo.class);
|
||||||
.thenReturn(isValid);
|
when(info.getId()).thenReturn(SHORTCUT_ID);
|
||||||
|
when(mShortcutHelper.getValidShortcutInfo(SHORTCUT_ID, PKG, mUserHandle))
|
||||||
|
.thenReturn(isValid ? info : null);
|
||||||
when(mBubbleMetadata.getIntent()).thenReturn(null);
|
when(mBubbleMetadata.getIntent()).thenReturn(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6372,13 +6372,41 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
|||||||
|
|
||||||
ShortcutInfo si = mock(ShortcutInfo.class);
|
ShortcutInfo si = mock(ShortcutInfo.class);
|
||||||
when(si.getShortLabel()).thenReturn("Hello");
|
when(si.getShortLabel()).thenReturn("Hello");
|
||||||
|
when(si.isLongLived()).thenReturn(true);
|
||||||
when(mLauncherApps.getShortcuts(any(), any())).thenReturn(Arrays.asList(si));
|
when(mLauncherApps.getShortcuts(any(), any())).thenReturn(Arrays.asList(si));
|
||||||
|
|
||||||
List<ConversationChannelWrapper> conversations =
|
List<ConversationChannelWrapper> conversations =
|
||||||
mBinderService.getConversationsForPackage(PKG_P, mUid).getList();
|
mBinderService.getConversationsForPackage(PKG_P, mUid).getList();
|
||||||
assertEquals(si, conversations.get(0).getShortcutInfo());
|
assertEquals(si, conversations.get(0).getShortcutInfo());
|
||||||
assertEquals(si, conversations.get(1).getShortcutInfo());
|
assertEquals(si, conversations.get(1).getShortcutInfo());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetConversationsForPackage_shortcut_notLongLived() throws Exception {
|
||||||
|
mService.setPreferencesHelper(mPreferencesHelper);
|
||||||
|
ArrayList<ConversationChannelWrapper> convos = new ArrayList<>();
|
||||||
|
ConversationChannelWrapper convo1 = new ConversationChannelWrapper();
|
||||||
|
NotificationChannel channel1 = new NotificationChannel("a", "a", 1);
|
||||||
|
channel1.setConversationId("parent1", "convo 1");
|
||||||
|
convo1.setNotificationChannel(channel1);
|
||||||
|
convos.add(convo1);
|
||||||
|
|
||||||
|
ConversationChannelWrapper convo2 = new ConversationChannelWrapper();
|
||||||
|
NotificationChannel channel2 = new NotificationChannel("b", "b", 1);
|
||||||
|
channel2.setConversationId("parent1", "convo 2");
|
||||||
|
convo2.setNotificationChannel(channel2);
|
||||||
|
convos.add(convo2);
|
||||||
|
when(mPreferencesHelper.getConversations(anyString(), anyInt())).thenReturn(convos);
|
||||||
|
|
||||||
|
ShortcutInfo si = mock(ShortcutInfo.class);
|
||||||
|
when(si.getShortLabel()).thenReturn("Hello");
|
||||||
|
when(si.isLongLived()).thenReturn(false);
|
||||||
|
when(mLauncherApps.getShortcuts(any(), any())).thenReturn(Arrays.asList(si));
|
||||||
|
|
||||||
|
List<ConversationChannelWrapper> conversations =
|
||||||
|
mBinderService.getConversationsForPackage(PKG_P, mUid).getList();
|
||||||
|
assertNull(conversations.get(0).getShortcutInfo());
|
||||||
|
assertNull(conversations.get(1).getShortcutInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user