Loading core/java/android/service/dreams/DreamOverlayService.java +34 −11 Original line number Diff line number Diff line Loading @@ -28,7 +28,9 @@ 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; /** Loading @@ -52,43 +54,51 @@ 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 DreamOverlayService mService; private final WeakReference<DreamOverlayService> mService; private boolean mShowComplications; private ComponentName mDreamComponent; IDreamOverlayCallback mDreamOverlayCallback; OverlayClient(DreamOverlayService service) { OverlayClient(WeakReference<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; mService.startDream(this, params); applyToDream(dreamOverlayService -> dreamOverlayService.startDream(this, params)); } @Override public void wakeUp() { mService.wakeUp(this); applyToDream(dreamOverlayService -> dreamOverlayService.wakeUp(this)); } @Override public void endDream() { mService.endDream(this); applyToDream(dreamOverlayService -> dreamOverlayService.endDream(this)); } @Override public void comeToFront() { mService.comeToFront(this); applyToDream(dreamOverlayService -> dreamOverlayService.comeToFront(this)); } @Override public void onWakeRequested() { if (Flags.dreamWakeRedirect()) { mService.onWakeRequested(); applyToDream(DreamOverlayService::onWakeRequested); } } Loading Loading @@ -161,17 +171,24 @@ public abstract class DreamOverlayService extends Service { }); } private IDreamOverlay mDreamOverlay = new IDreamOverlay.Stub() { private static class DreamOverlay extends IDreamOverlay.Stub { private final WeakReference<DreamOverlayService> mService; DreamOverlay(DreamOverlayService service) { mService = new WeakReference<>(service); } @Override public void getClient(IDreamOverlayClientCallback callback) { try { callback.onDreamOverlayClient( new OverlayClient(DreamOverlayService.this)); callback.onDreamOverlayClient(new OverlayClient(mService)); } catch (RemoteException e) { Log.e(TAG, "could not send client to callback", e); } } }; } private final IDreamOverlay mDreamOverlay = new DreamOverlay(this); public DreamOverlayService() { } Loading @@ -195,6 +212,12 @@ public abstract class DreamOverlayService extends Service { } } @Override public void onDestroy() { mCurrentClient = null; super.onDestroy(); } @Nullable @Override public final IBinder onBind(@NonNull Intent intent) { Loading packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayContainerViewControllerTest.java +10 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,7 @@ 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; Loading Loading @@ -324,4 +325,13 @@ 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()); } } packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayServiceTest.kt +3 −0 Original line number Diff line number Diff line Loading @@ -596,6 +596,9 @@ class DreamOverlayServiceTest : SysuiTestCase() { // are created. verify(mDreamOverlayComponent).getDreamOverlayContainerViewController() verify(mAmbientTouchComponent).getTouchMonitor() // Verify DreamOverlayContainerViewController is destroyed. verify(mDreamOverlayContainerViewController).destroy() } @Test Loading packages/SystemUI/src/com/android/systemui/ambient/touch/TouchHandler.java +5 −0 Original line number Diff line number Diff line Loading @@ -122,4 +122,9 @@ public interface TouchHandler { * @param session */ void onSessionStart(TouchSession session); /** * Called when the handler is being torn down. */ default void onDestroy() {} } packages/SystemUI/src/com/android/systemui/ambient/touch/TouchMonitor.java +4 −0 Original line number Diff line number Diff line Loading @@ -581,6 +581,10 @@ public class TouchMonitor { mBoundsFlow.cancel(new CancellationException()); } for (TouchHandler handler : mHandlers) { handler.onDestroy(); } mInitialized = false; } Loading Loading
core/java/android/service/dreams/DreamOverlayService.java +34 −11 Original line number Diff line number Diff line Loading @@ -28,7 +28,9 @@ 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; /** Loading @@ -52,43 +54,51 @@ 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 DreamOverlayService mService; private final WeakReference<DreamOverlayService> mService; private boolean mShowComplications; private ComponentName mDreamComponent; IDreamOverlayCallback mDreamOverlayCallback; OverlayClient(DreamOverlayService service) { OverlayClient(WeakReference<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; mService.startDream(this, params); applyToDream(dreamOverlayService -> dreamOverlayService.startDream(this, params)); } @Override public void wakeUp() { mService.wakeUp(this); applyToDream(dreamOverlayService -> dreamOverlayService.wakeUp(this)); } @Override public void endDream() { mService.endDream(this); applyToDream(dreamOverlayService -> dreamOverlayService.endDream(this)); } @Override public void comeToFront() { mService.comeToFront(this); applyToDream(dreamOverlayService -> dreamOverlayService.comeToFront(this)); } @Override public void onWakeRequested() { if (Flags.dreamWakeRedirect()) { mService.onWakeRequested(); applyToDream(DreamOverlayService::onWakeRequested); } } Loading Loading @@ -161,17 +171,24 @@ public abstract class DreamOverlayService extends Service { }); } private IDreamOverlay mDreamOverlay = new IDreamOverlay.Stub() { private static class DreamOverlay extends IDreamOverlay.Stub { private final WeakReference<DreamOverlayService> mService; DreamOverlay(DreamOverlayService service) { mService = new WeakReference<>(service); } @Override public void getClient(IDreamOverlayClientCallback callback) { try { callback.onDreamOverlayClient( new OverlayClient(DreamOverlayService.this)); callback.onDreamOverlayClient(new OverlayClient(mService)); } catch (RemoteException e) { Log.e(TAG, "could not send client to callback", e); } } }; } private final IDreamOverlay mDreamOverlay = new DreamOverlay(this); public DreamOverlayService() { } Loading @@ -195,6 +212,12 @@ public abstract class DreamOverlayService extends Service { } } @Override public void onDestroy() { mCurrentClient = null; super.onDestroy(); } @Nullable @Override public final IBinder onBind(@NonNull Intent intent) { Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayContainerViewControllerTest.java +10 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,7 @@ 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; Loading Loading @@ -324,4 +325,13 @@ 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()); } }
packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayServiceTest.kt +3 −0 Original line number Diff line number Diff line Loading @@ -596,6 +596,9 @@ class DreamOverlayServiceTest : SysuiTestCase() { // are created. verify(mDreamOverlayComponent).getDreamOverlayContainerViewController() verify(mAmbientTouchComponent).getTouchMonitor() // Verify DreamOverlayContainerViewController is destroyed. verify(mDreamOverlayContainerViewController).destroy() } @Test Loading
packages/SystemUI/src/com/android/systemui/ambient/touch/TouchHandler.java +5 −0 Original line number Diff line number Diff line Loading @@ -122,4 +122,9 @@ public interface TouchHandler { * @param session */ void onSessionStart(TouchSession session); /** * Called when the handler is being torn down. */ default void onDestroy() {} }
packages/SystemUI/src/com/android/systemui/ambient/touch/TouchMonitor.java +4 −0 Original line number Diff line number Diff line Loading @@ -581,6 +581,10 @@ public class TouchMonitor { mBoundsFlow.cancel(new CancellationException()); } for (TouchHandler handler : mHandlers) { handler.onDestroy(); } mInitialized = false; } Loading