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

Commit 4f548215 authored by Dave Mankoff's avatar Dave Mankoff
Browse files

4/N Simplify InjectionInflationController.

This class used unnecessarily complex subcomponent and module
initialization.

I am simplifyhing this class in anticipation of moving a great deal
of code from the GlobalRootComponent into the SysUIRootComponent.

Bug: 162923491
Test: manual
Change-Id: I5e8808d43742925af5bdedf1bbcf6193e1527065
parent eea2eedd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -256,7 +256,7 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
        mUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
        mSpringAnimation = new SpringAnimation(this, DynamicAnimation.Y);
        mInjectionInflationController =  new InjectionInflationController(
            SystemUIFactory.getInstance().getRootComponent());
            SystemUIFactory.getInstance().getRootComponent().createViewInstanceCreatorFactory());
        mViewConfiguration = ViewConfiguration.get(context);
        mKeyguardStateController = Dependency.get(KeyguardStateController.class);
        mSecondaryLockScreenController = new AdminSecondaryLockScreenController(context, this,
+2 −2
Original line number Diff line number Diff line
@@ -120,9 +120,9 @@ public interface GlobalRootComponent {
    InitController getInitController();

    /**
     * ViewCreator generates all Views that need injection.
     * ViewInstanceCreator generates all Views that need injection.
     */
    InjectionInflationController.ViewCreator createViewCreator();
    InjectionInflationController.ViewInstanceCreator.Factory createViewInstanceCreatorFactory();

    /**
     * Whether notification long press is allowed.
+5 −5
Original line number Diff line number Diff line
@@ -85,7 +85,6 @@ import com.android.keyguard.ViewMediatorCallback;
import com.android.systemui.Dumpable;
import com.android.systemui.R;
import com.android.systemui.SystemUI;
import com.android.systemui.SystemUIFactory;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.qualifiers.UiBackground;
import com.android.systemui.dump.DumpManager;
@@ -229,6 +228,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {

    /** TrustManager for letting it know when we change visibility */
    private final TrustManager mTrustManager;
    private final InjectionInflationController mInjectionInflationController;

    /**
     * Used to keep the device awake while to ensure the keyguard finishes opening before
@@ -723,7 +723,8 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
            @UiBackground Executor uiBgExecutor, PowerManager powerManager,
            TrustManager trustManager,
            DeviceConfigProxy deviceConfig,
            NavigationModeController navigationModeController) {
            NavigationModeController navigationModeController,
            InjectionInflationController injectionInflationController) {
        super(context);
        mFalsingManager = falsingManager;
        mLockPatternUtils = lockPatternUtils;
@@ -734,6 +735,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
        mUpdateMonitor = keyguardUpdateMonitor;
        mPM = powerManager;
        mTrustManager = trustManager;
        mInjectionInflationController = injectionInflationController;
        dumpManager.registerDumpable(getClass().getName(), this);
        mDeviceConfig = deviceConfig;
        mShowHomeOverLockscreen = mDeviceConfig.getBoolean(
@@ -773,10 +775,8 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
        mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter,
                SYSTEMUI_PERMISSION, null /* scheduler */);

        InjectionInflationController injectionInflationController =
                new InjectionInflationController(SystemUIFactory.getInstance().getRootComponent());
        mKeyguardDisplayManager = new KeyguardDisplayManager(mContext,
                injectionInflationController);
                mInjectionInflationController);

        mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);

+5 −2
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.statusbar.phone.NavigationModeController;
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.util.DeviceConfigProxy;
import com.android.systemui.util.InjectionInflationController;

import java.util.concurrent.Executor;

@@ -64,7 +65,8 @@ public class KeyguardModule {
            TrustManager trustManager,
            @UiBackground Executor uiBgExecutor,
            DeviceConfigProxy deviceConfig,
            NavigationModeController navigationModeController) {
            NavigationModeController navigationModeController,
            InjectionInflationController injectionInflationController) {
        return new KeyguardViewMediator(
                context,
                falsingManager,
@@ -78,6 +80,7 @@ public class KeyguardModule {
                powerManager,
                trustManager,
                deviceConfig,
                navigationModeController);
                navigationModeController,
                injectionInflationController);
    }
}
+15 −62
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.view.View;

import com.android.keyguard.KeyguardMessageArea;
import com.android.keyguard.KeyguardSliceView;
import com.android.systemui.dagger.GlobalRootComponent;
import com.android.systemui.qs.QSFooterImpl;
import com.android.systemui.qs.QSPanel;
import com.android.systemui.qs.QuickQSPanel;
@@ -41,8 +40,7 @@ import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import dagger.BindsInstance;
import dagger.Subcomponent;

/**
@@ -53,24 +51,16 @@ import dagger.Subcomponent;
public class InjectionInflationController {

    public static final String VIEW_CONTEXT = "view_context";
    private final ViewCreator mViewCreator;
    private final ArrayMap<String, Method> mInjectionMap = new ArrayMap<>();
    private final LayoutInflater.Factory2 mFactory = new InjectionFactory();
    private final ViewInstanceCreator.Factory mViewInstanceCreatorFactory;

    @Inject
    public InjectionInflationController(GlobalRootComponent rootComponent) {
        mViewCreator = rootComponent.createViewCreator();
    public InjectionInflationController(ViewInstanceCreator.Factory viewInstanceCreatorFactory) {
        mViewInstanceCreatorFactory = viewInstanceCreatorFactory;
        initInjectionMap();
    }

    ArrayMap<String, Method> getInjectionMap() {
        return mInjectionMap;
    }

    ViewCreator getFragmentCreator() {
        return mViewCreator;
    }

    /**
     * Wraps a {@link LayoutInflater} to support creating dagger injected views.
     * See docs/dagger.md for details.
@@ -91,25 +81,19 @@ public class InjectionInflationController {
    }

    /**
     * The subcomponent of dagger that holds all views that need injection.
     * Subcomponent that actually creates injected views.
     */
    @Subcomponent
    public interface ViewCreator {
        /**
         * Creates another subcomponent to actually generate the view.
         */
        ViewInstanceCreator createInstanceCreator(ViewAttributeProvider attributeProvider);
    public interface ViewInstanceCreator {

        /** Factory for creating a ViewInstanceCreator. */
        @Subcomponent.Factory
        interface Factory {
            ViewInstanceCreator build(
                    @BindsInstance @Named(VIEW_CONTEXT) Context context,
                    @BindsInstance AttributeSet attributeSet);
        }

    /**
     * Secondary sub-component that actually creates the views.
     *
     * Having two subcomponents lets us hide the complexity of providing the named context
     * and AttributeSet from the GlobalRootComponent, instead we have one subcomponent that
     * creates a new ViewInstanceCreator any time we need to inflate a view.
     */
    @Subcomponent(modules = ViewAttributeProvider.class)
    public interface ViewInstanceCreator {
        /**
         * Creates the QuickStatusBarHeader.
         */
@@ -150,36 +134,6 @@ public class InjectionInflationController {
        QSCustomizer createQSCustomizer();
    }

    /**
     * Module for providing view-specific constructor objects.
     */
    @Module
    public class ViewAttributeProvider {
        private final Context mContext;
        private final AttributeSet mAttrs;

        private ViewAttributeProvider(Context context, AttributeSet attrs) {
            mContext = context;
            mAttrs = attrs;
        }

        /**
         * Provides the view-themed context (as opposed to the global sysui application context).
         */
        @Provides
        @Named(VIEW_CONTEXT)
        public Context provideContext() {
            return mContext;
        }

        /**
         * Provides the AttributeSet for the current view being inflated.
         */
        @Provides
        public AttributeSet provideAttributeSet() {
            return mAttrs;
        }
    }

    private class InjectionFactory implements LayoutInflater.Factory2 {

@@ -187,10 +141,9 @@ public class InjectionInflationController {
        public View onCreateView(String name, Context context, AttributeSet attrs) {
            Method creationMethod = mInjectionMap.get(name);
            if (creationMethod != null) {
                ViewAttributeProvider provider = new ViewAttributeProvider(context, attrs);
                try {
                    return (View) creationMethod.invoke(
                            mViewCreator.createInstanceCreator(provider));
                            mViewInstanceCreatorFactory.build(context, attrs));
                } catch (IllegalAccessException e) {
                    throw new InflateException("Could not inflate " + name, e);
                } catch (InvocationTargetException e) {
Loading