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

Commit e4696770 authored by Sailesh Nepal's avatar Sailesh Nepal Committed by Android (Google) Code Review
Browse files

Merge "Add connection manager fallback" into lmp-mr1-dev

parents ecaaeac2 bafadce5
Loading
Loading
Loading
Loading
+38 −1
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ final class CreateConnectionProcessor {
    private DisconnectCause mLastErrorDisconnectCause;
    private final PhoneAccountRegistrar mPhoneAccountRegistrar;
    private final Context mContext;
    private boolean mShouldUseConnectionManager = true;

    CreateConnectionProcessor(
            Call call, ConnectionServiceRepository repository, CreateConnectionResponse response,
@@ -185,6 +186,10 @@ final class CreateConnectionProcessor {
    }

    private boolean shouldSetConnectionManager() {
        if (!mShouldUseConnectionManager) {
            return false;
        }

        if (mAttemptRecords.size() == 0) {
            return false;
        }
@@ -307,12 +312,44 @@ final class CreateConnectionProcessor {
            }
        }

        private boolean shouldFallbackToNoConnectionManager(DisconnectCause cause) {
            PhoneAccountHandle handle = mCall.getConnectionManagerPhoneAccount();
            if (handle == null || !handle.equals(mPhoneAccountRegistrar.getSimCallManager())) {
                return false;
            }

            ConnectionServiceWrapper connectionManager = mCall.getConnectionService();
            if (connectionManager == null) {
                return false;
            }

            if (cause.getCode() == DisconnectCause.CONNECTION_MANAGER_NOT_SUPPORTED) {
                Log.d(CreateConnectionProcessor.this, "Connection manager declined to handle the "
                        + "call, falling back to not using a connection manager");
                return true;
            }

            if (!connectionManager.isServiceValid("createConnection")) {
                Log.d(CreateConnectionProcessor.this, "Connection manager unbound while trying "
                        + "create a connection, falling back to not using a connection manager");
                return true;
            }

            return false;
        }

        @Override
        public void handleCreateConnectionFailure(DisconnectCause errorDisconnectCause) {
            // Failure of some sort; record the reasons for failure and try again if possible
            Log.d(CreateConnectionProcessor.this, "Connection failed: (%s)", errorDisconnectCause);
            mLastErrorDisconnectCause = errorDisconnectCause;
            if (shouldFallbackToNoConnectionManager(errorDisconnectCause)) {
                mShouldUseConnectionManager = false;
                // Restart from the beginning.
                process();
            } else {
                attemptNextPhoneAccount();
            }
        }
    }
}