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

Commit c3fe8d87 authored by Hugh Chen's avatar Hugh Chen
Browse files

Fix output switcher will display previous media session

Before this CL, the same request code will cause intent to
be cached. It will cause the output switcher to display the
previous media session.

This CL uses the package name as an unique request code to
fix this issue.

Bug: 169077753
Test: make -j42 RunSettingsRoboTests
Change-Id: Iebfc7904609e243d5bf0222307bae98a952a3331
parent c4ae7696
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.media.session.MediaController;
import android.net.Uri;
import android.text.TextUtils;

import androidx.annotation.VisibleForTesting;
import androidx.core.graphics.drawable.IconCompat;
@@ -62,8 +63,12 @@ public class MediaOutputIndicatorSlice implements CustomSliceable {
                com.android.internal.R.drawable.ic_settings_bluetooth);
        final CharSequence title = mContext.getString(R.string.media_output_label_title,
                Utils.getApplicationLabel(mContext, getWorker().getPackageName()));
        final int requestCode = TextUtils.isEmpty(getWorker().getPackageName())
                ? 0
                : getWorker().getPackageName().hashCode();
        final PendingIntent primaryActionIntent = PendingIntent.getActivity(mContext,
                0 /* requestCode */, getMediaOutputSliceIntent(), FLAG_UPDATE_CURRENT);
                requestCode,
                getMediaOutputSliceIntent(), FLAG_UPDATE_CURRENT);
        final SliceAction primarySliceAction = SliceAction.createDeeplink(
                primaryActionIntent, icon, ListBuilder.ICON_IMAGE, title);
        @ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
+4 −2
Original line number Diff line number Diff line
@@ -257,9 +257,11 @@ public class MediaOutputSlice implements CustomSliceable {
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                .putExtra(MediaOutputSliceConstants.EXTRA_PACKAGE_NAME,
                        getWorker().getPackageName());

        final int requestCode = TextUtils.isEmpty(getWorker().getPackageName())
                ? 0
                : getWorker().getPackageName().hashCode();
        return SliceAction.createDeeplink(
                PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */),
                PendingIntent.getActivity(mContext, requestCode, intent, 0 /* flags */),
                IconCompat.createWithResource(mContext, R.drawable.ic_add_blue_24dp),
                ListBuilder.ICON_IMAGE,
                mContext.getText(R.string.add));
+2 −1
Original line number Diff line number Diff line
@@ -151,8 +151,9 @@ public class RemoteMediaSlice implements CustomSliceable {
                .putExtra(MediaOutputSliceConstants.EXTRA_PACKAGE_NAME, packageName);
        final IconCompat icon = IconCompat.createWithResource(mContext,
                R.drawable.ic_volume_remote);
        final int requestCode = TextUtils.isEmpty(packageName) ? 0 : packageName.hashCode();
        final PendingIntent primaryActionIntent = PendingIntent.getActivity(mContext,
                0 /* requestCode */, intent, 0 /* flags */);
                requestCode, intent, 0 /* flags */);
        final SliceAction primarySliceAction = SliceAction.createDeeplink(
                primaryActionIntent, icon, ListBuilder.ICON_IMAGE,
                mContext.getString(R.string.media_output_label_title,