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

Commit 19e29925 authored by Ahaan Ugale's avatar Ahaan Ugale
Browse files

Allow only preloaded voice recognition services to blame calling apps.

Bug: 170795434
Test: manual
Merged-In: Ided2b19661d937ff0b4ec881f2e629afe47435e5
Change-Id: I92a146e5763afd07a44f8e9c7a3c71a27d1f16bd
parent 35c4f102
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.database.DatabaseUtils;
@@ -7649,23 +7650,28 @@ public class AppOpsManager {
        }
        final String voiceRecognitionComponent = Settings.Secure.getString(
                context.getContentResolver(), Settings.Secure.VOICE_RECOGNITION_SERVICE);
        final String voiceInteractionComponent = Settings.Secure.getString(
                context.getContentResolver(), Settings.Secure.VOICE_INTERACTION_SERVICE);

        final String voiceRecognitionServicePackageName =
                getComponentPackagenameFromString(voiceRecognitionComponent);
        final String voiceInteractionServicePackageName =
                getComponentPackagenameFromString(voiceInteractionComponent);

        return Objects.equals(packageName, voiceRecognitionServicePackageName) && Objects.equals(
                voiceRecognitionServicePackageName, voiceInteractionServicePackageName);
                getComponentPackageNameFromString(voiceRecognitionComponent);
        return (Objects.equals(packageName, voiceRecognitionServicePackageName))
                && isPackagePreInstalled(context, packageName);
    }

    private static String getComponentPackagenameFromString(String from) {
    private static String getComponentPackageNameFromString(String from) {
        ComponentName componentName = from != null ? ComponentName.unflattenFromString(from) : null;
        return componentName != null ? componentName.getPackageName() : "";
    }

    private static boolean isPackagePreInstalled(Context context, String packageName) {
        try {
            final PackageManager pm = context.getPackageManager();
            final ApplicationInfo info = pm.getApplicationInfo(packageName, 0);
            return ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
    }

    /**
     * Do a quick check for whether an application might be able to perform an operation.
     * This is <em>not</em> a security check; you must use {@link #noteOp(String, int, String,