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

Commit bd1644c9 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

CallAudioWatchdog cleanups.

1. Always log audio sessions in the dumpsys; we were doing this only for
calls which weren't Telecom calls, however it is nicer to see them both
in one place from an audio perspective.
2. If all media resources end for a call, don't immediately remove it if
has a Telecom call ID associated.  One voip app started and stopped media
entirely during the scope of a single telecom call; this ensures we don't
count that as two separate calls.  Granted, a non-telecom call could get
double-counted for the same reason, however during manual testing of
a number of voip apps this was not seen in any other app.
3. When a call is removed from Telecom, don't remove it from the CAW
unless all audio resources are cleaned up.  We'll cleanup the session once
all audio resources are freed.

Flag: com.android.server.telecom.flags.enable_call_audio_watchdog
Test: Run full CTS suite with flag on
Test: Comprehensive manual testing with voip apps.
Bug: 384570270
Change-Id: Ib684e81335b4b29644ed41af5350396ac6808b94
parent 29996d5d
Loading
Loading
Loading
Loading
+28 −9
Original line number Diff line number Diff line
@@ -395,7 +395,10 @@ public class CallAudioWatchdog extends CallsManagerListenerBase {

    @Override
    public void onCallRemoved(Call call) {
        // Nothing to do for call removal; sessions get cleaned up when their audio goes away.
        // Only track for voip calls.
        if (call.isSelfManaged() || call.isTransactionalCall()) {
            maybeRemoveCall(call);
        }
    }

    @VisibleForTesting
@@ -428,7 +431,7 @@ public class CallAudioWatchdog extends CallsManagerListenerBase {
        }
        sessions.forEach(pw::println);
        pw.decreaseIndent();
        pw.println("Non-Telecom Sessions:");
        pw.println("Audio sessions Sessions:");
        pw.increaseIndent();
        mLocalLog.dump(pw);
        pw.decreaseIndent();
@@ -543,6 +546,27 @@ public class CallAudioWatchdog extends CallsManagerListenerBase {
                CommunicationSession.sessionAttrToString(session.getSessionAttr()));
    }

    /**
     * Given a telecom call, cleanup the session if there are no audio resources remaining for that
     * session.
     * @param call The call.
     */
    private void maybeRemoveCall(Call call) {
        int uid = mPhoneAccountRegistrarProxy.getUidForPhoneAccountHandle(
                call.getTargetPhoneAccount());
        CommunicationSession session;
        synchronized (mCommunicationSessionsLock) {
            session = getSession(uid);
            if (session == null) {
                return;
            }
            if (!session.hasMediaResources()) {
                mLocalLog.log(session.toString());
                mCommunicationSessions.remove(uid);
            }
        }
    }

    /**
     * Returns an existing session for a uid, or {@code null} if none exists.
     * @param uid the uid,
@@ -620,14 +644,9 @@ public class CallAudioWatchdog extends CallsManagerListenerBase {

                // If audio resources are no longer held for a uid, then we'll clean up its
                // media session.
                if (!session.hasMediaResources()) {
                if (!session.hasMediaResources() && session.getTelecomCall() == null) {
                    Log.i(this, "cleanupAttributeForSessions: removing session %s", session);
                    // Only log the audio session if it has no telecom call; we'll correlate to
                    // a telecom call if one was present so the logs for a telecom call will be
                    // in the calls dumpsys.
                    if (session.getTelecomCall() == null) {
                    mLocalLog.log(session.toString());
                    }
                    iterator.remove();
                }
            }