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

Commit 357a4854 authored by Tyler Gunn's avatar Tyler Gunn Committed by Automerger Merge Worker
Browse files

Merge "Improve connection manager logging." into rvc-dev am: 6e8a87e0

Change-Id: I86961e4b8b3f2fb5d43be27e3a7668bd7c011d42
parents 0675309d 6e8a87e0
Loading
Loading
Loading
Loading
+29 −29
Original line number Diff line number Diff line
@@ -2102,12 +2102,12 @@ public abstract class ConnectionService extends Service {


    private void abort(String callId) {
        Log.d(this, "abort %s", callId);
        Log.i(this, "abort %s", callId);
        findConnectionForAction(callId, "abort").onAbort();
    }

    private void answerVideo(String callId, int videoState) {
        Log.d(this, "answerVideo %s", callId);
        Log.i(this, "answerVideo %s", callId);
        if (mConnectionById.containsKey(callId)) {
            findConnectionForAction(callId, "answer").onAnswer(videoState);
        } else {
@@ -2116,7 +2116,7 @@ public abstract class ConnectionService extends Service {
    }

    private void answer(String callId) {
        Log.d(this, "answer %s", callId);
        Log.i(this, "answer %s", callId);
        if (mConnectionById.containsKey(callId)) {
            findConnectionForAction(callId, "answer").onAnswer();
        } else {
@@ -2125,12 +2125,12 @@ public abstract class ConnectionService extends Service {
    }

    private void deflect(String callId, Uri address) {
        Log.d(this, "deflect %s", callId);
        Log.i(this, "deflect %s", callId);
        findConnectionForAction(callId, "deflect").onDeflect(address);
    }

    private void reject(String callId) {
        Log.d(this, "reject %s", callId);
        Log.i(this, "reject %s", callId);
        if (mConnectionById.containsKey(callId)) {
            findConnectionForAction(callId, "reject").onReject();
        } else {
@@ -2139,34 +2139,34 @@ public abstract class ConnectionService extends Service {
    }

    private void reject(String callId, String rejectWithMessage) {
        Log.d(this, "reject %s with message", callId);
        Log.i(this, "reject %s with message", callId);
        findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
    }

    private void reject(String callId, @android.telecom.Call.RejectReason int rejectReason) {
        Log.d(this, "reject %s with reason %d", callId, rejectReason);
        Log.i(this, "reject %s with reason %d", callId, rejectReason);
        findConnectionForAction(callId, "reject").onReject(rejectReason);
    }

    private void transfer(String callId, Uri number, boolean isConfirmationRequired) {
        Log.d(this, "transfer %s", callId);
        Log.i(this, "transfer %s", callId);
        findConnectionForAction(callId, "transfer").onTransfer(number, isConfirmationRequired);
    }

    private void consultativeTransfer(String callId, String otherCallId) {
        Log.d(this, "consultativeTransfer %s", callId);
        Log.i(this, "consultativeTransfer %s", callId);
        Connection connection1 = findConnectionForAction(callId, "consultativeTransfer");
        Connection connection2 = findConnectionForAction(otherCallId, " consultativeTransfer");
        connection1.onTransfer(connection2);
    }

    private void silence(String callId) {
        Log.d(this, "silence %s", callId);
        Log.i(this, "silence %s", callId);
        findConnectionForAction(callId, "silence").onSilence();
    }

    private void disconnect(String callId) {
        Log.d(this, "disconnect %s", callId);
        Log.i(this, "disconnect %s", callId);
        if (mConnectionById.containsKey(callId)) {
            findConnectionForAction(callId, "disconnect").onDisconnect();
        } else {
@@ -2175,7 +2175,7 @@ public abstract class ConnectionService extends Service {
    }

    private void hold(String callId) {
        Log.d(this, "hold %s", callId);
        Log.i(this, "hold %s", callId);
        if (mConnectionById.containsKey(callId)) {
            findConnectionForAction(callId, "hold").onHold();
        } else {
@@ -2184,7 +2184,7 @@ public abstract class ConnectionService extends Service {
    }

    private void unhold(String callId) {
        Log.d(this, "unhold %s", callId);
        Log.i(this, "unhold %s", callId);
        if (mConnectionById.containsKey(callId)) {
            findConnectionForAction(callId, "unhold").onUnhold();
        } else {
@@ -2193,7 +2193,7 @@ public abstract class ConnectionService extends Service {
    }

    private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
        Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
        Log.i(this, "onAudioStateChanged %s %s", callId, callAudioState);
        if (mConnectionById.containsKey(callId)) {
            findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
                    callAudioState);
@@ -2204,7 +2204,7 @@ public abstract class ConnectionService extends Service {
    }

    private void playDtmfTone(String callId, char digit) {
        Log.d(this, "playDtmfTone %s %c", callId, digit);
        Log.i(this, "playDtmfTone %s %c", callId, digit);
        if (mConnectionById.containsKey(callId)) {
            findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
        } else {
@@ -2213,7 +2213,7 @@ public abstract class ConnectionService extends Service {
    }

    private void stopDtmfTone(String callId) {
        Log.d(this, "stopDtmfTone %s", callId);
        Log.i(this, "stopDtmfTone %s", callId);
        if (mConnectionById.containsKey(callId)) {
            findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
        } else {
@@ -2222,7 +2222,7 @@ public abstract class ConnectionService extends Service {
    }

    private void conference(String callId1, String callId2) {
        Log.d(this, "conference %s, %s", callId1, callId2);
        Log.i(this, "conference %s, %s", callId1, callId2);

        // Attempt to get second connection or conference.
        Connection connection2 = findConnectionForAction(callId2, "conference");
@@ -2269,7 +2269,7 @@ public abstract class ConnectionService extends Service {
    }

    private void splitFromConference(String callId) {
        Log.d(this, "splitFromConference(%s)", callId);
        Log.i(this, "splitFromConference(%s)", callId);

        Connection connection = findConnectionForAction(callId, "splitFromConference");
        if (connection == getNullConnection()) {
@@ -2284,7 +2284,7 @@ public abstract class ConnectionService extends Service {
    }

    private void mergeConference(String callId) {
        Log.d(this, "mergeConference(%s)", callId);
        Log.i(this, "mergeConference(%s)", callId);
        Conference conference = findConferenceForAction(callId, "mergeConference");
        if (conference != null) {
            conference.onMerge();
@@ -2292,7 +2292,7 @@ public abstract class ConnectionService extends Service {
    }

    private void swapConference(String callId) {
        Log.d(this, "swapConference(%s)", callId);
        Log.i(this, "swapConference(%s)", callId);
        Conference conference = findConferenceForAction(callId, "swapConference");
        if (conference != null) {
            conference.onSwap();
@@ -2300,7 +2300,7 @@ public abstract class ConnectionService extends Service {
    }

    private void addConferenceParticipants(String callId, List<Uri> participants) {
        Log.d(this, "addConferenceParticipants(%s)", callId);
        Log.i(this, "addConferenceParticipants(%s)", callId);
        if (mConnectionById.containsKey(callId)) {
            findConnectionForAction(callId, "addConferenceParticipants")
                    .onAddConferenceParticipants(participants);
@@ -2318,7 +2318,7 @@ public abstract class ConnectionService extends Service {
     * @param callId The ID of the call to pull.
     */
    private void pullExternalCall(String callId) {
        Log.d(this, "pullExternalCall(%s)", callId);
        Log.i(this, "pullExternalCall(%s)", callId);
        Connection connection = findConnectionForAction(callId, "pullExternalCall");
        if (connection != null) {
            connection.onPullExternalCall();
@@ -2335,7 +2335,7 @@ public abstract class ConnectionService extends Service {
     * @param extras Extras associated with the event.
     */
    private void sendCallEvent(String callId, String event, Bundle extras) {
        Log.d(this, "sendCallEvent(%s, %s)", callId, event);
        Log.i(this, "sendCallEvent(%s, %s)", callId, event);
        Connection connection = findConnectionForAction(callId, "sendCallEvent");
        if (connection != null) {
            connection.onCallEvent(event, extras);
@@ -2348,7 +2348,7 @@ public abstract class ConnectionService extends Service {
     * @param callId The ID of the call which completed handover.
     */
    private void notifyHandoverComplete(String callId) {
        Log.d(this, "notifyHandoverComplete(%s)", callId);
        Log.i(this, "notifyHandoverComplete(%s)", callId);
        Connection connection = findConnectionForAction(callId, "notifyHandoverComplete");
        if (connection != null) {
            connection.onHandoverComplete();
@@ -2368,7 +2368,7 @@ public abstract class ConnectionService extends Service {
     * @param extras The new extras bundle.
     */
    private void handleExtrasChanged(String callId, Bundle extras) {
        Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
        Log.i(this, "handleExtrasChanged(%s, %s)", callId, extras);
        if (mConnectionById.containsKey(callId)) {
            findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
        } else if (mConferenceById.containsKey(callId)) {
@@ -2377,7 +2377,7 @@ public abstract class ConnectionService extends Service {
    }

    private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
        Log.d(this, "startRtt(%s)", callId);
        Log.i(this, "startRtt(%s)", callId);
        if (mConnectionById.containsKey(callId)) {
            findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
        } else if (mConferenceById.containsKey(callId)) {
@@ -2386,7 +2386,7 @@ public abstract class ConnectionService extends Service {
    }

    private void stopRtt(String callId) {
        Log.d(this, "stopRtt(%s)", callId);
        Log.i(this, "stopRtt(%s)", callId);
        if (mConnectionById.containsKey(callId)) {
            findConnectionForAction(callId, "stopRtt").onStopRtt();
        } else if (mConferenceById.containsKey(callId)) {
@@ -2395,7 +2395,7 @@ public abstract class ConnectionService extends Service {
    }

    private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
        Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
        Log.i(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
        if (mConnectionById.containsKey(callId)) {
            findConnectionForAction(callId, "handleRttUpgradeResponse")
                    .handleRttUpgradeResponse(rttTextStream);
@@ -2405,7 +2405,7 @@ public abstract class ConnectionService extends Service {
    }

    private void onPostDialContinue(String callId, boolean proceed) {
        Log.d(this, "onPostDialContinue(%s)", callId);
        Log.i(this, "onPostDialContinue(%s)", callId);
        findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
    }

+44 −0
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@

package android.telecom;

import android.annotation.NonNull;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
@@ -29,8 +31,10 @@ import android.text.TextUtils;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IndentingPrintWriter;

import java.util.Arrays;
import java.util.IllegalFormatException;
import java.util.Locale;
import java.util.stream.Collectors;

/**
 * Manages logging for the entire module.
@@ -212,6 +216,16 @@ public class Log {
        return getSessionManager().getExternalSession();
    }

    /**
     * Retrieves external session information, providing a context for the recipient of the session
     * info where the external session came from.
     * @param ownerInfo The external owner info.
     * @return New {@link Session.Info} instance with owner info set.
     */
    public static Session.Info getExternalSession(@NonNull String ownerInfo) {
        return getSessionManager().getExternalSession(ownerInfo);
    }

    public static void cancelSubsession(Session subsession) {
        getSessionManager().cancelSubsession(subsession);
    }
@@ -481,4 +495,34 @@ public class Log {
        }
        return String.format(Locale.US, "%s: %s%s", prefix, msg, sessionPostfix);
    }

    /**
     * Generates an abbreviated version of the package name from a component.
     * E.g. com.android.phone becomes cap
     * @param componentName The component name to abbreviate.
     * @return Abbreviation of empty string if component is null.
     * @hide
     */
    public static String getPackageAbbreviation(ComponentName componentName) {
        if (componentName == null) {
            return "";
        }
        return getPackageAbbreviation(componentName.getPackageName());
    }

    /**
     * Generates an abbreviated version of the package name.
     * E.g. com.android.phone becomes cap
     * @param packageName The packageName name to abbreviate.
     * @return Abbreviation of empty string if package is null.
     * @hide
     */
    public static String getPackageAbbreviation(String packageName) {
        if (packageName == null) {
            return "";
        }
        return Arrays.stream(packageName.split("\\."))
                .map(s -> s.substring(0,1))
                .collect(Collectors.joining(""));
    }
}
+37 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.telecom.Logging;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;
import android.telecom.Log;
@@ -59,10 +60,12 @@ public class Session {
    public static class Info implements Parcelable {
        public final String sessionId;
        public final String methodPath;
        public final String ownerInfo;

        private Info(String id, String path) {
        private Info(String id, String path, String owner) {
            sessionId = id;
            methodPath = path;
            ownerInfo = owner;
        }

        public static Info getInfo (Session s) {
@@ -70,7 +73,28 @@ public class Session {
            // not get multiple stacking external sessions (unless we have DEBUG level logging or
            // lower).
            return new Info(s.getFullSessionId(), s.getFullMethodPath(
                    !Log.DEBUG && s.isSessionExternal()));
                    !Log.DEBUG && s.isSessionExternal()), s.getOwnerInfo());
        }

        public static Info getExternalInfo(Session s, @Nullable String ownerInfo) {
            // When creating session information for an existing session, the caller may pass in a
            // context to be passed along to the recipient of the external session info.
            // So, for example, if telecom has an active session with owner 'cad', and Telecom is
            // calling into Telephony and providing external session info, it would pass in 'cast'
            // as the owner info.  This would result in Telephony seeing owner info 'cad/cast',
            // which would make it very clear in the Telephony logs the chain of package calls which
            // ultimately resulted in the logs.
            String newInfo = ownerInfo != null && s.getOwnerInfo() != null
                    // If we've got both, concatenate them.
                    ? s.getOwnerInfo() + "/" + ownerInfo
                    // Otherwise use whichever is present.
                    : ownerInfo != null ? ownerInfo : s.getOwnerInfo();

            // Create Info based on the truncated method path if the session is external, so we do
            // not get multiple stacking external sessions (unless we have DEBUG level logging or
            // lower).
            return new Info(s.getFullSessionId(), s.getFullMethodPath(
                    !Log.DEBUG && s.isSessionExternal()), newInfo);
        }

        /** Responsible for creating Info objects for deserialized Parcels. */
@@ -80,7 +104,8 @@ public class Session {
                    public Info createFromParcel(Parcel source) {
                        String id = source.readString();
                        String methodName = source.readString();
                        return new Info(id, methodName);
                        String ownerInfo = source.readString();
                        return new Info(id, methodName, ownerInfo);
                    }

                    @Override
@@ -100,6 +125,7 @@ public class Session {
        public void writeToParcel(Parcel destination, int flags) {
            destination.writeString(sessionId);
            destination.writeString(methodPath);
            destination.writeString(ownerInfo);
        }
    }

@@ -206,6 +232,14 @@ public class Session {
        return Info.getInfo(this);
    }

    public Info getExternalInfo(@Nullable String ownerInfo) {
        return Info.getExternalInfo(this, ownerInfo);
    }

    public String getOwnerInfo() {
        return mOwnerInfo;
    }

    @VisibleForTesting
    public String getSessionId() {
        return mSessionId;
+11 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.telecom.Logging;

import android.annotation.Nullable;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
@@ -180,7 +181,7 @@ public class SessionManager {
        Log.d(LOGGING_TAG, Session.START_EXTERNAL_SESSION);
        Session externalSession = new Session(Session.EXTERNAL_INDICATOR + sessionInfo.sessionId,
                sessionInfo.methodPath, System.currentTimeMillis(),
                false /*isStartedFromActiveSession*/, null);
                false /*isStartedFromActiveSession*/, sessionInfo.ownerInfo);
        externalSession.setIsExternal(true);
        // Mark the external session as already completed, since we have no way of knowing when
        // the external session actually has completed.
@@ -224,7 +225,7 @@ public class SessionManager {
        // Start execution time of the session will be overwritten in continueSession(...).
        Session newSubsession = new Session(threadSession.getNextChildId(),
                threadSession.getShortMethodName(), System.currentTimeMillis(),
                isStartedFromActiveSession, null);
                isStartedFromActiveSession, threadSession.getOwnerInfo());
        threadSession.addChild(newSubsession);
        newSubsession.setParentSession(threadSession);

@@ -238,12 +239,18 @@ public class SessionManager {
        return newSubsession;
    }

    public synchronized Session.Info getExternalSession() {
        return getExternalSession(null /* ownerInfo */);
    }

    /**
     * Retrieve the information of the currently active Session. This information is parcelable and
     * is used to create an external Session ({@link #startExternalSession(Session.Info, String)}).
     * If there is no Session active, this method will return null.
     * @param ownerInfo Owner information for the session.
     * @return The session information
     */
    public synchronized Session.Info getExternalSession() {
    public synchronized Session.Info getExternalSession(@Nullable String ownerInfo) {
        int threadId = getCallingThreadId();
        Session threadSession = mSessionMapper.get(threadId);
        if (threadSession == null) {
@@ -251,8 +258,7 @@ public class SessionManager {
                    "active.");
            return null;
        }

        return threadSession.getInfo();
        return threadSession.getExternalInfo(ownerInfo);
    }

    /**
+80 −3

File changed.

Preview size limit exceeded, changes collapsed.