mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-24 17:10:33 +00:00
Fix AudioManager memory leak
This commit is contained in:
parent
e69c45a246
commit
15142c1ec3
@ -0,0 +1,30 @@
|
|||||||
|
package org.schabi.newpipe.player;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.ContextWrapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fixes a leak caused by AudioManager using an Activity context.
|
||||||
|
* Tracked at https://android-review.googlesource.com/#/c/140481/1 and
|
||||||
|
* https://github.com/square/leakcanary/issues/205
|
||||||
|
* Source:
|
||||||
|
* https://gist.github.com/jankovd/891d96f476f7a9ce24e2
|
||||||
|
*/
|
||||||
|
public class AudioServiceLeakFix extends ContextWrapper {
|
||||||
|
|
||||||
|
AudioServiceLeakFix(Context base) {
|
||||||
|
super(base);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ContextWrapper preventLeakOf(Context base) {
|
||||||
|
return new AudioServiceLeakFix(base);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getSystemService(String name) {
|
||||||
|
if (Context.AUDIO_SERVICE.equals(name)) {
|
||||||
|
return getApplicationContext().getSystemService(name);
|
||||||
|
}
|
||||||
|
return super.getSystemService(name);
|
||||||
|
}
|
||||||
|
}
|
@ -130,6 +130,11 @@ public final class BackgroundPlayer extends Service {
|
|||||||
onClose();
|
onClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void attachBaseContext(Context base) {
|
||||||
|
super.attachBaseContext(AudioServiceLeakFix.preventLeakOf(base));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
return mBinder;
|
return mBinder;
|
||||||
|
@ -241,6 +241,11 @@ public final class MainVideoPlayer extends AppCompatActivity
|
|||||||
isBackPressed = false;
|
isBackPressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void attachBaseContext(Context newBase) {
|
||||||
|
super.attachBaseContext(AudioServiceLeakFix.preventLeakOf(newBase));
|
||||||
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// State Saving
|
// State Saving
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
@ -181,6 +181,11 @@ public final class PopupVideoPlayer extends Service {
|
|||||||
closePopup();
|
closePopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void attachBaseContext(Context base) {
|
||||||
|
super.attachBaseContext(AudioServiceLeakFix.preventLeakOf(base));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
return mBinder;
|
return mBinder;
|
||||||
|
Loading…
Reference in New Issue
Block a user