Use PendingIntent for media click action over lockscreen
The clickIntent is provided by apps as the notification's contentIntent,
and it should be sent as is. This fixes the case where the intent called
an activity that could show over lockscreen.
Bug: 271845008
Test: atest MediaControlPanelTest
Test: manually with test app
Change-Id: I09d64452c46c4d21b9d958570020b2f5e6c2b23f
Merged-In: I09d64452c46c4d21b9d958570020b2f5e6c2b23f
(cherry picked from commit cb2904c7ff)
This commit is contained in:
@@ -428,16 +428,16 @@ public class MediaControlPanel {
|
|||||||
mLogger.logTapContentView(mUid, mPackageName, mInstanceId);
|
mLogger.logTapContentView(mUid, mPackageName, mInstanceId);
|
||||||
logSmartspaceCardReported(SMARTSPACE_CARD_CLICK_EVENT);
|
logSmartspaceCardReported(SMARTSPACE_CARD_CLICK_EVENT);
|
||||||
|
|
||||||
// See StatusBarNotificationActivityStarter#onNotificationClicked
|
|
||||||
boolean showOverLockscreen = mKeyguardStateController.isShowing()
|
boolean showOverLockscreen = mKeyguardStateController.isShowing()
|
||||||
&& mActivityIntentHelper.wouldShowOverLockscreen(clickIntent.getIntent(),
|
&& mActivityIntentHelper.wouldPendingShowOverLockscreen(clickIntent,
|
||||||
mLockscreenUserManager.getCurrentUserId());
|
mLockscreenUserManager.getCurrentUserId());
|
||||||
|
|
||||||
if (showOverLockscreen) {
|
if (showOverLockscreen) {
|
||||||
mActivityStarter.startActivity(clickIntent.getIntent(),
|
try {
|
||||||
/* dismissShade */ true,
|
clickIntent.send();
|
||||||
/* animationController */ null,
|
} catch (PendingIntent.CanceledException e) {
|
||||||
/* showOverLockscreenWhenLocked */ true);
|
Log.e(TAG, "Pending intent for " + key + " was cancelled");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mActivityStarter.postStartActivityDismissingKeyguard(clickIntent,
|
mActivityStarter.postStartActivityDismissingKeyguard(clickIntent,
|
||||||
buildLaunchAnimatorController(mMediaViewHolder.getPlayer()));
|
buildLaunchAnimatorController(mMediaViewHolder.getPlayer()));
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ import com.android.systemui.util.mockito.KotlinArgumentCaptor
|
|||||||
import com.android.systemui.util.mockito.argumentCaptor
|
import com.android.systemui.util.mockito.argumentCaptor
|
||||||
import com.android.systemui.util.mockito.any
|
import com.android.systemui.util.mockito.any
|
||||||
import com.android.systemui.util.mockito.eq
|
import com.android.systemui.util.mockito.eq
|
||||||
import com.android.systemui.util.mockito.nullable
|
|
||||||
import com.android.systemui.util.mockito.withArgCaptor
|
import com.android.systemui.util.mockito.withArgCaptor
|
||||||
import com.android.systemui.util.time.FakeSystemClock
|
import com.android.systemui.util.time.FakeSystemClock
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
@@ -1548,7 +1547,7 @@ public class MediaControlPanelTest : SysuiTestCase() {
|
|||||||
fun tapContentView_showOverLockscreen_openActivity() {
|
fun tapContentView_showOverLockscreen_openActivity() {
|
||||||
// WHEN we are on lockscreen and this activity can show over lockscreen
|
// WHEN we are on lockscreen and this activity can show over lockscreen
|
||||||
whenever(keyguardStateController.isShowing).thenReturn(true)
|
whenever(keyguardStateController.isShowing).thenReturn(true)
|
||||||
whenever(activityIntentHelper.wouldShowOverLockscreen(any(), any())).thenReturn(true)
|
whenever(activityIntentHelper.wouldPendingShowOverLockscreen(any(), any())).thenReturn(true)
|
||||||
|
|
||||||
val clickIntent = mock(Intent::class.java)
|
val clickIntent = mock(Intent::class.java)
|
||||||
val pendingIntent = mock(PendingIntent::class.java)
|
val pendingIntent = mock(PendingIntent::class.java)
|
||||||
@@ -1559,17 +1558,20 @@ public class MediaControlPanelTest : SysuiTestCase() {
|
|||||||
player.bindPlayer(data, KEY)
|
player.bindPlayer(data, KEY)
|
||||||
verify(viewHolder.player).setOnClickListener(captor.capture())
|
verify(viewHolder.player).setOnClickListener(captor.capture())
|
||||||
|
|
||||||
// THEN it shows without dismissing keyguard first
|
// THEN it sends the PendingIntent without dismissing keyguard first,
|
||||||
|
// and does not use the Intent directly (see b/271845008)
|
||||||
captor.value.onClick(viewHolder.player)
|
captor.value.onClick(viewHolder.player)
|
||||||
verify(activityStarter).startActivity(eq(clickIntent), eq(true),
|
verify(pendingIntent).send()
|
||||||
nullable(), eq(true))
|
verify(pendingIntent, never()).getIntent()
|
||||||
|
verify(activityStarter, never()).postStartActivityDismissingKeyguard(eq(clickIntent), any())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun tapContentView_noShowOverLockscreen_dismissKeyguard() {
|
fun tapContentView_noShowOverLockscreen_dismissKeyguard() {
|
||||||
// WHEN we are on lockscreen and the activity cannot show over lockscreen
|
// WHEN we are on lockscreen and the activity cannot show over lockscreen
|
||||||
whenever(keyguardStateController.isShowing).thenReturn(true)
|
whenever(keyguardStateController.isShowing).thenReturn(true)
|
||||||
whenever(activityIntentHelper.wouldShowOverLockscreen(any(), any())).thenReturn(false)
|
whenever(activityIntentHelper.wouldPendingShowOverLockscreen(any(), any()))
|
||||||
|
.thenReturn(false)
|
||||||
|
|
||||||
val clickIntent = mock(Intent::class.java)
|
val clickIntent = mock(Intent::class.java)
|
||||||
val pendingIntent = mock(PendingIntent::class.java)
|
val pendingIntent = mock(PendingIntent::class.java)
|
||||||
|
|||||||
Reference in New Issue
Block a user