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

Commit f31151ff authored by Cody Northrop's avatar Cody Northrop Committed by android-build-merger
Browse files

Merge "GraphicsEnvironment: Expose query to determine ANGLE use" into qt-dev

am: 4112ec55

Change-Id: I1de0f3362f321aac31166d19706f0b8974b73a02
parents 6dcb8220 4112ec55
Loading
Loading
Loading
Loading
+51 −36
Original line number Diff line number Diff line
@@ -163,6 +163,43 @@ public class GraphicsEnvironment {
        return true;
    }

    /**
     * Query to determine if ANGLE should be used
     */
    public static boolean shouldUseAngle(Context context, Bundle coreSettings,
            String packageName) {
        if (packageName.isEmpty()) {
            Log.v(TAG, "No package name available yet, ANGLE should not be used");
            return false;
        }

        final String devOptIn = getDriverForPkg(context, coreSettings, packageName);
        if (DEBUG) {
            Log.v(TAG, "ANGLE Developer option for '" + packageName + "' "
                    + "set to: '" + devOptIn + "'");
        }

        // We only want to use ANGLE if the app is whitelisted or the developer has
        // explicitly chosen something other than default driver.
        // The whitelist will be generated by the ANGLE APK at both boot time and
        // ANGLE update time. It will only include apps mentioned in the rules file.
        final boolean whitelisted = checkAngleWhitelist(context, coreSettings, packageName);
        final boolean requested = devOptIn.equals(sDriverMap.get(OpenGlDriverChoice.ANGLE));
        final boolean useAngle = (whitelisted || requested);
        if (!useAngle) {
            return false;
        }

        if (whitelisted) {
            Log.v(TAG, "ANGLE whitelist includes " + packageName);
        }
        if (requested) {
            Log.v(TAG, "ANGLE developer option for " + packageName + ": " + devOptIn);
        }

        return true;
    }

    /**
     * Check whether application is debuggable
     */
@@ -535,6 +572,8 @@ public class GraphicsEnvironment {
                getGlobalSettingsString(contentResolver, bundle,
                    Settings.Global.GLOBAL_SETTINGS_ANGLE_WHITELIST);

        if (DEBUG) Log.v(TAG, "ANGLE whitelist: " + angleWhitelist);

        return angleWhitelist.contains(packageName);
    }

@@ -549,43 +588,11 @@ public class GraphicsEnvironment {
     */
    public boolean setupAngle(Context context, Bundle bundle, PackageManager pm,
            String packageName) {
        if (packageName.isEmpty()) {
            Log.v(TAG, "No package name available yet, skipping ANGLE setup");
            return false;
        }

        final String devOptIn = getDriverForPkg(context, bundle, packageName);
        if (DEBUG) {
            Log.v(TAG, "ANGLE Developer option for '" + packageName + "' "
                    + "set to: '" + devOptIn + "'");
        }

        // We only need to check rules if the app is whitelisted or the developer has
        // explicitly chosen something other than default driver.
        //
        // The whitelist will be generated by the ANGLE APK at both boot time and
        // ANGLE update time. It will only include apps mentioned in the rules file.
        //
        // If the user has set the developer option to something other than default,
        // we need to call setupAngleRulesApk() with the package name and the developer
        // option value (native/angle/other). Then later when we are actually trying to
        // load a driver, GraphicsEnv::shouldUseAngle() has seen the package name before
        // and can confidently answer yes/no based on the previously set developer
        // option value.
        final boolean whitelisted = checkAngleWhitelist(context, bundle, packageName);
        final boolean defaulted = devOptIn.equals(sDriverMap.get(OpenGlDriverChoice.DEFAULT));
        final boolean rulesCheck = (whitelisted || !defaulted);
        if (!rulesCheck) {
        if (!shouldUseAngle(context, bundle, packageName)) {
            return false;
        }

        if (whitelisted) {
            Log.v(TAG, "ANGLE whitelist includes " + packageName);
        }
        if (!defaulted) {
            Log.v(TAG, "ANGLE developer option for " + packageName + ": " + devOptIn);
        }

        final String anglePkgName = getAnglePackageName(pm);
        if (anglePkgName.isEmpty()) {
            Log.e(TAG, "Failed to find ANGLE package.");
@@ -623,6 +630,14 @@ public class GraphicsEnvironment {

        if (DEBUG) Log.v(TAG, "ANGLE package libs: " + paths);

        // If the user has set the developer option to something other than default,
        // we need to call setupAngleRulesApk() with the package name and the developer
        // option value (native/angle/other). Then later when we are actually trying to
        // load a driver, GraphicsEnv::getShouldUseAngle() has seen the package name before
        // and can confidently answer yes/no based on the previously set developer
        // option value.
        final String devOptIn = getDriverForPkg(context, bundle, packageName);

        if (setupAngleWithTempRulesFile(context, packageName, paths, devOptIn)) {
            // We setup ANGLE with a temp rules file, so we're done here.
            return true;
@@ -655,9 +670,9 @@ public class GraphicsEnvironment {
    }

    /**
     * Determine if ANGLE should be used.
     * Determine if ANGLE will be used and setup the environment
     */
    private boolean shouldUseAngle(Context context, String packageName) {
    private boolean setupAndUseAngle(Context context, String packageName) {
        // Need to make sure we are evaluating ANGLE usage for the correct circumstances
        if (!setupAngle(context, null, context.getPackageManager(), packageName)) {
            Log.v(TAG, "Package '" + packageName + "' should use not ANGLE");
@@ -677,7 +692,7 @@ public class GraphicsEnvironment {
    public void showAngleInUseDialogBox(Context context) {
        final String packageName = context.getPackageName();

        if (shouldShowAngleInUseDialogBox(context) && shouldUseAngle(context, packageName)) {
        if (shouldShowAngleInUseDialogBox(context) && setupAndUseAngle(context, packageName)) {
            final Intent intent = new Intent(ACTION_ANGLE_FOR_ANDROID_TOAST_MESSAGE);
            String anglePkg = getAnglePackageName(context.getPackageManager());
            intent.setPackage(anglePkg);
+4 −1
Original line number Diff line number Diff line
@@ -709,7 +709,10 @@ public final class ProcessList {
            ApplicationInfo applicationInfo) {
        final boolean shouldUseGameDriver =
                GraphicsEnvironment.shouldUseGameDriver(context, coreSettings, applicationInfo);
        return !shouldUseGameDriver;
        final boolean shouldUseAngle =
                GraphicsEnvironment.shouldUseAngle(context, coreSettings,
                    applicationInfo.packageName);
        return !shouldUseGameDriver && !shouldUseAngle;
    }

    public static String makeOomAdjString(int setAdj, boolean compact) {