From afc242bddf183098f87436eadd5c4fad39bfc767 Mon Sep 17 00:00:00 2001 From: Dave Mankoff Date: Mon, 11 Nov 2019 15:39:23 -0500 Subject: [PATCH] Remove circular depdendency in VolumdDialogControllerImpl. This was affecting CarSystemUI. Bug: 144289426 Test: atest SystemUITests Change-Id: I9c3b682dd8b68f458a515b173ec52b81c81a1d1b --- .../volume/CarVolumeDialogComponent.java | 6 ++--- .../volume/VolumeDialogComponent.java | 5 +++-- .../volume/VolumeDialogControllerImpl.java | 22 +++++++++++-------- .../VolumeDialogControllerImplTest.java | 16 +++++++++----- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/packages/CarSystemUI/src/com/android/systemui/volume/CarVolumeDialogComponent.java b/packages/CarSystemUI/src/com/android/systemui/volume/CarVolumeDialogComponent.java index 4d6af95b3f9c7..9d39684bf7966 100644 --- a/packages/CarSystemUI/src/com/android/systemui/volume/CarVolumeDialogComponent.java +++ b/packages/CarSystemUI/src/com/android/systemui/volume/CarVolumeDialogComponent.java @@ -18,7 +18,6 @@ package com.android.systemui.volume; import android.content.Context; -import com.android.systemui.SystemUI; import com.android.systemui.keyguard.KeyguardViewMediator; import com.android.systemui.plugins.VolumeDialog; @@ -32,8 +31,9 @@ import javax.inject.Singleton; public class CarVolumeDialogComponent extends VolumeDialogComponent { @Inject - public CarVolumeDialogComponent(Context context, KeyguardViewMediator keyguardViewMediator) { - super(context, keyguardViewMediator); + public CarVolumeDialogComponent(Context context, KeyguardViewMediator keyguardViewMediator, + VolumeDialogControllerImpl volumeDialogController) { + super(context, keyguardViewMediator, volumeDialogController); } protected VolumeDialog createDefault() { diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java index 25a5139bf6618..1c2a2fa53beac 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java +++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java @@ -72,10 +72,11 @@ public class VolumeDialogComponent implements VolumeComponent, TunerService.Tuna ); @Inject - public VolumeDialogComponent(Context context, KeyguardViewMediator keyguardViewMediator) { + public VolumeDialogComponent(Context context, KeyguardViewMediator keyguardViewMediator, + VolumeDialogControllerImpl volumeDialogController) { mContext = context; mKeyguardViewMediator = keyguardViewMediator; - mController = (VolumeDialogControllerImpl) Dependency.get(VolumeDialogController.class); + mController = volumeDialogController; mController.setUserActivityListener(this); // Allow plugins to reference the VolumeDialogController. Dependency.get(PluginDependencyProvider.class) diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java index fc57981aea246..da0117116aa11 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java @@ -74,6 +74,8 @@ import java.util.Optional; import javax.inject.Inject; import javax.inject.Singleton; +import dagger.Lazy; + /** * Source of truth for all state / events related to the volume dialog. No presentation. * @@ -115,7 +117,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa private final Context mContext; private AudioManager mAudio; private IAudioService mAudioService; - private final Optional mStatusBarOptional; + private final Optional> mStatusBarOptionalLazy; private final NotificationManager mNoMan; private final SettingObserver mObserver; private final Receiver mReceiver = new Receiver(); @@ -142,9 +144,9 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa @Inject public VolumeDialogControllerImpl(Context context, BroadcastDispatcher broadcastDispatcher, - Optional statusBarOptional) { + Optional> statusBarOptionalLazy) { mContext = context.getApplicationContext(); - mStatusBarOptional = statusBarOptional; + mStatusBarOptionalLazy = statusBarOptionalLazy; mNotificationManager = (NotificationManager) mContext.getSystemService( Context.NOTIFICATION_SERVICE); Events.writeEvent(mContext, Events.EVENT_COLLECTION_STARTED); @@ -448,12 +450,14 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa private boolean shouldShowUI(int flags) { // if status bar isn't null, check if phone is in AOD, else check flags // since we could be using a different status bar - return mStatusBarOptional.map(statusBar -> - statusBar.getWakefulnessState() != WakefulnessLifecycle.WAKEFULNESS_ASLEEP - && statusBar.getWakefulnessState() - != WakefulnessLifecycle.WAKEFULNESS_GOING_TO_SLEEP - && statusBar.isDeviceInteractive() - && (flags & AudioManager.FLAG_SHOW_UI) != 0 && mShowVolumeDialog).orElse( + return mStatusBarOptionalLazy.map(statusBarLazy -> { + StatusBar statusBar = statusBarLazy.get(); + return statusBar.getWakefulnessState() != WakefulnessLifecycle.WAKEFULNESS_ASLEEP + && statusBar.getWakefulnessState() + != WakefulnessLifecycle.WAKEFULNESS_GOING_TO_SLEEP + && statusBar.isDeviceInteractive() && (flags & AudioManager.FLAG_SHOW_UI) != 0 + && mShowVolumeDialog; + }).orElse( mShowVolumeDialog && (flags & AudioManager.FLAG_SHOW_UI) != 0); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogControllerImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogControllerImplTest.java index fe719262937d6..2854665aedb11 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogControllerImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogControllerImplTest.java @@ -69,8 +69,7 @@ public class VolumeDialogControllerImplTest extends SysuiTestCase { @Test public void testRegisteredWithDispatcher() { - verify(mBroadcastDispatcher).registerReceiver( - any(BroadcastReceiver.class), + verify(mBroadcastDispatcher).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class), any(Handler.class)); // VolumeDialogControllerImpl does not call with user } @@ -97,7 +96,8 @@ public class VolumeDialogControllerImplTest extends SysuiTestCase { when(mStatusBar.getWakefulnessState()).thenReturn(WakefulnessLifecycle.WAKEFULNESS_AWAKE); mVolumeController.onVolumeChangedW(0, AudioManager.FLAG_SHOW_UI); when(mStatusBar.isDeviceInteractive()).thenReturn(false); - when(mStatusBar.getWakefulnessState()).thenReturn(WakefulnessLifecycle.WAKEFULNESS_GOING_TO_SLEEP); + when(mStatusBar.getWakefulnessState()).thenReturn( + WakefulnessLifecycle.WAKEFULNESS_GOING_TO_SLEEP); mVolumeController.onVolumeChangedW(0, AudioManager.FLAG_SHOW_UI); verify(mCallback, times(1)).onShowRequested(Events.SHOW_REASON_VOLUME_CHANGED); } @@ -105,8 +105,10 @@ public class VolumeDialogControllerImplTest extends SysuiTestCase { @Test public void testVolumeChangeW_nullStatusBar() { VolumeDialogControllerImpl.C callback = mock(VolumeDialogControllerImpl.C.class); - TestableVolumeDialogControllerImpl nullStatusBarTestableDialog = new - TestableVolumeDialogControllerImpl(mContext, callback, null, mBroadcastDispatcher); + TestableVolumeDialogControllerImpl + nullStatusBarTestableDialog = + new TestableVolumeDialogControllerImpl( + mContext, callback, null, mBroadcastDispatcher); nullStatusBarTestableDialog.setEnableDialogs(true, true); nullStatusBarTestableDialog.onVolumeChangedW(0, AudioManager.FLAG_SHOW_UI); verify(callback, times(1)).onShowRequested(Events.SHOW_REASON_VOLUME_CHANGED); @@ -127,7 +129,9 @@ public class VolumeDialogControllerImplTest extends SysuiTestCase { static class TestableVolumeDialogControllerImpl extends VolumeDialogControllerImpl { TestableVolumeDialogControllerImpl(Context context, C callback, StatusBar s, BroadcastDispatcher broadcastDispatcher) { - super(context, broadcastDispatcher, s == null ? Optional.empty() : Optional.of(s)); + super( + context, broadcastDispatcher, + s == null ? Optional.empty() : Optional.of(() -> s)); mCallbacks = callback; } }