From c1c451fc3b2c330e3c067fa98eff27e36a964d66 Mon Sep 17 00:00:00 2001 From: Guojing Yuan Date: Wed, 23 Feb 2022 18:12:14 +0000 Subject: [PATCH] [CDM bug] Fix CDM crash when there's no CDM service Move the service connector empty check before adding it to the service connectors map. So when there's no CDM services, there won't be a value in the map. Bug: 219784113 Test: manually tested no services case using CDM test app. The app doesn't crash now. Change-Id: Ib236d42a43c001c0ea5fa4debf5f832daee811c4 --- .../companion/CompanionApplicationController.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/services/companion/java/com/android/server/companion/CompanionApplicationController.java b/services/companion/java/com/android/server/companion/CompanionApplicationController.java index c39b59ae35b3b..ec4bfe09e415b 100644 --- a/services/companion/java/com/android/server/companion/CompanionApplicationController.java +++ b/services/companion/java/com/android/server/companion/CompanionApplicationController.java @@ -118,13 +118,14 @@ class CompanionApplicationController { serviceConnectors = CollectionUtils.map(companionServices, componentName -> new CompanionDeviceServiceConnector(mContext, userId, componentName)); - mBoundCompanionApplications.setValueForPackage(userId, packageName, serviceConnectors); - } - if (serviceConnectors.isEmpty()) { - Slog.e(TAG, "Can't find CompanionDeviceService implementer in package: " - + packageName + ". Please check if they are correctly declared."); - return; + if (serviceConnectors.isEmpty()) { + Slog.e(TAG, "Can't find CompanionDeviceService implementer in package: " + + packageName + ". Please check if they are correctly declared."); + return; + } + + mBoundCompanionApplications.setValueForPackage(userId, packageName, serviceConnectors); } // The first connector in the list is always the primary connector: set a listener to it.