5/N Reduce number of accessors of root component.
Ensure that only the code that actually needs the root component asks
for it.
This also fixes ContentProvider injection (a bit). They no longer have
to manually run injection on themselves, as long as they implement
SystemUIAppComponentFactory.ContextInitializer properly and define
an inject(MyClass) method in the root component.
Bug: 162923491
Test: manual && atest SystemUITests
Change-Id: I507859f5f8d89bdde5b10e78b54c5cfbf28737bc
diff --git a/packages/SystemUI/proguard.flags b/packages/SystemUI/proguard.flags
index 14097b1..f242157 100644
--- a/packages/SystemUI/proguard.flags
+++ b/packages/SystemUI/proguard.flags
@@ -41,4 +41,6 @@
public <init>(android.content.Context);
}
--keep class com.android.wm.shell.*
\ No newline at end of file
+-keep class com.android.wm.shell.*
+
+-keep class com.android.systemui.dagger.GlobalRootComponent { *; }
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIAppComponentFactory.java b/packages/SystemUI/src/com/android/systemui/SystemUIAppComponentFactory.java
index cacbf96..627f559 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIAppComponentFactory.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIAppComponentFactory.java
@@ -29,6 +29,10 @@
import androidx.core.app.AppComponentFactory;
import com.android.systemui.dagger.ContextComponentHelper;
+import com.android.systemui.dagger.GlobalRootComponent;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import javax.inject.Inject;
@@ -81,8 +85,17 @@
((ContextInitializer) contentProvider).setContextAvailableCallback(
context -> {
SystemUIFactory.createFromConfig(context);
- SystemUIFactory.getInstance().getRootComponent().inject(
- contentProvider);
+ GlobalRootComponent rootComponent =
+ SystemUIFactory.getInstance().getRootComponent();
+ try {
+ Method injectMethod = rootComponent.getClass()
+ .getMethod("inject", contentProvider.getClass());
+ injectMethod.invoke(rootComponent, contentProvider);
+ } catch (NoSuchMethodException
+ | IllegalAccessException
+ | InvocationTargetException e) {
+ // no-op
+ }
}
);
}
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java b/packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java
index 4d985c7..9c55095 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java
@@ -16,9 +16,6 @@
package com.android.systemui.dagger;
-import static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME;
-
-import android.content.ContentProvider;
import android.content.Context;
import com.android.systemui.BootCompleteCacheImpl;
@@ -26,14 +23,12 @@
import com.android.systemui.InitController;
import com.android.systemui.SystemUIAppComponentFactory;
import com.android.systemui.dump.DumpManager;
-import com.android.systemui.fragments.FragmentService;
import com.android.systemui.keyguard.KeyguardSliceProvider;
import com.android.systemui.onehanded.dagger.OneHandedModule;
import com.android.systemui.pip.phone.dagger.PipModule;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.util.InjectionInflationController;
-import javax.inject.Named;
import javax.inject.Singleton;
import dagger.BindsInstance;
@@ -107,13 +102,6 @@
DumpManager createDumpManager();
/**
- * FragmentCreator generates all Fragments that need injection.
- */
- @Singleton
- FragmentService.FragmentCreator createFragmentCreator();
-
-
- /**
* Creates a InitController.
*/
@Singleton
@@ -125,12 +113,6 @@
InjectionInflationController.ViewInstanceCreator.Factory createViewInstanceCreatorFactory();
/**
- * Whether notification long press is allowed.
- */
- @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME)
- boolean allowNotificationLongPressName();
-
- /**
* Member injection into the supplied argument.
*/
void inject(SystemUIAppComponentFactory factory);
@@ -138,10 +120,5 @@
/**
* Member injection into the supplied argument.
*/
- void inject(ContentProvider contentProvider);
-
- /**
- * Member injection into the supplied argument.
- */
void inject(KeyguardSliceProvider keyguardSliceProvider);
}
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java
index f774358..f6db6d5 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java
@@ -26,6 +26,7 @@
import com.android.systemui.assist.AssistModule;
import com.android.systemui.doze.dagger.DozeComponent;
import com.android.systemui.dump.DumpManager;
+import com.android.systemui.fragments.FragmentService;
import com.android.systemui.log.dagger.LogModule;
import com.android.systemui.model.SysUiState;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
@@ -74,7 +75,8 @@
NotificationRowComponent.class,
DozeComponent.class,
ExpandableNotificationRowComponent.class,
- NotificationShelfComponent.class})
+ NotificationShelfComponent.class,
+ FragmentService.FragmentCreator.class})
public abstract class SystemUIModule {
@Binds
diff --git a/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java b/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java
index f83699d..0507592 100644
--- a/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java
+++ b/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java
@@ -21,7 +21,6 @@
import android.view.View;
import com.android.systemui.Dumpable;
-import com.android.systemui.dagger.GlobalRootComponent;
import com.android.systemui.qs.QSFragment;
import com.android.systemui.statusbar.phone.NavigationBarFragment;
import com.android.systemui.statusbar.policy.ConfigurationController;
@@ -61,9 +60,9 @@
};
@Inject
- public FragmentService(GlobalRootComponent rootComponent,
+ public FragmentService(FragmentCreator.Factory fragmentCreatorFactory,
ConfigurationController configurationController) {
- mFragmentCreator = rootComponent.createFragmentCreator();
+ mFragmentCreator = fragmentCreatorFactory.build();
initInjectionMap();
configurationController.addCallback(mConfigurationListener);
}
@@ -121,6 +120,11 @@
*/
@Subcomponent
public interface FragmentCreator {
+ /** Factory for creating a FragmentCreator. */
+ @Subcomponent.Factory
+ interface Factory {
+ FragmentCreator build();
+ }
/**
* Inject a NavigationBarFragment.
*/
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java
index 3a37c0f..daef2c5 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java
@@ -52,7 +52,6 @@
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.SystemUIAppComponentFactory;
-import com.android.systemui.SystemUIFactory;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.statusbar.StatusBarState;
@@ -72,6 +71,9 @@
/**
* Simple Slice provider that shows the current date.
+ *
+ * Injection is handled by {@link SystemUIAppComponentFactory} +
+ * {@link com.android.systemui.dagger.GlobalRootComponent#inject(KeyguardSliceProvider)}.
*/
public class KeyguardSliceProvider extends SliceProvider implements
NextAlarmController.NextAlarmChangeCallback, ZenModeController.Callback,
@@ -298,7 +300,8 @@
@Override
public boolean onCreateSliceProvider() {
mContextAvailableCallback.onContextAvailable(getContext());
- inject();
+ mMediaWakeLock = new SettableWakeLock(WakeLock.createPartial(getContext(), "media"),
+ "media");
synchronized (KeyguardSliceProvider.sInstanceLock) {
KeyguardSliceProvider oldInstance = KeyguardSliceProvider.sInstance;
if (oldInstance != null) {
@@ -319,13 +322,6 @@
}
@VisibleForTesting
- protected void inject() {
- SystemUIFactory.getInstance().getRootComponent().inject(this);
- mMediaWakeLock = new SettableWakeLock(WakeLock.createPartial(getContext(), "media"),
- "media");
- }
-
- @VisibleForTesting
protected void onDestroy() {
synchronized (KeyguardSliceProvider.sInstanceLock) {
mNextAlarmController.removeCallback(this);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java
index 1538a32..5c86fcb 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java
@@ -211,7 +211,8 @@
when(mColorExtractor.getNeutralColors()).thenReturn(mGradientColors);
mSuperStatusBarViewFactory = new SuperStatusBarViewFactory(mContext,
- new InjectionInflationController(SystemUIFactory.getInstance().getRootComponent()),
+ new InjectionInflationController(SystemUIFactory.getInstance().getRootComponent()
+ .createViewInstanceCreatorFactory()),
new NotificationShelfComponent.Builder() {
@Override
public NotificationShelfComponent.Builder notificationShelf(
diff --git a/packages/SystemUI/tests/src/com/android/systemui/bubbles/NewNotifPipelineBubbleControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/bubbles/NewNotifPipelineBubbleControllerTest.java
index 0e7cb79..196aa65 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/bubbles/NewNotifPipelineBubbleControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/bubbles/NewNotifPipelineBubbleControllerTest.java
@@ -201,7 +201,8 @@
when(mColorExtractor.getNeutralColors()).thenReturn(mGradientColors);
mSuperStatusBarViewFactory = new SuperStatusBarViewFactory(mContext,
- new InjectionInflationController(SystemUIFactory.getInstance().getRootComponent()),
+ new InjectionInflationController(SystemUIFactory.getInstance().getRootComponent()
+ .createViewInstanceCreatorFactory()),
new NotificationShelfComponent.Builder() {
@Override
public NotificationShelfComponent.Builder notificationShelf(
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java
index f70fb4f..d1f505b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java
@@ -254,16 +254,12 @@
int mCleanDateFormatInvokations;
private int mCounter;
- Uri getUri() {
- return mSliceUri;
- }
+ TestableKeyguardSliceProvider() {
+ super();
- @Override
- protected void inject() {
mAlarmManager = KeyguardSliceProviderTest.this.mAlarmManager;
mContentResolver = KeyguardSliceProviderTest.this.mContentResolver;
mZenModeController = KeyguardSliceProviderTest.this.mZenModeController;
- mMediaWakeLock = KeyguardSliceProviderTest.this.mMediaWakeLock;
mDozeParameters = KeyguardSliceProviderTest.this.mDozeParameters;
mNextAlarmController = KeyguardSliceProviderTest.this.mNextAlarmController;
mStatusBarStateController = KeyguardSliceProviderTest.this.mStatusBarStateController;
@@ -272,6 +268,17 @@
}
@Override
+ public boolean onCreateSliceProvider() {
+ boolean result = super.onCreateSliceProvider();
+ mMediaWakeLock = KeyguardSliceProviderTest.this.mMediaWakeLock;
+ return result;
+ }
+
+ Uri getUri() {
+ return mSliceUri;
+ }
+
+ @Override
protected boolean isDndOn() {
return mIsZenMode;
}