Merge "Remove unneeded notif vis checks" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c8a32ef1f8
@@ -22,10 +22,8 @@ import android.view.View.GONE
|
|||||||
import com.android.systemui.R
|
import com.android.systemui.R
|
||||||
import com.android.systemui.dagger.SysUISingleton
|
import com.android.systemui.dagger.SysUISingleton
|
||||||
import com.android.systemui.dagger.qualifiers.Main
|
import com.android.systemui.dagger.qualifiers.Main
|
||||||
import com.android.systemui.statusbar.NotificationLockscreenUserManager
|
|
||||||
import com.android.systemui.statusbar.StatusBarState.KEYGUARD
|
import com.android.systemui.statusbar.StatusBarState.KEYGUARD
|
||||||
import com.android.systemui.statusbar.SysuiStatusBarStateController
|
import com.android.systemui.statusbar.SysuiStatusBarStateController
|
||||||
import com.android.systemui.statusbar.notification.collection.legacy.NotificationGroupManagerLegacy
|
|
||||||
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
|
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
|
||||||
import com.android.systemui.statusbar.notification.row.ExpandableView
|
import com.android.systemui.statusbar.notification.row.ExpandableView
|
||||||
import com.android.systemui.util.children
|
import com.android.systemui.util.children
|
||||||
@@ -41,8 +39,6 @@ private const val DEBUG = false
|
|||||||
class NotificationStackSizeCalculator
|
class NotificationStackSizeCalculator
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val groupManager: NotificationGroupManagerLegacy,
|
|
||||||
private val lockscreenUserManager: NotificationLockscreenUserManager,
|
|
||||||
private val statusBarStateController: SysuiStatusBarStateController,
|
private val statusBarStateController: SysuiStatusBarStateController,
|
||||||
@Main private val resources: Resources
|
@Main private val resources: Resources
|
||||||
) {
|
) {
|
||||||
@@ -191,7 +187,7 @@ constructor(
|
|||||||
if (onLockscreen) {
|
if (onLockscreen) {
|
||||||
when (this) {
|
when (this) {
|
||||||
is ExpandableNotificationRow -> {
|
is ExpandableNotificationRow -> {
|
||||||
if (isSummaryOfSuppressedGroup() || !canShowViewOnLockscreen() || isRemoved) {
|
if (!canShowViewOnLockscreen() || isRemoved) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,9 +204,6 @@ constructor(
|
|||||||
visibleIndex: Int
|
visibleIndex: Int
|
||||||
) = stack.calculateGapHeight(previous, /* current= */ this, visibleIndex)
|
) = stack.calculateGapHeight(previous, /* current= */ this, visibleIndex)
|
||||||
|
|
||||||
private fun ExpandableNotificationRow.isSummaryOfSuppressedGroup() =
|
|
||||||
groupManager.isSummaryOfSuppressedGroup(entry.sbn)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can a view be shown on the lockscreen when calculating the number of allowed notifications to
|
* Can a view be shown on the lockscreen when calculating the number of allowed notifications to
|
||||||
* show?
|
* show?
|
||||||
@@ -220,31 +213,12 @@ constructor(
|
|||||||
private fun ExpandableView.canShowViewOnLockscreen(): Boolean {
|
private fun ExpandableView.canShowViewOnLockscreen(): Boolean {
|
||||||
if (hasNoContentHeight()) {
|
if (hasNoContentHeight()) {
|
||||||
return false
|
return false
|
||||||
}
|
|
||||||
if (this is ExpandableNotificationRow && !canShowRowOnLockscreen()) {
|
|
||||||
return false
|
|
||||||
} else if (visibility == GONE) {
|
} else if (visibility == GONE) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Can a row be shown on the lockscreen when calculating the number of allowed notifications to
|
|
||||||
* show?
|
|
||||||
*
|
|
||||||
* @return true if it can be shown
|
|
||||||
*/
|
|
||||||
private fun ExpandableNotificationRow.canShowRowOnLockscreen(): Boolean {
|
|
||||||
if (isSummaryOfSuppressedGroup()) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if (!lockscreenUserManager.shouldShowOnKeyguard(entry)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return !isRemoved
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun log(s: () -> String) {
|
private fun log(s: () -> String) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, s())
|
Log.d(TAG, s())
|
||||||
|
|||||||
@@ -22,12 +22,10 @@ import android.view.View.VISIBLE
|
|||||||
import androidx.test.filters.SmallTest
|
import androidx.test.filters.SmallTest
|
||||||
import com.android.systemui.R
|
import com.android.systemui.R
|
||||||
import com.android.systemui.SysuiTestCase
|
import com.android.systemui.SysuiTestCase
|
||||||
import com.android.systemui.statusbar.NotificationLockscreenUserManager
|
|
||||||
import com.android.systemui.statusbar.StatusBarState.KEYGUARD
|
import com.android.systemui.statusbar.StatusBarState.KEYGUARD
|
||||||
import com.android.systemui.statusbar.StatusBarState.SHADE
|
import com.android.systemui.statusbar.StatusBarState.SHADE
|
||||||
import com.android.systemui.statusbar.SysuiStatusBarStateController
|
import com.android.systemui.statusbar.SysuiStatusBarStateController
|
||||||
import com.android.systemui.statusbar.notification.collection.NotificationEntry
|
import com.android.systemui.statusbar.notification.collection.NotificationEntry
|
||||||
import com.android.systemui.statusbar.notification.collection.legacy.NotificationGroupManagerLegacy
|
|
||||||
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
|
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
|
||||||
import com.android.systemui.statusbar.notification.row.ExpandableView
|
import com.android.systemui.statusbar.notification.row.ExpandableView
|
||||||
import com.android.systemui.util.mockito.any
|
import com.android.systemui.util.mockito.any
|
||||||
@@ -38,17 +36,13 @@ import org.junit.Test
|
|||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito.mock
|
import org.mockito.Mockito.mock
|
||||||
import org.mockito.Mockito.`when` as whenever
|
|
||||||
import org.mockito.MockitoAnnotations
|
import org.mockito.MockitoAnnotations
|
||||||
|
import org.mockito.Mockito.`when` as whenever
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
@RunWith(AndroidTestingRunner::class)
|
@RunWith(AndroidTestingRunner::class)
|
||||||
class NotificationStackSizeCalculatorTest : SysuiTestCase() {
|
class NotificationStackSizeCalculatorTest : SysuiTestCase() {
|
||||||
|
|
||||||
@Mock private lateinit var groupManager: NotificationGroupManagerLegacy
|
|
||||||
|
|
||||||
@Mock private lateinit var notificationLockscreenUserManager: NotificationLockscreenUserManager
|
|
||||||
|
|
||||||
@Mock private lateinit var sysuiStatusBarStateController: SysuiStatusBarStateController
|
@Mock private lateinit var sysuiStatusBarStateController: SysuiStatusBarStateController
|
||||||
|
|
||||||
@Mock private lateinit var stackLayout: NotificationStackScrollLayout
|
@Mock private lateinit var stackLayout: NotificationStackScrollLayout
|
||||||
@@ -63,7 +57,6 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
|
|||||||
|
|
||||||
whenever(stackLayout.calculateGapHeight(nullable(), nullable(), any()))
|
whenever(stackLayout.calculateGapHeight(nullable(), nullable(), any()))
|
||||||
.thenReturn(GAP_HEIGHT)
|
.thenReturn(GAP_HEIGHT)
|
||||||
whenever(groupManager.isSummaryOfSuppressedGroup(any())).thenReturn(false)
|
|
||||||
with(testableResources) {
|
with(testableResources) {
|
||||||
addOverride(R.integer.keyguard_max_notification_count, -1)
|
addOverride(R.integer.keyguard_max_notification_count, -1)
|
||||||
addOverride(R.dimen.notification_divider_height, NOTIFICATION_PADDING.toInt())
|
addOverride(R.dimen.notification_divider_height, NOTIFICATION_PADDING.toInt())
|
||||||
@@ -71,15 +64,13 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
|
|||||||
|
|
||||||
sizeCalculator =
|
sizeCalculator =
|
||||||
NotificationStackSizeCalculator(
|
NotificationStackSizeCalculator(
|
||||||
groupManager = groupManager,
|
|
||||||
lockscreenUserManager = notificationLockscreenUserManager,
|
|
||||||
statusBarStateController = sysuiStatusBarStateController,
|
statusBarStateController = sysuiStatusBarStateController,
|
||||||
testableResources.resources)
|
testableResources.resources)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun computeMaxKeyguardNotifications_zeroSpace_returnZero() {
|
fun computeMaxKeyguardNotifications_zeroSpace_returnZero() {
|
||||||
val rows = listOf(createMockRow(height = ROW_HEIGHT, visibleOnLockscreen = true))
|
val rows = listOf(createMockRow(height = ROW_HEIGHT))
|
||||||
|
|
||||||
val maxNotifications =
|
val maxNotifications =
|
||||||
computeMaxKeyguardNotifications(rows, availableSpace = 0f, shelfHeight = 0f)
|
computeMaxKeyguardNotifications(rows, availableSpace = 0f, shelfHeight = 0f)
|
||||||
@@ -106,8 +97,8 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
|
|||||||
val spaceForOne = totalSpaceForEachRow
|
val spaceForOne = totalSpaceForEachRow
|
||||||
val rows =
|
val rows =
|
||||||
listOf(
|
listOf(
|
||||||
createMockRow(rowHeight, visibleOnLockscreen = true),
|
createMockRow(rowHeight),
|
||||||
createMockRow(rowHeight, visibleOnLockscreen = true))
|
createMockRow(rowHeight))
|
||||||
|
|
||||||
val maxNotifications =
|
val maxNotifications =
|
||||||
computeMaxKeyguardNotifications(
|
computeMaxKeyguardNotifications(
|
||||||
@@ -124,8 +115,8 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
|
|||||||
val spaceForOne = totalSpaceForEachRow
|
val spaceForOne = totalSpaceForEachRow
|
||||||
val rows =
|
val rows =
|
||||||
listOf(
|
listOf(
|
||||||
createMockRow(rowHeight, visibleOnLockscreen = true),
|
createMockRow(rowHeight),
|
||||||
createMockRow(rowHeight, visibleOnLockscreen = true))
|
createMockRow(rowHeight))
|
||||||
|
|
||||||
val maxNotifications =
|
val maxNotifications =
|
||||||
computeMaxKeyguardNotifications(
|
computeMaxKeyguardNotifications(
|
||||||
@@ -134,15 +125,6 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
|
|||||||
assertThat(maxNotifications).isEqualTo(1)
|
assertThat(maxNotifications).isEqualTo(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun computeMaxKeyguardNotifications_invisibleOnLockscreen_returnsZero() {
|
|
||||||
val rows = listOf(createMockRow(visibleOnLockscreen = false))
|
|
||||||
|
|
||||||
val maxNotifications = computeMaxKeyguardNotifications(rows, Float.MAX_VALUE)
|
|
||||||
|
|
||||||
assertThat(maxNotifications).isEqualTo(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun computeMaxKeyguardNotifications_spaceForTwo_returnsTwo() {
|
fun computeMaxKeyguardNotifications_spaceForTwo_returnsTwo() {
|
||||||
val rowHeight = ROW_HEIGHT
|
val rowHeight = ROW_HEIGHT
|
||||||
@@ -150,9 +132,9 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
|
|||||||
val spaceForTwo = totalSpaceForEachRow * 2 + NOTIFICATION_PADDING
|
val spaceForTwo = totalSpaceForEachRow * 2 + NOTIFICATION_PADDING
|
||||||
val rows =
|
val rows =
|
||||||
listOf(
|
listOf(
|
||||||
createMockRow(rowHeight, visibleOnLockscreen = true),
|
createMockRow(rowHeight),
|
||||||
createMockRow(rowHeight, visibleOnLockscreen = true),
|
createMockRow(rowHeight),
|
||||||
createMockRow(rowHeight, visibleOnLockscreen = true))
|
createMockRow(rowHeight))
|
||||||
|
|
||||||
val maxNotifications = computeMaxKeyguardNotifications(rows, spaceForTwo, shelfHeight = 0f)
|
val maxNotifications = computeMaxKeyguardNotifications(rows, spaceForTwo, shelfHeight = 0f)
|
||||||
|
|
||||||
@@ -167,9 +149,9 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
|
|||||||
val availableSpace = totalSpaceForEachRow * 2
|
val availableSpace = totalSpaceForEachRow * 2
|
||||||
val rows =
|
val rows =
|
||||||
listOf(
|
listOf(
|
||||||
createMockRow(rowHeight, visibleOnLockscreen = true),
|
createMockRow(rowHeight),
|
||||||
createMockRow(rowHeight, visibleOnLockscreen = true),
|
createMockRow(rowHeight),
|
||||||
createMockRow(rowHeight, visibleOnLockscreen = true))
|
createMockRow(rowHeight))
|
||||||
|
|
||||||
val maxNotifications = computeMaxKeyguardNotifications(rows, availableSpace, shelfHeight)
|
val maxNotifications = computeMaxKeyguardNotifications(rows, availableSpace, shelfHeight)
|
||||||
assertThat(maxNotifications).isEqualTo(2)
|
assertThat(maxNotifications).isEqualTo(2)
|
||||||
@@ -178,31 +160,6 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
|
|||||||
assertThat(height).isAtMost(availableSpace + SHELF_HEIGHT)
|
assertThat(height).isAtMost(availableSpace + SHELF_HEIGHT)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun computeHeight_allInvisibleToLockscreen_NotInLockscreen_returnsHigherThanZero() {
|
|
||||||
setOnLockscreen(false)
|
|
||||||
val rowHeight = 10f
|
|
||||||
setupChildren(listOf(createMockRow(rowHeight, visibleOnLockscreen = false)))
|
|
||||||
|
|
||||||
val height =
|
|
||||||
sizeCalculator.computeHeight(
|
|
||||||
stackLayout, maxNotifications = Int.MAX_VALUE, SHELF_HEIGHT)
|
|
||||||
|
|
||||||
assertThat(height).isGreaterThan(rowHeight)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun computeHeight_allInvisibleToLockscreen_onLockscreen_returnsZero() {
|
|
||||||
setOnLockscreen(true)
|
|
||||||
setupChildren(listOf(createMockRow(visibleOnLockscreen = false)))
|
|
||||||
|
|
||||||
val height =
|
|
||||||
sizeCalculator.computeHeight(
|
|
||||||
stackLayout, maxNotifications = Int.MAX_VALUE, SHELF_HEIGHT)
|
|
||||||
|
|
||||||
assertThat(height).isEqualTo(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun computeMaxKeyguardNotifications(
|
private fun computeMaxKeyguardNotifications(
|
||||||
rows: List<ExpandableView>,
|
rows: List<ExpandableView>,
|
||||||
availableSpace: Float,
|
availableSpace: Float,
|
||||||
@@ -222,14 +179,12 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createLockscreenRows(number: Int): List<ExpandableNotificationRow> =
|
private fun createLockscreenRows(number: Int): List<ExpandableNotificationRow> =
|
||||||
(1..number).map { createMockRow(visibleOnLockscreen = true) }.toList()
|
(1..number).map { createMockRow() }.toList()
|
||||||
|
|
||||||
private fun createMockRow(
|
private fun createMockRow(
|
||||||
height: Float = ROW_HEIGHT,
|
height: Float = ROW_HEIGHT,
|
||||||
visibleOnLockscreen: Boolean = true,
|
|
||||||
isRemoved: Boolean = false,
|
isRemoved: Boolean = false,
|
||||||
visibility: Int = VISIBLE,
|
visibility: Int = VISIBLE,
|
||||||
summaryOfSuppressed: Boolean = false
|
|
||||||
): ExpandableNotificationRow {
|
): ExpandableNotificationRow {
|
||||||
val row = mock(ExpandableNotificationRow::class.java)
|
val row = mock(ExpandableNotificationRow::class.java)
|
||||||
val entry = mock(NotificationEntry::class.java)
|
val entry = mock(NotificationEntry::class.java)
|
||||||
@@ -238,24 +193,11 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
|
|||||||
whenever(row.entry).thenReturn(entry)
|
whenever(row.entry).thenReturn(entry)
|
||||||
whenever(row.isRemoved).thenReturn(isRemoved)
|
whenever(row.isRemoved).thenReturn(isRemoved)
|
||||||
whenever(row.visibility).thenReturn(visibility)
|
whenever(row.visibility).thenReturn(visibility)
|
||||||
whenever(notificationLockscreenUserManager.shouldShowOnKeyguard(entry))
|
|
||||||
.thenReturn(visibleOnLockscreen)
|
|
||||||
whenever(groupManager.isSummaryOfSuppressedGroup(sbn)).thenReturn(summaryOfSuppressed)
|
|
||||||
whenever(row.getMinHeight(any())).thenReturn(height.toInt())
|
whenever(row.getMinHeight(any())).thenReturn(height.toInt())
|
||||||
whenever(row.intrinsicHeight).thenReturn(height.toInt())
|
whenever(row.intrinsicHeight).thenReturn(height.toInt())
|
||||||
return row
|
return row
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setOnLockscreen(onLockscreen: Boolean) {
|
|
||||||
whenever(sysuiStatusBarStateController.state)
|
|
||||||
.thenReturn(
|
|
||||||
if (onLockscreen) {
|
|
||||||
KEYGUARD
|
|
||||||
} else {
|
|
||||||
SHADE
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Default dimensions for tests that don't overwrite them. */
|
/** Default dimensions for tests that don't overwrite them. */
|
||||||
companion object {
|
companion object {
|
||||||
const val GAP_HEIGHT = 12f
|
const val GAP_HEIGHT = 12f
|
||||||
|
|||||||
Reference in New Issue
Block a user