SurfaceControl: Query native object for transform hint

When a new SurfaceControl was created, the java object's transform
hint was not updated. This created a mismatch between the java and
native objects resulting in the client getting an incorrect transform
hint. Fix this by making the native object the source of truth for
transform hints.

Test: in landscape mode, dismiss apps and check launcher does not reject buffers
Bug: 191841127

Change-Id: Icc87b8cf8158eedb87eea886392a0460a76c6443
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java
index c03db6d..4e2f37f 100644
--- a/core/java/android/view/SurfaceControl.java
+++ b/core/java/android/view/SurfaceControl.java
@@ -234,6 +234,7 @@
     private static native long nativeCreateJankDataListenerWrapper(OnJankDataListener listener);
     private static native int nativeGetGPUContextPriority();
     private static native void nativeSetTransformHint(long nativeObject, int transformHint);
+    private static native int nativeGetTransformHint(long nativeObject);
 
     @Nullable
     @GuardedBy("mLock")
@@ -608,7 +609,6 @@
         mName = other.mName;
         mWidth = other.mWidth;
         mHeight = other.mHeight;
-        mTransformHint = other.mTransformHint;
         mLocalOwnerView = other.mLocalOwnerView;
         assignNativeObject(nativeCopyFromSurfaceControl(other.mNativeObject), callsite);
     }
@@ -1471,7 +1471,6 @@
         mName = in.readString8();
         mWidth = in.readInt();
         mHeight = in.readInt();
-        mTransformHint = in.readInt();
 
         long object = 0;
         if (in.readInt() != 0) {
@@ -1490,7 +1489,6 @@
         dest.writeString8(mName);
         dest.writeInt(mWidth);
         dest.writeInt(mHeight);
-        dest.writeInt(mTransformHint);
         if (mNativeObject == 0) {
             dest.writeInt(0);
         } else {
@@ -3603,7 +3601,8 @@
      * @hide
      */
     public int getTransformHint() {
-        return mTransformHint;
+        checkNotReleased();
+        return nativeGetTransformHint(mNativeObject);
     }
 
     /**
@@ -3616,9 +3615,6 @@
      * @hide
      */
     public void setTransformHint(@Surface.Rotation int transformHint) {
-        if (mTransformHint != transformHint) {
-            mTransformHint = transformHint;
-            nativeSetTransformHint(mNativeObject, transformHint);
-        }
+        nativeSetTransformHint(mNativeObject, transformHint);
     }
 }
diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp
index e9e79dc3..1695e1a 100644
--- a/core/jni/android_view_SurfaceControl.cpp
+++ b/core/jni/android_view_SurfaceControl.cpp
@@ -1785,6 +1785,14 @@
             ui::Transform::toRotationFlags(static_cast<ui::Rotation>(transformHint)));
 }
 
+static jint nativeGetTransformHint(JNIEnv* env, jclass clazz, jlong nativeSurfaceControl) {
+    sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl*>(nativeSurfaceControl));
+    ui::Transform::RotationFlags transformHintRotationFlags =
+            static_cast<ui::Transform::RotationFlags>(surface->getTransformHint());
+
+    return toRotationInt(ui::Transform::toRotation((transformHintRotationFlags)));
+}
+
 // ----------------------------------------------------------------------------
 
 static const JNINativeMethod sSurfaceControlMethods[] = {
@@ -1974,6 +1982,8 @@
             (void*)nativeGetGPUContextPriority },
     {"nativeSetTransformHint", "(JI)V",
             (void*)nativeSetTransformHint },
+    {"nativeGetTransformHint", "(J)I",
+            (void*)nativeGetTransformHint },
         // clang-format on
 };