am cfcaa31f: Merge "Work on issue #17381033: Program icon and shortcut disappear after..." into lmp-dev

* commit 'cfcaa31f5136b44da4b8b9ae16ec3311d9c7cdde':
  Work on issue #17381033: Program icon and shortcut disappear after...
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index fdf2fc8..01e4650 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -11190,6 +11190,7 @@
                 pw.println("    p[policy]: policy state");
                 pw.println("    a[animator]: animator state");
                 pw.println("    s[essions]: active sessions");
+                pw.println("    surfaces: active surfaces (debugging enabled only)");
                 pw.println("    d[isplays]: active display contents");
                 pw.println("    t[okens]: token list");
                 pw.println("    w[indows]: window list");
@@ -11229,6 +11230,11 @@
                     dumpSessionsLocked(pw, true);
                 }
                 return;
+            } else if ("surfaces".equals(cmd)) {
+                synchronized(mWindowMap) {
+                    WindowStateAnimator.SurfaceTrace.dumpAllSurfaces(pw, null);
+                }
+                return;
             } else if ("displays".equals(cmd) || "d".equals(cmd)) {
                 synchronized(mWindowMap) {
                     dumpDisplayContentsLocked(pw, true);
@@ -11284,6 +11290,13 @@
             if (dumpAll) {
                 pw.println("-------------------------------------------------------------------------------");
             }
+            WindowStateAnimator.SurfaceTrace.dumpAllSurfaces(pw, dumpAll ?
+                    "-------------------------------------------------------------------------------"
+                    : null);
+            pw.println();
+            if (dumpAll) {
+                pw.println("-------------------------------------------------------------------------------");
+            }
             dumpDisplayContentsLocked(pw, dumpAll);
             pw.println();
             if (dumpAll) {
diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java
index ff17d78..5b007d4 100644
--- a/services/core/java/com/android/server/wm/WindowStateAnimator.java
+++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java
@@ -536,6 +536,9 @@
             mSize.set(w, h);
             Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
                     + Debug.getCallers(3));
+            synchronized (sSurfaces) {
+                sSurfaces.add(0, this);
+            }
         }
 
         @Override
@@ -557,15 +560,17 @@
             }
             super.setLayer(zorder);
 
-            sSurfaces.remove(this);
-            int i;
-            for (i = sSurfaces.size() - 1; i >= 0; i--) {
-                SurfaceTrace s = sSurfaces.get(i);
-                if (s.mLayer < zorder) {
-                    break;
+            synchronized (sSurfaces) {
+                sSurfaces.remove(this);
+                int i;
+                for (i = sSurfaces.size() - 1; i >= 0; i--) {
+                    SurfaceTrace s = sSurfaces.get(i);
+                    if (s.mLayer < zorder) {
+                        break;
+                    }
                 }
+                sSurfaces.add(i + 1, this);
             }
-            sSurfaces.add(i + 1, this);
         }
 
         @Override
@@ -655,7 +660,9 @@
         public void destroy() {
             super.destroy();
             Slog.v(SURFACE_TAG, "destroy: " + this + ". Called by " + Debug.getCallers(3));
-            sSurfaces.remove(this);
+            synchronized (sSurfaces) {
+                sSurfaces.remove(this);
+            }
         }
 
         @Override
@@ -663,13 +670,40 @@
             super.release();
             Slog.v(SURFACE_TAG, "release: " + this + ". Called by "
                     + Debug.getCallers(3));
-            sSurfaces.remove(this);
+            synchronized (sSurfaces) {
+                sSurfaces.remove(this);
+            }
         }
 
-        static void dumpAllSurfaces() {
-            final int N = sSurfaces.size();
-            for (int i = 0; i < N; i++) {
-                Slog.i(TAG, "SurfaceDump: " + sSurfaces.get(i));
+        static void dumpAllSurfaces(PrintWriter pw, String header) {
+            synchronized (sSurfaces) {
+                final int N = sSurfaces.size();
+                if (N <= 0) {
+                    return;
+                }
+                if (header != null) {
+                    pw.println(header);
+                }
+                pw.println("WINDOW MANAGER SURFACES (dumpsys window surfaces)");
+                for (int i = 0; i < N; i++) {
+                    SurfaceTrace s = sSurfaces.get(i);
+                    pw.print("  Surface #"); pw.print(i); pw.print(": #");
+                            pw.print(Integer.toHexString(System.identityHashCode(s)));
+                            pw.print(" "); pw.println(s.mName);
+                    pw.print("    mLayerStack="); pw.print(s.mLayerStack);
+                            pw.print(" mLayer="); pw.println(s.mLayer);
+                    pw.print("    mShown="); pw.print(s.mShown); pw.print(" mAlpha=");
+                            pw.print(s.mSurfaceTraceAlpha); pw.print(" mIsOpaque=");
+                            pw.println(s.mIsOpaque);
+                    pw.print("    mPosition="); pw.print(s.mPosition.x); pw.print(",");
+                            pw.print(s.mPosition.y);
+                            pw.print(" mSize="); pw.print(s.mSize.x); pw.print("x");
+                            pw.println(s.mSize.y);
+                    pw.print("    mCrop="); s.mWindowCrop.printShortString(pw); pw.println();
+                    pw.print("    Transform: ("); pw.print(s.mDsdx); pw.print(", ");
+                            pw.print(s.mDtdx); pw.print(", "); pw.print(s.mDsdy);
+                            pw.print(", "); pw.print(s.mDtdy); pw.println(")");
+                }
             }
         }