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

Commit a8822628 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes from topic "GameDriver2"

* changes:
  Game Driver: rename GUP to Game Driver
  [Game Driver] Add support for whitelist.
  [Game Driver] Add blacklist mechanism.
  GUP: Add a global property for genreal preference
  GUP: Update global property for the new dev opt
  GUP: Add metrics constant for GUP UI
parents 3876ca9d c4db14e7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -687,6 +687,7 @@ java_defaults {
    static_libs: [
        "apex_aidl_interface-java",
        "framework-protos",
        "game-driver-protos",
        "android.hidl.base-V1.0-java",
        "android.hardware.cas-V1.0-java",
        "android.hardware.contexthub-V1.0-java",
+97 −23
Original line number Diff line number Diff line
@@ -20,12 +20,17 @@ import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.gamedriver.GameDriverProto.Blacklist;
import android.gamedriver.GameDriverProto.Blacklists;
import android.opengl.EGL14;
import android.os.Build;
import android.os.SystemProperties;
import android.provider.Settings;
import android.util.Base64;
import android.util.Log;

import com.android.framework.protobuf.InvalidProtocolBufferException;

import dalvik.system.VMRuntime;

import java.io.BufferedReader;
@@ -33,6 +38,9 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/** @hide */
public class GraphicsEnvironment {
@@ -49,7 +57,9 @@ public class GraphicsEnvironment {
    private static final boolean DEBUG = false;
    private static final String TAG = "GraphicsEnvironment";
    private static final String PROPERTY_GFX_DRIVER = "ro.gfx.driver.0";
    private static final String GUP_WHITELIST_FILENAME = "whitelist.txt";
    private static final String GAME_DRIVER_WHITELIST_FILENAME = "whitelist.txt";
    private static final String GAME_DRIVER_BLACKLIST_FLAG = "blacklist";
    private static final int BASE64_FLAGS = Base64.NO_PADDING | Base64.NO_WRAP;

    private ClassLoader mClassLoader;
    private String mLayerPath;
@@ -136,6 +146,19 @@ public class GraphicsEnvironment {
        setLayerPaths(mClassLoader, layerPaths);
    }

    private static List<String> getGlobalSettingsString(Bundle bundle, String globalSetting) {
        List<String> valueList = null;
        String settingsValue = bundle.getString(globalSetting);

        if (settingsValue != null) {
            valueList = new ArrayList<>(Arrays.asList(settingsValue.split(",")));
        } else {
            valueList = new ArrayList<>();
        }

        return valueList;
    }

    /**
     * Choose whether the current process should use the builtin or an updated driver.
     */
@@ -145,6 +168,24 @@ public class GraphicsEnvironment {
            return;
        }

        ApplicationInfo driverInfo;
        try {
            driverInfo = context.getPackageManager().getApplicationInfo(driverPackageName,
                    PackageManager.MATCH_SYSTEM_ONLY);
        } catch (PackageManager.NameNotFoundException e) {
            Log.w(TAG, "driver package '" + driverPackageName + "' not installed");
            return;
        }

        // O drivers are restricted to the sphal linker namespace, so don't try to use
        // packages unless they declare they're compatible with that restriction.
        if (driverInfo.targetSdkVersion < Build.VERSION_CODES.O) {
            if (DEBUG) {
                Log.w(TAG, "updated driver package is not known to be compatible with O");
            }
            return;
        }

        // To minimize risk of driver updates crippling the device beyond user repair, never use an
        // updated driver for privileged or non-updated system apps. Presumably pre-installed apps
        // were tested thoroughly with the pre-installed driver.
@@ -154,35 +195,68 @@ public class GraphicsEnvironment {
            return;
        }

        String applicationPackageName = context.getPackageName();
        String devOptInApplicationName = coreSettings.getString(
                Settings.Global.GUP_DEV_OPT_IN_APPS);
        boolean devOptIn = applicationPackageName.equals(devOptInApplicationName);
        boolean whitelisted = onWhitelist(context, driverPackageName, ai.packageName);
        if (!devOptIn && !whitelisted) {
        // GAME_DRIVER_ALL_APPS
        // 0: Default (Invalid values fallback to default as well)
        // 1: All apps use Game Driver
        // 2: All apps use system graphics driver
        int gameDriverAllApps = coreSettings.getInt(Settings.Global.GAME_DRIVER_ALL_APPS, 0);
        if (gameDriverAllApps == 2) {
            if (DEBUG) {
                Log.w(TAG, applicationPackageName + " is not on the whitelist.");
                Log.w(TAG, "Game Driver is turned off on this device");
            }
            return;
        }

        ApplicationInfo driverInfo;
        try {
            driverInfo = context.getPackageManager().getApplicationInfo(driverPackageName,
                    PackageManager.MATCH_SYSTEM_ONLY);
        } catch (PackageManager.NameNotFoundException e) {
            Log.w(TAG, "driver package '" + driverPackageName + "' not installed");
        if (gameDriverAllApps != 1) {
            // GAME_DRIVER_OPT_OUT_APPS has higher priority than GAME_DRIVER_OPT_IN_APPS
            if (getGlobalSettingsString(coreSettings, Settings.Global.GAME_DRIVER_OPT_OUT_APPS)
                            .contains(ai.packageName)) {
                if (DEBUG) {
                    Log.w(TAG, ai.packageName + " opts out from Game Driver.");
                }
                return;
            }
            boolean isOptIn =
                    getGlobalSettingsString(coreSettings, Settings.Global.GAME_DRIVER_OPT_IN_APPS)
                            .contains(ai.packageName);

        // O drivers are restricted to the sphal linker namespace, so don't try to use
        // packages unless they declare they're compatible with that restriction.
        if (driverInfo.targetSdkVersion < Build.VERSION_CODES.O) {
            if (!isOptIn && !onWhitelist(context, driverPackageName, ai.packageName)) {
                if (DEBUG) {
                Log.w(TAG, "updated driver package is not known to be compatible with O");
                    Log.w(TAG, ai.packageName + " is not on the whitelist.");
                }
                return;
            }

            if (!isOptIn) {
                // At this point, the application is on the whitelist only, check whether it's
                // on the blacklist, terminate early when it's on the blacklist.
                try {
                    // TODO(b/121350991) Switch to DeviceConfig with property listener.
                    String base64String =
                            coreSettings.getString(Settings.Global.GAME_DRIVER_BLACKLIST);
                    if (base64String != null && !base64String.isEmpty()) {
                        Blacklists blacklistsProto = Blacklists.parseFrom(
                                Base64.decode(base64String, BASE64_FLAGS));
                        List<Blacklist> blacklists = blacklistsProto.getBlacklistsList();
                        long driverVersionCode = driverInfo.longVersionCode;
                        for (Blacklist blacklist : blacklists) {
                            if (blacklist.getVersionCode() == driverVersionCode) {
                                for (String packageName : blacklist.getPackageNamesList()) {
                                    if (packageName == ai.packageName) {
                                        return;
                                    }
                                }
                                break;
                            }
                        }
                    }
                } catch (InvalidProtocolBufferException e) {
                    if (DEBUG) {
                        Log.w(TAG, "Can't parse blacklist, skip and continue...");
                    }
                }
            }
        }

        String abi = chooseAbi(driverInfo);
        if (abi == null) {
@@ -245,7 +319,7 @@ public class GraphicsEnvironment {
            Context driverContext = context.createPackageContext(driverPackageName,
                                                                 Context.CONTEXT_RESTRICTED);
            AssetManager assets = driverContext.getAssets();
            InputStream stream = assets.open(GUP_WHITELIST_FILENAME);
            InputStream stream = assets.open(GAME_DRIVER_WHITELIST_FILENAME);
            BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
            for (String packageName; (packageName = reader.readLine()) != null; ) {
                if (packageName.equals(applicationPackageName)) {
+29 −4
Original line number Diff line number Diff line
@@ -11446,16 +11446,41 @@ public final class Settings {
        public static final String GPU_DEBUG_APP = "gpu_debug_app";
        /**
         * Apps that are selected to use Game Update Package.
         * Game Driver global preference for all Apps.
         * 0 = Default
         * 1 = All Apps use Game Driver
         * 2 = All Apps use system graphics driver
         * @hide
         */
        public static final String GUP_DEV_OPT_IN_APPS = "gup_dev_opt_in_apps";
        public static final String GAME_DRIVER_ALL_APPS = "game_driver_all_apps";
        /**
         * Apps on the black list that are forbidden to useGame Update Package.
         * List of Apps selected to use Game Driver.
         * i.e. <pkg1>,<pkg2>,...,<pkgN>
         * @hide
         */
        public static final String GUP_BLACK_LIST = "gup_black_list";
        public static final String GAME_DRIVER_OPT_IN_APPS = "game_driver_opt_in_apps";
        /**
         * List of Apps selected not to use Game Driver.
         * i.e. <pkg1>,<pkg2>,...,<pkgN>
         * @hide
         */
        public static final String GAME_DRIVER_OPT_OUT_APPS = "game_driver_opt_out_apps";
        /**
         * Apps on the blacklist that are forbidden to use Game Driver.
         * @hide
         */
        public static final String GAME_DRIVER_BLACKLIST = "game_driver_blacklist";
        /**
         * Apps on the whitelist that are allowed to use Game Driver.
         * The string is a list of application package names, seperated by comma.
         * i.e. <apk1>,<apk2>,...,<apkN>
         * @hide
         */
        public static final String GAME_DRIVER_WHITELIST = "game_driver_whitelist";
        /**
         * Ordered GPU debug layer list
+15 −5
Original line number Diff line number Diff line
@@ -384,11 +384,21 @@ message GlobalSettingsProto {
        // App allowed to load GPU debug layers.
        optional SettingProto debug_app = 1;
        optional SettingProto debug_layers = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
        // Apps opt in to load graphics driver from Game Update Package
        // instead of native graphcis driver through developer options.
        optional SettingProto gup_dev_opt_in_apps = 8;
        // Apps on the black list that are forbidden to useGame Update Package.
        optional SettingProto gup_black_list = 9;
        // Game Driver - global preference for all Apps
        // 0 = Default
        // 1 = All Apps use Game Driver
        // 2 = All Apps use system graphics driver
        optional SettingProto game_driver_all_apps = 8;
        // Game Driver - List of Apps selected to use Game Driver
        // i.e. <pkg1>,<pkg2>,...,<pkgN>
        optional SettingProto game_driver_opt_in_apps = 9;
        // Game Driver - List of Apps selected not to use Game Driver
        // i.e. <pkg1>,<pkg2>,...,<pkgN>
        optional SettingProto game_driver_opt_out_apps = 10;
        // Game Driver - List of Apps that are forbidden to use Game Driver
        optional SettingProto game_driver_blacklist = 11;
        // Game Driver - List of Apps that are allowed to use Game Driver
        optional SettingProto game_driver_whitelist = 12;
    }
    optional Gpu gpu = 59;

+5 −2
Original line number Diff line number Diff line
@@ -444,8 +444,11 @@ public class SettingsBackupTest {
                    Settings.Global.ENABLE_GPU_DEBUG_LAYERS,
                    Settings.Global.GPU_DEBUG_APP,
                    Settings.Global.GPU_DEBUG_LAYERS,
                    Settings.Global.GUP_DEV_OPT_IN_APPS,
                    Settings.Global.GUP_BLACK_LIST,
                    Settings.Global.GAME_DRIVER_ALL_APPS,
                    Settings.Global.GAME_DRIVER_OPT_IN_APPS,
                    Settings.Global.GAME_DRIVER_OPT_OUT_APPS,
                    Settings.Global.GAME_DRIVER_BLACKLIST,
                    Settings.Global.GAME_DRIVER_WHITELIST,
                    Settings.Global.ENABLE_GNSS_RAW_MEAS_FULL_TRACKING,
                    Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_PERSISTENT,
                    Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_SLEEP_MILLIS,
Loading