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

Commit e80b6e74 authored by Bruno Martins's avatar Bruno Martins
Browse files

Telecomm: Squashed phone_type switch support

 * This is still required for some legacy MSIM devices and instructs
   the audio HAL's MSIM voice extension which VOICE_CALL usecase should
   be used when placing phone calls.

 * Current change is based on the following commits, with some slight
   simplifications and the necessary changes to adapt to the new code.

   Author: ljzyal <ljzyal@gmail.com>
   Date:   Mon Jul 20 17:02:50 2015 +0800

       Telecomm: Support Samsung Dual Sims Phone phone_type switch

       Change-Id: Id6a91a47a5d9ebbb39869a66c05eeec14e1366e2

   Author: Bruno Martins <bgcngm@gmail.com>
   Date: 2015-08-06 23:26:41 +0100

       Telecomm: Make phone_type switch generic

       Change-Id: I78129aaab82493c1107699932f7ae8d780006c8f

   Author: Bruno Martins <bgcngm@gmail.com>
   Date: 2015-08-20 19:38:07 +0100

       Telecomm: Avoid NPE when invoking setAudioParameters

        * This exception would occur when preferred SIM for calls was set to
          "Ask every time" and if dialog was dismissed before starting the call

       Change-Id: Iee9968a7ad95fa16a085ecd7e765873904e0b88a

   Author: hawst1 <hawst1@gmail.com>
   Date: 2015-11-02 22:39:58 +0700

       - Fix SIP soft-reboot on call

       Change-Id: Ic78c52bbbe6b93b78bfdb8fdef479ef93ce1bd9f

   Author: Gabriele M <moto.falcon.git@gmail.com>
   Date:   Tue Jan 3 21:29:12 2017 +0100

       Telecomm: Set MSIM audio params using the proper ID

       It is assumed that the ID of every PhoneAccountHandle is the string
       equivalent of an int, however, the ID can also includes hex chars or,
       in case of the emergency account handle, it's just "E". This causes
       issues when we try to get the sub ID using Integer.parseInt(),
       so don't do it.

       Change-Id: Iae6cfacaf65bb2791b6fa9ae491bb4ad6edbe936

   Author: Simon Shields <keepcalm444@gmail.com>
   Date:   Fri Jan 27 22:12:40 2017 +1100

       CallAudioModeStateMachineTest: fix compilation

       Change-Id: Ie58189ce192469762aedfede18db7ce417d86f5d

   Author: Bruno Martins <bgcngm@gmail.com>
   Date:   Sun May 6 02:11:09 2018 +0100

       Telecomm: Account for default data sub ID when setting MSIM audio params

        * After all, the preferred SIM for mobile data also determines if
          audio routing must be switched. In case SIM2 is set to the
          preferred one, then the whole logic needs to be inverted.

        * This also addresses the edge case where in-call audio was broken
          while calling from SIM2 without any SIM card inserted in slot 0.
          Quite obviously, since default data SIM is automatically set to
          match the one and only inserted SIM card.

       Change-Id: I72be3cf30d23b5993e5e54a48e377c8ad976d860

   Author: Kevin F. Haggerty <haggertk@lineageos.org>
   Date:   Mon Dec 3 19:40:55 2018 -0700

       Telecomm: Update MSIM audio params logic again

       * Change c0e6b1fd updated the audio
         logic to track the preferred SIM, which is appropriate for most
         devices, but this inversion logic actually breaks audio routing
         on (some?) Samsung MSIM devices. The inversion logic is still
         required on such devices when SIM0 is not inserted/ready.
       * Create a property to allow such devices to opt-out of the inversion
         logic.
       * Test the state of SIM0 to make sure that the edge case is still
         handled.

       Change-Id: Iec488433e2bed5c0109addfd3f934a4b18f146ff

Change-Id: If6280d0be84d54c55a0e1a5431d79fcb7134b3df
parent 3ed9d743
Loading
Loading
Loading
Loading
+41 −4
Original line number Diff line number Diff line
@@ -19,9 +19,15 @@ package com.android.server.telecom;
import android.media.AudioManager;
import android.os.Looper;
import android.os.Message;
import android.os.SystemProperties;
import android.telecom.Log;
import android.telecom.Logging.Runnable;
import android.telecom.Logging.Session;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.SparseArray;

import com.android.internal.util.IState;
@@ -32,8 +38,8 @@ import com.android.internal.util.StateMachine;
public class CallAudioModeStateMachine extends StateMachine {
    public static class Factory {
        public CallAudioModeStateMachine create(SystemStateHelper systemStateHelper,
                AudioManager am) {
            return new CallAudioModeStateMachine(systemStateHelper, am);
                AudioManager am, TelecomManager tm) {
            return new CallAudioModeStateMachine(systemStateHelper, am, tm);
        }
    }

@@ -456,8 +462,36 @@ public class CallAudioModeStateMachine extends StateMachine {
        @Override
        public void enter() {
            Log.i(LOG_TAG, "Audio focus entering SIM CALL state");
            boolean setMsimAudioParams = SystemProperties
                    .getBoolean("ro.multisim.set_audio_params", false);
            Call call = mCallAudioManager.getForegroundCall();

            mAudioManager.requestAudioFocusForCall(AudioManager.STREAM_VOICE_CALL,
                    AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

            if (setMsimAudioParams && call != null && call.getTargetPhoneAccount() != null) {
                PhoneAccountHandle handle = call.getTargetPhoneAccount();
                PhoneAccount account = mTelecomManager.getPhoneAccount(handle);
                TelephonyManager tm = TelephonyManager.getDefault();
                boolean audioFollowDefaultSim = SystemProperties
                        .getBoolean("ro.multisim.audio_follow_default_sim", true);
                int subId = tm.getSubIdForPhoneAccount(account);
                int phoneId = SubscriptionManager.getPhoneId(subId);

                if (audioFollowDefaultSim ||
                        tm.getSimState(0) != TelephonyManager.SIM_STATE_READY) {
                    int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
                    phoneId ^= SubscriptionManager.getPhoneId(defaultDataSubId);
                }

                Log.d(LOG_TAG, "setAudioParameters phoneId=" + phoneId);
                if (phoneId == 0) {
                    mAudioManager.setParameters("phone_type=cp1");
                } else if (phoneId == 1) {
                    mAudioManager.setParameters("phone_type=cp2");
                }
            }

            mAudioManager.setMode(AudioManager.MODE_IN_CALL);
            mMostRecentMode = AudioManager.MODE_IN_CALL;
            mCallAudioManager.setCallAudioRouteFocusState(CallAudioRouteStateMachine.ACTIVE_FOCUS);
@@ -684,16 +718,18 @@ public class CallAudioModeStateMachine extends StateMachine {

    private final AudioManager mAudioManager;
    private final SystemStateHelper mSystemStateHelper;
    private final TelecomManager mTelecomManager;
    private CallAudioManager mCallAudioManager;

    private int mMostRecentMode;
    private boolean mIsInitialized = false;

    public CallAudioModeStateMachine(SystemStateHelper systemStateHelper,
            AudioManager audioManager) {
            AudioManager audioManager, TelecomManager telecomManager) {
        super(CallAudioModeStateMachine.class.getSimpleName());
        mAudioManager = audioManager;
        mSystemStateHelper = systemStateHelper;
        mTelecomManager = telecomManager;
        mMostRecentMode = AudioManager.MODE_NORMAL;

        createStates();
@@ -703,10 +739,11 @@ public class CallAudioModeStateMachine extends StateMachine {
     * Used for testing
     */
    public CallAudioModeStateMachine(SystemStateHelper systemStateHelper,
            AudioManager audioManager, Looper looper) {
            AudioManager audioManager, TelecomManager telecomManager, Looper looper) {
        super(CallAudioModeStateMachine.class.getSimpleName(), looper);
        mAudioManager = audioManager;
        mSystemStateHelper = systemStateHelper;
        mTelecomManager = telecomManager;
        mMostRecentMode = AudioManager.MODE_NORMAL;

        createStates();
+2 −1
Original line number Diff line number Diff line
@@ -547,7 +547,8 @@ public class CallsManager extends Call.ListenerBase
                mTimeoutsAdapter, mLock);
        mCallAudioManager = new CallAudioManager(callAudioRouteStateMachine,
                this, callAudioModeStateMachineFactory.create(systemStateHelper,
                (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE)),
                        (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE),
                        (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE)),
                playerFactory, mRinger, new RingbackPlayer(playerFactory),
                bluetoothStateReceiver, mDtmfLocalTonePlayer);

+5 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.telecom.tests;

import android.media.AudioManager;
import android.os.HandlerThread;
import android.telecom.TelecomManager;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.server.telecom.CallAudioManager;
@@ -49,6 +50,7 @@ public class CallAudioModeStateMachineTest extends TelecomTestCase {
    @Mock private SystemStateHelper mSystemStateHelper;
    @Mock private AudioManager mAudioManager;
    @Mock private CallAudioManager mCallAudioManager;
    @Mock private TelecomManager mTelecomManager;

    private HandlerThread mTestThread;

@@ -72,7 +74,7 @@ public class CallAudioModeStateMachineTest extends TelecomTestCase {
    @Test
    public void testNoFocusWhenRingerSilenced() throws Throwable {
        CallAudioModeStateMachine sm = new CallAudioModeStateMachine(mSystemStateHelper,
                mAudioManager, mTestThread.getLooper());
                mAudioManager, mTelecomManager, mTestThread.getLooper());
        sm.setCallAudioManager(mCallAudioManager);
        sm.sendMessage(CallAudioModeStateMachine.ABANDON_FOCUS_FOR_TESTING);
        waitForHandlerAction(sm.getHandler(), TEST_TIMEOUT);
@@ -104,7 +106,7 @@ public class CallAudioModeStateMachineTest extends TelecomTestCase {
    @Test
    public void testNoRingWhenDeviceIsAtEar() {
        CallAudioModeStateMachine sm = new CallAudioModeStateMachine(mSystemStateHelper,
                mAudioManager, mTestThread.getLooper());
                mAudioManager, mTelecomManager, mTestThread.getLooper());
        sm.setCallAudioManager(mCallAudioManager);
        sm.sendMessage(CallAudioModeStateMachine.ABANDON_FOCUS_FOR_TESTING);
        sm.sendMessage(CallAudioModeStateMachine.NEW_HOLDING_CALL, new Builder()
@@ -140,7 +142,7 @@ public class CallAudioModeStateMachineTest extends TelecomTestCase {
    @Test
    public void testRegainFocusWhenHfpIsConnectedSilenced() throws Throwable {
        CallAudioModeStateMachine sm = new CallAudioModeStateMachine(mSystemStateHelper,
                mAudioManager, mTestThread.getLooper());
                mAudioManager, mTelecomManager, mTestThread.getLooper());
        sm.setCallAudioManager(mCallAudioManager);
        sm.sendMessage(CallAudioModeStateMachine.ABANDON_FOCUS_FOR_TESTING);
        waitForHandlerAction(sm.getHandler(), TEST_TIMEOUT);
+3 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.telecom.tests;

import android.media.AudioManager;
import android.os.HandlerThread;
import android.telecom.TelecomManager;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.server.telecom.CallAudioManager;
@@ -103,6 +104,7 @@ public class CallAudioModeTransitionTests extends TelecomTestCase {
    @Mock private SystemStateHelper mSystemStateHelper;
    @Mock private AudioManager mAudioManager;
    @Mock private CallAudioManager mCallAudioManager;
    @Mock private TelecomManager mTelecomManager;
    private final ModeTestParameters mParams;
    private HandlerThread mTestThread;

@@ -130,7 +132,7 @@ public class CallAudioModeTransitionTests extends TelecomTestCase {
    @SmallTest
    public void modeTransitionTest() {
        CallAudioModeStateMachine sm = new CallAudioModeStateMachine(mSystemStateHelper,
                mAudioManager, mTestThread.getLooper());
                mAudioManager, mTelecomManager, mTestThread.getLooper());
        sm.setCallAudioManager(mCallAudioManager);
        sm.sendMessage(mParams.initialAudioState);
        waitForHandlerAction(sm.getHandler(), TEST_TIMEOUT);