@Test
@Config(minSdk = 26, maxSdk = TARGET_SDK)
public void setAudioAttributes_withNullUsage_releasesAudioFocus_v26() {

  // Create attributes and request audio focus.
  AudioAttributes media = new AudioAttributes.Builder().setUsage(C.USAGE_MEDIA).build();
  Shadows.shadowOf(audioManager)
      .setNextFocusRequestResponse(AudioManager.AUDIOFOCUS_REQUEST_GRANTED);
  assertThat(
          audioFocusManager.setAudioAttributes(
              media, /* playWhenReady= */ true, Player.STATE_READY))
      .isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
  ShadowAudioManager.AudioFocusRequest request =
      Shadows.shadowOf(audioManager).getLastAudioFocusRequest();
  assertThat(getAudioFocusGainFromRequest(request)).isEqualTo(AudioManager.AUDIOFOCUS_GAIN);
  // Ensure that setting null audio attributes with audio focus releases audio focus.
  assertThat(
          audioFocusManager.setAudioAttributes(
              /* audioAttributes= */ null, /* playWhenReady= */ true, Player.STATE_READY))
      .isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
  AudioFocusRequest lastRequest =
      Shadows.shadowOf(audioManager).getLastAbandonedAudioFocusRequest();
  assertThat(lastRequest).isNotNull();
}