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

Commit 427a8ebc authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Merge cherrypicks of ['googleplex-android-review.googlesource.com/27630623',...

Merge cherrypicks of ['googleplex-android-review.googlesource.com/27630623', 'googleplex-android-review.googlesource.com/27790553', 'googleplex-android-review.googlesource.com/27801273'] into security-aosp-sc-v2-release.

Change-Id: I76f9f8550ba92c4a2bb9bb80d06af0f9cef68a5c
parents 14e1cf9a dac6bc98
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -353,6 +353,17 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
    /** The state of the call. */
    private int mState;

    /**
     * Determines whether the {@link ConnectionService} has responded to the initial request to
     * create the connection.
     *
     * {@code false} indicates the {@link Call} has been added to Telecom, but the
     * {@link Connection} has not yet been returned by the associated {@link ConnectionService}.
     * {@code true} indicates the {@link Call} has an associated {@link Connection} reported by the
     * {@link ConnectionService}.
     */
    private boolean mIsCreateConnectionComplete = false;

    /** The handle with which to establish this call. */
    private Uri mHandle;

@@ -1038,6 +1049,19 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
        return mConnectionService;
    }

    /**
     * @return {@code true} if the connection has been created by the underlying
     * {@link ConnectionService}, {@code false} otherwise.
     */
    public boolean isCreateConnectionComplete() {
        return mIsCreateConnectionComplete;
    }

    @VisibleForTesting
    public void setIsCreateConnectionComplete(boolean isCreateConnectionComplete) {
        mIsCreateConnectionComplete = isCreateConnectionComplete;
    }

    @VisibleForTesting
    public int getState() {
        return mState;
@@ -2189,6 +2213,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
            CallIdMapper idMapper,
            ParcelableConference conference) {
        Log.v(this, "handleCreateConferenceSuccessful %s", conference);
        mIsCreateConnectionComplete = true;
        setTargetPhoneAccount(conference.getPhoneAccount());
        setHandle(conference.getHandle(), conference.getHandlePresentation());

@@ -2222,6 +2247,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
            CallIdMapper idMapper,
            ParcelableConnection connection) {
        Log.v(this, "handleCreateConnectionSuccessful %s", connection);
        mIsCreateConnectionComplete = true;
        setTargetPhoneAccount(connection.getPhoneAccount());
        setHandle(connection.getHandle(), connection.getHandlePresentation());
        setCallerDisplayName(
+4 −0
Original line number Diff line number Diff line
@@ -176,6 +176,10 @@ public class CallScreeningServiceHelper {
                            Log.w(TAG, "Cancelling call id process due to timeout");
                        }
                        mFuture.complete(null);
                        mContext.unbindService(serviceConnection);
                    } catch (IllegalArgumentException e) {
                        Log.i(this, "Exception when unbinding service %s : %s", serviceConnection,
                                e.getMessage());
                    } finally {
                        Log.endSession();
                    }
+79 −2
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.telecom.ConnectionService;
import android.telecom.DisconnectCause;
import android.telecom.GatewayInfo;
import android.telecom.Log;
import android.telecom.Logging.Runnable;
import android.telecom.Logging.Session;
import android.telecom.ParcelableConference;
import android.telecom.ParcelableConnection;
@@ -61,6 +62,11 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/**
 * Wrapper for {@link IConnectionService}s, handles binding to {@link IConnectionService} and keeps
@@ -74,6 +80,11 @@ public class ConnectionServiceWrapper extends ServiceBinder implements

    private static final String TELECOM_ABBREVIATION = "cast";

    private static final long SERVICE_BINDING_TIMEOUT = 15000L;
    private ScheduledExecutorService mScheduledExecutor =
            Executors.newSingleThreadScheduledExecutor();
    // Pre-allocate space for 2 calls; realistically thats all we should ever need (tm)
    private final Map<Call, ScheduledFuture<?>> mScheduledFutureMap = new ConcurrentHashMap<>(2);
    private final class Adapter extends IConnectionServiceAdapter.Stub {

        @Override
@@ -86,6 +97,12 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
            try {
                synchronized (mLock) {
                    logIncoming("handleCreateConnectionComplete %s", callId);
                    Call call = mCallIdMapper.getCall(callId);
                    if (mScheduledFutureMap.containsKey(call)) {
                        ScheduledFuture<?> existingTimeout = mScheduledFutureMap.get(call);
                        existingTimeout.cancel(false /* cancelIfRunning */);
                        mScheduledFutureMap.remove(call);
                    }
                    // Check status hints image for cross user access
                    if (connection.getStatusHints() != null) {
                        Icon icon = connection.getStatusHints().getIcon();
@@ -119,10 +136,23 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
                ParcelableConference conference, Session.Info sessionInfo) {
            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_HANDLE_CREATE_CONNECTION_COMPLETE,
                    mPackageAbbreviation);
            UserHandle callingUserHandle = Binder.getCallingUserHandle();
            long token = Binder.clearCallingIdentity();
            try {
                synchronized (mLock) {
                    logIncoming("handleCreateConferenceComplete %s", callId);
                    // Check status hints image for cross user access
                    if (conference.getStatusHints() != null) {
                        Icon icon = conference.getStatusHints().getIcon();
                        conference.getStatusHints().setIcon(StatusHints.
                                validateAccountIconUserBoundary(icon, callingUserHandle));
                    }
                    Call call = mCallIdMapper.getCall(callId);
                    if (mScheduledFutureMap.containsKey(call)) {
                        ScheduledFuture<?> existingTimeout = mScheduledFutureMap.get(call);
                        existingTimeout.cancel(false /* cancelIfRunning */);
                        mScheduledFutureMap.remove(call);
                    }
                    ConnectionServiceWrapper.this
                            .handleCreateConferenceComplete(callId, request, conference);

@@ -1225,7 +1255,8 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
     * @param context The context.
     * @param userHandle The {@link UserHandle} to use when binding.
     */
    ConnectionServiceWrapper(
    @VisibleForTesting
    public ConnectionServiceWrapper(
            ComponentName componentName,
            ConnectionServiceRepository connectionServiceRepository,
            PhoneAccountRegistrar phoneAccountRegistrar,
@@ -1304,6 +1335,26 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
                        .setIsAdhocConferenceCall(call.isAdhocConferenceCall())
                        .build();

                Runnable r = new Runnable("CSW.cC", mLock) {
                            @Override
                            public void loggedRun() {
                                if (!call.isCreateConnectionComplete()) {
                                    Log.e(this, new Exception(),
                                            "Conference %s creation timeout",
                                            getComponentName());
                                    Log.addEvent(call, LogUtils.Events.CREATE_CONFERENCE_TIMEOUT,
                                            Log.piiHandle(call.getHandle()) + " via:" +
                                                    getComponentName().getPackageName());
                                    response.handleCreateConferenceFailure(
                                            new DisconnectCause(DisconnectCause.ERROR));
                                }
                            }
                        };
                // Post cleanup to the executor service and cache the future, so we can cancel it if
                // needed.
                ScheduledFuture<?> future = mScheduledExecutor.schedule(r.getRunnableToCancel(),
                        SERVICE_BINDING_TIMEOUT, TimeUnit.MILLISECONDS);
                mScheduledFutureMap.put(call, future);
                try {
                    mServiceInterface.createConference(
                            call.getConnectionManagerPhoneAccount(),
@@ -1401,6 +1452,26 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
                        .setRttPipeToInCall(call.getCsToInCallRttPipeForCs())
                        .build();

                Runnable r = new Runnable("CSW.cC", mLock) {
                            @Override
                            public void loggedRun() {
                                if (!call.isCreateConnectionComplete()) {
                                    Log.e(this, new Exception(),
                                            "Connection %s creation timeout",
                                            getComponentName());
                                    Log.addEvent(call, LogUtils.Events.CREATE_CONNECTION_TIMEOUT,
                                            Log.piiHandle(call.getHandle()) + " via:" +
                                                    getComponentName().getPackageName());
                                    response.handleCreateConnectionFailure(
                                            new DisconnectCause(DisconnectCause.ERROR));
                                }
                            }
                        };
                // Post cleanup to the executor service and cache the future, so we can cancel it if
                // needed.
                ScheduledFuture<?> future = mScheduledExecutor.schedule(r.getRunnableToCancel(),
                        SERVICE_BINDING_TIMEOUT, TimeUnit.MILLISECONDS);
                mScheduledFutureMap.put(call, future);
                try {
                    mServiceInterface.createConnection(
                            call.getConnectionManagerPhoneAccount(),
@@ -1810,7 +1881,8 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
        }
    }

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

    @VisibleForTesting
    public void setScheduledExecutorService(ScheduledExecutorService service) {
        mScheduledExecutor = service;
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -126,8 +126,10 @@ public class LogUtils {
        public static final String STOP_CALL_WAITING_TONE = "STOP_CALL_WAITING_TONE";
        public static final String START_CONNECTION = "START_CONNECTION";
        public static final String CREATE_CONNECTION_FAILED = "CREATE_CONNECTION_FAILED";
        public static final String CREATE_CONNECTION_TIMEOUT = "CREATE_CONNECTION_TIMEOUT";
        public static final String START_CONFERENCE = "START_CONFERENCE";
        public static final String CREATE_CONFERENCE_FAILED = "CREATE_CONFERENCE_FAILED";
        public static final String CREATE_CONFERENCE_TIMEOUT = "CREATE_CONFERENCE_TIMEOUT";
        public static final String BIND_CS = "BIND_CS";
        public static final String CS_BOUND = "CS_BOUND";
        public static final String CONFERENCE_WITH = "CONF_WITH";
+2 −0
Original line number Diff line number Diff line
@@ -987,6 +987,7 @@ public class BasicCallTests extends TelecomSystemTest {
        call.setTargetPhoneAccount(mPhoneAccountA1.getAccountHandle());
        assert(call.isVideoCallingSupportedByPhoneAccount());
        assertEquals(VideoProfile.STATE_BIDIRECTIONAL, call.getVideoState());
        call.setIsCreateConnectionComplete(true);
    }

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

    /**
Loading