Merge changes from topic "GameDriver3"
am: 5d832d2988
Change-Id: If2449acb0eef75ad81d913ab8fc07ae927f2ab8e
This commit is contained in:
@@ -20,24 +20,16 @@ import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.AssetManager;
|
||||
import android.gamedriver.GameDriverProto.Blacklist;
|
||||
import android.gamedriver.GameDriverProto.Blacklists;
|
||||
import android.opengl.EGL14;
|
||||
import android.os.Build;
|
||||
import android.os.SystemProperties;
|
||||
import android.provider.Settings;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.framework.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import dalvik.system.VMRuntime;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -57,9 +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 GAME_DRIVER_WHITELIST_FILENAME = "whitelist.txt";
|
||||
private static final String GAME_DRIVER_BLACKLIST_FLAG = "blacklist";
|
||||
private static final int BASE64_FLAGS = Base64.NO_PADDING | Base64.NO_WRAP;
|
||||
private static final String GAME_DRIVER_WHITELIST_ALL = "*";
|
||||
|
||||
private ClassLoader mClassLoader;
|
||||
private String mLayerPath;
|
||||
@@ -108,15 +98,15 @@ public class GraphicsEnvironment {
|
||||
|
||||
if (isDebuggable(context)) {
|
||||
|
||||
int enable = Settings.Global.getInt(context.getContentResolver(),
|
||||
Settings.Global.ENABLE_GPU_DEBUG_LAYERS, 0);
|
||||
final int enable = Settings.Global.getInt(context.getContentResolver(),
|
||||
Settings.Global.ENABLE_GPU_DEBUG_LAYERS, 0);
|
||||
|
||||
if (enable != 0) {
|
||||
|
||||
String gpuDebugApp = Settings.Global.getString(context.getContentResolver(),
|
||||
Settings.Global.GPU_DEBUG_APP);
|
||||
final String gpuDebugApp = Settings.Global.getString(context.getContentResolver(),
|
||||
Settings.Global.GPU_DEBUG_APP);
|
||||
|
||||
String packageName = context.getPackageName();
|
||||
final String packageName = context.getPackageName();
|
||||
|
||||
if ((gpuDebugApp != null && packageName != null)
|
||||
&& (!gpuDebugApp.isEmpty() && !packageName.isEmpty())
|
||||
@@ -148,7 +138,7 @@ public class GraphicsEnvironment {
|
||||
|
||||
private static List<String> getGlobalSettingsString(Bundle bundle, String globalSetting) {
|
||||
List<String> valueList = null;
|
||||
String settingsValue = bundle.getString(globalSetting);
|
||||
final String settingsValue = bundle.getString(globalSetting);
|
||||
|
||||
if (settingsValue != null) {
|
||||
valueList = new ArrayList<>(Arrays.asList(settingsValue.split(",")));
|
||||
@@ -163,12 +153,12 @@ public class GraphicsEnvironment {
|
||||
* Choose whether the current process should use the builtin or an updated driver.
|
||||
*/
|
||||
private static void chooseDriver(Context context, Bundle coreSettings) {
|
||||
String driverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER);
|
||||
final String driverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER);
|
||||
if (driverPackageName == null || driverPackageName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ApplicationInfo driverInfo;
|
||||
final ApplicationInfo driverInfo;
|
||||
try {
|
||||
driverInfo = context.getPackageManager().getApplicationInfo(driverPackageName,
|
||||
PackageManager.MATCH_SYSTEM_ONLY);
|
||||
@@ -189,7 +179,7 @@ public class GraphicsEnvironment {
|
||||
// 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.
|
||||
ApplicationInfo ai = context.getApplicationInfo();
|
||||
final ApplicationInfo ai = context.getApplicationInfo();
|
||||
if (ai.isPrivilegedApp() || (ai.isSystemApp() && !ai.isUpdatedSystemApp())) {
|
||||
if (DEBUG) Log.v(TAG, "ignoring driver package for privileged/non-updated system app");
|
||||
return;
|
||||
@@ -199,7 +189,7 @@ public class GraphicsEnvironment {
|
||||
// 0: Default (Invalid values fallback to default as well)
|
||||
// 1: All apps use Game Driver
|
||||
// 2: All apps use system graphics driver
|
||||
int gameDriverAllApps = coreSettings.getInt(Settings.Global.GAME_DRIVER_ALL_APPS, 0);
|
||||
final int gameDriverAllApps = coreSettings.getInt(Settings.Global.GAME_DRIVER_ALL_APPS, 0);
|
||||
if (gameDriverAllApps == 2) {
|
||||
if (DEBUG) {
|
||||
Log.w(TAG, "Game Driver is turned off on this device");
|
||||
@@ -216,49 +206,29 @@ public class GraphicsEnvironment {
|
||||
}
|
||||
return;
|
||||
}
|
||||
boolean isOptIn =
|
||||
final boolean isOptIn =
|
||||
getGlobalSettingsString(coreSettings, Settings.Global.GAME_DRIVER_OPT_IN_APPS)
|
||||
.contains(ai.packageName);
|
||||
|
||||
if (!isOptIn && !onWhitelist(context, driverPackageName, ai.packageName)) {
|
||||
final List<String> whitelist = getGlobalSettingsString(coreSettings,
|
||||
Settings.Global.GAME_DRIVER_WHITELIST);
|
||||
if (!isOptIn && whitelist.indexOf(GAME_DRIVER_WHITELIST_ALL) != 0
|
||||
&& !whitelist.contains(ai.packageName)) {
|
||||
if (DEBUG) {
|
||||
Log.w(TAG, ai.packageName + " is not on the whitelist.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isOptIn) {
|
||||
// At this point, the application is on the whitelist only, check whether it's
|
||||
// on the blacklist, terminate early when it's on the blacklist.
|
||||
try {
|
||||
// TODO(b/121350991) Switch to DeviceConfig with property listener.
|
||||
String base64String =
|
||||
coreSettings.getString(Settings.Global.GAME_DRIVER_BLACKLIST);
|
||||
if (base64String != null && !base64String.isEmpty()) {
|
||||
Blacklists blacklistsProto = Blacklists.parseFrom(
|
||||
Base64.decode(base64String, BASE64_FLAGS));
|
||||
List<Blacklist> blacklists = blacklistsProto.getBlacklistsList();
|
||||
long driverVersionCode = driverInfo.longVersionCode;
|
||||
for (Blacklist blacklist : blacklists) {
|
||||
if (blacklist.getVersionCode() == driverVersionCode) {
|
||||
for (String packageName : blacklist.getPackageNamesList()) {
|
||||
if (packageName == ai.packageName) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
if (DEBUG) {
|
||||
Log.w(TAG, "Can't parse blacklist, skip and continue...");
|
||||
}
|
||||
}
|
||||
// If the application is not opted-in and check whether it's on the blacklist,
|
||||
// terminate early if it's on the blacklist and fallback to system driver.
|
||||
if (!isOptIn
|
||||
&& getGlobalSettingsString(coreSettings, Settings.Global.GAME_DRIVER_BLACKLIST)
|
||||
.contains(ai.packageName)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String abi = chooseAbi(driverInfo);
|
||||
final String abi = chooseAbi(driverInfo);
|
||||
if (abi == null) {
|
||||
if (DEBUG) {
|
||||
// This is the normal case for the pre-installed empty driver package, don't spam
|
||||
@@ -269,16 +239,23 @@ public class GraphicsEnvironment {
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(driverInfo.nativeLibraryDir)
|
||||
.append(File.pathSeparator);
|
||||
sb.append(driverInfo.sourceDir)
|
||||
.append("!/lib/")
|
||||
.append(abi);
|
||||
String paths = sb.toString();
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -292,7 +269,7 @@ public class GraphicsEnvironment {
|
||||
* Should only be called after chooseDriver().
|
||||
*/
|
||||
public static void earlyInitEGL() {
|
||||
Thread eglInitThread = new Thread(
|
||||
final Thread eglInitThread = new Thread(
|
||||
() -> {
|
||||
EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
|
||||
},
|
||||
@@ -301,7 +278,7 @@ public class GraphicsEnvironment {
|
||||
}
|
||||
|
||||
private static String chooseAbi(ApplicationInfo ai) {
|
||||
String isa = VMRuntime.getCurrentInstructionSet();
|
||||
final String isa = VMRuntime.getCurrentInstructionSet();
|
||||
if (ai.primaryCpuAbi != null &&
|
||||
isa.equals(VMRuntime.getInstructionSet(ai.primaryCpuAbi))) {
|
||||
return ai.primaryCpuAbi;
|
||||
@@ -313,32 +290,7 @@ 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(GAME_DRIVER_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);
|
||||
private static native void setDriverPathAndSphalLibraries(String path, String sphalLibraries);
|
||||
}
|
||||
|
||||
@@ -11474,6 +11474,12 @@ public final class Settings {
|
||||
*/
|
||||
public static final String GAME_DRIVER_BLACKLIST = "game_driver_blacklist";
|
||||
|
||||
/**
|
||||
* List of blacklists, each blacklist is a blacklist for a specific version of Game Driver.
|
||||
* @hide
|
||||
*/
|
||||
public static final String GAME_DRIVER_BLACKLISTS = "game_driver_blacklists";
|
||||
|
||||
/**
|
||||
* Apps on the whitelist that are allowed to use Game Driver.
|
||||
* The string is a list of application package names, seperated by comma.
|
||||
@@ -11482,6 +11488,14 @@ public final class Settings {
|
||||
*/
|
||||
public static final String GAME_DRIVER_WHITELIST = "game_driver_whitelist";
|
||||
|
||||
/**
|
||||
* List of libraries in sphal accessible by Game Driver
|
||||
* The string is a list of library names, separated by colon.
|
||||
* i.e. <lib1>:<lib2>:...:<libN>
|
||||
* @hide
|
||||
*/
|
||||
public static final String GAME_DRIVER_SPHAL_LIBRARIES = "game_driver_sphal_libraries";
|
||||
|
||||
/**
|
||||
* Ordered GPU debug layer list
|
||||
* i.e. <layer1>:<layer2>:...:<layerN>
|
||||
|
||||
@@ -23,9 +23,12 @@
|
||||
|
||||
namespace {
|
||||
|
||||
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 setLayerPaths_native(JNIEnv* env, jobject clazz, jobject classLoader, jstring layerPaths) {
|
||||
@@ -43,7 +46,7 @@ void setDebugLayers_native(JNIEnv* env, jobject clazz, jstring layers) {
|
||||
}
|
||||
|
||||
const JNINativeMethod g_methods[] = {
|
||||
{ "setDriverPath", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDriverPath) },
|
||||
{ "setDriverPathAndSphalLibraries", "(Ljava/lang/String;Ljava/lang/String;)V", reinterpret_cast<void*>(setDriverPathAndSphalLibraries_native) },
|
||||
{ "setLayerPaths", "(Ljava/lang/ClassLoader;Ljava/lang/String;)V", reinterpret_cast<void*>(setLayerPaths_native) },
|
||||
{ "setDebugLayers", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDebugLayers_native) },
|
||||
};
|
||||
|
||||
@@ -399,6 +399,11 @@ message GlobalSettingsProto {
|
||||
optional SettingProto game_driver_blacklist = 11;
|
||||
// Game Driver - List of Apps that are allowed to use Game Driver
|
||||
optional SettingProto game_driver_whitelist = 12;
|
||||
// Game Driver - List of blacklists, each blacklist is a blacklist for
|
||||
// a specific Game Driver version
|
||||
optional SettingProto game_driver_blacklists = 14;
|
||||
// Game Driver - List of libraries in sphal accessible by Game Driver
|
||||
optional SettingProto game_driver_sphal_libraries = 16;
|
||||
}
|
||||
optional Gpu gpu = 59;
|
||||
|
||||
|
||||
@@ -447,8 +447,10 @@ public class SettingsBackupTest {
|
||||
Settings.Global.GAME_DRIVER_ALL_APPS,
|
||||
Settings.Global.GAME_DRIVER_OPT_IN_APPS,
|
||||
Settings.Global.GAME_DRIVER_OPT_OUT_APPS,
|
||||
Settings.Global.GAME_DRIVER_BLACKLISTS,
|
||||
Settings.Global.GAME_DRIVER_BLACKLIST,
|
||||
Settings.Global.GAME_DRIVER_WHITELIST,
|
||||
Settings.Global.GAME_DRIVER_SPHAL_LIBRARIES,
|
||||
Settings.Global.ENABLE_GNSS_RAW_MEAS_FULL_TRACKING,
|
||||
Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_PERSISTENT,
|
||||
Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_SLEEP_MILLIS,
|
||||
|
||||
@@ -662,6 +662,12 @@ class SettingsProtoDumpUtil {
|
||||
dumpSetting(s, p,
|
||||
Settings.Global.GAME_DRIVER_WHITELIST,
|
||||
GlobalSettingsProto.Gpu.GAME_DRIVER_WHITELIST);
|
||||
dumpSetting(s, p,
|
||||
Settings.Global.GAME_DRIVER_BLACKLISTS,
|
||||
GlobalSettingsProto.Gpu.GAME_DRIVER_BLACKLISTS);
|
||||
dumpSetting(s, p,
|
||||
Settings.Global.GAME_DRIVER_SPHAL_LIBRARIES,
|
||||
GlobalSettingsProto.Gpu.GAME_DRIVER_SPHAL_LIBRARIES);
|
||||
p.end(gpuToken);
|
||||
|
||||
final long hdmiToken = p.start(GlobalSettingsProto.HDMI);
|
||||
|
||||
@@ -60,6 +60,8 @@ final class CoreSettingsObserver extends ContentObserver {
|
||||
sGlobalSettingToTypeMap.put(Settings.Global.GAME_DRIVER_OPT_OUT_APPS, String.class);
|
||||
sGlobalSettingToTypeMap.put(Settings.Global.GAME_DRIVER_BLACKLIST, String.class);
|
||||
sGlobalSettingToTypeMap.put(Settings.Global.GAME_DRIVER_WHITELIST, String.class);
|
||||
sGlobalSettingToTypeMap.put(Settings.Global.GAME_DRIVER_BLACKLISTS, String.class);
|
||||
sGlobalSettingToTypeMap.put(Settings.Global.GAME_DRIVER_SPHAL_LIBRARIES, String.class);
|
||||
// add other global settings here...
|
||||
}
|
||||
|
||||
|
||||
274
services/core/java/com/android/server/gpu/GpuService.java
Normal file
274
services/core/java/com/android/server/gpu/GpuService.java
Normal file
@@ -0,0 +1,274 @@
|
||||
/*
|
||||
* Copyright 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server.gpu;
|
||||
|
||||
import static android.content.Intent.ACTION_PACKAGE_ADDED;
|
||||
import static android.content.Intent.ACTION_PACKAGE_CHANGED;
|
||||
import static android.content.Intent.ACTION_PACKAGE_REMOVED;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.ContentObserver;
|
||||
import android.gamedriver.GameDriverProto.Blacklist;
|
||||
import android.gamedriver.GameDriverProto.Blacklists;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Base64;
|
||||
import android.util.Slog;
|
||||
|
||||
import com.android.framework.protobuf.InvalidProtocolBufferException;
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.server.SystemService;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Service to manage GPU related features.
|
||||
*
|
||||
* <p>GPU service is a core service that monitors, coordinates all GPU related features,
|
||||
* as well as collect metrics about the GPU and GPU driver.</p>
|
||||
*/
|
||||
public class GpuService extends SystemService {
|
||||
public static final String TAG = "GpuService";
|
||||
public static final boolean DEBUG = false;
|
||||
|
||||
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;
|
||||
private final String mDriverPackageName;
|
||||
private final PackageManager mPackageManager;
|
||||
private final Object mLock = new Object();
|
||||
private ContentResolver mContentResolver;
|
||||
private long mGameDriverVersionCode;
|
||||
private SettingsObserver mSettingsObserver;
|
||||
@GuardedBy("mLock")
|
||||
private Blacklists mBlacklists;
|
||||
|
||||
public GpuService(Context context) {
|
||||
super(context);
|
||||
|
||||
mContext = context;
|
||||
mDriverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER);
|
||||
mGameDriverVersionCode = -1;
|
||||
mPackageManager = context.getPackageManager();
|
||||
if (mDriverPackageName != null && !mDriverPackageName.isEmpty()) {
|
||||
final IntentFilter packageFilter = new IntentFilter();
|
||||
packageFilter.addAction(ACTION_PACKAGE_ADDED);
|
||||
packageFilter.addAction(ACTION_PACKAGE_CHANGED);
|
||||
packageFilter.addAction(ACTION_PACKAGE_REMOVED);
|
||||
packageFilter.addDataScheme("package");
|
||||
getContext().registerReceiverAsUser(new PackageReceiver(), UserHandle.ALL,
|
||||
packageFilter, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBootPhase(int phase) {
|
||||
if (phase == PHASE_BOOT_COMPLETED) {
|
||||
mContentResolver = mContext.getContentResolver();
|
||||
mSettingsObserver = new SettingsObserver();
|
||||
if (mDriverPackageName == null || mDriverPackageName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
fetchGameDriverPackageProperties();
|
||||
processBlacklists();
|
||||
setBlacklist();
|
||||
}
|
||||
}
|
||||
|
||||
private final class SettingsObserver extends ContentObserver {
|
||||
private final Uri mGameDriverBlackUri =
|
||||
Settings.Global.getUriFor(Settings.Global.GAME_DRIVER_BLACKLISTS);
|
||||
|
||||
SettingsObserver() {
|
||||
super(new Handler());
|
||||
mContentResolver.registerContentObserver(mGameDriverBlackUri, false, this,
|
||||
UserHandle.USER_ALL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
if (uri == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mGameDriverBlackUri.equals(uri)) {
|
||||
processBlacklists();
|
||||
setBlacklist();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class PackageReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(@NonNull final Context context, @NonNull final Intent intent) {
|
||||
final Uri data = intent.getData();
|
||||
if (data == null && DEBUG) {
|
||||
Slog.e(TAG, "Cannot handle package broadcast with null data");
|
||||
return;
|
||||
}
|
||||
final String packageName = data.getSchemeSpecificPart();
|
||||
if (!packageName.equals(mDriverPackageName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
|
||||
|
||||
switch (intent.getAction()) {
|
||||
case ACTION_PACKAGE_ADDED:
|
||||
case ACTION_PACKAGE_CHANGED:
|
||||
case ACTION_PACKAGE_REMOVED:
|
||||
fetchGameDriverPackageProperties();
|
||||
setBlacklist();
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
driverInfo = mPackageManager.getApplicationInfo(mDriverPackageName,
|
||||
PackageManager.MATCH_SYSTEM_ONLY);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
if (DEBUG) {
|
||||
Slog.e(TAG, "driver package '" + mDriverPackageName + "' 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) {
|
||||
Slog.w(TAG, "Driver package is not known to be compatible with O");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processBlacklists() {
|
||||
// TODO(b/121350991) Switch to DeviceConfig with property listener.
|
||||
String base64String =
|
||||
Settings.Global.getString(mContentResolver, Settings.Global.GAME_DRIVER_BLACKLISTS);
|
||||
if (base64String == null || base64String.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (mLock) {
|
||||
// Reset all blacklists
|
||||
mBlacklists = null;
|
||||
try {
|
||||
mBlacklists = Blacklists.parseFrom(Base64.decode(base64String, BASE64_FLAGS));
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (DEBUG) {
|
||||
Slog.w(TAG, "Can't parse blacklist, skip and continue...");
|
||||
}
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
if (DEBUG) {
|
||||
Slog.w(TAG, "Can't parse blacklist, skip and continue...");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setBlacklist() {
|
||||
Settings.Global.putString(mContentResolver,
|
||||
Settings.Global.GAME_DRIVER_BLACKLIST, "");
|
||||
synchronized (mLock) {
|
||||
if (mBlacklists == null) {
|
||||
return;
|
||||
}
|
||||
List<Blacklist> blacklists = mBlacklists.getBlacklistsList();
|
||||
for (Blacklist blacklist : blacklists) {
|
||||
if (blacklist.getVersionCode() == mGameDriverVersionCode) {
|
||||
Settings.Global.putString(mContentResolver,
|
||||
Settings.Global.GAME_DRIVER_BLACKLIST,
|
||||
String.join(",", blacklist.getPackageNamesList()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,7 @@ import com.android.server.display.DisplayManagerService;
|
||||
import com.android.server.dreams.DreamManagerService;
|
||||
import com.android.server.emergency.EmergencyAffordanceService;
|
||||
import com.android.server.fingerprint.FingerprintService;
|
||||
import com.android.server.gpu.GpuService;
|
||||
import com.android.server.hdmi.HdmiControlService;
|
||||
import com.android.server.input.InputManagerService;
|
||||
import com.android.server.job.JobSchedulerService;
|
||||
@@ -747,6 +748,11 @@ public final class SystemServer {
|
||||
traceBeginAndSlog("StartBugreportManagerService");
|
||||
mSystemServiceManager.startService(BugreportManagerService.class);
|
||||
traceEnd();
|
||||
|
||||
// Serivce for GPU and GPU driver.
|
||||
traceBeginAndSlog("GpuService");
|
||||
mSystemServiceManager.startService(GpuService.class);
|
||||
traceEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user