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

Commit b67dfbd3 authored by András Kurucz's avatar András Kurucz Committed by Android (Google) Code Review
Browse files

Merge "Remove recycling HeadsUpManagerPhone objects" into main

parents 68670ec4 4171ecc0
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -103,6 +103,13 @@ flag {
    bug: "308623704"
}

flag {
    name: "notifications_heads_up_refactor"
    namespace: "systemui"
    description: "Use HeadsUpInteractor to feed HUN updates to the NSSL."
    bug: "325936094"
}

flag {
   name: "pss_app_selector_abrupt_exit_fix"
   namespace: "systemui"
+3 −8
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ class AvalancheControllerTest : SysuiTestCase() {
    private val mGlobalSettings = FakeGlobalSettings()
    private val mSystemClock = FakeSystemClock()
    private val mExecutor = FakeExecutor(mSystemClock)
    private var testableHeadsUpManager: BaseHeadsUpManager? = null
    private lateinit var testableHeadsUpManager: BaseHeadsUpManager

    @Before
    fun setUp() {
@@ -88,20 +88,15 @@ class AvalancheControllerTest : SysuiTestCase() {
    }

    private fun createHeadsUpEntry(id: Int): BaseHeadsUpManager.HeadsUpEntry {
        val entry = testableHeadsUpManager!!.createHeadsUpEntry()

        entry.setEntry(
        return testableHeadsUpManager.createHeadsUpEntry(
            NotificationEntryBuilder()
                .setSbn(HeadsUpManagerTestUtil.createSbn(id, Notification.Builder(mContext, "")))
                .build()
        )
        return entry
    }

    private fun createFsiHeadsUpEntry(id: Int): BaseHeadsUpManager.HeadsUpEntry {
        val entry = testableHeadsUpManager!!.createHeadsUpEntry()
        entry.setEntry(createFullScreenIntentEntry(id, mContext))
        return entry
        return testableHeadsUpManager.createHeadsUpEntry(createFullScreenIntentEntry(id, mContext))
    }

    @Test
+20 −22
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ import static org.mockito.Mockito.when;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Person;
import android.content.Intent;
import android.testing.TestableLooper;

import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -498,16 +497,16 @@ public class BaseHeadsUpManagerTest extends SysuiTestCase {
    public void testAlertEntryCompareTo_ongoingCallLessThanActiveRemoteInput() {
        final BaseHeadsUpManager hum = createHeadsUpManager();

        final BaseHeadsUpManager.HeadsUpEntry ongoingCall = hum.new HeadsUpEntry();
        ongoingCall.setEntry(new NotificationEntryBuilder()
        final BaseHeadsUpManager.HeadsUpEntry ongoingCall = hum.new HeadsUpEntry(
                new NotificationEntryBuilder()
                        .setSbn(HeadsUpManagerTestUtil.createSbn(/* id = */ 0,
                                new Notification.Builder(mContext, "")
                                        .setCategory(Notification.CATEGORY_CALL)
                                        .setOngoing(true)))
                        .build());

        final BaseHeadsUpManager.HeadsUpEntry activeRemoteInput = hum.new HeadsUpEntry();
        activeRemoteInput.setEntry(HeadsUpManagerTestUtil.createEntry(/* id = */ 1, mContext));
        final BaseHeadsUpManager.HeadsUpEntry activeRemoteInput = hum.new HeadsUpEntry(
                HeadsUpManagerTestUtil.createEntry(/* id = */ 1, mContext));
        activeRemoteInput.mRemoteInputActive = true;

        assertThat(ongoingCall.compareTo(activeRemoteInput)).isLessThan(0);
@@ -518,18 +517,18 @@ public class BaseHeadsUpManagerTest extends SysuiTestCase {
    public void testAlertEntryCompareTo_incomingCallLessThanActiveRemoteInput() {
        final BaseHeadsUpManager hum = createHeadsUpManager();

        final BaseHeadsUpManager.HeadsUpEntry incomingCall = hum.new HeadsUpEntry();
        final Person person = new Person.Builder().setName("person").build();
        final PendingIntent intent = mock(PendingIntent.class);
        incomingCall.setEntry(new NotificationEntryBuilder()
        final BaseHeadsUpManager.HeadsUpEntry incomingCall = hum.new HeadsUpEntry(
                new NotificationEntryBuilder()
                        .setSbn(HeadsUpManagerTestUtil.createSbn(/* id = */ 0,
                                new Notification.Builder(mContext, "")
                                        .setStyle(Notification.CallStyle
                                                .forIncomingCall(person, intent, intent))))
                        .build());

        final BaseHeadsUpManager.HeadsUpEntry activeRemoteInput = hum.new HeadsUpEntry();
        activeRemoteInput.setEntry(HeadsUpManagerTestUtil.createEntry(/* id = */ 1, mContext));
        final BaseHeadsUpManager.HeadsUpEntry activeRemoteInput = hum.new HeadsUpEntry(
                HeadsUpManagerTestUtil.createEntry(/* id = */ 1, mContext));
        activeRemoteInput.mRemoteInputActive = true;

        assertThat(incomingCall.compareTo(activeRemoteInput)).isLessThan(0);
@@ -541,8 +540,7 @@ public class BaseHeadsUpManagerTest extends SysuiTestCase {
        final BaseHeadsUpManager hum = createHeadsUpManager();

        // Needs full screen intent in order to be pinned
        final BaseHeadsUpManager.HeadsUpEntry entryToPin = hum.new HeadsUpEntry();
        entryToPin.setEntry(
        final BaseHeadsUpManager.HeadsUpEntry entryToPin = hum.new HeadsUpEntry(
                HeadsUpManagerTestUtil.createFullScreenIntentEntry(/* id = */ 0, mContext));

        // Note: the standard way to show a notification would be calling showNotification rather
+3 −2
Original line number Diff line number Diff line
@@ -54,9 +54,10 @@ class TestableHeadsUpManager extends BaseHeadsUpManager {
        mStickyForSomeTimeAutoDismissTime = BaseHeadsUpManagerTest.TEST_STICKY_AUTO_DISMISS_TIME;
    }

    @NonNull
    @Override
    protected HeadsUpEntry createHeadsUpEntry() {
        mLastCreatedEntry = spy(super.createHeadsUpEntry());
    protected HeadsUpEntry createHeadsUpEntry(NotificationEntry entry) {
        mLastCreatedEntry = spy(super.createHeadsUpEntry(entry));
        return mLastCreatedEntry;
    }

+53 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.notification.shared

import com.android.systemui.Flags
import com.android.systemui.flags.FlagToken
import com.android.systemui.flags.RefactorFlagUtils

/** Helper for reading or using the notifications heads up refactor flag state. */
@Suppress("NOTHING_TO_INLINE")
object NotificationsHeadsUpRefactor {
    /** The aconfig flag name */
    const val FLAG_NAME = Flags.FLAG_NOTIFICATIONS_HEADS_UP_REFACTOR

    /** A token used for dependency declaration */
    val token: FlagToken
        get() = FlagToken(FLAG_NAME, isEnabled)

    /** Is the refactor enabled */
    @JvmStatic
    inline val isEnabled
        get() = Flags.notificationsHeadsUpRefactor()

    /**
     * Called to ensure code is only run when the flag is enabled. This protects users from the
     * unintended behaviors caused by accidentally running new logic, while also crashing on an eng
     * build to ensure that the refactor author catches issues in testing.
     */
    @JvmStatic
    inline fun isUnexpectedlyInLegacyMode() =
        RefactorFlagUtils.isUnexpectedlyInLegacyMode(isEnabled, FLAG_NAME)

    /**
     * Called to ensure code is only run when the flag is disabled. This will throw an exception if
     * the flag is enabled to ensure that the refactor author catches issues in testing.
     */
    @JvmStatic
    inline fun assertInLegacyMode() = RefactorFlagUtils.assertInLegacyMode(isEnabled, FLAG_NAME)
}
Loading