diff options
2 files changed, 90 insertions, 23 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/people/widget/LaunchConversationActivity.java b/packages/SystemUI/src/com/android/systemui/people/widget/LaunchConversationActivity.java index 48f6184a96d9..c01a52dd0a8e 100644 --- a/packages/SystemUI/src/com/android/systemui/people/widget/LaunchConversationActivity.java +++ b/packages/SystemUI/src/com/android/systemui/people/widget/LaunchConversationActivity.java @@ -27,6 +27,7 @@ import android.service.notification.NotificationStats; import android.text.TextUtils; import android.util.Log; +import com.android.internal.annotations.VisibleForTesting; import com.android.internal.logging.UiEventLogger; import com.android.internal.logging.UiEventLoggerImpl; import com.android.internal.statusbar.IStatusBarService; @@ -34,6 +35,9 @@ import com.android.internal.statusbar.NotificationVisibility; import com.android.systemui.people.PeopleSpaceUtils; import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.collection.NotificationEntry; +import com.android.systemui.wmshell.BubblesManager; + +import java.util.Optional; import javax.inject.Inject; @@ -43,16 +47,23 @@ public class LaunchConversationActivity extends Activity { private static final boolean DEBUG = PeopleSpaceUtils.DEBUG; private UiEventLogger mUiEventLogger = new UiEventLoggerImpl(); private NotificationEntryManager mNotificationEntryManager; + private final Optional<BubblesManager> mBubblesManagerOptional; + private boolean mIsForTesting; + private IStatusBarService mIStatusBarService; @Inject - public LaunchConversationActivity(NotificationEntryManager notificationEntryManager) { + public LaunchConversationActivity(NotificationEntryManager notificationEntryManager, + Optional<BubblesManager> bubblesManagerOptional) { super(); mNotificationEntryManager = notificationEntryManager; + mBubblesManagerOptional = bubblesManagerOptional; } @Override public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + if (!mIsForTesting) { + super.onCreate(savedInstanceState); + } if (DEBUG) Log.d(TAG, "onCreate called"); Intent intent = getIntent(); @@ -63,21 +74,30 @@ public class LaunchConversationActivity extends Activity { String notificationKey = intent.getStringExtra(PeopleSpaceWidgetProvider.EXTRA_NOTIFICATION_KEY); - if (tileId != null && !tileId.isEmpty()) { + if (!TextUtils.isEmpty(tileId)) { if (DEBUG) { Log.d(TAG, "Launching conversation with shortcutInfo id " + tileId); } mUiEventLogger.log(PeopleSpaceUtils.PeopleSpaceWidgetEvent.PEOPLE_SPACE_WIDGET_CLICKED); try { + NotificationEntry entry = mNotificationEntryManager.getPendingOrActiveNotif( + notificationKey); + if (entry != null && entry.canBubble() && mBubblesManagerOptional.isPresent()) { + if (DEBUG) Log.d(TAG, "Open bubble for conversation"); + mBubblesManagerOptional.get().expandStackAndSelectBubble(entry); + // Just opt-out and don't cancel the notification for bubbles. + return; + } + + if (mIStatusBarService == null) { + mIStatusBarService = IStatusBarService.Stub.asInterface( + ServiceManager.getService(Context.STATUS_BAR_SERVICE)); + } + clearNotificationIfPresent(notificationKey, packageName, userHandle); LauncherApps launcherApps = getApplicationContext().getSystemService(LauncherApps.class); launcherApps.startShortcut( packageName, tileId, null, null, userHandle); - - IStatusBarService statusBarService = IStatusBarService.Stub.asInterface( - ServiceManager.getService(Context.STATUS_BAR_SERVICE)); - clearNotificationIfPresent( - statusBarService, notificationKey, packageName, userHandle); } catch (Exception e) { Log.e(TAG, "Exception:" + e); } @@ -87,15 +107,14 @@ public class LaunchConversationActivity extends Activity { finish(); } - void clearNotificationIfPresent(IStatusBarService statusBarService, - String notifKey, String packageName, UserHandle userHandle) { + void clearNotificationIfPresent(String notifKey, String packageName, UserHandle userHandle) { if (TextUtils.isEmpty(notifKey)) { if (DEBUG) Log.d(TAG, "Skipping clear notification: notification key is empty"); return; } try { - if (statusBarService == null || mNotificationEntryManager == null) { + if (mIStatusBarService == null || mNotificationEntryManager == null) { if (DEBUG) { Log.d(TAG, "Skipping clear notification: null services, key: " + notifKey); } @@ -117,7 +136,7 @@ public class LaunchConversationActivity extends Activity { rank, count, true); if (DEBUG) Log.d(TAG, "Clearing notification, key: " + notifKey + ", rank: " + rank); - statusBarService.onNotificationClear( + mIStatusBarService.onNotificationClear( packageName, userHandle.getIdentifier(), notifKey, NotificationStats.DISMISSAL_OTHER, NotificationStats.DISMISS_SENTIMENT_POSITIVE, notifVisibility); @@ -125,4 +144,10 @@ public class LaunchConversationActivity extends Activity { Log.e(TAG, "Exception cancelling notification:" + e); } } + + @VisibleForTesting + void setIsForTesting(boolean isForTesting, IStatusBarService statusBarService) { + mIsForTesting = isForTesting; + mIStatusBarService = statusBarService; + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/widget/LaunchConversationActivityTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/widget/LaunchConversationActivityTest.java index fce02174a1e0..0ef3ca29bdf6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/people/widget/LaunchConversationActivityTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/people/widget/LaunchConversationActivityTest.java @@ -20,11 +20,14 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import android.content.Intent; +import android.os.Bundle; import android.os.UserHandle; import android.service.notification.NotificationListenerService; import android.testing.AndroidTestingRunner; @@ -37,6 +40,7 @@ import com.android.internal.statusbar.NotificationVisibility; import com.android.systemui.SysuiTestCase; import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.collection.NotificationEntry; +import com.android.systemui.wmshell.BubblesManager; import org.junit.Before; import org.junit.Test; @@ -46,6 +50,8 @@ import org.mockito.Captor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import java.util.Optional; + @SmallTest @RunWith(AndroidTestingRunner.class) @RunWithLooper @@ -55,7 +61,7 @@ public class LaunchConversationActivityTest extends SysuiTestCase { private static final String NOTIF_KEY = "notifKey"; private static final String NOTIF_KEY_NO_ENTRY = "notifKeyNoEntry"; private static final String NOTIF_KEY_NO_RANKING = "notifKeyNoRanking"; - + private static final String NOTIF_KEY_CAN_BUBBLE = "notifKeyCanBubble"; private static final UserHandle USER_HANDLE = UserHandle.of(0); private static final int NOTIF_COUNT = 10; @@ -72,16 +78,27 @@ public class LaunchConversationActivityTest extends SysuiTestCase { @Mock private NotificationEntry mNotifEntryNoRanking; @Mock + private NotificationEntry mNotifEntryCanBubble; + @Mock + private BubblesManager mBubblesManager; + @Mock private NotificationListenerService.Ranking mRanking; @Captor private ArgumentCaptor<NotificationVisibility> mNotificationVisibilityCaptor; + private Intent mIntent; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - mActivity = new LaunchConversationActivity(mNotificationEntryManager); + mActivity = new LaunchConversationActivity(mNotificationEntryManager, + Optional.of(mBubblesManager)); + mActivity.setIsForTesting(true, mIStatusBarService); + mIntent = new Intent(); + mIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_TILE_ID, "tile ID"); + mIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_PACKAGE_NAME, PACKAGE_NAME); + mIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_USER_HANDLE, USER_HANDLE); when(mNotificationEntryManager.getActiveNotificationsCount()).thenReturn(NOTIF_COUNT); when(mNotificationEntryManager.getPendingOrActiveNotif(NOTIF_KEY)).thenReturn(mNotifEntry); @@ -89,15 +106,21 @@ public class LaunchConversationActivityTest extends SysuiTestCase { .thenReturn(null); when(mNotificationEntryManager.getPendingOrActiveNotif(NOTIF_KEY_NO_RANKING)) .thenReturn(mNotifEntryNoRanking); + when(mNotificationEntryManager.getPendingOrActiveNotif(NOTIF_KEY_CAN_BUBBLE)) + .thenReturn(mNotifEntryCanBubble); when(mNotifEntry.getRanking()).thenReturn(mRanking); + when(mNotifEntryCanBubble.getRanking()).thenReturn(mRanking); + when(mNotifEntryCanBubble.canBubble()).thenReturn(true); when(mNotifEntryNoRanking.getRanking()).thenReturn(null); when(mRanking.getRank()).thenReturn(NOTIF_RANK); } @Test public void testDoNotClearNotificationIfNoKey() throws Exception { - mActivity.clearNotificationIfPresent(mIStatusBarService, - EMPTY_STRING, PACKAGE_NAME, USER_HANDLE); + mIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_NOTIFICATION_KEY, + EMPTY_STRING); + mActivity.setIntent(mIntent); + mActivity.onCreate(new Bundle()); verify(mIStatusBarService, never()).onNotificationClear( any(), anyInt(), any(), anyInt(), anyInt(), any()); @@ -105,8 +128,10 @@ public class LaunchConversationActivityTest extends SysuiTestCase { @Test public void testDoNotClearNotificationIfNoNotificationEntry() throws Exception { - mActivity.clearNotificationIfPresent(mIStatusBarService, - NOTIF_KEY_NO_ENTRY, PACKAGE_NAME, USER_HANDLE); + mIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_NOTIFICATION_KEY, + NOTIF_KEY_NO_ENTRY); + mActivity.setIntent(mIntent); + mActivity.onCreate(new Bundle()); verify(mIStatusBarService, never()).onNotificationClear( any(), anyInt(), any(), anyInt(), anyInt(), any()); @@ -114,24 +139,41 @@ public class LaunchConversationActivityTest extends SysuiTestCase { @Test public void testDoNotClearNotificationIfNoRanking() throws Exception { - mActivity.clearNotificationIfPresent(mIStatusBarService, - NOTIF_KEY_NO_RANKING, PACKAGE_NAME, USER_HANDLE); + mIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_NOTIFICATION_KEY, + NOTIF_KEY_NO_RANKING); + mActivity.setIntent(mIntent); + mActivity.onCreate(new Bundle()); verify(mIStatusBarService, never()).onNotificationClear( any(), anyInt(), any(), anyInt(), anyInt(), any()); } @Test - public void testClearNotification() throws Exception { - mActivity.clearNotificationIfPresent(mIStatusBarService, - NOTIF_KEY, PACKAGE_NAME, USER_HANDLE); + public void testEntryClearsNotificationAndDoesNotOpenBubble() throws Exception { + mIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_NOTIFICATION_KEY, + NOTIF_KEY); + mActivity.setIntent(mIntent); + mActivity.onCreate(new Bundle()); verify(mIStatusBarService, times(1)).onNotificationClear(any(), anyInt(), any(), anyInt(), anyInt(), mNotificationVisibilityCaptor.capture()); + verify(mBubblesManager, never()).expandStackAndSelectBubble(any()); NotificationVisibility nv = mNotificationVisibilityCaptor.getValue(); assertThat(nv.count).isEqualTo(NOTIF_COUNT); assertThat(nv.rank).isEqualTo(NOTIF_RANK); } + @Test + public void testBubbleEntryOpensBubbleAndDoesNotClearNotification() throws Exception { + mIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_NOTIFICATION_KEY, + NOTIF_KEY_CAN_BUBBLE); + mActivity.setIntent(mIntent); + mActivity.onCreate(new Bundle()); + + // Don't clear the notification for bubbles. + verify(mIStatusBarService, never()).onNotificationClear(any(), + anyInt(), any(), anyInt(), anyInt(), any()); + verify(mBubblesManager, times(1)).expandStackAndSelectBubble(eq(mNotifEntryCanBubble)); + } } |