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

Commit e4352bae authored by Helen's avatar Helen
Browse files

Add onAudioModeIsVoipChanged for dynamic audio switching feature

Bug: 250815288
Bug: 255715090
Test: build and atest ImsCallingTest#testSetCallAudioHandler

Change-Id: I11a383a43adbead8cd9fae64c597255b4b5a0a8d
parent aeb5071c
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ import android.telephony.ServiceState;
import android.telephony.ServiceState.RilRadioTechnology;
import android.telephony.emergency.EmergencyNumber;
import android.telephony.ims.RtpHeaderExtension;
import android.telephony.ims.feature.MmTelFeature;
import android.telephony.ims.feature.MmTelFeature.ImsAudioHandler;
import android.util.Log;

import com.android.ims.internal.ConferenceParticipant;
@@ -139,6 +141,13 @@ public abstract class Connection {
         * @param extensionData The extension data.
         */
        public void onReceivedRtpHeaderExtensions(@NonNull Set<RtpHeaderExtension> extensionData);

        /**
         * Indicates that the audio handler for this connection is changed.
         *
         * @param imsAudioHandler {@link MmTelFeature#ImsAudioHandler}.
         */
        void onAudioModeIsVoipChanged(@ImsAudioHandler int imsAudioHandler);
    }

    /**
@@ -194,6 +203,8 @@ public abstract class Connection {
        public void onReceivedDtmfDigit(char digit) {}
        @Override
        public void onReceivedRtpHeaderExtensions(@NonNull Set<RtpHeaderExtension> extensionData) {}
        @Override
        public void onAudioModeIsVoipChanged(@ImsAudioHandler int imsAudioHandler) {}
    }

    public static final int AUDIO_QUALITY_STANDARD = 1;
@@ -1574,6 +1585,25 @@ public abstract class Connection {
        }
    }

    /**
     * Called to report audio mode changed for Voip.
     * @param imsAudioHandler the received value to handle the audio for this IMS call.
     */
    public void onAudioModeIsVoipChanged(@ImsAudioHandler int imsAudioHandler) {
        Rlog.i(TAG, "onAudioModeIsVoipChanged: conn imsAudioHandler " + imsAudioHandler);

        boolean isVoip = imsAudioHandler == MmTelFeature.AUDIO_HANDLER_ANDROID;
        if (isVoip == mAudioModeIsVoip) return;
        mAudioModeIsVoip = isVoip;

        Rlog.i(TAG, "onAudioModeIsVoipChanged: isVoip: " + isVoip
                + "mAudioModeIsVoip:" + mAudioModeIsVoip);

        for (Listener l : mListeners) {
            l.onAudioModeIsVoipChanged(imsAudioHandler);
        }
    }

    /**
     * Called to report RTP header extensions received from the network.
     * @param extensionData the received extension data.
+27 −0
Original line number Diff line number Diff line
@@ -362,6 +362,33 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
            }, mExecutor);
        }

        @Override
        public void onAudioModeIsVoipChanged(int imsAudioHandler) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                ImsCall imsCall = null;
                if (mForegroundCall.hasConnections()) {
                    imsCall = mForegroundCall.getImsCall();
                } else if (mBackgroundCall.hasConnections()) {
                    imsCall = mBackgroundCall.getImsCall();
                } else if (mRingingCall.hasConnections()) {
                    imsCall = mRingingCall.getImsCall();
                } else if (mHandoverCall.hasConnections()) {
                    imsCall = mHandoverCall.getImsCall();
                } else {
                    Rlog.e(LOG_TAG, "onAudioModeIsVoipChanged: no Call");
                }

                if (imsCall != null) {
                    ImsPhoneConnection conn = findConnection(imsCall);
                    if (conn != null) {
                        conn.onAudioModeIsVoipChanged(imsAudioHandler);
                    }
                } else {
                    Rlog.e(LOG_TAG, "onAudioModeIsVoipChanged: no ImsCall");
                }
            }, mExecutor);
        }

        /**
         * Schedule the given Runnable on mExecutor and block this thread until it finishes.
         * @param r The Runnable to run.