summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chavi Weingarten <chaviw@google.com> 2023-04-07 21:58:51 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-04-07 21:58:51 +0000
commit5932006e177c65d363d89d93005f3339775edce5 (patch)
tree48abc34c61c86ad577d6382d846b13e7e95f7ae9
parentb2c8f86c62bc6bd7ebf1b9b5dc3547bb5734a2cf (diff)
parentdbce4f859f573df994e4f5ce10c81a2f0c880324 (diff)
Merge "Check if already on main thread when getting SSG for SCVH" into udc-dev
-rw-r--r--core/java/android/view/SurfaceControlViewHost.java13
1 files changed, 10 insertions, 3 deletions
diff --git a/core/java/android/view/SurfaceControlViewHost.java b/core/java/android/view/SurfaceControlViewHost.java
index ac50d09cc091..cd89a561074c 100644
--- a/core/java/android/view/SurfaceControlViewHost.java
+++ b/core/java/android/view/SurfaceControlViewHost.java
@@ -99,9 +99,16 @@ public class SurfaceControlViewHost {
@Override
public ISurfaceSyncGroup getSurfaceSyncGroup() {
CompletableFuture<ISurfaceSyncGroup> surfaceSyncGroup = new CompletableFuture<>();
- mViewRoot.mHandler.post(
- () -> surfaceSyncGroup.complete(
- mViewRoot.getOrCreateSurfaceSyncGroup().mISurfaceSyncGroup));
+ // If the call came from in process and it's already running on the UI thread, return
+ // results immediately instead of posting to the main thread. If we post to the main
+ // thread, it will block itself and the return value will always be null.
+ if (Thread.currentThread() == mViewRoot.mThread) {
+ return mViewRoot.getOrCreateSurfaceSyncGroup().mISurfaceSyncGroup;
+ } else {
+ mViewRoot.mHandler.post(
+ () -> surfaceSyncGroup.complete(
+ mViewRoot.getOrCreateSurfaceSyncGroup().mISurfaceSyncGroup));
+ }
try {
return surfaceSyncGroup.get(1, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {