Merge "Game Driver: process sphal libraries in GPU service"
This commit is contained in:
@@ -664,8 +664,15 @@ public class GraphicsEnvironment {
|
||||
.append(abi);
|
||||
final String paths = sb.toString();
|
||||
|
||||
if (DEBUG) Log.v(TAG, "gfx driver package libs: " + paths);
|
||||
setDriverPath(paths);
|
||||
final String sphalLibraries =
|
||||
coreSettings.getString(Settings.Global.GAME_DRIVER_SPHAL_LIBRARIES);
|
||||
|
||||
if (DEBUG) {
|
||||
Log.v(TAG,
|
||||
"gfx driver package search path: " + paths
|
||||
+ ", required sphal libraries: " + sphalLibraries);
|
||||
}
|
||||
setDriverPathAndSphalLibraries(paths, sphalLibraries);
|
||||
|
||||
if (driverAppInfo.metaData == null) {
|
||||
throw new NullPointerException("apk's meta-data cannot be null");
|
||||
@@ -700,7 +707,7 @@ public class GraphicsEnvironment {
|
||||
private static native void setLayerPaths(ClassLoader classLoader, String layerPaths);
|
||||
private static native void setDebugLayers(String layers);
|
||||
private static native void setDebugLayersGLES(String layers);
|
||||
private static native void setDriverPath(String path);
|
||||
private static native void setDriverPathAndSphalLibraries(String path, String sphalLibraries);
|
||||
private static native void setGpuStats(String driverPackageName, String driverVersionName,
|
||||
long driverVersionCode, long driverBuildTime, String appPackageName);
|
||||
private static native void setAngleInfo(String path, String appPackage, String devOptIn,
|
||||
|
||||
@@ -27,9 +27,12 @@ int getCanLoadSystemLibraries_native() {
|
||||
return android::GraphicsEnv::getInstance().getCanLoadSystemLibraries();
|
||||
}
|
||||
|
||||
void setDriverPath(JNIEnv* env, jobject clazz, jstring path) {
|
||||
void setDriverPathAndSphalLibraries_native(JNIEnv* env, jobject clazz, jstring path,
|
||||
jstring sphalLibraries) {
|
||||
ScopedUtfChars pathChars(env, path);
|
||||
android::GraphicsEnv::getInstance().setDriverPath(pathChars.c_str());
|
||||
ScopedUtfChars sphalLibrariesChars(env, sphalLibraries);
|
||||
android::GraphicsEnv::getInstance().setDriverPathAndSphalLibraries(pathChars.c_str(),
|
||||
sphalLibrariesChars.c_str());
|
||||
}
|
||||
|
||||
void setGpuStats_native(JNIEnv* env, jobject clazz, jstring driverPackageName,
|
||||
@@ -84,7 +87,7 @@ void setDebugLayersGLES_native(JNIEnv* env, jobject clazz, jstring layers) {
|
||||
|
||||
const JNINativeMethod g_methods[] = {
|
||||
{ "getCanLoadSystemLibraries", "()I", reinterpret_cast<void*>(getCanLoadSystemLibraries_native) },
|
||||
{ "setDriverPath", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDriverPath) },
|
||||
{ "setDriverPathAndSphalLibraries", "(Ljava/lang/String;Ljava/lang/String;)V", reinterpret_cast<void*>(setDriverPathAndSphalLibraries_native) },
|
||||
{ "setGpuStats", "(Ljava/lang/String;Ljava/lang/String;JJLjava/lang/String;)V", reinterpret_cast<void*>(setGpuStats_native) },
|
||||
{ "setAngleInfo", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/io/FileDescriptor;JJ)V", reinterpret_cast<void*>(setAngleInfo_native) },
|
||||
{ "getShouldUseAngle", "(Ljava/lang/String;)Z", reinterpret_cast<void*>(shouldUseAngle_native) },
|
||||
|
||||
@@ -62,6 +62,7 @@ public class GpuService extends SystemService {
|
||||
|
||||
private static final String PROPERTY_GFX_DRIVER = "ro.gfx.driver.0";
|
||||
private static final String GAME_DRIVER_WHITELIST_FILENAME = "whitelist.txt";
|
||||
private static final String GAME_DRIVER_SPHAL_LIBRARIES_FILENAME = "sphal_libraries.txt";
|
||||
private static final int BASE64_FLAGS = Base64.NO_PADDING | Base64.NO_WRAP;
|
||||
|
||||
private final Context mContext;
|
||||
@@ -162,6 +163,25 @@ public class GpuService extends SystemService {
|
||||
}
|
||||
}
|
||||
|
||||
private static void assetToSettingsGlobal(Context context, Context driverContext,
|
||||
String fileName, String settingsGlobal, CharSequence delimiter) {
|
||||
try {
|
||||
final BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(driverContext.getAssets().open(fileName)));
|
||||
final ArrayList<String> assetStrings = new ArrayList<>();
|
||||
for (String assetString; (assetString = reader.readLine()) != null; ) {
|
||||
assetStrings.add(assetString);
|
||||
}
|
||||
Settings.Global.putString(context.getContentResolver(),
|
||||
settingsGlobal,
|
||||
String.join(delimiter, assetStrings));
|
||||
} catch (IOException e) {
|
||||
if (DEBUG) {
|
||||
Slog.w(TAG, "Failed to load " + fileName + ", abort.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchGameDriverPackageProperties() {
|
||||
final ApplicationInfo driverInfo;
|
||||
try {
|
||||
@@ -186,29 +206,25 @@ public class GpuService extends SystemService {
|
||||
// Reset the whitelist.
|
||||
Settings.Global.putString(mContentResolver,
|
||||
Settings.Global.GAME_DRIVER_WHITELIST, "");
|
||||
// Reset the sphal libraries
|
||||
Settings.Global.putString(mContentResolver,
|
||||
Settings.Global.GAME_DRIVER_SPHAL_LIBRARIES, "");
|
||||
mGameDriverVersionCode = driverInfo.longVersionCode;
|
||||
|
||||
try {
|
||||
final Context driverContext = mContext.createPackageContext(mDriverPackageName,
|
||||
Context.CONTEXT_RESTRICTED);
|
||||
final BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(driverContext.getAssets()
|
||||
.open(GAME_DRIVER_WHITELIST_FILENAME)));
|
||||
final ArrayList<String> whitelistedPackageNames = new ArrayList<>();
|
||||
for (String packageName; (packageName = reader.readLine()) != null; ) {
|
||||
whitelistedPackageNames.add(packageName);
|
||||
}
|
||||
Settings.Global.putString(mContentResolver,
|
||||
Settings.Global.GAME_DRIVER_WHITELIST,
|
||||
String.join(",", whitelistedPackageNames));
|
||||
|
||||
assetToSettingsGlobal(mContext, driverContext, GAME_DRIVER_WHITELIST_FILENAME,
|
||||
Settings.Global.GAME_DRIVER_WHITELIST, ",");
|
||||
|
||||
assetToSettingsGlobal(mContext, driverContext, GAME_DRIVER_SPHAL_LIBRARIES_FILENAME,
|
||||
Settings.Global.GAME_DRIVER_SPHAL_LIBRARIES, ":");
|
||||
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
if (DEBUG) {
|
||||
Slog.w(TAG, "driver package '" + mDriverPackageName + "' not installed");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (DEBUG) {
|
||||
Slog.w(TAG, "Failed to load whitelist driver package, abort.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user