Merge "Add debugging for issue #23190084: [APPComm][Dev Test] {Unable to share photo..." into mnc-dev
diff --git a/core/java/android/content/ClipData.java b/core/java/android/content/ClipData.java
index 0cafff8..c934e8d 100644
--- a/core/java/android/content/ClipData.java
+++ b/core/java/android/content/ClipData.java
@@ -609,6 +609,23 @@
                 b.append("NULL");
             }
         }
+
+        /** @hide */
+        public void toShortSummaryString(StringBuilder b) {
+            if (mHtmlText != null) {
+                b.append("HTML");
+            } else if (mText != null) {
+                b.append("TEXT");
+            } else if (mUri != null) {
+                b.append("U:");
+                b.append(mUri);
+            } else if (mIntent != null) {
+                b.append("I:");
+                mIntent.toShortString(b, true, true, true, true);
+            } else {
+                b.append("NULL");
+            }
+        }
     }
 
     /**
@@ -884,6 +901,19 @@
         }
     }
 
+    /** @hide */
+    public void toShortStringShortItems(StringBuilder b, boolean first) {
+        if (mItems.size() > 0) {
+            if (!first) {
+                b.append(' ');
+            }
+            mItems.get(0).toShortString(b);
+            if (mItems.size() > 1) {
+                b.append(" ...");
+            }
+        }
+    }
+
     @Override
     public int describeContents() {
         return 0;
diff --git a/core/java/android/content/ClipDescription.java b/core/java/android/content/ClipDescription.java
index be35f08..e988516 100644
--- a/core/java/android/content/ClipDescription.java
+++ b/core/java/android/content/ClipDescription.java
@@ -201,14 +201,7 @@
 
     /** @hide */
     public boolean toShortString(StringBuilder b) {
-        boolean first = true;
-        for (int i=0; i<mMimeTypes.length; i++) {
-            if (!first) {
-                b.append(' ');
-            }
-            first = false;
-            b.append(mMimeTypes[i]);
-        }
+        boolean first = !toShortStringTypesOnly(b);
         if (mLabel != null) {
             if (!first) {
                 b.append(' ');
@@ -221,6 +214,19 @@
         return !first;
     }
 
+    /** @hide */
+    public boolean toShortStringTypesOnly(StringBuilder b) {
+        boolean first = true;
+        for (int i=0; i<mMimeTypes.length; i++) {
+            if (!first) {
+                b.append(' ');
+            }
+            first = false;
+            b.append(mMimeTypes[i]);
+        }
+        return !first;
+    }
+
     @Override
     public int describeContents() {
         return 0;
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index ec443cd..87d52e4 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -7533,14 +7533,19 @@
             if (!first) {
                 b.append(' ');
             }
-            first = false;
+            b.append("clip={");
             if (clip) {
-                b.append("clip={");
                 mClipData.toShortString(b);
-                b.append('}');
             } else {
-                b.append("(has clip)");
+                if (mClipData.getDescription() != null) {
+                    first = !mClipData.getDescription().toShortStringTypesOnly(b);
+                } else {
+                    first = true;
+                }
+                mClipData.toShortStringShortItems(b, first);
             }
+            first = false;
+            b.append('}');
         }
         if (extras && mExtras != null) {
             if (!first) {
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 3d523d9..113c9b6 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -12850,6 +12850,7 @@
                 pw.println("    i[ntents] [PACKAGE_NAME]: pending intent state");
                 pw.println("    p[rocesses] [PACKAGE_NAME]: process state");
                 pw.println("    o[om]: out of memory management");
+                pw.println("    perm[issions]: URI permission grant state");
                 pw.println("    prov[iders] [COMP_SPEC ...]: content provider state");
                 pw.println("    provider [COMP_SPEC]: provider client-side state");
                 pw.println("    s[ervices] [COMP_SPEC ...]: service state");
@@ -12940,6 +12941,10 @@
                 synchronized (this) {
                     dumpOomLocked(fd, pw, args, opti, true);
                 }
+            } else if ("permissions".equals(cmd) || "perm".equals(cmd)) {
+                synchronized (this) {
+                    dumpPermissionsLocked(fd, pw, args, opti, true, null);
+                }
             } else if ("provider".equals(cmd)) {
                 String[] newArgs;
                 String name;
@@ -13055,6 +13060,11 @@
             if (dumpAll) {
                 pw.println("-------------------------------------------------------------------------------");
             }
+            dumpPermissionsLocked(fd, pw, args, opti, dumpAll, dumpPackage);
+            pw.println();
+            if (dumpAll) {
+                pw.println("-------------------------------------------------------------------------------");
+            }
             mServices.dumpServicesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage);
             pw.println();
             if (dumpAll) {
@@ -14075,6 +14085,18 @@
             }
         }
 
+        if (!printedAnything) {
+            pw.println("  (nothing)");
+        }
+    }
+
+    void dumpPermissionsLocked(FileDescriptor fd, PrintWriter pw, String[] args,
+            int opti, boolean dumpAll, String dumpPackage) {
+        boolean needSep = false;
+        boolean printedAnything = false;
+
+        pw.println("ACTIVITY MANAGER URI PERMISSIONS (dumpsys activity permissions)");
+
         if (mGrantedUriPermissions.size() > 0) {
             boolean printed = false;
             int dumpUid = -2;