diff options
Diffstat (limited to 'core/java/android/os/GraphicsEnvironment.java')
| -rw-r--r-- | core/java/android/os/GraphicsEnvironment.java | 118 |
1 files changed, 68 insertions, 50 deletions
diff --git a/core/java/android/os/GraphicsEnvironment.java b/core/java/android/os/GraphicsEnvironment.java index 53503f47ca74..06720f98d987 100644 --- a/core/java/android/os/GraphicsEnvironment.java +++ b/core/java/android/os/GraphicsEnvironment.java @@ -72,6 +72,14 @@ public class GraphicsEnvironment { private static final String INTENT_KEY_A4A_TOAST_MESSAGE = "A4A Toast Message"; private static final String GAME_DRIVER_WHITELIST_ALL = "*"; + // 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 + private static final int GAME_DRIVER_GLOBAL_OPT_IN_DEFAULT = 0; + private static final int GAME_DRIVER_GLOBAL_OPT_IN_ALL = 1; + private static final int GAME_DRIVER_GLOBAL_OPT_IN_NONE = 2; + private ClassLoader mClassLoader; private String mLayerPath; private String mDebugLayerPath; @@ -97,6 +105,65 @@ public class GraphicsEnvironment { } /** + * 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; + } + + /** * Check whether application is debuggable */ private static boolean isDebuggable(Context context) { @@ -652,59 +719,10 @@ public class GraphicsEnvironment { 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. - 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 false; - } - - // 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 - final int gameDriverAllApps = coreSettings.getInt(Settings.Global.GAME_DRIVER_ALL_APPS, 0); - if (gameDriverAllApps == 2) { - if (DEBUG) { - Log.w(TAG, "Game Driver is turned off on this device"); - } + if (!shouldUseGameDriver(context, coreSettings, context.getApplicationInfo())) { return false; } - if (gameDriverAllApps != 1) { - // GAME_DRIVER_OPT_OUT_APPS has higher priority than GAME_DRIVER_OPT_IN_APPS - if (getGlobalSettingsString(null, coreSettings, - Settings.Global.GAME_DRIVER_OPT_OUT_APPS).contains(packageName)) { - if (DEBUG) { - Log.w(TAG, packageName + " opts out from Game Driver."); - } - return false; - } - final boolean isOptIn = - getGlobalSettingsString(null, coreSettings, - Settings.Global.GAME_DRIVER_OPT_IN_APPS).contains(packageName); - final List<String> whitelist = getGlobalSettingsString(null, coreSettings, - Settings.Global.GAME_DRIVER_WHITELIST); - if (!isOptIn && whitelist.indexOf(GAME_DRIVER_WHITELIST_ALL) != 0 - && !whitelist.contains(packageName)) { - if (DEBUG) { - Log.w(TAG, packageName + " is not on the whitelist."); - } - return false; - } - - // If the application is not opted-in and 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(ai.packageName)) { - return false; - } - } - final String abi = chooseAbi(driverAppInfo); if (abi == null) { if (DEBUG) { |
