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

Commit d1a269ba authored by yueg's avatar yueg Committed by Copybara-Service
Browse files

Fix add call button behavior.

Double clicking add call button mutes the call, and going back to in call UI doesn't unmute the call. It's because previousMuteState is set twice. We shouldn't do anything for the second click since the first click makes you leave in call UI.

Also change automaticallyMuted to automaticallyMutedByAddCall to clearly indicate the value is for add call button only.

Test: CallButtonPresenterTest
PiperOrigin-RevId: 196590319
Change-Id: I9f41b1a75ced3900ae0c4fa787f3defaf7f1cbe6
parent c876815d
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -62,13 +62,14 @@ public class CallButtonPresenter
        Listener,
        InCallButtonUiDelegate {

  private static final String KEY_AUTOMATICALLY_MUTED = "incall_key_automatically_muted";
  private static final String KEY_AUTOMATICALLY_MUTED_BY_ADD_CALL =
      "incall_key_automatically_muted_by_add_call";
  private static final String KEY_PREVIOUS_MUTE_STATE = "incall_key_previous_mute_state";

  private final Context context;
  private InCallButtonUi inCallButtonUi;
  private DialerCall call;
  private boolean automaticallyMuted = false;
  private boolean automaticallyMutedByAddCall = false;
  private boolean previousMuteState = false;
  private boolean isInCallButtonUiReady;
  private PhoneAccountHandle otherAccount;
@@ -276,8 +277,14 @@ public class CallButtonPresenter
            DialerImpression.Type.IN_CALL_ADD_CALL_BUTTON_PRESSED,
            call.getUniqueCallId(),
            call.getTimeAddedMs());
    if (automaticallyMutedByAddCall) {
      // Since clicking add call button brings user to MainActivity and coming back refreshes mute
      // state, add call button should only be clicked once during InCallActivity shows. Otherwise,
      // we set previousMuteState wrong.
      return;
    }
    // Automatically mute the current call
    automaticallyMuted = true;
    automaticallyMutedByAddCall = true;
    previousMuteState = AudioModeProvider.getInstance().getAudioState().isMuted();
    // Simulate a click on the mute button
    muteClicked(true /* checked */, false /* clickedByUser */);
@@ -540,25 +547,27 @@ public class CallButtonPresenter
  @Override
  public void refreshMuteState() {
    // Restore the previous mute state
    if (automaticallyMuted
    if (automaticallyMutedByAddCall
        && AudioModeProvider.getInstance().getAudioState().isMuted() != previousMuteState) {
      if (inCallButtonUi == null) {
        return;
      }
      muteClicked(previousMuteState, false /* clickedByUser */);
    }
    automaticallyMuted = false;
    automaticallyMutedByAddCall = false;
  }

  @Override
  public void onSaveInstanceState(Bundle outState) {
    outState.putBoolean(KEY_AUTOMATICALLY_MUTED, automaticallyMuted);
    outState.putBoolean(KEY_AUTOMATICALLY_MUTED_BY_ADD_CALL, automaticallyMutedByAddCall);
    outState.putBoolean(KEY_PREVIOUS_MUTE_STATE, previousMuteState);
  }

  @Override
  public void onRestoreInstanceState(Bundle savedInstanceState) {
    automaticallyMuted = savedInstanceState.getBoolean(KEY_AUTOMATICALLY_MUTED, automaticallyMuted);
    automaticallyMutedByAddCall =
        savedInstanceState.getBoolean(
            KEY_AUTOMATICALLY_MUTED_BY_ADD_CALL, automaticallyMutedByAddCall);
    previousMuteState = savedInstanceState.getBoolean(KEY_PREVIOUS_MUTE_STATE, previousMuteState);
  }