From c0fd24c02b90defae387f6c8cc53304fbd77b80f Mon Sep 17 00:00:00 2001 From: Nick Chameyev Date: Thu, 6 Jun 2024 16:16:56 +0000 Subject: Include SysUIUnfoldComponent only in phone SystemUI Change Dagger depepdencies structure to add SysUIUnfoldComponent subcomponent only in phone SystemUI modules. - SystemUIModule is included in all variants of SystemUI (e.g. for TV/Chromium/tablets/etc.) - CommonSystemUIUnfoldModule binds optional of Optional, so this dependency will be present only if the component of this specific variant has this dependency. - CommonSystemUIUnfoldModule is part of SystemUIModule, so it is also added in all variants of SystemUI. It doesn't actually contain the dependency, it's just a proxy module to unwrap optional dependency from SysUIUnfoldComponent - SysUIUnfoldComponent is provided by SysUIUnfoldModule, SysUIUnfoldModule is only added in the variants where unfold classes might be useful (e.g. phone variant of SystemUI), so this dependency will be present only in these variants of SystemUI Bug: 334100546 Test: presubmit Flag: EXEMPT bugfix Change-Id: I2e1eaee81c68dcb8cc0be6e3d6696495100691a6 --- .../systemui/dagger/CommonSystemUIUnfoldModule.kt | 53 ++++++++++++++++++++++ .../systemui/dagger/ReferenceSysUIComponent.java | 3 ++ .../android/systemui/dagger/SystemUIModule.java | 3 +- .../android/systemui/unfold/SysUIUnfoldModule.kt | 10 ++++ 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/dagger/CommonSystemUIUnfoldModule.kt diff --git a/packages/SystemUI/src/com/android/systemui/dagger/CommonSystemUIUnfoldModule.kt b/packages/SystemUI/src/com/android/systemui/dagger/CommonSystemUIUnfoldModule.kt new file mode 100644 index 000000000000..a91ce164ae7f --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/dagger/CommonSystemUIUnfoldModule.kt @@ -0,0 +1,53 @@ +/* + * 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.dagger + +import com.android.systemui.unfold.SysUIUnfoldComponent +import com.android.systemui.unfold.SysUIUnfoldModule.BoundFromSysUiUnfoldModule +import dagger.BindsOptionalOf +import dagger.Module +import dagger.Provides +import java.util.Optional +import kotlin.jvm.optionals.getOrElse + + +/** + * Module for foldable-related classes that is available in all SystemUI variants. + * Provides `Optional` which is present when the device is a foldable + * device that has fold/unfold animation enabled. + */ +@Module +abstract class CommonSystemUIUnfoldModule { + + /* Note this will be injected as @BoundFromSysUiUnfoldModule Optional> */ + @BindsOptionalOf + @BoundFromSysUiUnfoldModule + abstract fun optionalSysUiUnfoldComponent(): Optional + + companion object { + @Provides + @SysUISingleton + fun sysUiUnfoldComponent( + /** + * This will be empty when [com.android.systemui.unfold.SysUIUnfoldModule] is not part + * of the graph, and contain the optional when it is. + */ + @BoundFromSysUiUnfoldModule + optionalOfOptional: Optional> + ): Optional = optionalOfOptional.getOrElse { Optional.empty() } + } +} \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/dagger/ReferenceSysUIComponent.java b/packages/SystemUI/src/com/android/systemui/dagger/ReferenceSysUIComponent.java index a431a59fcef6..b71af69b13cb 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/ReferenceSysUIComponent.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/ReferenceSysUIComponent.java @@ -19,6 +19,7 @@ package com.android.systemui.dagger; import com.android.systemui.keyguard.CustomizationProvider; import com.android.systemui.statusbar.NotificationInsetsModule; import com.android.systemui.statusbar.QsFrameTranslateModule; +import com.android.systemui.unfold.SysUIUnfoldModule; import dagger.Subcomponent; @@ -34,6 +35,7 @@ import dagger.Subcomponent; SystemUIBinder.class, SystemUIModule.class, SystemUICoreStartableModule.class, + SysUIUnfoldModule.class, ReferenceSystemUIModule.class}) public interface ReferenceSysUIComponent extends SysUIComponent { @@ -51,3 +53,4 @@ public interface ReferenceSysUIComponent extends SysUIComponent { */ void inject(CustomizationProvider customizationProvider); } + diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java index 2ebb94f8bcf4..a7ff3c36a641 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java @@ -143,7 +143,6 @@ import com.android.systemui.statusbar.window.StatusBarWindowModule; import com.android.systemui.telephony.data.repository.TelephonyRepositoryModule; import com.android.systemui.temporarydisplay.dagger.TemporaryDisplayModule; import com.android.systemui.tuner.dagger.TunerModule; -import com.android.systemui.unfold.SysUIUnfoldModule; import com.android.systemui.user.UserModule; import com.android.systemui.user.domain.UserDomainLayerModule; import com.android.systemui.util.EventLogModule; @@ -254,7 +253,7 @@ import javax.inject.Named; SystemPropertiesFlagsModule.class, SysUIConcurrencyModule.class, SysUICoroutinesModule.class, - SysUIUnfoldModule.class, + CommonSystemUIUnfoldModule.class, TelephonyRepositoryModule.class, TemporaryDisplayModule.class, TunerModule.class, diff --git a/packages/SystemUI/src/com/android/systemui/unfold/SysUIUnfoldModule.kt b/packages/SystemUI/src/com/android/systemui/unfold/SysUIUnfoldModule.kt index 139ac7e4f687..a27989d772c4 100644 --- a/packages/SystemUI/src/com/android/systemui/unfold/SysUIUnfoldModule.kt +++ b/packages/SystemUI/src/com/android/systemui/unfold/SysUIUnfoldModule.kt @@ -36,6 +36,7 @@ import dagger.multibindings.IntoMap import dagger.multibindings.IntoSet import java.util.Optional import javax.inject.Named +import javax.inject.Qualifier import javax.inject.Scope @Scope @MustBeDocumented @Retention(AnnotationRetention.RUNTIME) annotation class SysUIUnfoldScope @@ -54,8 +55,17 @@ import javax.inject.Scope @Module(subcomponents = [SysUIUnfoldComponent::class]) class SysUIUnfoldModule { + /** + * Qualifier for dependencies bound in [com.android.systemui.unfold.SysUIUnfoldModule] + */ + @Qualifier + @MustBeDocumented + @Retention(AnnotationRetention.RUNTIME) + annotation class BoundFromSysUiUnfoldModule + @Provides @SysUISingleton + @BoundFromSysUiUnfoldModule fun provideSysUIUnfoldComponent( provider: Optional, rotationProvider: Optional, -- cgit v1.2.3-59-g8ed1b