214 lines
9 KiB
Java
214 lines
9 KiB
Java
package androidx.media;
|
|
|
|
import android.media.AudioAttributes;
|
|
import android.media.AudioFocusRequest;
|
|
import android.media.AudioManager;
|
|
import android.os.Build;
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.os.Message;
|
|
import androidx.annotation.DoNotInline;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.RequiresApi;
|
|
import androidx.core.util.ObjectsCompat;
|
|
import androidx.media.AudioAttributesCompat;
|
|
import b.d.b.a.a;
|
|
import java.util.Objects;
|
|
/* loaded from: classes.dex */
|
|
public class AudioFocusRequestCompat {
|
|
public static final AudioAttributesCompat FOCUS_DEFAULT_ATTR = new AudioAttributesCompat.Builder().setUsage(1).build();
|
|
private final AudioAttributesCompat mAudioAttributesCompat;
|
|
private final Handler mFocusChangeHandler;
|
|
private final int mFocusGain;
|
|
private final Object mFrameworkAudioFocusRequest;
|
|
private final AudioManager.OnAudioFocusChangeListener mOnAudioFocusChangeListener;
|
|
private final boolean mPauseOnDuck;
|
|
|
|
@RequiresApi(26)
|
|
/* loaded from: classes.dex */
|
|
public static class Api26Impl {
|
|
private Api26Impl() {
|
|
}
|
|
|
|
@DoNotInline
|
|
public static AudioFocusRequest createInstance(int i, AudioAttributes audioAttributes, boolean z2, AudioManager.OnAudioFocusChangeListener onAudioFocusChangeListener, Handler handler) {
|
|
return new AudioFocusRequest.Builder(i).setAudioAttributes(audioAttributes).setWillPauseWhenDucked(z2).setOnAudioFocusChangeListener(onAudioFocusChangeListener, handler).build();
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
public static final class Builder {
|
|
private AudioAttributesCompat mAudioAttributesCompat;
|
|
private Handler mFocusChangeHandler;
|
|
private int mFocusGain;
|
|
private AudioManager.OnAudioFocusChangeListener mOnAudioFocusChangeListener;
|
|
private boolean mPauseOnDuck;
|
|
|
|
public Builder(int i) {
|
|
this.mAudioAttributesCompat = AudioFocusRequestCompat.FOCUS_DEFAULT_ATTR;
|
|
setFocusGain(i);
|
|
}
|
|
|
|
public Builder(@NonNull AudioFocusRequestCompat audioFocusRequestCompat) {
|
|
this.mAudioAttributesCompat = AudioFocusRequestCompat.FOCUS_DEFAULT_ATTR;
|
|
if (audioFocusRequestCompat != null) {
|
|
this.mFocusGain = audioFocusRequestCompat.getFocusGain();
|
|
this.mOnAudioFocusChangeListener = audioFocusRequestCompat.getOnAudioFocusChangeListener();
|
|
this.mFocusChangeHandler = audioFocusRequestCompat.getFocusChangeHandler();
|
|
this.mAudioAttributesCompat = audioFocusRequestCompat.getAudioAttributesCompat();
|
|
this.mPauseOnDuck = audioFocusRequestCompat.willPauseWhenDucked();
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("AudioFocusRequestCompat to copy must not be null");
|
|
}
|
|
|
|
private static boolean isValidFocusGain(int i) {
|
|
return i == 1 || i == 2 || i == 3 || i == 4;
|
|
}
|
|
|
|
public AudioFocusRequestCompat build() {
|
|
if (this.mOnAudioFocusChangeListener != null) {
|
|
return new AudioFocusRequestCompat(this.mFocusGain, this.mOnAudioFocusChangeListener, this.mFocusChangeHandler, this.mAudioAttributesCompat, this.mPauseOnDuck);
|
|
}
|
|
throw new IllegalStateException("Can't build an AudioFocusRequestCompat instance without a listener");
|
|
}
|
|
|
|
@NonNull
|
|
public Builder setAudioAttributes(@NonNull AudioAttributesCompat audioAttributesCompat) {
|
|
Objects.requireNonNull(audioAttributesCompat, "Illegal null AudioAttributes");
|
|
this.mAudioAttributesCompat = audioAttributesCompat;
|
|
return this;
|
|
}
|
|
|
|
@NonNull
|
|
public Builder setFocusGain(int i) {
|
|
if (isValidFocusGain(i)) {
|
|
this.mFocusGain = i;
|
|
return this;
|
|
}
|
|
throw new IllegalArgumentException(a.p("Illegal audio focus gain type ", i));
|
|
}
|
|
|
|
@NonNull
|
|
public Builder setOnAudioFocusChangeListener(@NonNull AudioManager.OnAudioFocusChangeListener onAudioFocusChangeListener) {
|
|
return setOnAudioFocusChangeListener(onAudioFocusChangeListener, new Handler(Looper.getMainLooper()));
|
|
}
|
|
|
|
@NonNull
|
|
public Builder setOnAudioFocusChangeListener(@NonNull AudioManager.OnAudioFocusChangeListener onAudioFocusChangeListener, @NonNull Handler handler) {
|
|
if (onAudioFocusChangeListener == null) {
|
|
throw new IllegalArgumentException("OnAudioFocusChangeListener must not be null");
|
|
} else if (handler != null) {
|
|
this.mOnAudioFocusChangeListener = onAudioFocusChangeListener;
|
|
this.mFocusChangeHandler = handler;
|
|
return this;
|
|
} else {
|
|
throw new IllegalArgumentException("Handler must not be null");
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
public Builder setWillPauseWhenDucked(boolean z2) {
|
|
this.mPauseOnDuck = z2;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
public static class OnAudioFocusChangeListenerHandlerCompat implements Handler.Callback, AudioManager.OnAudioFocusChangeListener {
|
|
private static final int FOCUS_CHANGE = 2782386;
|
|
private final Handler mHandler;
|
|
private final AudioManager.OnAudioFocusChangeListener mListener;
|
|
|
|
public OnAudioFocusChangeListenerHandlerCompat(@NonNull AudioManager.OnAudioFocusChangeListener onAudioFocusChangeListener, @NonNull Handler handler) {
|
|
this.mListener = onAudioFocusChangeListener;
|
|
this.mHandler = new Handler(handler.getLooper(), this);
|
|
}
|
|
|
|
@Override // android.os.Handler.Callback
|
|
public boolean handleMessage(Message message) {
|
|
if (message.what != FOCUS_CHANGE) {
|
|
return false;
|
|
}
|
|
this.mListener.onAudioFocusChange(message.arg1);
|
|
return true;
|
|
}
|
|
|
|
@Override // android.media.AudioManager.OnAudioFocusChangeListener
|
|
public void onAudioFocusChange(int i) {
|
|
Handler handler = this.mHandler;
|
|
handler.sendMessage(Message.obtain(handler, FOCUS_CHANGE, i, 0));
|
|
}
|
|
}
|
|
|
|
public AudioFocusRequestCompat(int i, AudioManager.OnAudioFocusChangeListener onAudioFocusChangeListener, Handler handler, AudioAttributesCompat audioAttributesCompat, boolean z2) {
|
|
this.mFocusGain = i;
|
|
this.mFocusChangeHandler = handler;
|
|
this.mAudioAttributesCompat = audioAttributesCompat;
|
|
this.mPauseOnDuck = z2;
|
|
int i2 = Build.VERSION.SDK_INT;
|
|
if (i2 >= 26 || handler.getLooper() == Looper.getMainLooper()) {
|
|
this.mOnAudioFocusChangeListener = onAudioFocusChangeListener;
|
|
} else {
|
|
this.mOnAudioFocusChangeListener = new OnAudioFocusChangeListenerHandlerCompat(onAudioFocusChangeListener, handler);
|
|
}
|
|
if (i2 >= 26) {
|
|
this.mFrameworkAudioFocusRequest = Api26Impl.createInstance(i, getAudioAttributes(), z2, this.mOnAudioFocusChangeListener, handler);
|
|
} else {
|
|
this.mFrameworkAudioFocusRequest = null;
|
|
}
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof AudioFocusRequestCompat)) {
|
|
return false;
|
|
}
|
|
AudioFocusRequestCompat audioFocusRequestCompat = (AudioFocusRequestCompat) obj;
|
|
return this.mFocusGain == audioFocusRequestCompat.mFocusGain && this.mPauseOnDuck == audioFocusRequestCompat.mPauseOnDuck && ObjectsCompat.equals(this.mOnAudioFocusChangeListener, audioFocusRequestCompat.mOnAudioFocusChangeListener) && ObjectsCompat.equals(this.mFocusChangeHandler, audioFocusRequestCompat.mFocusChangeHandler) && ObjectsCompat.equals(this.mAudioAttributesCompat, audioFocusRequestCompat.mAudioAttributesCompat);
|
|
}
|
|
|
|
@RequiresApi(21)
|
|
public AudioAttributes getAudioAttributes() {
|
|
AudioAttributesCompat audioAttributesCompat = this.mAudioAttributesCompat;
|
|
if (audioAttributesCompat != null) {
|
|
return (AudioAttributes) audioAttributesCompat.unwrap();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@NonNull
|
|
public AudioAttributesCompat getAudioAttributesCompat() {
|
|
return this.mAudioAttributesCompat;
|
|
}
|
|
|
|
@RequiresApi(26)
|
|
public AudioFocusRequest getAudioFocusRequest() {
|
|
return (AudioFocusRequest) this.mFrameworkAudioFocusRequest;
|
|
}
|
|
|
|
@NonNull
|
|
public Handler getFocusChangeHandler() {
|
|
return this.mFocusChangeHandler;
|
|
}
|
|
|
|
public int getFocusGain() {
|
|
return this.mFocusGain;
|
|
}
|
|
|
|
@NonNull
|
|
public AudioManager.OnAudioFocusChangeListener getOnAudioFocusChangeListener() {
|
|
return this.mOnAudioFocusChangeListener;
|
|
}
|
|
|
|
public int hashCode() {
|
|
return ObjectsCompat.hash(Integer.valueOf(this.mFocusGain), this.mOnAudioFocusChangeListener, this.mFocusChangeHandler, this.mAudioAttributesCompat, Boolean.valueOf(this.mPauseOnDuck));
|
|
}
|
|
|
|
public boolean willPauseWhenDucked() {
|
|
return this.mPauseOnDuck;
|
|
}
|
|
}
|