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

Commit 5d69e8ed authored by Ahaan Ugale's avatar Ahaan Ugale Committed by Automerger Merge Worker
Browse files

Allow only preloaded voice recognition services to blame calling apps. am: 19e29925

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13095463

Change-Id: I48f2f854ee8efc9db99ceaaba28a48888a39f1d7
parents d5fce50f 19e29925
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;
@@ -7640,23 +7641,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,