Limit broadcasts to current app

This commit is contained in:
ByteHamster 2018-05-29 23:25:19 +02:00
parent fe92c98661
commit 02186a3f0d
12 changed files with 29 additions and 20 deletions

View File

@ -628,7 +628,8 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
int playerStatus = PlaybackPreferences.getCurrentPlayerStatus();
if(playerStatus == PlaybackPreferences.PLAYER_STATUS_PLAYING) {
sendBroadcast(new Intent(
PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE)
.setPackage(getPackageName()));
}
}
remover.executeAsync();

View File

@ -863,7 +863,8 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
}
if (butSkip != null) {
butSkip.setOnClickListener(v -> sendBroadcast(new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE)));
butSkip.setOnClickListener(v -> sendBroadcast(new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE)
.setPackage(getPackageName())));
}
}

View File

@ -414,7 +414,8 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem
remover.skipOnCompletion = true;
if(controller.getStatus() == PlayerStatus.PLAYING) {
sendBroadcast(new Intent(
PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE)
.setPackage(getPackageName()));
}
}
}

View File

@ -86,13 +86,15 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
.startWhenPrepared(true)
.shouldStream(false)
.start();
context.sendBroadcast(new Intent(PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
context.sendBroadcast(new Intent(PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE)
.setPackage(context.getPackageName()));
} else if (media.isCurrentlyPaused()) {
new PlaybackServiceStarter(context, media)
.startWhenPrepared(true)
.shouldStream(false)
.start();
context.sendBroadcast(new Intent(PlaybackService.ACTION_RESUME_PLAY_CURRENT_EPISODE));
context.sendBroadcast(new Intent(PlaybackService.ACTION_RESUME_PLAY_CURRENT_EPISODE)
.setPackage(context.getPackageName()));
} else {
DBTasks.playMedia(context, media, false, true, false);
}

View File

@ -212,7 +212,8 @@ public class SubscriptionFragment extends Fragment {
int playerStatus = PlaybackPreferences.getCurrentPlayerStatus();
if(playerStatus == PlaybackPreferences.PLAYER_STATUS_PLAYING) {
getActivity().sendBroadcast(new Intent(
PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE)
.setPackage(getContext().getPackageName()));
}
}
remover.executeAsync();

View File

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

View File

@ -41,7 +41,8 @@ public class SPAUtil {
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
if (!prefs.getBoolean(PREF_HAS_QUERIED_SP_APPS, false)) {
appContext.sendBroadcast(new Intent(SPAReceiver.ACTION_SP_APPS_QUERY_FEEDS));
appContext.sendBroadcast(new Intent(SPAReceiver.ACTION_SP_APPS_QUERY_FEEDS)
.setPackage(context.getPackageName()));
if (BuildConfig.DEBUG) Log.d(TAG, "Sending SP_APPS_QUERY_FEEDS intent");
SharedPreferences.Editor editor = prefs.edit();

View File

@ -41,7 +41,8 @@ public class FeedRemover extends AsyncTask<Void, Void, Void> {
dialog.dismiss();
}
if(skipOnCompletion) {
context.sendBroadcast(new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE));
context.sendBroadcast(new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE)
.setPackage(context.getPackageName()));
}
}

View File

@ -701,6 +701,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
Intent statusUpdate = new Intent(ACTION_PLAYER_STATUS_CHANGED);
// statusUpdate.putExtra(EXTRA_NEW_PLAYER_STATUS, newInfo.playerStatus.ordinal());
statusUpdate.setPackage(getPackageName());
sendBroadcast(statusUpdate);
PlayerWidgetJobService.updateWidget(getBaseContext());
bluetoothNotifyChange(newInfo, AVRCP_ACTION_PLAYER_STATUS_CHANGED);
@ -1042,17 +1043,11 @@ public class PlaybackService extends MediaBrowserServiceCompat {
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) {
Intent intent = new Intent(ACTION_PLAYER_NOTIFICATION);
intent.putExtra(EXTRA_NOTIFICATION_TYPE, type);
intent.putExtra(EXTRA_NOTIFICATION_CODE, code);
intent.setPackage(getPackageName());
sendBroadcast(intent);
}

View File

@ -143,7 +143,8 @@ public final class DBTasks {
e.printStackTrace();
if (media.isPlaying()) {
context.sendBroadcast(new Intent(
PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE));
PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE)
.setPackage(context.getPackageName()));
}
notifyMissingFeedMediaFile(context, media);
}

View File

@ -120,7 +120,8 @@ public class DBWriter {
.getCurrentlyPlayingFeedMediaId() == media
.getId()) {
context.sendBroadcast(new Intent(
PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE));
PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE)
.setPackage(context.getPackageName()));
}
}
// Gpodder: queue delete action for synchronization
@ -158,7 +159,8 @@ public class DBWriter {
&& PlaybackPreferences.getLastPlayedFeedId() == feed
.getId()) {
context.sendBroadcast(new Intent(
PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE));
PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE)
.setPackage(context.getPackageName()));
SharedPreferences.Editor editor = prefs.edit();
editor.putLong(
PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID,

View File

@ -242,6 +242,7 @@ public class DownloadRequester {
Log.d(TAG, "Cancelling download with url " + downloadUrl);
Intent cancelIntent = new Intent(DownloadService.ACTION_CANCEL_DOWNLOAD);
cancelIntent.putExtra(DownloadService.EXTRA_DOWNLOAD_URL, downloadUrl);
cancelIntent.setPackage(context.getPackageName());
context.sendBroadcast(cancelIntent);
}
@ -251,7 +252,8 @@ public class DownloadRequester {
public synchronized void cancelAllDownloads(Context context) {
Log.d(TAG, "Cancelling all running downloads");
context.sendBroadcast(new Intent(
DownloadService.ACTION_CANCEL_ALL_DOWNLOADS));
DownloadService.ACTION_CANCEL_ALL_DOWNLOADS)
.setPackage(context.getPackageName()));
}
/**