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

Commit 83b7fafe authored by Ioana Alexandru's avatar Ioana Alexandru Committed by Android (Google) Code Review
Browse files

Merge changes Ieb3493f2,Iff1926d2 into udc-qpr-dev

* changes:
  Only notify listeners when group expansion changes.
  Add flag for group expansion listener changes.
parents 412fd60e 2a98b955
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -112,6 +112,12 @@ object Flags {
            default = true
        )

    /** Only notify group expansion listeners when a change happens. */
    // TODO(b/292213543): Tracking Bug
    @JvmField
    val NOTIFICATION_GROUP_EXPANSION_CHANGE =
            unreleasedFlag(292213543, "notification_group_expansion_change", teamfood = false)

    // 200 - keyguard/lockscreen
    // ** Flag retired **
    // public static final BooleanFlag KEYGUARD_LAYOUT =
+18 −5
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import androidx.annotation.NonNull;
import com.android.systemui.Dumpable;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.statusbar.notification.collection.GroupEntry;
import com.android.systemui.statusbar.notification.collection.ListEntry;
import com.android.systemui.statusbar.notification.collection.NotifPipeline;
@@ -44,14 +46,21 @@ public class GroupExpansionManagerImpl implements GroupExpansionManager, Dumpabl
    private final GroupMembershipManager mGroupMembershipManager;
    private final Set<OnGroupExpansionChangeListener> mOnGroupChangeListeners = new HashSet<>();

    // Set of summary keys whose groups are expanded
    /**
     * Set of summary keys whose groups are expanded.
     * NOTE: This should not be modified without notifying listeners, so prefer using
     * {@code setGroupExpanded} when making changes.
      */
    private final Set<NotificationEntry> mExpandedGroups = new HashSet<>();

    private final FeatureFlags mFeatureFlags;

    @Inject
    public GroupExpansionManagerImpl(DumpManager dumpManager,
            GroupMembershipManager groupMembershipManager) {
            GroupMembershipManager groupMembershipManager, FeatureFlags featureFlags) {
        mDumpManager = dumpManager;
        mGroupMembershipManager = groupMembershipManager;
        mFeatureFlags = featureFlags;
    }

    /**
@@ -85,14 +94,18 @@ public class GroupExpansionManagerImpl implements GroupExpansionManager, Dumpabl
    @Override
    public void setGroupExpanded(NotificationEntry entry, boolean expanded) {
        final NotificationEntry groupSummary = mGroupMembershipManager.getGroupSummary(entry);
        boolean changed;
        if (expanded) {
            mExpandedGroups.add(groupSummary);
            changed = mExpandedGroups.add(groupSummary);
        } else {
            mExpandedGroups.remove(groupSummary);
            changed = mExpandedGroups.remove(groupSummary);
        }

        // Only notify listeners if something changed.
        if (!mFeatureFlags.isEnabled(Flags.NOTIFICATION_GROUP_EXPANSION_CHANGE) || changed) {
            sendOnGroupExpandedChange(entry, expanded);
        }
    }

    @Override
    public boolean toggleGroupExpansion(NotificationEntry entry) {
+87 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.collection.render

import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.dump.DumpManager
import com.android.systemui.flags.FakeFeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder
import com.android.systemui.util.mockito.mock
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito.`when` as whenever

@SmallTest
class GroupExpansionManagerTest : SysuiTestCase() {
    private lateinit var gem: GroupExpansionManagerImpl

    private val dumpManager: DumpManager = mock()
    private val groupMembershipManager: GroupMembershipManager = mock()
    private val featureFlags = FakeFeatureFlags()

    private val entry1 = NotificationEntryBuilder().build()
    private val entry2 = NotificationEntryBuilder().build()

    @Before
    fun setUp() {
        whenever(groupMembershipManager.getGroupSummary(entry1)).thenReturn(entry1)
        whenever(groupMembershipManager.getGroupSummary(entry2)).thenReturn(entry2)

        gem = GroupExpansionManagerImpl(dumpManager, groupMembershipManager, featureFlags)
    }

    @Test
    fun testNotifyOnlyOnChange_enabled() {
        featureFlags.set(Flags.NOTIFICATION_GROUP_EXPANSION_CHANGE, true)

        var listenerCalledCount = 0
        gem.registerGroupExpansionChangeListener { _, _ -> listenerCalledCount++ }

        gem.setGroupExpanded(entry1, false)
        Assert.assertEquals(0, listenerCalledCount)
        gem.setGroupExpanded(entry1, true)
        Assert.assertEquals(1, listenerCalledCount)
        gem.setGroupExpanded(entry2, true)
        Assert.assertEquals(2, listenerCalledCount)
        gem.setGroupExpanded(entry1, true)
        Assert.assertEquals(2, listenerCalledCount)
        gem.setGroupExpanded(entry2, false)
        Assert.assertEquals(3, listenerCalledCount)
    }

    @Test
    fun testNotifyOnlyOnChange_disabled() {
        featureFlags.set(Flags.NOTIFICATION_GROUP_EXPANSION_CHANGE, false)

        var listenerCalledCount = 0
        gem.registerGroupExpansionChangeListener { _, _ -> listenerCalledCount++ }

        gem.setGroupExpanded(entry1, false)
        Assert.assertEquals(1, listenerCalledCount)
        gem.setGroupExpanded(entry1, true)
        Assert.assertEquals(2, listenerCalledCount)
        gem.setGroupExpanded(entry2, true)
        Assert.assertEquals(3, listenerCalledCount)
        gem.setGroupExpanded(entry1, true)
        Assert.assertEquals(4, listenerCalledCount)
        gem.setGroupExpanded(entry2, false)
        Assert.assertEquals(5, listenerCalledCount)
    }
}