From effa5f438369810a3381cec612ab02deeda92f4c Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Mon, 28 Jan 2019 14:59:46 -0800 Subject: [PATCH] Fixed ContentCaptureManager.getServiceComponentName() Here's the current code: mHandler.sendMessage(obtainMessage(ContentCaptureManager::handleGetComponentName, this, resultReceiver)); return resultReceiver.getParcelableResult(); That code posts a message to a handler, than blocks waiting for the result. It used to work fine, but now it deadlocks because the handler is also running in the UI thread. The solution is to not use the handler anymore, at least for these non-session related methods. Test: atest BlankActivityTest#testGetServiceComponentName_onUi Fixes: 123521559 Change-Id: I774dc6338f685d185447cd61da31bcc63b085996 --- .../contentcapture/ContentCaptureManager.java | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/core/java/android/view/contentcapture/ContentCaptureManager.java b/core/java/android/view/contentcapture/ContentCaptureManager.java index d7f1b9f2c3e13..07c91017a3a50 100644 --- a/core/java/android/view/contentcapture/ContentCaptureManager.java +++ b/core/java/android/view/contentcapture/ContentCaptureManager.java @@ -17,8 +17,6 @@ package android.view.contentcapture; import static android.view.contentcapture.ContentCaptureHelper.VERBOSE; -import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage; - import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemService; @@ -33,7 +31,6 @@ import android.util.Log; import android.view.contentcapture.ContentCaptureSession.FlushReason; import com.android.internal.annotations.GuardedBy; -import com.android.internal.os.IResultReceiver; import com.android.internal.util.Preconditions; import com.android.internal.util.SyncResultReceiver; @@ -155,13 +152,12 @@ public final class ContentCaptureManager { } // Wait for system server to return the component name. final SyncResultReceiver resultReceiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS); - mHandler.sendMessage(obtainMessage( - ContentCaptureManager::handleGetComponentName, this, resultReceiver)); + try { + mService.getServiceComponentName(resultReceiver); return resultReceiver.getParcelableResult(); } catch (RemoteException e) { - // Unable to retrieve component name in a reasonable amount of time. throw e.rethrowFromSystemServer(); } } @@ -223,14 +219,4 @@ public final class ContentCaptureManager { } } } - - - /** Retrieves the component name of the target content capture service through system_server. */ - private void handleGetComponentName(@NonNull IResultReceiver resultReceiver) { - try { - mService.getServiceComponentName(resultReceiver); - } catch (RemoteException e) { - Log.w(TAG, "Unable to retrieve service component name: " + e); - } - } }