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

Commit 646d5e67 authored by Shiv Maliyappanahalli's avatar Shiv Maliyappanahalli Committed by Steve Kondik
Browse files

audio: grant focus to qchat application

To achieve QCHAT concurrencies with telephonoy and music player,
QCHAT application should be allowed to run while voice call is
in HOLD/INACTIVE state. Music player should not be granted audio
focus if QCHAT is running.
Add call state, vsid and all_call_states keys so that application
can set/get keyvalues.

Change-Id: Ia8941bf45074dd4edaa9dc236649293496c76e7b
parent ef3c1896
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -1740,6 +1740,38 @@ public class AudioManager {
     */
    public static final int MODE_IN_COMMUNICATION   = AudioSystem.MODE_IN_COMMUNICATION;

    /* Calls states for Voice calls */
    /**
     * @hide Call state for inactive call state.
     */
    public static final int CALL_INACTIVE         = AudioSystem.CALL_INACTIVE;
    /**
     * @hide Call state for active call state.
     */
    public static final int CALL_ACTIVE           = AudioSystem.CALL_ACTIVE;
    /**
     * @hide Call state for hold call state.
     */
    public static final int CALL_HOLD             = AudioSystem.CALL_HOLD;
    /**
     * @hide Call state for local call hold state.
     */
    public static final int CALL_LOCAL_HOLD       = AudioSystem.CALL_LOCAL_HOLD;
    /* Key used in setParameters for VSID and Call_state */
    /**
     * @hide Key for vsid used in setParameters.
     */
    public static final String VSID_KEY           = AudioSystem.VSID_KEY;

    /**
     * @hide Key for call_state used in setParameters.
     */
    public static final String CALL_STATE_KEY     = AudioSystem.CALL_STATE_KEY;

    /**
     * @hide Key for all_call_states used in getParameters.
     */
    public static final String ALL_CALL_STATES_KEY     = AudioSystem.ALL_CALL_STATES_KEY;
    /* Routing bits for setRouting/getRouting API */
    /**
     * Routing audio output to earpiece
+4 −0
Original line number Diff line number Diff line
@@ -102,6 +102,10 @@ class FocusRequester {
        return mStreamType;
    }

    String getClientId() {
        return mClientId;
    }


    private static String focusChangeToString(int focus) {
        switch(focus) {
+30 −3
Original line number Diff line number Diff line
@@ -455,7 +455,7 @@ public class MediaFocusControl implements OnFinished {
    private void notifyTopOfAudioFocusStack() {
        // notify the top of the stack it gained focus
        if (!mFocusStack.empty()) {
            if (canReassignAudioFocus()) {
            if (canReassignAudioFocus(mFocusStack.peek().getClientId())) {
                mFocusStack.peek().handleFocusGain(AudioManager.AUDIOFOCUS_GAIN);
            }
        }
@@ -554,14 +554,37 @@ public class MediaFocusControl implements OnFinished {
        }
    }

    /* Constant to identify focus stack entry clientid for QCHAT client */
    private static final String CLIENT_ID_QCHAT = "QCHAT";

    /**
     * Helper function:
     * Returns true if the system is in a state where the focus can be reevaluated, false otherwise.
     */
    private boolean canReassignAudioFocus() {
    private boolean canReassignAudioFocus(String clientId) {
        // focus requests are rejected during a phone call or when the phone is ringing
        // this is equivalent to IN_VOICE_COMM_FOCUS_ID having the focus
        // Also focus request is granted to QCHAT client even when voice call is active. QCHAT
        // client will first check if any voice calls are in CALL_INACTIVE/CALL_HOLD state
        if (!mFocusStack.isEmpty() && mFocusStack.peek().hasSameClient(IN_VOICE_COMM_FOCUS_ID)) {
            if (clientId.contains(CLIENT_ID_QCHAT))
                return true;
            else
                return false;
        }
        return true;
    }

     /**
     * Helper function:
     * Returns true if the system is in a state where the focus can be reevaluated , false otherwise.
     */
    private boolean canReassignAudioFocusFromQchat(int streamType, String clientId) {
        // Focus request is rejected for Music Player and for QChat client if the focus is already
        // acquired by a QChat client
        if (!mFocusStack.isEmpty() &&
            mFocusStack.peek().getClientId().contains(CLIENT_ID_QCHAT) &&
            (clientId.contains(CLIENT_ID_QCHAT) || (streamType == AudioManager.STREAM_MUSIC))) {
            return false;
        }
        return true;
@@ -616,7 +639,11 @@ public class MediaFocusControl implements OnFinished {
        }

        synchronized(mAudioFocusLock) {
            if (!canReassignAudioFocus()) {
            if (!canReassignAudioFocus(clientId)) {
                return AudioManager.AUDIOFOCUS_REQUEST_FAILED;
            }

            if (!canReassignAudioFocusFromQchat(mainStreamType, clientId)) {
                return AudioManager.AUDIOFOCUS_REQUEST_FAILED;
            }