Add a new GpuService API to query persist.graphics.egl
To solve b/408439360 and b/409589250, we need to query
persist.graphics.egl in GraphicsEnvironment.java. This change
adds the GpuService API to read persist.graphics.egl value
through aidl. This way we don't need to alter the sepolicy
to expose read access of graphics_config_writable_prop to
general apps, and we can control when the persist.graphics.egl
is accessed by adding UID permission.
Flag: com.android.graphics.graphicsenv.flags.query_persist_graphics_egl
Bug: b/408439360
Bug: b/409589250
Test: make, flash to shiba, check there is no avc: denied { read } for name="u:object_r:graphics_config_writable_prop
Change-Id: Ic12c6a3ca515728740f6e9c70bb3834d67d3231e
diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp
index 03e6456..22e2772 100644
--- a/libs/graphicsenv/GraphicsEnv.cpp
+++ b/libs/graphicsenv/GraphicsEnv.cpp
@@ -746,6 +746,18 @@
gpuService->toggleAngleAsSystemDriver(enabled);
}
+std::string GraphicsEnv::nativeGetPersistGraphicsEgl() {
+ if (!graphicsenv_flags::query_persist_graphics_egl()) {
+ return "";
+ }
+ const sp<IGpuService> gpuService = getGpuService();
+ if (!gpuService) {
+ ALOGE("No GPU service");
+ return "";
+ }
+ return gpuService->getPersistGraphicsEgl();
+}
+
bool GraphicsEnv::shouldUseSystemAngle() {
return mShouldUseSystemAngle;
}
diff --git a/libs/graphicsenv/IGpuService.cpp b/libs/graphicsenv/IGpuService.cpp
index 9a34aff..2efdc71 100644
--- a/libs/graphicsenv/IGpuService.cpp
+++ b/libs/graphicsenv/IGpuService.cpp
@@ -108,6 +108,18 @@
IBinder::FLAG_ONEWAY);
}
+ std::string getPersistGraphicsEgl() override {
+ Parcel data, reply;
+ data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
+
+ status_t error = remote()->transact(BnGpuService::GET_PERSIST_GRAPHICS_EGL, data, &reply);
+ std::string persistGraphicsEgl;
+ if (error == OK) {
+ error = reply.readUtf8FromUtf16(&persistGraphicsEgl);
+ }
+ return persistGraphicsEgl;
+ }
+
std::string getUpdatableDriverPath() override {
Parcel data, reply;
data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
@@ -286,6 +298,12 @@
toggleAngleAsSystemDriver(enableAngleAsSystemDriver);
return OK;
}
+ case GET_PERSIST_GRAPHICS_EGL: {
+ CHECK_INTERFACE(IGpuService, data, reply);
+
+ std::string persistGraphicsEgl = getPersistGraphicsEgl();
+ return reply->writeUtf8AsUtf16(persistGraphicsEgl);
+ }
case GET_FEATURE_CONFIG_OVERRIDES: {
CHECK_INTERFACE(IGpuService, data, reply);
diff --git a/libs/graphicsenv/graphicsenv_flags.aconfig b/libs/graphicsenv/graphicsenv_flags.aconfig
index efa4bca..dd8e6a3 100644
--- a/libs/graphicsenv/graphicsenv_flags.aconfig
+++ b/libs/graphicsenv/graphicsenv_flags.aconfig
@@ -7,3 +7,10 @@
description: "This flag controls the ANGLE Feature Overrides in GraphicsEnv."
bug: "372694741"
}
+
+flag {
+ name: "query_persist_graphics_egl"
+ namespace: "gpu"
+ description: "This flag controls the ability to query persist.graphics.egl through GpuService"
+ bug: "408439360"
+}
diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
index 6821900..3275073 100644
--- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
+++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
@@ -126,6 +126,8 @@
std::vector<const char*>& disabled);
// Set the persist.graphics.egl system property value.
void nativeToggleAngleAsSystemDriver(bool enabled);
+ // Get the persist.graphics.egl system property value.
+ std::string nativeGetPersistGraphicsEgl();
bool shouldUseSystemAngle();
bool shouldUseNativeDriver();
diff --git a/libs/graphicsenv/include/graphicsenv/IGpuService.h b/libs/graphicsenv/include/graphicsenv/IGpuService.h
index 442683a..a73f797 100644
--- a/libs/graphicsenv/include/graphicsenv/IGpuService.h
+++ b/libs/graphicsenv/include/graphicsenv/IGpuService.h
@@ -57,6 +57,9 @@
// sets ANGLE as system GLES driver if enabled==true by setting persist.graphics.egl to true.
virtual void toggleAngleAsSystemDriver(bool enabled) = 0;
+ // gets persist.graphics.egl value
+ virtual std::string getPersistGraphicsEgl() = 0;
+
// Get the list of features to override.
virtual FeatureOverrides getFeatureOverrides() = 0;
};
@@ -72,6 +75,7 @@
SET_TARGET_STATS_ARRAY,
ADD_VULKAN_ENGINE_NAME,
GET_FEATURE_CONFIG_OVERRIDES,
+ GET_PERSIST_GRAPHICS_EGL,
// Always append new enum to the end.
};
diff --git a/services/gpuservice/GpuService.cpp b/services/gpuservice/GpuService.cpp
index 46327df..7bfb447 100644
--- a/services/gpuservice/GpuService.cpp
+++ b/services/gpuservice/GpuService.cpp
@@ -146,6 +146,11 @@
}
}
+std::string GpuService::getPersistGraphicsEgl() {
+ std::lock_guard<std::mutex> lock(mLock);
+ return android::base::GetProperty("persist.graphics.egl", "");
+}
+
FeatureOverrides GpuService::getFeatureOverrides() {
if (!graphicsenv_flags::angle_feature_overrides()) {
FeatureOverrides featureOverrides;
diff --git a/services/gpuservice/include/gpuservice/GpuService.h b/services/gpuservice/include/gpuservice/GpuService.h
index 22be9a7..e8ac533 100644
--- a/services/gpuservice/include/gpuservice/GpuService.h
+++ b/services/gpuservice/include/gpuservice/GpuService.h
@@ -67,6 +67,7 @@
std::string getUpdatableDriverPath() override;
FeatureOverrides getFeatureOverrides() override;
void toggleAngleAsSystemDriver(bool enabled) override;
+ std::string getPersistGraphicsEgl() override;
void addVulkanEngineName(const std::string& appPackageName, const uint64_t driverVersionCode,
const char *engineName) override;