diff options
| author | Cody Northrop <cnorthrop@google.com> | 2019-01-15 14:06:36 -0700 |
|---|---|---|
| committer | Cody Northrop <cnorthrop@google.com> | 2019-01-24 07:06:37 -0700 |
| commit | 5ebb0db1043f71ca785396ca98047639e7627e99 (patch) | |
| tree | 6cab3c62a39635dfe0ad29b21843cd76dcc26924 /core/java/android/os/GraphicsEnvironment.java | |
| parent | b959de1a9435312a2a15afbcd720c8829333a7e5 (diff) | |
Guard ANGLE rules checking with a whitelist
In order to reduce the startup impact to near zero, we are
creating a whitelist to be checked before parsing rules.
The whitelist will be generated by the APK based on apps
mentioned in the rules files. At app launch, only those in
the whitelist will do full rules checking.
The whitelist will be checked via Global Settings, which will
be populated by the ANGLE APK when intents are received. The
APK will listen for intents at boot (LOCKED_BOOT_COMPLETED)
and when ANGLE itself is updated (MY_PACKAGE_REPLACED).
The whitelist can also be populated by hand:
adb shell settings put global angle_whitelist app1,app2,appN
We plan to further mitigate the ANGLE-enabled app impact
by parsing the full rules when creating the whitelist, off of
the critical path.
Note: Developer Options will continue to work, regardless of
whitelist. But temp rules will not be loaded if the app is
not whitelisted.
Test: atest CtsAngleIntegrationHostTestCases
Test: atest google/perf/app-startup/hermetic-apps/cold-dropcache-test -v
Bug: 80239516
Bug: 122528316
Change-Id: I96e5b4d5b4774f59aadbd1e52295437a395cab6b
Diffstat (limited to 'core/java/android/os/GraphicsEnvironment.java')
| -rw-r--r-- | core/java/android/os/GraphicsEnvironment.java | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/core/java/android/os/GraphicsEnvironment.java b/core/java/android/os/GraphicsEnvironment.java index 099b4f33fa4d..efcad3ece97d 100644 --- a/core/java/android/os/GraphicsEnvironment.java +++ b/core/java/android/os/GraphicsEnvironment.java @@ -405,16 +405,57 @@ public class GraphicsEnvironment { } /** + * Pull ANGLE whitelist from GlobalSettings and compare against current package + */ + private boolean checkAngleWhitelist(Bundle bundle, String packageName) { + List<String> angleWhitelist = + getGlobalSettingsString(bundle, + Settings.Global.GLOBAL_SETTINGS_ANGLE_WHITELIST); + + return angleWhitelist.contains(packageName); + } + + /** * Pass ANGLE details down to trigger enable logic */ public void setupAngle(Context context, Bundle bundle, String packageName) { - String devOptIn = getDriverForPkg(bundle, packageName); + if (packageName.isEmpty()) { + Log.v(TAG, "No package name available yet, skipping ANGLE setup"); + return; + } + String devOptIn = getDriverForPkg(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. + boolean whitelisted = checkAngleWhitelist(bundle, packageName); + boolean defaulted = devOptIn.equals(sDriverMap.get(OpenGlDriverChoice.DEFAULT)); + boolean rulesCheck = (whitelisted || !defaulted); + if (!rulesCheck) { + return; + } + + if (whitelisted) { + Log.v(TAG, "ANGLE whitelist includes " + packageName); + } + if (!defaulted) { + Log.v(TAG, "ANGLE developer option for " + packageName + ": " + devOptIn); + } + String anglePkgName = getAnglePackageName(context); if (anglePkgName.isEmpty()) { Log.e(TAG, "Failed to find ANGLE package."); |
