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

Commit 581b1cb8 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Update self-managed CS logging and telecom test app.

Updating telecom test app to support:
- Focus gained and lost.
- Holdable calls.

These updates help test the new SMCS apis and call swapping functionality.

Updated telecom logging to make it more clear why things are happening:
- Add overloads of hold/unhold methods that allow specifying a reason for
the operation.  This lets us make the telecom dumpsys more clear by
indicating why something was held/unheld.
- Add disconnect overload which allows specifying reason for disconnect.

Bug: 75303815
Test: Manual
Change-Id: I1717d68d07b71d74bcf3be3cd2ac310bd3cd62b4
parent 0b672769
Loading
Loading
Loading
Loading
+26 −8
Original line number Diff line number Diff line
@@ -1725,20 +1725,28 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
        disconnect(0);
    }

    @VisibleForTesting
    public void disconnect(String reason) {
        disconnect(0, reason);
    }

    /**
     * Attempts to disconnect the call through the connection service.
     */
    @VisibleForTesting
    public void disconnect(long disconnectionTimeout) {
        disconnect(disconnectionTimeout, "internal" /** callingPackage */);
        disconnect(disconnectionTimeout, "internal" /** reason */);
    }

    /**
     * Attempts to disconnect the call through the connection service.
     * @param reason the reason for the disconnect; used for logging purposes only.  In some cases
     *               this can be a package name if the disconnect was initiated through an API such
     *               as TelecomManager.
     */
    @VisibleForTesting
    public void disconnect(long disconnectionTimeout, String callingPackage) {
        Log.addEvent(this, LogUtils.Events.REQUEST_DISCONNECT, callingPackage);
    public void disconnect(long disconnectionTimeout, String reason) {
        Log.addEvent(this, LogUtils.Events.REQUEST_DISCONNECT, reason);

        // Track that the call is now locally disconnecting.
        setLocallyDisconnecting(true);
@@ -1859,7 +1867,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
     */
    @VisibleForTesting
    public void reject(boolean rejectWithMessage, String textMessage) {
        reject(rejectWithMessage, textMessage, "internal" /** callingPackage */);
        reject(rejectWithMessage, textMessage, "internal" /** reason */);
    }

    /**
@@ -1867,9 +1875,11 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
     *
     * @param rejectWithMessage Whether to send a text message as part of the call rejection.
     * @param textMessage An optional text message to send as part of the rejection.
     * @param reason The reason for the reject; used for logging purposes.  May be a package name
     *               if the reject is initiated from an API such as TelecomManager.
     */
    @VisibleForTesting
    public void reject(boolean rejectWithMessage, String textMessage, String callingPackage) {
    public void reject(boolean rejectWithMessage, String textMessage, String reason) {
        // Check to verify that the call is still in the ringing state. A call can change states
        // between the time the user hits 'reject' and Telecomm receives the command.
        if (isRinging("reject")) {
@@ -1882,7 +1892,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
                Log.e(this, new NullPointerException(),
                        "reject call failed due to null CS callId=%s", getId());
            }
            Log.addEvent(this, LogUtils.Events.REQUEST_REJECT, callingPackage);
            Log.addEvent(this, LogUtils.Events.REQUEST_REJECT, reason);
        }
    }

@@ -1891,6 +1901,10 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
     */
    @VisibleForTesting
    public void hold() {
        hold(null /* reason */);
    }

    public void hold(String reason) {
        if (mState == CallState.ACTIVE) {
            if (mConnectionService != null) {
                mConnectionService.hold(this);
@@ -1898,7 +1912,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
                Log.e(this, new NullPointerException(),
                        "hold call failed due to null CS callId=%s", getId());
            }
            Log.addEvent(this, LogUtils.Events.REQUEST_HOLD);
            Log.addEvent(this, LogUtils.Events.REQUEST_HOLD, reason);
        }
    }

@@ -1907,6 +1921,10 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
     */
    @VisibleForTesting
    public void unhold() {
        unhold(null /* reason */);
    }

    public void unhold(String reason) {
        if (mState == CallState.ON_HOLD) {
            if (mConnectionService != null) {
                mConnectionService.unhold(this);
@@ -1914,7 +1932,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
                Log.e(this, new NullPointerException(),
                        "unhold call failed due to null CS callId=%s", getId());
            }
            Log.addEvent(this, LogUtils.Events.REQUEST_UNHOLD);
            Log.addEvent(this, LogUtils.Events.REQUEST_UNHOLD, reason);
        }
    }

+26 −19
Original line number Diff line number Diff line
@@ -286,7 +286,8 @@ public class CallsManager extends Call.ListenerBase
                        ConnectionServiceFocusManager.ConnectionServiceFocus connectionService) {
                    mCalls.stream()
                            .filter(c -> c.getConnectionServiceWrapper().equals(connectionService))
                            .forEach(c -> c.disconnect());
                            .forEach(c -> c.disconnect("release " +
                                    connectionService.getComponentName().getPackageName()));
                }

                @Override
@@ -1469,7 +1470,7 @@ public class CallsManager extends Call.ListenerBase
                    // service, then disconnect it, otherwise allow the connection service to
                    // figure out the right states.
                    if (activeCall.getConnectionService() != call.getConnectionService()) {
                        activeCall.disconnect();
                        activeCall.disconnect("Can't hold when answering " + call.getId());
                    }
                }
            }
@@ -1661,25 +1662,27 @@ public class CallsManager extends Call.ListenerBase
            Log.w(this, "Unknown call (%s) asked to be removed from hold", call);
        } else {
            Call activeCall = (Call) mConnectionSvrFocusMgr.getCurrentFocusCall();
            String activeCallId = null;
            if (activeCall != null) {
                activeCallId = activeCall.getId();
                if (canHold(activeCall)) {
                    activeCall.hold();
                    Log.addEvent(activeCall, LogUtils.Events.SWAP);
                    Log.addEvent(call, LogUtils.Events.SWAP);
                    activeCall.hold("Swap to " + call.getId());
                    Log.addEvent(activeCall, LogUtils.Events.SWAP, "To " + call.getId());
                    Log.addEvent(call, LogUtils.Events.SWAP, "From " + activeCall.getId());
                } else {
                    // This call does not support hold. If it is from a different connection
                    // service, then disconnect it, otherwise invoke call.hold() and allow the
                    // connection service to handle the situation.
                    if (activeCall.getConnectionService() != call.getConnectionService()) {
                        activeCall.disconnect();
                        activeCall.disconnect("Swap to " + call.getId());
                    } else {
                        activeCall.hold();
                        activeCall.hold("Swap to " + call.getId());
                    }
                }
            }
            mConnectionSvrFocusMgr.requestFocus(
                    call,
                    new RequestCallback(new ActionUnHoldCall(call)));
                    new RequestCallback(new ActionUnHoldCall(call, activeCallId)));
        }
    }

@@ -1848,7 +1851,7 @@ public class CallsManager extends Call.ListenerBase
            if (makeRoomForOutgoingCall(call, false /* isEmergencyCall */)) {
                call.startCreateConnection(mPhoneAccountRegistrar);
            } else {
                call.disconnect();
                call.disconnect("no room");
            }

            if (setDefault) {
@@ -2807,7 +2810,7 @@ public class CallsManager extends Call.ListenerBase
            if (isEmergency && !canHold(liveCall)) {
                call.getAnalytics().setCallIsAdditional(true);
                liveCall.getAnalytics().setCallIsInterrupted(true);
                liveCall.disconnect();
                liveCall.disconnect("emergency, can't hold");
                return true;
            }

@@ -2850,7 +2853,7 @@ public class CallsManager extends Call.ListenerBase
                Log.i(this, "makeRoomForOutgoingCall: holding live call.");
                call.getAnalytics().setCallIsAdditional(true);
                liveCall.getAnalytics().setCallIsInterrupted(true);
                liveCall.hold();
                liveCall.hold("calling " + call.getId());
                return true;
            }

@@ -3149,7 +3152,7 @@ public class CallsManager extends Call.ListenerBase

            // We are going to place the new outgoing call, so disconnect any ongoing self-managed
            // calls which are ongoing at this time.
            disconnectSelfManagedCalls();
            disconnectSelfManagedCalls("outgoing call " + callId);

            // Kick of the new outgoing call intent from where it left off prior to confirming the
            // call.
@@ -3211,14 +3214,14 @@ public class CallsManager extends Call.ListenerBase
    /**
     * Disconnects all self-managed calls.
     */
    private void disconnectSelfManagedCalls() {
    private void disconnectSelfManagedCalls(String reason) {
        // Disconnect all self-managed calls to make priority for emergency call.
        // Use Call.disconnect() to command the ConnectionService to disconnect the calls.
        // CallsManager.markCallAsDisconnected doesn't actually tell the ConnectionService to
        // disconnect.
        mCalls.stream()
                .filter(c -> c.isSelfManaged())
                .forEach(c -> c.disconnect());
                .forEach(c -> c.disconnect(reason));

        // When disconnecting all self-managed calls, switch audio routing back to the baseline
        // route.  This ensures if, for example, the self-managed ConnectionService was routed to
@@ -3228,11 +3231,13 @@ public class CallsManager extends Call.ListenerBase
    }

    private void disconnectCallsHaveDifferentConnectionService(Call exceptCall) {
        String csPackage = exceptCall.getConnectionService() != null ?
                exceptCall.getConnectionService().getComponentName().toShortString() : "null";
        mCalls.stream().filter(c ->
                c.getConnectionService() != exceptCall.getConnectionService()
                        && c.getConnectionManagerPhoneAccount()
                        != exceptCall.getConnectionManagerPhoneAccount())
                .forEach(c -> c.disconnect());
                .forEach(c -> c.disconnect("CS not " + csPackage));
    }

    /**
@@ -3361,7 +3366,7 @@ public class CallsManager extends Call.ListenerBase
        ConnectionServiceWrapper service = call.getConnectionService();
        service.handoverFailed(call, reason);
        call.setDisconnectCause(new DisconnectCause(DisconnectCause.CANCELED));
        call.disconnect();
        call.disconnect("handover failed");
    }

    /**
@@ -3541,7 +3546,7 @@ public class CallsManager extends Call.ListenerBase
        } else {
            if (call.isEmergencyCall()) {
                // Disconnect all self-managed calls to make priority for emergency call.
                disconnectSelfManagedCalls();
                disconnectSelfManagedCalls("emergency call");
            }

            call.startCreateConnection(mPhoneAccountRegistrar);
@@ -3754,15 +3759,17 @@ public class CallsManager extends Call.ListenerBase

    private final class ActionUnHoldCall implements PendingAction {
        private final Call mCall;
        private final String mPreviouslyHeldCallId;

        ActionUnHoldCall(Call call) {
        ActionUnHoldCall(Call call, String previouslyHeldCallId) {
            mCall = call;
            mPreviouslyHeldCallId = previouslyHeldCallId;
        }

        @Override
        public void performAction() {
            Log.d(this, "perform unhold call for %s", mCall);
            mCall.unhold();
            mCall.unhold("held " + mPreviouslyHeldCallId);
        }
    }

+7 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.telecom;

import android.annotation.Nullable;
import android.content.ComponentName;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -64,6 +65,12 @@ public class ConnectionServiceFocusManager {
         * @see {@link ConnectionServiceFocusListener}.
         */
        void setConnectionServiceFocusListener(ConnectionServiceFocusListener listener);

        /**
         * Get the {@link ComponentName} of the ConnectionService for logging purposes.
         * @return the {@link ComponentName}.
         */
        ComponentName getComponentName();
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -309,7 +309,7 @@ abstract class ServiceBinder {
        }
    }

    final ComponentName getComponentName() {
    public final ComponentName getComponentName() {
        return mComponentName;
    }

+5 −0
Original line number Diff line number Diff line
@@ -72,5 +72,10 @@
            android:layout_height="wrap_content"
            android:text="Earpiece"
            android:id="@+id/earpieceButton" />
        <CheckBox
            android:id="@+id/holdable"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_weight="1"
            android:text="Holdable"/>
    </LinearLayout>
</LinearLayout>
 No newline at end of file
Loading