Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d81206e5 authored by Sohail Nagaraj's avatar Sohail Nagaraj Committed by Sohail Nagaraj (xWF)
Browse files

Handle MediaPlayer creation failure in CallManger

Handle MediaPlayer IllegalStateExcetion without crashing InCallTonePlayer. When the exception is caught,MediaPlayer is initialized to null.

Flag: EXEMPT bugfix
Bug: 406985688

Test: atest TelecomUnitTests
Change-Id: I96a84b6b3a4296c026901030f0ef4a61f87e287c
parent e86130a7
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -750,11 +750,17 @@ public class CallsManager extends Call.ListenerBase
                        mDockManager,
                        asyncRingtonePlayer);
        AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
        InCallTonePlayer.MediaPlayerFactory mediaPlayerFactory =
                (resourceId, attributes) ->
                        new InCallTonePlayer.MediaPlayerAdapterImpl(
                                MediaPlayer.create(mContext, resourceId, attributes,
                                        audioManager.generateAudioSessionId()));
        InCallTonePlayer.MediaPlayerFactory mediaPlayerFactory = (resourceId, attributes) -> {
          MediaPlayer mediaPlayer;
          try {
            mediaPlayer = MediaPlayer.create(
                mContext, resourceId, attributes, audioManager.generateAudioSessionId());
          } catch (IllegalStateException e) {
            Log.e(TAG, e, "Failed to create mediaplayer");
            mediaPlayer = null;
          }
          return new InCallTonePlayer.MediaPlayerAdapterImpl(mediaPlayer);
        };
        InCallTonePlayer.Factory playerFactory = new InCallTonePlayer.Factory(
                callAudioRoutePeripheralAdapter, lock, toneGeneratorFactory, mediaPlayerFactory,
                () -> audioManager.getStreamVolume(AudioManager.STREAM_RING) > 0, featureFlags,