Made PendingIntent request codes unique

This commit is contained in:
ByteHamster 2020-05-27 11:02:41 +02:00
parent 4b2aa3e8b0
commit 018a91d66c
6 changed files with 40 additions and 27 deletions

View File

@ -5,11 +5,10 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.DownloadAuthenticationActivity;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.adapter.NavListAdapter;
import de.danoeh.antennapod.core.DownloadServiceCallbacks;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.service.download.DownloadRequest;
import de.danoeh.antennapod.fragment.DownloadsFragment;
import de.danoeh.antennapod.fragment.QueueFragment;
@ -24,7 +23,8 @@ public class DownloadServiceCallbacksImpl implements DownloadServiceCallbacks {
Bundle args = new Bundle();
args.putInt(DownloadsFragment.ARG_SELECTED_TAB, DownloadsFragment.POS_RUNNING);
intent.putExtra(MainActivity.EXTRA_FRAGMENT_ARGS, args);
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
return PendingIntent.getActivity(context,
R.id.pending_intent_download_service_notification, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
@Override
@ -32,7 +32,8 @@ public class DownloadServiceCallbacksImpl implements DownloadServiceCallbacks {
final Intent activityIntent = new Intent(context.getApplicationContext(), DownloadAuthenticationActivity.class);
activityIntent.putExtra(DownloadAuthenticationActivity.ARG_DOWNLOAD_REQUEST, request);
activityIntent.putExtra(DownloadAuthenticationActivity.ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL, true);
return PendingIntent.getActivity(context.getApplicationContext(), 0, activityIntent, PendingIntent.FLAG_ONE_SHOT);
return PendingIntent.getActivity(context.getApplicationContext(),
R.id.pending_intent_download_service_auth, activityIntent, PendingIntent.FLAG_ONE_SHOT);
}
@Override
@ -42,14 +43,16 @@ public class DownloadServiceCallbacksImpl implements DownloadServiceCallbacks {
Bundle args = new Bundle();
args.putInt(DownloadsFragment.ARG_SELECTED_TAB, DownloadsFragment.POS_LOG);
intent.putExtra(MainActivity.EXTRA_FRAGMENT_ARGS, args);
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
return PendingIntent.getActivity(context, R.id.pending_intent_download_service_report,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
@Override
public PendingIntent getAutoDownloadReportNotificationContentIntent(Context context) {
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra(MainActivity.EXTRA_FRAGMENT_TAG, QueueFragment.TAG);
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
return PendingIntent.getActivity(context, R.id.pending_intent_download_service_autodownload_report,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
@Override

View File

@ -103,12 +103,8 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
AppWidgetManager manager = AppWidgetManager.getInstance(this);
int[] widgetIds = manager.getAppWidgetIds(playerWidget);
RemoteViews views = new RemoteViews(getPackageName(), R.layout.player_widget);
PendingIntent startMediaplayer = PendingIntent.getActivity(this, 0,
PlaybackService.getPlayerActivityIntent(this), 0);
final PendingIntent startAppPending = PendingIntent.getActivity(this, 0,
PlaybackService.getPlayerActivityIntent(this),
PendingIntent.FLAG_UPDATE_CURRENT);
final PendingIntent startMediaPlayer = PendingIntent.getActivity(this, R.id.pending_intent_player_activity,
PlaybackService.getPlayerActivityIntent(this), PendingIntent.FLAG_UPDATE_CURRENT);
boolean nothingPlaying = false;
Playable media;
@ -122,7 +118,7 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
}
if (media != null) {
views.setOnClickPendingIntent(R.id.layout_left, startMediaplayer);
views.setOnClickPendingIntent(R.id.layout_left, startMediaPlayer);
try {
Bitmap icon = null;
@ -170,8 +166,8 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
if (nothingPlaying) {
// start the app if they click anything
views.setOnClickPendingIntent(R.id.layout_left, startAppPending);
views.setOnClickPendingIntent(R.id.butPlay, startAppPending);
views.setOnClickPendingIntent(R.id.layout_left, startMediaPlayer);
views.setOnClickPendingIntent(R.id.butPlay, startMediaPlayer);
views.setViewVisibility(R.id.txtvProgress, View.GONE);
views.setViewVisibility(R.id.txtvTitle, View.GONE);
views.setViewVisibility(R.id.txtNoPlaying, View.VISIBLE);

View File

@ -542,9 +542,11 @@ public class PlaybackService extends MediaBrowserServiceCompat {
intentAllowThisTime.putExtra(EXTRA_ALLOW_STREAM_THIS_TIME, true);
PendingIntent pendingIntentAllowThisTime;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
pendingIntentAllowThisTime = PendingIntent.getForegroundService(this, 0, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntentAllowThisTime = PendingIntent.getForegroundService(this,
R.id.pending_intent_allow_stream_this_time, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT);
} else {
pendingIntentAllowThisTime = PendingIntent.getService(this, 0, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntentAllowThisTime = PendingIntent.getService(this,
R.id.pending_intent_allow_stream_this_time, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT);
}
Intent intentAlwaysAllow = new Intent(intentAllowThisTime);
@ -552,12 +554,15 @@ public class PlaybackService extends MediaBrowserServiceCompat {
intentAlwaysAllow.putExtra(EXTRA_ALLOW_STREAM_ALWAYS, true);
PendingIntent pendingIntentAlwaysAllow;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
pendingIntentAlwaysAllow = PendingIntent.getForegroundService(this, 0, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntentAlwaysAllow = PendingIntent.getForegroundService(this,
R.id.pending_intent_allow_stream_always, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT);
} else {
pendingIntentAlwaysAllow = PendingIntent.getService(this, 0, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntentAlwaysAllow = PendingIntent.getService(this,
R.id.pending_intent_allow_stream_always, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_USER_ACTION)
NotificationCompat.Builder builder = new NotificationCompat.Builder(this,
NotificationUtils.CHANNEL_ID_USER_ACTION)
.setSmallIcon(R.drawable.ic_stream_white)
.setContentTitle(getString(R.string.confirm_mobile_streaming_notification_title))
.setContentText(getString(R.string.confirm_mobile_streaming_notification_message))
@ -1238,9 +1243,8 @@ public class PlaybackService extends MediaBrowserServiceCompat {
}
}
if (!Thread.currentThread().isInterrupted() && stateManager.hasReceivedValidStartCommand()) {
mediaSession.setSessionActivity(PendingIntent.getActivity(this, 0,
PlaybackService.getPlayerActivityIntent(this),
PendingIntent.FLAG_UPDATE_CURRENT));
mediaSession.setSessionActivity(PendingIntent.getActivity(this, R.id.pending_intent_player_activity,
PlaybackService.getPlayerActivityIntent(this), PendingIntent.FLAG_UPDATE_CURRENT));
try {
mediaSession.setMetadata(builder.build());
} catch (OutOfMemoryError e) {

View File

@ -146,8 +146,8 @@ public class PlaybackServiceNotificationBuilder {
}
private PendingIntent getPlayerActivityPendingIntent() {
return PendingIntent.getActivity(context, 0, PlaybackService.getPlayerActivityIntent(context),
PendingIntent.FLAG_UPDATE_CURRENT);
return PendingIntent.getActivity(context, R.id.pending_intent_player_activity,
PlaybackService.getPlayerActivityIntent(context), PendingIntent.FLAG_UPDATE_CURRENT);
}
private void addActions(NotificationCompat.Builder notification, MediaSessionCompat.Token mediaSessionToken,

View File

@ -488,8 +488,8 @@ public class SyncService extends Worker {
Intent intent = getApplicationContext().getPackageManager().getLaunchIntentForPackage(
getApplicationContext().getPackageName());
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),
R.id.pending_intent_sync_error, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new NotificationCompat.Builder(getApplicationContext(),
NotificationUtils.CHANNEL_ID_ERROR)
.setContentTitle(getApplicationContext().getString(R.string.gpodnetsync_error_title))

View File

@ -25,4 +25,14 @@
<item name="undobar_button" type="id"/>
<item name="undobar_message" type="id"/>
<item name="episode_item_view_holder" type="id"/>
<!-- PendingIntent objects that use the same action but different extras need to use a unique request code -->
<item name="pending_intent_download_service_notification" type="id"/>
<item name="pending_intent_download_service_auth" type="id"/>
<item name="pending_intent_download_service_report" type="id"/>
<item name="pending_intent_download_service_autodownload_report" type="id"/>
<item name="pending_intent_allow_stream_always" type="id"/>
<item name="pending_intent_allow_stream_this_time" type="id"/>
<item name="pending_intent_player_activity" type="id"/>
<item name="pending_intent_sync_error" type="id"/>
</resources>