/* * 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 import com.android.internal.statusbar.NotificationVisibility import com.android.systemui.statusbar.notification.collection.notifcollection.DismissedByUserStats import com.android.systemui.statusbar.notification.shared.NotificationBundleUi /** * A holder class for a [NotificationEntry] and an associated [DismissedByUserStats], used by * [NotifCollection] for handling dismissal. */ data class EntryWithDismissStats( /** * A [NotificationEntry] associated with [stats]. Will be `null` if * [NotificationBundleUi.isEnabled], in which case [key] and [entryHashCode] should be used to * lookup the entry in [NotifCollection]. */ private val _entry: NotificationEntry?, val stats: DismissedByUserStats, val key: String, val entryHashCode: Int, ) { init { if (_entry == null) { NotificationBundleUi.isUnexpectedlyInLegacyMode() } else { NotificationBundleUi.assertInLegacyMode() } } val entry: NotificationEntry get() { NotificationBundleUi.assertInLegacyMode() return _entry!! } /** Creates deep a copy of this object, but updated to correspond to [newEntry]. */ fun copyForEntry(newEntry: NotificationEntry) = EntryWithDismissStats( _entry = if (NotificationBundleUi.isEnabled) null else newEntry, stats = DismissedByUserStats( stats.dismissalSurface, stats.dismissalSentiment, NotificationVisibility.obtain( newEntry.key, newEntry.ranking.rank, stats.notificationVisibility.count, /* visible= */ false, ), ), key = newEntry.key, entryHashCode = newEntry.hashCode(), ) }