Skip to content

Commit 92a07a3

Browse files
committed
Use tryBindIfNeeded(), send player started only if player!=null
This commit fixes one way ghost notifications could be produced (although I don't know if there are other ways). This is the call chain that would lead to ghost notifications being created: 1. the system starts `PlayerService` to query information from it, without providing `SHOULD_START_FOREGROUND_EXTRA=true`, so NewPipe does not start the player nor show any notification, as expected 2. the `PlayerHolder::serviceConnection.onServiceConnected()` gets called by the system to inform `PlayerHolder` that the player started 3. `PlayerHolder` notifies `MainActivity` that the player has started (although in fact only the service has started), by sending a `ACTION_PLAYER_STARTED` broadcast 4. `MainActivity` receives the `ACTION_PLAYER_STARTED` broadcast and brings up the mini-player, but then also tries to make `PlayerHolder` bind to `PlayerService` just in case it was not bound yet, but does so using `PlayerHolder::startService()` instead of the more passive `PlayerHolder::tryBindIfNeeded()` 5. `PlayerHolder::startService()` sends an intent to the `PlayerService` again, this time with `startForegroundService` and with `SHOULD_START_FOREGROUND_EXTRA=true` 6. the `PlayerService` receives the intent and due to `SHOULD_START_FOREGROUND_EXTRA=true` decides to start up the player and show a dummy notification Steps 3 and 4 are wrong, and this commit fixes them: 3. `PlayerHolder` will now broadcast `ACTION_PLAYER_STARTED` when the service connects, only if the player is not-null 4. `PlayerHolder::tryBindIfNeeded()` is now used to passively try to bind, instead of `PlayerHolder::startService()`
1 parent eed09f8 commit 92a07a3

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,10 +1416,8 @@ public void onReceive(final Context context, final Intent intent) {
14161416
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
14171417
}
14181418
// Rebound to the service if it was closed via notification or mini player
1419-
if (!playerHolder.isBound()) {
1420-
playerHolder.startService(
1421-
false, VideoDetailFragment.this);
1422-
}
1419+
playerHolder.setListener(VideoDetailFragment.this);
1420+
playerHolder.tryBindIfNeeded(context);
14231421
break;
14241422
}
14251423
}

app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,11 @@ public void onServiceConnected(final ComponentName compName, final IBinder servi
192192
startPlayerListener();
193193
// ^ will call listener.onPlayerConnected() down the line if there is an active player
194194

195-
// notify the main activity that binding the service has completed, so that it can
196-
// open the bottom mini-player
197-
NavigationHelper.sendPlayerStartedEvent(localBinder.getService());
195+
if (playerService != null && playerService.getPlayer() != null) {
196+
// notify the main activity that binding the service has completed and that there is
197+
// a player, so that it can open the bottom mini-player
198+
NavigationHelper.sendPlayerStartedEvent(localBinder.getService());
199+
}
198200
}
199201
}
200202

0 commit comments

Comments
 (0)