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

Unverified Commit 7e496964 authored by ljzyal's avatar ljzyal Committed by Michael Bestas
Browse files

Telecomm: Forward port phone_type switch support



* This change is still required for some MSIM devices
* Change is based on the following commits, but with some slight
  simplifications and the necessary changes to adapt to the new code:

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

	    - Fix SIP soft-reboot on call

	    Change-Id: Ic78c52bbbe6b93b78bfdb8fdef479ef93ce1bd9f
	    Signed-off-by: default avatarljzyal <ljzyal@gmail.com>

	commit 9552ca5d
	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

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

	    Telecomm: Make phone_type switch generic

	    Change-Id: I78129aaab82493c1107699932f7ae8d780006c8f

	commit 235e20b2
	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

Change-Id: Ifedf0c4a674afb32a7c9e3366a2337fff469b64f
parent a1381c59
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -18,6 +18,9 @@ package com.android.server.telecom;

import android.media.AudioManager;
import android.os.Message;
import android.os.SystemProperties;
import android.telecom.PhoneAccountHandle;
import android.telephony.SubscriptionManager;
import android.util.SparseArray;

import com.android.internal.util.IState;
@@ -287,8 +290,23 @@ 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 (call != null && setMsimAudioParams) {
                int phoneId = getPhoneId(call);
                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);
@@ -343,6 +361,22 @@ public class CallAudioModeStateMachine extends StateMachine {
                    return NOT_HANDLED;
            }
        }

        private int getPhoneId(Call call) {
            if (call.getTargetPhoneAccount() != null) {
                PhoneAccountHandle account = call.getTargetPhoneAccount();
                try {
                    int index = Integer.parseInt(account.getId());
                    int phoneId = SubscriptionManager.getPhoneId(index);
                    if (SubscriptionManager.isValidPhoneId(phoneId)) {
                        return phoneId;
                    }
                } catch (NumberFormatException e) {
                    Log.e(LOG_TAG, e, "Cannot get phoneId from ID value " + account.getId());
                }
            }
            return -1;
        }
    }

    private class VoipCallFocusState extends BaseState {