diff options
author | 2021-08-03 13:29:52 +0000 | |
---|---|---|
committer | 2021-08-03 13:29:52 +0000 | |
commit | edbdd4310c0ded757e477ee948b9cd0ff5340a6d (patch) | |
tree | 5d38454d67b21ed48d03b03c8c9cf676e95ad279 | |
parent | 657edec50fab8e4c741c584d0846b4e33cea357a (diff) | |
parent | e3bcc4a895743fd7629284d7927ffd9afabd8bab (diff) |
Merge "Bug fix: fix System crash due to NullPointerException." into sc-dev am: 6791ed0112 am: e3bcc4a895
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15234896
Change-Id: I648ce2e830e0c0bdaffa346c1f2ad7009a1d6c0d
-rw-r--r-- | services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java index 71541ad729d5..9ea2b7b12ad0 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java @@ -1896,17 +1896,19 @@ public class VoiceInteractionManagerService extends SystemService { String serviceComponentName = serviceInfo.getComponentName() .flattenToShortString(); - - String serviceRecognizerName = new ComponentName(pkg, - voiceInteractionServiceInfo.getRecognitionService()) - .flattenToShortString(); + if (voiceInteractionServiceInfo.getRecognitionService() == null) { + Slog.e(TAG, "The RecognitionService must be set to avoid boot " + + "loop on earlier platform version. Also make sure that this " + + "is a valid RecognitionService when running on Android 11 " + + "or earlier."); + serviceComponentName = ""; + } Settings.Secure.putStringForUser(getContext().getContentResolver(), Settings.Secure.ASSISTANT, serviceComponentName, userId); Settings.Secure.putStringForUser(getContext().getContentResolver(), Settings.Secure.VOICE_INTERACTION_SERVICE, serviceComponentName, userId); - return; } @@ -1947,6 +1949,29 @@ public class VoiceInteractionManagerService extends SystemService { } } + private void resetServicesIfNoRecognitionService(ComponentName serviceComponent, + int userHandle) { + for (ResolveInfo resolveInfo : queryInteractorServices(userHandle, + serviceComponent.getPackageName())) { + VoiceInteractionServiceInfo serviceInfo = + new VoiceInteractionServiceInfo( + mContext.getPackageManager(), + resolveInfo.serviceInfo); + if (!serviceInfo.getSupportsAssist()) { + continue; + } + if (serviceInfo.getRecognitionService() == null) { + Slog.e(TAG, "The RecognitionService must be set to " + + "avoid boot loop on earlier platform version. " + + "Also make sure that this is a valid " + + "RecognitionService when running on Android 11 " + + "or earlier."); + setCurInteractor(null, userHandle); + resetCurAssistant(userHandle); + } + } + } + PackageMonitor mPackageMonitor = new PackageMonitor() { @Override public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) { @@ -2090,6 +2115,7 @@ public class VoiceInteractionManagerService extends SystemService { change = isPackageAppearing(curInteractor.getPackageName()); if (change != PACKAGE_UNCHANGED) { + resetServicesIfNoRecognitionService(curInteractor, userHandle); // If current interactor is now appearing, for any reason, then // restart our connection with it. if (mImpl != null && curInteractor.getPackageName().equals( @@ -2112,6 +2138,13 @@ public class VoiceInteractionManagerService extends SystemService { initForUser(userHandle); return; } + change = isPackageAppearing(curAssistant.getPackageName()); + if (change != PACKAGE_UNCHANGED) { + // It is possible to update Assistant without a voice interactor to one + // with a voice-interactor. We should make sure the recognition service + // is set to avoid boot loop. + resetServicesIfNoRecognitionService(curAssistant, userHandle); + } } // There is no interactor, so just deal with a simple recognizer. |