Merge "Bug fix: fix System crash due to NullPointerException." into sc-dev am: 6791ed0112
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15234896 Change-Id: Iaa8b3ee0377a16a5e5a790ea6dfd5451e77dfdf7
This commit is contained in:
@@ -1896,17 +1896,19 @@ public class VoiceInteractionManagerService extends SystemService {
|
|||||||
|
|
||||||
String serviceComponentName = serviceInfo.getComponentName()
|
String serviceComponentName = serviceInfo.getComponentName()
|
||||||
.flattenToShortString();
|
.flattenToShortString();
|
||||||
|
if (voiceInteractionServiceInfo.getRecognitionService() == null) {
|
||||||
String serviceRecognizerName = new ComponentName(pkg,
|
Slog.e(TAG, "The RecognitionService must be set to avoid boot "
|
||||||
voiceInteractionServiceInfo.getRecognitionService())
|
+ "loop on earlier platform version. Also make sure that this "
|
||||||
.flattenToShortString();
|
+ "is a valid RecognitionService when running on Android 11 "
|
||||||
|
+ "or earlier.");
|
||||||
|
serviceComponentName = "";
|
||||||
|
}
|
||||||
|
|
||||||
Settings.Secure.putStringForUser(getContext().getContentResolver(),
|
Settings.Secure.putStringForUser(getContext().getContentResolver(),
|
||||||
Settings.Secure.ASSISTANT, serviceComponentName, userId);
|
Settings.Secure.ASSISTANT, serviceComponentName, userId);
|
||||||
Settings.Secure.putStringForUser(getContext().getContentResolver(),
|
Settings.Secure.putStringForUser(getContext().getContentResolver(),
|
||||||
Settings.Secure.VOICE_INTERACTION_SERVICE, serviceComponentName,
|
Settings.Secure.VOICE_INTERACTION_SERVICE, serviceComponentName,
|
||||||
userId);
|
userId);
|
||||||
|
|
||||||
return;
|
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() {
|
PackageMonitor mPackageMonitor = new PackageMonitor() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
|
public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
|
||||||
@@ -2090,6 +2115,7 @@ public class VoiceInteractionManagerService extends SystemService {
|
|||||||
|
|
||||||
change = isPackageAppearing(curInteractor.getPackageName());
|
change = isPackageAppearing(curInteractor.getPackageName());
|
||||||
if (change != PACKAGE_UNCHANGED) {
|
if (change != PACKAGE_UNCHANGED) {
|
||||||
|
resetServicesIfNoRecognitionService(curInteractor, userHandle);
|
||||||
// If current interactor is now appearing, for any reason, then
|
// If current interactor is now appearing, for any reason, then
|
||||||
// restart our connection with it.
|
// restart our connection with it.
|
||||||
if (mImpl != null && curInteractor.getPackageName().equals(
|
if (mImpl != null && curInteractor.getPackageName().equals(
|
||||||
@@ -2112,6 +2138,13 @@ public class VoiceInteractionManagerService extends SystemService {
|
|||||||
initForUser(userHandle);
|
initForUser(userHandle);
|
||||||
return;
|
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.
|
// There is no interactor, so just deal with a simple recognizer.
|
||||||
|
|||||||
Reference in New Issue
Block a user