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

Commit ae96d18c authored by Jeff DeCew's avatar Jeff DeCew Committed by Android (Google) Code Review
Browse files

Merge changes If09440d2,Ida7330fd into main

* changes:
  Add RowAlertTimeCoordinator to ensure group summaries have an alerting bell
  Set the correct when value for the public view of groups; reset when no longer a group.
parents 5ae5a4ca f3007b81
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ class NotifCoordinatorsImpl @Inject constructor(
        mediaCoordinator: MediaCoordinator,
        preparationCoordinator: PreparationCoordinator,
        remoteInputCoordinator: RemoteInputCoordinator,
        rowAlertTimeCoordinator: RowAlertTimeCoordinator,
        rowAppearanceCoordinator: RowAppearanceCoordinator,
        stackCoordinator: StackCoordinator,
        shadeEventCoordinator: ShadeEventCoordinator,
@@ -69,9 +70,7 @@ class NotifCoordinatorsImpl @Inject constructor(
    private val mCoordinators: MutableList<Coordinator> = ArrayList()
    private val mOrderedSections: MutableList<NotifSectioner> = ArrayList()

    /**
     * Creates all the coordinators.
     */
    /** Creates all the coordinators. */
    init {
        // Attach core coordinators.
        mCoreCoordinators.add(dataStoreCoordinator)
@@ -89,6 +88,7 @@ class NotifCoordinatorsImpl @Inject constructor(
        mCoordinators.add(groupCountCoordinator)
        mCoordinators.add(groupWhenCoordinator)
        mCoordinators.add(mediaCoordinator)
        mCoordinators.add(rowAlertTimeCoordinator)
        mCoordinators.add(rowAppearanceCoordinator)
        mCoordinators.add(stackCoordinator)
        mCoordinators.add(shadeEventCoordinator)
+61 −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.collection.coordinator

import android.util.ArrayMap
import com.android.systemui.statusbar.notification.collection.GroupEntry
import com.android.systemui.statusbar.notification.collection.ListEntry
import com.android.systemui.statusbar.notification.collection.NotifPipeline
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorScope
import com.android.systemui.statusbar.notification.collection.render.NotifRowController
import javax.inject.Inject
import kotlin.math.max

/**
 * A small coordinator which ensures the "alerted" bell shows not just for recently alerted entries,
 * but also on the summary for every such entry.
 */
@CoordinatorScope
class RowAlertTimeCoordinator @Inject constructor() : Coordinator {

    private val latestAlertTimeBySummary = ArrayMap<NotificationEntry, Long>()

    override fun attach(pipeline: NotifPipeline) {
        pipeline.addOnBeforeFinalizeFilterListener(::onBeforeFinalizeFilterListener)
        pipeline.addOnAfterRenderEntryListener(::onAfterRenderEntry)
    }

    private fun onBeforeFinalizeFilterListener(entries: List<ListEntry>) {
        latestAlertTimeBySummary.clear()
        entries.asSequence().filterIsInstance<GroupEntry>().forEach { groupEntry ->
            val summary = checkNotNull(groupEntry.summary)
            latestAlertTimeBySummary[summary] = groupEntry.calculateLatestAlertTime()
        }
    }

    private fun onAfterRenderEntry(entry: NotificationEntry, controller: NotifRowController) {
        // Show the "alerted" bell icon based on the latest group member for summaries
        val lastAudiblyAlerted = latestAlertTimeBySummary[entry] ?: entry.lastAudiblyAlertedMs
        controller.setLastAudibleMs(lastAudiblyAlerted)
    }

    private fun GroupEntry.calculateLatestAlertTime(): Long {
        val lastChildAlertedTime = children.maxOf { it.lastAudiblyAlertedMs }
        val summaryAlertedTime = checkNotNull(summary).lastAudiblyAlertedMs
        return max(lastChildAlertedTime, summaryAlertedTime)
    }
}
+0 −2
Original line number Diff line number Diff line
@@ -75,7 +75,5 @@ class RowAppearanceCoordinator @Inject internal constructor(
                (mAutoExpandFirstNotification && entry == entryToExpand))
        // Show/hide the feedback icon
        controller.setFeedbackIcon(mAssistantFeedbackController.getFeedbackIcon(entry))
        // Show the "alerted" bell icon
        controller.setLastAudibleMs(entry.lastAudiblyAlertedMs)
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -849,6 +849,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    public void setNotificationGroupWhen(long whenMillis) {
        if (mIsSummaryWithChildren) {
            mChildrenContainer.setNotificationGroupWhen(whenMillis);
            mPublicLayout.setNotificationWhen(whenMillis);
        } else {
            Log.w(TAG, "setNotificationGroupWhen( whenMillis: " + whenMillis + ")"
                    + " mIsSummaryWithChildren: false"
@@ -2704,6 +2705,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    }

    private void onAttachedChildrenCountChanged() {
        final boolean wasSummary = mIsSummaryWithChildren;
        mIsSummaryWithChildren = mChildrenContainer != null
                && mChildrenContainer.getNotificationChildCount() > 0;
        if (mIsSummaryWithChildren) {
@@ -2714,6 +2716,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
                        isConversation());
            }
        }
        if (!mIsSummaryWithChildren && wasSummary) {
            // Reset the 'when' once the row stops being a summary
            mPublicLayout.setNotificationWhen(mEntry.getSbn().getNotification().when);
        }
        getShowingLayout().updateBackgroundColor(false /* animate */);
        mPrivateLayout.updateExpandButtons(isExpandable());
        updateChildrenAppearance();
+8 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import com.android.systemui.statusbar.notification.collection.render.GroupMember
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier;
import com.android.systemui.statusbar.notification.row.shared.AsyncHybridViewInflation;
import com.android.systemui.statusbar.notification.row.wrapper.NotificationCustomViewWrapper;
import com.android.systemui.statusbar.notification.row.wrapper.NotificationHeaderViewWrapper;
import com.android.systemui.statusbar.notification.row.wrapper.NotificationViewWrapper;
import com.android.systemui.statusbar.policy.InflatedSmartReplyState;
import com.android.systemui.statusbar.policy.InflatedSmartReplyViewHolder;
@@ -2314,6 +2315,13 @@ public class NotificationContentView extends FrameLayout implements Notification
        return false;
    }

    public void setNotificationWhen(long whenMillis) {
        NotificationViewWrapper wrapper = getNotificationViewWrapper();
        if (wrapper instanceof NotificationHeaderViewWrapper headerViewWrapper) {
            headerViewWrapper.setNotificationWhen(whenMillis);
        }
    }

    private static class RemoteInputViewData {
        @Nullable RemoteInputView mView;
        @Nullable RemoteInputViewController mController;
Loading