Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac74bc8f authored by Peiyong Lin's avatar Peiyong Lin Committed by Yiwei Zhang
Browse files

[Game Driver] Add blacklist mechanism.

When a blacklist is set, we must not use driver package for those applications
on the blacklist.

BUG: 120869311
Test: Build, flash, boot. Verify with command line.
Change-Id: I1c9f10a3086007038c328a20346ffadeff1861ae
Merged-In: I1c9f10a3086007038c328a20346ffadeff1861ae
parent 79c5356a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -687,6 +687,7 @@ java_defaults {
    static_libs: [
        "apex_aidl_interface-java",
        "framework-protos",
        "game-driver-protos",
        "android.hidl.base-V1.0-java",
        "android.hardware.cas-V1.0-java",
        "android.hardware.contexthub-V1.0-java",
+57 −20
Original line number Diff line number Diff line
@@ -20,12 +20,17 @@ 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;
@@ -53,6 +58,8 @@ public class GraphicsEnvironment {
    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 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;
@@ -161,6 +168,24 @@ public class GraphicsEnvironment {
            return;
        }

        ApplicationInfo driverInfo;
        try {
            driverInfo = context.getPackageManager().getApplicationInfo(driverPackageName,
                    PackageManager.MATCH_SYSTEM_ONLY);
        } catch (PackageManager.NameNotFoundException e) {
            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;
        }

        // 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.
@@ -172,7 +197,7 @@ public class GraphicsEnvironment {

        // GUP_DEV_ALL_APPS
        // 0: Default (Invalid values fallback to default as well)
        // 1: All apps use Game Update Package
        // 1: All apps use Game Driver
        // 2: All apps use system graphics driver
        int gupDevAllApps = coreSettings.getInt(Settings.Global.GUP_DEV_ALL_APPS, 0);
        if (gupDevAllApps == 2) {
@@ -191,33 +216,45 @@ public class GraphicsEnvironment {
                }
                return;
            }
            boolean isDevOptIn = getGlobalSettingsString(coreSettings,
                                                         Settings.Global.GUP_DEV_OPT_IN_APPS)
                              .contains(ai.packageName);

            if (!getGlobalSettingsString(coreSettings, Settings.Global.GUP_DEV_OPT_IN_APPS)
                            .contains(ai.packageName)
                    && !onWhitelist(context, driverPackageName, ai.packageName)) {
            if (!isDevOptIn && !onWhitelist(context, driverPackageName, ai.packageName)) {
                if (DEBUG) {
                    Log.w(TAG, ai.packageName + " is not on the whitelist.");
                }
                return;
            }
        }

        ApplicationInfo driverInfo;
            if (!isDevOptIn) {
                // 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 {
            driverInfo = context.getPackageManager().getApplicationInfo(driverPackageName,
                    PackageManager.MATCH_SYSTEM_ONLY);
        } catch (PackageManager.NameNotFoundException e) {
            Log.w(TAG, "driver package '" + driverPackageName + "' not installed");
                    // TODO(b/121350991) Switch to DeviceConfig with property listener.
                    String base64String = coreSettings.getString(Settings.Global.GUP_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;
                                    }

        // 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) {
                                }
                                break;
                            }
                        }
                    }
                } catch (InvalidProtocolBufferException e) {
                    if (DEBUG) {
                Log.w(TAG, "updated driver package is not known to be compatible with O");
                        Log.w(TAG, "Can't parse blacklist, skip and continue...");
                    }
                }
            }
            return;
        }

        String abi = chooseAbi(driverInfo);
+11 −0
Original line number Diff line number Diff line
java_library_static {
    name: "game-driver-protos",
    host_supported: true,
    proto: {
        type: "lite",
    },
    srcs: ["game_driver.proto"],
    no_framework_libs: true,
    jarjar_rules: "jarjar-rules.txt",
    sdk_version: "28",
}
+31 −0
Original line number Diff line number Diff line
/*
 * 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.
 */

syntax = "proto2";

package android.gamedriver;

option java_package = "android.gamedriver";
option java_outer_classname = "GameDriverProto";

message Blacklist {
    optional int64 version_code = 1;
    repeated string package_names = 2;
}

message Blacklists {
    repeated Blacklist blacklists = 1;
}
+1 −0
Original line number Diff line number Diff line
rule com.google.protobuf.** com.android.framework.protobuf.@1