From 0106a9f1b48adbbe4c7094e7ff1c8dfbefe7ed13 Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Mon, 8 Nov 2021 17:04:10 -0800 Subject: [PATCH] Load CommunalSource.Connector from config. This changelist moves CommunalSource.Connector dependencies behind a multi-binding provider. The selected connector is based on a configuration, which specifies the fully qualified class. Test: manual Bug: 205600269 Change-Id: I289800da19839897c57ae5205d76115fa3367468 --- packages/SystemUI/res/values/config.xml | 4 ++ .../communal/dagger/CommunalModule.java | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index ff748a982b33b..df8fc22827b1a 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -742,4 +742,8 @@ false + + + + diff --git a/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.java b/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.java index fca842ade7bb2..a0986660ebdca 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.java +++ b/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.java @@ -23,6 +23,8 @@ import android.text.TextUtils; import android.view.View; import android.widget.FrameLayout; +import androidx.annotation.Nullable; + import com.android.systemui.R; import com.android.systemui.communal.CommunalSource; import com.android.systemui.communal.PackageObserver; @@ -35,15 +37,19 @@ import com.android.systemui.idle.dagger.IdleViewComponent; import java.util.Collections; import java.util.HashSet; +import java.util.Map; import java.util.Optional; import java.util.Set; import javax.inject.Named; +import javax.inject.Provider; import dagger.Binds; import dagger.Module; import dagger.Provides; import dagger.multibindings.ElementsIntoSet; +import dagger.multibindings.IntoMap; +import dagger.multibindings.StringKey; /** * Dagger Module providing Communal-related functionality. @@ -97,4 +103,36 @@ public interface CommunalModule { CommunalSettingCondition communalSettingCondition) { return new HashSet<>(Collections.singletonList(communalSettingCondition)); } + + /** + * TODO(b/205638389): Remove when there is a base implementation of + * {@link CommunalSource.Connector}. Currently a place holder to allow a map to be present. + */ + @Provides + @IntoMap + @Nullable + @StringKey("empty") + static CommunalSource.Connector provideEmptyCommunalSourceConnector() { + return null; + } + + /** */ + @Provides + static Optional provideCommunalSourceConnector( + @Main Resources resources, + Map, Provider> connectorCreators) { + final String className = resources.getString(R.string.config_communalSourceConnector); + + if (TextUtils.isEmpty(className)) { + return Optional.empty(); + } + + try { + Class clazz = Class.forName(className); + Provider provider = connectorCreators.get(clazz); + return provider != null ? Optional.of(provider.get()) : Optional.empty(); + } catch (ClassNotFoundException e) { + return Optional.empty(); + } + } }