Merge "Revert "Revert "[GPU Service] Move blacklists process to GPU service."""
This commit is contained in:
@@ -25,16 +25,11 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.content.res.AssetManager;
|
||||
import android.gamedriver.GameDriverProto.Blacklist;
|
||||
import android.gamedriver.GameDriverProto.Blacklists;
|
||||
import android.opengl.EGL14;
|
||||
import android.provider.Settings;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.framework.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import dalvik.system.VMRuntime;
|
||||
|
||||
import java.io.File;
|
||||
@@ -69,8 +64,6 @@ public class GraphicsEnvironment {
|
||||
private static final String ANGLE_RULES_FILE = "a4a_rules.json";
|
||||
private static final String ANGLE_TEMP_RULES = "debug.angle.rules";
|
||||
private static final String ACTION_ANGLE_FOR_ANDROID = "android.app.action.ANGLE_FOR_ANDROID";
|
||||
private static final String GAME_DRIVER_BLACKLIST_FLAG = "blacklist";
|
||||
private static final int BASE64_FLAGS = Base64.NO_PADDING | Base64.NO_WRAP;
|
||||
|
||||
private ClassLoader mClassLoader;
|
||||
private String mLayerPath;
|
||||
@@ -639,34 +632,13 @@ public class GraphicsEnvironment {
|
||||
return false;
|
||||
}
|
||||
|
||||
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.
|
||||
final String base64String =
|
||||
coreSettings.getString(Settings.Global.GAME_DRIVER_BLACKLIST);
|
||||
if (base64String != null && !base64String.isEmpty()) {
|
||||
final Blacklists blacklistsProto =
|
||||
Blacklists.parseFrom(Base64.decode(base64String, BASE64_FLAGS));
|
||||
final List<Blacklist> blacklists = blacklistsProto.getBlacklistsList();
|
||||
final long driverVersionCode = driverAppInfo.longVersionCode;
|
||||
for (Blacklist blacklist : blacklists) {
|
||||
if (blacklist.getVersionCode() == driverVersionCode) {
|
||||
for (String pkgName : blacklist.getPackageNamesList()) {
|
||||
if (pkgName == packageName) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
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(null, coreSettings,
|
||||
Settings.Global.GAME_DRIVER_BLACKLIST)
|
||||
.contains(ai.packageName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,24 +22,33 @@ 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.
|
||||
@@ -52,17 +61,25 @@ public class GpuService extends SystemService {
|
||||
public static final boolean DEBUG = false;
|
||||
|
||||
private static final String PROPERTY_GFX_DRIVER = "ro.gfx.driver.0";
|
||||
private static final String WHITELIST_FILENAME = "whitelist.txt";
|
||||
private static final String GAME_DRIVER_WHITELIST_FILENAME = "whitelist.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();
|
||||
@@ -82,10 +99,37 @@ public class GpuService extends SystemService {
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +153,7 @@ public class GpuService extends SystemService {
|
||||
case ACTION_PACKAGE_CHANGED:
|
||||
case ACTION_PACKAGE_REMOVED:
|
||||
fetchGameDriverPackageProperties();
|
||||
setBlacklist();
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
@@ -138,16 +183,22 @@ public class GpuService extends SystemService {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset the whitelist.
|
||||
Settings.Global.putString(mContentResolver,
|
||||
Settings.Global.GAME_DRIVER_WHITELIST, "");
|
||||
mGameDriverVersionCode = driverInfo.longVersionCode;
|
||||
|
||||
try {
|
||||
final Context driverContext = mContext.createPackageContext(mDriverPackageName,
|
||||
Context.CONTEXT_RESTRICTED);
|
||||
final BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(driverContext.getAssets().open(WHITELIST_FILENAME)));
|
||||
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(mContext.getContentResolver(),
|
||||
Settings.Global.putString(mContentResolver,
|
||||
Settings.Global.GAME_DRIVER_WHITELIST,
|
||||
String.join(",", whitelistedPackageNames));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
@@ -160,4 +211,48 @@ public class GpuService extends SystemService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user