Merge "Add Connection#EXTRA_ORIGINAL_CONNECTION_ID extra in the ConnectionRequest when creating an conference."
diff --git a/src/com/android/server/telecom/Call.java b/src/com/android/server/telecom/Call.java
index cc1607e..636a1b2 100644
--- a/src/com/android/server/telecom/Call.java
+++ b/src/com/android/server/telecom/Call.java
@@ -17,6 +17,7 @@
 package com.android.server.telecom;
 
 import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.content.Context;
 import android.content.Intent;
 import android.graphics.Bitmap;
@@ -318,6 +319,8 @@
 
     private PhoneAccountHandle mTargetPhoneAccountHandle;
 
+    private PhoneAccountHandle mRemotePhoneAccountHandle;
+
     private UserHandle mInitiatingUser;
 
     private final Handler mHandler = new Handler(Looper.getMainLooper());
@@ -845,19 +848,46 @@
         s.append(SimpleDateFormat.getDateTimeInstance().format(new Date(getCreationTimeMillis())));
         s.append("]");
         s.append(isIncoming() ? "(MT - incoming)" : "(MO - outgoing)");
-        s.append("\n\tVia PhoneAccount: ");
+        s.append("\n\t");
+
         PhoneAccountHandle targetPhoneAccountHandle = getTargetPhoneAccount();
+        PhoneAccountHandle remotePhoneAccountHandle = getRemotePhoneAccountHandle();
+        PhoneAccountHandle connectionMgrAccountHandle = getConnectionManagerPhoneAccount();
+        PhoneAccountHandle delegatePhoneAccountHandle = getDelegatePhoneAccountHandle();
+        boolean isTargetSameAsRemote = targetPhoneAccountHandle != null
+                && targetPhoneAccountHandle.equals(remotePhoneAccountHandle);
+        if (delegatePhoneAccountHandle.equals(targetPhoneAccountHandle)) {
+            s.append(">>>");
+        }
+        s.append("Target");
+        s.append(" PhoneAccount: ");
         if (targetPhoneAccountHandle != null) {
             s.append(targetPhoneAccountHandle);
             s.append(" (");
             s.append(getTargetPhoneAccountLabel());
             s.append(")");
+            if (isTargetSameAsRemote) {
+                s.append("(remote)");
+            }
         } else {
             s.append("not set");
         }
-        if (getConnectionManagerPhoneAccount() != null) {
-            s.append("\n\tConn mgr: ");
-            s.append(getConnectionManagerPhoneAccount());
+        if (!isTargetSameAsRemote && remotePhoneAccountHandle != null) {
+            // This is a RARE case and will likely not be seen in practice but it is possible.
+            if (delegatePhoneAccountHandle.equals(remotePhoneAccountHandle)) {
+                s.append("\n\t>>>Remote PhoneAccount: ");
+            } else {
+                s.append("\n\tRemote PhoneAccount: ");
+            }
+            s.append(remotePhoneAccountHandle);
+        }
+        if (connectionMgrAccountHandle != null) {
+            if (delegatePhoneAccountHandle.equals(connectionMgrAccountHandle)) {
+                s.append("\n\t>>>Conn mgr: ");
+            } else {
+                s.append("\n\tConn mgr: ");
+            }
+            s.append(connectionMgrAccountHandle);
         }
 
         s.append("\n\tTo address: ");
@@ -1371,6 +1401,45 @@
         checkIfRttCapable();
     }
 
+    /**
+     * @return the {@link PhoneAccountHandle} of the remote connection service which placing this
+     * call was delegated to, or {@code null} if a remote connection service was not used.
+     */
+    public @Nullable PhoneAccountHandle getRemotePhoneAccountHandle() {
+        return mRemotePhoneAccountHandle;
+    }
+
+    /**
+     * Sets the {@link PhoneAccountHandle} of the remote connection service which placing this
+     * call was delegated to.
+     * @param accountHandle The phone account handle.
+     */
+    public void setRemotePhoneAccountHandle(PhoneAccountHandle accountHandle) {
+        mRemotePhoneAccountHandle = accountHandle;
+    }
+
+    /**
+     * Determines which {@link PhoneAccountHandle} is actually placing a call.
+     * Where {@link #getRemotePhoneAccountHandle()} is non-null, the connection manager is placing
+     * the call via a remote connection service, so the remote connection service's phone account
+     * is the source.
+     * Where {@link #getConnectionManagerPhoneAccount()} is non-null and
+     * {@link #getRemotePhoneAccountHandle()} is null, the connection manager is placing the call
+     * itself (even if the target specifies something else).
+     * Finally, if neither of the above cases apply, the target phone account is the one actually
+     * placing the call.
+     * @return The {@link PhoneAccountHandle} which is actually placing a call.
+     */
+    public @NonNull PhoneAccountHandle getDelegatePhoneAccountHandle() {
+        if (mRemotePhoneAccountHandle != null) {
+            return mRemotePhoneAccountHandle;
+        }
+        if (mConnectionManagerPhoneAccountHandle != null) {
+            return mConnectionManagerPhoneAccountHandle;
+        }
+        return mTargetPhoneAccountHandle;
+    }
+
     @VisibleForTesting
     public PhoneAccountHandle getTargetPhoneAccount() {
         return mTargetPhoneAccountHandle;
@@ -2533,6 +2602,18 @@
             mWasVolte = true;
         }
 
+        if (extras.containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
+            setOriginalConnectionId(extras.getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID));
+        }
+
+        // The remote connection service API can track the phone account which was originally
+        // requested to create a connection via the remote connection service API; we store that so
+        // we have some visibility into how a call was actually placed.
+        if (mExtras.containsKey(Connection.EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE)) {
+            setRemotePhoneAccountHandle(extras.getParcelable(
+                    Connection.EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE));
+        }
+
         // If the change originated from an InCallService, notify the connection service.
         if (source == SOURCE_INCALL_SERVICE) {
             if (mConnectionService != null) {
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index f060a0d..41506a9 100755
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -2025,7 +2025,8 @@
                             + "callId=%s, callRedirectionAppName=%s",
                     call.getId(), callRedirectionApp);
 
-            showRedirectionDialog(call.getId());
+            showRedirectionDialog(call.getId(),
+                    mRoleManagerAdapter.getApplicationLabelForPackageName(callRedirectionApp));
         } else {
             call.setTargetPhoneAccount(phoneAccountHandle);
             placeOutgoingCall(call, handle, gatewayInfo, speakerphoneOn, videoState);
@@ -2044,7 +2045,7 @@
      * content on the screen.
      * @param callId The ID of the call to show the redirection dialog for.
      */
-    private void showRedirectionDialog(@NonNull String callId) {
+    private void showRedirectionDialog(@NonNull String callId, @NonNull CharSequence appName) {
         AlertDialog confirmDialog = new AlertDialog.Builder(mContext).create();
         LayoutInflater layoutInflater = LayoutInflater.from(mContext);
         View dialogView = layoutInflater.inflate(R.layout.call_redirection_confirm_dialog, null);
@@ -2066,8 +2067,8 @@
         });
 
         Button buttonSecondLine = (Button) dialogView.findViewById(R.id.buttonSecondLine);
-        buttonSecondLine.setText(mContext.getText(
-                R.string.alert_place_outgoing_call_with_redirection));
+        buttonSecondLine.setText(mContext.getString(
+                R.string.alert_place_outgoing_call_with_redirection, appName));
         buttonSecondLine.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -4216,13 +4217,8 @@
         call.setCallerDisplayName(connection.getCallerDisplayName(),
                 connection.getCallerDisplayNamePresentation());
         call.addListener(this);
+        call.putExtras(Call.SOURCE_CONNECTION_SERVICE, connection.getExtras());
 
-        // In case this connection was added via a ConnectionManager, keep track of the original
-        // Connection ID as created by the originating ConnectionService.
-        Bundle extras = connection.getExtras();
-        if (extras != null && extras.containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
-            call.setOriginalConnectionId(extras.getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID));
-        }
         Log.i(this, "createCallForExistingConnection: %s", connection);
         Call parentCall = null;
         if (!TextUtils.isEmpty(connection.getParentCallId())) {
diff --git a/src/com/android/server/telecom/ConnectionServiceWrapper.java b/src/com/android/server/telecom/ConnectionServiceWrapper.java
index 77d79bb..7bd5376 100755
--- a/src/com/android/server/telecom/ConnectionServiceWrapper.java
+++ b/src/com/android/server/telecom/ConnectionServiceWrapper.java
@@ -74,7 +74,8 @@
         @Override
         public void handleCreateConnectionComplete(String callId, ConnectionRequest request,
                 ParcelableConnection connection, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_HANDLE_CREATE_CONNECTION_COMPLETE);
+            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_HANDLE_CREATE_CONNECTION_COMPLETE,
+                    mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -104,7 +105,8 @@
         @Override
         public void handleCreateConferenceComplete(String callId, ConnectionRequest request,
                 ParcelableConference conference, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_HANDLE_CREATE_CONNECTION_COMPLETE);
+            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_HANDLE_CREATE_CONNECTION_COMPLETE,
+                    mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -133,7 +135,8 @@
 
         @Override
         public void setActive(String callId, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_ACTIVE);
+            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_ACTIVE,
+                    mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -156,7 +159,7 @@
 
         @Override
         public void setRinging(String callId, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_RINGING);
+            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_RINGING, mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -179,7 +182,7 @@
 
         @Override
         public void resetConnectionTime(String callId, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.rCCT");
+            Log.startSession(sessionInfo, "CSW.rCCT", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -200,7 +203,7 @@
         @Override
         public void setVideoProvider(String callId, IVideoProvider videoProvider,
                 Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.sVP");
+            Log.startSession(sessionInfo, "CSW.sVP", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -221,7 +224,7 @@
 
         @Override
         public void setDialing(String callId, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_DIALING);
+            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_DIALING, mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -244,7 +247,7 @@
 
         @Override
         public void setPulling(String callId, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_PULLING);
+            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_PULLING, mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -266,7 +269,8 @@
         @Override
         public void setDisconnected(String callId, DisconnectCause disconnectCause,
                 Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_DISCONNECTED);
+            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_DISCONNECTED,
+                    mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -290,7 +294,7 @@
 
         @Override
         public void setOnHold(String callId, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_ON_HOLD);
+            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_ON_HOLD, mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -314,7 +318,7 @@
         @Override
         public void setRingbackRequested(String callId, boolean ringback,
                 Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.SRR");
+            Log.startSession(sessionInfo, "CSW.SRR", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -337,7 +341,7 @@
 
         @Override
         public void removeCall(String callId, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_REMOVE_CALL);
+            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_REMOVE_CALL, mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -364,7 +368,7 @@
         @Override
         public void setConnectionCapabilities(String callId, int connectionCapabilities,
                 Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.sCC");
+            Log.startSession(sessionInfo, "CSW.sCC", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -389,7 +393,7 @@
         @Override
         public void setConnectionProperties(String callId, int connectionProperties,
                 Session.Info sessionInfo) {
-            Log.startSession("CSW.sCP");
+            Log.startSession("CSW.sCP", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -411,7 +415,8 @@
         @Override
         public void setIsConferenced(String callId, String conferenceCallId,
                 Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_IS_CONFERENCED);
+            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_IS_CONFERENCED,
+                    mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -440,7 +445,7 @@
 
         @Override
         public void setConferenceMergeFailed(String callId, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.sCMF");
+            Log.startSession(sessionInfo, "CSW.sCMF", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -467,7 +472,8 @@
         @Override
         public void addConferenceCall(String callId, ParcelableConference parcelableConference,
                 Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_ADD_CONFERENCE_CALL);
+            Log.startSession(sessionInfo, LogUtils.Sessions.CSW_ADD_CONFERENCE_CALL,
+                    mPackageAbbreviation);
 
             if (parcelableConference.getConnectElapsedTimeMillis() != 0
                     && mContext.checkCallingOrSelfPermission(MODIFY_PHONE_STATE)
@@ -581,7 +587,7 @@
         @Override
         public void onPostDialWait(String callId, String remaining,
                 Session.Info sessionInfo) throws RemoteException {
-            Log.startSession(sessionInfo, "CSW.oPDW");
+            Log.startSession(sessionInfo, "CSW.oPDW", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -605,7 +611,7 @@
         @Override
         public void onPostDialChar(String callId, char nextChar,
                 Session.Info sessionInfo) throws RemoteException {
-            Log.startSession(sessionInfo, "CSW.oPDC");
+            Log.startSession(sessionInfo, "CSW.oPDC", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -630,7 +636,7 @@
         public void queryRemoteConnectionServices(RemoteServiceCallback callback,
                 String callingPackage, Session.Info sessionInfo) {
             final UserHandle callingUserHandle = Binder.getCallingUserHandle();
-            Log.startSession(sessionInfo, "CSW.qRCS");
+            Log.startSession(sessionInfo, "CSW.qRCS", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -650,7 +656,7 @@
 
         @Override
         public void setVideoState(String callId, int videoState, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.sVS");
+            Log.startSession(sessionInfo, "CSW.sVS", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -671,7 +677,7 @@
 
         @Override
         public void setIsVoipAudioMode(String callId, boolean isVoip, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.sIVAM");
+            Log.startSession(sessionInfo, "CSW.sIVAM", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -693,7 +699,7 @@
         @Override
         public void setAudioRoute(String callId, int audioRoute,
                 String bluetoothAddress, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.sAR");
+            Log.startSession(sessionInfo, "CSW.sAR", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -713,7 +719,7 @@
         @Override
         public void setStatusHints(String callId, StatusHints statusHints,
                 Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.sSH");
+            Log.startSession(sessionInfo, "CSW.sSH", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -734,7 +740,7 @@
 
         @Override
         public void putExtras(String callId, Bundle extras, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.pE");
+            Log.startSession(sessionInfo, "CSW.pE", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -755,7 +761,7 @@
 
         @Override
         public void removeExtras(String callId, List<String> keys, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.rE");
+            Log.startSession(sessionInfo, "CSW.rE", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -777,7 +783,7 @@
         @Override
         public void setAddress(String callId, Uri address, int presentation,
                 Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.sA");
+            Log.startSession(sessionInfo, "CSW.sA", mPackageAbbreviation);
 
             long token = Binder.clearCallingIdentity();
             try {
@@ -800,7 +806,7 @@
         @Override
         public void setCallerDisplayName(String callId, String callerDisplayName, int presentation,
                 Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.sCDN");
+            Log.startSession(sessionInfo, "CSW.sCDN", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -823,7 +829,7 @@
         @Override
         public void setConferenceableConnections(String callId, List<String> conferenceableCallIds,
                 Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.sCC");
+            Log.startSession(sessionInfo, "CSW.sCC", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -855,7 +861,7 @@
         @Override
         public void addExistingConnection(String callId, ParcelableConnection connection,
                 Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.aEC");
+            Log.startSession(sessionInfo, "CSW.aEC", mPackageAbbreviation);
             UserHandle userHandle = Binder.getCallingUserHandle();
             // Check that the Calling Package matches PhoneAccountHandle's Component Package
             PhoneAccountHandle callingPhoneAccountHandle = connection.getPhoneAccount();
@@ -944,7 +950,7 @@
         @Override
         public void onConnectionEvent(String callId, String event, Bundle extras,
                 Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.oCE");
+            Log.startSession(sessionInfo, "CSW.oCE", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -972,7 +978,7 @@
         @Override
         public void onRttInitiationFailure(String callId, int reason, Session.Info sessionInfo)
                 throws RemoteException {
-            Log.startSession(sessionInfo, "CSW.oRIF");
+            Log.startSession(sessionInfo, "CSW.oRIF", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -999,7 +1005,7 @@
         @Override
         public void onRemoteRttRequest(String callId, Session.Info sessionInfo)
                 throws RemoteException {
-            Log.startSession(sessionInfo, "CSW.oRRR");
+            Log.startSession(sessionInfo, "CSW.oRRR", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -1025,7 +1031,7 @@
                 mAppOpsManager.checkPackage(Binder.getCallingUid(),
                         pHandle.getComponentName().getPackageName());
             }
-            Log.startSession(sessionInfo, "CSW.oPAC");
+            Log.startSession(sessionInfo, "CSW.oPAC", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -1046,7 +1052,7 @@
         @Override
         public void onConnectionServiceFocusReleased(Session.Info sessionInfo)
                 throws RemoteException {
-            Log.startSession(sessionInfo, "CSW.oCSFR");
+            Log.startSession(sessionInfo, "CSW.oCSFR", mPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -1065,7 +1071,7 @@
         @Override
         public void setConferenceState(String callId, boolean isConference,
                 Session.Info sessionInfo) throws RemoteException {
-            Log.startSession(sessionInfo, "CSW.sCS");
+            Log.startSession(sessionInfo, "CSW.sCS", mPackageAbbreviation);
 
             if (mContext.checkCallingOrSelfPermission(MODIFY_PHONE_STATE)
                     != PackageManager.PERMISSION_GRANTED) {
@@ -1093,7 +1099,7 @@
 
         @Override
         public void setCallDirection(String callId, int direction, Session.Info sessionInfo) {
-            Log.startSession(sessionInfo, "CSW.sCD");
+            Log.startSession(sessionInfo, "CSW.sCD", mPackageAbbreviation);
 
             if (mContext.checkCallingOrSelfPermission(MODIFY_PHONE_STATE)
                     != PackageManager.PERMISSION_GRANTED) {
@@ -1256,7 +1262,7 @@
      */
     @VisibleForTesting
     public void createConnection(final Call call, final CreateConnectionResponse response) {
-        Log.d(this, "createConnection(%s) via %s.", call, getComponentName());
+        Log.i(this, "createConnection(%s) via %s.", call, getComponentName());
         BindCallback callback = new BindCallback() {
             @Override
             public void onSuccess() {
@@ -1295,7 +1301,8 @@
                 }
 
                 Log.addEvent(call, LogUtils.Events.START_CONNECTION,
-                        Log.piiHandle(call.getHandle()));
+                        Log.piiHandle(call.getHandle()) + " via:" +
+                                getComponentName().getPackageName());
 
                 ConnectionRequest connectionRequest = new ConnectionRequest.Builder()
                         .setAccountHandle(call.getTargetPhoneAccount())
diff --git a/src/com/android/server/telecom/InCallAdapter.java b/src/com/android/server/telecom/InCallAdapter.java
index d25665f..3b66a51 100755
--- a/src/com/android/server/telecom/InCallAdapter.java
+++ b/src/com/android/server/telecom/InCallAdapter.java
@@ -36,6 +36,7 @@
     private final CallIdMapper mCallIdMapper;
     private final TelecomSystem.SyncRoot mLock;
     private final String mOwnerPackageName;
+    private final String mOwnerPackageAbbreviation;
 
     /** Persists the specified parameters. */
     public InCallAdapter(CallsManager callsManager, CallIdMapper callIdMapper,
@@ -44,12 +45,13 @@
         mCallIdMapper = callIdMapper;
         mLock = lock;
         mOwnerPackageName = ownerPackageName;
+        mOwnerPackageAbbreviation = ServiceBinder.getPackageAbbreviation(ownerPackageName);
     }
 
     @Override
     public void answerCall(String callId, int videoState) {
         try {
-            Log.startSession(LogUtils.Sessions.ICA_ANSWER_CALL, mOwnerPackageName);
+            Log.startSession(LogUtils.Sessions.ICA_ANSWER_CALL, mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -72,7 +74,7 @@
     @Override
     public void deflectCall(String callId, Uri address) {
         try {
-            Log.startSession(LogUtils.Sessions.ICA_DEFLECT_CALL, mOwnerPackageName);
+            Log.startSession(LogUtils.Sessions.ICA_DEFLECT_CALL, mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -95,7 +97,7 @@
     @Override
     public void rejectCall(String callId, boolean rejectWithMessage, String textMessage) {
         try {
-            Log.startSession(LogUtils.Sessions.ICA_REJECT_CALL, mOwnerPackageName);
+            Log.startSession(LogUtils.Sessions.ICA_REJECT_CALL, mOwnerPackageAbbreviation);
 
             int callingUid = Binder.getCallingUid();
             long token = Binder.clearCallingIdentity();
@@ -129,7 +131,7 @@
     public void rejectCallWithReason(String callId,
             @android.telecom.Call.RejectReason int rejectReason) {
         try {
-            Log.startSession(LogUtils.Sessions.ICA_REJECT_CALL, mOwnerPackageName);
+            Log.startSession(LogUtils.Sessions.ICA_REJECT_CALL, mOwnerPackageAbbreviation);
 
             int callingUid = Binder.getCallingUid();
             long token = Binder.clearCallingIdentity();
@@ -153,7 +155,7 @@
 
     public void transferCall(String callId, Uri targetNumber, boolean isConfirmationRequired) {
         try {
-            Log.startSession(LogUtils.Sessions.ICA_TRANSFER_CALL, mOwnerPackageName);
+            Log.startSession(LogUtils.Sessions.ICA_TRANSFER_CALL, mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -177,7 +179,8 @@
     @Override
     public void consultativeTransfer(String callId, String otherCallId) {
         try {
-            Log.startSession(LogUtils.Sessions.ICA_CONSULTATIVE_TRANSFER, mOwnerPackageName);
+            Log.startSession(LogUtils.Sessions.ICA_CONSULTATIVE_TRANSFER,
+                    mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -202,7 +205,7 @@
     @Override
     public void playDtmfTone(String callId, char digit) {
         try {
-            Log.startSession("ICA.pDT", mOwnerPackageName);
+            Log.startSession("ICA.pDT", mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -225,7 +228,7 @@
     @Override
     public void stopDtmfTone(String callId) {
         try {
-            Log.startSession("ICA.sDT", mOwnerPackageName);
+            Log.startSession("ICA.sDT", mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -248,7 +251,7 @@
     @Override
     public void postDialContinue(String callId, boolean proceed) {
         try {
-            Log.startSession("ICA.pDC", mOwnerPackageName);
+            Log.startSession("ICA.pDC", mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -271,7 +274,7 @@
     @Override
     public void disconnectCall(String callId) {
         try {
-            Log.startSession(LogUtils.Sessions.ICA_DISCONNECT_CALL, mOwnerPackageName);
+            Log.startSession(LogUtils.Sessions.ICA_DISCONNECT_CALL, mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -294,7 +297,7 @@
     @Override
     public void holdCall(String callId) {
         try {
-            Log.startSession(LogUtils.Sessions.ICA_HOLD_CALL, mOwnerPackageName);
+            Log.startSession(LogUtils.Sessions.ICA_HOLD_CALL, mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -316,7 +319,7 @@
     @Override
     public void unholdCall(String callId) {
         try {
-            Log.startSession(LogUtils.Sessions.ICA_UNHOLD_CALL, mOwnerPackageName);
+            Log.startSession(LogUtils.Sessions.ICA_UNHOLD_CALL, mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -339,7 +342,7 @@
     public void phoneAccountSelected(String callId, PhoneAccountHandle accountHandle,
             boolean setDefault) {
         try {
-            Log.startSession("ICA.pAS", mOwnerPackageName);
+            Log.startSession("ICA.pAS", mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -361,7 +364,7 @@
     @Override
     public void mute(boolean shouldMute) {
         try {
-            Log.startSession(LogUtils.Sessions.ICA_MUTE, mOwnerPackageName);
+            Log.startSession(LogUtils.Sessions.ICA_MUTE, mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -378,7 +381,7 @@
     @Override
     public void setAudioRoute(int route, String bluetoothAddress) {
         try {
-            Log.startSession(LogUtils.Sessions.ICA_SET_AUDIO_ROUTE, mOwnerPackageName);
+            Log.startSession(LogUtils.Sessions.ICA_SET_AUDIO_ROUTE, mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -395,7 +398,8 @@
     @Override
     public void enterBackgroundAudioProcessing(String callId) {
         try {
-            Log.startSession(LogUtils.Sessions.ICA_ENTER_AUDIO_PROCESSING, mOwnerPackageName);
+            Log.startSession(LogUtils.Sessions.ICA_ENTER_AUDIO_PROCESSING,
+                    mOwnerPackageAbbreviation);
             // TODO: enforce the extra permission.
             Binder.withCleanCallingIdentity(() -> {
                 synchronized (mLock) {
@@ -415,7 +419,8 @@
     @Override
     public void exitBackgroundAudioProcessing(String callId, boolean shouldRing) {
         try {
-            Log.startSession(LogUtils.Sessions.ICA_EXIT_AUDIO_PROCESSING, mOwnerPackageName);
+            Log.startSession(LogUtils.Sessions.ICA_EXIT_AUDIO_PROCESSING,
+                    mOwnerPackageAbbreviation);
             Binder.withCleanCallingIdentity(() -> {
                 synchronized (mLock) {
                     Call call = mCallIdMapper.getCall(callId);
@@ -435,7 +440,7 @@
     @Override
     public void conference(String callId, String otherCallId) {
         try {
-            Log.startSession(LogUtils.Sessions.ICA_CONFERENCE, mOwnerPackageName);
+            Log.startSession(LogUtils.Sessions.ICA_CONFERENCE, mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -458,7 +463,7 @@
     @Override
     public void splitFromConference(String callId) {
         try {
-            Log.startSession("ICA.sFC", mOwnerPackageName);
+            Log.startSession("ICA.sFC", mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -480,7 +485,7 @@
     @Override
     public void mergeConference(String callId) {
         try {
-            Log.startSession("ICA.mC", mOwnerPackageName);
+            Log.startSession("ICA.mC", mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -502,7 +507,7 @@
     @Override
     public void swapConference(String callId) {
         try {
-            Log.startSession("ICA.sC", mOwnerPackageName);
+            Log.startSession("ICA.sC", mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -524,7 +529,7 @@
     @Override
     public void addConferenceParticipants(String callId, List<Uri> participants) {
         try {
-            Log.startSession("ICA.aCP", mOwnerPackageName);
+            Log.startSession("ICA.aCP", mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -547,7 +552,7 @@
     @Override
     public void pullExternalCall(String callId) {
         try {
-            Log.startSession("ICA.pEC", mOwnerPackageName);
+            Log.startSession("ICA.pEC", mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -569,7 +574,7 @@
     @Override
     public void sendCallEvent(String callId, String event, int targetSdkVer, Bundle extras) {
         try {
-            Log.startSession("ICA.sCE", mOwnerPackageName);
+            Log.startSession("ICA.sCE", mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -591,7 +596,7 @@
     @Override
     public void putExtras(String callId, Bundle extras) {
         try {
-            Log.startSession("ICA.pE", mOwnerPackageName);
+            Log.startSession("ICA.pE", mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -613,7 +618,7 @@
     @Override
     public void removeExtras(String callId, List<String> keys) {
         try {
-            Log.startSession("ICA.rE", mOwnerPackageName);
+            Log.startSession("ICA.rE", mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -635,7 +640,7 @@
     @Override
     public void turnOnProximitySensor() {
         try {
-            Log.startSession("ICA.tOnPS", mOwnerPackageName);
+            Log.startSession("ICA.tOnPS", mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -652,7 +657,7 @@
     @Override
     public void turnOffProximitySensor(boolean screenOnImmediately) {
         try {
-            Log.startSession("ICA.tOffPS", mOwnerPackageName);
+            Log.startSession("ICA.tOffPS", mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
@@ -753,7 +758,7 @@
     public void handoverTo(String callId, PhoneAccountHandle destAcct, int videoState,
                            Bundle extras) {
         try {
-            Log.startSession("ICA.hT", mOwnerPackageName);
+            Log.startSession("ICA.hT", mOwnerPackageAbbreviation);
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
diff --git a/src/com/android/server/telecom/InCallController.java b/src/com/android/server/telecom/InCallController.java
index 4718871..5969659 100644
--- a/src/com/android/server/telecom/InCallController.java
+++ b/src/com/android/server/telecom/InCallController.java
@@ -199,7 +199,7 @@
         private final ServiceConnection mServiceConnection = new ServiceConnection() {
             @Override
             public void onServiceConnected(ComponentName name, IBinder service) {
-                Log.startSession("ICSBC.oSC");
+                Log.startSession("ICSBC.oSC", ServiceBinder.getPackageAbbreviation(name));
                 synchronized (mLock) {
                     try {
                         Log.d(this, "onServiceConnected: %s %b %b", name, mIsBound, mIsConnected);
@@ -216,7 +216,7 @@
 
             @Override
             public void onServiceDisconnected(ComponentName name) {
-                Log.startSession("ICSBC.oSD");
+                Log.startSession("ICSBC.oSD", ServiceBinder.getPackageAbbreviation(name));
                 synchronized (mLock) {
                     try {
                         Log.d(this, "onDisconnected: %s", name);
@@ -230,7 +230,7 @@
 
             @Override
             public void onNullBinding(ComponentName name) {
-                Log.startSession("ICSBC.oNB");
+                Log.startSession("ICSBC.oNB", ServiceBinder.getPackageAbbreviation(name));
                 synchronized (mLock) {
                     try {
                         Log.d(this, "onNullBinding: %s", name);
@@ -245,7 +245,7 @@
 
             @Override
             public void onBindingDied(ComponentName name) {
-                Log.startSession("ICSBC.oBD");
+                Log.startSession("ICSBC.oBD", ServiceBinder.getPackageAbbreviation(name));
                 synchronized (mLock) {
                     try {
                         Log.d(this, "onBindingDied: %s", name);
diff --git a/src/com/android/server/telecom/ServiceBinder.java b/src/com/android/server/telecom/ServiceBinder.java
index c64fc73..3ad9070 100644
--- a/src/com/android/server/telecom/ServiceBinder.java
+++ b/src/com/android/server/telecom/ServiceBinder.java
@@ -30,9 +30,11 @@
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.util.Preconditions;
 
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
 
 /**
  * Abstract class to perform the work of binding and unbinding to the specified service interface.
@@ -120,7 +122,8 @@
         public void binderDied() {
             try {
                 synchronized (mLock) {
-                    Log.startSession("SDR.bD");
+                    Log.startSession("SDR.bD",
+                            ServiceBinder.getPackageAbbreviation(mComponentName));
                     Log.i(this, "binderDied: ConnectionService %s died.", mComponentName);
                     logServiceDisconnected("binderDied");
                     handleDisconnect();
@@ -144,7 +147,7 @@
         @Override
         public void onServiceConnected(ComponentName componentName, IBinder binder) {
             try {
-                Log.startSession("SBC.oSC");
+                Log.startSession("SBC.oSC", getPackageAbbreviation(componentName));
                 synchronized (mLock) {
                     Log.i(this, "Service bound %s", componentName);
 
@@ -182,7 +185,7 @@
         @Override
         public void onServiceDisconnected(ComponentName componentName) {
             try {
-                Log.startSession("SBC.oSD");
+                Log.startSession("SBC.oSD", getPackageAbbreviation(componentName));
                 synchronized (mLock) {
                     logServiceDisconnected("onServiceDisconnected");
                     handleDisconnect();
@@ -212,6 +215,11 @@
     /** The component name of the service to bind to. */
     protected final ComponentName mComponentName;
 
+    /**
+     * Abbreviated form of the package name from {@link #mComponentName}; used for session logging.
+     */
+    protected final String mPackageAbbreviation;
+
     /** The set of callbacks waiting for notification of the binding's success or failure. */
     private final Set<BindCallback> mCallbacks = new ArraySet<>();
 
@@ -261,6 +269,7 @@
         mLock = lock;
         mServiceAction = serviceAction;
         mComponentName = componentName;
+        mPackageAbbreviation = getPackageAbbreviation(componentName);
         mUserHandle = userHandle;
     }
 
@@ -441,4 +450,32 @@
      * Removes the service interface before the service is unbound.
      */
     protected abstract void removeServiceInterface();
+
+    /**
+     * 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.
+     */
+    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.
+     */
+    public static String getPackageAbbreviation(String packageName) {
+        if (packageName == null) {
+            return "";
+        }
+        return Arrays.stream(packageName.split("\\."))
+                .map(s -> s.substring(0,1))
+                .collect(Collectors.joining(""));
+    }
 }