OSDN Git Service

Add global property to store opt-in application package name.
authorPeiyong Lin <lpy@google.com>
Thu, 8 Nov 2018 05:10:07 +0000 (21:10 -0800)
committerYiwei Zhang <zzyiwei@google.com>
Wed, 17 Apr 2019 01:35:17 +0000 (18:35 -0700)
We provide a way in developer option to opt-in an application to use updated
graphics driver. To make sure we set up the graphics environment correctly, we
need to access the package name of the selected application. This patch
introduces a global property to store the package name.

BUG: 119221883
Test: Build, flash and boot, verify with prototype
Change-Id: I49dfcccf387169c072fb9345f7a50c00fcdb0737
Merged-In: I49dfcccf387169c072fb9345f7a50c00fcdb0737

core/java/android/app/ActivityThread.java
core/java/android/os/GraphicsEnvironment.java
core/java/android/provider/Settings.java
core/proto/android/providers/settings/global.proto
core/tests/coretests/src/android/provider/SettingsBackupTest.java
packages/SettingsLib/res/values/strings.xml
packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
services/core/java/com/android/server/am/CoreSettingsObserver.java

index a6f19f4..f453289 100644 (file)
@@ -5594,7 +5594,7 @@ public final class ActivityThread extends ClientTransactionHandler {
             }
         }
 
-        GraphicsEnvironment.getInstance().setup(context);
+        GraphicsEnvironment.getInstance().setup(context, mCoreSettings);
         Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
     }
 
index b1408f4..60003d3 100644 (file)
@@ -33,8 +33,6 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.util.HashSet;
-import java.util.Set;
 
 /** @hide */
 public class GraphicsEnvironment {
@@ -60,9 +58,9 @@ public class GraphicsEnvironment {
     /**
      * Set up GraphicsEnvironment
      */
-    public void setup(Context context) {
+    public void setup(Context context, Bundle coreSettings) {
         setupGpuLayers(context);
-        chooseDriver(context);
+        chooseDriver(context, coreSettings);
     }
 
     /**
@@ -141,11 +139,12 @@ public class GraphicsEnvironment {
     /**
      * Choose whether the current process should use the builtin or an updated driver.
      */
-    private static void chooseDriver(Context context) {
+    private static void chooseDriver(Context context, Bundle coreSettings) {
         String driverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER);
         if (driverPackageName == null || driverPackageName.isEmpty()) {
             return;
         }
+
         // 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.
@@ -154,12 +153,16 @@ public class GraphicsEnvironment {
             if (DEBUG) Log.v(TAG, "ignoring driver package for privileged/non-updated system app");
             return;
         }
-        Set<String> whitelist = loadWhitelist(context, driverPackageName);
 
-        // Empty whitelist implies no updatable graphics driver. Typically, the pre-installed
-        // updatable graphics driver is supposed to be a place holder and contains no graphics
-        // driver and whitelist.
-        if (whitelist == null || whitelist.isEmpty()) {
+        String applicationPackageName = context.getPackageName();
+        String devOptInApplicationName = coreSettings.getString(
+                Settings.Global.UPDATED_GFX_DRIVER_DEV_OPT_IN_APP);
+        boolean devOptIn = applicationPackageName.equals(devOptInApplicationName);
+        boolean whitelisted = onWhitelist(context, driverPackageName, ai.packageName);
+        if (!devOptIn && !whitelisted) {
+            if (DEBUG) {
+                Log.w(TAG, applicationPackageName + " is not on the whitelist.");
+            }
             return;
         }
 
@@ -171,12 +174,6 @@ public class GraphicsEnvironment {
             Log.w(TAG, "driver package '" + driverPackageName + "' not installed");
             return;
         }
-        if (!whitelist.contains(context.getPackageName())) {
-            if (DEBUG) {
-                Log.w(TAG, context.getPackageName() + " is not on the whitelist.");
-            }
-            return;
-        }
 
         // O drivers are restricted to the sphal linker namespace, so don't try to use
         // packages unless they declare they're compatible with that restriction.
@@ -242,10 +239,18 @@ public class GraphicsEnvironment {
         return null;
     }
 
-    private static Set<String> loadWhitelist(Context context, String driverPackageName) {
+    private static boolean onWhitelist(Context context, String driverPackageName,
+            String applicationPackageName) {
         String whitelistName = SystemProperties.get(PROPERTY_GFX_DRIVER_WHITELIST);
+
+        // Empty whitelist implies no updatable graphics driver. Typically, the pre-installed
+        // updatable graphics driver is supposed to be a place holder and contains no graphics
+        // driver and whitelist.
         if (whitelistName == null || whitelistName.isEmpty()) {
-            return null;
+            if (DEBUG) {
+                Log.w(TAG, "No whitelist found.");
+            }
+            return false;
         }
         try {
             Context driverContext = context.createPackageContext(driverPackageName,
@@ -253,11 +258,11 @@ public class GraphicsEnvironment {
             AssetManager assets = driverContext.getAssets();
             InputStream stream = assets.open(whitelistName);
             BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
-            Set<String> whitelist = new HashSet<>();
-            for (String line; (line = reader.readLine()) != null; ) {
-                whitelist.add(line);
+            for (String packageName; (packageName = reader.readLine()) != null; ) {
+                if (packageName.equals(applicationPackageName)) {
+                    return true;
+                }
             }
-            return whitelist;
         } catch (PackageManager.NameNotFoundException e) {
             if (DEBUG) {
                 Log.w(TAG, "driver package '" + driverPackageName + "' not installed");
@@ -267,7 +272,7 @@ public class GraphicsEnvironment {
                 Log.w(TAG, "Failed to load whitelist driver package, abort.");
             }
         }
-        return null;
+        return false;
     }
 
     private static native void setLayerPaths(ClassLoader classLoader, String layerPaths);
index 34e9eb3..734df0d 100644 (file)
@@ -11446,6 +11446,13 @@ public final class Settings {
         public static final String GPU_DEBUG_APP = "gpu_debug_app";
 
         /**
+         * App that is selected to use updated graphics driver.
+         * @hide
+         */
+        public static final String UPDATED_GFX_DRIVER_DEV_OPT_IN_APP =
+                "updated_gfx_driver_dev_opt_in_app";
+
+        /**
          * Ordered GPU debug layer list
          * i.e. <layer1>:<layer2>:...:<layerN>
          * @hide
index 99f3034..c8cf8c3 100644 (file)
@@ -384,6 +384,9 @@ message GlobalSettingsProto {
         // App allowed to load GPU debug layers.
         optional SettingProto debug_app = 1;
         optional SettingProto debug_layers = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // App opt in to load updated graphics driver instead of
+        // native graphcis driver through developer options.
+        optional SettingProto updated_gfx_driver_dev_opt_in_app = 6;
     }
     optional Gpu gpu = 59;
 
index 8e383a5..8976f45 100644 (file)
@@ -444,6 +444,7 @@ public class SettingsBackupTest {
                     Settings.Global.ENABLE_GPU_DEBUG_LAYERS,
                     Settings.Global.GPU_DEBUG_APP,
                     Settings.Global.GPU_DEBUG_LAYERS,
+                    Settings.Global.UPDATED_GFX_DRIVER_DEV_OPT_IN_APP,
                     Settings.Global.ENABLE_GNSS_RAW_MEAS_FULL_TRACKING,
                     Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_PERSISTENT,
                     Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_SLEEP_MILLIS,
index d5b1217..4684ab9 100644 (file)
 
     <!-- The notice header of Third-party licenses. not translatable -->
     <string name="notice_header" translatable="false"></string>
+
+    <!-- UI debug setting: opt in to use updated graphics driver? [CHAR LIMIT=100] -->
+    <string name="updated_gfx_driver_dev_opt_in_app_summary">Opt in app to use updated graphcis driver in developement</string>
 </resources>
index d5efcb5..34448f5 100644 (file)
@@ -647,6 +647,9 @@ class SettingsProtoDumpUtil {
         dumpSetting(s, p,
                 Settings.Global.GPU_DEBUG_LAYERS,
                 GlobalSettingsProto.Gpu.DEBUG_LAYERS);
+        dumpSetting(s, p,
+                Settings.Global.UPDATED_GFX_DRIVER_DEV_OPT_IN_APP,
+                GlobalSettingsProto.Gpu.UPDATED_GFX_DRIVER_DEV_OPT_IN_APP);
         p.end(gpuToken);
 
         final long hdmiToken = p.start(GlobalSettingsProto.HDMI);
index 160c753..ee3d3a1 100644 (file)
@@ -55,6 +55,8 @@ final class CoreSettingsObserver extends ContentObserver {
         // add other system settings here...
 
         sGlobalSettingToTypeMap.put(Settings.Global.DEBUG_VIEW_ATTRIBUTES, int.class);
+        sGlobalSettingToTypeMap.put(Settings.Global.UPDATED_GFX_DRIVER_DEV_OPT_IN_APP,
+                                    String.class);
         // add other global settings here...
     }