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

Commit 0106a9f1 authored by Bryce Lee's avatar Bryce Lee
Browse files

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
parent ad587fc6
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -742,4 +742,8 @@

    <!-- Flag to enable dream overlay service and its registration -->
    <bool name="config_dreamOverlayServiceEnabled">false</bool>

    <!-- Class for the communal source connector to be used -->
    <string name="config_communalSourceConnector" translatable="false"></string>

</resources>
+38 −0
Original line number Diff line number Diff line
@@ -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<CommunalSource.Connector> provideCommunalSourceConnector(
            @Main Resources resources,
            Map<Class<?>, Provider<CommunalSource.Connector>> connectorCreators) {
        final String className = resources.getString(R.string.config_communalSourceConnector);

        if (TextUtils.isEmpty(className)) {
            return Optional.empty();
        }

        try {
            Class<?> clazz = Class.forName(className);
            Provider<CommunalSource.Connector> provider = connectorCreators.get(clazz);
            return provider != null ? Optional.of(provider.get()) : Optional.empty();
        } catch (ClassNotFoundException e) {
            return Optional.empty();
        }
    }
}