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

Commit c2ed09b5 authored by Gabriele M's avatar Gabriele M Committed by Bruno Martins
Browse files

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
parent 9d6a21f6
Loading
Loading
Loading
Loading
+11 −19
Original line number Diff line number Diff line
@@ -19,8 +19,11 @@ package com.android.server.telecom;
import android.media.AudioManager;
import android.os.Message;
import android.os.SystemProperties;
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;
@@ -297,8 +300,11 @@ public class CallAudioModeStateMachine extends StateMachine {
            mAudioManager.requestAudioFocusForCall(AudioManager.STREAM_VOICE_CALL,
                    AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

            if (call != null && setMsimAudioParams) {
                int phoneId = getPhoneId(call);
            if (call != null && call.getTargetPhoneAccount() != null && setMsimAudioParams) {
                PhoneAccountHandle handle = call.getTargetPhoneAccount();
                PhoneAccount account = mTelecomManager.getPhoneAccount(handle);
                int subId = TelephonyManager.getDefault().getSubIdForPhoneAccount(account);
                int phoneId = SubscriptionManager.getPhoneId(subId);
                Log.d(LOG_TAG, "setAudioParameters phoneId=" + phoneId);
                if (phoneId == 0) {
                    mAudioManager.setParameters("phone_type=cp1");
@@ -361,22 +367,6 @@ 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 {
@@ -503,14 +493,16 @@ public class CallAudioModeStateMachine extends StateMachine {
    private final BaseState mOtherFocusState = new OtherFocusState();

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

    private int mMostRecentMode;
    private boolean mIsInitialized = false;

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

        addState(mUnfocusedState);
+2 −1
Original line number Diff line number Diff line
@@ -322,7 +322,8 @@ public class CallsManager extends Call.ListenerBase

        mCallAudioManager = new CallAudioManager(callAudioRouteStateMachine,
                this,new CallAudioModeStateMachine((AudioManager)
                        mContext.getSystemService(Context.AUDIO_SERVICE)),
                        mContext.getSystemService(Context.AUDIO_SERVICE),
                        (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE)),
                playerFactory, mRinger, new RingbackPlayer(playerFactory), mDtmfLocalTonePlayer);

        mHeadsetMediaButton = headsetMediaButtonFactory.create(context, this, mLock);