summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/test-current.txt2
-rw-r--r--core/java/android/view/InsetsSourceConsumer.java8
-rw-r--r--core/java/android/view/InsetsSourceControl.java3
-rw-r--r--core/java/android/view/SurfaceControl.java38
-rw-r--r--core/jni/android_view_SurfaceControl.cpp8
-rw-r--r--core/tests/coretests/src/android/view/InsetsControllerTest.java3
-rw-r--r--services/core/java/com/android/server/wm/DisplayContent.java3
-rw-r--r--services/core/java/com/android/server/wm/WindowContainer.java4
8 files changed, 47 insertions, 22 deletions
diff --git a/api/test-current.txt b/api/test-current.txt
index 5de6c2ae4c82..c29f1c4c657d 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -4860,7 +4860,9 @@ package android.view {
}
public final class SurfaceControl implements android.os.Parcelable {
+ ctor public SurfaceControl(@NonNull android.view.SurfaceControl);
method public static long acquireFrameRateFlexibilityToken();
+ method public boolean isSameSurface(@NonNull android.view.SurfaceControl);
method public static void releaseFrameRateFlexibilityToken(long);
}
diff --git a/core/java/android/view/InsetsSourceConsumer.java b/core/java/android/view/InsetsSourceConsumer.java
index 69bab4df2cae..6cb93746a9a4 100644
--- a/core/java/android/view/InsetsSourceConsumer.java
+++ b/core/java/android/view/InsetsSourceConsumer.java
@@ -91,6 +91,8 @@ public class InsetsSourceConsumer {
if (mSourceControl == control) {
return;
}
+ SurfaceControl oldLeash = mSourceControl != null ? mSourceControl.getLeash() : null;
+
final InsetsSourceControl lastControl = mSourceControl;
mSourceControl = control;
@@ -116,6 +118,12 @@ public class InsetsSourceConsumer {
// However make sure that the leash visibility is still up to date.
if (applyLocalVisibilityOverride()) {
mController.notifyVisibilityChanged();
+ }
+
+ // If we have a new leash, make sure visibility is up-to-date, even though we
+ // didn't want to run an animation above.
+ SurfaceControl newLeash = mSourceControl.getLeash();
+ if (oldLeash == null || newLeash == null || !oldLeash.isSameSurface(newLeash)) {
applyHiddenToControl();
}
}
diff --git a/core/java/android/view/InsetsSourceControl.java b/core/java/android/view/InsetsSourceControl.java
index f3ec65f997ba..e001b668f71a 100644
--- a/core/java/android/view/InsetsSourceControl.java
+++ b/core/java/android/view/InsetsSourceControl.java
@@ -44,8 +44,7 @@ public class InsetsSourceControl implements Parcelable {
public InsetsSourceControl(InsetsSourceControl other) {
mType = other.mType;
if (other.mLeash != null) {
- mLeash = new SurfaceControl();
- mLeash.copyFrom(other.mLeash);
+ mLeash = new SurfaceControl(other.mLeash);
} else {
mLeash = null;
}
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java
index b5f9df72f756..ab65e3a5c849 100644
--- a/core/java/android/view/SurfaceControl.java
+++ b/core/java/android/view/SurfaceControl.java
@@ -216,6 +216,7 @@ public final class SurfaceControl implements Parcelable {
private static native void nativeSetFrameRate(
long transactionObj, long nativeObject, float frameRate, int compatibility);
+ private static native long nativeGetHandle(long nativeObject);
private static native long nativeAcquireFrameRateFlexibilityToken();
private static native void nativeReleaseFrameRateFlexibilityToken(long token);
@@ -226,6 +227,7 @@ public final class SurfaceControl implements Parcelable {
* @hide
*/
public long mNativeObject;
+ private long mNativeHandle;
// TODO: Move this to native.
private final Object mSizeLock = new Object();
@@ -428,12 +430,13 @@ public final class SurfaceControl implements Parcelable {
mCloseGuard.open("release");
}
mNativeObject = nativeObject;
+ mNativeHandle = mNativeObject != 0 ? nativeGetHandle(nativeObject) : 0;
}
/**
* @hide
*/
- public void copyFrom(SurfaceControl other) {
+ public void copyFrom(@NonNull SurfaceControl other) {
mName = other.mName;
mWidth = other.mWidth;
mHeight = other.mHeight;
@@ -853,23 +856,19 @@ public final class SurfaceControl implements Parcelable {
throw new OutOfResourcesException(
"Couldn't allocate SurfaceControl native object");
}
-
+ mNativeHandle = nativeGetHandle(mNativeObject);
mCloseGuard.open("release");
}
- /** This is a transfer constructor, useful for transferring a live SurfaceControl native
- * object to another Java wrapper which could have some different behavior, e.g.
- * event logging.
+ /**
+ * Copy constructor. Creates a new native object pointing to the same surface as {@code other}.
+ *
+ * @param other The object to copy the surface from.
* @hide
*/
- public SurfaceControl(SurfaceControl other) {
- mName = other.mName;
- mWidth = other.mWidth;
- mHeight = other.mHeight;
- mNativeObject = other.mNativeObject;
- other.mCloseGuard.close();
- other.mNativeObject = 0;
- mCloseGuard.open("release");
+ @TestApi
+ public SurfaceControl(@NonNull SurfaceControl other) {
+ copyFrom(other);
}
private SurfaceControl(Parcel in) {
@@ -921,6 +920,18 @@ public final class SurfaceControl implements Parcelable {
}
/**
+ * Checks whether two {@link SurfaceControl} objects represent the same surface.
+ *
+ * @param other The other object to check
+ * @return {@code true} if these two {@link SurfaceControl} objects represent the same surface.
+ * @hide
+ */
+ @TestApi
+ public boolean isSameSurface(@NonNull SurfaceControl other) {
+ return other.mNativeHandle == mNativeHandle;
+ }
+
+ /**
* Write to a protocol buffer output stream. Protocol buffer message definition is at {@link
* android.view.SurfaceControlProto}.
*
@@ -977,6 +988,7 @@ public final class SurfaceControl implements Parcelable {
if (mNativeObject != 0) {
nativeRelease(mNativeObject);
mNativeObject = 0;
+ mNativeHandle = 0;
mCloseGuard.close();
}
}
diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp
index b11c4c92ff33..1cfa12df32ab 100644
--- a/core/jni/android_view_SurfaceControl.cpp
+++ b/core/jni/android_view_SurfaceControl.cpp
@@ -1430,6 +1430,12 @@ static void nativeSetGlobalShadowSettings(JNIEnv* env, jclass clazz, jfloatArray
client->setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ, lightRadius);
}
+
+static jlong nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
+ SurfaceControl *surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
+ return reinterpret_cast<jlong>(surfaceControl->getHandle().get());
+}
+
// ----------------------------------------------------------------------------
static const JNINativeMethod sSurfaceControlMethods[] = {
@@ -1606,6 +1612,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
(void*)nativeMirrorSurface },
{"nativeSetGlobalShadowSettings", "([F[FFFF)V",
(void*)nativeSetGlobalShadowSettings },
+ {"nativeGetHandle", "(J)J",
+ (void*)nativeGetHandle },
};
int register_android_view_SurfaceControl(JNIEnv* env)
diff --git a/core/tests/coretests/src/android/view/InsetsControllerTest.java b/core/tests/coretests/src/android/view/InsetsControllerTest.java
index cbb379bf8207..d432dda4a1be 100644
--- a/core/tests/coretests/src/android/view/InsetsControllerTest.java
+++ b/core/tests/coretests/src/android/view/InsetsControllerTest.java
@@ -696,8 +696,7 @@ public class InsetsControllerTest {
// Simulate binder behavior by copying SurfaceControl. Otherwise, InsetsController will
// attempt to release mLeash directly.
- SurfaceControl copy = new SurfaceControl();
- copy.copyFrom(mLeash);
+ SurfaceControl copy = new SurfaceControl(mLeash);
return new InsetsSourceControl(type, copy, new Point());
}
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index a93b962c33b4..dba6be4f1096 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -1082,8 +1082,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
return null;
}
mShellRoots.put(windowType, root);
- SurfaceControl out = new SurfaceControl();
- out.copyFrom(rootLeash);
+ SurfaceControl out = new SurfaceControl(rootLeash);
return out;
}
diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java
index 569b8f61c4f4..4734b63d59b2 100644
--- a/services/core/java/com/android/server/wm/WindowContainer.java
+++ b/services/core/java/com/android/server/wm/WindowContainer.java
@@ -2501,9 +2501,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
// We need to copy the SurfaceControl instead of returning the original
// because the Parcel FLAGS PARCELABLE_WRITE_RETURN_VALUE cause SurfaceControls
// to release themselves.
- SurfaceControl sc = new SurfaceControl();
- sc.copyFrom(wc.getSurfaceControl());
- return sc;
+ return new SurfaceControl(wc.getSurfaceControl());
}
WindowContainerToken toWindowContainerToken() {