diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java index 3c867603546a6..383c442ad1380 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java @@ -69,6 +69,7 @@ import com.android.systemui.statusbar.notification.row.dagger.NotificationShelfC import com.android.systemui.statusbar.phone.ShadeController; import com.android.systemui.statusbar.phone.StatusBar; import com.android.systemui.statusbar.phone.dagger.StatusBarComponent; +import com.android.systemui.statusbar.phone.fragment.dagger.StatusBarFragmentComponent; import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.statusbar.policy.HeadsUpManager; import com.android.systemui.statusbar.policy.ZenModeController; @@ -129,6 +130,7 @@ import dagger.Provides; }, subcomponents = { StatusBarComponent.class, + StatusBarFragmentComponent.class, NotificationRowComponent.class, DozeComponent.class, ExpandableNotificationRowComponent.class, diff --git a/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java b/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java index 4f5a969c97911..7f57fcc56117d 100644 --- a/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java +++ b/packages/SystemUI/src/com/android/systemui/fragments/FragmentService.java @@ -24,7 +24,7 @@ import com.android.systemui.Dumpable; import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dump.DumpManager; import com.android.systemui.qs.QSFragment; -import com.android.systemui.statusbar.phone.CollapsedStatusBarFragment; +import com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragment; import com.android.systemui.statusbar.policy.ConfigurationController; import java.io.FileDescriptor; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/CollapsedSbFragmentLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/CollapsedSbFragmentLog.java index c8afd72d1dde8..9ca0293fbd865 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/CollapsedSbFragmentLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/CollapsedSbFragmentLog.java @@ -26,8 +26,8 @@ import java.lang.annotation.Retention; import javax.inject.Qualifier; /** - * A {@link LogBuffer} for - * {@link com.android.systemui.statusbar.phone.CollapsedStatusBarFragment}-related messages. + * A {@link LogBuffer} for {@link + * com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragment}-related messages. */ @Qualifier @Documented diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java index 02beff9fffdb7..d3bd0a5e31a00 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java @@ -110,7 +110,7 @@ public class LogModule { /** * Provides a logging buffer for - * {@link com.android.systemui.statusbar.phone.CollapsedStatusBarFragment}. + * {@link com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragment}. */ @Provides @SysUISingleton diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSFragmentDisableFlagsLogger.kt b/packages/SystemUI/src/com/android/systemui/qs/QSFragmentDisableFlagsLogger.kt index 17a815e72583a..8544f61d70318 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSFragmentDisableFlagsLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/QSFragmentDisableFlagsLogger.kt @@ -4,7 +4,6 @@ import com.android.systemui.log.LogBuffer import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.QSFragmentDisableLog import com.android.systemui.statusbar.DisableFlagsLogger -import com.android.systemui.statusbar.phone.CollapsedStatusBarFragment import javax.inject.Inject /** A helper class for logging disable flag changes made in [QSFragment]. */ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java index 3ea9f843561b9..8a07fc02c6a56 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java @@ -182,6 +182,7 @@ import com.android.systemui.statusbar.notification.stack.NotificationStackScroll import com.android.systemui.statusbar.notification.stack.StackStateAnimator; import com.android.systemui.statusbar.phone.LockscreenGestureLogger.LockscreenUiEvent; import com.android.systemui.statusbar.phone.dagger.StatusBarComponent; +import com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragment; import com.android.systemui.statusbar.phone.panelstate.PanelExpansionStateManager; import com.android.systemui.statusbar.phone.panelstate.PanelState; import com.android.systemui.statusbar.policy.ConfigurationController; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index b47e71aaccc25..ab7951ff52098 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -137,7 +137,6 @@ import com.android.systemui.R; import com.android.systemui.animation.ActivityLaunchAnimator; import com.android.systemui.animation.DelegateLaunchAnimatorController; import com.android.systemui.assist.AssistManager; -import com.android.systemui.battery.BatteryMeterViewController; import com.android.systemui.biometrics.AuthRippleController; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.camera.CameraIntents; @@ -217,6 +216,9 @@ import com.android.systemui.statusbar.notification.stack.NotificationStackScroll import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController; import com.android.systemui.statusbar.phone.dagger.StatusBarComponent; import com.android.systemui.statusbar.phone.dagger.StatusBarPhoneModule; +import com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragment; +import com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragmentLogger; +import com.android.systemui.statusbar.phone.fragment.dagger.StatusBarFragmentComponent; import com.android.systemui.statusbar.phone.ongoingcall.OngoingCallController; import com.android.systemui.statusbar.phone.panelstate.PanelExpansionStateManager; import com.android.systemui.statusbar.policy.BatteryController; @@ -488,6 +490,7 @@ public class StatusBar extends CoreStartable implements private final DozeParameters mDozeParameters; private final Lazy mBiometricUnlockControllerLazy; private final StatusBarComponent.Factory mStatusBarComponentFactory; + private final StatusBarFragmentComponent.Factory mStatusBarFragmentComponentFactory; private final PluginManager mPluginManager; private final Optional mSplitScreenOptional; private final StatusBarNotificationActivityStarter.Builder @@ -672,7 +675,6 @@ public class StatusBar extends CoreStartable implements private final ActivityIntentHelper mActivityIntentHelper; private NotificationStackScrollLayoutController mStackScrollerController; - private BatteryMeterViewController mBatteryMeterViewController; private final ColorExtractor.OnColorsChangedListener mOnColorsChangedListener = (extractor, which) -> updateTheme(); @@ -744,6 +746,7 @@ public class StatusBar extends CoreStartable implements CommandQueue commandQueue, CollapsedStatusBarFragmentLogger collapsedStatusBarFragmentLogger, StatusBarComponent.Factory statusBarComponentFactory, + StatusBarFragmentComponent.Factory statusBarFragmentComponentFactory, PluginManager pluginManager, Optional splitScreenOptional, LightsOutNotifController lightsOutNotifController, @@ -848,6 +851,7 @@ public class StatusBar extends CoreStartable implements mCommandQueue = commandQueue; mCollapsedStatusBarFragmentLogger = collapsedStatusBarFragmentLogger; mStatusBarComponentFactory = statusBarComponentFactory; + mStatusBarFragmentComponentFactory = statusBarFragmentComponentFactory; mPluginManager = pluginManager; mSplitScreenOptional = splitScreenOptional; mStatusBarNotificationActivityStarterBuilder = statusBarNotificationActivityStarterBuilder; @@ -1134,28 +1138,21 @@ public class StatusBar extends CoreStartable implements mPluginDependencyProvider.allowPluginDependency(StatusBarStateController.class); mStatusBarWindowController.getFragmentHostManager() .addTagListener(CollapsedStatusBarFragment.TAG, (tag, fragment) -> { - CollapsedStatusBarFragment statusBarFragment = - (CollapsedStatusBarFragment) fragment; + StatusBarFragmentComponent statusBarFragmentComponent = + ((CollapsedStatusBarFragment) fragment).getStatusBarFragmentComponent(); + if (statusBarFragmentComponent == null) { + throw new IllegalStateException( + "CollapsedStatusBarFragment should have a valid component"); + } - PhoneStatusBarView oldStatusBarView = mStatusBarView; - mStatusBarView = (PhoneStatusBarView) statusBarFragment.getView(); + mStatusBarView = statusBarFragmentComponent.getPhoneStatusBarView(); + // TODO(b/205609837): Migrate this to StatusBarFragmentComponent. mPhoneStatusBarViewController = mPhoneStatusBarViewControllerFactory .create(mStatusBarView, mNotificationPanelViewController .getStatusBarTouchEventHandler()); mPhoneStatusBarViewController.init(); - mBatteryMeterViewController = new BatteryMeterViewController( - mStatusBarView.findViewById(R.id.battery), - mConfigurationController, - mTunerService, - mBroadcastDispatcher, - mMainHandler, - mContext.getContentResolver(), - mBatteryController - ); - mBatteryMeterViewController.init(); - // Ensure we re-propagate panel expansion values to the panel controller and // any listeners it may have, such as PanelBar. This will also ensure we // re-display the notification panel if necessary (for example, if @@ -1169,8 +1166,8 @@ public class StatusBar extends CoreStartable implements // This view is being recreated, let's destroy the old one mHeadsUpAppearanceController.destroy(); } - // TODO: this should probably be scoped to the StatusBarComponent // TODO (b/136993073) Separate notification shade and status bar + // TODO(b/205609837): Migrate this to StatusBarFragmentComponent. mHeadsUpAppearanceController = new HeadsUpAppearanceController( mNotificationIconAreaController, mHeadsUpManager, mStackScrollerController, @@ -1187,6 +1184,7 @@ public class StatusBar extends CoreStartable implements .beginTransaction() .replace(R.id.status_bar_container, new CollapsedStatusBarFragment( + mStatusBarFragmentComponentFactory, mOngoingCallController, mAnimationScheduler, mStatusBarLocationPublisher, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarPhoneModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarPhoneModule.java index 3259f6b8027b2..56fd6e4446deb 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarPhoneModule.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarPhoneModule.java @@ -75,7 +75,6 @@ import com.android.systemui.statusbar.notification.logging.NotificationLogger; import com.android.systemui.statusbar.notification.row.NotificationGutsManager; import com.android.systemui.statusbar.phone.AutoHideController; import com.android.systemui.statusbar.phone.BiometricUnlockController; -import com.android.systemui.statusbar.phone.CollapsedStatusBarFragmentLogger; import com.android.systemui.statusbar.phone.DozeParameters; import com.android.systemui.statusbar.phone.DozeScrimController; import com.android.systemui.statusbar.phone.DozeServiceHost; @@ -99,6 +98,8 @@ import com.android.systemui.statusbar.phone.StatusBarLocationPublisher; import com.android.systemui.statusbar.phone.StatusBarNotificationActivityStarter; import com.android.systemui.statusbar.phone.StatusBarTouchableRegionManager; import com.android.systemui.statusbar.phone.UnlockedScreenOffAnimationController; +import com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragmentLogger; +import com.android.systemui.statusbar.phone.fragment.dagger.StatusBarFragmentComponent; import com.android.systemui.statusbar.phone.ongoingcall.OngoingCallController; import com.android.systemui.statusbar.phone.panelstate.PanelExpansionStateManager; import com.android.systemui.statusbar.policy.BatteryController; @@ -197,6 +198,7 @@ public interface StatusBarPhoneModule { CommandQueue commandQueue, CollapsedStatusBarFragmentLogger collapsedStatusBarFragmentLogger, StatusBarComponent.Factory statusBarComponentFactory, + StatusBarFragmentComponent.Factory statusBarFragmentComponentFactory, PluginManager pluginManager, Optional splitScreenOptional, LightsOutNotifController lightsOutNotifController, @@ -297,6 +299,7 @@ public interface StatusBarPhoneModule { commandQueue, collapsedStatusBarFragmentLogger, statusBarComponentFactory, + statusBarFragmentComponentFactory, pluginManager, splitScreenOptional, lightsOutNotifController, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragment.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragment.java similarity index 94% rename from packages/SystemUI/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragment.java rename to packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragment.java index 2b62e0bf07a21..2880e4dc7033a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragment.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragment.java @@ -12,7 +12,7 @@ * permissions and limitations under the License. */ -package com.android.systemui.statusbar.phone; +package com.android.systemui.statusbar.phone.fragment; import static android.app.StatusBarManager.DISABLE2_SYSTEM_ICONS; import static android.app.StatusBarManager.DISABLE_CLOCK; @@ -52,7 +52,14 @@ import com.android.systemui.statusbar.connectivity.NetworkController; import com.android.systemui.statusbar.connectivity.SignalCallback; import com.android.systemui.statusbar.events.SystemStatusAnimationCallback; import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler; +import com.android.systemui.statusbar.phone.NotificationIconAreaController; +import com.android.systemui.statusbar.phone.PhoneStatusBarView; +import com.android.systemui.statusbar.phone.StatusBar; +import com.android.systemui.statusbar.phone.StatusBarHideIconsForBouncerManager; +import com.android.systemui.statusbar.phone.StatusBarIconController; import com.android.systemui.statusbar.phone.StatusBarIconController.DarkIconManager; +import com.android.systemui.statusbar.phone.StatusBarLocationPublisher; +import com.android.systemui.statusbar.phone.fragment.dagger.StatusBarFragmentComponent; import com.android.systemui.statusbar.phone.ongoingcall.OngoingCallController; import com.android.systemui.statusbar.phone.ongoingcall.OngoingCallListener; import com.android.systemui.statusbar.phone.panelstate.PanelExpansionStateManager; @@ -83,6 +90,7 @@ public class CollapsedStatusBarFragment extends Fragment implements CommandQueue public static final String STATUS_BAR_ICON_MANAGER_TAG = "status_bar_icon_manager"; public static final int FADE_IN_DURATION = 320; public static final int FADE_IN_DELAY = 50; + private StatusBarFragmentComponent mStatusBarFragmentComponent; private PhoneStatusBarView mStatusBar; private final StatusBarStateController mStatusBarStateController; private final KeyguardStateController mKeyguardStateController; @@ -96,6 +104,7 @@ public class CollapsedStatusBarFragment extends Fragment implements CommandQueue private int mDisabled2; private Lazy> mStatusBarOptionalLazy; private DarkIconManager mDarkIconManager; + private final StatusBarFragmentComponent.Factory mStatusBarFragmentComponentFactory; private final CommandQueue mCommandQueue; private final CollapsedStatusBarFragmentLogger mCollapsedStatusBarFragmentLogger; private final OperatorNameViewController.Factory mOperatorNameViewControllerFactory; @@ -127,6 +136,7 @@ public class CollapsedStatusBarFragment extends Fragment implements CommandQueue @Inject public CollapsedStatusBarFragment( + StatusBarFragmentComponent.Factory statusBarFragmentComponentFactory, OngoingCallController ongoingCallController, SystemStatusAnimationScheduler animationScheduler, StatusBarLocationPublisher locationPublisher, @@ -143,6 +153,7 @@ public class CollapsedStatusBarFragment extends Fragment implements CommandQueue CollapsedStatusBarFragmentLogger collapsedStatusBarFragmentLogger, OperatorNameViewController.Factory operatorNameViewControllerFactory ) { + mStatusBarFragmentComponentFactory = statusBarFragmentComponentFactory; mOngoingCallController = ongoingCallController; mAnimationScheduler = animationScheduler; mLocationPublisher = locationPublisher; @@ -169,6 +180,9 @@ public class CollapsedStatusBarFragment extends Fragment implements CommandQueue @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + mStatusBarFragmentComponent = mStatusBarFragmentComponentFactory.create(this); + mStatusBarFragmentComponent.init(); + mStatusBar = (PhoneStatusBarView) view; View contents = mStatusBar.findViewById(R.id.status_bar_contents); contents.addOnLayoutChangeListener(mStatusBarLayoutListener); @@ -252,6 +266,17 @@ public class CollapsedStatusBarFragment extends Fragment implements CommandQueue updateNotificationIconAreaAndCallChip(mDisabled1, false); } + /** + * Returns the dagger component for this fragment. + * + * TODO(b/205609837): Eventually, the dagger component should encapsulate all status bar + * fragment functionality and we won't need to expose it here anymore. + */ + @Nullable + public StatusBarFragmentComponent getStatusBarFragmentComponent() { + return mStatusBarFragmentComponent; + } + @Override public void disable(int displayId, int state1, int state2, boolean animate) { if (displayId != getContext().getDisplayId()) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragmentLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentLogger.kt similarity index 95% rename from packages/SystemUI/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragmentLogger.kt rename to packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentLogger.kt index 4d472e47a387c..9ae378f34fc05 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragmentLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentLogger.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.systemui.statusbar.phone +package com.android.systemui.statusbar.phone.fragment import com.android.systemui.log.LogBuffer import com.android.systemui.log.LogLevel diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/dagger/StatusBarFragmentComponent.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/dagger/StatusBarFragmentComponent.java new file mode 100644 index 0000000000000..47c1875407409 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/dagger/StatusBarFragmentComponent.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.phone.fragment.dagger; + +import com.android.systemui.battery.BatteryMeterViewController; +import com.android.systemui.dagger.qualifiers.RootView; +import com.android.systemui.statusbar.phone.PhoneStatusBarView; +import com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragment; + +import dagger.BindsInstance; +import dagger.Subcomponent; + +/** + * A subcomponent that gets re-created each time we create a new {@link CollapsedStatusBarFragment}. + * + * This component will also re-create all classes that depend on {@link CollapsedStatusBarFragment} + * and friends. Specifically, the fragment creates a new {@link PhoneStatusBarView} and multiple + * controllers need access to that view, so those controllers will be re-created whenever the + * fragment is recreated. + * + * Note that this is completely separate from + * {@link com.android.systemui.statusbar.phone.dagger.StatusBarComponent}. This component gets + * re-created on each new fragment creation, whereas + * {@link com.android.systemui.statusbar.phone.dagger.StatusBarComponent} is only created once in + * {@link com.android.systemui.statusbar.phone.StatusBar} and never re-created. + */ + +@Subcomponent(modules = {StatusBarFragmentModule.class}) +@StatusBarFragmentScope +public interface StatusBarFragmentComponent { + /** Simple factory. */ + @Subcomponent.Factory + interface Factory { + StatusBarFragmentComponent create( + @BindsInstance CollapsedStatusBarFragment collapsedStatusBarFragment); + } + + /** + * Initialize anything extra for the component. Must be called after the component is created. + */ + default void init() { + // No one accesses this controller, so we need to make sure we reference it here so it does + // get initialized. + getBatteryMeterViewController().init(); + } + + /** */ + @StatusBarFragmentScope + BatteryMeterViewController getBatteryMeterViewController(); + + /** */ + @StatusBarFragmentScope + @RootView + PhoneStatusBarView getPhoneStatusBarView(); +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/dagger/StatusBarFragmentModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/dagger/StatusBarFragmentModule.java new file mode 100644 index 0000000000000..969361bb6100d --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/dagger/StatusBarFragmentModule.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.phone.fragment.dagger; + +import com.android.systemui.R; +import com.android.systemui.battery.BatteryMeterView; +import com.android.systemui.dagger.qualifiers.RootView; +import com.android.systemui.statusbar.phone.PhoneStatusBarView; +import com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragment; + +import dagger.Module; +import dagger.Provides; + +/** Dagger module for {@link StatusBarFragmentComponent}. */ +@Module +public interface StatusBarFragmentModule { + /** */ + @Provides + @RootView + @StatusBarFragmentScope + static PhoneStatusBarView providePhoneStatusBarView( + CollapsedStatusBarFragment collapsedStatusBarFragment) { + return (PhoneStatusBarView) collapsedStatusBarFragment.getView(); + } + + /** */ + @Provides + @StatusBarFragmentScope + static BatteryMeterView provideBatteryMeterView(@RootView PhoneStatusBarView view) { + return view.findViewById(R.id.battery); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/dagger/StatusBarFragmentScope.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/dagger/StatusBarFragmentScope.java new file mode 100644 index 0000000000000..96cff5960d68f --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/dagger/StatusBarFragmentScope.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.phone.fragment.dagger; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; + +import javax.inject.Scope; + +/** + * Scope annotation for singleton items within the {@link StatusBarFragmentComponent}. + */ +@Documented +@Retention(RUNTIME) +@Scope +public @interface StatusBarFragmentScope {} diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java index 371b91f17ce93..cf70dc360ce1f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java @@ -133,6 +133,8 @@ import com.android.systemui.statusbar.notification.stack.NotificationListContain import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController; import com.android.systemui.statusbar.phone.dagger.StatusBarComponent; +import com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragmentLogger; +import com.android.systemui.statusbar.phone.fragment.dagger.StatusBarFragmentComponent; import com.android.systemui.statusbar.phone.ongoingcall.OngoingCallController; import com.android.systemui.statusbar.phone.panelstate.PanelExpansionStateManager; import com.android.systemui.statusbar.policy.BatteryController; @@ -243,6 +245,8 @@ public class StatusBarTest extends SysuiTestCase { @Mock private CollapsedStatusBarFragmentLogger mCollapsedStatusBarFragmentLogger; @Mock private StatusBarComponent.Factory mStatusBarComponentFactory; @Mock private StatusBarComponent mStatusBarComponent; + @Mock private StatusBarFragmentComponent.Factory mStatusBarFragmentComponentFactory; + @Mock private StatusBarFragmentComponent mStatusBarFragmentComponent; @Mock private PluginManager mPluginManager; @Mock private LegacySplitScreen mLegacySplitScreen; @Mock private LightsOutNotifController mLightsOutNotifController; @@ -356,6 +360,8 @@ public class StatusBarTest extends SysuiTestCase { when(mBiometricUnlockControllerLazy.get()).thenReturn(mBiometricUnlockController); when(mStatusBarComponentFactory.create()).thenReturn(mStatusBarComponent); + when(mStatusBarFragmentComponentFactory.create(any())) + .thenReturn(mStatusBarFragmentComponent); when(mStatusBarComponent.getNotificationShadeWindowViewController()).thenReturn( mNotificationShadeWindowViewController); @@ -425,6 +431,7 @@ public class StatusBarTest extends SysuiTestCase { mCommandQueue, mCollapsedStatusBarFragmentLogger, mStatusBarComponentFactory, + mStatusBarFragmentComponentFactory, mPluginManager, Optional.of(mLegacySplitScreen), mLightsOutNotifController, diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragmentLoggerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentLoggerTest.kt similarity index 97% rename from packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragmentLoggerTest.kt rename to packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentLoggerTest.kt index bf8cc37697b4f..1ee8875eada80 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragmentLoggerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentLoggerTest.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.systemui.statusbar.phone +package com.android.systemui.statusbar.phone.fragment import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragmentTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentTest.java similarity index 89% rename from packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragmentTest.java rename to packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentTest.java index 75a86244bb69b..0ee4e7a2c5856 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragmentTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentTest.java @@ -12,7 +12,7 @@ * permissions and limitations under the License. */ -package com.android.systemui.statusbar.phone; +package com.android.systemui.statusbar.phone.fragment; import static android.view.Display.DEFAULT_DISPLAY; @@ -48,6 +48,13 @@ import com.android.systemui.statusbar.DisableFlagsLogger; import com.android.systemui.statusbar.OperatorNameViewController; import com.android.systemui.statusbar.connectivity.NetworkController; import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler; +import com.android.systemui.statusbar.phone.NotificationIconAreaController; +import com.android.systemui.statusbar.phone.NotificationPanelViewController; +import com.android.systemui.statusbar.phone.StatusBar; +import com.android.systemui.statusbar.phone.StatusBarHideIconsForBouncerManager; +import com.android.systemui.statusbar.phone.StatusBarIconController; +import com.android.systemui.statusbar.phone.StatusBarLocationPublisher; +import com.android.systemui.statusbar.phone.fragment.dagger.StatusBarFragmentComponent; import com.android.systemui.statusbar.phone.ongoingcall.OngoingCallController; import com.android.systemui.statusbar.phone.panelstate.PanelExpansionStateManager; import com.android.systemui.statusbar.policy.KeyguardStateController; @@ -72,7 +79,6 @@ public class CollapsedStatusBarFragmentTest extends SysuiBaseFragmentTest { private OngoingCallController mOngoingCallController; private SystemStatusAnimationScheduler mAnimationScheduler; private StatusBarLocationPublisher mLocationPublisher; - // Set in instantiate() private StatusBarIconController mStatusBarIconController; private NetworkController mNetworkController; @@ -84,6 +90,8 @@ public class CollapsedStatusBarFragmentTest extends SysuiBaseFragmentTest { private OperatorNameViewController.Factory mOperatorNameViewControllerFactory; private OperatorNameViewController mOperatorNameViewController; + private StatusBarFragmentComponent.Factory mStatusBarFragmentComponentFactory; + private StatusBarFragmentComponent mStatusBarFragmentComponent; public CollapsedStatusBarFragmentTest() { super(CollapsedStatusBarFragment.class); @@ -245,8 +253,22 @@ public class CollapsedStatusBarFragmentTest extends SysuiBaseFragmentTest { Mockito.verify(mNotificationAreaInner, atLeast(1)).setVisibility(eq(View.VISIBLE)); } + @Test + public void setUp_fragmentCreatesDaggerComponent() { + mFragments.dispatchResume(); + processAllMessages(); + CollapsedStatusBarFragment fragment = (CollapsedStatusBarFragment) mFragment; + + assertEquals(mStatusBarFragmentComponent, fragment.getStatusBarFragmentComponent()); + } + @Override protected Fragment instantiate(Context context, String className, Bundle arguments) { + mStatusBarFragmentComponentFactory = + mock(StatusBarFragmentComponent.Factory.class); + mStatusBarFragmentComponent = mock(StatusBarFragmentComponent.class); + when(mStatusBarFragmentComponentFactory.create(any())) + .thenReturn(mStatusBarFragmentComponent); mOngoingCallController = mock(OngoingCallController.class); mAnimationScheduler = mock(SystemStatusAnimationScheduler.class); mLocationPublisher = mock(StatusBarLocationPublisher.class); @@ -261,6 +283,7 @@ public class CollapsedStatusBarFragmentTest extends SysuiBaseFragmentTest { setUpNotificationIconAreaController(); return new CollapsedStatusBarFragment( + mStatusBarFragmentComponentFactory, mOngoingCallController, mAnimationScheduler, mLocationPublisher, @@ -282,7 +305,6 @@ public class CollapsedStatusBarFragmentTest extends SysuiBaseFragmentTest { mOperatorNameViewControllerFactory); } - private void setUpNotificationIconAreaController() { mMockNotificationAreaController = mock(NotificationIconAreaController.class);