Allow relative layering of children

Initially we had hoped not to go down this route in order to produce the most
understandable model, but in the end it seems to be the most sane way to
satisfy some existing use cases from the WM. In particular we have the use
case of the IME. The IME may of course be larger than the application it is
targetting, in particular we see this in side by side split-screen portrait
and freeform. However, various UI features such as the text drag handles,
spell checking popups, etc, are controlled by the application process
and modelled as child windows of the application. This is a good fit for them
as they need to inherit most properties of the application window: Cropping,
Transform, Alpha. However they need to appear over the IME! As the IME can't
be a child of the application (it is bigger), we now see our use case for relative
layering. Perhaps the drag handles could be reimplemented as controlled by the IME
process but if nothing else as a legacy API we have exposed the idea of child windows
of the app going over the IME and are likely to need to continue to support it in some
mode.

Test: Transaction_test.cpp
Change-Id: If2d831bcbe88fc753b02c044a57882cca6ccffbb
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 50e2c6f..07fc0b3 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -1100,6 +1100,19 @@
     return true;
 }
 
+bool Layer::setChildRelativeLayer(const sp<Layer>& childLayer,
+        const sp<IBinder>& relativeToHandle, int32_t relativeZ) {
+    ssize_t idx = mCurrentChildren.indexOf(childLayer);
+    if (idx < 0) {
+        return false;
+    }
+    if (childLayer->setRelativeLayer(relativeToHandle, relativeZ)) {
+        mCurrentChildren.removeAt(idx);
+        mCurrentChildren.add(childLayer);
+    }
+    return true;
+}
+
 bool Layer::setLayer(int32_t z) {
     if (mCurrentState.z == z) return false;
     mCurrentState.sequence++;
@@ -1601,11 +1614,7 @@
     const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
     const State& state = useDrawing ? mDrawingState : mCurrentState;
 
-    if (state.zOrderRelatives.size() == 0) {
-        return children;
-    }
     LayerVector traverse;
-
     for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
         sp<Layer> strongRelative = weakRelative.promote();
         if (strongRelative != nullptr) {
@@ -1614,6 +1623,10 @@
     }
 
     for (const sp<Layer>& child : children) {
+        const State& childState = useDrawing ? child->mDrawingState : child->mCurrentState;
+        if (childState.zOrderRelativeOf != nullptr) {
+            continue;
+        }
         traverse.add(child);
     }