summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Cody Northrop <cnorthrop@google.com> 2019-04-09 20:39:20 -0600
committer Cody Northrop <cnorthrop@google.com> 2019-04-16 11:48:29 -0600
commit12d320a5018e81e67a41df00188516b693a26585 (patch)
treeb25e8ec796b6236d7d5f8e3b70abf2d4d172cd98
parent20d039537f3afe82c26311de991bdd470b35b279 (diff)
GraphicsEnvironment: Expose query to determine ANGLE use
Move the early logic that decides whether ANGLE should be used to a static public function that can be queried elsewhere without setting up the environment further. Bug: 130029351 Test: atest CtsAngleIntegrationHostTestCases Change-Id: I908233d46631ec91dca714bff3f8fd9341160c9e
-rw-r--r--core/java/android/os/GraphicsEnvironment.java87
-rw-r--r--services/core/java/com/android/server/am/ProcessList.java5
2 files changed, 55 insertions, 37 deletions
diff --git a/core/java/android/os/GraphicsEnvironment.java b/core/java/android/os/GraphicsEnvironment.java
index 779790c09dc8..a51a871e7780 100644
--- a/core/java/android/os/GraphicsEnvironment.java
+++ b/core/java/android/os/GraphicsEnvironment.java
@@ -164,6 +164,43 @@ public class GraphicsEnvironment {
}
/**
+ * 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
*/
private static boolean isDebuggable(Context context) {
@@ -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);
diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java
index 9780a7f71970..b3d611364b56 100644
--- a/services/core/java/com/android/server/am/ProcessList.java
+++ b/services/core/java/com/android/server/am/ProcessList.java
@@ -708,7 +708,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) {