From 61732f5f6901ce66cae605b880298c00642d55f4 Mon Sep 17 00:00:00 2001 From: Ahaan Ugale Date: Sun, 17 Jan 2021 19:32:23 -0800 Subject: [PATCH] VIMS: Simplify findAvailInteractor() by getting metadata in initial pm query. Also reorders the conditional blocks for readability. Currently, available interactors are queried and one of them is selected, then the metadata for it is retrieved through the VoiceInteractionServiceInfo constructor. With this change, both things are done in a single step. That might mean we retrieve some unneeded data (the metadata for the packages that aren't selected), but optimizing it isn't important since there's usually just one interactor. Bug: 178410946 Test: atest CtsVoiceInteractionTestCases Change-Id: I9a0d859f12d043f47f33a307609dbcf9de759e7e --- .../VoiceInteractionManagerService.java | 66 ++++++++----------- 1 file changed, 29 insertions(+), 37 deletions(-) diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java index e5f194877cf24..a5fea344f9810 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java @@ -585,48 +585,41 @@ public class VoiceInteractionManagerService extends SystemService { mContext.getPackageManager().queryIntentServicesAsUser( new Intent(VoiceInteractionService.SERVICE_INTERFACE) .setPackage(packageName), - PackageManager.MATCH_DIRECT_BOOT_AWARE + PackageManager.GET_META_DATA + | PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userHandle); int numAvailable = available.size(); - if (numAvailable == 0) { Slog.w(TAG, "no available voice interaction services found for user " + userHandle); return null; - } else { - // Find first system package. We never want to allow third party services to - // be automatically selected, because those require approval of the user. - VoiceInteractionServiceInfo foundInfo = null; - for (int i=0; i