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

Commit aa1b3725 authored by MingWei's avatar MingWei Committed by MingWei Liao
Browse files

Validate the VoiceInteractionService before rebind

When an app providing VIS got updated, VoiceInteractionManagerService
would try to rebind the VIS. However, it didn't check if the service is
still valid or not.

Bug: 324868836
Test: CtsVoiceInteractionTestCases
Change-Id: I54f1a94ecd4721b20b30922372411826a76f854e
parent 6fdf7401
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) {