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

Commit 56878caf authored by Yiyi Shen's avatar Yiyi Shen Committed by Android (Google) Code Review
Browse files

Merge "[Cleanup] Clean up legacy broadcast dialog from output switcher" into main

parents 7bef9aff 1817bfbb
Loading
Loading
Loading
Loading
+1 −73
Original line number Diff line number Diff line
@@ -25,13 +25,10 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.content.Intent;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.settingslib.flags.Flags;
import com.android.settingslib.media.MediaOutputConstants;
import com.android.systemui.SysuiTestCase;

@@ -48,13 +45,9 @@ public class MediaOutputDialogReceiverTest extends SysuiTestCase {
    private final MediaOutputDialogManager mMockMediaOutputDialogManager =
            mock(MediaOutputDialogManager.class);

    private final MediaOutputBroadcastDialogManager mMockMediaOutputBroadcastDialogManager =
            mock(MediaOutputBroadcastDialogManager.class);

    @Before
    public void setup() {
        mMediaOutputDialogReceiver = new MediaOutputDialogReceiver(mMockMediaOutputDialogManager,
                mMockMediaOutputBroadcastDialogManager);
        mMediaOutputDialogReceiver = new MediaOutputDialogReceiver(mMockMediaOutputDialogManager);
    }

    @Test
@@ -65,8 +58,6 @@ public class MediaOutputDialogReceiverTest extends SysuiTestCase {

        verify(mMockMediaOutputDialogManager, times(1))
                .createAndShow(eq(getContext().getPackageName()), eq(false), any(), any(), any());
        verify(mMockMediaOutputBroadcastDialogManager, never())
                .createAndShow(any(), anyBoolean(), any());
    }

    @Test
@@ -77,8 +68,6 @@ public class MediaOutputDialogReceiverTest extends SysuiTestCase {

        verify(mMockMediaOutputDialogManager, never())
                .createAndShow(any(), anyBoolean(), any(), any(), any());
        verify(mMockMediaOutputBroadcastDialogManager, never())
                .createAndShow(any(), anyBoolean(), any());
    }

    @Test
@@ -88,63 +77,6 @@ public class MediaOutputDialogReceiverTest extends SysuiTestCase {

        verify(mMockMediaOutputDialogManager, never())
                .createAndShow(any(), anyBoolean(), any(), any(), any());
        verify(mMockMediaOutputBroadcastDialogManager, never())
                .createAndShow(any(), anyBoolean(), any());
    }

    @Test
    @DisableFlags(Flags.FLAG_LEGACY_LE_AUDIO_SHARING)
    public void launchMediaOutputBroadcastDialog_flagOff_broadcastDialogFactoryNotCalled() {
        Intent intent = new Intent(
                MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_BROADCAST_DIALOG);
        intent.putExtra(MediaOutputConstants.EXTRA_PACKAGE_NAME, getContext().getPackageName());
        mMediaOutputDialogReceiver.onReceive(getContext(), intent);

        verify(mMockMediaOutputDialogManager, never())
                .createAndShow(any(), anyBoolean(), any(), any(), any());
        verify(mMockMediaOutputBroadcastDialogManager, never())
                .createAndShow(any(), anyBoolean(), any());
    }

    @Test
    @EnableFlags(Flags.FLAG_LEGACY_LE_AUDIO_SHARING)
    public void launchMediaOutputBroadcastDialog_ExtraPackageName_BroadcastDialogFactoryCalled() {
        Intent intent = new Intent(
                MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_BROADCAST_DIALOG);
        intent.putExtra(MediaOutputConstants.EXTRA_PACKAGE_NAME, getContext().getPackageName());
        mMediaOutputDialogReceiver.onReceive(getContext(), intent);

        verify(mMockMediaOutputDialogManager, never())
                .createAndShow(any(), anyBoolean(), any(), any(), any());
        verify(mMockMediaOutputBroadcastDialogManager, times(1))
                .createAndShow(eq(getContext().getPackageName()), eq(true), any());
    }

    @Test
    @EnableFlags(Flags.FLAG_LEGACY_LE_AUDIO_SHARING)
    public void launchMediaOutputBroadcastDialog_WrongExtraKey_DialogBroadcastFactoryNotCalled() {
        Intent intent = new Intent(
                MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_BROADCAST_DIALOG);
        intent.putExtra("Wrong Package Name Key", getContext().getPackageName());
        mMediaOutputDialogReceiver.onReceive(getContext(), intent);

        verify(mMockMediaOutputDialogManager, never())
                .createAndShow(any(), anyBoolean(), any(), any(), any());
        verify(mMockMediaOutputBroadcastDialogManager, never())
                .createAndShow(any(), anyBoolean(), any());
    }

    @Test
    @EnableFlags(Flags.FLAG_LEGACY_LE_AUDIO_SHARING)
    public void launchMediaOutputBroadcastDialog_NoExtra_BroadcastDialogFactoryNotCalled() {
        Intent intent = new Intent(
                MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_BROADCAST_DIALOG);
        mMediaOutputDialogReceiver.onReceive(getContext(), intent);

        verify(mMockMediaOutputDialogManager, never())
                .createAndShow(any(), anyBoolean(), any(), any(), any());
        verify(mMockMediaOutputBroadcastDialogManager, never())
                .createAndShow(any(), anyBoolean(), any());
    }

    @Test
@@ -156,8 +88,6 @@ public class MediaOutputDialogReceiverTest extends SysuiTestCase {

        verify(mMockMediaOutputDialogManager, never())
                .createAndShow(any(), anyBoolean(), any(), any(), any());
        verify(mMockMediaOutputBroadcastDialogManager, never())
                .createAndShow(any(), anyBoolean(), any());
    }

    @Test
@@ -167,7 +97,5 @@ public class MediaOutputDialogReceiverTest extends SysuiTestCase {

        verify(mMockMediaOutputDialogManager, never())
                .createAndShow(any(), anyBoolean(), any(), any(), any());
        verify(mMockMediaOutputBroadcastDialogManager, never())
                .createAndShow(any(), anyBoolean(), any());
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -581,7 +581,6 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog
    }

    protected void startLeBroadcastDialog() {
        mMediaSwitchingController.launchMediaOutputBroadcastDialog(mDialogView, mBroadcastSender);
        refresh();
    }

+0 −606

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −78
Original line number Diff line number Diff line
/*
 * 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.
 * 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.media.dialog

import android.content.Context
import android.view.View
import com.android.systemui.animation.DialogTransitionAnimator
import com.android.systemui.broadcast.BroadcastSender
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import java.util.concurrent.Executor
import javax.inject.Inject

/** Manager to create and show a [MediaOutputBroadcastDialog]. */
class MediaOutputBroadcastDialogManager
@Inject
constructor(
    private val context: Context,
    private val broadcastSender: BroadcastSender,
    private val dialogTransitionAnimator: DialogTransitionAnimator,
    private val mediaSwitchingControllerFactory: MediaSwitchingController.Factory,
    @Main private val mainExecutor: Executor,
    @Background private val backgroundExecutor: Executor,
) {
    var mediaOutputBroadcastDialog: MediaOutputBroadcastDialog? = null

    /** Creates a [MediaOutputBroadcastDialog] for the given package. */
    fun createAndShow(packageName: String, aboveStatusBar: Boolean, view: View? = null) {
        // Dismiss the previous dialog, if any.
        mediaOutputBroadcastDialog?.dismiss()

        // TODO: b/321969740 - Populate the userHandle parameter. The user handle is necessary to
        //  disambiguate the same package running on different users.
        val controller =
            mediaSwitchingControllerFactory.create(
                packageName,
                /* userHandle= */ null,
                /* token */ null,
            )
        val dialog =
            MediaOutputBroadcastDialog(
                context,
                aboveStatusBar,
                broadcastSender,
                controller,
                mainExecutor,
                backgroundExecutor,
            )
        mediaOutputBroadcastDialog = dialog

        // Show the dialog.
        if (view != null) {
            dialogTransitionAnimator.showFromView(dialog, view)
        } else {
            dialog.show()
        }
    }

    /** dismiss [MediaOutputBroadcastDialog] if exist. */
    fun dismiss() {
        mediaOutputBroadcastDialog?.dismiss()
        mediaOutputBroadcastDialog = null
    }
}
+4 −23
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.media.dialog

import com.android.settingslib.flags.Flags.legacyLeAudioSharing
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
@@ -27,13 +26,10 @@ import javax.inject.Inject
private const val TAG = "MediaOutputDlgReceiver"
private val DEBUG = Log.isLoggable(TAG, Log.DEBUG)

/**
 * BroadcastReceiver for handling media output intent
 */
class MediaOutputDialogReceiver @Inject constructor(
        private val mediaOutputDialogManager: MediaOutputDialogManager,
        private val mediaOutputBroadcastDialogManager: MediaOutputBroadcastDialogManager
) : BroadcastReceiver() {
/** BroadcastReceiver for handling media output intent */
class MediaOutputDialogReceiver
@Inject
constructor(private val mediaOutputDialogManager: MediaOutputDialogManager) : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        when (intent.action) {
            MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG -> {
@@ -44,12 +40,6 @@ class MediaOutputDialogReceiver @Inject constructor(
            MediaOutputConstants.ACTION_LAUNCH_SYSTEM_MEDIA_OUTPUT_DIALOG -> {
                mediaOutputDialogManager.createAndShowForSystemRouting()
            }
            MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_BROADCAST_DIALOG -> {
                if (!legacyLeAudioSharing()) return
                val packageName: String? =
                    intent.getStringExtra(MediaOutputConstants.EXTRA_PACKAGE_NAME)
                launchMediaOutputBroadcastDialogIfPossible(packageName)
            }
        }
    }

@@ -60,13 +50,4 @@ class MediaOutputDialogReceiver @Inject constructor(
            Log.e(TAG, "Unable to launch media output dialog. Package name is empty.")
        }
    }

    private fun launchMediaOutputBroadcastDialogIfPossible(packageName: String?) {
        if (!packageName.isNullOrEmpty()) {
            mediaOutputBroadcastDialogManager.createAndShow(
                    packageName, aboveStatusBar = true, view = null)
        } else if (DEBUG) {
            Log.e(TAG, "Unable to launch media output broadcast dialog. Package name is empty.")
        }
    }
}
Loading