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

Commit 2b947d32 authored by Thomas Stuart's avatar Thomas Stuart
Browse files

add CTS coverage for SM calls with sim based defaults

While creating some CTS tests that changed the default
phone account handle, I noticed the handle was not changing.
After looking through the logs, I discovered that since test handles
are given a subid=-1, SubscriptionMananger#setDefaultVoiceSubId would
then re-call setUserSelectedOutgoingPhoneAccount again and override
the new default phone account with null.

Therefore, to prevent this override on test handles, a new early exit
was put in.

bug: 234846282
Test: android.telecom.cts.SelfManagedConnectionServiceTest
    #testSelfManagedCallWithSimBasedPhoneAccountAsDefault
    #testSelfManagedCallWithNoCallPreferenceAsDefault
    #testSelfManagedCallWithMultipleSimBasedAccountsActiveAndAsDefault
Change-Id: If5d15b32e8fcdab758a44e31edd9af85cc02242f
parent 899e4b6a
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
package: "com.android.server.telecom.flags"

flag {
  name: "only_update_telephony_on_valid_sub_ids"
  namespace: "telecom"
  description: "For testing purposes, only update Telephony when the default calling subId is non-zero"
  bug: "234846282"
}

flag {
  name: "telephony_has_default_but_telecom_does_not"
  namespace: "telecom"
+47 −10
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.XmlUtils;
import com.android.modules.utils.ModifiedUtf8;
import com.android.server.telecom.flags.Flags;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -389,10 +390,28 @@ public class PhoneAccountRegistrar {
                            account.getGroupId()));
        }

        // Potentially update the default voice subid in SubscriptionManager.
        // Potentially update the default voice subid in SubscriptionManager so that Telephony and
        // Telecom are in sync.
        int newSubId = accountHandle == null ? SubscriptionManager.INVALID_SUBSCRIPTION_ID :
                getSubscriptionIdForPhoneAccount(accountHandle);
        if (Flags.onlyUpdateTelephonyOnValidSubIds()) {
            if (shouldUpdateTelephonyDefaultVoiceSubId(accountHandle, isSimAccount, newSubId)) {
                updateDefaultVoiceSubId(newSubId, accountHandle);
            } else {
                Log.i(this, "setUserSelectedOutgoingPhoneAccount: %s is not a sub", accountHandle);
            }
        } else {
            if (isSimAccount || accountHandle == null) {
                updateDefaultVoiceSubId(newSubId, accountHandle);
            } else {
                Log.i(this, "setUserSelectedOutgoingPhoneAccount: %s is not a sub", accountHandle);
            }
        }
        write();
        fireDefaultOutgoingChanged();
    }

    private void updateDefaultVoiceSubId(int newSubId, PhoneAccountHandle accountHandle){
        int currentVoiceSubId = mSubscriptionManager.getDefaultVoiceSubscriptionId();
        if (newSubId != currentVoiceSubId) {
            Log.i(this, "setUserSelectedOutgoingPhoneAccount: update voice sub; "
@@ -401,12 +420,30 @@ public class PhoneAccountRegistrar {
        } else {
            Log.i(this, "setUserSelectedOutgoingPhoneAccount: no change to voice sub");
        }
        } else {
            Log.i(this, "setUserSelectedOutgoingPhoneAccount: %s is not a sub", accountHandle);
    }

        write();
        fireDefaultOutgoingChanged();
    // This helper is important for CTS testing.  [PhoneAccount]s created by Telecom in CTS are
    // assigned a  subId value of INVALID_SUBSCRIPTION_ID (-1) by Telephony.  However, when
    // Telephony has a default outgoing calling voice account of -1, that translates to no default
    // account (user should be prompted to select an acct when making MOs).  In order to avoid
    // Telephony clearing out the newly changed default [PhoneAccount] in Telecom, Telephony should
    // not be updated. This situation will never occur in production since [PhoneAccount]s in
    // production are assigned non-negative subId values.
    private boolean shouldUpdateTelephonyDefaultVoiceSubId(PhoneAccountHandle phoneAccountHandle,
            boolean isSimAccount, int newSubId) {
        // user requests no call preference
        if (phoneAccountHandle == null) {
            return true;
        }
        // do not update Telephony if the newSubId is invalid
        if (newSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
            Log.w(this, "shouldUpdateTelephonyDefaultVoiceSubId: "
                            + "invalid subId scenario, not updating Telephony. "
                            + "phoneAccountHandle=[%s], isSimAccount=[%b], newSubId=[%s]",
                    phoneAccountHandle, isSimAccount, newSubId);
            return false;
        }
        return isSimAccount;
    }

    boolean isUserSelectedSmsPhoneAccount(PhoneAccountHandle accountHandle) {