summaryrefslogtreecommitdiff
path: root/core/java/android/view/SurfaceControl.java
diff options
context:
space:
mode:
authorTiger Huang <tigerhuang@google.com>2020-04-15 22:16:13 +0800
committerTiger Huang <tigerhuang@google.com>2021-01-08 18:39:40 +0800
commit596e4fd4f78ddb15328e17e94fd87ac8ad4c4729 (patch)
treeaed67f72a98806b6024016c9d8be730aa58f6acf /core/java/android/view/SurfaceControl.java
parentdd0180a142887e8311bfd23f2639e831721ab850 (diff)
Add logs to indicate why a surface is invalid
This helps us to debug. Bug: 175954493 Test: Locally make leashes invalid and check the log format. Change-Id: Idcde497ffee1f10a4289520e154aa8b39eed1f78
Diffstat (limited to 'core/java/android/view/SurfaceControl.java')
-rw-r--r--core/java/android/view/SurfaceControl.java33
1 files changed, 31 insertions, 2 deletions
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java
index f642d7580d4d..2f973571fff7 100644
--- a/core/java/android/view/SurfaceControl.java
+++ b/core/java/android/view/SurfaceControl.java
@@ -333,6 +333,8 @@ public final class SurfaceControl implements Parcelable {
*/
public long mNativeObject;
private long mNativeHandle;
+ private boolean mDebugRelease = false;
+ private Throwable mReleaseStack = null;
// TODO: Move width/height to native and fix locking through out.
private final Object mLock = new Object();
@@ -580,6 +582,13 @@ public final class SurfaceControl implements Parcelable {
}
mNativeObject = nativeObject;
mNativeHandle = mNativeObject != 0 ? nativeGetHandle(nativeObject) : 0;
+ if (mNativeObject == 0) {
+ if (mDebugRelease) {
+ mReleaseStack = new Throwable("assigned zero nativeObject here");
+ }
+ } else {
+ mReleaseStack = null;
+ }
}
/**
@@ -590,6 +599,7 @@ public final class SurfaceControl implements Parcelable {
mWidth = other.mWidth;
mHeight = other.mHeight;
mLocalOwnerView = other.mLocalOwnerView;
+ mDebugRelease = other.mDebugRelease;
assignNativeObject(nativeCopyFromSurfaceControl(other.mNativeObject), callsite);
}
@@ -1419,6 +1429,7 @@ public final class SurfaceControl implements Parcelable {
mName = in.readString8();
mWidth = in.readInt();
mHeight = in.readInt();
+ mDebugRelease = in.readBoolean();
long object = 0;
if (in.readInt() != 0) {
@@ -1437,8 +1448,12 @@ public final class SurfaceControl implements Parcelable {
dest.writeString8(mName);
dest.writeInt(mWidth);
dest.writeInt(mHeight);
+ dest.writeBoolean(mDebugRelease);
if (mNativeObject == 0) {
dest.writeInt(0);
+ if (mReleaseStack != null) {
+ Log.w(TAG, "Sending invalid " + this + " caused by:", mReleaseStack);
+ }
} else {
dest.writeInt(1);
}
@@ -1450,6 +1465,13 @@ public final class SurfaceControl implements Parcelable {
}
/**
+ * @hide
+ */
+ public void setDebugRelease(boolean debug) {
+ mDebugRelease = debug;
+ }
+
+ /**
* Checks whether two {@link SurfaceControl} objects represent the same surface.
*
* @param other The other object to check
@@ -1519,6 +1541,9 @@ public final class SurfaceControl implements Parcelable {
nativeRelease(mNativeObject);
mNativeObject = 0;
mNativeHandle = 0;
+ if (mDebugRelease) {
+ mReleaseStack = new Throwable("released here");
+ }
mCloseGuard.close();
}
}
@@ -1534,8 +1559,11 @@ public final class SurfaceControl implements Parcelable {
}
private void checkNotReleased() {
- if (mNativeObject == 0) throw new NullPointerException(
- "Invalid " + this + ", mNativeObject is null. Have you called release() already?");
+ if (mNativeObject == 0) {
+ Log.wtf(TAG, "Invalid " + this + " caused by:", mReleaseStack);
+ throw new NullPointerException(
+ "mNativeObject of " + this + " is null. Have you called release() already?");
+ }
}
/**
@@ -2383,6 +2411,7 @@ public final class SurfaceControl implements Parcelable {
public static SurfaceControl mirrorSurface(SurfaceControl mirrorOf) {
long nativeObj = nativeMirrorSurface(mirrorOf.mNativeObject);
SurfaceControl sc = new SurfaceControl();
+ sc.mDebugRelease = mirrorOf.mDebugRelease;
sc.assignNativeObject(nativeObj, "mirrorSurface");
return sc;
}