summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Dave Mankoff <mankoff@google.com> 2020-08-05 16:51:59 -0400
committer Dave Mankoff <mankoff@google.com> 2020-08-11 10:06:44 -0400
commit4f548215943d08e3d8b79cc67e25815802cb93e4 (patch)
tree0bc8a3add79de0f50acd4d0cfb0e72d810de19ca
parenteea2eeddd5cff033a95cce3044b001bf6e227987 (diff)
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
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java4
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java10
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java77
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java4
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java4
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java4
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java5
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java5
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationShadeWindowViewTest.java4
11 files changed, 48 insertions, 78 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
index 1db2e32b8cdb..5f00a591860e 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
@@ -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,
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java b/packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java
index 6eda21136f92..4d985c771828 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java
@@ -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.
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
index 75f4809d752f..d55ac7c7fc4b 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
@@ -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);
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java
index 83c95b77b716..ab41afb5a831 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java
@@ -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);
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java b/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java
index 493f0c1558e9..c82b39af4ab3 100644
--- a/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java
+++ b/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java
@@ -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);
- }
-
- /**
- * 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 {
+
+ /** Factory for creating a ViewInstanceCreator. */
+ @Subcomponent.Factory
+ interface Factory {
+ ViewInstanceCreator build(
+ @BindsInstance @Named(VIEW_CONTEXT) Context context,
+ @BindsInstance AttributeSet attributeSet);
+ }
+
/**
* 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) {
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java
index 4c0762e4ea32..0d52e4fefd3e 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java
@@ -79,7 +79,9 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
.thenReturn(mMockKeyguardSliceView);
InjectionInflationController inflationController = new InjectionInflationController(
- SystemUIFactory.getInstance().getRootComponent());
+ SystemUIFactory.getInstance()
+ .getRootComponent()
+ .createViewInstanceCreatorFactory());
LayoutInflater layoutInflater = inflationController
.injectable(LayoutInflater.from(getContext()));
layoutInflater.setPrivateFactory(new LayoutInflater.Factory2() {
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java
index e6c2ddcf7e65..aa4db3205d82 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java
@@ -65,7 +65,9 @@ public class KeyguardPresentationTest extends SysuiTestCase {
allowTestableLooperAsMainThread();
InjectionInflationController inflationController = new InjectionInflationController(
- SystemUIFactory.getInstance().getRootComponent());
+ SystemUIFactory.getInstance()
+ .getRootComponent()
+ .createViewInstanceCreatorFactory());
mLayoutInflater = inflationController.injectable(LayoutInflater.from(mContext));
mLayoutInflater.setPrivateFactory(new LayoutInflater.Factory2() {
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java
index bc3c3d995ce6..560d581c20e7 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java
@@ -51,7 +51,9 @@ public class KeyguardStatusViewTest extends SysuiTestCase {
allowTestableLooperAsMainThread();
mDependency.injectMockDependency(KeyguardUpdateMonitor.class);
InjectionInflationController inflationController = new InjectionInflationController(
- SystemUIFactory.getInstance().getRootComponent());
+ SystemUIFactory.getInstance()
+ .getRootComponent()
+ .createViewInstanceCreatorFactory());
LayoutInflater layoutInflater = inflationController
.injectable(LayoutInflater.from(getContext()));
mKeyguardStatusView =
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
index 90e9ef4e9c56..98a6ced91af6 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
@@ -46,6 +46,7 @@ import com.android.systemui.statusbar.phone.NavigationModeController;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.util.DeviceConfigProxy;
import com.android.systemui.util.DeviceConfigProxyFake;
+import com.android.systemui.util.InjectionInflationController;
import com.android.systemui.util.concurrency.FakeExecutor;
import com.android.systemui.util.time.FakeSystemClock;
@@ -71,6 +72,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
private @Mock PowerManager mPowerManager;
private @Mock TrustManager mTrustManager;
private @Mock NavigationModeController mNavigationModeController;
+ private @Mock InjectionInflationController mInjectionInflationController;
private DeviceConfigProxy mDeviceConfig = new DeviceConfigProxyFake();
private FakeExecutor mUiBgExecutor = new FakeExecutor(new FakeSystemClock());
@@ -88,7 +90,8 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
mContext, mFalsingManager, mLockPatternUtils, mBroadcastDispatcher,
() -> mStatusBarKeyguardViewManager,
mDismissCallbackRegistry, mUpdateMonitor, mDumpManager, mUiBgExecutor,
- mPowerManager, mTrustManager, mDeviceConfig, mNavigationModeController);
+ mPowerManager, mTrustManager, mDeviceConfig, mNavigationModeController,
+ mInjectionInflationController);
mViewMediator.start();
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java
index d338cbf51fb5..9922d3620a57 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java
@@ -150,7 +150,10 @@ public class QSFragmentTest extends SysuiBaseFragmentTest {
return new QSFragment(
new RemoteInputQuickSettingsDisabler(context, mock(ConfigurationController.class),
commandQueue),
- new InjectionInflationController(SystemUIFactory.getInstance().getRootComponent()),
+ new InjectionInflationController(
+ SystemUIFactory.getInstance()
+ .getRootComponent()
+ .createViewInstanceCreatorFactory()),
mock(QSTileHost.class),
mock(StatusBarStateController.class),
commandQueue,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationShadeWindowViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationShadeWindowViewTest.java
index e04d25b17c71..51900cb7dda1 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationShadeWindowViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationShadeWindowViewTest.java
@@ -100,7 +100,9 @@ public class NotificationShadeWindowViewTest extends SysuiTestCase {
mController = new NotificationShadeWindowViewController(
new InjectionInflationController(
- SystemUIFactory.getInstance().getRootComponent()),
+ SystemUIFactory.getInstance()
+ .getRootComponent()
+ .createViewInstanceCreatorFactory()),
mCoordinator,
mPulseExpansionHandler,
mDynamicPrivacyController,