diff options
11 files changed, 59 insertions, 177 deletions
diff --git a/core/java/android/service/dreams/DreamOverlayService.java b/core/java/android/service/dreams/DreamOverlayService.java index 013ec5f35761..17d2790eac96 100644 --- a/core/java/android/service/dreams/DreamOverlayService.java +++ b/core/java/android/service/dreams/DreamOverlayService.java @@ -28,9 +28,7 @@ import android.os.RemoteException; import android.util.Log; import android.view.WindowManager; -import java.lang.ref.WeakReference; import java.util.concurrent.Executor; -import java.util.function.Consumer; /** @@ -54,51 +52,43 @@ public abstract class DreamOverlayService extends Service { // An {@link IDreamOverlayClient} implementation that identifies itself when forwarding // requests to the {@link DreamOverlayService} private static class OverlayClient extends IDreamOverlayClient.Stub { - private final WeakReference<DreamOverlayService> mService; + private final DreamOverlayService mService; private boolean mShowComplications; private ComponentName mDreamComponent; IDreamOverlayCallback mDreamOverlayCallback; - OverlayClient(WeakReference<DreamOverlayService> service) { + OverlayClient(DreamOverlayService service) { mService = service; } - private void applyToDream(Consumer<DreamOverlayService> consumer) { - final DreamOverlayService service = mService.get(); - - if (service != null) { - consumer.accept(service); - } - } - @Override public void startDream(WindowManager.LayoutParams params, IDreamOverlayCallback callback, String dreamComponent, boolean shouldShowComplications) throws RemoteException { mDreamComponent = ComponentName.unflattenFromString(dreamComponent); mShowComplications = shouldShowComplications; mDreamOverlayCallback = callback; - applyToDream(dreamOverlayService -> dreamOverlayService.startDream(this, params)); + mService.startDream(this, params); } @Override public void wakeUp() { - applyToDream(dreamOverlayService -> dreamOverlayService.wakeUp(this)); + mService.wakeUp(this); } @Override public void endDream() { - applyToDream(dreamOverlayService -> dreamOverlayService.endDream(this)); + mService.endDream(this); } @Override public void comeToFront() { - applyToDream(dreamOverlayService -> dreamOverlayService.comeToFront(this)); + mService.comeToFront(this); } @Override public void onWakeRequested() { if (Flags.dreamWakeRedirect()) { - applyToDream(DreamOverlayService::onWakeRequested); + mService.onWakeRequested(); } } @@ -171,24 +161,17 @@ public abstract class DreamOverlayService extends Service { }); } - private static class DreamOverlay extends IDreamOverlay.Stub { - private final WeakReference<DreamOverlayService> mService; - - DreamOverlay(DreamOverlayService service) { - mService = new WeakReference<>(service); - } - + private IDreamOverlay mDreamOverlay = new IDreamOverlay.Stub() { @Override public void getClient(IDreamOverlayClientCallback callback) { try { - callback.onDreamOverlayClient(new OverlayClient(mService)); + callback.onDreamOverlayClient( + new OverlayClient(DreamOverlayService.this)); } catch (RemoteException e) { Log.e(TAG, "could not send client to callback", e); } } - } - - private final IDreamOverlay mDreamOverlay = new DreamOverlay(this); + }; public DreamOverlayService() { } @@ -212,12 +195,6 @@ public abstract class DreamOverlayService extends Service { } } - @Override - public void onDestroy() { - mCurrentClient = null; - super.onDestroy(); - } - @Nullable @Override public final IBinder onBind(@NonNull Intent intent) { diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayContainerViewControllerTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayContainerViewControllerTest.java index 3895595aaea6..6412276ba34b 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayContainerViewControllerTest.java +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayContainerViewControllerTest.java @@ -62,7 +62,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -325,13 +324,4 @@ public class DreamOverlayContainerViewControllerTest extends SysuiTestCase { // enabled. mController.onViewAttached(); } - - @Test - public void destroy_cleansUpState() { - mController.destroy(); - verify(mStateController).removeCallback(any()); - verify(mAmbientStatusBarViewController).destroy(); - verify(mComplicationHostViewController).destroy(); - verify(mLowLightTransitionCoordinator).setLowLightEnterListener(ArgumentMatchers.isNull()); - } } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayServiceTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayServiceTest.kt index 7a86e57779b9..5c09777ddde5 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayServiceTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayServiceTest.kt @@ -596,9 +596,6 @@ class DreamOverlayServiceTest : SysuiTestCase() { // are created. verify(mDreamOverlayComponent).getDreamOverlayContainerViewController() verify(mAmbientTouchComponent).getTouchMonitor() - - // Verify DreamOverlayContainerViewController is destroyed. - verify(mDreamOverlayContainerViewController).destroy() } @Test diff --git a/packages/SystemUI/src/com/android/systemui/ambient/touch/TouchHandler.java b/packages/SystemUI/src/com/android/systemui/ambient/touch/TouchHandler.java index d27e72a9c185..190bc1587525 100644 --- a/packages/SystemUI/src/com/android/systemui/ambient/touch/TouchHandler.java +++ b/packages/SystemUI/src/com/android/systemui/ambient/touch/TouchHandler.java @@ -122,9 +122,4 @@ public interface TouchHandler { * @param session */ void onSessionStart(TouchSession session); - - /** - * Called when the handler is being torn down. - */ - default void onDestroy() {} } diff --git a/packages/SystemUI/src/com/android/systemui/ambient/touch/TouchMonitor.java b/packages/SystemUI/src/com/android/systemui/ambient/touch/TouchMonitor.java index 1be6f9e7ca4f..efa55e90081e 100644 --- a/packages/SystemUI/src/com/android/systemui/ambient/touch/TouchMonitor.java +++ b/packages/SystemUI/src/com/android/systemui/ambient/touch/TouchMonitor.java @@ -581,10 +581,6 @@ public class TouchMonitor { mBoundsFlow.cancel(new CancellationException()); } - for (TouchHandler handler : mHandlers) { - handler.onDestroy(); - } - mInitialized = false; } diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt index 24ac542c6266..b45ebd865c55 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt @@ -44,7 +44,6 @@ import com.android.systemui.statusbar.BlurUtils import com.android.systemui.statusbar.CrossFadeHelper import javax.inject.Inject import javax.inject.Named -import kotlinx.coroutines.DisposableHandle import kotlinx.coroutines.launch /** Controller for dream overlay animations. */ @@ -85,62 +84,51 @@ constructor( private var mCurrentBlurRadius: Float = 0f - private var mLifecycleFlowHandle: DisposableHandle? = null - fun init(view: View) { this.view = view - mLifecycleFlowHandle = - view.repeatWhenAttached { - repeatOnLifecycle(Lifecycle.State.CREATED) { - launch { - dreamViewModel.dreamOverlayTranslationY.collect { px -> - ComplicationLayoutParams.iteratePositions( - { position: Int -> - setElementsTranslationYAtPosition(px, position) - }, - POSITION_TOP or POSITION_BOTTOM - ) - } + view.repeatWhenAttached { + repeatOnLifecycle(Lifecycle.State.CREATED) { + launch { + dreamViewModel.dreamOverlayTranslationY.collect { px -> + ComplicationLayoutParams.iteratePositions( + { position: Int -> setElementsTranslationYAtPosition(px, position) }, + POSITION_TOP or POSITION_BOTTOM + ) } + } - launch { - dreamViewModel.dreamOverlayTranslationX.collect { px -> - ComplicationLayoutParams.iteratePositions( - { position: Int -> - setElementsTranslationXAtPosition(px, position) - }, - POSITION_TOP or POSITION_BOTTOM - ) - } + launch { + dreamViewModel.dreamOverlayTranslationX.collect { px -> + ComplicationLayoutParams.iteratePositions( + { position: Int -> setElementsTranslationXAtPosition(px, position) }, + POSITION_TOP or POSITION_BOTTOM + ) } + } - launch { - dreamViewModel.dreamOverlayAlpha.collect { alpha -> - ComplicationLayoutParams.iteratePositions( - { position: Int -> - setElementsAlphaAtPosition( - alpha = alpha, - position = position, - fadingOut = true, - ) - }, - POSITION_TOP or POSITION_BOTTOM - ) - } + launch { + dreamViewModel.dreamOverlayAlpha.collect { alpha -> + ComplicationLayoutParams.iteratePositions( + { position: Int -> + setElementsAlphaAtPosition( + alpha = alpha, + position = position, + fadingOut = true, + ) + }, + POSITION_TOP or POSITION_BOTTOM + ) } + } - launch { - dreamViewModel.transitionEnded.collect { _ -> - mOverlayStateController.setExitAnimationsRunning(false) - } + launch { + dreamViewModel.transitionEnded.collect { _ -> + mOverlayStateController.setExitAnimationsRunning(false) } } } - } - - fun destroy() { - mLifecycleFlowHandle?.dispose() + } } /** diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java index bf6d266ac42f..76c7d2383751 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java @@ -59,7 +59,6 @@ import com.android.systemui.touch.TouchInsetManager; import com.android.systemui.util.ViewController; import kotlinx.coroutines.CoroutineDispatcher; -import kotlinx.coroutines.DisposableHandle; import kotlinx.coroutines.flow.FlowKt; import java.util.Arrays; @@ -186,8 +185,6 @@ public class DreamOverlayContainerViewController extends } }; - private DisposableHandle mFlowHandle; - @Inject public DreamOverlayContainerViewController( DreamOverlayContainerView containerView, @@ -255,17 +252,6 @@ public class DreamOverlayContainerViewController extends } @Override - public void destroy() { - mStateController.removeCallback(mDreamOverlayStateCallback); - mStatusBarViewController.destroy(); - mComplicationHostViewController.destroy(); - mDreamOverlayAnimationsController.destroy(); - mLowLightTransitionCoordinator.setLowLightEnterListener(null); - - super.destroy(); - } - - @Override protected void onViewAttached() { mWakingUpFromSwipe = false; mJitterStartTimeMillis = System.currentTimeMillis(); @@ -277,7 +263,7 @@ public class DreamOverlayContainerViewController extends emptyRegion.recycle(); if (dreamHandlesBeingObscured()) { - mFlowHandle = collectFlow( + collectFlow( mView, FlowKt.distinctUntilChanged(combineFlows( mKeyguardTransitionInteractor.isFinishedIn( @@ -309,10 +295,6 @@ public class DreamOverlayContainerViewController extends @Override protected void onViewDetached() { - if (mFlowHandle != null) { - mFlowHandle.dispose(); - mFlowHandle = null; - } mHandler.removeCallbacksAndMessages(null); mPrimaryBouncerCallbackInteractor.removeBouncerExpansionCallback(mBouncerExpansionCallback); mBouncerlessScrimController.removeCallback(mBouncerlessExpansionCallback); diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java index 4b9e5a024393..931066d5c582 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java @@ -70,12 +70,8 @@ import com.android.systemui.shade.ShadeExpansionChangeEvent; import com.android.systemui.touch.TouchInsetManager; import com.android.systemui.util.concurrency.DelayableExecutor; -import kotlinx.coroutines.Job; - -import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; -import java.util.concurrent.CancellationException; import java.util.function.Consumer; import javax.inject.Inject; @@ -144,8 +140,6 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ private ComponentName mCurrentBlockedGestureDreamActivityComponent; - private final ArrayList<Job> mFlows = new ArrayList<>(); - /** * This {@link LifecycleRegistry} controls when dream overlay functionality, like touch * handling, should be active. It will automatically be paused when the dream overlay is hidden @@ -315,12 +309,12 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ mExecutor.execute(() -> setLifecycleStateLocked(Lifecycle.State.CREATED)); - mFlows.add(collectFlow(getLifecycle(), mCommunalInteractor.isCommunalAvailable(), - mIsCommunalAvailableCallback)); - mFlows.add(collectFlow(getLifecycle(), communalInteractor.isCommunalVisible(), - mCommunalVisibleConsumer)); - mFlows.add(collectFlow(getLifecycle(), keyguardInteractor.primaryBouncerShowing, - mBouncerShowingConsumer)); + collectFlow(getLifecycle(), mCommunalInteractor.isCommunalAvailable(), + mIsCommunalAvailableCallback); + collectFlow(getLifecycle(), communalInteractor.isCommunalVisible(), + mCommunalVisibleConsumer); + collectFlow(getLifecycle(), keyguardInteractor.primaryBouncerShowing, + mBouncerShowingConsumer); } @NonNull @@ -345,11 +339,6 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ public void onDestroy() { mKeyguardUpdateMonitor.removeCallback(mKeyguardCallback); - for (Job job : mFlows) { - job.cancel(new CancellationException()); - } - mFlows.clear(); - mExecutor.execute(() -> { setLifecycleStateLocked(Lifecycle.State.DESTROYED); @@ -570,7 +559,6 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ if (mStarted && mWindow != null) { try { - mWindow.clearContentView(); mWindowManager.removeView(mWindow.getDecorView()); } catch (IllegalArgumentException e) { Log.e(TAG, "Error removing decor view when resetting overlay", e); @@ -581,10 +569,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ mStateController.setLowLightActive(false); mStateController.setEntryAnimationsFinished(false); - if (mDreamOverlayContainerViewController != null) { - mDreamOverlayContainerViewController.destroy(); - mDreamOverlayContainerViewController = null; - } + mDreamOverlayContainerViewController = null; if (mTouchMonitor != null) { mTouchMonitor.destroy(); diff --git a/packages/SystemUI/src/com/android/systemui/dreams/touch/CommunalTouchHandler.java b/packages/SystemUI/src/com/android/systemui/dreams/touch/CommunalTouchHandler.java index 5ba780f9c99d..ee7b6f52ac55 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/touch/CommunalTouchHandler.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/touch/CommunalTouchHandler.java @@ -33,11 +33,7 @@ import com.android.systemui.communal.domain.interactor.CommunalInteractor; import com.android.systemui.dreams.touch.dagger.CommunalTouchModule; import com.android.systemui.statusbar.phone.CentralSurfaces; -import kotlinx.coroutines.Job; - -import java.util.ArrayList; import java.util.Optional; -import java.util.concurrent.CancellationException; import java.util.function.Consumer; import javax.inject.Inject; @@ -53,8 +49,6 @@ public class CommunalTouchHandler implements TouchHandler { private final ConfigurationInteractor mConfigurationInteractor; private Boolean mIsEnabled = false; - private ArrayList<Job> mFlows = new ArrayList<>(); - private int mLayoutDirection = LayoutDirection.LTR; @VisibleForTesting @@ -76,17 +70,17 @@ public class CommunalTouchHandler implements TouchHandler { mCommunalInteractor = communalInteractor; mConfigurationInteractor = configurationInteractor; - mFlows.add(collectFlow( + collectFlow( mLifecycle, mCommunalInteractor.isCommunalAvailable(), mIsCommunalAvailableCallback - )); + ); - mFlows.add(collectFlow( + collectFlow( mLifecycle, mConfigurationInteractor.getLayoutDirection(), mLayoutDirectionCallback - )); + ); } @Override @@ -146,13 +140,4 @@ public class CommunalTouchHandler implements TouchHandler { } }); } - - @Override - public void onDestroy() { - for (Job job : mFlows) { - job.cancel(new CancellationException()); - } - mFlows.clear(); - TouchHandler.super.onDestroy(); - } } diff --git a/packages/SystemUI/src/com/android/systemui/util/kotlin/JavaAdapter.kt b/packages/SystemUI/src/com/android/systemui/util/kotlin/JavaAdapter.kt index 055671cf32ca..28ac2c0e8283 100644 --- a/packages/SystemUI/src/com/android/systemui/util/kotlin/JavaAdapter.kt +++ b/packages/SystemUI/src/com/android/systemui/util/kotlin/JavaAdapter.kt @@ -28,7 +28,6 @@ import javax.inject.Inject import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.DisposableHandle import kotlinx.coroutines.Job import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine @@ -63,9 +62,7 @@ constructor( /** * Collect information for the given [flow], calling [consumer] for each emitted event. Defaults to * [LifeCycle.State.CREATED] to better align with legacy ViewController usage of attaching listeners - * during onViewAttached() and removing during onViewRemoved(). - * - * @return a disposable handle in order to cancel the flow in the future. + * during onViewAttached() and removing during onViewRemoved() */ @JvmOverloads fun <T> collectFlow( @@ -74,8 +71,8 @@ fun <T> collectFlow( consumer: Consumer<T>, coroutineContext: CoroutineContext = EmptyCoroutineContext, state: Lifecycle.State = Lifecycle.State.CREATED, -): DisposableHandle { - return view.repeatWhenAttached(coroutineContext) { +) { + view.repeatWhenAttached(coroutineContext) { repeatOnLifecycle(state) { flow.collect { consumer.accept(it) } } } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/ambient/touch/TouchMonitorTest.java b/packages/SystemUI/tests/src/com/android/systemui/ambient/touch/TouchMonitorTest.java index a18d272b8fe3..5600b87280ad 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/ambient/touch/TouchMonitorTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/ambient/touch/TouchMonitorTest.java @@ -711,16 +711,6 @@ public class TouchMonitorTest extends SysuiTestCase { } @Test - public void testDestroy_cleansUpHandler() { - final TouchHandler touchHandler = createTouchHandler(); - - final Environment environment = new Environment(Stream.of(touchHandler) - .collect(Collectors.toCollection(HashSet::new)), mKosmos); - environment.destroyMonitor(); - verify(touchHandler).onDestroy(); - } - - @Test public void testLastSessionPop_createsNewInputSession() { final TouchHandler touchHandler = createTouchHandler(); |