mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-06-27 15:43:07 +00:00
PlayerService: runtime-assert that we get passed a service
We directly call the `getService` function after receiving the argument, so resolving the WeakPointer should never return `null` in our case. Of course there could be a race condition in theory, but I feel like if that happens we have bigger problems?
This commit is contained in:
parent
36115c3164
commit
cf8fe95abf
@ -220,11 +220,18 @@ public final class PlayQueueActivity extends AppCompatActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(final ComponentName name, final IBinder service) {
|
||||
public void onServiceConnected(final ComponentName name, final IBinder binder) {
|
||||
Log.d(TAG, "Player service is connected");
|
||||
|
||||
if (service instanceof PlayerService.LocalBinder) {
|
||||
player = ((PlayerService.LocalBinder) service).getService().getPlayer();
|
||||
if (binder instanceof PlayerService.LocalBinder) {
|
||||
@Nullable final PlayerService s =
|
||||
((PlayerService.LocalBinder) binder).getService();
|
||||
if (s == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"PlayerService.LocalBinder.getService() must never be"
|
||||
+ "null after the service connects");
|
||||
}
|
||||
player = s.getPlayer();
|
||||
}
|
||||
|
||||
if (player == null || player.getPlayQueue() == null || player.exoPlayerIsNull()) {
|
||||
|
@ -188,9 +188,15 @@ public final class PlayerHolder {
|
||||
}
|
||||
final PlayerService.LocalBinder localBinder = (PlayerService.LocalBinder) service;
|
||||
|
||||
playerService = localBinder.getService();
|
||||
@Nullable final PlayerService s = localBinder.getService();
|
||||
if (s == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"PlayerService.LocalBinder.getService() must never be"
|
||||
+ "null after the service connects");
|
||||
}
|
||||
playerService = s;
|
||||
if (listener != null) {
|
||||
listener.onServiceConnected(playerService);
|
||||
listener.onServiceConnected(s);
|
||||
getPlayer().ifPresent(p -> listener.onPlayerConnected(p, playAfterConnect));
|
||||
}
|
||||
startPlayerListener();
|
||||
@ -198,7 +204,7 @@ public final class PlayerHolder {
|
||||
|
||||
// notify the main activity that binding the service has completed, so that it can
|
||||
// open the bottom mini-player
|
||||
NavigationHelper.sendPlayerStartedEvent(localBinder.getService());
|
||||
NavigationHelper.sendPlayerStartedEvent(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user