summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Peiyong Lin <lpy@google.com> 2019-08-22 22:59:39 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-08-22 22:59:39 +0000
commitbc80fff0a4293765fc686f10a8018502f49a9cea (patch)
tree238c7be992aae075f54d7cd6c12a9c61aa2842f6
parentf4fc3e2693a38ca576e7522df2175016f6e9f152 (diff)
parent7797b4de46f712335c496a59d39215be0f0ee2aa (diff)
Merge "Add manifest flag to enable prerelease driver." into qt-qpr1-dev
-rw-r--r--core/java/android/os/GraphicsEnvironment.java26
1 files changed, 21 insertions, 5 deletions
diff --git a/core/java/android/os/GraphicsEnvironment.java b/core/java/android/os/GraphicsEnvironment.java
index ce1942cc6d91..7a70e93b69d5 100644
--- a/core/java/android/os/GraphicsEnvironment.java
+++ b/core/java/android/os/GraphicsEnvironment.java
@@ -67,6 +67,8 @@ public class GraphicsEnvironment {
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 METADATA_DEVELOPER_DRIVER_ENABLE =
+ "com.android.graphics.developerdriver.enable";
private static final String ANGLE_RULES_FILE = "a4a_rules.json";
private static final String ANGLE_TEMP_RULES = "debug.angle.rules";
private static final String ACTION_ANGLE_FOR_ANDROID = "android.app.action.ANGLE_FOR_ANDROID";
@@ -691,7 +693,8 @@ public class GraphicsEnvironment {
/**
* Return the driver package name to use. Return null for system driver.
*/
- private static String chooseDriverInternal(Context context, Bundle coreSettings) {
+ private static String chooseDriverInternal(
+ Context context, Bundle coreSettings, PackageManager pm, String packageName) {
final String gameDriver = SystemProperties.get(PROPERTY_GFX_DRIVER);
final boolean hasGameDriver = gameDriver != null && !gameDriver.isEmpty();
@@ -706,12 +709,24 @@ public class GraphicsEnvironment {
// 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();
+ ApplicationInfo ai;
+ try {
+ // Get the ApplicationInfo from PackageManager so that metadata fields present.
+ ai = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
+ } catch (PackageManager.NameNotFoundException e) {
+ // Unlikely to fail for applications, but in case of failure, fall back to use the
+ // ApplicationInfo from context directly.
+ 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;
}
+ final boolean enablePrereleaseDriver =
+ (ai.metaData != null && ai.metaData.getBoolean(METADATA_DEVELOPER_DRIVER_ENABLE))
+ || getCanLoadSystemLibraries() == 1;
+
// Priority for Game Driver settings global on confliction (Higher priority comes first):
// 1. GAME_DRIVER_ALL_APPS
// 2. GAME_DRIVER_OPT_OUT_APPS
@@ -728,7 +743,7 @@ public class GraphicsEnvironment {
return hasGameDriver ? gameDriver : null;
case GAME_DRIVER_GLOBAL_OPT_IN_PRERELEASE_DRIVER:
if (DEBUG) Log.v(TAG, "All apps opt in to use prerelease driver.");
- return hasPrereleaseDriver ? prereleaseDriver : null;
+ return hasPrereleaseDriver && enablePrereleaseDriver ? prereleaseDriver : null;
case GAME_DRIVER_GLOBAL_OPT_IN_DEFAULT:
default:
break;
@@ -745,7 +760,7 @@ public class GraphicsEnvironment {
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;
+ return hasPrereleaseDriver && enablePrereleaseDriver ? prereleaseDriver : null;
}
// Early return here since the rest logic is only for Game Driver.
@@ -783,7 +798,8 @@ public class GraphicsEnvironment {
*/
private static boolean chooseDriver(
Context context, Bundle coreSettings, PackageManager pm, String packageName) {
- final String driverPackageName = chooseDriverInternal(context, coreSettings);
+ final String driverPackageName = chooseDriverInternal(context, coreSettings, pm,
+ packageName);
if (driverPackageName == null) {
return false;
}