From d29c3758bbd7a594bfe66ccef5c49c2c1d9bbc13 Mon Sep 17 00:00:00 2001 From: Prashanth Swaminathan Date: Fri, 16 Jun 2023 18:28:49 -0700 Subject: [PATCH] Move ServiceConnector job timeouts to the job handler thread Prior to this change, the response timeout was assigned via `orTimeout` to the AndroidFuture, which has the default behavior of creating a timeout task assigned to the main Looper (the application thread). Callers that consumed the returned Future via a blocking call like `Future.get()` would prevent the timeout from firing, leading to a block in the main application thread. This change explicitly sets the timeout handler to the job handler, where the completion tasks of all jobs are handled. Bug: 281589918 Test: Reproduced issue on aosp_cf_riscv64_phone (happens reliably due to service bind failure) and confirmed that patch now successfully fires the timeout and recovers. Change-Id: Iee6736554904eaf59c22cdd252e0e1f8730b0643 --- core/java/com/android/internal/infra/ServiceConnector.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/java/com/android/internal/infra/ServiceConnector.java b/core/java/com/android/internal/infra/ServiceConnector.java index cb162674eb167..6489c8ed30aea 100644 --- a/core/java/com/android/internal/infra/ServiceConnector.java +++ b/core/java/com/android/internal/infra/ServiceConnector.java @@ -745,6 +745,10 @@ public interface ServiceConnector { boolean mAsync = false; private String mDebugName; { + // The timeout handler must be set before any calls to set timeouts on the + // AndroidFuture, to ensure they are posted on the proper thread. + setTimeoutHandler(getJobHandler()); + long requestTimeout = getRequestTimeoutMs(); if (requestTimeout > 0) { orTimeout(requestTimeout, TimeUnit.MILLISECONDS);