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

Commit 27d01a62 authored by Jason Monk's avatar Jason Monk
Browse files

Start using some dagger 2

Early days as we start migration, so lots of duplication between
Dependency and dagger2, but can be removed when migration is done.

Test: existing tests.
Change-Id: I00c3da6ebbd46a26e512d8a7aa1e2b828e08f33f
parent 2ec8b910
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -80,4 +80,5 @@ android_app {
        "com.android.keyguard",
    ],

    annotation_processors: ["dagger2-compiler-2.19"],
}
+42 −10
Original line number Diff line number Diff line
@@ -17,25 +17,42 @@
package com.android.systemui;

import android.content.Context;
import android.util.ArrayMap;

import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.ViewMediatorCallback;
import com.android.systemui.Dependency.DependencyProvider;
import com.android.systemui.car.CarNotificationEntryManager;
import com.android.systemui.statusbar.car.CarFacetButtonController;
import com.android.systemui.statusbar.car.CarStatusBarKeyguardViewManager;
import com.android.systemui.statusbar.car.hvac.HvacController;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.volume.CarVolumeDialogComponent;
import com.android.systemui.volume.VolumeDialogComponent;

import javax.inject.Singleton;

import dagger.Component;
import dagger.Module;
import dagger.Provides;

/**
 * Class factory to provide car specific SystemUI components.
 */
public class CarSystemUIFactory extends SystemUIFactory {

    private CarDependencyComponent mCarDependencyComponent;

    @Override
    protected void init(Context context) {
        super.init(context);
        mCarDependencyComponent = DaggerCarSystemUIFactory_CarDependencyComponent.builder()
                .contextHolder(new ContextHolder(context))
                .build();
    }

    public CarDependencyComponent getCarDependencyComponent() {
        return mCarDependencyComponent;
    }

    public StatusBarKeyguardViewManager createStatusBarKeyguardViewManager(Context context,
        ViewMediatorCallback viewMediatorCallback, LockPatternUtils lockPatternUtils) {
        return new CarStatusBarKeyguardViewManager(context, viewMediatorCallback, lockPatternUtils);
@@ -46,12 +63,27 @@ public class CarSystemUIFactory extends SystemUIFactory {
    }

    @Override
    public void injectDependencies(ArrayMap<Object, DependencyProvider> providers,
        Context context) {
        super.injectDependencies(providers, context);
        providers.put(NotificationEntryManager.class,
            () -> new CarNotificationEntryManager(context));
        providers.put(CarFacetButtonController.class, () -> new CarFacetButtonController(context));
        providers.put(HvacController.class, () -> new HvacController(context));
    public NotificationEntryManager provideNotificationEntryManager(Context context) {
        return new CarNotificationEntryManager(context);
    }

    @Module
    protected static class ContextHolder {
        private Context mContext;

        public ContextHolder(Context context) {
            mContext = context;
        }

        @Provides
        public Context provideContext() {
            return mContext;
        }
    }

    @Singleton
    @Component(modules = ContextHolder.class)
    public interface CarDependencyComponent {
        CarFacetButtonController getCarFacetButtonController();
    }
}
+5 −3
Original line number Diff line number Diff line
@@ -26,8 +26,9 @@ import android.widget.ImageView;
import android.widget.LinearLayout;

import com.android.keyguard.AlphaOptimizedImageButton;
import com.android.systemui.Dependency;
import com.android.systemui.CarSystemUIFactory;
import com.android.systemui.R;
import com.android.systemui.SystemUIFactory;

/**
 * CarFacetButton is a ui component designed to be used as a shortcut for an app of a defined
@@ -76,8 +77,9 @@ public class CarFacetButton extends LinearLayout {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CarFacetButton);
        setupIntents(typedArray);
        setupIcons(typedArray);
        CarFacetButtonController carFacetButtonController = Dependency.get(
                CarFacetButtonController.class);
        CarSystemUIFactory factory = SystemUIFactory.getInstance();
        CarFacetButtonController carFacetButtonController = factory.getCarDependencyComponent()
                .getCarFacetButtonController();
        carFacetButtonController.addFacetButton(this);
    }

+5 −0
Original line number Diff line number Diff line
@@ -29,11 +29,15 @@ import java.util.HashMap;
import java.util.List;
import java.util.Set;

import javax.inject.Inject;
import javax.inject.Singleton;

/**
 * CarFacetButtons placed on the nav bar are designed to have visual indication that the active
 * application on screen is associated with it. This is basically a similar concept to a radio
 * button group.
 */
@Singleton
public class CarFacetButtonController {

    protected HashMap<String, CarFacetButton> mButtonsByCategory = new HashMap<>();
@@ -42,6 +46,7 @@ public class CarFacetButtonController {
    protected CarFacetButton mSelectedFacetButton;
    protected Context mContext;

    @Inject
    public CarFacetButtonController(Context context) {
        mContext = context;
    }
+6 −2
Original line number Diff line number Diff line
@@ -29,9 +29,11 @@ import android.view.WindowManager;

import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.BatteryMeterView;
import com.android.systemui.CarSystemUIFactory;
import com.android.systemui.Dependency;
import com.android.systemui.Prefs;
import com.android.systemui.R;
import com.android.systemui.SystemUIFactory;
import com.android.systemui.classifier.FalsingLog;
import com.android.systemui.classifier.FalsingManager;
import com.android.systemui.fragments.FragmentHostManager;
@@ -102,7 +104,9 @@ public class CarStatusBar extends StatusBar implements

        mHvacController.connectToCarService();

        mCarFacetButtonController = Dependency.get(CarFacetButtonController.class);
        CarSystemUIFactory factory = SystemUIFactory.getInstance();
        mCarFacetButtonController = factory.getCarDependencyComponent()
                .getCarFacetButtonController();
        mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class);
        mDeviceIsProvisioned = mDeviceProvisionedController.isDeviceProvisioned();
        if (!mDeviceIsProvisioned) {
@@ -239,7 +243,7 @@ public class CarStatusBar extends StatusBar implements
    @Override
    protected void makeStatusBarView() {
        super.makeStatusBarView();
        mHvacController = Dependency.get(HvacController.class);
        mHvacController = new HvacController(mContext);

        mNotificationPanelBackground = getDefaultWallpaper();
        mScrimController.setScrimBehindDrawable(mNotificationPanelBackground);
Loading