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

Commit 5884effa authored by Grace Jia's avatar Grace Jia
Browse files

Revert "Unbind ConnectionService if connection creation timed out."

This reverts commit c6048375.

Reason for revert: Security fix should not be guarded by a flag(b/293458004 comment#35)

Change-Id: Ib93a20f0a55bc4535d4775a324001bddbf310985
parent 6403236f
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -14,13 +14,6 @@ flag {
  bug: "301713560"
}

flag {
  name: "unbind_timeout_connections"
  namespace: "telecom"
  description: "When set, Telecom will auto-unbind if a ConnectionService returns no connections after some time."
  bug: "293458004"
}

flag{
  name: "add_call_uri_for_missed_calls"
  namespace: "telecom"
+4 −47
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.UserHandle;
@@ -73,14 +74,13 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.Objects;

/**
 * Wrapper for {@link IConnectionService}s, handles binding to {@link IConnectionService} and keeps
@@ -93,12 +93,9 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
        ConnectionServiceFocusManager.ConnectionServiceFocus {

    private static final String TELECOM_ABBREVIATION = "cast";
    private static final long SERVICE_BINDING_TIMEOUT = 15000L;
    private CompletableFuture<Pair<Integer, Location>> mQueryLocationFuture = null;
    private @Nullable CancellationSignal mOngoingQueryLocationRequest = null;
    private final ExecutorService mQueryLocationExecutor = Executors.newSingleThreadExecutor();
    private ScheduledExecutorService mScheduledExecutor =
            Executors.newSingleThreadScheduledExecutor();

    private final class Adapter extends IConnectionServiceAdapter.Stub {

@@ -1603,22 +1600,6 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
                        .setParticipants(call.getParticipants())
                        .setIsAdhocConferenceCall(call.isAdhocConferenceCall())
                        .build();
                if (Flags.unbindTimeoutConnections()) {
                    android.telecom.Logging.Runnable r =
                            new android.telecom.Logging.Runnable("CSW.cC", mLock) {
                        @Override
                        public void loggedRun() {
                            if (!call.isCreateConnectionComplete()) {
                                Log.e(this, new Exception(), "Conference %s creation timeout",
                                        getComponentName());
                                response.handleCreateConferenceFailure(
                                        new DisconnectCause(DisconnectCause.ERROR));
                            }
                        }
                    };
                    mScheduledExecutor.schedule(r.getRunnableToCancel(), SERVICE_BINDING_TIMEOUT,
                            TimeUnit.MILLISECONDS);
                }
                try {
                    mServiceInterface.createConference(
                            call.getConnectionManagerPhoneAccount(),
@@ -1659,7 +1640,6 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
                    Log.i(ConnectionServiceWrapper.this, "Call not present"
                            + " in call id mapper, maybe it was aborted before the bind"
                            + " completed successfully?");

                    response.handleCreateConnectionFailure(
                            new DisconnectCause(DisconnectCause.CANCELED));
                    return;
@@ -1720,24 +1700,6 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
                        .setRttPipeFromInCall(call.getInCallToCsRttPipeForCs())
                        .setRttPipeToInCall(call.getCsToInCallRttPipeForCs())
                        .build();

                if (Flags.unbindTimeoutConnections()) {
                    android.telecom.Logging.Runnable r =
                            new android.telecom.Logging.Runnable("CSW.cC", mLock) {
                                @Override
                                public void loggedRun() {
                                    if (!call.isCreateConnectionComplete()) {
                                        Log.e(this, new Exception(),
                                                "Connection %s creation timeout",
                                                getComponentName());
                                        response.handleCreateConnectionFailure(
                                                new DisconnectCause(DisconnectCause.ERROR));
                                    }
                                }
                            };
                    mScheduledExecutor.schedule(r.getRunnableToCancel(), SERVICE_BINDING_TIMEOUT,
                            TimeUnit.MILLISECONDS);
                }
                try {
                    mServiceInterface.createConnection(
                            call.getConnectionManagerPhoneAccount(),
@@ -1746,6 +1708,7 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
                            call.shouldAttachToExistingConnection(),
                            call.isUnknown(),
                            Log.getExternalSession(TELECOM_ABBREVIATION));

                } catch (RemoteException e) {
                    Log.e(this, e, "Failure to createConnection -- %s", getComponentName());
                    mPendingResponses.remove(callId).handleCreateConnectionFailure(
@@ -2194,8 +2157,7 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
        }
    }

    @VisibleForTesting
    public void addCall(Call call) {
    void addCall(Call call) {
        if (mCallIdMapper.getCallId(call) == null) {
            mCallIdMapper.addCall(call);
        }
@@ -2663,9 +2625,4 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
        sb.append("]");
        return sb.toString();
    }

    @VisibleForTesting
    public void setScheduledExecutorService(ScheduledExecutorService service) {
        mScheduledExecutor = service;
    }
}
+0 −2
Original line number Diff line number Diff line
@@ -1035,7 +1035,6 @@ public class BasicCallTests extends TelecomSystemTest {
        call.setTargetPhoneAccount(mPhoneAccountA1.getAccountHandle());
        assert(call.isVideoCallingSupportedByPhoneAccount());
        assertEquals(VideoProfile.STATE_BIDIRECTIONAL, call.getVideoState());
        call.setIsCreateConnectionComplete(true);
    }

    /**
@@ -1059,7 +1058,6 @@ public class BasicCallTests extends TelecomSystemTest {
        call.setTargetPhoneAccount(mPhoneAccountA2.getAccountHandle());
        assert(!call.isVideoCallingSupportedByPhoneAccount());
        assertEquals(VideoProfile.STATE_AUDIO_ONLY, call.getVideoState());
        call.setIsCreateConnectionComplete(true);
    }

    /**
+1 −61
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.OutcomeReceiver;
import android.os.Process;
@@ -64,7 +63,6 @@ import android.os.ResultReceiver;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.BlockedNumberContract;
import android.telecom.CallException;
import android.telecom.CallScreeningService;
@@ -104,7 +102,6 @@ import com.android.server.telecom.ClockProxy;
import com.android.server.telecom.ConnectionServiceFocusManager;
import com.android.server.telecom.ConnectionServiceFocusManager.ConnectionServiceFocusManagerFactory;
import com.android.server.telecom.ConnectionServiceWrapper;
import com.android.server.telecom.CreateConnectionResponse;
import com.android.server.telecom.DefaultDialerCache;
import com.android.server.telecom.EmergencyCallDiagnosticLogger;
import com.android.server.telecom.EmergencyCallHelper;
@@ -131,9 +128,8 @@ import com.android.server.telecom.bluetooth.BluetoothRouteManager;
import com.android.server.telecom.bluetooth.BluetoothStateReceiver;
import com.android.server.telecom.callfiltering.BlockedNumbersAdapter;
import com.android.server.telecom.callfiltering.CallFilteringResult;
import com.android.server.telecom.callfiltering.IncomingCallFilterGraph;
import com.android.server.telecom.flags.FeatureFlags;
import com.android.server.telecom.flags.Flags;
import com.android.server.telecom.callfiltering.IncomingCallFilterGraph;
import com.android.server.telecom.ui.AudioProcessingNotification;
import com.android.server.telecom.ui.CallStreamingNotification;
import com.android.server.telecom.ui.DisconnectedCallNotifier;
@@ -142,7 +138,6 @@ import com.android.server.telecom.voip.TransactionManager;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -291,10 +286,7 @@ public class CallsManagerTest extends TelecomTestCase {
    @Mock private CallAudioCommunicationDeviceTracker mCommunicationDeviceTracker;
    @Mock private CallStreamingNotification mCallStreamingNotification;
    @Mock private FeatureFlags mFeatureFlags;

    @Mock private IncomingCallFilterGraph mIncomingCallFilterGraph;
    @Mock private IConnectionService mIConnectionService;
    @Rule public SetFlagsRule mSetRlagsRule = new SetFlagsRule();
    private CallsManager mCallsManager;

    @Override
@@ -382,17 +374,11 @@ public class CallsManagerTest extends TelecomTestCase {
                eq(WORK_HANDLE), any())).thenReturn(WORK_ACCOUNT);
        when(mToastFactory.makeText(any(), anyInt(), anyInt())).thenReturn(mToast);
        when(mToastFactory.makeText(any(), any(), anyInt())).thenReturn(mToast);
        when(mIConnectionService.asBinder()).thenReturn(mock(IBinder.class));

        mComponentContextFixture.addConnectionService(
                SIM_1_ACCOUNT.getAccountHandle().getComponentName(), mIConnectionService);
    }

    @Override
    @After
    public void tearDown() throws Exception {
        mComponentContextFixture.removeConnectionService(
                SIM_1_ACCOUNT.getAccountHandle().getComponentName(), mIConnectionService);
        super.tearDown();
    }

@@ -2841,37 +2827,6 @@ public class CallsManagerTest extends TelecomTestCase {
        assertTrue(result.contains("onReceiveResult"));
    }

    @Test
    public void testConnectionServiceCreateConnectionTimeout() throws Exception {
        mSetRlagsRule.enableFlags(Flags.FLAG_UNBIND_TIMEOUT_CONNECTIONS);
        ConnectionServiceWrapper service = new ConnectionServiceWrapper(
                SIM_1_ACCOUNT.getAccountHandle().getComponentName(), null,
                mPhoneAccountRegistrar, mCallsManager, mContext, mLock, null,
                mFeatureFlags);
        TestScheduledExecutorService scheduledExecutorService = new TestScheduledExecutorService();
        service.setScheduledExecutorService(scheduledExecutorService);
        Call call = addSpyCall();
        service.addCall(call);
        when(call.isCreateConnectionComplete()).thenReturn(false);
        CreateConnectionResponse response = mock(CreateConnectionResponse.class);

        service.createConnection(call, response);
        waitUntilConditionIsTrueOrTimeout(new Condition() {
            @Override
            public Object expected() {
                return true;
            }

            @Override
            public Object actual() {
                return scheduledExecutorService.isRunnableScheduledAtTime(15000L);
            }
        }, 5000L, "Expected job failed to schedule");
        scheduledExecutorService.advanceTime(15000L);
        verify(response).handleCreateConnectionFailure(
                eq(new DisconnectCause(DisconnectCause.ERROR)));
    }

    @SmallTest
    @Test
    public void testOnFailedOutgoingCallUnholdsCallAfterLocallyDisconnect() {
@@ -3457,19 +3412,4 @@ public class CallsManagerTest extends TelecomTestCase {
        when(mockTelephonyManager.getPhoneCapability()).thenReturn(mPhoneCapability);
        when(mPhoneCapability.getMaxActiveVoiceSubscriptions()).thenReturn(num);
    }

    private void waitUntilConditionIsTrueOrTimeout(Condition condition, long timeout,
                                                   String description) throws InterruptedException {
        final long start = System.currentTimeMillis();
        while (!condition.expected().equals(condition.actual())
                && System.currentTimeMillis() - start < timeout) {
            sleep(50);
        }
        assertEquals(description, condition.expected(), condition.actual());
    }

    protected interface Condition {
        Object expected();
        Object actual();
    }
}