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

Commit 4b698405 authored by Anton Potapov's avatar Anton Potapov Committed by Android (Google) Code Review
Browse files

Merge changes from topic "BC25Volume_core_infra" into main

* changes:
  Add interactors to wrap VolumeDialogController callbacks into flows and make them easier to integrate into the new architecture.
  Add new Volume Dialog dagger and coroutines infra
parents d6d92205 3fbbb096
Loading
Loading
Loading
Loading
+34 −25
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import android.os.Looper;


import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.systemui.CoreStartable;
import com.android.systemui.CoreStartable;
import com.android.systemui.Flags;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.media.dialog.MediaOutputDialogManager;
import com.android.systemui.media.dialog.MediaOutputDialogManager;
import com.android.systemui.plugins.VolumeDialog;
import com.android.systemui.plugins.VolumeDialog;
@@ -40,6 +41,8 @@ import com.android.systemui.volume.VolumeDialogComponent;
import com.android.systemui.volume.VolumeDialogImpl;
import com.android.systemui.volume.VolumeDialogImpl;
import com.android.systemui.volume.VolumePanelDialogReceiver;
import com.android.systemui.volume.VolumePanelDialogReceiver;
import com.android.systemui.volume.VolumeUI;
import com.android.systemui.volume.VolumeUI;
import com.android.systemui.volume.dialog.VolumeDialogPlugin;
import com.android.systemui.volume.dialog.dagger.VolumeDialogPluginComponent;
import com.android.systemui.volume.domain.interactor.VolumeDialogInteractor;
import com.android.systemui.volume.domain.interactor.VolumeDialogInteractor;
import com.android.systemui.volume.domain.interactor.VolumePanelNavigationInteractor;
import com.android.systemui.volume.domain.interactor.VolumePanelNavigationInteractor;
import com.android.systemui.volume.panel.dagger.VolumePanelComponent;
import com.android.systemui.volume.panel.dagger.VolumePanelComponent;
@@ -66,7 +69,8 @@ import dagger.multibindings.IntoSet;
                SpatializerModule.class,
                SpatializerModule.class,
        },
        },
        subcomponents = {
        subcomponents = {
                VolumePanelComponent.class
                VolumePanelComponent.class,
                VolumeDialogPluginComponent.class,
        }
        }
)
)
public interface VolumeModule {
public interface VolumeModule {
@@ -101,6 +105,7 @@ public interface VolumeModule {
    /**  */
    /**  */
    @Provides
    @Provides
    static VolumeDialog provideVolumeDialog(
    static VolumeDialog provideVolumeDialog(
            Lazy<VolumeDialogPlugin> volumeDialogProvider,
            Context context,
            Context context,
            VolumeDialogController volumeDialogController,
            VolumeDialogController volumeDialogController,
            AccessibilityManagerWrapper accessibilityManagerWrapper,
            AccessibilityManagerWrapper accessibilityManagerWrapper,
@@ -118,6 +123,9 @@ public interface VolumeModule {
            VibratorHelper vibratorHelper,
            VibratorHelper vibratorHelper,
            SystemClock systemClock,
            SystemClock systemClock,
            VolumeDialogInteractor interactor) {
            VolumeDialogInteractor interactor) {
        if (Flags.volumeRedesign()) {
            return volumeDialogProvider.get();
        } else {
            VolumeDialogImpl impl = new VolumeDialogImpl(
            VolumeDialogImpl impl = new VolumeDialogImpl(
                    context,
                    context,
                    volumeDialogController,
                    volumeDialogController,
@@ -144,3 +152,4 @@ public interface VolumeModule {
            return impl;
            return impl;
        }
        }
    }
    }
}
+34 −0
Original line number Original line 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.volume.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.ContextThemeWrapper
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.res.R
import javax.inject.Inject

class NewVolumeDialog @Inject constructor(@Application context: Context) :
    Dialog(ContextThemeWrapper(context, R.style.volume_dialog_theme)) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.volume_dialog)
    }
}
+67 −0
Original line number Original line 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.volume.dialog

import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.plugins.VolumeDialog
import com.android.systemui.volume.dialog.dagger.VolumeDialogComponent
import com.android.systemui.volume.dialog.dagger.VolumeDialogPluginComponent
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch

class NewVolumeDialogPlugin
@Inject
constructor(
    @Application private val applicationCoroutineScope: CoroutineScope,
    private val volumeDialogPluginComponentFactory: VolumeDialogPluginComponent.Factory,
) : VolumeDialog {

    private var volumeDialogPluginComponent: VolumeDialogPluginComponent? = null
    private var job: Job? = null

    override fun init(windowType: Int, callback: VolumeDialog.Callback?) {
        job =
            applicationCoroutineScope.launch {
                coroutineScope {
                    volumeDialogPluginComponent = volumeDialogPluginComponentFactory.create(this)
                }
            }
    }

    private fun showDialog() {
        val volumeDialogPluginComponent =
            volumeDialogPluginComponent ?: error("Creating dialog before init was called")
        volumeDialogPluginComponent.coroutineScope().launch {
            coroutineScope {
                val volumeDialogComponent: VolumeDialogComponent =
                    volumeDialogPluginComponent.volumeDialogComponentFactory().create(this)
                with(volumeDialogComponent.volumeDialog()) {
                    setOnDismissListener { volumeDialogComponent.coroutineScope().cancel() }
                    show()
                }
            }
        }
    }

    override fun destroy() {
        job?.cancel()
    }
}
+34 −0
Original line number Original line 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.volume.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.ContextThemeWrapper
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.res.R
import javax.inject.Inject

class VolumeDialog @Inject constructor(@Application context: Context) :
    Dialog(ContextThemeWrapper(context, R.style.volume_dialog_theme)) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.volume_dialog)
    }
}
+67 −0
Original line number Original line 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.volume.dialog

import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.plugins.VolumeDialog
import com.android.systemui.volume.dialog.dagger.VolumeDialogComponent
import com.android.systemui.volume.dialog.dagger.VolumeDialogPluginComponent
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch

class VolumeDialogPlugin
@Inject
constructor(
    @Application private val applicationCoroutineScope: CoroutineScope,
    private val volumeDialogPluginComponentFactory: VolumeDialogPluginComponent.Factory,
) : VolumeDialog {

    private var volumeDialogPluginComponent: VolumeDialogPluginComponent? = null
    private var job: Job? = null

    override fun init(windowType: Int, callback: VolumeDialog.Callback?) {
        job =
            applicationCoroutineScope.launch {
                coroutineScope {
                    volumeDialogPluginComponent = volumeDialogPluginComponentFactory.create(this)
                }
            }
    }

    private fun showDialog() {
        val volumeDialogPluginComponent =
            volumeDialogPluginComponent ?: error("Creating dialog before init was called")
        volumeDialogPluginComponent.coroutineScope().launch {
            coroutineScope {
                val volumeDialogComponent: VolumeDialogComponent =
                    volumeDialogPluginComponent.volumeDialogComponentFactory().create(this)
                with(volumeDialogComponent.volumeDialog()) {
                    setOnDismissListener { volumeDialogComponent.coroutineScope().cancel() }
                    show()
                }
            }
        }
    }

    override fun destroy() {
        job?.cancel()
    }
}
Loading