Skip to content

Commit

Permalink
Fix PlayerService leakead by Binder instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Stypox committed Jul 14, 2023
1 parent 135f0f7 commit 00257e9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app/src/main/java/org/schabi/newpipe/player/PlayerService.java
Original file line number Diff line number Diff line change
@@ -31,6 +31,8 @@
import org.schabi.newpipe.player.mediasession.MediaSessionPlayerUi;
import org.schabi.newpipe.util.ThemeHelper;

import java.lang.ref.WeakReference;


/**
* One service for all players.
@@ -41,7 +43,7 @@ public final class PlayerService extends Service {

private Player player;

private final IBinder mBinder = new PlayerService.LocalBinder();
private final IBinder mBinder = new PlayerService.LocalBinder(this);


/*//////////////////////////////////////////////////////////////////////////
@@ -134,14 +136,19 @@ public IBinder onBind(final Intent intent) {
return mBinder;
}

public class LocalBinder extends Binder {
public static class LocalBinder extends Binder {
private final WeakReference<PlayerService> playerService;

LocalBinder(final PlayerService playerService) {
this.playerService = new WeakReference<>(playerService);
}

public PlayerService getService() {
return PlayerService.this;
return playerService.get();
}

public Player getPlayer() {
return PlayerService.this.player;
return playerService.get().player;
}
}
}

0 comments on commit 00257e9

Please sign in to comment.