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

Commit d1ca03fe authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[Pod] Make SystemClock a @Singleton, pull into separate Dagger module

For pods, we want to ensure all production code only references
interfaces, not implementations. The last use of SystemClockImpl in
production code in AOSP was in UnfoldTransitionModule, so this CL
changes that to SystemClock.

But to do that, SystemClock has to become an @Singleton instead of an
@SysUISingleton because UnfoldTransitionModule is part of GlobalModule,
not SystemUIModule.

Bug: 307607958
Flag: EXEMPT build change
Test: mp sysuig, verify LogBuffers & other classes still have the right
time
Test: verify via logging only one SystemClockImpl is created for AOSP
classes

Change-Id: Ib1f7f5648b44ad695a963ea931f1c959e20d6715
parent 400a3513
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.plugins.PluginsModule;
import com.android.systemui.unfold.UnfoldTransitionModule;
import com.android.systemui.util.concurrency.GlobalConcurrencyModule;
import com.android.systemui.util.kotlin.GlobalCoroutinesModule;
import com.android.systemui.util.time.dagger.TimeModule;

import dagger.Module;
import dagger.Provides;
@@ -52,6 +53,7 @@ import dagger.Provides;
        GlobalCoroutinesModule.class,
        UnfoldTransitionModule.class,
        PluginsModule.class,
        TimeModule.class,
})
public class GlobalModule {
    /**
+0 −6
Original line number Diff line number Diff line
@@ -176,8 +176,6 @@ import com.android.systemui.util.reference.ReferenceModule;
import com.android.systemui.util.sensors.SensorModule;
import com.android.systemui.util.settings.SettingsProxy;
import com.android.systemui.util.settings.SettingsUtilModule;
import com.android.systemui.util.time.SystemClock;
import com.android.systemui.util.time.SystemClockImpl;
import com.android.systemui.wallet.dagger.WalletModule;
import com.android.systemui.wmshell.BubblesManager;
import com.android.wm.shell.bubbles.Bubbles;
@@ -409,10 +407,6 @@ public abstract class SystemUIModule {
    abstract Optional<DeviceStateRotationLockSettingController>
            optionalDeviceStateRotationLockSettingController();

    @SysUISingleton
    @Binds
    abstract SystemClock bindSystemClock(SystemClockImpl systemClock);

    // TODO: This should provided by the WM component

    /** Provides Optional of BubbleManager */
+9 −9
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ import com.android.systemui.unfold.util.NaturalRotationUnfoldProgressProvider
import com.android.systemui.unfold.util.ScopedUnfoldTransitionProgressProvider
import com.android.systemui.unfold.util.UnfoldOnlyProgressProvider
import com.android.systemui.unfold.util.UnfoldTransitionATracePrefix
import com.android.systemui.util.time.SystemClockImpl
import com.android.systemui.util.time.SystemClock
import com.android.wm.shell.unfold.ShellUnfoldProgressProvider
import dagger.Binds
import dagger.Lazy
@@ -60,7 +60,7 @@ import javax.inject.Singleton
        [
            UnfoldSharedModule::class,
            SystemUnfoldSharedModule::class,
            UnfoldTransitionModule.Bindings::class
            UnfoldTransitionModule.Bindings::class,
        ]
)
class UnfoldTransitionModule {
@@ -78,7 +78,7 @@ class UnfoldTransitionModule {
    fun providesFoldStateListener(
        deviceStateManager: DeviceStateManager,
        @Application context: Context,
        @Main executor: Executor
        @Main executor: Executor,
    ): DeviceStateManager.FoldStateListener {
        val listener = DeviceStateManager.FoldStateListener(context)
        deviceStateManager.registerCallback(executor, listener)
@@ -90,10 +90,11 @@ class UnfoldTransitionModule {
    @Singleton
    fun providesFoldStateLoggingProvider(
        config: UnfoldTransitionConfig,
        foldStateProvider: Lazy<FoldStateProvider>
        foldStateProvider: Lazy<FoldStateProvider>,
        systemClock: SystemClock,
    ): Optional<FoldStateLoggingProvider> =
        if (config.isHingeAngleEnabled) {
            Optional.of(FoldStateLoggingProviderImpl(foldStateProvider.get(), SystemClockImpl()))
            Optional.of(FoldStateLoggingProviderImpl(foldStateProvider.get(), systemClock))
        } else {
            Optional.empty()
        }
@@ -112,7 +113,7 @@ class UnfoldTransitionModule {
    fun provideNaturalRotationProgressProvider(
        context: Context,
        @UnfoldMain rotationChangeProvider: RotationChangeProvider,
        unfoldTransitionProgressProvider: Optional<UnfoldTransitionProgressProvider>
        unfoldTransitionProgressProvider: Optional<UnfoldTransitionProgressProvider>,
    ): Optional<NaturalRotationUnfoldProgressProvider> =
        unfoldTransitionProgressProvider.map { provider ->
            NaturalRotationUnfoldProgressProvider(context, rotationChangeProvider, provider)
@@ -145,7 +146,7 @@ class UnfoldTransitionModule {
        foldProvider: FoldProvider,
        provider: Provider<Optional<UnfoldTransitionProgressProvider>>,
        @Named(UNFOLD_ONLY_PROVIDER)
        unfoldOnlyProvider: Provider<Optional<UnfoldTransitionProgressProvider>>
        unfoldOnlyProvider: Provider<Optional<UnfoldTransitionProgressProvider>>,
    ): ShellUnfoldProgressProvider {
        val resultingProvider =
            if (config.isEnabled) {
@@ -162,8 +163,7 @@ class UnfoldTransitionModule {

        return resultingProvider?.get()?.orElse(null)?.let { unfoldProgressProvider ->
            UnfoldProgressProvider(unfoldProgressProvider, foldProvider)
        }
            ?: ShellUnfoldProgressProvider.NO_PROVIDER
        } ?: ShellUnfoldProgressProvider.NO_PROVIDER
    }

    @Provides
+28 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.util.time.dagger

import com.android.systemui.util.time.SystemClock
import com.android.systemui.util.time.SystemClockImpl
import dagger.Binds
import dagger.Module
import javax.inject.Singleton

@Module
public abstract class TimeModule {
    @Singleton @Binds public abstract fun bindSystemClock(impl: SystemClockImpl): SystemClock
}