Merge changes from topic "sc_handles"

* changes:
  Remove SurfaceControl#getHandle from JAVA apis 2/2
  Remove SurfaceControl#getHandle from JAVA apis 1/2
diff --git a/core/java/android/view/CompositionSamplingListener.java b/core/java/android/view/CompositionSamplingListener.java
index e4309a6..368445c 100644
--- a/core/java/android/view/CompositionSamplingListener.java
+++ b/core/java/android/view/CompositionSamplingListener.java
@@ -17,7 +17,6 @@
 package android.view;
 
 import android.graphics.Rect;
-import android.os.IBinder;
 
 import com.android.internal.util.Preconditions;
 
@@ -58,11 +57,12 @@
      * Registers a sampling listener.
      */
     public static void register(CompositionSamplingListener listener,
-            int displayId, IBinder stopLayer, Rect samplingArea) {
+            int displayId, SurfaceControl stopLayer, Rect samplingArea) {
         Preconditions.checkArgument(displayId == Display.DEFAULT_DISPLAY,
                 "default display only for now");
-        nativeRegister(listener.mNativeListener, stopLayer, samplingArea.left, samplingArea.top,
-                samplingArea.right, samplingArea.bottom);
+        long nativeStopLayerObject = stopLayer != null ? stopLayer.mNativeObject : 0;
+        nativeRegister(listener.mNativeListener, nativeStopLayerObject, samplingArea.left,
+                samplingArea.top, samplingArea.right, samplingArea.bottom);
     }
 
     /**
@@ -84,7 +84,7 @@
 
     private static native long nativeCreate(CompositionSamplingListener thiz);
     private static native void nativeDestroy(long ptr);
-    private static native void nativeRegister(long ptr, IBinder stopLayer,
+    private static native void nativeRegister(long ptr, long stopLayerObject,
             int samplingAreaLeft, int top, int right, int bottom);
     private static native void nativeUnregister(long ptr);
 }
diff --git a/core/java/android/view/InputWindowHandle.java b/core/java/android/view/InputWindowHandle.java
index 16a6412..10a9aaa 100644
--- a/core/java/android/view/InputWindowHandle.java
+++ b/core/java/android/view/InputWindowHandle.java
@@ -109,10 +109,10 @@
      * bounds of a parent window. That is the window should receive touch events outside its
      * window but be limited to its stack bounds, such as in the case of split screen.
      */
-    public WeakReference<IBinder> touchableRegionCropHandle = new WeakReference<>(null);
+    public WeakReference<SurfaceControl> touchableRegionSurfaceControl = new WeakReference<>(null);
 
     /**
-     * Replace {@link touchableRegion} with the bounds of {@link touchableRegionCropHandle}. If
+     * Replace {@link touchableRegion} with the bounds of {@link touchableRegionSurfaceControl}. If
      * the handle is {@code null}, the bounds of the surface associated with this window is used
      * as the touchable region.
      */
@@ -164,8 +164,6 @@
      * Crop the window touchable region to the bounds of the surface provided.
      */
     public void setTouchableRegionCrop(@Nullable SurfaceControl bounds) {
-        if (bounds != null) {
-            touchableRegionCropHandle = new WeakReference<>(bounds.getHandle());
-        }
+        touchableRegionSurfaceControl = new WeakReference<>(bounds);
     }
 }
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java
index 8ed56f6..d1ab7c99 100644
--- a/core/java/android/view/SurfaceControl.java
+++ b/core/java/android/view/SurfaceControl.java
@@ -90,7 +90,7 @@
             Rect sourceCrop, int width, int height, boolean useIdentityTransform, int rotation,
             boolean captureSecureLayers);
     private static native ScreenshotGraphicBuffer nativeCaptureLayers(IBinder displayToken,
-            IBinder layerHandleToken, Rect sourceCrop, float frameScale, IBinder[] excludeLayers);
+            long layerObject, Rect sourceCrop, float frameScale, long[] excludeLayerObjects);
 
     private static native long nativeCreateTransaction();
     private static native long nativeGetNativeTransactionFinalizer();
@@ -102,7 +102,7 @@
 
     private static native void nativeSetLayer(long transactionObj, long nativeObject, int zorder);
     private static native void nativeSetRelativeLayer(long transactionObj, long nativeObject,
-            IBinder relativeTo, int zorder);
+            long relativeToObject, int zorder);
     private static native void nativeSetPosition(long transactionObj, long nativeObject,
             float x, float y);
     private static native void nativeSetGeometryAppliesWithResize(long transactionObj,
@@ -172,18 +172,17 @@
     private static native void nativeSetDisplayPowerMode(
             IBinder displayToken, int mode);
     private static native void nativeDeferTransactionUntil(long transactionObj, long nativeObject,
-            IBinder handle, long frame);
+            long barrierObject, long frame);
     private static native void nativeDeferTransactionUntilSurface(long transactionObj,
             long nativeObject,
             long surfaceObject, long frame);
     private static native void nativeReparentChildren(long transactionObj, long nativeObject,
-            IBinder handle);
+            long newParentObject);
     private static native void nativeReparent(long transactionObj, long nativeObject,
             long newParentNativeObject);
     private static native void nativeSeverChildren(long transactionObj, long nativeObject);
     private static native void nativeSetOverrideScalingMode(long transactionObj, long nativeObject,
             int scalingMode);
-    private static native IBinder nativeGetHandle(long nativeObject);
     private static native boolean nativeGetTransformToDisplayInverse(long nativeObject);
 
     private static native Display.HdrCapabilities nativeGetHdrCapabilities(IBinder displayToken);
@@ -1009,9 +1008,9 @@
     /**
      * @hide
      */
-    public void deferTransactionUntil(IBinder handle, long frame) {
+    public void deferTransactionUntil(SurfaceControl barrier, long frame) {
         synchronized(SurfaceControl.class) {
-            sGlobalTransaction.deferTransactionUntil(this, handle, frame);
+            sGlobalTransaction.deferTransactionUntil(this, barrier, frame);
         }
     }
 
@@ -1027,9 +1026,9 @@
     /**
      * @hide
      */
-    public void reparentChildren(IBinder newParentHandle) {
+    public void reparentChildren(SurfaceControl newParent) {
         synchronized(SurfaceControl.class) {
-            sGlobalTransaction.reparentChildren(this, newParentHandle);
+            sGlobalTransaction.reparentChildren(this, newParent);
         }
     }
 
@@ -1064,13 +1063,6 @@
     /**
      * @hide
      */
-    public IBinder getHandle() {
-        return nativeGetHandle(mNativeObject);
-    }
-
-    /**
-     * @hide
-     */
     public static void setAnimationTransaction() {
         synchronized (SurfaceControl.class) {
             sGlobalTransaction.setAnimationTransaction();
@@ -1975,7 +1967,7 @@
     /**
      * Captures a layer and its children and returns a {@link GraphicBuffer} with the content.
      *
-     * @param layerHandleToken The root layer to capture.
+     * @param layer            The root layer to capture.
      * @param sourceCrop       The portion of the root surface to capture; caller may pass in 'new
      *                         Rect()' or null if no cropping is desired.
      * @param frameScale       The desired scale of the returned buffer; the raw
@@ -1984,20 +1976,25 @@
      * @return Returns a GraphicBuffer that contains the layer capture.
      * @hide
      */
-    public static ScreenshotGraphicBuffer captureLayers(IBinder layerHandleToken, Rect sourceCrop,
+    public static ScreenshotGraphicBuffer captureLayers(SurfaceControl layer, Rect sourceCrop,
             float frameScale) {
         final IBinder displayToken = SurfaceControl.getInternalDisplayToken();
-        return nativeCaptureLayers(displayToken, layerHandleToken, sourceCrop, frameScale, null);
+        return nativeCaptureLayers(displayToken, layer.mNativeObject, sourceCrop, frameScale, null);
     }
 
     /**
      * Like {@link captureLayers} but with an array of layer handles to exclude.
      * @hide
      */
-    public static ScreenshotGraphicBuffer captureLayersExcluding(IBinder layerHandleToken,
-            Rect sourceCrop, float frameScale, IBinder[] exclude) {
+    public static ScreenshotGraphicBuffer captureLayersExcluding(SurfaceControl layer,
+            Rect sourceCrop, float frameScale, SurfaceControl[] exclude) {
         final IBinder displayToken = SurfaceControl.getInternalDisplayToken();
-        return nativeCaptureLayers(displayToken, layerHandleToken, sourceCrop, frameScale, exclude);
+        long[] nativeExcludeObjects = new long[exclude.length];
+        for (int i = 0; i < exclude.length; i++) {
+            nativeExcludeObjects[i] = exclude[i].mNativeObject;
+        }
+        return nativeCaptureLayers(displayToken, layer.mNativeObject, sourceCrop, frameScale,
+                nativeExcludeObjects);
     }
 
     /**
@@ -2214,8 +2211,7 @@
          */
         public Transaction setRelativeLayer(SurfaceControl sc, SurfaceControl relativeTo, int z) {
             sc.checkNotReleased();
-            nativeSetRelativeLayer(mNativeObject, sc.mNativeObject,
-                    relativeTo.getHandle(), z);
+            nativeSetRelativeLayer(mNativeObject, sc.mNativeObject, relativeTo.mNativeObject, z);
             return this;
         }
 
@@ -2402,13 +2398,14 @@
          * @hide
          */
         @UnsupportedAppUsage
-        public Transaction deferTransactionUntil(SurfaceControl sc, IBinder handle,
+        public Transaction deferTransactionUntil(SurfaceControl sc, SurfaceControl barrier,
                 long frameNumber) {
             if (frameNumber < 0) {
                 return this;
             }
             sc.checkNotReleased();
-            nativeDeferTransactionUntil(mNativeObject, sc.mNativeObject, handle, frameNumber);
+            nativeDeferTransactionUntil(mNativeObject, sc.mNativeObject, barrier.mNativeObject,
+                    frameNumber);
             return this;
         }
 
@@ -2430,9 +2427,9 @@
         /**
          * @hide
          */
-        public Transaction reparentChildren(SurfaceControl sc, IBinder newParentHandle) {
+        public Transaction reparentChildren(SurfaceControl sc, SurfaceControl newParent) {
             sc.checkNotReleased();
-            nativeReparentChildren(mNativeObject, sc.mNativeObject, newParentHandle);
+            nativeReparentChildren(mNativeObject, sc.mNativeObject, newParent.mNativeObject);
             return this;
         }
 
diff --git a/core/jni/android_hardware_input_InputWindowHandle.cpp b/core/jni/android_hardware_input_InputWindowHandle.cpp
index a1d1d4f..98680fa1e 100644
--- a/core/jni/android_hardware_input_InputWindowHandle.cpp
+++ b/core/jni/android_hardware_input_InputWindowHandle.cpp
@@ -23,6 +23,7 @@
 #include <utils/threads.h>
 
 #include <android/graphics/Region.h>
+#include <gui/SurfaceControl.h>
 #include <ui/Region.h>
 
 #include "android_hardware_input_InputWindowHandle.h"
@@ -32,8 +33,9 @@
 namespace android {
 
 struct WeakRefHandleField {
-    jfieldID handle;
+    jfieldID ctrl;
     jmethodID get;
+    jfieldID mNativeObject;
 };
 
 static struct {
@@ -63,7 +65,7 @@
     jfieldID displayId;
     jfieldID portalToDisplayId;
     jfieldID replaceTouchableRegionWithCrop;
-    WeakRefHandleField touchableRegionCropHandle;
+    WeakRefHandleField touchableRegionSurfaceControl;
 } gInputWindowHandleClassInfo;
 
 static Mutex gHandleMutex;
@@ -172,19 +174,27 @@
     mInfo.replaceTouchableRegionWithCrop = env->GetBooleanField(obj,
             gInputWindowHandleClassInfo.replaceTouchableRegionWithCrop);
 
-    jobject handleObj = env->GetObjectField(obj,
-            gInputWindowHandleClassInfo.touchableRegionCropHandle.handle);
-    if (handleObj) {
+    jobject weakSurfaceCtrl = env->GetObjectField(obj,
+            gInputWindowHandleClassInfo.touchableRegionSurfaceControl.ctrl);
+    bool touchableRegionCropHandleSet = false;
+    if (weakSurfaceCtrl) {
         // Promote java weak reference.
-        jobject strongHandleObj = env->CallObjectMethod(handleObj,
-                gInputWindowHandleClassInfo.touchableRegionCropHandle.get);
-        if (strongHandleObj) {
-            mInfo.touchableRegionCropHandle = ibinderForJavaObject(env, strongHandleObj);
-            env->DeleteLocalRef(strongHandleObj);
-        } else {
-            mInfo.touchableRegionCropHandle.clear();
+        jobject strongSurfaceCtrl = env->CallObjectMethod(weakSurfaceCtrl,
+                gInputWindowHandleClassInfo.touchableRegionSurfaceControl.get);
+        if (strongSurfaceCtrl) {
+            jlong mNativeObject = env->GetLongField(strongSurfaceCtrl,
+                    gInputWindowHandleClassInfo.touchableRegionSurfaceControl.mNativeObject);
+            if (mNativeObject) {
+                auto ctrl = reinterpret_cast<SurfaceControl *>(mNativeObject);
+                mInfo.touchableRegionCropHandle = ctrl->getHandle();
+                touchableRegionCropHandleSet = true;
+            }
+            env->DeleteLocalRef(strongSurfaceCtrl);
         }
-        env->DeleteLocalRef(handleObj);
+        env->DeleteLocalRef(weakSurfaceCtrl);
+    }
+    if (!touchableRegionCropHandleSet) {
+        mInfo.touchableRegionCropHandle.clear();
     }
 
     env->DeleteLocalRef(obj);
@@ -340,11 +350,17 @@
     jclass weakRefClazz;
     FIND_CLASS(weakRefClazz, "java/lang/ref/Reference");
 
-    GET_METHOD_ID(gInputWindowHandleClassInfo.touchableRegionCropHandle.get, weakRefClazz,
+    GET_METHOD_ID(gInputWindowHandleClassInfo.touchableRegionSurfaceControl.get, weakRefClazz,
              "get", "()Ljava/lang/Object;")
 
-    GET_FIELD_ID(gInputWindowHandleClassInfo.touchableRegionCropHandle.handle, clazz,
-            "touchableRegionCropHandle", "Ljava/lang/ref/WeakReference;");
+    GET_FIELD_ID(gInputWindowHandleClassInfo.touchableRegionSurfaceControl.ctrl, clazz,
+            "touchableRegionSurfaceControl", "Ljava/lang/ref/WeakReference;");
+
+    jclass surfaceControlClazz;
+    FIND_CLASS(surfaceControlClazz, "android/view/SurfaceControl");
+    GET_FIELD_ID(gInputWindowHandleClassInfo.touchableRegionSurfaceControl.mNativeObject,
+        surfaceControlClazz, "mNativeObject", "J");
+
     return 0;
 }
 
diff --git a/core/jni/android_view_CompositionSamplingListener.cpp b/core/jni/android_view_CompositionSamplingListener.cpp
index d489ae0..783b0d4 100644
--- a/core/jni/android_view_CompositionSamplingListener.cpp
+++ b/core/jni/android_view_CompositionSamplingListener.cpp
@@ -87,11 +87,11 @@
     listener->decStrong((void*)nativeCreate);
 }
 
-void nativeRegister(JNIEnv* env, jclass clazz, jlong ptr, jobject stopLayerTokenObj,
+void nativeRegister(JNIEnv* env, jclass clazz, jlong ptr, jlong stopLayerObj,
         jint left, jint top, jint right, jint bottom) {
     sp<CompositionSamplingListener> listener = reinterpret_cast<CompositionSamplingListener*>(ptr);
-    sp<IBinder> stopLayerHandle = ibinderForJavaObject(env, stopLayerTokenObj);
-
+    auto stopLayer = reinterpret_cast<SurfaceControl*>(stopLayerObj);
+    sp<IBinder> stopLayerHandle = stopLayer != nullptr ? stopLayer->getHandle() : nullptr;
     if (SurfaceComposerClient::addRegionSamplingListener(
             Rect(left, top, right, bottom), stopLayerHandle, listener) != OK) {
         constexpr auto error_msg = "Couldn't addRegionSamplingListener";
@@ -116,7 +116,7 @@
             (void*)nativeCreate },
     { "nativeDestroy", "(J)V",
             (void*)nativeDestroy },
-    { "nativeRegister", "(JLandroid/os/IBinder;IIII)V",
+    { "nativeRegister", "(JJIIII)V",
             (void*)nativeRegister },
     { "nativeUnregister", "(J)V",
             (void*)nativeUnregister }
diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp
index 0b1fa02..78dd1aa 100644
--- a/core/jni/android_view_SurfaceControl.cpp
+++ b/core/jni/android_view_SurfaceControl.cpp
@@ -266,11 +266,11 @@
 }
 
 static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject displayTokenObj,
-        jobject layerHandleToken, jobject sourceCropObj, jfloat frameScale,
-        jobjectArray excludeArray) {
+        jlong layerObject, jobject sourceCropObj, jfloat frameScale,
+        jlongArray excludeObjectArray) {
 
-    sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken);
-    if (layerHandle == NULL) {
+    auto layer = reinterpret_cast<SurfaceControl *>(layerObject);
+    if (layer == NULL) {
         return NULL;
     }
 
@@ -280,19 +280,20 @@
     }
 
     std::unordered_set<sp<IBinder>,ISurfaceComposer::SpHash<IBinder>> excludeHandles;
-    if (excludeArray != NULL) {
-        const jsize len = env->GetArrayLength(excludeArray);
+    if (excludeObjectArray != NULL) {
+        const jsize len = env->GetArrayLength(excludeObjectArray);
         excludeHandles.reserve(len);
 
+        const jlong* objects = env->GetLongArrayElements(excludeObjectArray, nullptr);
         for (jsize i = 0; i < len; i++) {
-            jobject obj = env->GetObjectArrayElement(excludeArray, i);
-            if (obj == nullptr) {
+            auto excludeObject = reinterpret_cast<SurfaceControl *>(objects[i]);
+            if (excludeObject == nullptr) {
                 jniThrowNullPointerException(env, "Exclude layer is null");
                 return NULL;
             }
-            sp<IBinder> excludeHandle = ibinderForJavaObject(env, obj);
-            excludeHandles.emplace(excludeHandle);
+            excludeHandles.emplace(excludeObject->getHandle());
         }
+        env->ReleaseLongArrayElements(excludeObjectArray, const_cast<jlong*>(objects), JNI_ABORT);
     }
 
     sp<GraphicBuffer> buffer;
@@ -302,7 +303,7 @@
         const ui::ColorMode colorMode = SurfaceComposerClient::getActiveColorMode(displayToken);
         dataspace = pickDataspaceFromColorMode(colorMode);
     }
-    status_t res = ScreenshotClient::captureChildLayers(layerHandle, dataspace,
+    status_t res = ScreenshotClient::captureChildLayers(layer->getHandle(), dataspace,
                                                         ui::PixelFormat::RGBA_8888, sourceCrop,
                                                         excludeHandles, frameScale, &buffer);
     if (res != NO_ERROR) {
@@ -354,15 +355,12 @@
 
 static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
         jlong nativeObject,
-        jobject relativeTo, jint zorder) {
+        jlong relativeToObject, jint zorder) {
 
     auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
-    sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
-
-    {
-        auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
-        transaction->setRelativeLayer(ctrl, handle, zorder);
-    }
+    auto relative = reinterpret_cast<SurfaceControl *>(relativeToObject);
+    auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
+    transaction->setRelativeLayer(ctrl, relative->getHandle(), zorder);
 }
 
 static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
@@ -459,7 +457,7 @@
             env, inputWindow);
     handle->updateInfo();
 
-    SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
+    auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
     transaction->setInputWindowInfo(ctrl, *handle->getInfo());
 }
 
@@ -1103,15 +1101,11 @@
 }
 
 static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
-        jlong nativeObject,
-        jobject handleObject, jlong frameNumber) {
+        jlong nativeObject, jlong barrierObject, jlong frameNumber) {
     auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
-    sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
-
-    {
-        auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
-        transaction->deferTransactionUntil_legacy(ctrl, handle, frameNumber);
-    }
+    auto barrier = reinterpret_cast<SurfaceControl *>(barrierObject);
+    auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
+    transaction->deferTransactionUntil_legacy(ctrl, barrier->getHandle(), frameNumber);
 }
 
 static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
@@ -1127,15 +1121,12 @@
 
 static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
         jlong nativeObject,
-        jobject newParentObject) {
+        jlong newParentObject) {
 
     auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
-    sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
-
-    {
-        auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
-        transaction->reparentChildren(ctrl, handle);
-    }
+    auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
+    auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
+    transaction->reparentChildren(ctrl, newParent->getHandle());
 }
 
 static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
@@ -1143,11 +1134,8 @@
         jlong newParentObject) {
     auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
     auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
-
-    {
-        auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
-        transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
-    }
+    auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
+    transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
 }
 
 static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
@@ -1167,11 +1155,6 @@
     transaction->setOverrideScalingMode(ctrl, scalingMode);
 }
 
-static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
-    auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
-    return javaObjectForIBinder(env, ctrl->getHandle());
-}
-
 static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
     sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
     if (token == NULL) return NULL;
@@ -1305,7 +1288,7 @@
             (void*)nativeSetEarlyWakeup },
     {"nativeSetLayer", "(JJI)V",
             (void*)nativeSetLayer },
-    {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V",
+    {"nativeSetRelativeLayer", "(JJJI)V",
             (void*)nativeSetRelativeLayer },
     {"nativeSetPosition", "(JJFF)V",
             (void*)nativeSetPosition },
@@ -1383,11 +1366,11 @@
             (void*)nativeSetDisplayPowerMode },
     {"nativeGetProtectedContentSupport", "()Z",
             (void*)nativeGetProtectedContentSupport },
-    {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V",
+    {"nativeDeferTransactionUntil", "(JJJJ)V",
             (void*)nativeDeferTransactionUntil },
     {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
             (void*)nativeDeferTransactionUntilSurface },
-    {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V",
+    {"nativeReparentChildren", "(JJJ)V",
             (void*)nativeReparentChildren } ,
     {"nativeReparent", "(JJJ)V",
             (void*)nativeReparent },
@@ -1395,15 +1378,13 @@
             (void*)nativeSeverChildren } ,
     {"nativeSetOverrideScalingMode", "(JJI)V",
             (void*)nativeSetOverrideScalingMode },
-    {"nativeGetHandle", "(J)Landroid/os/IBinder;",
-            (void*)nativeGetHandle },
     {"nativeScreenshot",
             "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZIZ)"
             "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
             (void*)nativeScreenshot },
     {"nativeCaptureLayers",
-            "(Landroid/os/IBinder;Landroid/os/IBinder;Landroid/graphics/Rect;"
-            "F[Landroid/os/IBinder;)"
+            "(Landroid/os/IBinder;JLandroid/graphics/Rect;"
+            "F[J)"
             "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
             (void*)nativeCaptureLayers },
     {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
diff --git a/core/tests/coretests/src/android/view/CompositionSamplingListenerTest.java b/core/tests/coretests/src/android/view/CompositionSamplingListenerTest.java
index 75a2e8a..729a555 100644
--- a/core/tests/coretests/src/android/view/CompositionSamplingListenerTest.java
+++ b/core/tests/coretests/src/android/view/CompositionSamplingListenerTest.java
@@ -19,7 +19,6 @@
 import static android.view.Display.DEFAULT_DISPLAY;
 
 import android.graphics.Rect;
-import android.os.Binder;
 import android.platform.test.annotations.Presubmit;
 
 import androidx.test.filters.SmallTest;
@@ -35,7 +34,7 @@
 
     @Test
     public void testRegisterUnregister() {
-        CompositionSamplingListener.register(mListener, DEFAULT_DISPLAY, new Binder(),
+        CompositionSamplingListener.register(mListener, DEFAULT_DISPLAY, new SurfaceControl(),
                 new Rect(1, 1, 10, 10));
         CompositionSamplingListener.unregister(mListener);
     }
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/TransactionCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/TransactionCompat.java
index af32f48..073688b 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/TransactionCompat.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/TransactionCompat.java
@@ -18,7 +18,6 @@
 
 import android.graphics.Matrix;
 import android.graphics.Rect;
-import android.os.IBinder;
 import android.view.Surface;
 import android.view.SurfaceControl.Transaction;
 
@@ -88,12 +87,6 @@
     }
 
     public TransactionCompat deferTransactionUntil(SurfaceControlCompat surfaceControl,
-            IBinder handle, long frameNumber) {
-        mTransaction.deferTransactionUntil(surfaceControl.mSurfaceControl, handle, frameNumber);
-        return this;
-    }
-
-    public TransactionCompat deferTransactionUntil(SurfaceControlCompat surfaceControl,
             Surface barrier, long frameNumber) {
         mTransaction.deferTransactionUntilSurface(surfaceControl.mSurfaceControl, barrier,
                 frameNumber);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavBarTintController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavBarTintController.java
index bfd17b9..8bb8ca2 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavBarTintController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavBarTintController.java
@@ -159,7 +159,7 @@
             }
             mSamplingListenerRegistered = true;
             CompositionSamplingListener.register(mSamplingListener, DEFAULT_DISPLAY,
-                    mNavigationBarView.getViewRootImpl().getSurfaceControl().getHandle(),
+                    mNavigationBarView.getViewRootImpl().getSurfaceControl(),
                     mSamplingBounds);
         }
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/RegionSamplingHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/RegionSamplingHelper.java
index 2b0bb21..8026f65 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/RegionSamplingHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/RegionSamplingHelper.java
@@ -18,12 +18,9 @@
 
 import static android.view.Display.DEFAULT_DISPLAY;
 
-import android.annotation.Nullable;
 import android.content.res.Resources;
 import android.graphics.Rect;
 import android.os.Handler;
-import android.os.IBinder;
-import android.provider.Settings;
 import android.view.CompositionSamplingListener;
 import android.view.SurfaceControl;
 import android.view.View;
@@ -181,8 +178,7 @@
                 unregisterSamplingListener();
                 mSamplingListenerRegistered = true;
                 CompositionSamplingListener.register(mSamplingListener, DEFAULT_DISPLAY,
-                        stopLayerControl != null ? stopLayerControl.getHandle() : null,
-                        mSamplingRequestBounds);
+                        stopLayerControl, mSamplingRequestBounds);
                 mRegisteredSamplingBounds.set(mSamplingRequestBounds);
                 mRegisteredStopLayer = stopLayerControl;
             }
diff --git a/services/core/java/com/android/server/wm/SeamlessRotator.java b/services/core/java/com/android/server/wm/SeamlessRotator.java
index 05f556c..bcd90a1 100644
--- a/services/core/java/com/android/server/wm/SeamlessRotator.java
+++ b/services/core/java/com/android/server/wm/SeamlessRotator.java
@@ -100,9 +100,9 @@
         t.setPosition(win.mSurfaceControl, win.mLastSurfacePosition.x, win.mLastSurfacePosition.y);
         if (win.mWinAnimator.mSurfaceController != null && !timeout) {
             t.deferTransactionUntil(win.mSurfaceControl,
-                    win.mWinAnimator.mSurfaceController.getHandle(), win.getFrameNumber());
+                    win.mWinAnimator.mSurfaceController.mSurfaceControl, win.getFrameNumber());
             t.deferTransactionUntil(win.mWinAnimator.mSurfaceController.mSurfaceControl,
-                    win.mWinAnimator.mSurfaceController.getHandle(), win.getFrameNumber());
+                    win.mWinAnimator.mSurfaceController.mSurfaceControl, win.getFrameNumber());
         }
     }
 
diff --git a/services/core/java/com/android/server/wm/TaskScreenshotAnimatable.java b/services/core/java/com/android/server/wm/TaskScreenshotAnimatable.java
index ee4e462..8031cfd 100644
--- a/services/core/java/com/android/server/wm/TaskScreenshotAnimatable.java
+++ b/services/core/java/com/android/server/wm/TaskScreenshotAnimatable.java
@@ -47,8 +47,7 @@
         }
         final Rect tmpRect = task.getBounds();
         tmpRect.offset(0, 0);
-        return SurfaceControl.captureLayers(
-                task.getSurfaceControl().getHandle(), tmpRect, 1f);
+        return SurfaceControl.captureLayers(task.getSurfaceControl(), tmpRect, 1f);
     }
 
     private TaskScreenshotAnimatable(Task task,
diff --git a/services/core/java/com/android/server/wm/TaskSnapshotController.java b/services/core/java/com/android/server/wm/TaskSnapshotController.java
index 9fdc045..bd114d9 100644
--- a/services/core/java/com/android/server/wm/TaskSnapshotController.java
+++ b/services/core/java/com/android/server/wm/TaskSnapshotController.java
@@ -258,7 +258,7 @@
         mTmpRect.offsetTo(0, 0);
         final SurfaceControl.ScreenshotGraphicBuffer screenshotBuffer =
                 SurfaceControl.captureLayers(
-                        task.getSurfaceControl().getHandle(), mTmpRect, scaleFraction);
+                        task.getSurfaceControl(), mTmpRect, scaleFraction);
         final GraphicBuffer buffer = screenshotBuffer != null ? screenshotBuffer.getGraphicBuffer()
                 : null;
         if (buffer == null || buffer.getWidth() <= 1 || buffer.getHeight() <= 1) {
diff --git a/services/core/java/com/android/server/wm/WallpaperController.java b/services/core/java/com/android/server/wm/WallpaperController.java
index 21410c4..6147272 100644
--- a/services/core/java/com/android/server/wm/WallpaperController.java
+++ b/services/core/java/com/android/server/wm/WallpaperController.java
@@ -735,7 +735,7 @@
         bounds.offsetTo(0, 0);
 
         SurfaceControl.ScreenshotGraphicBuffer wallpaperBuffer = SurfaceControl.captureLayers(
-                wallpaperWindowState.getSurfaceControl().getHandle(), bounds, 1 /* frameScale */);
+                wallpaperWindowState.getSurfaceControl(), bounds, 1 /* frameScale */);
 
         if (wallpaperBuffer == null) {
             Slog.w(TAG_WM, "Failed to screenshot wallpaper");
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index d1ddbfe..bf874be 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -4918,7 +4918,7 @@
             if (surfaceInsetsChanging() && mWinAnimator.hasSurface()) {
                 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
                 t.deferTransactionUntil(mSurfaceControl,
-                        mWinAnimator.mSurfaceController.mSurfaceControl.getHandle(),
+                        mWinAnimator.mSurfaceController.mSurfaceControl,
                         getFrameNumber());
             }
         }
diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java
index 15bbf90..73344ac 100644
--- a/services/core/java/com/android/server/wm/WindowStateAnimator.java
+++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java
@@ -398,7 +398,7 @@
                 // transparent to the app.
                 if (mWin.mAppToken == null || mWin.mAppToken.isRelaunching() == false) {
                     mPostDrawTransaction.reparentChildren(mPendingDestroySurface.mSurfaceControl,
-                            mSurfaceController.mSurfaceControl.getHandle())
+                            mSurfaceController.mSurfaceControl)
                             .apply();
                 }
             }
@@ -1013,7 +1013,7 @@
                         // the WS position is reset (so the stack position is shown) at the same
                         // time that the buffer size changes.
                         setOffsetPositionForStackResize(false);
-                        mSurfaceController.deferTransactionUntil(mSurfaceController.getHandle(),
+                        mSurfaceController.deferTransactionUntil(mSurfaceController.mSurfaceControl,
                                 mWin.getFrameNumber());
                     } else {
                         final TaskStack stack = mWin.getStack();
@@ -1044,7 +1044,7 @@
         // comes in at the new size (normally position and crop are unfrozen).
         // setGeometryAppliesWithResizeInTransaction accomplishes this for us.
         if (wasForceScaled && !mForceScaleUntilResize) {
-            mSurfaceController.deferTransactionUntil(mSurfaceController.getHandle(),
+            mSurfaceController.deferTransactionUntil(mSurfaceController.mSurfaceControl,
                     mWin.getFrameNumber());
             mSurfaceController.forceScaleableInTransaction(false);
         }
@@ -1296,7 +1296,7 @@
             final SurfaceControl pendingSurfaceControl = mPendingDestroySurface.mSurfaceControl;
             mPostDrawTransaction.hide(pendingSurfaceControl);
             mPostDrawTransaction.reparentChildren(pendingSurfaceControl,
-                    mSurfaceController.getHandle());
+                    mSurfaceController.mSurfaceControl);
         }
 
         mPostDrawTransaction.apply();
diff --git a/services/core/java/com/android/server/wm/WindowSurfaceController.java b/services/core/java/com/android/server/wm/WindowSurfaceController.java
index 8d619d7..a616e06 100644
--- a/services/core/java/com/android/server/wm/WindowSurfaceController.java
+++ b/services/core/java/com/android/server/wm/WindowSurfaceController.java
@@ -33,7 +33,6 @@
 import android.graphics.Rect;
 import android.graphics.Region;
 import android.os.Debug;
-import android.os.IBinder;
 import android.os.Trace;
 import android.util.Slog;
 import android.util.proto.ProtoOutputStream;
@@ -123,7 +122,7 @@
     void reparentChildrenInTransaction(WindowSurfaceController other) {
         if (SHOW_TRANSACTIONS) Slog.i(TAG, "REPARENT from: " + this + " to: " + other);
         if ((mSurfaceControl != null) && (other.mSurfaceControl != null)) {
-            mSurfaceControl.reparentChildren(other.getHandle());
+            mSurfaceControl.reparentChildren(other.mSurfaceControl);
         }
     }
 
@@ -452,9 +451,9 @@
         return false;
     }
 
-    void deferTransactionUntil(IBinder handle, long frame) {
+    void deferTransactionUntil(SurfaceControl barrier, long frame) {
         // TODO: Logging
-        mSurfaceControl.deferTransactionUntil(handle, frame);
+        mSurfaceControl.deferTransactionUntil(barrier, frame);
     }
 
     void forceScaleableInTransaction(boolean force) {
@@ -483,13 +482,6 @@
         return mSurfaceControl != null;
     }
 
-    IBinder getHandle() {
-        if (mSurfaceControl == null) {
-            return null;
-        }
-        return mSurfaceControl.getHandle();
-    }
-
     void getSurfaceControl(SurfaceControl outSurfaceControl) {
         outSurfaceControl.copyFrom(mSurfaceControl);
     }
diff --git a/services/tests/wmtests/src/com/android/server/wm/StubTransaction.java b/services/tests/wmtests/src/com/android/server/wm/StubTransaction.java
index dec88f0..83dd69a 100644
--- a/services/tests/wmtests/src/com/android/server/wm/StubTransaction.java
+++ b/services/tests/wmtests/src/com/android/server/wm/StubTransaction.java
@@ -145,8 +145,8 @@
     }
 
     @Override
-    public SurfaceControl.Transaction deferTransactionUntil(SurfaceControl sc, IBinder handle,
-            long frameNumber) {
+    public SurfaceControl.Transaction deferTransactionUntil(SurfaceControl sc,
+            SurfaceControl barrier, long frameNumber) {
         return this;
     }
 
@@ -158,7 +158,8 @@
     }
 
     @Override
-    public SurfaceControl.Transaction reparentChildren(SurfaceControl sc, IBinder newParentHandle) {
+    public SurfaceControl.Transaction reparentChildren(SurfaceControl sc,
+            SurfaceControl newParent) {
         return this;
     }