Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c9a551fe authored by Bryce Lee's avatar Bryce Lee
Browse files

Refactor touch handling out of dreams

This changelist lifts touch handling Dagger dependencies out of
dream logic so that it can be used in other contexts. The new
Ambient dagger dependencies allow the soon-to-be-renamed
DreamOverlayTouchMonitor and associated DreamTouchHandlers to
work in other environments.

Test: atest DreamOverlayTouchMonitorTest
Test: atest DreamOverlayServiceTest
Flag: NA
Bug: 333885071
Change-Id: I3d19d4c7cca3135d2ca809e4ad2e921a04d129de
parent 804f0c04
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import androidx.test.filters.SmallTest;
import com.android.internal.logging.UiEventLogger;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.ambient.touch.dagger.AmbientTouchComponent;
import com.android.systemui.complication.ComplicationLayoutEngine;
import com.android.systemui.dreams.complication.HideComplicationTouchHandler;
import com.android.systemui.dreams.complication.dagger.ComplicationComponent;
@@ -126,6 +127,12 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
    @Mock
    DreamOverlayComponent mDreamOverlayComponent;

    @Mock
    AmbientTouchComponent.Factory mAmbientTouchComponentFactory;

    @Mock
    AmbientTouchComponent mAmbientTouchComponent;

    @Mock
    DreamOverlayContainerView mDreamOverlayContainerView;

@@ -166,8 +173,6 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
                .thenReturn(mDreamOverlayContainerViewController);
        when(mLifecycleOwner.getRegistry())
                .thenReturn(mLifecycleRegistry);
        when(mDreamOverlayComponent.getDreamOverlayTouchMonitor())
                .thenReturn(mDreamOverlayTouchMonitor);
        when(mComplicationComponentFactory
                .create(any(), any(), any(), any()))
                .thenReturn(mComplicationComponent);
@@ -179,8 +184,11 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
                .create(any(), any()))
                .thenReturn(mDreamComplicationComponent);
        when(mDreamOverlayComponentFactory
                .create(any(), any(), any(), any()))
                .create(any(), any(), any()))
                .thenReturn(mDreamOverlayComponent);
        when(mAmbientTouchComponentFactory.create(any(), any())).thenReturn(mAmbientTouchComponent);
        when(mAmbientTouchComponent.getDreamOverlayTouchMonitor())
                .thenReturn(mDreamOverlayTouchMonitor);
        when(mDreamOverlayContainerViewController.getContainerView())
                .thenReturn(mDreamOverlayContainerView);

@@ -193,6 +201,7 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
                mComplicationComponentFactory,
                mDreamComplicationComponentFactory,
                mDreamOverlayComponentFactory,
                mAmbientTouchComponentFactory,
                mStateController,
                mKeyguardUpdateMonitor,
                mUiEventLogger,
@@ -486,6 +495,7 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
        assertThat(mService.shouldShowComplications()).isFalse();

        clearInvocations(mDreamOverlayComponent);
        clearInvocations(mAmbientTouchComponent);
        clearInvocations(mWindowManager);

        // New dream starting with dream complications showing. Note that when a new dream is
@@ -505,7 +515,7 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
        // Verify that new instances of overlay container view controller and overlay touch monitor
        // are created.
        verify(mDreamOverlayComponent).getDreamOverlayContainerViewController();
        verify(mDreamOverlayComponent).getDreamOverlayTouchMonitor();
        verify(mAmbientTouchComponent).getDreamOverlayTouchMonitor();
    }

    @Test
+10 −15
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 * Copyright (C) 2024 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.
@@ -14,20 +14,15 @@
 * limitations under the License.
 */

package com.android.systemui.dreams.touch.dagger;
package com.android.systemui.ambient.dagger

import dagger.Module;
import com.android.systemui.ambient.touch.dagger.AmbientTouchComponent
import com.android.systemui.dreams.touch.dagger.InputSessionComponent
import dagger.Module

/**
 * {@link DreamTouchModule} encapsulates dream touch-related components.
 */
@Module(includes = {
            BouncerSwipeModule.class,
            ShadeModule.class,
        }, subcomponents = {
            InputSessionComponent.class,
})
public interface DreamTouchModule {
    String INPUT_SESSION_NAME = "INPUT_SESSION_NAME";
    String PILFER_ON_GESTURE_CONSUME = "PILFER_ON_GESTURE_CONSUME";
@Module(subcomponents = [AmbientTouchComponent::class, InputSessionComponent::class])
interface AmbientModule {
    companion object {
        const val TOUCH_HANDLERS = "touch_handlers"
    }
}
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.ambient.touch.dagger

import androidx.lifecycle.LifecycleOwner
import com.android.systemui.ambient.dagger.AmbientModule.Companion.TOUCH_HANDLERS
import com.android.systemui.dreams.touch.DreamOverlayTouchMonitor
import com.android.systemui.dreams.touch.DreamTouchHandler
import com.android.systemui.dreams.touch.dagger.BouncerSwipeModule
import com.android.systemui.dreams.touch.dagger.ShadeModule
import dagger.BindsInstance
import dagger.Subcomponent
import javax.inject.Named

/**
 * {@link AmbientTouchComponent} can be used for setting up a touch environment over the entire
 * display surface. This allows for implementing behaviors such as swiping up to bring up the
 * bouncer.
 */
@Subcomponent(modules = [AmbientTouchModule::class, ShadeModule::class, BouncerSwipeModule::class])
interface AmbientTouchComponent {
    @Subcomponent.Factory
    interface Factory {
        fun create(
            @BindsInstance lifecycleOwner: LifecycleOwner,
            @BindsInstance
            @Named(TOUCH_HANDLERS)
            dreamTouchHandlers: Set<@JvmSuppressWildcards DreamTouchHandler>
        ): AmbientTouchComponent
    }

    /** Builds a [DreamOverlayTouchMonitor] */
    fun getDreamOverlayTouchMonitor(): DreamOverlayTouchMonitor
}
+48 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.ambient.touch.dagger

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import com.android.systemui.ambient.dagger.AmbientModule
import com.android.systemui.dreams.touch.DreamTouchHandler
import dagger.Module
import dagger.Provides
import dagger.multibindings.ElementsIntoSet
import javax.inject.Named

@Module
interface AmbientTouchModule {
    companion object {
        @JvmStatic
        @Provides
        fun providesLifecycle(lifecycleOwner: LifecycleOwner): Lifecycle {
            return lifecycleOwner.lifecycle
        }

        @Provides
        @ElementsIntoSet
        fun providesDreamTouchHandlers(
            @Named(AmbientModule.TOUCH_HANDLERS)
            touchHandlers: Set<@JvmSuppressWildcards DreamTouchHandler>
        ): Set<@JvmSuppressWildcards DreamTouchHandler> {
            return touchHandlers
        }

        const val INPUT_SESSION_NAME = "INPUT_SESSION_NAME"
        const val PILFER_ON_GESTURE_CONSUME = "PILFER_ON_GESTURE_CONSUME"
    }
}
+4 −2
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.systemui.CameraProtectionModule;
import com.android.systemui.SystemUISecondaryUserService;
import com.android.systemui.accessibility.AccessibilityModule;
import com.android.systemui.accessibility.data.repository.AccessibilityRepositoryModule;
import com.android.systemui.ambient.dagger.AmbientModule;
import com.android.systemui.appops.dagger.AppOpsModule;
import com.android.systemui.assist.AssistModule;
import com.android.systemui.authentication.AuthenticationModule;
@@ -162,14 +163,14 @@ import dagger.Provides;
import dagger.multibindings.ClassKey;
import dagger.multibindings.IntoMap;

import kotlinx.coroutines.CoroutineScope;

import java.util.Collections;
import java.util.Optional;
import java.util.concurrent.Executor;

import javax.inject.Named;

import kotlinx.coroutines.CoroutineScope;

/**
 * A dagger module for injecting components of System UI that are required by System UI.
 *
@@ -183,6 +184,7 @@ import kotlinx.coroutines.CoroutineScope;
@Module(includes = {
        AccessibilityModule.class,
        AccessibilityRepositoryModule.class,
        AmbientModule.class,
        AppOpsModule.class,
        AssistModule.class,
        AuthenticationModule.class,
Loading