1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-06-24 06:03:25 +00:00
NewPipe/app/src/main/java/org/schabi/newpipe/player/AudioServiceLeakFix.java
2020-04-02 15:57:50 +02:00

30 lines
875 B
Java

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(final Context base) {
super(base);
}
public static ContextWrapper preventLeakOf(final Context base) {
return new AudioServiceLeakFix(base);
}
@Override
public Object getSystemService(final String name) {
if (Context.AUDIO_SERVICE.equals(name)) {
return getApplicationContext().getSystemService(name);
}
return super.getSystemService(name);
}
}