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

Commit b6c26cbb authored by Bryce Lee's avatar Bryce Lee Committed by Android (Google) Code Review
Browse files

Merge changes Ic04f62a8,I9bee8b05

* changes:
  Move Lifecycle out of DreamOverlayModule.
  Move HideComplicationTouchHandler out of DreamTouchModule.
parents 20c82558 6eb501e6
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 * Copyright (C) 2022 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,27 +14,21 @@
 * limitations under the License.
 */

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

import com.android.systemui.dreams.touch.DreamTouchHandler;
import com.android.systemui.dreams.touch.HideComplicationTouchHandler;
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import javax.inject.Inject

import dagger.Module;
import dagger.Provides;
import dagger.multibindings.IntoSet;

/**
 * Module for {@link HideComplicationTouchHandler}.
 */
@Module
public class HideComplicationModule {
/**
     * Provides {@link HideComplicationTouchHandler} for inclusion in touch handling over the dream.
 * {@link DreamOverlayLifecycleOwner} is a concrete implementation of {@link LifecycleOwner}, which
 * provides access to an associated {@link LifecycleRegistry}.
 */
    @Provides
    @IntoSet
    public static DreamTouchHandler providesHideComplicationTouchHandler(
            HideComplicationTouchHandler touchHandler) {
        return touchHandler;
class DreamOverlayLifecycleOwner @Inject constructor() : LifecycleOwner {
    val registry: LifecycleRegistry = LifecycleRegistry(this)

    override fun getLifecycle(): Lifecycle {
        return registry
    }
}
+7 −2
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;
import androidx.lifecycle.ViewModelStore;

@@ -85,6 +86,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ

    private final DreamOverlayComponent mDreamOverlayComponent;

    private final DreamOverlayLifecycleOwner mLifecycleOwner;
    private final LifecycleRegistry mLifecycleRegistry;

    private DreamOverlayTouchMonitor mDreamOverlayTouchMonitor;
@@ -130,6 +132,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
    public DreamOverlayService(
            Context context,
            @Main Executor executor,
            DreamOverlayLifecycleOwner lifecycleOwner,
            WindowManager windowManager,
            ComplicationComponent.Factory complicationComponentFactory,
            DreamOverlayComponent.Factory dreamOverlayComponentFactory,
@@ -152,8 +155,10 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
                () -> mExecutor.execute(DreamOverlayService.this::requestExit);

        mComplicationComponent = complicationComponentFactory.create();
        mDreamOverlayComponent = dreamOverlayComponentFactory.create(viewModelStore, host, null);
        mLifecycleRegistry = mDreamOverlayComponent.getLifecycleRegistry();
        mDreamOverlayComponent =
                dreamOverlayComponentFactory.create(lifecycleOwner, viewModelStore, host, null);
        mLifecycleOwner = lifecycleOwner;
        mLifecycleRegistry = mLifecycleOwner.getRegistry();

        mExecutor.execute(() -> setCurrentStateLocked(Lifecycle.State.CREATED));
    }
+5 −2
Original line number Diff line number Diff line
@@ -25,13 +25,15 @@ import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dreams.DreamOverlayNotificationCountProvider;
import com.android.systemui.dreams.complication.dagger.RegisteredComplicationsModule;
import com.android.systemui.dreams.dreamcomplication.dagger.ComplicationComponent;

import dagger.Module;
import dagger.Provides;

import java.util.Optional;

import javax.inject.Named;

import dagger.Module;
import dagger.Provides;

/**
 * Dagger Module providing Dream-related functionality.
@@ -41,6 +43,7 @@ import dagger.Provides;
            LowLightDreamModule.class,
        },
        subcomponents = {
            ComplicationComponent.class,
            DreamOverlayComponent.class,
        })
public interface DreamModule {
+3 −8
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
import android.annotation.Nullable;

import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;
import androidx.lifecycle.ViewModelStore;

import com.android.systemui.dreams.DreamOverlayContainerViewController;
@@ -56,7 +55,9 @@ public interface DreamOverlayComponent {
    /** Simple factory for {@link DreamOverlayComponent}. */
    @Subcomponent.Factory
    interface Factory {
        DreamOverlayComponent create(@BindsInstance ViewModelStore store,
        DreamOverlayComponent create(
                @BindsInstance LifecycleOwner lifecycleOwner,
                @BindsInstance ViewModelStore store,
                @BindsInstance Complication.Host host,
                @BindsInstance @Named(DREAM_TOUCH_HANDLERS) @Nullable
                        Set<DreamTouchHandler> dreamTouchHandlers);
@@ -71,12 +72,6 @@ public interface DreamOverlayComponent {
    /** Builds a {@link DreamOverlayContainerViewController}. */
    DreamOverlayContainerViewController getDreamOverlayContainerViewController();

    /** Builds a {@link androidx.lifecycle.LifecycleRegistry} */
    LifecycleRegistry getLifecycleRegistry();

    /** Builds a {@link androidx.lifecycle.LifecycleOwner} */
    LifecycleOwner getLifecycleOwner();

    /** Builds a {@link DreamOverlayTouchMonitor} */
    DreamOverlayTouchMonitor getDreamOverlayTouchMonitor();
}
+18 −14
Original line number Diff line number Diff line
@@ -23,20 +23,22 @@ import android.view.ViewGroup;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;

import com.android.internal.util.Preconditions;
import com.android.systemui.R;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dreams.DreamOverlayContainerView;
import com.android.systemui.dreams.DreamOverlayStatusBarView;
import com.android.systemui.dreams.complication.Complication;
import com.android.systemui.dreams.dreamcomplication.HideComplicationTouchHandler;
import com.android.systemui.dreams.dreamcomplication.dagger.ComplicationComponent;
import com.android.systemui.dreams.touch.DreamTouchHandler;
import com.android.systemui.touch.TouchInsetManager;

import dagger.Lazy;
import dagger.Module;
import dagger.Provides;
import dagger.multibindings.ElementsIntoSet;
import dagger.multibindings.IntoSet;

import java.util.HashSet;
import java.util.Set;
@@ -250,18 +252,6 @@ public abstract class DreamOverlayModule {
        return (long) resources.getInteger(R.integer.config_dreamOverlayOutBlurDurationMs);
    }

    @Provides
    @DreamOverlayComponent.DreamOverlayScope
    static LifecycleOwner providesLifecycleOwner(Lazy<LifecycleRegistry> lifecycleRegistryLazy) {
        return () -> lifecycleRegistryLazy.get();
    }

    @Provides
    @DreamOverlayComponent.DreamOverlayScope
    static LifecycleRegistry providesLifecycleRegistry(LifecycleOwner lifecycleOwner) {
        return new LifecycleRegistry(lifecycleOwner);
    }

    @Provides
    @DreamOverlayComponent.DreamOverlayScope
    static Lifecycle providesLifecycle(LifecycleOwner lifecycleOwner) {
@@ -274,4 +264,18 @@ public abstract class DreamOverlayModule {
            @Named(DREAM_TOUCH_HANDLERS) @Nullable Set<DreamTouchHandler> touchHandlers) {
        return touchHandlers != null ? touchHandlers : new HashSet<>();
    }

    /**
     * Provides {@link HideComplicationTouchHandler} for inclusion in touch handling over the dream.
     */
    @Provides
    @IntoSet
    public static DreamTouchHandler providesHideComplicationTouchHandler(
            ComplicationComponent.Factory componentFactory,
            Complication.VisibilityController visibilityController,
            TouchInsetManager touchInsetManager) {
        ComplicationComponent component =
                componentFactory.create(visibilityController, touchInsetManager);
        return component.getHideComplicationTouchHandler();
    }
}
Loading