Merge "GraphicsEnvironment: Expose query to determine ANGLE use" into qt-dev

This commit is contained in:
Cody Northrop
2019-04-18 19:47:07 +00:00
committed by Android (Google) Code Review
2 changed files with 56 additions and 38 deletions

View File

@@ -163,6 +163,43 @@ public class GraphicsEnvironment {
return true;
}
/**
* 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
*/
@@ -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");
if (!shouldUseAngle(context, bundle, packageName)) {
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) {
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);

View File

@@ -709,7 +709,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) {