Only attach descendants if parent was detached

If a layer is reparented, we also attach the children. We traverse down
the heirarchy and attach all descendants. However, we really only want
to attach descendants if they were initially detached because the layer
that's getting reparented detached them.

For example, Child called detachChildren and its Grandchild was
detached. Parent calls reparent. We want to attach Child if it was
detached and then proceed down its children. If Child wasn't detached,
we don't want to attach Grandchild since the layer that detached it
hasn't been reparented.

As cleanup, also moved DetachChildren test to their own file

Test: DetachChildren.ReparentParentLayerOfDetachedChildren
Change-Id: I53b6d9cb165b810e9c55da8a9ba86c7b53a13c0e
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index a34af17..2ed363a 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -1820,7 +1820,7 @@
         onRemovedFromCurrentState();
     }
 
-    if (callSetTransactionFlags || attachChildren()) {
+    if (attachChildren() || callSetTransactionFlags) {
         setTransactionFlags(eTransactionNeeded);
     }
     return true;
@@ -1848,9 +1848,9 @@
         if (client != nullptr && parentClient != client) {
             if (child->mLayerDetached) {
                 child->mLayerDetached = false;
+                child->attachChildren();
                 changed = true;
             }
-            changed |= child->attachChildren();
         }
     }