Route speaker via speaker and headset when tapping speaker button in NUI VM

Clicking the speaker button in the NUI VM for a voicemail entry alternates playing the audio via the speaker and headset. This CL does not change the state of the speaker icon, that will be done in a follow up CL (cl/183175378) and the todo for that has been added.

Bug: 69858226
Test: N/A
PiperOrigin-RevId: 183304029
Change-Id: I3a55e62ab8d1203f659a45db9534fd69deda122f
diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailMediaPlayerView.java b/java/com/android/dialer/voicemail/listui/NewVoicemailMediaPlayerView.java
index 66a6fea..37a8dc8 100644
--- a/java/com/android/dialer/voicemail/listui/NewVoicemailMediaPlayerView.java
+++ b/java/com/android/dialer/voicemail/listui/NewVoicemailMediaPlayerView.java
@@ -21,6 +21,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.database.Cursor;
+import android.media.AudioManager;
 import android.net.Uri;
 import android.provider.VoicemailContract;
 import android.provider.VoicemailContract.Voicemails;
@@ -452,6 +453,19 @@
               "NewVoicemailMediaPlayer.speakerButtonListener",
               "speaker request for voicemailUri: %s",
               voicemailUri.toString());
+          AudioManager audioManager =
+              (AudioManager) getContext().getSystemService(AudioManager.class);
+          audioManager.setMode(AudioManager.STREAM_MUSIC);
+          if (audioManager.isSpeakerphoneOn()) {
+            LogUtil.i(
+                "NewVoicemailMediaPlayer.phoneButtonListener", "speaker was on, turning it off");
+            audioManager.setSpeakerphoneOn(false);
+          } else {
+            LogUtil.i(
+                "NewVoicemailMediaPlayer.phoneButtonListener", "speaker was off, turning it on");
+            audioManager.setSpeakerphoneOn(true);
+          }
+          // TODO(uabdullah): Handle colors of speaker icon when speaker is on and off.
         }
       };