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

Commit 6841e717 authored by Vasyl Gello's avatar Vasyl Gello
Browse files

InCallUI: improve in-call UI for different supported routes

On some devices, there is no earpiece route available, and the speaker
is the default audio output. To make in-call UI correctly operate on
such devices, the following changes are introduced:

* the "earpiece handset" output icon becomes hidden from the list of
  choices in the audio button if no earpiece route is supported

* if device does not support earpiece route but wired headset is
  plugged in, the "earpiece handset" output icon becomes visible
  to reflect the wired headset as an actual call audio output

* the text option of earpiece becomes hidden from choices if the
  device does not support earpiece route

* audio button is shown only if there are more than one route is
  present on the device, otherwise it stays hidden

Test:

* On devices with speaker and earpiece routes present, the audio
  button is visible and acts like a speaker toggle

* On devices with speaker and earpiece routes present and wired
  headset plugged in, the audio button is visible and acts as
  a speaker toggle

* On devices with speaker-only or earpiece-only routes present
  and wired headset plugged in, the audio button is visible and
  acts as a speaker toggle

* On devices with speaker and earpiece routes present and
  Bluetooth headset paired, the audio button is visible and acts
  as a multi-state toggle allowing user to choose Bluetooth
  (by default), speaker or handset earpiece

* On devices with speaker-only or earpiece-only routes present
  and Bluetooth headset paired, the audio button is visible and
  acts as a multi-state toggle allowing user to choose Bluetooth
  (by default) and speaker or handset earpiece

* On devices with speaker-only or earpiece-only routes present,
  the audio button is invisible

Change-Id: I9359aaaa44b89f5937cc1a7d9fbd5fe25c71133d
parent d4a6cea1
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -734,6 +734,8 @@ public class CallButtonFragment
    private void updateAudioButtons() {
        final boolean bluetoothSupported = isSupported(CallAudioState.ROUTE_BLUETOOTH);
        final boolean speakerSupported = isSupported(CallAudioState.ROUTE_SPEAKER);
        final boolean earpieceOrWiredHeadsetSupported =
                          isSupported(CallAudioState.ROUTE_WIRED_OR_EARPIECE);

        boolean audioButtonEnabled = false;
        boolean audioButtonChecked = false;
@@ -757,7 +759,7 @@ public class CallButtonFragment
                showBluetoothIcon = true;
            } else if (isAudio(CallAudioState.ROUTE_SPEAKER)) {
                showSpeakerphoneIcon = true;
            } else {
            } else if (earpieceOrWiredHeadsetSupported) {
                showHandsetIcon = true;
                // TODO: if a wired headset is plugged in, that takes precedence
                // over the handset earpiece.  If so, maybe we should show some
@@ -888,8 +890,9 @@ public class CallButtonFragment
        final MenuItem wiredHeadsetItem = menu.findItem(R.id.audio_mode_wired_headset);

        final boolean usingHeadset = isSupported(CallAudioState.ROUTE_WIRED_HEADSET);
        earpieceItem.setVisible(!usingHeadset);
        earpieceItem.setEnabled(!usingHeadset);
        final boolean earpieceSupported = isSupported(CallAudioState.ROUTE_EARPIECE);
        earpieceItem.setVisible(!usingHeadset && earpieceSupported);
        earpieceItem.setEnabled(!usingHeadset && earpieceSupported);
        wiredHeadsetItem.setVisible(usingHeadset);
        wiredHeadsetItem.setEnabled(usingHeadset);
        // TODO: Show the above item (either earpieceItem or wiredHeadsetItem)
+40 −1
Original line number Diff line number Diff line
@@ -194,6 +194,11 @@ public class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButto
    public void onSupportedAudioMode(int mask) {
        if (getUi() != null) {
            getUi().setSupportedAudio(mask);

            // toggle the visibility of audio button
            getUi().showButton(BUTTON_AUDIO, shouldAudioButtonShow());
            getUi().updateButtonStates();
            getUi().updateColors();
        }
    }

@@ -532,6 +537,40 @@ public class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButto
        updateButtonsState(call);
    }

    /**
     * Checks if audio route is supported on device
     *
     */
    private boolean isAudioRouteSupported(int route) {
        return (getSupportedAudio() & route) > 0;
    }

    /**
     * Counts number of supported routes and disables audio button if there is only one
     * route supported (i.e nothing to choose from)
     */
    private boolean shouldAudioButtonShow() {
        int numSupportedRoutes = 0;

        int routes[] = {
            CallAudioState.ROUTE_BLUETOOTH,
            CallAudioState.ROUTE_WIRED_OR_EARPIECE,
            CallAudioState.ROUTE_SPEAKER
        };

        for (int i = 0; i < routes.length; i++) {
            if (isAudioRouteSupported(routes[i])) {
                numSupportedRoutes++;
            }
        }

        if (numSupportedRoutes == 0) {
            Log.e(this, "numSupportedRoutes = 0");
        }

        return (numSupportedRoutes > 1);
    }

    /**
     * Updates the buttons applicable for the UI.
     *
@@ -603,7 +642,7 @@ public class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButto
        boolean showCallRecordOption = recorder.isEnabled()
                && !isVideo && call.getState() == Call.State.ACTIVE;

        ui.showButton(BUTTON_AUDIO, true);
        ui.showButton(BUTTON_AUDIO, shouldAudioButtonShow());
        ui.showButton(BUTTON_SWAP, showSwap);
        ui.showButton(BUTTON_HOLD, showHold);
        ui.setHold(isCallOnHold);