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

Commit d46a9813 authored by Ryan Horoff's avatar Ryan Horoff
Browse files

Move carrier in-service check to after E911 timeout.

Instead of choosing whether to add a timeout when iterating through the phone accounts to see if we should make the CallAttempt, we now assign the timeout and check for the Voice capability at the end. This way, the connection service can keep trying if the CallManager is unable to handle the call after the 25 seconds.

Bug: 333816574
Test: atest CreateConnectionProcessorTest
Test: manually deployed and tested in a shieldbox with Fi's connection service to prevent radio connectivity
Change-Id: I8ffca4cb948d18f37a6b93f6eec2f82630c7ddf6
Merged-In: I8ffca4cb948d18f37a6b93f6eec2f82630c7ddf6
parent d0b67760
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2511,7 +2511,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
            return;
        }
        mCreateConnectionProcessor = new CreateConnectionProcessor(this, mRepository, this,
                phoneAccountRegistrar, mContext, mFlags);
                phoneAccountRegistrar, mContext, mFlags, new Timeouts.Adapter());
        mCreateConnectionProcessor.process();
    }

+2 −1
Original line number Diff line number Diff line
@@ -2028,7 +2028,8 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
    }

    /** @see IConnectionService#disconnect(String, Session.Info) */
    void disconnect(Call call) {
    @VisibleForTesting
    public void disconnect(Call call) {
        final String callId = mCallIdMapper.getCallId(call);
        if (callId != null && isServiceValid("disconnect")) {
            try {
+10 −5
Original line number Diff line number Diff line
@@ -128,15 +128,19 @@ public class CreateConnectionProcessor implements CreateConnectionResponse {
    private final PhoneAccountRegistrar mPhoneAccountRegistrar;
    private final Context mContext;
    private final FeatureFlags mFlags;
    private final Timeouts.Adapter mTimeoutsAdapter;
    private CreateConnectionTimeout mTimeout;
    private ConnectionServiceWrapper mService;
    private int mConnectionAttempt;

    @VisibleForTesting
    public CreateConnectionProcessor(
            Call call, ConnectionServiceRepository repository, CreateConnectionResponse response,
            PhoneAccountRegistrar phoneAccountRegistrar, Context context,
            FeatureFlags featureFlags) {
    public CreateConnectionProcessor(Call call,
            ConnectionServiceRepository repository,
            CreateConnectionResponse response,
            PhoneAccountRegistrar phoneAccountRegistrar,
            Context context,
            FeatureFlags featureFlags,
            Timeouts.Adapter timeoutsAdapter) {
        Log.v(this, "CreateConnectionProcessor created for Call = %s", call);
        mCall = call;
        mRepository = repository;
@@ -145,6 +149,7 @@ public class CreateConnectionProcessor implements CreateConnectionResponse {
        mContext = context;
        mConnectionAttempt = 0;
        mFlags = featureFlags;
        mTimeoutsAdapter = timeoutsAdapter;
    }

    boolean isProcessingComplete() {
@@ -317,7 +322,7 @@ public class CreateConnectionProcessor implements CreateConnectionResponse {
        clearTimeout();

        CreateConnectionTimeout timeout = new CreateConnectionTimeout(
                mContext, mPhoneAccountRegistrar, service, mCall);
                mContext, mPhoneAccountRegistrar, service, mCall, mTimeoutsAdapter);
        if (timeout.isTimeoutNeededForCall(getConnectionServices(mAttemptRecords),
                attempt.connectionManagerPhoneAccount)) {
            mTimeout = timeout;
+43 −20
Original line number Diff line number Diff line
@@ -44,15 +44,17 @@ public final class CreateConnectionTimeout extends Runnable {
    private final Handler mHandler = new Handler(Looper.getMainLooper());
    private boolean mIsRegistered;
    private boolean mIsCallTimedOut;
    private final Timeouts.Adapter mTimeoutsAdapter;

    @VisibleForTesting
    public CreateConnectionTimeout(Context context, PhoneAccountRegistrar phoneAccountRegistrar,
            ConnectionServiceWrapper service, Call call) {
            ConnectionServiceWrapper service, Call call, Timeouts.Adapter timeoutsAdapter) {
        super("CCT", null /*lock*/);
        mContext = context;
        mPhoneAccountRegistrar = phoneAccountRegistrar;
        mConnectionService = service;
        mCall = call;
        mTimeoutsAdapter = timeoutsAdapter;
    }

    @VisibleForTesting
@@ -60,6 +62,7 @@ public final class CreateConnectionTimeout extends Runnable {
            PhoneAccountHandle currentAccount) {
        // Non-emergency calls timeout automatically at the radio layer. No need for a timeout here.
        if (!mCall.isEmergencyCall()) {
            Log.d(this, "isTimeoutNeededForCall, not an emergency call");
            return false;
        }

@@ -68,11 +71,13 @@ public final class CreateConnectionTimeout extends Runnable {
        PhoneAccountHandle connectionManager =
                mPhoneAccountRegistrar.getSimCallManagerFromCall(mCall);
        if (!accounts.contains(connectionManager)) {
            Log.d(this, "isTimeoutNeededForCall, no connection manager");
            return false;
        }

        // No need to add a timeout if the current attempt is over the connection manager.
        if (Objects.equals(connectionManager, currentAccount)) {
            Log.d(this, "isTimeoutNeededForCall, already attempting over connection manager");
            return false;
        }

@@ -83,17 +88,6 @@ public final class CreateConnectionTimeout extends Runnable {
            return false;
        }

        // Timeout is not required if carrier is not in service.
        if (carrierEnabledSatelliteFlag() && connectionManager != null) {
            PhoneAccount account = mPhoneAccountRegistrar.getPhoneAccount(connectionManager,
                    connectionManager.getUserHandle());
            if (account.hasCapabilities(PhoneAccount.CAPABILITY_SUPPORTS_VOICE_CALLING_INDICATIONS)
                    && !account.hasCapabilities(PhoneAccount.CAPABILITY_VOICE_CALLING_AVAILABLE)) {
                Log.d(this, "isTimeoutNeededForCall, carrier is not in service.");
                return false;
            }
        }

        Log.i(this, "isTimeoutNeededForCall, returning true");
        return true;
    }
@@ -123,8 +117,31 @@ public final class CreateConnectionTimeout extends Runnable {

    @Override
    public void loggedRun() {
        if (!carrierEnabledSatelliteFlag()) {
            timeoutCallIfNeeded();
            return;
        }

        PhoneAccountHandle connectionManager =
                mPhoneAccountRegistrar.getSimCallManagerFromCall(mCall);
        if (connectionManager != null) {
            PhoneAccount account = mPhoneAccountRegistrar.getPhoneAccount(connectionManager,
                    connectionManager.getUserHandle());
            if (account != null && account.hasCapabilities(
                    (PhoneAccount.CAPABILITY_SUPPORTS_VOICE_CALLING_INDICATIONS
                            | PhoneAccount.CAPABILITY_VOICE_CALLING_AVAILABLE))) {
                // If we have encountered the timeout and there is an in service
                // ConnectionManager, disconnect the call so that it can be attempted over
                // the ConnectionManager.
                timeoutCallIfNeeded();
                return;
            }
        }
    }

    private void timeoutCallIfNeeded() {
        if (mIsRegistered && isCallBeingPlaced(mCall)) {
            Log.i(this, "run, call timed out, calling disconnect");
            Log.i(this, "timeoutCallIfNeeded, call timed out, calling disconnect");
            mIsCallTimedOut = true;
            mConnectionService.disconnect(mCall);
        }
@@ -141,13 +158,19 @@ public final class CreateConnectionTimeout extends Runnable {
    private long getTimeoutLengthMillis() {
        // If the radio is off then use a longer timeout. This gives us more time to power on the
        // radio.
        try {
            TelephonyManager telephonyManager =
                    (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
            if (telephonyManager.isRadioOn()) {
            return Timeouts.getEmergencyCallTimeoutMillis(mContext.getContentResolver());
                return mTimeoutsAdapter.getEmergencyCallTimeoutMillis(
                        mContext.getContentResolver());
            } else {
            return Timeouts.getEmergencyCallTimeoutRadioOffMillis(
                return mTimeoutsAdapter.getEmergencyCallTimeoutRadioOffMillis(
                        mContext.getContentResolver());
            }
        } catch (UnsupportedOperationException uoe) {
            Log.e(this, uoe, "getTimeoutLengthMillis - telephony is not supported");
            return mTimeoutsAdapter.getEmergencyCallTimeoutMillis(mContext.getContentResolver());
        }
    }
}
+8 −1
Original line number Diff line number Diff line
@@ -61,6 +61,14 @@ public final class Timeouts {
            return Timeouts.getEmergencyCallbackWindowMillis(cr);
        }

        public long getEmergencyCallTimeoutMillis(ContentResolver cr) {
            return Timeouts.getEmergencyCallTimeoutMillis(cr);
        }

        public long getEmergencyCallTimeoutRadioOffMillis(ContentResolver cr) {
            return Timeouts.getEmergencyCallTimeoutRadioOffMillis(cr);
        }

        public long getUserDefinedCallRedirectionTimeoutMillis(ContentResolver cr) {
            return Timeouts.getUserDefinedCallRedirectionTimeoutMillis(cr);
        }
@@ -127,7 +135,6 @@ public final class Timeouts {

        public int getDaysBackToSearchEmergencyDiagnosticEntries(){
            return Timeouts.getDaysBackToSearchEmergencyDiagnosticEntries();

        }
    }

Loading