Downgrade AudioManagerCompat errors to warnings.

This commit is contained in:
Alex Hart 2020-05-29 10:31:36 -03:00 committed by GitHub
parent e55d8007fc
commit fc7be87468
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,10 +10,13 @@ import android.os.Build;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.util.ServiceUtil; import org.thoughtcrime.securesms.util.ServiceUtil;
public abstract class AudioManagerCompat { public abstract class AudioManagerCompat {
private static final String TAG = Log.tag(AudioManagerCompat.class);
protected final AudioManager audioManager; protected final AudioManager audioManager;
private AudioManagerCompat(@NonNull Context context) { private AudioManagerCompat(@NonNull Context context) {
@ -59,7 +62,8 @@ public abstract class AudioManagerCompat {
@Override @Override
public void requestCallAudioFocus() { public void requestCallAudioFocus() {
if (audioFocusRequest != null) { if (audioFocusRequest != null) {
throw new IllegalStateException("Already focused."); Log.w(TAG, "Already requested audio focus. Ignoring...");
return;
} }
audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT) audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT)
@ -69,20 +73,21 @@ public abstract class AudioManagerCompat {
int result = audioManager.requestAudioFocus(audioFocusRequest); int result = audioManager.requestAudioFocus(audioFocusRequest);
if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
throw new IllegalStateException("Got " + result); Log.w(TAG, "Audio focus not granted. Result code: " + result);
} }
} }
@Override @Override
public void abandonCallAudioFocus() { public void abandonCallAudioFocus() {
if (audioFocusRequest == null) { if (audioFocusRequest == null) {
throw new IllegalStateException("Not focused."); Log.w(TAG, "Don't currently have audio focus. Ignoring...");
return;
} }
int result = audioManager.abandonAudioFocusRequest(audioFocusRequest); int result = audioManager.abandonAudioFocusRequest(audioFocusRequest);
if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
throw new IllegalStateException("Got " + result); Log.w(TAG, "Audio focus abandon failed. Result code: " + result);
} }
audioFocusRequest = null; audioFocusRequest = null;
@ -127,7 +132,7 @@ public abstract class AudioManagerCompat {
int result = audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); int result = audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
throw new IllegalStateException("Got " + result); Log.w(TAG, "Audio focus not granted. Result code: " + result);
} }
} }
@ -136,7 +141,7 @@ public abstract class AudioManagerCompat {
int result = audioManager.abandonAudioFocus(null); int result = audioManager.abandonAudioFocus(null);
if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
throw new IllegalStateException("Got " + result); Log.w(TAG, "Audio focus abandon failed. Result code: " + result);
} }
} }
} }