Merge "Limit number of notification actions created" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7a06b6ae73
@@ -611,12 +611,11 @@ public class MediaControlPanel {
|
|||||||
|
|
||||||
private void bindActionButtons(MediaData data) {
|
private void bindActionButtons(MediaData data) {
|
||||||
MediaButton semanticActions = data.getSemanticActions();
|
MediaButton semanticActions = data.getSemanticActions();
|
||||||
ImageButton[] genericButtons = new ImageButton[]{
|
|
||||||
mMediaViewHolder.getAction0(),
|
List<ImageButton> genericButtons = new ArrayList<>();
|
||||||
mMediaViewHolder.getAction1(),
|
for (int id : MediaViewHolder.Companion.getGenericButtonIds()) {
|
||||||
mMediaViewHolder.getAction2(),
|
genericButtons.add(mMediaViewHolder.getAction(id));
|
||||||
mMediaViewHolder.getAction3(),
|
}
|
||||||
mMediaViewHolder.getAction4()};
|
|
||||||
|
|
||||||
ConstraintSet expandedSet = mMediaViewController.getExpandedLayout();
|
ConstraintSet expandedSet = mMediaViewController.getExpandedLayout();
|
||||||
ConstraintSet collapsedSet = mMediaViewController.getCollapsedLayout();
|
ConstraintSet collapsedSet = mMediaViewController.getCollapsedLayout();
|
||||||
@@ -643,19 +642,19 @@ public class MediaControlPanel {
|
|||||||
List<Integer> actionsWhenCollapsed = data.getActionsToShowInCompact();
|
List<Integer> actionsWhenCollapsed = data.getActionsToShowInCompact();
|
||||||
List<MediaAction> actions = data.getActions();
|
List<MediaAction> actions = data.getActions();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i < actions.size(); i++) {
|
for (; i < actions.size() && i < genericButtons.size(); i++) {
|
||||||
boolean showInCompact = actionsWhenCollapsed.contains(i);
|
boolean showInCompact = actionsWhenCollapsed.contains(i);
|
||||||
setGenericButton(
|
setGenericButton(
|
||||||
genericButtons[i],
|
genericButtons.get(i),
|
||||||
actions.get(i),
|
actions.get(i),
|
||||||
collapsedSet,
|
collapsedSet,
|
||||||
expandedSet,
|
expandedSet,
|
||||||
showInCompact);
|
showInCompact);
|
||||||
}
|
}
|
||||||
for (; i < 5; i++) {
|
for (; i < genericButtons.size(); i++) {
|
||||||
// Hide any unused buttons
|
// Hide any unused buttons
|
||||||
setGenericButton(
|
setGenericButton(
|
||||||
genericButtons[i],
|
genericButtons.get(i),
|
||||||
/* mediaAction= */ null,
|
/* mediaAction= */ null,
|
||||||
collapsedSet,
|
collapsedSet,
|
||||||
expandedSet,
|
expandedSet,
|
||||||
|
|||||||
@@ -161,6 +161,10 @@ class MediaDataManager(
|
|||||||
@JvmField
|
@JvmField
|
||||||
val MAX_COMPACT_ACTIONS = 3
|
val MAX_COMPACT_ACTIONS = 3
|
||||||
|
|
||||||
|
// Maximum number of actions allowed in expanded view
|
||||||
|
@JvmField
|
||||||
|
val MAX_NOTIFICATION_ACTIONS = MediaViewHolder.genericButtonIds.size
|
||||||
|
|
||||||
/** Maximum number of [PlaybackState.CustomAction] buttons supported */
|
/** Maximum number of [PlaybackState.CustomAction] buttons supported */
|
||||||
@JvmField
|
@JvmField
|
||||||
val MAX_CUSTOM_ACTIONS = 4
|
val MAX_CUSTOM_ACTIONS = 4
|
||||||
@@ -727,6 +731,11 @@ class MediaDataManager(
|
|||||||
|
|
||||||
if (actions != null) {
|
if (actions != null) {
|
||||||
for ((index, action) in actions.withIndex()) {
|
for ((index, action) in actions.withIndex()) {
|
||||||
|
if (index == MAX_NOTIFICATION_ACTIONS) {
|
||||||
|
Log.w(TAG, "Too many notification actions for ${sbn.key}," +
|
||||||
|
" limiting to first $MAX_NOTIFICATION_ACTIONS")
|
||||||
|
break
|
||||||
|
}
|
||||||
if (action.getIcon() == null) {
|
if (action.getIcon() == null) {
|
||||||
if (DEBUG) Log.i(TAG, "No icon for action $index ${action.title}")
|
if (DEBUG) Log.i(TAG, "No icon for action $index ${action.title}")
|
||||||
actionsToShowCollapsed.remove(index)
|
actionsToShowCollapsed.remove(index)
|
||||||
|
|||||||
@@ -178,5 +178,14 @@ class MediaViewHolder constructor(itemView: View) {
|
|||||||
R.id.dismiss,
|
R.id.dismiss,
|
||||||
R.id.settings
|
R.id.settings
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Buttons used for notification-based actions
|
||||||
|
val genericButtonIds = setOf(
|
||||||
|
R.id.action0,
|
||||||
|
R.id.action1,
|
||||||
|
R.id.action2,
|
||||||
|
R.id.action3,
|
||||||
|
R.id.action4
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.android.systemui.media
|
package com.android.systemui.media
|
||||||
|
|
||||||
|
import android.app.Notification
|
||||||
import android.app.Notification.MediaStyle
|
import android.app.Notification.MediaStyle
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.app.smartspace.SmartspaceAction
|
import android.app.smartspace.SmartspaceAction
|
||||||
@@ -620,6 +621,36 @@ class MediaDataManagerTest : SysuiTestCase() {
|
|||||||
MediaDataManager.MAX_COMPACT_ACTIONS)
|
MediaDataManager.MAX_COMPACT_ACTIONS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testTooManyNotificationActions_isTruncated() {
|
||||||
|
// GIVEN a notification where too many notification actions are added
|
||||||
|
val action = Notification.Action(R.drawable.ic_android, "action", null)
|
||||||
|
val notif = SbnBuilder().run {
|
||||||
|
setPkg(PACKAGE_NAME)
|
||||||
|
modifyNotification(context).also {
|
||||||
|
it.setSmallIcon(android.R.drawable.ic_media_pause)
|
||||||
|
it.setStyle(MediaStyle().apply {
|
||||||
|
setMediaSession(session.sessionToken)
|
||||||
|
})
|
||||||
|
for (i in 0..MediaDataManager.MAX_NOTIFICATION_ACTIONS) {
|
||||||
|
it.addAction(action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
build()
|
||||||
|
}
|
||||||
|
|
||||||
|
// WHEN the notification is loaded
|
||||||
|
mediaDataManager.onNotificationAdded(KEY, notif)
|
||||||
|
assertThat(backgroundExecutor.runAllReady()).isEqualTo(1)
|
||||||
|
assertThat(foregroundExecutor.runAllReady()).isEqualTo(1)
|
||||||
|
|
||||||
|
// THEN only the first MAX_NOTIFICATION_ACTIONS are actually included
|
||||||
|
verify(listener).onMediaDataLoaded(eq(KEY), eq(null), capture(mediaDataCaptor), eq(true),
|
||||||
|
eq(0), eq(false))
|
||||||
|
assertThat(mediaDataCaptor.value.actions.size).isEqualTo(
|
||||||
|
MediaDataManager.MAX_NOTIFICATION_ACTIONS)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testPlaybackActions_noState_usesNotification() {
|
fun testPlaybackActions_noState_usesNotification() {
|
||||||
val desc = "Notification Action"
|
val desc = "Notification Action"
|
||||||
|
|||||||
Reference in New Issue
Block a user