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

Commit 68e57f2d authored by Pengquan Meng's avatar Pengquan Meng Committed by android-build-merger
Browse files

Integrate connectionServiceFocusManager into call flow

am: 4832f208

Change-Id: Ia47e04bedae451b8dcf0a5e8ed7e187919bf98fc
parents 0c403a28 4832f208
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -1763,7 +1763,8 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
    /**
     * Puts the call on hold if it is currently active.
     */
    void hold() {
    @VisibleForTesting
    public void hold() {
        if (mState == CallState.ACTIVE) {
            if (mConnectionService != null) {
                mConnectionService.hold(this);
@@ -1778,7 +1779,8 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
    /**
     * Releases the call from hold if it is currently active.
     */
    void unhold() {
    @VisibleForTesting
    public void unhold() {
        if (mState == CallState.ON_HOLD) {
            if (mConnectionService != null) {
                mConnectionService.unhold(this);
@@ -2800,6 +2802,10 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
        return mOriginalConnectionId;
    }

    ConnectionServiceFocusManager getConnectionServiceFocusManager() {
        return mCallsManager.getConnectionServiceFocusManager();
    }

    /**
     * Determines if a {@link Call}'s capabilities bitmask indicates that video is supported either
     * remotely or locally.
+237 −131

File changed.

Preview size limit exceeded, changes collapsed.

+37 −13
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.Nullable;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.telecom.Log;
import com.android.internal.annotations.VisibleForTesting;

import java.util.ArrayList;
@@ -28,8 +29,12 @@ import java.util.Objects;
import java.util.stream.Collectors;

public class ConnectionServiceFocusManager {
    private static final String TAG = "ConnectionSvrFocusMgr";

    private static final String TAG = "ConnectionServiceFocusManager";
    /** Factory interface used to create the {@link ConnectionServiceFocusManager} instance. */
    public interface ConnectionServiceFocusManagerFactory {
        ConnectionServiceFocusManager create(CallsManagerRequester requester, Looper looper);
    }

    /**
     * Interface used by ConnectionServiceFocusManager to communicate with
@@ -191,14 +196,18 @@ public class ConnectionServiceFocusManager {
    private final ConnectionServiceFocusListener mConnectionServiceFocusListener =
            new ConnectionServiceFocusListener() {
                @Override
        public void onConnectionServiceReleased(ConnectionServiceFocus connectionServiceFocus) {
            mEventHandler.obtainMessage(MSG_RELEASE_CONNECTION_FOCUS, connectionServiceFocus)
                public void onConnectionServiceReleased(
                        ConnectionServiceFocus connectionServiceFocus) {
                    mEventHandler
                            .obtainMessage(MSG_RELEASE_CONNECTION_FOCUS, connectionServiceFocus)
                            .sendToTarget();
                }

                @Override
        public void onConnectionServiceDeath(ConnectionServiceFocus connectionServiceFocus) {
            mEventHandler.obtainMessage(MSG_CONNECTION_SERVICE_DEATH, connectionServiceFocus)
                public void onConnectionServiceDeath(
                        ConnectionServiceFocus connectionServiceFocus) {
                    mEventHandler
                            .obtainMessage(MSG_CONNECTION_SERVICE_DEATH, connectionServiceFocus)
                            .sendToTarget();
                }
            };
@@ -257,6 +266,7 @@ public class ConnectionServiceFocusManager {
                connSvrFocus.connectionServiceFocusGained();
            }
            mCurrentFocus = connSvrFocus;
            Log.d(this, "updateConnectionServiceFocus connSvr = %s", connSvrFocus);
        }
    }

@@ -276,10 +286,13 @@ public class ConnectionServiceFocusManager {
            for (CallFocus call : calls) {
                if (call.getState() == PRIORITY_FOCUS_CALL_STATE[i]) {
                    mCurrentFocusCall = call;
                    Log.d(this, "updateCurrentFocusCall %s", mCurrentFocusCall);
                    return;
                }
            }
        }

        Log.d(this, "updateCurrentFocusCall = null");
    }

    private void onRequestFocusDone(FocusRequest focusRequest) {
@@ -289,6 +302,7 @@ public class ConnectionServiceFocusManager {
    }

    private void handleRequestFocus(FocusRequest focusRequest) {
        Log.d(this, "handleRequestFocus req = %s", focusRequest);
        if (mCurrentFocus == null
                || mCurrentFocus.equals(focusRequest.call.getConnectionServiceWrapper())) {
            updateConnectionServiceFocus(focusRequest.call.getConnectionServiceWrapper());
@@ -304,6 +318,7 @@ public class ConnectionServiceFocusManager {
    }

    private void handleReleasedFocus(ConnectionServiceFocus connectionServiceFocus) {
        Log.d(this, "handleReleasedFocus connSvr = %s", connectionServiceFocus);
        // The ConnectionService can call onConnectionServiceFocusReleased even if it's not the
        // current focus connection service, nothing will be changed in this case.
        if (Objects.equals(mCurrentFocus, connectionServiceFocus)) {
@@ -322,6 +337,7 @@ public class ConnectionServiceFocusManager {
    }

    private void handleReleasedFocusTimeout(FocusRequest focusRequest) {
        Log.d(this, "handleReleasedFocusTimeout req = %s", focusRequest);
        mCallsManagerRequester.releaseConnectionService(mCurrentFocus);
        updateConnectionServiceFocus(focusRequest.call.getConnectionServiceWrapper());
        updateCurrentFocusCall();
@@ -330,6 +346,7 @@ public class ConnectionServiceFocusManager {
    }

    private void handleConnectionServiceDeath(ConnectionServiceFocus connectionServiceFocus) {
        Log.d(this, "handleConnectionServiceDeath %s", connectionServiceFocus);
        if (Objects.equals(connectionServiceFocus, mCurrentFocus)) {
            updateConnectionServiceFocus(null);
            updateCurrentFocusCall();
@@ -337,6 +354,7 @@ public class ConnectionServiceFocusManager {
    }

    private void handleAddedCall(CallFocus call) {
        Log.d(this, "handleAddedCall %s", call);
        if (!mCalls.contains(call)) {
            mCalls.add(call);
        }
@@ -346,6 +364,7 @@ public class ConnectionServiceFocusManager {
    }

    private void handleRemovedCall(CallFocus call) {
        Log.d(this, "handleRemovedCall %s", call);
        mCalls.remove(call);
        if (call.equals(mCurrentFocusCall)) {
            updateCurrentFocusCall();
@@ -353,6 +372,11 @@ public class ConnectionServiceFocusManager {
    }

    private void handleCallStateChanged(CallFocus call, int oldState, int newState) {
        Log.d(this,
                "handleCallStateChanged %s, oldState = %d, newState = %d",
                call,
                oldState,
                newState);
        if (mCalls.contains(call)
                && Objects.equals(mCurrentFocus, call.getConnectionServiceWrapper())) {
            updateCurrentFocusCall();
+42 −4
Original line number Diff line number Diff line
@@ -859,8 +859,17 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
        @Override
        public void onConnectionServiceFocusReleased(Session.Info sessionInfo)
                throws RemoteException {
            // TODO(mpq): This method is added to avoid the compiled error. Add the real
            // implementation once ag/3273964 done.
            Log.startSession(sessionInfo, "CSW.oCSFR");
            long token = Binder.clearCallingIdentity();
            try {
                synchronized (mLock) {
                    mConnSvrFocusListener.onConnectionServiceReleased(
                            ConnectionServiceWrapper.this);
                }
            } finally {
                Binder.restoreCallingIdentity(token);
                Log.endSession();
            }
        }
    }

@@ -1421,12 +1430,41 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
        // Immediately response to the Telecom that it has released the call resources.
        // TODO(mpq): Change back to the default implementation once b/69651192 done.
        if (mConnSvrFocusListener != null) {
            mConnSvrFocusListener.onConnectionServiceReleased(this);
            mConnSvrFocusListener.onConnectionServiceReleased(ConnectionServiceWrapper.this);
        }
        BindCallback callback = new BindCallback() {
            @Override
            public void onSuccess() {
                try {
                    mServiceInterface.connectionServiceFocusLost(Log.getExternalSession());
                } catch (RemoteException ignored) {
                    Log.d(this, "failed to inform the focus lost event");
                }
            }

            @Override
    public void connectionServiceFocusGained() {}
            public void onFailure() {}
        };
        mBinder.bind(callback, null /* null call */);
    }

    @Override
    public void connectionServiceFocusGained() {
        BindCallback callback = new BindCallback() {
            @Override
            public void onSuccess() {
                try {
                    mServiceInterface.connectionServiceFocusGained(Log.getExternalSession());
                } catch (RemoteException ignored) {
                    Log.d(this, "failed to inform the focus gained event");
                }
            }

            @Override
            public void onFailure() {}
        };
        mBinder.bind(callback, null /* null call */);
    }

    @Override
    public void setConnectionServiceFocusListener(
+17 −1
Original line number Diff line number Diff line
@@ -213,8 +213,24 @@ public class CreateConnectionProcessor implements CreateConnectionResponse {
                mCall.setTargetPhoneAccount(attempt.targetPhoneAccount);
                mCall.setConnectionService(mService);
                setTimeoutIfNeeded(mService, attempt);
                if (mCall.isIncoming()) {
                    mService.createConnection(mCall, CreateConnectionProcessor.this);
                } else {
                    // Start to create the connection for outgoing call after the ConnectionService
                    // of the call has gained the focus.
                    mCall.getConnectionServiceFocusManager().requestFocus(
                            mCall,
                            new CallsManager.RequestCallback(new CallsManager.PendingAction() {
                                @Override
                                public void performAction() {
                                    Log.d(this, "perform create connection");
                                    mService.createConnection(
                                            mCall,
                                            CreateConnectionProcessor.this);
                                }
                            }));

                mService.createConnection(mCall, this);
                }
            }
        } else {
            Log.v(this, "attemptNextPhoneAccount, no more accounts, failing");
Loading