From 8005b00b75619bc0d5c7c7590dd3681625ef50dd Mon Sep 17 00:00:00 2001 From: Charles Chen Date: Tue, 20 Oct 2020 15:37:24 +0800 Subject: [PATCH] Fix bind service failure on Android Auto The failure is because ActiveServices thought window context's token is an Activity token but could not find the corresponding ActivityRecord in ATMS and then early-returned. This issue was exposed because of Presentation's window context migration. This CL relaxed the condition to early return only if the token is neither an Activity token nor a WindowContext token. Bug: 171280916 Bug: 171027173 Bug: 170960206 Test: Tests mentioned in b/170960206#comment1 Test: manual - use auto desktop mode to launch Music/Maps Test: atest WindowContextTests#testWindowContextBindService Change-Id: I313d3d870caa28e02af035b4a6032d649f81a510 --- services/core/java/com/android/server/am/ActiveServices.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index 31712becec05b..6e5c0412985cf 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -1940,7 +1940,9 @@ public final class ActiveServices { ActivityServiceConnectionsHolder activity = null; if (token != null) { activity = mAm.mAtmInternal.getServiceConnectionsHolder(token); - if (activity == null) { + // TODO(b/171280916): Remove the check after we have another API get window context + // token than getActivityToken. + if (activity == null && !mAm.mWindowManager.isWindowToken(token)) { Slog.w(TAG, "Binding with unknown activity: " + token); return 0; }