Merge "Improve connection manager logging." into rvc-dev
diff --git a/telecomm/java/android/telecom/ConnectionService.java b/telecomm/java/android/telecom/ConnectionService.java
index a716b37..56cba1d 100755
--- a/telecomm/java/android/telecom/ConnectionService.java
+++ b/telecomm/java/android/telecom/ConnectionService.java
@@ -2102,12 +2102,12 @@
 
 
     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 @@
     }
 
     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 @@
     }
 
     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 @@
     }
 
     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 @@
     }
 
     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 @@
     }
 
     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 @@
     }
 
     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 @@
     }
 
     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 @@
     }
 
     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 @@
     }
 
     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 @@
     }
 
     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 @@
     }
 
     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 @@
     }
 
     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 @@
     }
 
     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 @@
      * @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 @@
      * @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 @@
      * @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 @@
      * @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 @@
     }
 
     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 @@
     }
 
     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 @@
     }
 
     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 @@
     }
 
     private void onPostDialContinue(String callId, boolean proceed) {
-        Log.d(this, "onPostDialContinue(%s)", callId);
+        Log.i(this, "onPostDialContinue(%s)", callId);
         findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
     }
 
diff --git a/telecomm/java/android/telecom/Log.java b/telecomm/java/android/telecom/Log.java
index 4f6a9d6..a90d053 100644
--- a/telecomm/java/android/telecom/Log.java
+++ b/telecomm/java/android/telecom/Log.java
@@ -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 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 @@
         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 @@
         }
         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(""));
+    }
 }
diff --git a/telecomm/java/android/telecom/Logging/Session.java b/telecomm/java/android/telecom/Logging/Session.java
index 8d3f4e1..4aa3614 100644
--- a/telecomm/java/android/telecom/Logging/Session.java
+++ b/telecomm/java/android/telecom/Logging/Session.java
@@ -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 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 @@
             // 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 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 void writeToParcel(Parcel destination, int flags) {
             destination.writeString(sessionId);
             destination.writeString(methodPath);
+            destination.writeString(ownerInfo);
         }
     }
 
@@ -206,6 +232,14 @@
         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;
diff --git a/telecomm/java/android/telecom/Logging/SessionManager.java b/telecomm/java/android/telecom/Logging/SessionManager.java
index ac30058..67e5eab 100644
--- a/telecomm/java/android/telecom/Logging/SessionManager.java
+++ b/telecomm/java/android/telecom/Logging/SessionManager.java
@@ -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 @@
         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 @@
         // 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 @@
         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 @@
                     "active.");
             return null;
         }
-
-        return threadSession.getInfo();
+        return threadSession.getExternalInfo(ownerInfo);
     }
 
     /**
diff --git a/telecomm/java/android/telecom/RemoteConnection.java b/telecomm/java/android/telecom/RemoteConnection.java
index 05480dc..f947d34 100644
--- a/telecomm/java/android/telecom/RemoteConnection.java
+++ b/telecomm/java/android/telecom/RemoteConnection.java
@@ -30,13 +30,16 @@
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.RemoteException;
+import android.telecom.Logging.Session;
 import android.view.Surface;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
 
 /**
  * A connection provided to a {@link ConnectionService} by another {@code ConnectionService}
@@ -655,6 +658,8 @@
     private int mCallerDisplayNamePresentation;
     private RemoteConference mConference;
     private Bundle mExtras;
+    private String mCallingPackage;
+    private String mCallingPackageAbbreviation;
 
     /**
      * @hide
@@ -667,6 +672,13 @@
         mConnectionService = connectionService;
         mConnected = true;
         mState = Connection.STATE_INITIALIZING;
+        if (request != null && request.getExtras() != null
+                && request.getExtras().containsKey(
+                        Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME)) {
+            mCallingPackage = request.getExtras().getString(
+                    Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME);
+            mCallingPackageAbbreviation = Log.getPackageAbbreviation(mCallingPackage);
+        }
     }
 
     /**
@@ -705,6 +717,8 @@
         Bundle newExtras = new Bundle();
         newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId);
         putExtras(newExtras);
+        mCallingPackage = callingPackage;
+        mCallingPackageAbbreviation = Log.getPackageAbbreviation(mCallingPackage);
     }
 
     /**
@@ -899,11 +913,14 @@
      * Instructs this {@code RemoteConnection} to abort.
      */
     public void abort() {
+        Log.startSession("RC.a", getActiveOwnerInfo());
         try {
             if (mConnected) {
-                mConnectionService.abort(mConnectionId, null /*Session.Info*/);
+                mConnectionService.abort(mConnectionId, Log.getExternalSession());
             }
         } catch (RemoteException ignored) {
+        } finally {
+            Log.endSession();
         }
     }
 
@@ -911,11 +928,14 @@
      * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
      */
     public void answer() {
+        Log.startSession("RC.an", getActiveOwnerInfo());
         try {
             if (mConnected) {
-                mConnectionService.answer(mConnectionId, null /*Session.Info*/);
+               mConnectionService.answer(mConnectionId, Log.getExternalSession());
             }
         } catch (RemoteException ignored) {
+        } finally {
+            Log.endSession();
         }
     }
 
@@ -925,11 +945,14 @@
      * @hide
      */
     public void answer(int videoState) {
+        Log.startSession("RC.an2", getActiveOwnerInfo());
         try {
             if (mConnected) {
                 mConnectionService.answerVideo(mConnectionId, videoState, null /*Session.Info*/);
             }
         } catch (RemoteException ignored) {
+        } finally {
+            Log.endSession();
         }
     }
 
@@ -937,11 +960,14 @@
      * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject.
      */
     public void reject() {
+        Log.startSession("RC.r", getActiveOwnerInfo());
         try {
             if (mConnected) {
                 mConnectionService.reject(mConnectionId, null /*Session.Info*/);
             }
         } catch (RemoteException ignored) {
+        } finally {
+            Log.endSession();
         }
     }
 
@@ -949,11 +975,14 @@
      * Instructs this {@code RemoteConnection} to go on hold.
      */
     public void hold() {
+        Log.startSession("RC.h", getActiveOwnerInfo());
         try {
             if (mConnected) {
                 mConnectionService.hold(mConnectionId, null /*Session.Info*/);
             }
         } catch (RemoteException ignored) {
+        } finally {
+            Log.endSession();
         }
     }
 
@@ -961,11 +990,14 @@
      * Instructs this {@link Connection#STATE_HOLDING} call to release from hold.
      */
     public void unhold() {
+        Log.startSession("RC.u", getActiveOwnerInfo());
         try {
             if (mConnected) {
                 mConnectionService.unhold(mConnectionId, null /*Session.Info*/);
             }
         } catch (RemoteException ignored) {
+        } finally {
+            Log.endSession();
         }
     }
 
@@ -973,11 +1005,15 @@
      * Instructs this {@code RemoteConnection} to disconnect.
      */
     public void disconnect() {
+        Log.startSession("RC.d", getActiveOwnerInfo());
         try {
             if (mConnected) {
-                mConnectionService.disconnect(mConnectionId, null /*Session.Info*/);
+                mConnectionService.disconnect(mConnectionId, Log.getExternalSession(
+                        mCallingPackageAbbreviation));
             }
         } catch (RemoteException ignored) {
+        } finally {
+            Log.endSession();
         }
     }
 
@@ -991,11 +1027,14 @@
      *         value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
      */
     public void playDtmfTone(char digit) {
+        Log.startSession("RC.pDT", getActiveOwnerInfo());
         try {
             if (mConnected) {
                 mConnectionService.playDtmfTone(mConnectionId, digit, null /*Session.Info*/);
             }
         } catch (RemoteException ignored) {
+        } finally {
+            Log.endSession();
         }
     }
 
@@ -1007,11 +1046,14 @@
      * currently playing, this method will do nothing.
      */
     public void stopDtmfTone() {
+        Log.startSession("RC.sDT", getActiveOwnerInfo());
         try {
             if (mConnected) {
                 mConnectionService.stopDtmfTone(mConnectionId, null /*Session.Info*/);
             }
         } catch (RemoteException ignored) {
+        } finally {
+            Log.endSession();
         }
     }
 
@@ -1037,12 +1079,16 @@
      * @param proceed Whether or not to continue with the post-dial sequence.
      */
     public void postDialContinue(boolean proceed) {
+        Log.startSession("RC.pDC", getActiveOwnerInfo());
         try {
             if (mConnected) {
                 mConnectionService.onPostDialContinue(mConnectionId, proceed,
                         null /*Session.Info*/);
             }
         } catch (RemoteException ignored) {
+            // bliss
+        } finally {
+            Log.endSession();
         }
     }
 
@@ -1052,11 +1098,14 @@
      * See {@link Call#pullExternalCall()} for more information.
      */
     public void pullExternalCall() {
+        Log.startSession("RC.pEC", getActiveOwnerInfo());
         try {
             if (mConnected) {
                 mConnectionService.pullExternalCall(mConnectionId, null /*Session.Info*/);
             }
         } catch (RemoteException ignored) {
+        } finally {
+            Log.endSession();
         }
     }
 
@@ -1079,12 +1128,15 @@
      * @param state The audio state of this {@code RemoteConnection}.
      */
     public void setCallAudioState(CallAudioState state) {
+        Log.startSession("RC.sCAS", getActiveOwnerInfo());
         try {
             if (mConnected) {
                 mConnectionService.onCallAudioStateChanged(mConnectionId, state,
                         null /*Session.Info*/);
             }
         } catch (RemoteException ignored) {
+        } finally {
+            Log.endSession();
         }
     }
 
@@ -1095,12 +1147,15 @@
      * @hide
      */
     public void startRtt(@NonNull Connection.RttTextStream rttTextStream) {
+        Log.startSession("RC.sR", getActiveOwnerInfo());
         try {
             if (mConnected) {
                 mConnectionService.startRtt(mConnectionId, rttTextStream.getFdFromInCall(),
                         rttTextStream.getFdToInCall(), null /*Session.Info*/);
             }
         } catch (RemoteException ignored) {
+        } finally {
+            Log.endSession();
         }
     }
 
@@ -1110,11 +1165,14 @@
      * @hide
      */
     public void stopRtt() {
+        Log.startSession("RC.stR", getActiveOwnerInfo());
         try {
             if (mConnected) {
                 mConnectionService.stopRtt(mConnectionId, null /*Session.Info*/);
             }
         } catch (RemoteException ignored) {
+        } finally {
+            Log.endSession();
         }
     }
 
@@ -1128,6 +1186,7 @@
      *                      the in-call app.
      */
     public void sendRttUpgradeResponse(@Nullable Connection.RttTextStream rttTextStream) {
+        Log.startSession("RC.sRUR", getActiveOwnerInfo());
         try {
             if (mConnected) {
                 if (rttTextStream == null) {
@@ -1140,6 +1199,8 @@
                 }
             }
         } catch (RemoteException ignored) {
+        } finally {
+            Log.endSession();
         }
     }
 
@@ -1164,6 +1225,22 @@
         return mConference;
     }
 
+    /**
+     * Get the owner info for the currently active session.  We want to make sure that any owner
+     * info from the original call into the connection manager gets retained so that the full
+     * context of the calls can be traced down to Telephony.
+     * Example: Telecom will provide owner info in it's external session info that indicates
+     * 'cast' as the calling owner.
+     * @return The active owner
+     */
+    private String getActiveOwnerInfo() {
+        Session.Info info = Log.getExternalSession();
+        if (info == null) {
+            return null;
+        }
+        return info.ownerInfo;
+    }
+
     /** {@hide} */
     String getId() {
         return mConnectionId;