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

Commit 49366436 authored by Ahaan Ugale's avatar Ahaan Ugale Committed by Android (Google) Code Review
Browse files

Merge changes I9a0d859f,I8ab1824a,I2093b163,Ie4370c2e,I62a9480f

* changes:
  VIMS: Simplify findAvailInteractor() by getting metadata in initial pm query.
  VIMS cleanup: set package on pm query instead of filtering results.
  VoiceInteraction: Remove MATCH_DEBUG_TRIAGED_MISSING from PM queries.
  VIMS: Remove useless field mCurUserUnlocked.
  VoiceInteractionServiceInfo cleanup: Nullability, javadoc, try-with, unused method.
parents 0a5926a8 61732f5f
Loading
Loading
Loading
Loading
+26 −28
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.service.voice;

import android.Manifest;
import android.annotation.NonNull;
import android.app.AppGlobals;
import android.content.ComponentName;
import android.content.pm.PackageManager;
@@ -28,6 +29,7 @@ import android.os.RemoteException;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

@@ -47,24 +49,27 @@ public class VoiceInteractionServiceInfo {
    private boolean mSupportsLaunchFromKeyguard;
    private boolean mSupportsLocalInteraction;

    public VoiceInteractionServiceInfo(PackageManager pm, ComponentName comp)
            throws PackageManager.NameNotFoundException {
        this(pm, pm.getServiceInfo(comp, PackageManager.GET_META_DATA));
    }

    public VoiceInteractionServiceInfo(PackageManager pm, ComponentName comp, int userHandle)
    /**
     * Loads the service metadata published by the component. Success is indicated by
     * {@link #getParseError()}.
     *
     * @param pm A PackageManager from which the XML can be loaded.
     * @param comp The {@link VoiceInteractionService} component.
     */
    public VoiceInteractionServiceInfo(
            @NonNull PackageManager pm, @NonNull ComponentName comp, int userHandle)
            throws PackageManager.NameNotFoundException {
        this(pm, getServiceInfoOrThrow(comp, userHandle));
    }

    static ServiceInfo getServiceInfoOrThrow(ComponentName comp, int userHandle)
    @NonNull
    private static ServiceInfo getServiceInfoOrThrow(@NonNull ComponentName comp, int userHandle)
            throws PackageManager.NameNotFoundException {
        try {
            ServiceInfo si = AppGlobals.getPackageManager().getServiceInfo(comp,
                    PackageManager.GET_META_DATA
                            | PackageManager.MATCH_DIRECT_BOOT_AWARE
                            | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
                            | PackageManager.MATCH_DEBUG_TRIAGED_MISSING,
                            | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                    userHandle);
            if (si != null) {
                return si;
@@ -74,20 +79,23 @@ public class VoiceInteractionServiceInfo {
        throw new PackageManager.NameNotFoundException(comp.toString());
    }

    public VoiceInteractionServiceInfo(PackageManager pm, ServiceInfo si) {
        if (si == null) {
            mParseError = "Service not available";
            return;
        }
    /**
     * Loads the service metadata published by the component. Success is indicated by
     * {@link #getParseError()}.
     *
     * @param pm A PackageManager from which the XML can be loaded; usually the PackageManager
     *           from which {@code si} was originally retrieved.
     * @param si The {@link VoiceInteractionService} info.
     */
    public VoiceInteractionServiceInfo(@NonNull PackageManager pm, @NonNull ServiceInfo si) {
        if (!Manifest.permission.BIND_VOICE_INTERACTION.equals(si.permission)) {
            mParseError = "Service does not require permission "
                    + Manifest.permission.BIND_VOICE_INTERACTION;
            return;
        }

        XmlResourceParser parser = null;
        try {
            parser = si.loadXmlMetaData(pm, VoiceInteractionService.SERVICE_META_DATA);
        try (XmlResourceParser parser = si.loadXmlMetaData(pm,
                VoiceInteractionService.SERVICE_META_DATA)) {
            if (parser == null) {
                mParseError = "No " + VoiceInteractionService.SERVICE_META_DATA
                        + " meta-data for " + si.packageName;
@@ -134,20 +142,10 @@ public class VoiceInteractionServiceInfo {
                mParseError = "No recognitionService specified";
                return;
            }
        } catch (XmlPullParserException e) {
            mParseError = "Error parsing voice interation service meta-data: " + e;
            Log.w(TAG, "error parsing voice interaction service meta-data", e);
            return;
        } catch (IOException e) {
            mParseError = "Error parsing voice interation service meta-data: " + e;
            Log.w(TAG, "error parsing voice interaction service meta-data", e);
            return;
        } catch (PackageManager.NameNotFoundException e) {
        } catch (XmlPullParserException | IOException | PackageManager.NameNotFoundException e) {
            mParseError = "Error parsing voice interation service meta-data: " + e;
            Log.w(TAG, "error parsing voice interaction service meta-data", e);
            return;
        } finally {
            if (parser != null) parser.close();
        }
        mServiceInfo = si;
    }
+31 −45
Original line number Diff line number Diff line
@@ -238,7 +238,6 @@ public class VoiceInteractionManagerService extends SystemService {

        private boolean mSafeMode;
        private int mCurUser;
        private boolean mCurUserUnlocked;
        private boolean mCurUserSupported;

        @GuardedBy("this")
@@ -494,7 +493,6 @@ public class VoiceInteractionManagerService extends SystemService {
            FgThread.getHandler().post(() -> {
                synchronized (this) {
                    setCurrentUserLocked(userHandle);
                    mCurUserUnlocked = false;
                    switchImplementationIfNeededLocked(false);
                }
            });
@@ -585,30 +583,31 @@ public class VoiceInteractionManagerService extends SystemService {
        VoiceInteractionServiceInfo findAvailInteractor(int userHandle, String packageName) {
            List<ResolveInfo> available =
                    mContext.getPackageManager().queryIntentServicesAsUser(
                            new Intent(VoiceInteractionService.SERVICE_INTERFACE),
                            PackageManager.MATCH_DIRECT_BOOT_AWARE
                                    | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
                                    | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userHandle);
                            new Intent(VoiceInteractionService.SERVICE_INTERFACE)
                                    .setPackage(packageName),
                            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 < numAvailable; i++) {
                ServiceInfo cur = available.get(i).serviceInfo;
                    if ((cur.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0) {
                        ComponentName comp = new ComponentName(cur.packageName, cur.name);
                        try {
                            VoiceInteractionServiceInfo info = new VoiceInteractionServiceInfo(
                                    mContext.getPackageManager(), comp, userHandle);
                            if (info.getParseError() == null) {
                                if (packageName == null || info.getServiceInfo().packageName.equals(
                                        packageName)) {
                                    if (foundInfo == null) {
                if ((cur.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                    continue;
                }
                VoiceInteractionServiceInfo info =
                        new VoiceInteractionServiceInfo(mContext.getPackageManager(), cur);
                if (info.getParseError() != null) {
                    Slog.w(TAG,
                            "Bad interaction service " + cur.packageName + "/"
                                    + cur.name + ": " + info.getParseError());
                } else if (foundInfo == null) {
                    foundInfo = info;
                } else {
                    Slog.w(TAG, "More than one voice interaction service, "
@@ -620,19 +619,8 @@ public class VoiceInteractionManagerService extends SystemService {
                            + new ComponentName(cur.packageName, cur.name));
                }
            }
                            } else {
                                Slog.w(TAG, "Bad interaction service " + comp + ": "
                                        + info.getParseError());
                            }
                        } catch (PackageManager.NameNotFoundException e) {
                            Slog.w(TAG, "Failure looking up interaction service " + comp);
                        }
                    }
                }

            return foundInfo;
        }
        }

        ComponentName getCurInteractor(int userHandle) {
            String curInteractor = Settings.Secure.getStringForUser(
@@ -661,7 +649,6 @@ public class VoiceInteractionManagerService extends SystemService {
                            PackageManager.MATCH_DIRECT_BOOT_AWARE
                                    | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userHandle);
            int numAvailable = available.size();

            if (numAvailable == 0) {
                Slog.w(TAG, "no available voice recognition services found for user " + userHandle);
                return null;
@@ -1458,7 +1445,6 @@ public class VoiceInteractionManagerService extends SystemService {
                pw.println("  mEnableService: " + mEnableService);
                pw.println("  mTemporarilyDisabled: " + mTemporarilyDisabled);
                pw.println("  mCurUser: " + mCurUser);
                pw.println("  mCurUserUnlocked: " + mCurUserUnlocked);
                pw.println("  mCurUserSupported: " + mCurUserSupported);
                dumpSupportedUsers(pw, "  ");
                mDbHelper.dump(pw);