Merge changes from topic "GameDriver"
* changes: Rename updatable graphics driver to Game Update Package. [GUP] Hard code the name of the whitelist file. Add global property to store opt-in application package name. [GraphicsEnvironment] Add whitelist support.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package android.os;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.AssetManager;
|
||||
import android.opengl.EGL14;
|
||||
import android.os.Build;
|
||||
import android.os.SystemProperties;
|
||||
@@ -27,7 +28,11 @@ import android.util.Log;
|
||||
|
||||
import dalvik.system.VMRuntime;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/** @hide */
|
||||
public class GraphicsEnvironment {
|
||||
@@ -44,6 +49,7 @@ public class GraphicsEnvironment {
|
||||
private static final boolean DEBUG = false;
|
||||
private static final String TAG = "GraphicsEnvironment";
|
||||
private static final String PROPERTY_GFX_DRIVER = "ro.gfx.driver.0";
|
||||
private static final String GUP_WHITELIST_FILENAME = "whitelist.txt";
|
||||
|
||||
private ClassLoader mClassLoader;
|
||||
private String mLayerPath;
|
||||
@@ -52,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,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.
|
||||
@@ -146,6 +153,19 @@ public class GraphicsEnvironment {
|
||||
if (DEBUG) Log.v(TAG, "ignoring driver package for privileged/non-updated system app");
|
||||
return;
|
||||
}
|
||||
|
||||
String applicationPackageName = context.getPackageName();
|
||||
String devOptInApplicationName = coreSettings.getString(
|
||||
Settings.Global.GUP_DEV_OPT_IN_APPS);
|
||||
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;
|
||||
}
|
||||
|
||||
ApplicationInfo driverInfo;
|
||||
try {
|
||||
driverInfo = context.getPackageManager().getApplicationInfo(driverPackageName,
|
||||
@@ -154,6 +174,16 @@ public class GraphicsEnvironment {
|
||||
Log.w(TAG, "driver package '" + driverPackageName + "' not installed");
|
||||
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.
|
||||
if (driverInfo.targetSdkVersion < Build.VERSION_CODES.O) {
|
||||
if (DEBUG) {
|
||||
Log.w(TAG, "updated driver package is not known to be compatible with O");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
String abi = chooseAbi(driverInfo);
|
||||
if (abi == null) {
|
||||
if (DEBUG) {
|
||||
@@ -164,12 +194,6 @@ public class GraphicsEnvironment {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (driverInfo.targetSdkVersion < Build.VERSION_CODES.O) {
|
||||
// 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.
|
||||
Log.w(TAG, "updated driver package is not known to be compatible with O");
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(driverInfo.nativeLibraryDir)
|
||||
@@ -215,6 +239,31 @@ public class GraphicsEnvironment {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean onWhitelist(Context context, String driverPackageName,
|
||||
String applicationPackageName) {
|
||||
try {
|
||||
Context driverContext = context.createPackageContext(driverPackageName,
|
||||
Context.CONTEXT_RESTRICTED);
|
||||
AssetManager assets = driverContext.getAssets();
|
||||
InputStream stream = assets.open(GUP_WHITELIST_FILENAME);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
|
||||
for (String packageName; (packageName = reader.readLine()) != null; ) {
|
||||
if (packageName.equals(applicationPackageName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
if (DEBUG) {
|
||||
Log.w(TAG, "driver package '" + driverPackageName + "' not installed");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (DEBUG) {
|
||||
Log.w(TAG, "Failed to load whitelist driver package, abort.");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static native void setLayerPaths(ClassLoader classLoader, String layerPaths);
|
||||
private static native void setDebugLayers(String layers);
|
||||
private static native void setDriverPath(String path);
|
||||
|
||||
@@ -11445,6 +11445,18 @@ public final class Settings {
|
||||
*/
|
||||
public static final String GPU_DEBUG_APP = "gpu_debug_app";
|
||||
|
||||
/**
|
||||
* Apps that are selected to use Game Update Package.
|
||||
* @hide
|
||||
*/
|
||||
public static final String GUP_DEV_OPT_IN_APPS = "gup_dev_opt_in_apps";
|
||||
|
||||
/**
|
||||
* Apps on the black list that are forbidden to useGame Update Package.
|
||||
* @hide
|
||||
*/
|
||||
public static final String GUP_BLACK_LIST = "gup_black_list";
|
||||
|
||||
/**
|
||||
* Ordered GPU debug layer list
|
||||
* i.e. <layer1>:<layer2>:...:<layerN>
|
||||
|
||||
@@ -460,7 +460,9 @@ message SystemPropertiesProto {
|
||||
optional int32 vts_coverage = 43;
|
||||
optional string zygote = 44;
|
||||
|
||||
// Next Tag: 45
|
||||
optional string gfx_driver_whitelist_0 = 45;
|
||||
|
||||
// Next Tag: 46
|
||||
}
|
||||
optional Ro ro = 21;
|
||||
|
||||
|
||||
@@ -384,6 +384,11 @@ message GlobalSettingsProto {
|
||||
// App allowed to load GPU debug layers.
|
||||
optional SettingProto debug_app = 1;
|
||||
optional SettingProto debug_layers = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
|
||||
// Apps opt in to load graphics driver from Game Update Package
|
||||
// instead of native graphcis driver through developer options.
|
||||
optional SettingProto gup_dev_opt_in_apps = 8;
|
||||
// Apps on the black list that are forbidden to useGame Update Package.
|
||||
optional SettingProto gup_black_list = 9;
|
||||
}
|
||||
optional Gpu gpu = 59;
|
||||
|
||||
|
||||
@@ -444,6 +444,8 @@ public class SettingsBackupTest {
|
||||
Settings.Global.ENABLE_GPU_DEBUG_LAYERS,
|
||||
Settings.Global.GPU_DEBUG_APP,
|
||||
Settings.Global.GPU_DEBUG_LAYERS,
|
||||
Settings.Global.GUP_DEV_OPT_IN_APPS,
|
||||
Settings.Global.GUP_BLACK_LIST,
|
||||
Settings.Global.ENABLE_GNSS_RAW_MEAS_FULL_TRACKING,
|
||||
Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_PERSISTENT,
|
||||
Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_SLEEP_MILLIS,
|
||||
|
||||
@@ -1131,4 +1131,7 @@
|
||||
|
||||
<!-- 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="gup_dev_opt_in_app_summary">Opt in app to use Game Update Package in developement</string>
|
||||
</resources>
|
||||
|
||||
@@ -647,6 +647,12 @@ class SettingsProtoDumpUtil {
|
||||
dumpSetting(s, p,
|
||||
Settings.Global.GPU_DEBUG_LAYERS,
|
||||
GlobalSettingsProto.Gpu.DEBUG_LAYERS);
|
||||
dumpSetting(s, p,
|
||||
Settings.Global.GUP_DEV_OPT_IN_APPS,
|
||||
GlobalSettingsProto.Gpu.GUP_DEV_OPT_IN_APPS);
|
||||
dumpSetting(s, p,
|
||||
Settings.Global.GUP_BLACK_LIST,
|
||||
GlobalSettingsProto.Gpu.GUP_BLACK_LIST);
|
||||
p.end(gpuToken);
|
||||
|
||||
final long hdmiToken = p.start(GlobalSettingsProto.HDMI);
|
||||
|
||||
@@ -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.GUP_DEV_OPT_IN_APPS, String.class);
|
||||
sGlobalSettingToTypeMap.put(Settings.Global.GUP_BLACK_LIST, String.class);
|
||||
// add other global settings here...
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user