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

Commit 25499523 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Pod] Don't directly use SystemClockImpl in SysUI code." into main

parents c47f1e1d 6d287373
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import com.android.systemui.Dumpable
import com.android.systemui.util.asIndenting
import com.android.systemui.util.printCollection
import com.android.systemui.util.time.SystemClock
import com.android.systemui.util.time.SystemClockImpl
import com.android.systemui.util.withIncreasedIndent
import java.io.PrintWriter
import java.util.concurrent.ConcurrentHashMap
@@ -43,7 +42,7 @@ import java.util.concurrent.atomic.AtomicInteger
class NotifCollectionCache<V>(
    private val retainCount: Int = 1,
    private val purgeTimeoutMillis: Long = 1000L,
    private val systemClock: SystemClock = SystemClockImpl(),
    private val systemClock: SystemClock,
) : Dumpable {
    @get:VisibleForTesting val cache = ConcurrentHashMap<String, CacheEntry>()

+8 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.systemui.dump.DumpManager
import com.android.systemui.shade.ShadeDisplayAware
import com.android.systemui.statusbar.notification.collection.NotifCollectionCache
import com.android.systemui.util.asIndenting
import com.android.systemui.util.time.SystemClock
import com.android.systemui.util.withIncreasedIndent
import dagger.Module
import dagger.Provides
@@ -87,8 +88,11 @@ interface AppIconProvider {
@SysUISingleton
class AppIconProviderImpl
@Inject
constructor(@ShadeDisplayAware private val sysuiContext: Context, dumpManager: DumpManager) :
    AppIconProvider, Dumpable {
constructor(
    @ShadeDisplayAware private val sysuiContext: Context,
    dumpManager: DumpManager,
    systemClock: SystemClock,
) : AppIconProvider, Dumpable {
    init {
        dumpManager.registerNormalDumpable(TAG, this)
    }
@@ -151,9 +155,9 @@ constructor(@ShadeDisplayAware private val sysuiContext: Context, dumpManager: D
    private val skeletonIconFactory: BaseIconFactory
        get() = SkeletonNotificationIcons(sysuiContext, densityDpi, iconSize)

    private val cache = NotifCollectionCache<Drawable>()
    private val cache = NotifCollectionCache<Drawable>(systemClock = systemClock)

    private val skeletonCache = NotifCollectionCache<Drawable>()
    private val skeletonCache = NotifCollectionCache<Drawable>(systemClock = systemClock)

    override fun getOrFetchAppIcon(
        packageName: String,
+7 −3
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dump.DumpManager
import com.android.systemui.statusbar.notification.collection.NotifCollectionCache
import com.android.systemui.util.asIndenting
import com.android.systemui.util.time.SystemClock
import com.android.systemui.util.withIncreasedIndent
import dagger.Module
import dagger.Provides
@@ -64,13 +65,16 @@ interface NotificationIconStyleProvider {
@SysUISingleton
class NotificationIconStyleProviderImpl
@Inject
constructor(private val userManager: UserManager, dumpManager: DumpManager) :
    NotificationIconStyleProvider, Dumpable {
constructor(
    private val userManager: UserManager,
    dumpManager: DumpManager,
    systemClock: SystemClock,
) : NotificationIconStyleProvider, Dumpable {
    init {
        dumpManager.registerNormalDumpable(TAG, this)
    }

    private val cache = NotifCollectionCache<Boolean>()
    private val cache = NotifCollectionCache<Boolean>(systemClock = systemClock)

    override fun shouldShowAppIcon(notification: StatusBarNotification, context: Context): Boolean {
        return cache.getOrFetch(notification.packageName) {
+3 −1
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import com.android.systemui.statusbar.notification.stack.ui.viewmodel.Notificati
import com.android.systemui.statusbar.notification.ui.viewbinder.HeadsUpNotificationViewBinder
import com.android.systemui.util.kotlin.awaitCancellationThenDispose
import com.android.systemui.util.kotlin.getOrNull
import com.android.systemui.util.time.SystemClock
import com.android.systemui.util.ui.isAnimating
import com.android.systemui.util.ui.stopAnimating
import com.android.systemui.util.ui.value
@@ -86,6 +87,7 @@ constructor(
    private val notificationActivityStarter: Provider<NotificationActivityStarter>,
    @SilentHeader private val silentHeaderController: SectionHeaderController,
    private val viewModel: NotificationListViewModel,
    private val systemClock: SystemClock,
) {

    fun bindWhileAttached(
@@ -303,7 +305,7 @@ constructor(
        if (NotificationsLiveDataStoreRefactor.isEnabled) {
            viewModel.logger.getOrNull()?.let { viewModel ->
                loggerOptional.getOrNull()?.let { logger ->
                    NotificationStatsLoggerBinder.bindLogger(view, logger, viewModel)
                    NotificationStatsLoggerBinder.bindLogger(view, logger, viewModel, systemClock)
                }
            }
        }
+5 −5
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.systemui.statusbar.notification.stack.ui.viewmodel.Notificati
import com.android.systemui.util.kotlin.Utils
import com.android.systemui.util.kotlin.sample
import com.android.systemui.util.kotlin.throttle
import com.android.systemui.util.time.SystemClock
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
@@ -40,13 +41,14 @@ object NotificationStatsLoggerBinder {
        view: NotificationStackScrollLayout,
        logger: NotificationStatsLogger,
        viewModel: NotificationLoggerViewModel,
        systemClock: SystemClock,
    ) {
        // Updates the logger about whether the Notification panel, and the individual Notifications
        // are visible to the user.
        viewModel.isLockscreenOrShadeInteractive
            .sample(
                combine(viewModel.isOnLockScreen, viewModel.activeNotifications, ::Pair),
                Utils.Companion::toTriple
                Utils.Companion::toTriple,
            )
            .collectLatest { (isPanelInteractive, isOnLockScreen, notifications) ->
                if (isPanelInteractive) {
@@ -58,15 +60,13 @@ object NotificationStatsLoggerBinder {
                        // Delay the updates with [NOTIFICATION_UPDATE_PERIOD_MS]. If the original
                        // flow emits more than once during this period, only the latest value is
                        // emitted, meaning that we won't log the intermediate Notification states.
                        .throttle(NOTIFICATION_UPDATE_PERIOD_MS)
                        .throttle(NOTIFICATION_UPDATE_PERIOD_MS, clock = systemClock)
                        .sample(viewModel.activeNotificationRanks, ::Pair)
                        .collect { (locationsProvider, ranks) ->
                            logger.onNotificationLocationsChanged(locationsProvider, ranks)
                        }
                } else {
                    logger.onLockscreenOrShadeNotInteractive(
                        activeNotifications = notifications,
                    )
                    logger.onLockscreenOrShadeNotInteractive(activeNotifications = notifications)
                }
            }
    }
Loading