Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fd152418 authored by MingWei Liao's avatar MingWei Liao Committed by Android (Google) Code Review
Browse files

Merge "Validate the VoiceInteractionService before rebind" into main

parents 6a35cc9d aa1b3725
Loading
Loading
Loading
Loading
+23 −3
Original line number Diff line number Diff line
@@ -794,9 +794,8 @@ public class VoiceInteractionManagerService extends SystemService {
                if (curService != null && !curService.isEmpty()) {
                    try {
                        serviceComponent = ComponentName.unflattenFromString(curService);
                        serviceInfo = AppGlobals.getPackageManager()
                                .getServiceInfo(serviceComponent, 0, mCurUser);
                    } catch (RuntimeException | RemoteException e) {
                        serviceInfo = getValidVoiceInteractionServiceInfo(serviceComponent);
                    } catch (RuntimeException e) {
                        Slog.wtf(TAG, "Bad voice interaction service name " + curService, e);
                        serviceComponent = null;
                        serviceInfo = null;
@@ -834,6 +833,27 @@ public class VoiceInteractionManagerService extends SystemService {
            }
        }

        @Nullable
        private ServiceInfo getValidVoiceInteractionServiceInfo(
                @Nullable ComponentName serviceComponent) {
            if (serviceComponent == null) {
                return null;
            }
            List<ResolveInfo> services = queryInteractorServices(
                    mCurUser, serviceComponent.getPackageName());
            for (int i = 0; i < services.size(); i++) {
                ResolveInfo service = services.get(i);
                VoiceInteractionServiceInfo info = new VoiceInteractionServiceInfo(
                        mContext.getPackageManager(), service.serviceInfo);
                ServiceInfo candidateInfo = info.getServiceInfo();
                if (candidateInfo != null
                        && candidateInfo.getComponentName().equals(serviceComponent)) {
                    return candidateInfo;
                }
            }
            return null;
        }

        private List<ResolveInfo> queryInteractorServices(
                @UserIdInt int user,
                @Nullable String packageName) {