Skip to content

Commit

Permalink
Downgrade AudioManagerCompat errors to warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-signal committed May 29, 2020
1 parent e55d800 commit fc7be87
Showing 1 changed file with 11 additions and 6 deletions.
Expand Up @@ -10,10 +10,13 @@
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.util.ServiceUtil;

public abstract class AudioManagerCompat {

private static final String TAG = Log.tag(AudioManagerCompat.class);

protected final AudioManager audioManager;

private AudioManagerCompat(@NonNull Context context) {
Expand Down Expand Up @@ -59,7 +62,8 @@ public SoundPool createSoundPool() {
@Override
public void requestCallAudioFocus() {
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)
Expand All @@ -69,20 +73,21 @@ public void requestCallAudioFocus() {
int result = audioManager.requestAudioFocus(audioFocusRequest);

if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
throw new IllegalStateException("Got " + result);
Log.w(TAG, "Audio focus not granted. Result code: " + result);
}
}

@Override
public void abandonCallAudioFocus() {
if (audioFocusRequest == null) {
throw new IllegalStateException("Not focused.");
Log.w(TAG, "Don't currently have audio focus. Ignoring...");
return;
}

int result = audioManager.abandonAudioFocusRequest(audioFocusRequest);

if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
throw new IllegalStateException("Got " + result);
Log.w(TAG, "Audio focus abandon failed. Result code: " + result);
}

audioFocusRequest = null;
Expand Down Expand Up @@ -127,7 +132,7 @@ public void requestCallAudioFocus() {
int result = audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
throw new IllegalStateException("Got " + result);
Log.w(TAG, "Audio focus not granted. Result code: " + result);
}
}

Expand All @@ -136,7 +141,7 @@ public void abandonCallAudioFocus() {
int result = audioManager.abandonAudioFocus(null);

if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
throw new IllegalStateException("Got " + result);
Log.w(TAG, "Audio focus abandon failed. Result code: " + result);
}
}
}
Expand Down

0 comments on commit fc7be87

Please sign in to comment.