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

Commit 44f5e141 authored by Thomas Stuart's avatar Thomas Stuart
Browse files

fix Telecom out of sync w/ Telephony#defaultVoiceSubId

Sony reported an edge case bug in call preferences.

When all sims were removed, Telephony sends the signal
to both:

(1) set the defaultVoiceSubId=-1 (INVALID_SUB_ID)
(2) set the default phoneAccountHandle=null

The getUserDefaultPhoneAccountHandle would temporarily
return null and never actually change the value in Telecom
because it was gated by a conditional check. However, upon
re-inserting the sims, the call preference from before would
be restored (before setting the value to null).

This would cause Telephony and Telecom to become out of sync.
Telephony showed voiceSubId=-1 while Telecom showed the default
phoneAccountHandle != null

Therefore, no longer want to rely on getUserDefaultPhoneAccountHandle
to change the default phoneAccountHandle from the Telephony side
of things.

bug: 204226202
bug: 255443949

Test: manual
Change-Id: I56b0eaaaa7a0eb998c0feb0859983dd6c5ddfc1b
Merged-In: I56b0eaaaa7a0eb998c0feb0859983dd6c5ddfc1b
parent 1a8bcb9d
Loading
Loading
Loading
Loading
+25 −13
Original line number Diff line number Diff line
@@ -287,6 +287,12 @@ public class PhoneAccountRegistrar {
        if (account != null) {
            return defaultPhoneAccountHandle.phoneAccountHandle;
        }

        Log.v(this,
                "getUserSelectedOutgoingPhoneAccount: defaultPhoneAccountHandle"
                        + ".phoneAccountHandle=[%s] is not registered or owned by %s"
                , defaultPhoneAccountHandle.phoneAccountHandle, userHandle);

        return null;
    }

@@ -343,6 +349,15 @@ public class PhoneAccountRegistrar {
                mState.defaultOutgoingAccountHandles.get(userHandle);
        PhoneAccountHandle currentDefaultPhoneAccount = currentDefaultInfo == null ? null :
                currentDefaultInfo.phoneAccountHandle;

        Log.i(this, "setUserSelectedOutgoingPhoneAccount: %s", accountHandle);

        if (Objects.equals(currentDefaultPhoneAccount, accountHandle)) {
            Log.i(this, "setUserSelectedOutgoingPhoneAccount: "
                    + "no change in default phoneAccountHandle.  current is same as new.");
            return;
        }

        boolean isSimAccount = false;
        if (accountHandle == null) {
            // Asking to clear the default outgoing is a valid request
@@ -371,10 +386,8 @@ public class PhoneAccountRegistrar {
                    .put(userHandle, new DefaultPhoneAccountHandle(userHandle, accountHandle,
                            account.getGroupId()));
        }
        Log.i(this, "setUserSelectedOutgoingPhoneAccount: %s", accountHandle);

        // Potentially update the default voice subid in SubscriptionManager.
        if (!Objects.equals(currentDefaultPhoneAccount, accountHandle)) {
        int newSubId = accountHandle == null ? SubscriptionManager.INVALID_SUBSCRIPTION_ID :
                getSubscriptionIdForPhoneAccount(accountHandle);
        if (isSimAccount || accountHandle == null) {
@@ -383,12 +396,11 @@ public class PhoneAccountRegistrar {
                Log.i(this, "setUserSelectedOutgoingPhoneAccount: update voice sub; "
                        + "account=%s, subId=%d", accountHandle, newSubId);
                mSubscriptionManager.setDefaultVoiceSubscriptionId(newSubId);
                }
            } else {
                Log.i(this, "setUserSelectedOutgoingPhoneAccount: %s is not a sub", accountHandle);
                Log.i(this, "setUserSelectedOutgoingPhoneAccount: no change to voice sub");
            }
        } else {
            Log.i(this, "setUserSelectedOutgoingPhoneAccount: no change to voice sub");
            Log.i(this, "setUserSelectedOutgoingPhoneAccount: %s is not a sub", accountHandle);
        }

        write();