diff options
author | 2019-06-13 09:10:11 -0700 | |
---|---|---|
committer | 2019-06-13 09:10:11 -0700 | |
commit | 38f703fc577888ce73e2e1e7b10ebe1923adca11 (patch) | |
tree | 29f2f1f0c14632dcbed1c0a8a8f0d01464e45318 | |
parent | ef2b2b285d1b7b1332fde816dab8485cec75311e (diff) | |
parent | 47f93359d1a8b0bb88f912127432d5915803e3e3 (diff) |
Merge "Game Driver: Add support for prerelease channel" into qt-dev am: ba3f191bd5 am: 17704b8d1b
am: 47f93359d1
Change-Id: Ifad6870eef4fd0bdd0dbafebfd4dd310d1d148d0
-rw-r--r-- | core/java/android/os/GraphicsEnvironment.java | 154 |
1 files changed, 89 insertions, 65 deletions
diff --git a/core/java/android/os/GraphicsEnvironment.java b/core/java/android/os/GraphicsEnvironment.java index 24a147783669..833bb8f6f790 100644 --- a/core/java/android/os/GraphicsEnvironment.java +++ b/core/java/android/os/GraphicsEnvironment.java @@ -62,6 +62,7 @@ public class GraphicsEnvironment { private static final String SYSTEM_DRIVER_VERSION_NAME = ""; private static final long SYSTEM_DRIVER_VERSION_CODE = 0; private static final String PROPERTY_GFX_DRIVER = "ro.gfx.driver.0"; + private static final String PROPERTY_GFX_DRIVER_PRERELEASE = "ro.gfx.driver.1"; private static final String PROPERTY_GFX_DRIVER_BUILD_TIME = "ro.gfx.driver_build_time"; private static final String METADATA_DRIVER_BUILD_TIME = "com.android.gamedriver.build_time"; private static final String ANGLE_RULES_FILE = "a4a_rules.json"; @@ -114,65 +115,6 @@ public class GraphicsEnvironment { public static native void hintActivityLaunch(); /** - * Allow to query whether an application will use Game Driver. - */ - public static boolean shouldUseGameDriver(Context context, Bundle coreSettings, - ApplicationInfo applicationInfo) { - final String driverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER); - if (driverPackageName == null || driverPackageName.isEmpty()) { - return false; - } - - // 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. - if (applicationInfo.isPrivilegedApp() || (applicationInfo.isSystemApp() - && !applicationInfo.isUpdatedSystemApp())) { - if (DEBUG) Log.v(TAG, "ignoring driver package for privileged/non-updated system app"); - return false; - } - final ContentResolver contentResolver = context.getContentResolver(); - final String packageName = applicationInfo.packageName; - final int globalOptIn; - if (coreSettings != null) { - globalOptIn = coreSettings.getInt(Settings.Global.GAME_DRIVER_ALL_APPS, 0); - } else { - globalOptIn = Settings.Global.getInt(contentResolver, - Settings.Global.GAME_DRIVER_ALL_APPS, 0); - } - if (globalOptIn == GAME_DRIVER_GLOBAL_OPT_IN_ALL) { - return true; - } - if (globalOptIn == GAME_DRIVER_GLOBAL_OPT_IN_NONE) { - return false; - } - - // GAME_DRIVER_OPT_OUT_APPS has higher priority than GAME_DRIVER_OPT_IN_APPS - if (getGlobalSettingsString(contentResolver, coreSettings, - Settings.Global.GAME_DRIVER_OPT_OUT_APPS).contains(packageName)) { - return false; - } - final boolean isOptIn = getGlobalSettingsString(contentResolver, coreSettings, - Settings.Global.GAME_DRIVER_OPT_IN_APPS).contains(packageName); - final List<String> whitelist = getGlobalSettingsString(contentResolver, coreSettings, - Settings.Global.GAME_DRIVER_WHITELIST); - if (!isOptIn && whitelist.indexOf(GAME_DRIVER_WHITELIST_ALL) != 0 - && !whitelist.contains(packageName)) { - return false; - } - - // If the application is not opted-in, then check whether it's on the blacklist, - // terminate early if it's on the blacklist and fallback to system driver. - if (!isOptIn - && getGlobalSettingsString(contentResolver, coreSettings, - Settings.Global.GAME_DRIVER_BLACKLIST) - .contains(packageName)) { - return false; - } - return true; - } - - /** * Query to determine if ANGLE should be used */ public static boolean shouldUseAngle(Context context, Bundle coreSettings, @@ -742,12 +684,98 @@ public class GraphicsEnvironment { } /** + * Return the driver package name to use. Return null for system driver. + */ + private static String chooseDriverInternal(Context context, Bundle coreSettings) { + final String gameDriver = SystemProperties.get(PROPERTY_GFX_DRIVER); + final boolean hasGameDriver = gameDriver != null && !gameDriver.isEmpty(); + + final String prereleaseDriver = SystemProperties.get(PROPERTY_GFX_DRIVER_PRERELEASE); + final boolean hasPrereleaseDriver = prereleaseDriver != null && !prereleaseDriver.isEmpty(); + + if (!hasGameDriver && !hasPrereleaseDriver) { + if (DEBUG) Log.v(TAG, "Neither Game Driver nor prerelease driver is supported."); + return null; + } + + // 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. + final ApplicationInfo ai = context.getApplicationInfo(); + if (ai.isPrivilegedApp() || (ai.isSystemApp() && !ai.isUpdatedSystemApp())) { + if (DEBUG) Log.v(TAG, "Ignoring driver package for privileged/non-updated system app."); + return null; + } + + // Priority for Game Driver settings global on confliction (Higher priority comes first): + // 1. GAME_DRIVER_ALL_APPS + // 2. GAME_DRIVER_OPT_OUT_APPS + // 3. GAME_DRIVER_PRERELEASE_OPT_IN_APPS + // 4. GAME_DRIVER_OPT_IN_APPS + // 5. GAME_DRIVER_BLACKLIST + // 6. GAME_DRIVER_WHITELIST + final int globalOptIn = coreSettings.getInt(Settings.Global.GAME_DRIVER_ALL_APPS, 0); + if (globalOptIn == GAME_DRIVER_GLOBAL_OPT_IN_NONE) { + if (DEBUG) Log.v(TAG, "Game Driver is turned off on this device."); + return null; + } + + if (globalOptIn == GAME_DRIVER_GLOBAL_OPT_IN_ALL) { + if (DEBUG) Log.v(TAG, "All apps opt in to use Game Driver."); + return hasGameDriver ? gameDriver : null; + } + + final String appPackageName = ai.packageName; + if (getGlobalSettingsString(null, coreSettings, Settings.Global.GAME_DRIVER_OPT_OUT_APPS) + .contains(appPackageName)) { + if (DEBUG) Log.v(TAG, "App opts out for Game Driver."); + return null; + } + + if (getGlobalSettingsString( + null, coreSettings, Settings.Global.GAME_DRIVER_PRERELEASE_OPT_IN_APPS) + .contains(appPackageName)) { + if (DEBUG) Log.v(TAG, "App opts in for prerelease Game Driver."); + return hasPrereleaseDriver ? prereleaseDriver : null; + } + + // Early return here since the rest logic is only for Game Driver. + if (!hasGameDriver) { + if (DEBUG) Log.v(TAG, "Game Driver is not supported on the device."); + return null; + } + + final boolean isOptIn = + getGlobalSettingsString(null, coreSettings, Settings.Global.GAME_DRIVER_OPT_IN_APPS) + .contains(appPackageName); + final List<String> whitelist = + getGlobalSettingsString(null, coreSettings, Settings.Global.GAME_DRIVER_WHITELIST); + if (!isOptIn && whitelist.indexOf(GAME_DRIVER_WHITELIST_ALL) != 0 + && !whitelist.contains(appPackageName)) { + if (DEBUG) Log.v(TAG, "App is not on the whitelist for Game Driver."); + return null; + } + + // If the application is not opted-in, then check whether it's on the blacklist, + // terminate early if it's on the blacklist and fallback to system driver. + if (!isOptIn + && getGlobalSettingsString( + null, coreSettings, Settings.Global.GAME_DRIVER_BLACKLIST) + .contains(appPackageName)) { + if (DEBUG) Log.v(TAG, "App is on the blacklist for Game Driver."); + return null; + } + + return gameDriver; + } + + /** * Choose whether the current process should use the builtin or an updated driver. */ private static boolean chooseDriver( Context context, Bundle coreSettings, PackageManager pm, String packageName) { - final String driverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER); - if (driverPackageName == null || driverPackageName.isEmpty()) { + final String driverPackageName = chooseDriverInternal(context, coreSettings); + if (driverPackageName == null) { return false; } @@ -770,10 +798,6 @@ public class GraphicsEnvironment { return false; } - if (!shouldUseGameDriver(context, coreSettings, context.getApplicationInfo())) { - return false; - } - final String abi = chooseAbi(driverAppInfo); if (abi == null) { if (DEBUG) { |