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

Unverified Commit 6b07c48a authored by Gabriele M's avatar Gabriele M Committed by Michael Bestas
Browse files

InCallUI: Use proper sub IDs

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: If82c8146d01dba03cc3323aef9a4df84dc1f4bfd
parent 3e5694aa
Loading
Loading
Loading
Loading
+15 −13
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.telecom.TelecomManager;
import android.telephony.SubscriptionManager;
import android.telecom.VideoProfile;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import com.android.contacts.common.CallUtil;
@@ -784,7 +785,7 @@ public class Call {
                    int subId = getSubId();
                    for (android.telecom.Call call : conferenceableCalls) {
                        PhoneAccountHandle phHandle = call.getDetails().getAccountHandle();
                        if ((phHandle != null) && ((Integer.parseInt(phHandle.getId())) == subId)) {
                        if ((phHandle != null) && (getSubId(phHandle) == subId)) {
                            hasConferenceableCall = true;
                            break;
                        }
@@ -861,20 +862,21 @@ public class Call {
        return mTelecomCall == null ? null : mTelecomCall.getDetails().getAccountHandle();
    }

    public int getSubId() {
        PhoneAccountHandle ph = getAccountHandle();
        if (ph != null) {
            try {
                if (ph.getId() != null) {
                    return Integer.parseInt(getAccountHandle().getId());
                }
            } catch (NumberFormatException e) {
                Log.w(this, "sub id is not a number" + e);
    public int getSubId(PhoneAccountHandle ph) {
        if (ph == null) {
            return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        }
            return SubscriptionManager.getDefaultVoiceSubscriptionId();
        TelecomManager mgr = InCallPresenter.getInstance().getTelecomManager();
        PhoneAccount account = mgr.getPhoneAccount(ph);
        if (account != null) {
            return TelephonyManager.getDefault().getSubIdForPhoneAccount(account);
        } else {
            return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
            return SubscriptionManager.getDefaultVoiceSubscriptionId();
        }
    }

    public int getSubId() {
        return getSubId(getAccountHandle());
    }

    /**
+17 −29
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ public class CallList {
        // Update active subscription from call object. it will be set by
        // Telecomm service for incoming call and whenever active sub changes.
        if (call.mIsActiveSub) {
            int sub = Integer.parseInt(call.getAccountHandle().getId());
            int sub = call.getSubId();
            Log.d(this, "onIncoming - sub:" + sub + " mSubId:" + mSubId);
            if (sub != mSubId) {
                setActiveSubId(sub);
@@ -174,17 +174,13 @@ public class CallList {
        Trace.beginSection("onUpdate");
        PhoneAccountHandle ph = call.getAccountHandle();
        Log.d(this, "onUpdate - " + call  + " ph:" + ph);
        try {
        if (call.mIsActiveSub && ph != null) {
                int sub = Integer.parseInt(ph.getId());
            int sub = call.getSubId(ph);
            Log.d(this, "onUpdate - sub:" + sub + " mSubId:" + mSubId);
            if(sub != mSubId) {
                setActiveSubId(sub);
            }
        }
        } catch (NumberFormatException e) {
                Log.w(this,"Sub Id is not a number " + e);
        }
        onUpdateCall(call);
        notifyGenericListeners();
        Trace.endSection();
@@ -774,14 +770,10 @@ public class CallList {
    boolean hasAnyLiveCall(int subId) {
        for (Call call : mCallById.values()) {
            PhoneAccountHandle ph = call.getAccountHandle();
            try {
                if (!isCallDead(call) && ph != null && (Integer.parseInt(ph.getId()) == subId)) {
            if (!isCallDead(call) && ph != null && (call.getSubId(ph) == subId)) {
                Log.d(this, "hasAnyLiveCall sub = " + subId);
                return true;
            }
            } catch (NumberFormatException e) {
                Log.w(this,"Sub Id is not a number " + e);
            }
        }
        Log.d(this, "no active call ");
        return false;
@@ -856,10 +848,9 @@ public class CallList {
        int position = 0;
        for (Call call : mCallById.values()) {
            PhoneAccountHandle ph = call.getAccountHandle();
            try {
            if ((call.getState() == state) && ((ph == null) ||
                    (ph != null && (ph.getId() != null) &&  ((ph.getId().contains("sip")
                        || ph.getId().contains("@")) || Integer.parseInt(ph.getId()) == subId)))) {
                    || ph.getId().contains("@")) || call.getSubId(ph) == subId)))) {
                if (position >= positionToFind) {
                    retval = call;
                    break;
@@ -867,9 +858,6 @@ public class CallList {
                    position++;
                }
            }
            } catch (NumberFormatException e) {
                   Log.w(this,"Sub Id is not a number " + e);
            }
        }
        return retval;
    }