Merge pull request #2718 from ByteHamster/broadcasts

Limit broadcasts to current app
This commit is contained in:
H. Lehmann 2018-06-26 17:31:42 +02:00 committed by GitHub
commit c9c2e68d7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 35 additions and 32 deletions

View File

@ -31,6 +31,7 @@ import android.widget.ListView;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import de.danoeh.antennapod.core.event.ServiceEvent; import de.danoeh.antennapod.core.event.ServiceEvent;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.gui.NotificationUtils; import de.danoeh.antennapod.core.util.gui.NotificationUtils;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
@ -627,8 +628,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
remover.skipOnCompletion = true; remover.skipOnCompletion = true;
int playerStatus = PlaybackPreferences.getCurrentPlayerStatus(); int playerStatus = PlaybackPreferences.getCurrentPlayerStatus();
if(playerStatus == PlaybackPreferences.PLAYER_STATUS_PLAYING) { if(playerStatus == PlaybackPreferences.PLAYER_STATUS_PLAYING) {
sendBroadcast(new Intent( IntentUtils.sendLocalBroadcast(MainActivity.this, PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE);
PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
} }
} }
remover.executeAsync(); remover.executeAsync();

View File

@ -45,6 +45,7 @@ import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.Flavors; import de.danoeh.antennapod.core.util.Flavors;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.ShareUtils; import de.danoeh.antennapod.core.util.ShareUtils;
import de.danoeh.antennapod.core.util.StorageUtils; import de.danoeh.antennapod.core.util.StorageUtils;
import de.danoeh.antennapod.core.util.Supplier; import de.danoeh.antennapod.core.util.Supplier;
@ -862,7 +863,8 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
} }
if (butSkip != null) { if (butSkip != null) {
butSkip.setOnClickListener(v -> sendBroadcast(new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE))); butSkip.setOnClickListener(v ->
IntentUtils.sendLocalBroadcast(MediaplayerActivity.this, PlaybackService.ACTION_SKIP_CURRENT_EPISODE));
} }
} }

View File

@ -48,6 +48,7 @@ import de.danoeh.antennapod.core.service.playback.PlayerStatus;
import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.core.util.playback.Playable;
import de.danoeh.antennapod.core.util.playback.PlaybackController; import de.danoeh.antennapod.core.util.playback.PlaybackController;
import de.danoeh.antennapod.dialog.RenameFeedDialog; import de.danoeh.antennapod.dialog.RenameFeedDialog;
@ -413,8 +414,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem
Log.d(TAG, "Currently playing episode is about to be deleted, skipping"); Log.d(TAG, "Currently playing episode is about to be deleted, skipping");
remover.skipOnCompletion = true; remover.skipOnCompletion = true;
if(controller.getStatus() == PlayerStatus.PLAYING) { if(controller.getStatus() == PlayerStatus.PLAYING) {
sendBroadcast(new Intent( IntentUtils.sendLocalBroadcast(MediaplayerInfoActivity.this, PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE);
PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
} }
} }
} }

View File

@ -6,6 +6,7 @@ import android.widget.Toast;
import com.afollestad.materialdialogs.MaterialDialog; import com.afollestad.materialdialogs.MaterialDialog;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter; import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
@ -86,13 +87,13 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
.startWhenPrepared(true) .startWhenPrepared(true)
.shouldStream(false) .shouldStream(false)
.start(); .start();
context.sendBroadcast(new Intent(PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE)); IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE);
} else if (media.isCurrentlyPaused()) { } else if (media.isCurrentlyPaused()) {
new PlaybackServiceStarter(context, media) new PlaybackServiceStarter(context, media)
.startWhenPrepared(true) .startWhenPrepared(true)
.shouldStream(false) .shouldStream(false)
.start(); .start();
context.sendBroadcast(new Intent(PlaybackService.ACTION_RESUME_PLAY_CURRENT_EPISODE)); IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_RESUME_PLAY_CURRENT_EPISODE);
} else { } else {
DBTasks.playMedia(context, media, false, true, false); DBTasks.playMedia(context, media, false, true, false);
} }

View File

@ -16,6 +16,7 @@ import android.widget.GridView;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.activity.MediaplayerInfoActivity;
import de.danoeh.antennapod.adapter.SubscriptionsAdapter; import de.danoeh.antennapod.adapter.SubscriptionsAdapter;
import de.danoeh.antennapod.core.asynctask.FeedRemover; import de.danoeh.antennapod.core.asynctask.FeedRemover;
import de.danoeh.antennapod.core.dialog.ConfirmationDialog; import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
@ -26,6 +27,7 @@ import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.dialog.RenameFeedDialog; import de.danoeh.antennapod.dialog.RenameFeedDialog;
import rx.Observable; import rx.Observable;
import rx.Subscription; import rx.Subscription;
@ -211,8 +213,8 @@ public class SubscriptionFragment extends Fragment {
remover.skipOnCompletion = true; remover.skipOnCompletion = true;
int playerStatus = PlaybackPreferences.getCurrentPlayerStatus(); int playerStatus = PlaybackPreferences.getCurrentPlayerStatus();
if(playerStatus == PlaybackPreferences.PLAYER_STATUS_PLAYING) { if(playerStatus == PlaybackPreferences.PLAYER_STATUS_PLAYING) {
getActivity().sendBroadcast(new Intent( IntentUtils.sendLocalBroadcast(getContext(), PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE);
PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
} }
} }
remover.executeAsync(); remover.executeAsync();

View File

@ -158,7 +158,7 @@ public class FeedItemMenuHandler {
FeedItem selectedItem) { FeedItem selectedItem) {
switch (menuItemId) { switch (menuItemId) {
case R.id.skip_episode_item: case R.id.skip_episode_item:
context.sendBroadcast(new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE)); IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SKIP_CURRENT_EPISODE);
break; break;
case R.id.remove_item: case R.id.remove_item:
DBWriter.deleteFeedMediaOfItem(context, selectedItem.getMedia().getId()); DBWriter.deleteFeedMediaOfItem(context, selectedItem.getMedia().getId());

View File

@ -9,8 +9,10 @@ import java.util.concurrent.ExecutionException;
import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.service.download.DownloadService;
import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.IntentUtils;
/** Removes a feed in the background. */ /** Removes a feed in the background. */
public class FeedRemover extends AsyncTask<Void, Void, Void> { public class FeedRemover extends AsyncTask<Void, Void, Void> {
@ -41,7 +43,7 @@ public class FeedRemover extends AsyncTask<Void, Void, Void> {
dialog.dismiss(); dialog.dismiss();
} }
if(skipOnCompletion) { if(skipOnCompletion) {
context.sendBroadcast(new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE)); IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SKIP_CURRENT_EPISODE);
} }
} }

View File

@ -65,6 +65,7 @@ import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.FeedSearcher; import de.danoeh.antennapod.core.storage.FeedSearcher;
import de.danoeh.antennapod.core.util.IntList; import de.danoeh.antennapod.core.util.IntList;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.gui.NotificationUtils; import de.danoeh.antennapod.core.util.gui.NotificationUtils;
import de.danoeh.antennapod.core.util.QueueAccess; import de.danoeh.antennapod.core.util.QueueAccess;
import de.danoeh.antennapod.core.util.playback.ExternalMedia; import de.danoeh.antennapod.core.util.playback.ExternalMedia;
@ -699,9 +700,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
} }
Intent statusUpdate = new Intent(ACTION_PLAYER_STATUS_CHANGED); IntentUtils.sendLocalBroadcast(getApplicationContext(), ACTION_PLAYER_STATUS_CHANGED);
// statusUpdate.putExtra(EXTRA_NEW_PLAYER_STATUS, newInfo.playerStatus.ordinal());
sendBroadcast(statusUpdate);
PlayerWidgetJobService.updateWidget(getBaseContext()); PlayerWidgetJobService.updateWidget(getBaseContext());
bluetoothNotifyChange(newInfo, AVRCP_ACTION_PLAYER_STATUS_CHANGED); bluetoothNotifyChange(newInfo, AVRCP_ACTION_PLAYER_STATUS_CHANGED);
bluetoothNotifyChange(newInfo, AVRCP_ACTION_META_CHANGED); bluetoothNotifyChange(newInfo, AVRCP_ACTION_META_CHANGED);
@ -1042,17 +1041,11 @@ public class PlaybackService extends MediaBrowserServiceCompat {
editor.commit(); editor.commit();
} }
/**
* Send ACTION_PLAYER_STATUS_CHANGED without changing the status attribute.
*/
private void postStatusUpdateIntent() {
sendBroadcast(new Intent(ACTION_PLAYER_STATUS_CHANGED));
}
private void sendNotificationBroadcast(int type, int code) { private void sendNotificationBroadcast(int type, int code) {
Intent intent = new Intent(ACTION_PLAYER_NOTIFICATION); Intent intent = new Intent(ACTION_PLAYER_NOTIFICATION);
intent.putExtra(EXTRA_NOTIFICATION_TYPE, type); intent.putExtra(EXTRA_NOTIFICATION_TYPE, type);
intent.putExtra(EXTRA_NOTIFICATION_CODE, code); intent.putExtra(EXTRA_NOTIFICATION_CODE, code);
intent.setPackage(getPackageName());
sendBroadcast(intent); sendBroadcast(intent);
} }

View File

@ -36,6 +36,7 @@ import de.danoeh.antennapod.core.service.download.DownloadStatus;
import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.DownloadError; import de.danoeh.antennapod.core.util.DownloadError;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.LongList;
import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator; import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator;
import de.danoeh.antennapod.core.util.exception.MediaFileNotFoundException; import de.danoeh.antennapod.core.util.exception.MediaFileNotFoundException;
@ -142,8 +143,7 @@ public final class DBTasks {
} catch (MediaFileNotFoundException e) { } catch (MediaFileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
if (media.isPlaying()) { if (media.isPlaying()) {
context.sendBroadcast(new Intent( IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE));
} }
notifyMissingFeedMediaFile(context, media); notifyMissingFeedMediaFile(context, media);
} }

View File

@ -7,6 +7,7 @@ import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import de.danoeh.antennapod.core.util.IntentUtils;
import org.shredzone.flattr4j.model.Flattr; import org.shredzone.flattr4j.model.Flattr;
import java.io.File; import java.io.File;
@ -115,11 +116,8 @@ public class DBWriter {
true); true);
editor.commit(); editor.commit();
} }
if (PlaybackPreferences if (PlaybackPreferences.getCurrentlyPlayingFeedMediaId() == media.getId()) {
.getCurrentlyPlayingFeedMediaId() == media IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
.getId()) {
context.sendBroadcast(new Intent(
PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE));
} }
} }
// Gpodder: queue delete action for synchronization // Gpodder: queue delete action for synchronization
@ -156,8 +154,7 @@ public class DBWriter {
if (PlaybackPreferences.getCurrentlyPlayingMedia() == FeedMedia.PLAYABLE_TYPE_FEEDMEDIA if (PlaybackPreferences.getCurrentlyPlayingMedia() == FeedMedia.PLAYABLE_TYPE_FEEDMEDIA
&& PlaybackPreferences.getLastPlayedFeedId() == feed && PlaybackPreferences.getLastPlayedFeedId() == feed
.getId()) { .getId()) {
context.sendBroadcast(new Intent( IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE));
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putLong( editor.putLong(
PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID, PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID,

View File

@ -9,6 +9,8 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.webkit.URLUtil; import android.webkit.URLUtil;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.util.IntentUtils;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import java.io.File; import java.io.File;
@ -242,6 +244,7 @@ public class DownloadRequester {
Log.d(TAG, "Cancelling download with url " + downloadUrl); Log.d(TAG, "Cancelling download with url " + downloadUrl);
Intent cancelIntent = new Intent(DownloadService.ACTION_CANCEL_DOWNLOAD); Intent cancelIntent = new Intent(DownloadService.ACTION_CANCEL_DOWNLOAD);
cancelIntent.putExtra(DownloadService.EXTRA_DOWNLOAD_URL, downloadUrl); cancelIntent.putExtra(DownloadService.EXTRA_DOWNLOAD_URL, downloadUrl);
cancelIntent.setPackage(context.getPackageName());
context.sendBroadcast(cancelIntent); context.sendBroadcast(cancelIntent);
} }
@ -250,8 +253,7 @@ public class DownloadRequester {
*/ */
public synchronized void cancelAllDownloads(Context context) { public synchronized void cancelAllDownloads(Context context) {
Log.d(TAG, "Cancelling all running downloads"); Log.d(TAG, "Cancelling all running downloads");
context.sendBroadcast(new Intent( IntentUtils.sendLocalBroadcast(context, DownloadService.ACTION_CANCEL_ALL_DOWNLOADS);
DownloadService.ACTION_CANCEL_ALL_DOWNLOADS));
} }
/** /**

View File

@ -23,4 +23,8 @@ public class IntentUtils {
return false; return false;
} }
public static void sendLocalBroadcast(Context context, String action) {
context.sendBroadcast(new Intent(action).setPackage(context.getPackageName()));
}
} }