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

Commit 5374961e authored by Tom Hsu's avatar Tom Hsu Committed by Android (Google) Code Review
Browse files

Merge "CP partial ag/26460595 for coroutine instance." into 24D1-dev

parents 6bf22b6b a43b57f2
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -68,13 +68,15 @@ import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.wifitrackerlib.WifiEntry;

import java.util.List;
import java.util.concurrent.Executor;

import dagger.assisted.Assisted;
import dagger.assisted.AssistedFactory;
import dagger.assisted.AssistedInject;

import kotlinx.coroutines.CoroutineScope;

import java.util.List;
import java.util.concurrent.Executor;

/**
 * Dialog for showing mobile network, connected Wi-Fi network and Wi-Fi networks.
 */
@@ -165,7 +167,8 @@ public class InternetDialogDelegate implements
        InternetDialogDelegate create(
                @Assisted(ABOVE_STATUS_BAR) boolean aboveStatusBar,
                @Assisted(CAN_CONFIG_MOBILE_DATA) boolean canConfigMobileData,
                @Assisted(CAN_CONFIG_WIFI) boolean canConfigWifi);
                @Assisted(CAN_CONFIG_WIFI) boolean canConfigWifi,
                @Assisted CoroutineScope coroutineScope);
    }

    @AssistedInject
@@ -176,6 +179,7 @@ public class InternetDialogDelegate implements
            @Assisted(ABOVE_STATUS_BAR) boolean canConfigMobileData,
            @Assisted(CAN_CONFIG_MOBILE_DATA) boolean canConfigWifi,
            @Assisted(CAN_CONFIG_WIFI) boolean aboveStatusBar,
            @Assisted CoroutineScope coroutineScope,
            UiEventLogger uiEventLogger,
            DialogTransitionAnimator dialogTransitionAnimator,
            @Main Handler handler,
+30 −13
Original line number Diff line number Diff line
@@ -21,26 +21,35 @@ import com.android.internal.jank.InteractionJankMonitor
import com.android.systemui.animation.DialogCuj
import com.android.systemui.animation.DialogTransitionAnimator
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.statusbar.phone.SystemUIDialog
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel

private const val TAG = "InternetDialogFactory"
private val DEBUG = Log.isLoggable(TAG, Log.DEBUG)

/**
 * Factory to create [InternetDialogDelegate] objects.
 */
/** Factory to create [InternetDialogDelegate] objects. */
@SysUISingleton
class InternetDialogManager @Inject constructor(
class InternetDialogManager
@Inject
constructor(
    private val dialogTransitionAnimator: DialogTransitionAnimator,
    private val dialogFactory: InternetDialogDelegate.Factory
    private val dialogFactory: InternetDialogDelegate.Factory,
    @Background private val bgDispatcher: CoroutineDispatcher,
) {
    private lateinit var coroutineScope: CoroutineScope
    companion object {
        private const val INTERACTION_JANK_TAG = "internet"
        var dialog: SystemUIDialog? = null
    }

    /** Creates a [InternetDialogDelegate]. The dialog will be animated from [view] if it is not null. */
    /**
     * Creates a [InternetDialogDelegate]. The dialog will be animated from [view] if it is not
     * null.
     */
    fun create(
        aboveStatusBar: Boolean,
        canConfigMobileData: Boolean,
@@ -53,13 +62,18 @@ class InternetDialogManager @Inject constructor(
            }
            return
        } else {
            dialog = dialogFactory.create(
                    aboveStatusBar, canConfigMobileData, canConfigWifi).createDialog()
            coroutineScope = CoroutineScope(bgDispatcher)
            dialog =
                dialogFactory
                    .create(aboveStatusBar, canConfigMobileData, canConfigWifi, coroutineScope)
                    .createDialog()
            if (view != null) {
                dialogTransitionAnimator.showFromView(
                        dialog!!, view,
                    dialog!!,
                    view,
                    animateBackgroundBoundsChange = true,
                    cuj = DialogCuj(
                    cuj =
                        DialogCuj(
                            InteractionJankMonitor.CUJ_SHADE_DIALOG_OPEN,
                            INTERACTION_JANK_TAG
                        )
@@ -74,6 +88,9 @@ class InternetDialogManager @Inject constructor(
        if (DEBUG) {
            Log.d(TAG, "destroyDialog")
        }
        if (dialog != null) {
            coroutineScope.cancel()
        }
        dialog = null
    }
}