Traverse all layers to check if parent exists to add child layer.

With the current implementation, when adding a child layer, the code
only looks in the layersSortedByZ vector to see if the parent exists.
The layersSortedByZ vector only contains the top most layers and not the
child layers. The current behavior prevents creating child layers that
have a parent that is also a child layer. This won't allow for nested child
layers. Instead, traverse the list of layers, which will include looking
at the child layers, to see if the parent layer exists.

Test: NestedChildren test in Transaction_test

Change-Id: I6c1a773b65e450010733f74f459fc327c7af3aea
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 4b079d6..2a9f923 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2777,7 +2777,14 @@
         if (parent == nullptr) {
             mCurrentState.layersSortedByZ.add(lbc);
         } else {
-            if (mCurrentState.layersSortedByZ.indexOf(parent) < 0) {
+            bool found = false;
+            mCurrentState.traverseInZOrder([&](Layer* layer) {
+                if (layer == parent.get()) {
+                    found = true;
+                }
+            });
+
+            if (!found) {
                 ALOGE("addClientLayer called with a removed parent");
                 return NAME_NOT_FOUND;
             }