Check for surface validity to avoid native crash
If the surface gets destroyed, return -1 to indicate such that
the client can abort the animation, instead of crashing.
Test: With Launcher in multi-window
Change-Id: I4ab11557c40ed843a4c2e985a53cc2247b18b5fd
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java
index 1f7f8b9..8830c90 100644
--- a/core/java/android/view/Surface.java
+++ b/core/java/android/view/Surface.java
@@ -283,6 +283,7 @@
*/
public long getNextFrameNumber() {
synchronized (mLock) {
+ checkNotReleasedLocked();
return nativeGetNextFrameNumber(mNativeObject);
}
}
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java
index 13f30b2..7d159b7 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java
@@ -20,6 +20,7 @@
import android.animation.AnimatorSet;
import android.animation.RectEvaluator;
import android.annotation.FloatRange;
+import android.annotation.Nullable;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
@@ -39,6 +40,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
+import android.view.ViewRootImpl;
import android.view.ViewStub;
import java.util.ArrayList;
@@ -294,17 +296,25 @@
}
/**
- * @return The next frame name for the specified surface.
+ * @return The next frame name for the specified surface or -1 if the surface is no longer
+ * valid.
*/
public static long getNextFrameNumber(Surface s) {
- return s.getNextFrameNumber();
+ return s != null && s.isValid()
+ ? s.getNextFrameNumber()
+ : -1;
+
}
/**
* @return The surface for the specified view.
*/
- public static Surface getSurface(View v) {
- return v.getViewRootImpl().mSurface;
+ public static @Nullable Surface getSurface(View v) {
+ ViewRootImpl viewRoot = v.getViewRootImpl();
+ if (viewRoot == null) {
+ return null;
+ }
+ return viewRoot.mSurface;
}
/**