Handle Choreographer.getInstance throwing RuntimeException

#minor-release

PiperOrigin-RevId: 427439588
This commit is contained in:
olly 2022-02-09 12:55:59 +00:00 committed by Ian Baker
parent dc0a293c3f
commit eb6e25b6fc

View File

@ -622,21 +622,30 @@ public final class VideoFrameReleaseHelper {
} }
private void createChoreographerInstanceInternal() { private void createChoreographerInstanceInternal() {
choreographer = Choreographer.getInstance(); try {
choreographer = Choreographer.getInstance();
} catch (RuntimeException e) {
// See [Internal: b/213926330].
Log.w(TAG, "Vsync sampling disabled due to platform error", e);
}
} }
private void addObserverInternal() { private void addObserverInternal() {
observerCount++; if (choreographer != null) {
if (observerCount == 1) { observerCount++;
checkNotNull(choreographer).postFrameCallback(this); if (observerCount == 1) {
choreographer.postFrameCallback(this);
}
} }
} }
private void removeObserverInternal() { private void removeObserverInternal() {
observerCount--; if (choreographer != null) {
if (observerCount == 0) { observerCount--;
checkNotNull(choreographer).removeFrameCallback(this); if (observerCount == 0) {
sampledVsyncTimeNs = C.TIME_UNSET; choreographer.removeFrameCallback(this);
sampledVsyncTimeNs = C.TIME_UNSET;
}
} }
} }
} }