Add more logging.

1) Call state logging was lost in a merge conflict, adding that back.
2) Adding better ringing state logging.  Fixes problems:
  - No more superfluous "STOP_RINGER" logging
  - Adding call-waiting logging
  - More accurate call attribution for start and stop ringing

Change-Id: Ie41340ab6790a6c5f87f5592836b29bf6799708d
diff --git a/src/com/android/server/telecom/PhoneAccountRegistrar.java b/src/com/android/server/telecom/PhoneAccountRegistrar.java
index 83f1207..f511c89 100644
--- a/src/com/android/server/telecom/PhoneAccountRegistrar.java
+++ b/src/com/android/server/telecom/PhoneAccountRegistrar.java
@@ -529,6 +529,9 @@
         if (oldAccount != null) {
             mState.accounts.remove(oldAccount);
             isEnabled = oldAccount.isEnabled();
+            Log.i(this, getAccountDiffString(account, oldAccount));
+        } else {
+            Log.i(this, "New phone account registered: " + account);
         }
 
         mState.accounts.add(account);
@@ -610,6 +613,39 @@
         }
     }
 
+    private String getAccountDiffString(PhoneAccount account1, PhoneAccount account2) {
+        if (account1 == null || account2 == null) {
+            return "Diff: " + account1 + ", " + account2;
+        }
+
+        StringBuffer sb = new StringBuffer();
+        sb.append("[").append(account1.getAccountHandle());
+        appendDiff(sb, "addr", account1.getAddress(), account2.getAddress());
+        appendDiff(sb, "cap", account1.getCapabilities(), account2.getCapabilities());
+        appendDiff(sb, "hl", account1.getHighlightColor(), account2.getHighlightColor());
+        appendDiff(sb, "icon", account1.getIcon(), account2.getIcon());
+        appendDiff(sb, "lbl", account1.getLabel(), account2.getLabel());
+        appendDiff(sb, "desc", account1.getShortDescription(), account2.getShortDescription());
+        appendDiff(sb, "subAddr", account1.getSubscriptionAddress(),
+                account2.getSubscriptionAddress());
+        appendDiff(sb, "uris", account1.getSupportedUriSchemes(),
+                account2.getSupportedUriSchemes());
+        sb.append("]");
+        return sb.toString();
+    }
+
+    private void appendDiff(StringBuffer sb, String attrName, Object obj1, Object obj2) {
+        if (!Objects.equals(obj1, obj2)) {
+            sb.append("(")
+                .append(attrName)
+                .append(": ")
+                .append(obj1)
+                .append(" -> ")
+                .append(obj2)
+                .append(")");
+        }
+    }
+
     /**
      * Determines if the connection service specified by a {@link PhoneAccountHandle} requires the
      * {@link Manifest.permission#BIND_TELECOM_CONNECTION_SERVICE} permission.