Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c0c0957a authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB][Notif] Hide the second chip if it doesn't fit.

Fixes: 369154365
Bug: 364653005
Flag: com.android.systemui.status_bar_notification_chips

Test: Trigger 2 chips that are icon-only -> verify both chips are shown
Test: Trigger 1 chip with a timer and 1 chip that's icon only -> verify
only timer chip shows because there's not enough room
Test: Verify 3-2-1 screen record countdown chip is still < 48dp
Test: Verify an icon-only tappaple chip is 48dp
Test: With status_bar_notification_chips flag off, verify screen record
& call chips still work as expected

Change-Id: I2a244c279b8a31f158e73f0665463bfac9dc6e0c
parent 0c74c972
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ class ChipBackgroundContainerTest : SysuiTestCase() {
        allowTestableLooperAsMainThread()
        TestableLooper.get(this).runWithLooper {
            val chipView =
                LayoutInflater.from(context).inflate(R.layout.ongoing_activity_chip, null)
                LayoutInflater.from(context).inflate(R.layout.ongoing_activity_chip_primary, null)
            underTest = chipView.requireViewById(R.id.ongoing_activity_chip_background)
        }
    }
+2 −2
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ class ChipChronometerTest : SysuiTestCase() {
        allowTestableLooperAsMainThread()
        TestableLooper.get(this).runWithLooper {
            val chipView =
                LayoutInflater.from(mContext).inflate(R.layout.ongoing_activity_chip, null)
                LayoutInflater.from(mContext).inflate(R.layout.ongoing_activity_chip_primary, null)
            textView = chipView.findViewById(R.id.ongoing_activity_chip_time)!!
            measureTextView()
            calculateDoesNotFixText()
@@ -161,7 +161,7 @@ class ChipChronometerTest : SysuiTestCase() {
    private fun measureTextView() {
        textView.measure(
            View.MeasureSpec.makeMeasureSpec(TEXT_VIEW_MAX_WIDTH, View.MeasureSpec.AT_MOST),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
        )
    }

+3 −2
Original line number Diff line number Diff line
@@ -114,7 +114,8 @@ class OngoingCallControllerViaListenerTest : SysuiTestCase() {
    fun setUp() {
        allowTestableLooperAsMainThread()
        TestableLooper.get(this).runWithLooper {
            chipView = LayoutInflater.from(mContext).inflate(R.layout.ongoing_activity_chip, null)
            chipView =
                LayoutInflater.from(mContext).inflate(R.layout.ongoing_activity_chip_primary, null)
        }

        MockitoAnnotations.initMocks(this)
@@ -498,7 +499,7 @@ class OngoingCallControllerViaListenerTest : SysuiTestCase() {
        lateinit var newChipView: View
        TestableLooper.get(this).runWithLooper {
            newChipView =
                LayoutInflater.from(mContext).inflate(R.layout.ongoing_activity_chip, null)
                LayoutInflater.from(mContext).inflate(R.layout.ongoing_activity_chip_primary, null)
        }

        // Change the chip view associated with the controller.
+18 −80
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.widget.LinearLayout
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.Flags.FLAG_STATUS_BAR_CALL_CHIP_NOTIFICATION_ICON
import com.android.systemui.Flags.FLAG_STATUS_BAR_CHIPS_MODERNIZATION
import com.android.systemui.Flags.FLAG_STATUS_BAR_SCREEN_SHARING_CHIPS
import com.android.systemui.Flags.FLAG_STATUS_BAR_USE_REPOS_FOR_CALL_CHIP
import com.android.systemui.SysuiTestCase
@@ -104,7 +103,8 @@ class OngoingCallControllerViaRepoTest : SysuiTestCase() {
    fun setUp() {
        allowTestableLooperAsMainThread()
        TestableLooper.get(this).runWithLooper {
            chipView = LayoutInflater.from(mContext).inflate(R.layout.ongoing_activity_chip, null)
            chipView =
                LayoutInflater.from(mContext).inflate(R.layout.ongoing_activity_chip_primary, null)
        }

        whenever(mockStatusBarWindowControllerStore.defaultDisplay)
@@ -134,12 +134,7 @@ class OngoingCallControllerViaRepoTest : SysuiTestCase() {
        testScope.runCurrent()
        reset(mockOngoingCallListener)

        whenever(
                mockIActivityManager.getUidProcessState(
                    eq(CALL_UID),
                    any(),
                )
            )
        whenever(mockIActivityManager.getUidProcessState(eq(CALL_UID), any()))
            .thenReturn(PROC_STATE_INVISIBLE)
    }

@@ -225,38 +220,18 @@ class OngoingCallControllerViaRepoTest : SysuiTestCase() {

    @Test
    fun notifRepoHasOngoingCallNotifThenScreeningNotif_listenerNotifiedTwice() {
        setNotifOnRepo(
            activeNotificationModel(
                key = "notif",
                callType = CallType.Ongoing,
            )
        )
        setNotifOnRepo(activeNotificationModel(key = "notif", callType = CallType.Ongoing))

        setNotifOnRepo(
            activeNotificationModel(
                key = "notif",
                callType = CallType.Screening,
            )
        )
        setNotifOnRepo(activeNotificationModel(key = "notif", callType = CallType.Screening))

        verify(mockOngoingCallListener, times(2)).onOngoingCallStateChanged(any())
    }

    @Test
    fun notifRepoHasOngoingCallNotifThenScreeningNotif_repoUpdated() {
        setNotifOnRepo(
            activeNotificationModel(
                key = "notif",
                callType = CallType.Ongoing,
            )
        )
        setNotifOnRepo(activeNotificationModel(key = "notif", callType = CallType.Ongoing))

        setNotifOnRepo(
            activeNotificationModel(
                key = "notif",
                callType = CallType.Screening,
            )
        )
        setNotifOnRepo(activeNotificationModel(key = "notif", callType = CallType.Screening))

        assertThat(ongoingCallRepository.ongoingCallState.value)
            .isInstanceOf(OngoingCallModel.NoCall::class.java)
@@ -289,7 +264,7 @@ class OngoingCallControllerViaRepoTest : SysuiTestCase() {

        chipView.measure(
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
        )

        assertThat(chipView.findViewById<View>(R.id.ongoing_activity_chip_time)?.measuredWidth)
@@ -309,7 +284,7 @@ class OngoingCallControllerViaRepoTest : SysuiTestCase() {

        chipView.measure(
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
        )

        assertThat(chipView.findViewById<View>(R.id.ongoing_activity_chip_time)?.measuredWidth)
@@ -323,11 +298,7 @@ class OngoingCallControllerViaRepoTest : SysuiTestCase() {
            // Re-create the notification each time so that it's considered a different object and
            // will re-trigger the whole flow.
            setNotifOnRepo(
                activeNotificationModel(
                    key = "notif$i",
                    callType = CallType.Ongoing,
                    whenTime = 44,
                )
                activeNotificationModel(key = "notif$i", callType = CallType.Ongoing, whenTime = 44)
            )
        }

@@ -337,12 +308,7 @@ class OngoingCallControllerViaRepoTest : SysuiTestCase() {
    /** Regression test for b/216248574. */
    @Test
    fun repoHasCallNotif_getUidProcessStateThrowsException_noCrash() {
        whenever(
                mockIActivityManager.getUidProcessState(
                    eq(CALL_UID),
                    any(),
                )
            )
        whenever(mockIActivityManager.getUidProcessState(eq(CALL_UID), any()))
            .thenThrow(SecurityException())

        // No assert required, just check no crash
@@ -352,14 +318,7 @@ class OngoingCallControllerViaRepoTest : SysuiTestCase() {
    /** Regression test for b/216248574. */
    @Test
    fun repoHasCallNotif_registerUidObserverThrowsException_noCrash() {
        whenever(
                mockIActivityManager.registerUidObserver(
                    any(),
                    any(),
                    any(),
                    any(),
                )
            )
        whenever(mockIActivityManager.registerUidObserver(any(), any(), any(), any()))
            .thenThrow(SecurityException())

        // No assert required, just check no crash
@@ -416,11 +375,7 @@ class OngoingCallControllerViaRepoTest : SysuiTestCase() {
    @Test
    fun hasOngoingCall_repoHasUnrelatedNotif_returnsFalse() {
        setNotifOnRepo(
            activeNotificationModel(
                key = "unrelated",
                callType = CallType.None,
                uid = CALL_UID,
            )
            activeNotificationModel(key = "unrelated", callType = CallType.None, uid = CALL_UID)
        )

        assertThat(controller.hasOngoingCall()).isFalse()
@@ -441,20 +396,11 @@ class OngoingCallControllerViaRepoTest : SysuiTestCase() {

    @Test
    fun hasOngoingCall_repoHasCallNotifAndCallAppNotVisible_returnsTrue() {
        whenever(
                mockIActivityManager.getUidProcessState(
                    eq(CALL_UID),
                    any(),
                )
            )
        whenever(mockIActivityManager.getUidProcessState(eq(CALL_UID), any()))
            .thenReturn(PROC_STATE_INVISIBLE)

        setNotifOnRepo(
            activeNotificationModel(
                key = "notif",
                callType = CallType.Ongoing,
                uid = CALL_UID,
            )
            activeNotificationModel(key = "notif", callType = CallType.Ongoing, uid = CALL_UID)
        )

        assertThat(controller.hasOngoingCall()).isTrue()
@@ -466,11 +412,7 @@ class OngoingCallControllerViaRepoTest : SysuiTestCase() {
            .thenReturn(PROC_STATE_VISIBLE)

        setNotifOnRepo(
            activeNotificationModel(
                key = "notif",
                callType = CallType.Ongoing,
                uid = CALL_UID,
            )
            activeNotificationModel(key = "notif", callType = CallType.Ongoing, uid = CALL_UID)
        )

        assertThat(controller.hasOngoingCall()).isFalse()
@@ -482,11 +424,7 @@ class OngoingCallControllerViaRepoTest : SysuiTestCase() {
        controller.setChipView(invalidChipView)

        setNotifOnRepo(
            activeNotificationModel(
                key = "notif",
                callType = CallType.Ongoing,
                uid = CALL_UID,
            )
            activeNotificationModel(key = "notif", callType = CallType.Ongoing, uid = CALL_UID)
        )

        assertThat(controller.hasOngoingCall()).isFalse()
@@ -532,7 +470,7 @@ class OngoingCallControllerViaRepoTest : SysuiTestCase() {
        lateinit var newChipView: View
        TestableLooper.get(this).runWithLooper {
            newChipView =
                LayoutInflater.from(mContext).inflate(R.layout.ongoing_activity_chip, null)
                LayoutInflater.from(mContext).inflate(R.layout.ongoing_activity_chip_primary, null)
        }

        // Change the chip view associated with the controller.
+4 −9
Original line number Diff line number Diff line
@@ -13,14 +13,9 @@
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
<!-- Have the wrapper frame layout match the parent height so that we get a larger touch area for
     the chip. -->
<FrameLayout

<merge
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="center_vertical|start"
    android:layout_marginStart="5dp"
    >
    <!-- TODO(b/332662551): Update this content description when this supports more than just
         phone calls. -->
@@ -72,4 +67,4 @@
            />

    </com.android.systemui.statusbar.chips.ui.view.ChipBackgroundContainer>
</FrameLayout>
</merge>
Loading