Merge "Add ims audio codec to Extra"
am: bfe145da2d
Change-Id: I937884dda605003201fe02232e7b5b6382ecb046
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index 702e6f7..55b1e26 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -46,6 +46,7 @@
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.ims.ImsCallProfile;
+import android.telephony.ims.ImsStreamMediaProfile;
import android.text.TextUtils;
import android.util.Pair;
@@ -1344,6 +1345,75 @@
}
}
+ private void refreshCodecType() {
+ Bundle newExtras = getExtras();
+ if (newExtras == null) {
+ newExtras = new Bundle();
+ }
+ int newCodecType;
+ if (isImsConnection()) {
+ newCodecType = transformCodec(getOriginalConnection().getAudioCodec());
+ } else {
+ // For SRVCC, report AUDIO_CODEC_NONE.
+ newCodecType = Connection.AUDIO_CODEC_NONE;
+ }
+ int oldCodecType = newExtras.getInt(Connection.EXTRA_AUDIO_CODEC,
+ Connection.AUDIO_CODEC_NONE);
+ if (newCodecType != oldCodecType) {
+ newExtras.putInt(Connection.EXTRA_AUDIO_CODEC, newCodecType);
+ putTelephonyExtras(newExtras);
+ }
+ }
+
+ private int transformCodec(int codec) {
+ switch (codec) {
+ case ImsStreamMediaProfile.AUDIO_QUALITY_NONE:
+ return Connection.AUDIO_CODEC_NONE;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_AMR:
+ return Connection.AUDIO_CODEC_AMR;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB:
+ return Connection.AUDIO_CODEC_AMR_WB;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_QCELP13K:
+ return Connection.AUDIO_CODEC_QCELP13K;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_EVRC:
+ return Connection.AUDIO_CODEC_EVRC;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_B:
+ return Connection.AUDIO_CODEC_EVRC_B;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_WB:
+ return Connection.AUDIO_CODEC_EVRC_WB;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_NW:
+ return Connection.AUDIO_CODEC_EVRC_NW;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_GSM_EFR:
+ return Connection.AUDIO_CODEC_GSM_EFR;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_GSM_FR:
+ return Connection.AUDIO_CODEC_GSM_FR;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_GSM_HR:
+ return Connection.AUDIO_CODEC_GSM_HR;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_G711U:
+ return Connection.AUDIO_CODEC_G711U;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_G723:
+ return Connection.AUDIO_CODEC_G723;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_G711A:
+ return Connection.AUDIO_CODEC_G711A;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_G722:
+ return Connection.AUDIO_CODEC_G722;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_G711AB:
+ return Connection.AUDIO_CODEC_G711AB;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_G729:
+ return Connection.AUDIO_CODEC_G729;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_EVS_NB:
+ return Connection.AUDIO_CODEC_EVS_NB;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_EVS_WB:
+ return Connection.AUDIO_CODEC_EVS_WB;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_EVS_SWB:
+ return Connection.AUDIO_CODEC_EVS_SWB;
+ case ImsStreamMediaProfile.AUDIO_QUALITY_EVS_FB:
+ return Connection.AUDIO_CODEC_EVS_FB;
+ default:
+ return Connection.AUDIO_CODEC_NONE;
+ }
+ }
+
private boolean shouldSetDisableAddCallExtra() {
if (mOriginalConnection == null) {
return false;
@@ -1778,6 +1848,7 @@
updateAddress();
updateMultiparty();
refreshDisableAddCall();
+ refreshCodecType();
}
/**
diff --git a/tests/src/com/android/services/telephony/TelephonyConnectionTest.java b/tests/src/com/android/services/telephony/TelephonyConnectionTest.java
new file mode 100644
index 0000000..7d15680
--- /dev/null
+++ b/tests/src/com/android/services/telephony/TelephonyConnectionTest.java
@@ -0,0 +1,25 @@
+package com.android.services.telephony;
+
+import static junit.framework.Assert.assertEquals;
+
+import android.os.Bundle;
+import android.telecom.Connection;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import androidx.test.runner.AndroidJUnit4;
+
+@RunWith(AndroidJUnit4.class)
+public class TelephonyConnectionTest {
+
+ @Test
+ public void testCodecInIms() {
+ TestTelephonyConnection c = new TestTelephonyConnection();
+ c.updateState();
+ Bundle extras = c.getExtras();
+ int codec = extras.getInt(Connection.EXTRA_AUDIO_CODEC, Connection.AUDIO_CODEC_NONE);
+ assertEquals(codec, Connection.AUDIO_CODEC_AMR);
+ }
+
+}
diff --git a/tests/src/com/android/services/telephony/TestTelephonyConnection.java b/tests/src/com/android/services/telephony/TestTelephonyConnection.java
index f77fd30..593494b 100644
--- a/tests/src/com/android/services/telephony/TestTelephonyConnection.java
+++ b/tests/src/com/android/services/telephony/TestTelephonyConnection.java
@@ -80,6 +80,9 @@
mOriginalConnection = mock(Connection.class);
// Set up mMockRadioConnection and mMockPhone to contain an active call
when(mMockRadioConnection.getState()).thenReturn(Call.State.ACTIVE);
+ when(mOriginalConnection.getState()).thenReturn(Call.State.ACTIVE);
+ when(mMockRadioConnection.getAudioCodec()).thenReturn(
+ android.telecom.Connection.AUDIO_CODEC_AMR);
when(mMockRadioConnection.getCall()).thenReturn(mMockCall);
when(mMockRadioConnection.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_IMS);
doNothing().when(mMockRadioConnection).addListener(any(Connection.Listener.class));